コード例 #1
0
def preproc(l_freq, h_freq, ds_freq):
    """Filter and downsample data."""
    from ephypype.interfaces.mne.preproc import PreprocFif

    preproc_node = pe.Node(interface=PreprocFif(), name='preproc')

    if l_freq:
        preproc_node.inputs.l_freq = l_freq
    if h_freq:
        preproc_node.inputs.h_freq = h_freq

    if ds_freq:
        preproc_node.inputs.down_sfreq = ds_freq

    return preproc_node
コード例 #2
0
ファイル: test_preproc.py プロジェクト: hyruuk/ephypype
def test_preprocess_fif():
    """Test filter and downsample raw data."""

    l_freq = 0.1
    h_freq = 40
    down_sfreq = 250

    # read raw data
    raw = mne.io.read_raw_fif(raw_fname)

    # save short segment of raw data
    segment_raw_fname = raw_fname.replace('raw.fif', '0_60s_raw.fif')
    raw.save(segment_raw_fname, tmin=0, tmax=60, overwrite=True)

    # create PreprocFif node
    preproc_node = pe.Node(interface=PreprocFif(), name='preprocess')
    preproc_node.inputs.fif_file = segment_raw_fname
    preproc_node.inputs.l_freq = l_freq
    preproc_node.inputs.h_freq = h_freq
    preproc_node.inputs.down_sfreq = down_sfreq

    preproc_node.run()

    assert preproc_node.result.outputs.fif_file
コード例 #3
0
ファイル: preproc_meeg.py プロジェクト: EtienneCmb/ephypype
def create_pipeline_preproc_meeg(
        main_path,
        pipeline_name='preproc_meeg',  # noqa
        data_type='fif',
        l_freq=1,
        h_freq=150,
        down_sfreq=300,
        is_ICA=True,
        variance=0.95,
        ECG_ch_name='',
        EoG_ch_name='',
        reject=None,
        is_set_ICA_components=False,
        n_comp_exclude=[],
        is_sensor_space=True):
    """Preprocessing pipeline.

    Parameters
    ----------
    main_path : str
        main path to of the pipeline
    pipeline_name: str (default 'preproc_meeg')
        name of the pipeline
    data_type: str (default 'fif')
        data type: 'fif' or 'ds'
    l_freq: float (default 1)
        low cut-off frequency in Hz
    h_freq: float (default 150)
        high cut-off frequency in Hz
    down_sfreq: float (default 300)
        sampling frequency at which the data are downsampled
    is_ICA : boolean (default True)
        if True apply ICA to automatically remove ECG and EoG artifacts
    variance: float (default 0.95)
        float between 0 and 1: the ICA components will be selected by the
        cumulative percentage of explained variance
    ECG_ch_name: str (default '')
        the name of ECG channels
    EoG_ch_name: str (default '')
        the name of EoG channels
    reject: dict | None
        rejection parameters based on peak-to-peak amplitude. Valid keys
        are 'grad' | 'mag' | 'eeg' | 'eog' | 'ecg'. If reject is None then
        no rejection is done
    is_set_ICA_components: boolean (default False)
        set to True if we had the ICA of the raw data, checked the Report
        and want to exclude some ICA components based on their topographies
        and time series
        if True, we have to fill the dictionary variable n_comp_exclude
    n_comp_exclude: dict
        if is_set_ICA_components=True, it has to be a dict containing for
        each subject and for each session the components to be excluded
    is_sensor_space: boolean (default True)
        True if we perform the analysis in sensor space and we use the
        pipeline as lego with the connectivity or inverse pipeline

    Inputs (inputnode)
    ------------------
    raw_file : str
        path to raw meg data in fif format
    subject_id : str
        subject id

    Outputs
    -------
    pipeline : instance of Workflow
    """
    from ephypype.interfaces.mne.preproc import PreprocFif
    from ephypype.interfaces.mne.preproc import CompIca
    from ephypype.nodes.import_data import ConvertDs2Fif
    from ephypype.preproc import preprocess_set_ica_comp_fif_to_ts
    from nipype.interfaces.utility import IdentityInterface, Function

    import nipype
    print((nipype.__version__))

    import nipype.pipeline.engine as pe

    pipeline = pe.Workflow(name=pipeline_name)
    pipeline.base_dir = main_path

    print(('*** main_path -> %s' % main_path + ' ***'))

    # define the inputs of the pipeline
    inputnode = pe.Node(IdentityInterface(fields=['raw_file', 'subject_id']),
                        name='inputnode')

    if data_type is 'ds':
        ds2fif_node = pe.Node(interface=ConvertDs2Fif(), name='ds2fif')
        pipeline.connect(inputnode, 'raw_file', ds2fif_node, 'ds_file')

    # preprocess
    if not is_set_ICA_components:
        preproc_node = pe.Node(interface=PreprocFif(), name='preproc')

        preproc_node.inputs.l_freq = l_freq
        preproc_node.inputs.h_freq = h_freq
        preproc_node.inputs.down_sfreq = down_sfreq

        if data_type is 'ds':
            pipeline.connect(ds2fif_node, 'fif_file', preproc_node, 'fif_file')
        elif data_type is 'fif':
            pipeline.connect(inputnode, 'raw_file', preproc_node, 'fif_file')

    if is_ICA:
        if is_set_ICA_components:
            inp = [
                'fif_file', 'subject_id', 'n_comp_exclude', 'is_sensor_space'
            ]
            out = [
                'out_file', 'channel_coords_file', 'channel_names_file',
                'sfreq'
            ]
            fcn = preprocess_set_ica_comp_fif_to_ts
            ica_node = pe.Node(interface=Function(input_names=inp,
                                                  output_names=out,
                                                  function=fcn),
                               name='ica_set_comp')

            ica_node.inputs.n_comp_exclude = n_comp_exclude
            ica_node.inputs.is_sensor_space = is_sensor_space

            pipeline.connect(inputnode, 'raw_file', ica_node, 'fif_file')
            pipeline.connect(inputnode, 'subject_id', ica_node, 'subject_id')

        else:

            ica_node = pe.Node(interface=CompIca(), name='ica')
            ica_node.inputs.n_components = variance
            ica_node.inputs.ecg_ch_name = ECG_ch_name
            ica_node.inputs.eog_ch_name = EoG_ch_name

            if reject:
                ica_node.inputs.reject = reject

            pipeline.connect(preproc_node, 'fif_file', ica_node, 'fif_file')

    return pipeline