# Path: ephypype/interfaces/mne/Inverse_solution.py
# class InverseSolution(BaseInterface):
#     """Compute the inverse solution on raw or epoch data.
# 
#     This class is considering N_r regions in source space based on a FreeSurfer
#     cortical parcellation.
# 
#     Inputs
#     ------
#         sbj_id : str
#             Subject name
#         subjects_dir : str
#             Freesurfer directory
#         raw_filename : str
#             Filename of the raw data
#         cov_filename : str
#             Filename of the noise covariance matrix
#         fwd_filename : str
#             Filename of the forward operator
#         is_epoched : bool
#             If True and events_id = None the input data are epoch data
#             in the format -epo.fif
#             if True and events_id is not None, the raw data are epoched
#             according to events_id and t_min and t_max values
#         events_id: dict
#             The dict of events
#         condition: list
#             List of events
#         t_min, t_max: int (defualt None)
#             Define the time interval in which to epoch the raw data
#         is_evoked: bool
#             If True the raw data will be averaged according to the events
#             contained in the dict events_id
#         is_ave: bool
#             If True the input data is an evoked dataset
#         is_fixed : bool
#             If True we use fixed orientation
#         inv_method : str
#             The inverse method to use; possible choices: MNE, dSPM, sLORETA
#         snr : float
#             The SNR value used to define the regularization parameter
#         parc: str
#             The parcellation defining the ROIs atlas in the source space
#         aseg: bool
#             If True a mixed source space will be created and the sub cortical
#             regions defined in aseg_labels will be added to the source space
#         aseg_labels: list
#             List of substructures we want to include in the mixed source space
#         all_src_space: bool
#             If True we compute the inverse for all points of the s0urce space
#         ROIs_mean: bool
#             If True we compute the mean of estimated time series on ROIs
# 
#     Outputs
#     -------
#         ts_file : str
#             Name of the .npy file with the estimated source time series
#         labels : str
#             Labels file in pickle format
#         label_names : str
#             Name of the .txt file with labels name
#         label_coords : str
#             Name of the .txt file with labels coordinates
# 
#     """
# 
#     input_spec = InverseSolutionConnInputSpec
#     output_spec = InverseSolutionConnOutputSpec
# 
#     def _run_interface(self, runtime):
# 
#         sbj_id = self.inputs.sbj_id
#         subjects_dir = self.inputs.subjects_dir
#         raw_filename = self.inputs.raw_filename
#         cov_filename = self.inputs.cov_filename
#         fwd_filename = self.inputs.fwd_filename
#         is_epoched = self.inputs.is_epoched
#         is_fixed = self.inputs.is_fixed
#         events_id = self.inputs.events_id
#         condition = self.inputs.condition
#         t_min = self.inputs.t_min
#         t_max = self.inputs.t_max
#         is_evoked = self.inputs.is_evoked
#         is_ave = self.inputs.is_ave
#         inv_method = self.inputs.inv_method
#         snr = self.inputs.snr
#         parc = self.inputs.parc
#         aseg = self.inputs.aseg
#         aseg_labels = self.inputs.aseg_labels
#         all_src_space = self.inputs.all_src_space
#         ROIs_mean = self.inputs.ROIs_mean
# 
#         if inv_method != 'LCMV':
#             self.ts_file, self.labels, self.label_names, \
#                 self.label_coords, self.stc_files = \
#                 _compute_inverse_solution(raw_filename, sbj_id, subjects_dir,
#                                           fwd_filename, cov_filename,
#                                           is_epoched=is_epoched,
#                                           events_id=events_id,
#                                           condition=condition, is_ave=is_ave,
#                                           t_min=t_min, t_max=t_max,
#                                           is_evoked=is_evoked, snr=snr,
#                                           inv_method=inv_method, parc=parc,
#                                           aseg=aseg, aseg_labels=aseg_labels,
#                                           all_src_space=all_src_space,
#                                           ROIs_mean=ROIs_mean,
#                                           is_fixed=is_fixed)
#         else:
#             self.ts_file, self.labels, self.label_names, \
#                 self.label_coords = \
#                 _compute_LCMV_inverse_solution(raw_filename, sbj_id,
#                                                subjects_dir,
#                                                fwd_filename, cov_filename,
#                                                parc=parc,
#                                                all_src_space=all_src_space,
#                                                ROIs_mean=ROIs_mean,
#                                                is_fixed=is_fixed)
#             self.stc_files = []
# 
#         return runtime
# 
#     def _list_outputs(self):
# 
#         outputs = self._outputs().get()
# 
#         outputs['ts_file'] = self.ts_file
#         outputs['labels'] = self.labels
#         outputs['label_names'] = self.label_names
#         outputs['label_coords'] = self.label_coords
#         outputs['stc_files'] = self.stc_files
# 
#         return outputs


