# Path: ephypype/power.py
# def _compute_and_save_psd(data_fname, fmin=0, fmax=120,
#                           method='welch', is_epoched=False,
#                           n_fft=256, n_overlap=0,
#                           picks=None, proj=False, n_jobs=1, verbose=None):
#     """Load epochs/raw from file, compute psd and save the result."""
# 
#     if is_epoched:
#         epochs = read_epochs(data_fname)
#     else:
#         epochs = read_raw_fif(data_fname, preload=True)
# 
#     epochs_meg = epochs.pick_types(meg=True, eeg=False, eog=False, ecg=False)
# 
#     if method == 'welch':
#         from mne.time_frequency import psd_welch
#         psds, freqs = psd_welch(epochs_meg, fmin=fmin, fmax=fmax)
#     elif method == 'multitaper':
#         from mne.time_frequency import psd_multitaper
#         psds, freqs = psd_multitaper(epochs_meg, fmin=fmin, fmax=fmax)
#     else:
#         raise Exception('nonexistent method for psd computation')
# 
#     _get_raw_array(data_fname, save_data=False)
# 
#     psds_fname = _save_psd(data_fname, psds, freqs)
#     _save_psd_img(data_fname, psds, freqs, is_epoched, method)
# 
#     return psds_fname
# 
# def _compute_and_save_src_psd(data_fname, sfreq, fmin=0, fmax=120,
#                               is_epoched=False,
#                               n_fft=256, n_overlap=0,
#                               n_jobs=1, verbose=None):
#     """Load epochs/raw from file, compute psd and save the result."""
#     src_data = np.load(data_fname)
#     dim = src_data.shape
#     if len(dim) == 3 and dim[0] == 1:
#         src_data = np.squeeze(src_data)
#     print(('src data dim: {}'.format(src_data.shape)))
# 
#     if n_fft > src_data.shape[1]:
#         nperseg = src_data.shape[1]
#     else:
#         nperseg = n_fft
# 
#     n_freqs = nperseg // 2 + 1
#     psds = np.empty([src_data.shape[0], n_freqs])
#     for i in range(src_data.shape[0]):
#         freqs, Pxx = welch(src_data[i, :], fs=sfreq, window='hamming',
#                            nperseg=nperseg, noverlap=n_overlap, nfft=None)
#         psds[i, :] = Pxx
# 
#     psds_fname = _save_psd(data_fname, psds, freqs)
#     _save_psd_img(data_fname, psds, freqs, is_epoched)
# 
#     return psds_fname


from nipype.interfaces.base import BaseInterface, \
    BaseInterfaceInputSpec, traits, File, TraitedSpec
from ...power import _compute_and_save_psd, _compute_and_save_src_psd
        overlap : float
            Number of points of overlap between segments
        method : str
            Power spectral density computation method. Possible values are
            'welch', 'multitaper'
        is_epoched : bool
            If true input data are mne.Epochs
        is_sensor_space : bool
            True for PSD on sensor space, False for PSD on source

    Outputs
    -------
        psds_file : str
            Name of the .npz file containing psd tensor and frequencies
    """

    input_spec = PowerInputSpec
    output_spec = PowerOutputSpec

    def _run_interface(self, runtime):
        data_file = self.inputs.data_file
        sfreq = self.inputs.sfreq
        fmin = self.inputs.fmin
        fmax = self.inputs.fmax
        nfft = self.inputs.nfft
        overlap = self.inputs.overlap
        method = self.inputs.method
        is_epoched = self.inputs.is_epoched
        is_sensor_space = self.inputs.is_sensor_space
        if is_sensor_space:

# Path: ephypype/power.py
# def _compute_and_save_psd(data_fname, fmin=0, fmax=120,
#                           method='welch', is_epoched=False,
#                           n_fft=256, n_overlap=0,
#                           picks=None, proj=False, n_jobs=1, verbose=None):
#     """Load epochs/raw from file, compute psd and save the result."""
# 
#     if is_epoched:
#         epochs = read_epochs(data_fname)
#     else:
#         epochs = read_raw_fif(data_fname, preload=True)
# 
#     epochs_meg = epochs.pick_types(meg=True, eeg=False, eog=False, ecg=False)
# 
#     if method == 'welch':
#         from mne.time_frequency import psd_welch
#         psds, freqs = psd_welch(epochs_meg, fmin=fmin, fmax=fmax)
#     elif method == 'multitaper':
#         from mne.time_frequency import psd_multitaper
#         psds, freqs = psd_multitaper(epochs_meg, fmin=fmin, fmax=fmax)
#     else:
#         raise Exception('nonexistent method for psd computation')
# 
#     _get_raw_array(data_fname, save_data=False)
# 
#     psds_fname = _save_psd(data_fname, psds, freqs)
#     _save_psd_img(data_fname, psds, freqs, is_epoched, method)
# 
#     return psds_fname
# 
# def _compute_and_save_src_psd(data_fname, sfreq, fmin=0, fmax=120,
#                               is_epoched=False,
#                               n_fft=256, n_overlap=0,
#                               n_jobs=1, verbose=None):
#     """Load epochs/raw from file, compute psd and save the result."""
#     src_data = np.load(data_fname)
#     dim = src_data.shape
#     if len(dim) == 3 and dim[0] == 1:
#         src_data = np.squeeze(src_data)
#     print(('src data dim: {}'.format(src_data.shape)))
# 
#     if n_fft > src_data.shape[1]:
#         nperseg = src_data.shape[1]
#     else:
#         nperseg = n_fft
# 
#     n_freqs = nperseg // 2 + 1
#     psds = np.empty([src_data.shape[0], n_freqs])
#     for i in range(src_data.shape[0]):
#         freqs, Pxx = welch(src_data[i, :], fs=sfreq, window='hamming',
#                            nperseg=nperseg, noverlap=n_overlap, nfft=None)
#         psds[i, :] = Pxx
# 
#     psds_fname = _save_psd(data_fname, psds, freqs)
#     _save_psd_img(data_fname, psds, freqs, is_epoched)
# 
#     return psds_fname


# Path: ephypype/interfaces/mne/power.py
from nipype.interfaces.base import BaseInterface, \
    BaseInterfaceInputSpec, traits, File, TraitedSpec
from ...power import _compute_and_save_psd, _compute_and_save_src_psd

        overlap : float
            Number of points of overlap between segments
        method : str
            Power spectral density computation method. Possible values are
            'welch', 'multitaper'
        is_epoched : bool
            If true input data are mne.Epochs
        is_sensor_space : bool
            True for PSD on sensor space, False for PSD on source

    Outputs
    -------
        psds_file : str
            Name of the .npz file containing psd tensor and frequencies
    """

    input_spec = PowerInputSpec
    output_spec = PowerOutputSpec

    def _run_interface(self, runtime):
        data_file = self.inputs.data_file
        sfreq = self.inputs.sfreq
        fmin = self.inputs.fmin
        fmax = self.inputs.fmax
        nfft = self.inputs.nfft
        overlap = self.inputs.overlap
        method = self.inputs.method
        is_epoched = self.inputs.is_epoched
        is_sensor_space = self.inputs.is_sensor_space
        if is_sensor_space:

            self.psds_file = _compute_and_save_psd(data_file, fmin, fmax,