コード例 #1
0
ファイル: test_gather.py プロジェクト: hyruuk/ephypype
def test_get_results():

    pipeline_names = ['connectivity', 'power', 'inverse', 'ica', 'tfr_morlet']

    for name in pipeline_names:
        res = get_results('', '', name)

        assert res
コード例 #2
0
###############################################################################
# Finally, we are now ready to execute our workflow.

main_workflow.config['execution'] = {'remove_unnecessary_outputs': 'false'}

# Run workflow locally on 1 CPU
main_workflow.run(plugin='MultiProc', plugin_args={'n_procs': 1})

###############################################################################
# The output is the preprocessed data stored in the workflow directory
# defined by `base_dir`.
#
# It’s a good rule to inspect the report file saved in the same dir to look at
# the excluded ICA components. It is also possible to include and exclude more
# components by using either a jupyter notebook or the preprocessing pipeline
# with different flag parameters.

###############################################################################
#
import mne  # noqa
from ephypype.gather.gather_results import get_results  # noqa

ica_files, raw_files = get_results(main_workflow.base_dir,
                                   main_workflow.name, pipeline='ica')

for ica_file, raw_file in zip(ica_files, raw_files):
    raw = mne.io.read_raw_fif(raw_file)
    ica = mne.preprocessing.read_ica(ica_file)
    ica.plot_properties(raw, picks=ica.exclude, figsize=[4.5, 4.5])
コード例 #3
0
# **mean PSD in .npy format** stored in the workflow directory defined by
# `base_dir`
#
# .. note:: The power pipeline in the **source space** is implemented by the
#   function :func:`ephypype.pipelines.power.create_pipeline_power_src_space`
#   and its Node :class:`ephypype.interfaces.mne.power.Power` compute the PSD
#   by the welch function of the scipy package.

##############################################################################
from ephypype.gather.gather_results import get_results  # noqa
from visbrain.objects import SourceObj, SceneObj, ColorbarObj  # noqa
from visbrain.utils import normalize  # noqa
from nipype.utils.filemanip import split_filename  # noqa

psd_files, channel_coo_files = get_results(main_workflow.base_dir,
                                           main_workflow.name,
                                           pipeline='power')

sc = SceneObj(size=(1800, 500), bgcolor=(.1, .1, .1))
for psd_file, channel_coo_file in zip(psd_files, channel_coo_files):
    path_xyz, basename, ext = split_filename(psd_file)

    arch = np.load(psd_file)
    psds, freqs = arch['psds'], arch['freqs']
    xyz = np.genfromtxt(channel_coo_file, dtype=float)
    freq_bands = np.asarray(freq_bands)
    clim = (psds.min(), psds.max())

    # Find indices of frequencies :
    idx_fplt = np.abs(
        (freqs.reshape(1, 1, -1) - freq_bands[..., np.newaxis])).argmin(2)
コード例 #4
0
#   <a href="https://github.com/neuropycon/graphpype" target="_blank">graphpype</a>

##############################################################################
from ephypype.gather.gather_results import get_results  # noqa
from ephypype.gather.gather_results import get_channel_files  # noqa
from ephypype.aux_tools import _parse_string  # noqa
from visbrain.objects import ConnectObj, SourceObj, SceneObj, ColorbarObj  # noqa

thresh = .75
with_text = False

channel_coo_files, channel_name_files = get_channel_files(
    main_workflow.base_dir, main_workflow.name)

connectivity_matrices, _ = get_results(main_workflow.base_dir,
                                       main_workflow.name,
                                       pipeline='connectivity')

sc = SceneObj(size=(1000, 1000), bgcolor=(.1, .1, .1))
for nf, (connect_file, channel_coo_file, channel_name_file) in \
        enumerate(zip(connectivity_matrices, channel_coo_files,
                      channel_name_files)):

    # Load files :
    xyz = np.genfromtxt(channel_coo_file, dtype=float)
    names = np.genfromtxt(channel_name_file, dtype=str)
    connect = np.load(connect_file)
    connect += connect.T
    connect = np.ma.masked_array(connect, mask=connect < thresh)
    names = names if with_text else None
    radius = connect.sum(1)
コード例 #5
0
###############################################################################
# The output is the source reconstruction matrix stored in the workflow
# directory defined by `base_dir`. This matrix can be used as input of
# the Connectivity pipeline.
#
# .. warning:: To use this pipeline, we need a cortical segmentation of MRI
#   data, that could be provided by Freesurfer

##############################################################################
import pickle  # noqa
from ephypype.gather.gather_results import get_results  # noqa
from visbrain.objects import BrainObj, ColorbarObj, SceneObj  # noqa

time_series_files, label_files = get_results(main_workflow.base_dir,
                                             main_workflow.name,
                                             pipeline='inverse')

time_pts = 30

sc = SceneObj(size=(800, 500), bgcolor=(0, 0, 0))
lh_file = op.join(subjects_dir, 'fsaverage', 'label/lh.aparc.annot')
rh_file = op.join(subjects_dir, 'fsaverage', 'label/rh.aparc.annot')
cmap = 'bwr'
txtcolor = 'white'
for inverse_file, label_file in zip(time_series_files, label_files):
    # Load files :
    with open(label_file, 'rb') as f:
        ar = pickle.load(f)
        names, xyz, colors = ar['ROI_names'], ar['ROI_coords'], ar[
            'ROI_colors']  # noqa