import mne
import pickle
import nipype.pipeline.engine as pe
import numpy as np
import os.path as op
from ephypype.interfaces.mne.Inverse_solution import InverseSolution
from numpy.testing import assert_array_almost_equal
"""Test Inverse_solution Interface."""




data_path = mne.datasets.testing.data_path()
sbj = 'sample'
subjects_dir = op.join(data_path, 'subjects')
raw_fname = op.join(data_path, 'MEG', sbj, 'sample_audvis_trunc_raw.fif')
ave_fname = op.join(data_path, 'MEG', sbj, 'sample_audvis_trunc-ave.fif')
fwd_fname = op.join(data_path, 'MEG', sbj,
                    'sample_audvis_trunc-meg-eeg-oct-6-fwd.fif')
cov_fname = op.join(data_path, 'MEG', sbj, 'sample_audvis_trunc-cov.fif')


def test_mne_inverse_solution():
    """Test compute MNE inverse solution."""


# Path: ephypype/interfaces/mne/Inverse_solution.py
# class InverseSolution(BaseInterface):
#     """Compute the inverse solution on raw or epoch data.
# 
#     This class is considering N_r regions in source space based on a FreeSurfer
#     cortical parcellation.
# 
#     Inputs
#     ------
#         sbj_id : str
#             Subject name
#         subjects_dir : str
#             Freesurfer directory
#         raw_filename : str
#             Filename of the raw data
#         cov_filename : str
#             Filename of the noise covariance matrix
#         fwd_filename : str
#             Filename of the forward operator
#         is_epoched : bool
#             If True and events_id = None the input data are epoch data
#             in the format -epo.fif
#             if True and events_id is not None, the raw data are epoched
#             according to events_id and t_min and t_max values
#         events_id: dict
#             The dict of events
#         condition: list
#             List of events
#         t_min, t_max: int (defualt None)
#             Define the time interval in which to epoch the raw data
#         is_evoked: bool
#             If True the raw data will be averaged according to the events
#             contained in the dict events_id
#         is_ave: bool
#             If True the input data is an evoked dataset
#         is_fixed : bool
#             If True we use fixed orientation
#         inv_method : str
#             The inverse method to use; possible choices: MNE, dSPM, sLORETA
#         snr : float
#             The SNR value used to define the regularization parameter
#         parc: str
#             The parcellation defining the ROIs atlas in the source space
#         aseg: bool
#             If True a mixed source space will be created and the sub cortical
#             regions defined in aseg_labels will be added to the source space
#         aseg_labels: list
#             List of substructures we want to include in the mixed source space
#         all_src_space: bool
#             If True we compute the inverse for all points of the s0urce space
#         ROIs_mean: bool
#             If True we compute the mean of estimated time series on ROIs
# 
#     Outputs
#     -------
#         ts_file : str
#             Name of the .npy file with the estimated source time series
#         labels : str
#             Labels file in pickle format
#         label_names : str
#             Name of the .txt file with labels name
#         label_coords : str
#             Name of the .txt file with labels coordinates
# 
#     """
# 
#     input_spec = InverseSolutionConnInputSpec
#     output_spec = InverseSolutionConnOutputSpec
# 
#     def _run_interface(self, runtime):
# 
#         sbj_id = self.inputs.sbj_id
#         subjects_dir = self.inputs.subjects_dir
#         raw_filename = self.inputs.raw_filename
#         cov_filename = self.inputs.cov_filename
#         fwd_filename = self.inputs.fwd_filename
#         is_epoched = self.inputs.is_epoched
#         is_fixed = self.inputs.is_fixed
#         events_id = self.inputs.events_id
#         condition = self.inputs.condition
#         t_min = self.inputs.t_min
#         t_max = self.inputs.t_max
#         is_evoked = self.inputs.is_evoked
#         is_ave = self.inputs.is_ave
#         inv_method = self.inputs.inv_method
#         snr = self.inputs.snr
#         parc = self.inputs.parc
#         aseg = self.inputs.aseg
#         aseg_labels = self.inputs.aseg_labels
#         all_src_space = self.inputs.all_src_space
#         ROIs_mean = self.inputs.ROIs_mean
# 
#         if inv_method != 'LCMV':
#             self.ts_file, self.labels, self.label_names, \
#                 self.label_coords, self.stc_files = \
#                 _compute_inverse_solution(raw_filename, sbj_id, subjects_dir,
#                                           fwd_filename, cov_filename,
#                                           is_epoched=is_epoched,
#                                           events_id=events_id,
#                                           condition=condition, is_ave=is_ave,
#                                           t_min=t_min, t_max=t_max,
#                                           is_evoked=is_evoked, snr=snr,
#                                           inv_method=inv_method, parc=parc,
#                                           aseg=aseg, aseg_labels=aseg_labels,
#                                           all_src_space=all_src_space,
#                                           ROIs_mean=ROIs_mean,
#                                           is_fixed=is_fixed)
#         else:
#             self.ts_file, self.labels, self.label_names, \
#                 self.label_coords = \
#                 _compute_LCMV_inverse_solution(raw_filename, sbj_id,
#                                                subjects_dir,
#                                                fwd_filename, cov_filename,
#                                                parc=parc,
#                                                all_src_space=all_src_space,
#                                                ROIs_mean=ROIs_mean,
#                                                is_fixed=is_fixed)
#             self.stc_files = []
# 
#         return runtime
# 
#     def _list_outputs(self):
# 
#         outputs = self._outputs().get()
# 
#         outputs['ts_file'] = self.ts_file
#         outputs['labels'] = self.labels
#         outputs['label_names'] = self.label_names
#         outputs['label_coords'] = self.label_coords
#         outputs['stc_files'] = self.stc_files
# 
#         return outputs


# Path: ephypype/interfaces/mne/tests/test_Inverse_solution.py
import mne
import pickle
import nipype.pipeline.engine as pe
import numpy as np
import os.path as op
from ephypype.interfaces.mne.Inverse_solution import InverseSolution
from numpy.testing import assert_array_almost_equal

"""Test Inverse_solution Interface."""




data_path = mne.datasets.testing.data_path()
sbj = 'sample'
subjects_dir = op.join(data_path, 'subjects')
raw_fname = op.join(data_path, 'MEG', sbj, 'sample_audvis_trunc_raw.fif')
ave_fname = op.join(data_path, 'MEG', sbj, 'sample_audvis_trunc-ave.fif')
fwd_fname = op.join(data_path, 'MEG', sbj,
                    'sample_audvis_trunc-meg-eeg-oct-6-fwd.fif')
cov_fname = op.join(data_path, 'MEG', sbj, 'sample_audvis_trunc-cov.fif')


def test_mne_inverse_solution():
    """Test compute MNE inverse solution."""


    inverse_node = pe.Node(interface=InverseSolution(), name='inverse')