# Path: ephypype/power.py
# def _compute_mean_band_psd(psds_file, freq_bands):
#     """Compute mean band psd."""
#     npzfile = np.load(psds_file)
#     print(('the .npz file contain {} \n'.format(npzfile.files)))
# 
#     # is a matrix with dim n_channels(n_voxel) x n_freqs
#     psds = npzfile['psds']
#     print(('psds is a matrix {} \n'.format(psds.shape)))
# 
#     # list of frequencies in which psds was computed;
#     # its length = columns of psds
#     freqs = npzfile['freqs']
#     print(('freqs contains {} frequencies \n'.format(len(freqs))))
# 
#     n_row, _ = psds.shape
#     n_fr = len(freq_bands)
# 
#     m_px = np.empty([n_row, n_fr])
# 
#     for f in range(n_fr):
#         min_fr = freq_bands[f][0]
#         max_fr = freq_bands[f][1]
#         print(('*** frequency band [{}, {}] ***\n'.format(min_fr, max_fr)))
#         m_px[:, f] = np.mean(psds[:, (freqs >= min_fr) * (freqs <= max_fr)], 1)
# 
#     psds_mean_fname = _save_m_px(psds_file, m_px)
# 
#     return psds_mean_fname


from nipype.interfaces.base import BaseInterface,\
    BaseInterfaceInputSpec, traits, TraitedSpec
from ..power import _compute_mean_band_psd
                                       desc="mean psd in bands in .npy format")


class PowerBand(BaseInterface):
    """Compute mean power spectral density for each frequency band.

    Then, it's save in a  numpy file .npy

    Parameters
    ----------
    psds_file
        type = File, exists=True, desc='psd tensor and frequencies in .npz
               format', mandatory=True
    freq_bands
        type = List of Float, desc='frequency bands', mandatory=True

    Returns
    -------
    mean_power_band_file
        type = File, exists=True, desc="mean psd in bands in .npy format"
    """

    input_spec = PowerBandInputSpec
    output_spec = PowerBandOutputSpec

    def _run_interface(self, runtime):

        psds_file = self.inputs.psds_file
        freq_bands = self.inputs.freq_bands


# Path: ephypype/power.py
# def _compute_mean_band_psd(psds_file, freq_bands):
#     """Compute mean band psd."""
#     npzfile = np.load(psds_file)
#     print(('the .npz file contain {} \n'.format(npzfile.files)))
# 
#     # is a matrix with dim n_channels(n_voxel) x n_freqs
#     psds = npzfile['psds']
#     print(('psds is a matrix {} \n'.format(psds.shape)))
# 
#     # list of frequencies in which psds was computed;
#     # its length = columns of psds
#     freqs = npzfile['freqs']
#     print(('freqs contains {} frequencies \n'.format(len(freqs))))
# 
#     n_row, _ = psds.shape
#     n_fr = len(freq_bands)
# 
#     m_px = np.empty([n_row, n_fr])
# 
#     for f in range(n_fr):
#         min_fr = freq_bands[f][0]
#         max_fr = freq_bands[f][1]
#         print(('*** frequency band [{}, {}] ***\n'.format(min_fr, max_fr)))
#         m_px[:, f] = np.mean(psds[:, (freqs >= min_fr) * (freqs <= max_fr)], 1)
# 
#     psds_mean_fname = _save_m_px(psds_file, m_px)
# 
#     return psds_mean_fname


# Path: ephypype/nodes/power_tools.py
from nipype.interfaces.base import BaseInterface,\
    BaseInterfaceInputSpec, traits, TraitedSpec
from ..power import _compute_mean_band_psd

                                       desc="mean psd in bands in .npy format")


class PowerBand(BaseInterface):
    """Compute mean power spectral density for each frequency band.

    Then, it's save in a  numpy file .npy

    Parameters
    ----------
    psds_file
        type = File, exists=True, desc='psd tensor and frequencies in .npz
               format', mandatory=True
    freq_bands
        type = List of Float, desc='frequency bands', mandatory=True

    Returns
    -------
    mean_power_band_file
        type = File, exists=True, desc="mean psd in bands in .npy format"
    """

    input_spec = PowerBandInputSpec
    output_spec = PowerBandOutputSpec

    def _run_interface(self, runtime):

        psds_file = self.inputs.psds_file
        freq_bands = self.inputs.freq_bands


        self.mean_power_band_file = _compute_mean_band_psd(psds_file,