### Install ephypype from source Source: https://neuropycon.github.io/ephypype/_sources/auto_workshop/index.rst.txt Clone the ephypype repository from GitHub and install it in development mode. This is useful for developers or when needing the absolute latest changes. ```bash $ git clone https://github.com/neuropycon/ephypype.git $ cd ephypype $ python setup.py develop ``` -------------------------------- ### Workflow Execution Output Example Source: https://neuropycon.github.io/ephypype/auto_workshop/01_meg/plot_02_events_inverse_stc.html Example output from workflow execution, showing subject IDs, lists of processed files, and generated output file paths. ```text sub-01 sub-01 ['/home/pasca/Science/workshop/PracticalMEEG/ds000117/derivatives/meg_derivatives/preprocessing_dsamp_workflow/preproc_meg_dsamp_pipeline/_session_id_01_subject_id_sub-01/ica/sub-01_ses-meg_task-facerecognition_run-01_proc-sss_meg_filt_dsamp_ica.fif', '/home/pasca/Science/workshop/PracticalMEEG/ds000117/derivatives/meg_derivatives/preprocessing_dsamp_workflow/preproc_meg_dsamp_pipeline/_session_id_02_subject_id_sub-01/ica/sub-01_ses-meg_task-facerecognition_run-02_proc-sss_meg_filt_dsamp_ica.fif'] /home/pasca/Science/workshop/PracticalMEEG/ds000117/derivatives/meg_derivatives/source_dsamp_full_reconstruction_dSPM_aparc/_subject_id_sub-01/concat_event/sub-01_sss_filt_dsamp_ica-raw.fif /home/pasca/Science/workshop/PracticalMEEG/ds000117/derivatives/meg_derivatives/source_dsamp_full_reconstruction_dSPM_aparc/_subject_id_sub-01/concat_event/sub-01_sss_filt_dsamp_ica-raw.fif /home/pasca/Science/workshop/PracticalMEEG/ds000117/derivatives/meg_derivatives/source_dsamp_full_reconstruction_dSPM_aparc/_subject_id_sub-01/concat_event/sub-01_sss_filt_dsamp_ica-raw-eve.fif ``` -------------------------------- ### Install ephypype from PyPI Source: https://neuropycon.github.io/ephypype/_sources/auto_workshop/index.rst.txt Install the ephypype package using pip. This is the recommended method for installing the latest stable version. ```bash $ pip install ephypype ``` -------------------------------- ### Configure and Run Reference Interface Source: https://neuropycon.github.io/ephypype/tutorials/wrap_fieldtrip.html Configures and runs the Reference interface for rereferencing iEEG data. Requires FieldTrip to be installed and its path correctly set. The output file path is printed upon completion. ```python ft_path = '/usr/local/MATLAB/R2018a/toolbox/MEEG/fieldtrip-20200327/' refmethod = 'bipolar' channels_name = '{"RAM*", "RHH*", "RTH*", "ROC*", "LAM*","LHH*", "LTH*"}' reference_if = Reference() reference_if.inputs.data_file = op.join(data_path, 'SubjectUCI29_data.mat') reference_if.inputs.channels = channels_name reference_if.inputs.ft_path = ft_path reference_if.inputs.refmethod = refmethod reference_if.inputs.script = '' out = reference_if.run() print('Rereferenced data saved at {}'.format(out.outputs.data_output)) ``` -------------------------------- ### Create Ephypype Workflow with FieldTrip Reference Node Source: https://neuropycon.github.io/ephypype/_sources/tutorials/wrap_fieldtrip.rst.txt This example shows how to create an Ephypype workflow, encapsulating the FieldTrip Reference interface within a node and connecting it to a data source. This enables the use of the reference node's output as input for subsequent nodes. ```python import os.path as op import nipype.pipeline.engine as pe import ephypype from ephypype.nodes import create_iterator, create_datagrabber from ephypype.nodes.FT_tools import Reference from ephypype.datasets import fetch_ieeg_dataset base_path = op.join(op.dirname(ephypype.__file__), '..', 'examples') data_path = fetch_ieeg_dataset(base_path) ft_path = '/usr/local/MATLAB/R2018a/toolbox/MEEG/fieldtrip-20200327/' updatesens = 'no' refmethod = 'avg' channels_name = '{"LPG*", "LTG*"}' workflow_name = 'workflow' main_workflow = pe.Workflow(name=workflow_name) main_workflow.base_dir = data_path subject_ids = ['SubjectUCI29'] infosource = create_iterator(['subject_id'], [subject_ids]) template_path = '%s*.mat' template_args = [['subject_id']] datasource = create_datagrabber(data_path, template_path, template_args, infields=['subject_id']) main_workflow.connect(infosource, 'subject_id', datasource, 'subject_id') reference_node = pe.Node(interface=Reference(), name='Reference') reference_node.inputs.channels = channels_name reference_node.inputs.ft_path = ft_path reference_node.inputs.updatesens = updatesens reference_node.inputs.refmethod = refmethod reference_node.inputs.script = '' main_workflow.connect(datasource, 'raw_file', reference_node, 'data_file') main_workflow.write_graph(graph2use='colored') # colored main_workflow.config['execution'] = {'remove_unnecessary_outputs': 'false'} # Run workflow locally on 1 CPU main_workflow.run(plugin='MultiProc', plugin_args={'n_procs': 1}) ``` -------------------------------- ### Workflow Graph File Path Source: https://neuropycon.github.io/ephypype/auto_workshop/01_meg/plot_02_events_inverse_stc.html Example output showing the file path where the workflow graph is saved. ```text '/home/pasca/Science/workshop/PracticalMEEG/ds000117/derivatives/meg_derivatives/source_dsamp_full_reconstruction_dSPM_aparc/graph.png' ``` -------------------------------- ### Install ephypype using pip Source: https://neuropycon.github.io/ephypype/_sources/index.rst.txt Installs the ephypype package and jupyter using pip. Ensure MNE python is installed first. ```bash $ pip install ephypype $ pip install jupyter ``` -------------------------------- ### Load and Print Time-Frequency Parameters Source: https://neuropycon.github.io/ephypype/_downloads/9db9cdd4bbb411e68f83d88399605850/run_fieldtrip_wf.ipynb Loads time-frequency analysis parameters from a JSON file and prints them. This step requires the 'params.json' file to be present and correctly formatted. Note that the FieldTrip package must be installed and its path set up for this example to run. ```python import json # noqa import pprint # noqa params = json.load(open("params.json")) pprint.pprint({'time frequency parameters': params["tfr"]}) ft_path = params["tfr"]['fieldtrip_path'] refmethod = params["tfr"]['refmethod'] channels_name = params["tfr"]['channels_name'] ``` -------------------------------- ### Install packages using conda and pip Source: https://neuropycon.github.io/ephypype/_sources/auto_workshop/index.rst.txt Use this command to create a new conda environment with Python 3.10, install packages from a requirements file, and then install jupyter. ```bash $ conda create -n practicalmeeg python=3.10 $ pip install -r requirements.txt $ pip install jupyter ``` -------------------------------- ### Import necessary libraries Source: https://neuropycon.github.io/ephypype/_sources/auto_examples/run_fieldtrip_wf.rst.txt Imports essential libraries for nipype, data handling, and FieldTrip integration. Ensure FieldTrip is installed and its path is correctly set. ```python # Authors: Annalisa Pascarella # License: BSD (3-clause) # sphinx_gallery_thumbnail_number = 2 import os.path as op import numpy as np import nipype.pipeline.engine as pe import ephypype from ephypype.nodes import create_iterator, create_datagrabber from ephypype.nodes import ImportFieldTripEpochs, Reference from ephypype.interfaces import TFRmorlet from ephypype.datasets import fetch_ieeg_dataset ``` -------------------------------- ### Initialize and Configure Main Workflow Source: https://neuropycon.github.io/ephypype/_sources/tutorials/howto.rst.txt Create a main Workflow instance using pe.Workflow and specify the base directory for storing outputs. This sets up the environment for connecting nodes. ```python power_analysis_name = 'power_workflow' main_workflow = pe.Workflow(name=power_analysis_name) main_workflow.base_dir = data_path ``` -------------------------------- ### Fetch iEEG Dataset Source: https://neuropycon.github.io/ephypype/tutorials/wrap_fieldtrip.html Fetches the iEEG dataset and sets up the base path for ephypype examples. Ensure ephypype is installed. ```python import os.path as op import ephypype from ephypype.nodes.FT_tools import Reference from ephypype.datasets import fetch_ieeg_dataset base_path = op.join(op.dirname(ephypype.__file__), '..', 'examples') data_path = fetch_ieeg_dataset(base_path) ``` -------------------------------- ### Sample Folder Layout Source: https://neuropycon.github.io/ephypype/tutorial.html Illustrates a typical MEEG dataset organization with subject subfolders and recording files. ```bash NeuroPyConData ├── K0015 │   ├── ecg_eog_info.pickle │   ├── ec_ipynb_report.html │   ├── eo_ipynb_report.html │   ├── K0015_rest_raw_tsss_mc_trans_ec.fif │   └── K0015_rest_raw_tsss_mc_trans_eo.fif ├── K0025 │   ├── ecg_eog_info.pickle │   ├── ec_ipynb_report.html │   ├── eo_ipynb_report.html │   ├── K0025_rest_raw_tsss_mc_trans_ec.fif │   └── K0025_rest_raw_tsss_mc_trans_eo.fif ├── K0034 │   ├── ecg_eog_info.pickle │   ├── ec_ipynb_report.html │   ├── eo_ipynb_report.html │   ├── K0034_rest_raw_tsss_mc_trans_ec.fif │   └── K0034_rest_raw_tsss_mc_trans_eo.fif ├── R0008 │   ├── ecg_eog_info.pickle │   ├── ec_ipynb_report.html │   ├── eo_ipynb_report.html │   ├── R0008_rest_raw_tsss_mc_trans_ec.fif │   └── R0008_rest_raw_tsss_mc_trans_eo.fif └── R0023 ├── ecg_eog_info.pickle ├── ec_ipynb_report.html ├── eo_ipynb_report.html ├── R0023_rest_raw_tsss_mc_trans_ec.fif └── R0023_rest_raw_tsss_mc_trans_eo.fif 5 directories, 25 files ``` -------------------------------- ### Create Main Workflow and Connect Nodes Source: https://neuropycon.github.io/ephypype/auto_workshop/01_meg/01-run-smri_reconall.html Sets up the main nipype workflow and connects the output of the reconall_workflow to the input of the bem_generation node. ```python freesurfer_workflow_name = 'FS_workflow' main_workflow = pe.Workflow(name=freesurfer_workflow_name) main_workflow.base_dir = subjects_dir main_workflow.connect(reconall_workflow, 'recon_all.subject_id', bem_generation, 'sbj_id') ``` -------------------------------- ### Initializing the main workflow and setting base directory Source: https://neuropycon.github.io/ephypype/auto_examples/plot_preprocessing.html Creates a nipype workflow engine and specifies the base directory for storing output files. This workflow will orchestrate the preprocessing steps. ```python # workflow directory within the `base_dir` preproc_pipeline_name = 'preprocessing_workflow' main_workflow = pe.Workflow(name=preproc_pipeline_name) main_workflow.base_dir = data_path ``` -------------------------------- ### Create Preprocessing Pipeline Source: https://neuropycon.github.io/ephypype/_sources/auto_examples/plot_preprocessing.rst.txt Instantiate the preprocessing pipeline by importing and configuring the `create_pipeline_preproc_meeg` function with relevant parameters. ```python from ephypype.pipelines import create_pipeline_preproc_meeg # noqa preproc_workflow = create_pipeline_preproc_meeg( data_path, l_freq=l_freq, h_freq=h_freq, down_sfreq=down_sfreq, variance=variance, ECG_ch_name=ECG_ch_name, EoG_ch_name=EoG_ch_name, data_type=data_type) ``` -------------------------------- ### Run and Visualize Workflow Source: https://neuropycon.github.io/ephypype/_sources/tutorials/howto.rst.txt This snippet demonstrates how to generate a colored graph of the workflow and then execute it using the MultiProc plugin with 2 processes. It also shows how to configure the workflow to prevent the removal of unnecessary outputs. ```python # run pipeline: main_workflow.write_graph(graph2use='colored') # colored main_workflow.config['execution'] = {'remove_unnecessary_outputs': 'false'} main_workflow.run(plugin='MultiProc', plugin_args={'n_procs': 2}) ``` -------------------------------- ### Run Workflow in Parallel Source: https://neuropycon.github.io/ephypype/tutorial.html Starts a workflow to run in parallel on 4 cores. Use this to configure parallel execution. ```bash $ neuropycon -p MultiProc -n 4 <...> ``` -------------------------------- ### Import necessary libraries Source: https://neuropycon.github.io/ephypype/auto_examples/plot_power.html Imports essential libraries for data manipulation, workflow creation, and fetching datasets. Ensure these are installed before running. ```python # Authors: Annalisa Pascarella # Mainak Jas # License: BSD (3-clause) # sphinx_gallery_thumbnail_number = 2 import os.path as op import numpy as np import nipype.pipeline.engine as pe import ephypype from ephypype.nodes import create_iterator, create_datagrabber from ephypype.datasets import fetch_omega_dataset ``` -------------------------------- ### Basic Pipeline Input Source: https://neuropycon.github.io/ephypype/_sources/tutorial.rst.txt A simple pipeline that takes 'sample1.fif' and 'sample2.fif' as input files. This demonstrates the basic 'input' command usage. ```bash $ neuropycon input sample1.fif sample2.fif ``` -------------------------------- ### Import necessary libraries Source: https://neuropycon.github.io/ephypype/_sources/auto_examples/plot_power.rst.txt Imports essential libraries for data manipulation, pipeline creation, and dataset fetching. Ensure these are installed before running. ```python # Authors: Annalisa Pascarella # Mainak Jas # License: BSD (3-clause) # sphinx_gallery_thumbnail_number = 2 import os.path as op import numpy as np import nipype.pipeline.engine as pe import ephypype from ephypype.nodes import create_iterator, create_datagrabber from ephypype.datasets import fetch_omega_dataset ``` -------------------------------- ### Configure and Run Main Workflow Source: https://neuropycon.github.io/ephypype/_sources/auto_workshop/01_meg/plot_04-preprocessing_inverse.rst.txt Configures the main workflow to prevent removal of unnecessary outputs and then executes the workflow using the LegacyMultiProc plugin. ```python main_workflow.config['execution'] = {'remove_unnecessary_outputs': 'false'} main_workflow.run(plugin='LegacyMultiProc', plugin_args={'n_procs': NJOBS}) ``` -------------------------------- ### Import Core Modules Source: https://neuropycon.github.io/ephypype/_downloads/d5151967f641f12ab39aa60c21fe976a/plot_eeg_preprocessing.ipynb Imports necessary libraries from nipype and ephypype for pipeline creation and data handling. Ensure these libraries are installed. ```python import json import pprint # noqa import os import os.path as op import nipype.pipeline.engine as pe from ephypype.nodes import create_iterator, create_datagrabber from ephypype.pipelines.preproc_meeg import create_pipeline_preproc_meeg from ephypype.datasets import fetch_erpcore_dataset ``` -------------------------------- ### Fetch iEEG dataset and load parameters Source: https://neuropycon.github.io/ephypype/_downloads/3648391fced145e21629be4ddffb42cb/run_fieldtrip_IF.ipynb Fetches a sample iEEG dataset and loads configuration parameters from a 'params.json' file. This step prepares the data and settings required for the rereferencing process. ```python base_path = op.join(op.dirname(ephypype.__file__), '..', 'examples') data_path = fetch_ieeg_dataset(base_path) import json # noqa import pprint # noqa params = json.load(open("params.json")) pprint.pprint({'time frequency parameters': params["tfr"]}) ft_path = params["tfr"]['fieldtrip_path'] refmethod = params["tfr"]['refmethod'] channels_name = params["tfr"]['channels_name'] ``` -------------------------------- ### Create Inverse Solution Workflow Source: https://neuropycon.github.io/ephypype/_sources/auto_examples/plot_inverse.rst.txt Instantiates the inverse solution pipeline by importing the create_pipeline_source_reconstruction function and passing necessary parameters. This sets up the nodes for Lead Field computation, noise covariance, and inverse solution estimation. ```python from ephypype.pipelines import create_pipeline_source_reconstruction # noqa inv_sol_workflow = create_pipeline_source_reconstruction( data_path, subjects_dir, spacing=spacing, inv_method=inv_method, parc=parc, noise_cov_fname=noise_cov_fname) ``` -------------------------------- ### Create a Pipeline Node Source: https://neuropycon.github.io/ephypype/_sources/tutorials/howto.rst.txt Instantiate a pipeline node by calling its creation function, passing necessary parameters and data paths. For example, create_pipeline_power is used here. ```python power_workflow = create_pipeline_power(data_path, freq_bands, fmin=fmin, fmax=fmax, method=power_method, is_epoched=is_epoched) ``` -------------------------------- ### Configure and run the Reference interface Source: https://neuropycon.github.io/ephypype/_downloads/3648391fced145e21629be4ddffb42cb/run_fieldtrip_IF.ipynb Initializes and configures the Ephypype Reference interface to apply a bipolar montage. It sets the input data file, channels, FieldTrip path, and rereferencing method, then executes the interface. ```python # Now we call the interface Reference to apply a bipolar montage to sEEG data reference_if = Reference() reference_if.inputs.data_file = op.join(data_path, 'SubjectUCI29_data.mat') reference_if.inputs.channels = channels_name reference_if.inputs.ft_path = ft_path reference_if.inputs.refmethod = refmethod reference_if.inputs.script = '' out = reference_if.run() print('Rereferenced data saved at {}'.format(out.outputs.data_output)) ``` -------------------------------- ### Run Workflow in Parallel Source: https://neuropycon.github.io/ephypype/_sources/tutorial.rst.txt Starts a workflow to run in parallel on 4 cores. Use the '-p' option for parallel processing and '-n' for the number of CPUs. ```bash $ neuropycon -p MultiProc -n 4 <...> ``` -------------------------------- ### Configure and connect Reference node Source: https://neuropycon.github.io/ephypype/auto_examples/run_fieldtrip_wf.html Initializes a Reference node for rereferencing sEEG data using bipolar montage. It sets input parameters like channel names, FieldTrip path, and reference method, then connects it to the datasource node. ```python reference_node = pe.Node(interface=Reference(), name='rereference') reference_node.inputs.channels = channels_name reference_node.inputs.ft_path = ft_path reference_node.inputs.refmethod = refmethod reference_node.inputs.script = '' # Then we connect the output of datasource node to the input of reference_node main_workflow.connect(datasource, 'raw_file', reference_node, 'data_file') ``` -------------------------------- ### Import necessary modules Source: https://neuropycon.github.io/ephypype/_sources/auto_workshop/01_meg/plot_02_events_inverse_stc.rst.txt Imports required nipype modules and custom ephypype functions for data processing and pipeline creation. Ensure these modules are installed in your environment. ```python import os.path as op import json import pprint # noqa import nipype.pipeline.engine as pe from nipype.interfaces.utility import Function from ephypype.nodes import create_iterator, create_datagrabber from ephypype.pipelines.fif_to_inv_sol import create_pipeline_source_reconstruction # noqa ``` -------------------------------- ### Create Test Files Source: https://neuropycon.github.io/ephypype/_sources/tutorial.rst.txt Creates two empty files named 'sample1.fif' and 'sample2.fif' in the current directory for testing purposes. ```bash $ touch sample1.fif sample2.fif ``` -------------------------------- ### Create Power Pipeline Source: https://neuropycon.github.io/ephypype/_downloads/28c69b982ff953f562e5d4eae4bc3c68/plot_power.ipynb Instantiate the power pipeline node by importing and configuring `create_pipeline_power` with necessary parameters. ```python from ephypype.pipelines import create_pipeline_power # noqa power_workflow = create_pipeline_power(data_path, freq_bands, fmin=fmin, fmax=fmax, method=power_method, is_epoched=is_epoched) ``` -------------------------------- ### Import Core Modules for Ephypype Workflow Source: https://neuropycon.github.io/ephypype/_downloads/50feaf72899c2174bc94bb258fca3e70/plot_ERP.ipynb Imports necessary libraries from nipype and ephypype for building and executing EEG processing pipelines. Ensure these packages are installed. ```python import os import os.path as op import json import pprint # noqa import ephypype import nipype.pipeline.engine as pe from nipype.interfaces.utility import Function from ephypype.nodes import create_iterator, create_datagrabber from ephypype.pipelines.preproc_meeg import create_pipeline_evoked from ephypype.datasets import fetch_erpcore_dataset ``` -------------------------------- ### Get Frequency Band Node Source: https://neuropycon.github.io/ephypype/_modules/ephypype/nodes/utils.html Creates a Nipype node to extract specific frequency bands of interest. This node relies on an internal auxiliary function `_get_freq_band`. ```python from ..aux_tools import _get_freq_band def get_frequency_band(freq_band_names, freq_bands): """Create node to get frequency band of interest. Parameters ---------- freq_band_names : list of str The frequency band names freq_bands : list of list The interval of frequency bands Returns ------- frequency_node : instance of pe.Node The node which recover the frequency band of interest. """ frequency_node = pe.Node(interface=Function( input_names=['freq_band_name', 'freq_band_names', 'freq_bands'], output_names=['freq_bands'], function=_get_freq_band), name='get_frequency_node') frequency_node.inputs.freq_band_names = freq_band_names frequency_node.inputs.freq_bands = freq_bands return frequency_node ``` -------------------------------- ### Initialize workflow and set base directory Source: https://neuropycon.github.io/ephypype/auto_examples/run_fieldtrip_wf.html Creates a nipype workflow named 'time_frequency_analysis' and sets its base directory to the fetched data path. This directory will store the workflow's outputs. ```python workflow_name = 'time_frequency_analysis' main_workflow = pe.Workflow(name=workflow_name) main_workflow.base_dir = data_path ``` -------------------------------- ### Get and Plot TFR Results Source: https://neuropycon.github.io/ephypype/_downloads/9db9cdd4bbb411e68f83d88399605850/run_fieldtrip_wf.ipynb Retrieves computed TFR files from the workflow directory and plots the power spectrum for each using MNE. Ensure MNE and ephypype.gather are imported. ```python import mne # noqa from ephypype.gather import get_results # noqa tfr_files, _ = get_results(main_workflow.base_dir, main_workflow.name, pipeline='tfr_morlet') for tfr_file in tfr_files: power = mne.time_frequency.read_tfrs(tfr_file) power[0].plot([0], baseline=(-.3, -.1), mode='logratio', title=power[0].ch_names[1]) ``` -------------------------------- ### Configuring the data grabber node Source: https://neuropycon.github.io/ephypype/auto_examples/plot_preprocessing.html Sets up a data grabber node to locate and retrieve raw MEG data files. The template path and arguments are configured to match the expected file structure. ```python template_path = '*%s/%s/meg/%s*rest*0_60*raw.fif' template_args = [['subject_id', 'session_id', 'subject_id']] datasource = create_datagrabber(data_path, template_path, template_args) ``` -------------------------------- ### Main Path Configuration Source: https://neuropycon.github.io/ephypype/auto_workshop/01_meg/plot_01_meg_preprocessing.html This snippet shows the main path configuration for the preprocessing pipeline. ```text *** main_path -> /home/pasca/Science/workshop/PracticalMEEG/ds000117/derivatives/meg_derivatives *** ``` -------------------------------- ### Load and Plot Time-Frequency Results Source: https://neuropycon.github.io/ephypype/auto_examples/run_fieldtrip_wf.html Loads time-frequency results from workflow files and plots the power spectral density for visualization. Ensure MNE and ephypype are installed and the workflow has been run. ```python import mne # noqa from ephypype.gather import get_results # noqa tfr_files, _ = get_results(main_workflow.base_dir, main_workflow.name, pipeline='tfr_morlet') for tfr_file in tfr_files: power = mne.time_frequency.read_tfrs(tfr_file) power[0].plot([0], baseline=(-.3, -.1), mode='logratio', title=power[0].ch_names[1]) ``` -------------------------------- ### Import Necessary Libraries for Ephypype Workflow Source: https://neuropycon.github.io/ephypype/_downloads/9db9cdd4bbb411e68f83d88399605850/run_fieldtrip_wf.ipynb Imports essential libraries and modules from nipype, ephypype, and standard Python libraries for building and executing the workflow. Ensure these libraries are installed and accessible. ```python import os.path as op import numpy as np import nipype.pipeline.engine as pe import ephypype from ephypype.nodes import create_iterator, create_datagrabber from ephypype.nodes import ImportFieldTripEpochs, Reference from ephypype.interfaces import TFRmorlet from ephypype.datasets import fetch_ieeg_dataset ``` -------------------------------- ### Import necessary libraries and load parameters Source: https://neuropycon.github.io/ephypype/_downloads/2c191d56a51323e1a46bf19ec940822c/plot_04-preprocessing_inverse.ipynb Imports essential libraries for Nipype, I/O operations, and NeuroPycon pipelines. It also loads experiment parameters from a 'params.json' file and prints them. Ensure 'params.json' is correctly formatted and accessible. ```python # Authors: Annalisa Pascarella # License: BSD (3-clause) # sphinx_gallery_thumbnail_number = 1 import json import pprint # noqa import os.path as op import nipype.pipeline.engine as pe from nipype.interfaces.utility import IdentityInterface, Function import nipype.interfaces.io as nio from ephypype.nodes import create_iterator, create_datagrabber from ephypype.pipelines.preproc_meeg import create_pipeline_preproc_meeg # noqa from ephypype.pipelines.fif_to_inv_sol import create_pipeline_source_reconstruction # noqa # Read experiment params as json params = json.load(open("params.json")) pprint.pprint({'parameters': params}) data_type = params["general"]["data_type"] subject_ids = params["general"]["subject_ids"] NJOBS = params["general"]["NJOBS"] if "data_path" in params["general"].keys(): data_path = params["general"]["data_path"] else: data_path = op.expanduser("~") print("data_path : %s" % data_path) ``` -------------------------------- ### Import necessary libraries for Ephypype connectivity analysis Source: https://neuropycon.github.io/ephypype/_downloads/d3138d01de4953c0b0af80f10da863ea/plot_connectivity.ipynb Imports essential libraries including os.path, numpy, nipype.pipeline.engine, and specific nodes and datasets from Ephypype. This setup is required before proceeding with connectivity computations. ```python # Authors: Annalisa Pascarella # License: BSD (3-clause) # sphinx_gallery_thumbnail_number = 2 import os.path as op import numpy as np import nipype.pipeline.engine as pe import ephypype from ephypype.nodes import create_iterator, create_datagrabber from ephypype.nodes import get_frequency_band from ephypype.datasets import fetch_omega_dataset ``` -------------------------------- ### Initialize Nipype workflow Source: https://neuropycon.github.io/ephypype/_downloads/2c191d56a51323e1a46bf19ec940822c/plot_04-preprocessing_inverse.ipynb Initializes a Nipype workflow named 'preprocessing_full_inverse' and sets its base directory for storing outputs. Ensure the specified `data_path` is accessible and has write permissions. ```python # workflow directory within the `base_dir` wf_name = 'preprocessing_full_inverse' main_workflow = pe.Workflow(name=wf_name) main_workflow.base_dir = data_path ``` -------------------------------- ### Import necessary libraries for preprocessing Source: https://neuropycon.github.io/ephypype/_downloads/156d56be1bfcb6a41fb0295d29f57e92/plot_preprocessing.ipynb Imports nipype, ephypype modules, and utility functions for creating iterator and datagrabber nodes, as well as fetching datasets. This setup is required before defining the preprocessing workflow. ```python # Authors: Annalisa Pascarella # Mainak Jas # License: BSD (3-clause) # sphinx_gallery_thumbnail_number = 2 import os.path as op import nipype.pipeline.engine as pe import ephypype from ephypype.nodes import create_iterator, create_datagrabber from ephypype.datasets import fetch_omega_dataset ``` -------------------------------- ### Import Libraries and Fetch Data Source: https://neuropycon.github.io/ephypype/_downloads/28c69b982ff953f562e5d4eae4bc3c68/plot_power.ipynb Imports necessary libraries and fetches the Omega dataset for analysis. Ensure the base path is correctly set. ```python import os.path as op import numpy as np import nipype.pipeline.engine as pe import ephypype from ephypype.nodes import create_iterator, create_datagrabber from ephypype.datasets import fetch_omega_dataset base_path = op.join(op.dirname(ephypype.__file__), '..', 'examples') data_path = fetch_omega_dataset(base_path) ``` -------------------------------- ### Initialize Nipype Workflow Source: https://neuropycon.github.io/ephypype/_downloads/9db9cdd4bbb411e68f83d88399605850/run_fieldtrip_wf.ipynb Creates a nipype workflow engine instance and sets its base directory for storing outputs. This is a fundamental step in setting up any nipype-based analysis pipeline. ```python workflow_name = 'time_frequency_analysis' main_workflow = pe.Workflow(name=workflow_name) main_workflow.base_dir = data_path ``` -------------------------------- ### Get and Plot ERP Results Source: https://neuropycon.github.io/ephypype/_downloads/50feaf72899c2174bc94bb258fca3e70/plot_ERP.ipynb Retrieves computed evoked potential files using 'get_results' and then plots the Global Field Power (GFP) for different conditions (Faces, Car, Contrast) using MNE-Python. ```python import mne # noqa import matplotlib.pyplot as plt # noqa from ephypype.gather import get_results # noqa evoked_files, _ = get_results(main_workflow.base_dir, main_workflow.name, pipeline='compute_evoked') for evoked_file in evoked_files: print(f'*** {evoked_file} ***\n') ave = mne.read_evokeds(evoked_file) faces, car = ave[0], ave[1] gfp_faces = faces.data.std(axis=0, ddof=0) gfp_car = car.data.std(axis=0, ddof=0) # compare conditions contrast = mne.combine_evoked([faces, car], weights=[1, -1]) gfp_contrast = contrast.data.std(axis=0, ddof=0) # Reproducing the MNE-Python plot style seen above fig, ax = plt.subplots() ax.plot(faces.times, gfp_faces * 1e6, color='blue') ax.plot(car.times, gfp_car * 1e6, color='orange') ax.plot(contrast.times, gfp_contrast * 1e6, color='green') ax.legend(['Faces', 'Car', 'Contrast']) fig.show() ``` -------------------------------- ### Import necessary libraries and fetch data Source: https://neuropycon.github.io/ephypype/_sources/auto_examples/run_fieldtrip_IF.rst.txt Imports required modules from ephypype and standard libraries. Fetches the iEEG dataset and loads parameters from a JSON file. This setup is necessary before applying the FieldTrip interface. ```python # Authors: Annalisa Pascarella # License: BSD (3-clause) import os.path as op import ephypype from ephypype.nodes.FT_tools import Reference from ephypype.datasets import fetch_ieeg_dataset base_path = op.join(op.dirname(ephypype.__file__), '..', 'examples') data_path = fetch_ieeg_dataset(base_path) import json # noqa import pprint # noqa params = json.load(open("params.json")) pprint.pprint({'time frequency parameters': params["tfr"]}) ft_path = params["tfr"]['fieldtrip_path'] refmethod = params["tfr"]['refmethod'] channels_name = params["tfr"]['channels_name'] ``` -------------------------------- ### Create Preprocessing Pipeline Node Source: https://neuropycon.github.io/ephypype/_downloads/d5151967f641f12ab39aa60c21fe976a/plot_eeg_preprocessing.ipynb Instantiate the preprocessing pipeline node by calling `create_pipeline_preproc_meeg`. Pass necessary parameters such as data path, frequency filters, number of components, and channel names. ```python preproc_workflow = create_pipeline_preproc_meeg( data_path, pipeline_name="preproc_eeg_pipeline", l_freq=l_freq, h_freq=h_freq, n_components=n_components, reject=reject, EoG_ch_name=EoG_ch_name, data_type=data_type, montage=montage, bipolar=bipolar, ch_new_names=ch_new_names) ``` -------------------------------- ### Create MEEG Preprocessing Pipeline Source: https://neuropycon.github.io/ephypype/_downloads/156d56be1bfcb6a41fb0295d29f57e92/plot_preprocessing.ipynb Instantiate the MEEG preprocessing pipeline by importing the create_pipeline_preproc_meeg function and passing relevant parameters. ```python from ephypype.pipelines import create_pipeline_preproc_meeg # noqa preproc_workflow = create_pipeline_preproc_meeg( data_path, l_freq=l_freq, h_freq=h_freq, down_sfreq=down_sfreq, variance=variance, ECG_ch_name=ECG_ch_name, EoG_ch_name=EoG_ch_name, data_type=data_type) ``` -------------------------------- ### Fetch and Process iEEG Data with FieldTrip Reference Source: https://neuropycon.github.io/ephypype/_sources/tutorials/wrap_fieldtrip.rst.txt This snippet demonstrates fetching iEEG data and applying a bipolar rereferencing method using the FieldTrip Reference interface. Ensure FieldTrip is installed and its path is correctly set. ```python import os.path as op import ephypype from ephypype.nodes.FT_tools import Reference from ephypype.datasets import fetch_ieeg_dataset base_path = op.join(op.dirname(ephypype.__file__), '..', 'examples') data_path = fetch_ieeg_dataset(base_path) ft_path = '/usr/local/MATLAB/R2018a/toolbox/MEEG/fieldtrip-20200327/' refmethod = 'bipolar' channels_name = '{"RAM*", "RHH*", "RTH*", "ROC*", "LAM*","LHH*", "LTH*"}' reference_if = Reference() reference_if.inputs.data_file = op.join(data_path, 'SubjectUCI29_data.mat') reference_if.inputs.channels = channels_name reference_if.inputs.ft_path = ft_path reference_if.inputs.refmethod = refmethod reference_if.inputs.script = '' out = reference_if.run() print('Rereferenced data saved at {}'.format(out.outputs.data_output)) ``` -------------------------------- ### Visualize and run the workflow Source: https://neuropycon.github.io/ephypype/auto_examples/run_fieldtrip_wf.html Generates a colored graph of the workflow, displays it using matplotlib, and then executes the workflow locally using the MultiProc plugin with 1 processor. It also configures the workflow to not remove unnecessary outputs. ```python main_workflow.write_graph(graph2use='colored') # colored import matplotlib.pyplot as plt # noqa img = plt.imread(op.join(data_path, workflow_name, 'graph.png')) plt.figure(figsize=(6, 6)) plt.imshow(img) plt.axis('off') main_workflow.write_graph(graph2use='colored') # colored main_workflow.config['execution'] = {'remove_unnecessary_outputs': 'false'} # Run workflow locally on 1 CPU main_workflow.run(plugin='MultiProc', plugin_args={'n_procs': 1}) ``` -------------------------------- ### Get and Inspect ICA Results Source: https://neuropycon.github.io/ephypype/_sources/auto_workshop/01_meg/plot_01_meg_preprocessing.rst.txt Retrieves ICA-processed files and raw data files from the workflow directory. It then iterates through these files, reads the raw MEG data and ICA decomposition, and plots the properties of the excluded ICA components. ```python import mne # noqa from ephypype.gather 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): print(f'*** {raw_file} ***') 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]) # ica.plot_components() # ica.plot_sources(raw) ``` -------------------------------- ### Load and Plot ICA Properties Source: https://neuropycon.github.io/ephypype/_downloads/156d56be1bfcb6a41fb0295d29f57e92/plot_preprocessing.ipynb Loads raw data and ICA components using MNE-Python and plots the ICA properties for excluded components. Ensure MNE and Ephypype are installed and the workflow base directory and name are correctly specified. ```python import mne # noqa from ephypype.gather 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]) ``` -------------------------------- ### Display Command Help Source: https://neuropycon.github.io/ephypype/_sources/tutorial.rst.txt Shows the help message for a specific command, detailing its options and arguments. ```bash $ neuropycon ica --help ``` -------------------------------- ### Create ReconAll Workflow Source: https://neuropycon.github.io/ephypype/_downloads/12023be1642091db1234b133c6d54fe8/01-run-smri_reconall.ipynb Sets up the reconall_workflow, specifying its base directory and connecting the infosource, datasource, and recon_all nodes. This workflow handles the initial segmentation of structural data. ```python # reconall_workflow will be a node of the main workflow reconall_workflow_name = 'segmentation_workflow' reconall_workflow = pe.Workflow(name=reconall_workflow_name) reconall_workflow.base_dir = data_path reconall_workflow.connect(infosource, 'subject_id', datasource, 'subject_id') reconall_workflow.connect(infosource, 'subject_id', recon_all, 'subject_id') reconall_workflow.connect(datasource, 'raw_file', recon_all, 'T1_files') ``` -------------------------------- ### Import Libraries and Fetch Data Source: https://neuropycon.github.io/ephypype/_downloads/1a926fb439cbc5d0c73fd5013ba067ba/plot_inverse_LCMV.ipynb Imports necessary libraries and fetches the omega dataset. This is a prerequisite for running the source reconstruction pipeline. ```python # Authors: Annalisa Pascarella # License: BSD (3-clause) # sphinx_gallery_thumbnail_number = 2 import os.path as op import numpy as np import nipype.pipeline.engine as pe import nipype.interfaces.io as nio import ephypype from ephypype.nodes import create_iterator from ephypype.datasets import fetch_omega_dataset data_type = 'fif' base_path = op.join(op.dirname(ephypype.__file__), '..', 'examples') data_path = fetch_omega_dataset(base_path) ``` -------------------------------- ### Initialize Nipype Workflow Source: https://neuropycon.github.io/ephypype/_downloads/28c69b982ff953f562e5d4eae4bc3c68/plot_power.ipynb Creates a Nipype workflow and sets its base directory for storing outputs. The workflow name is specified for organization. ```python # workflow directory within the `base_dir` power_analysis_name = 'power_workflow' main_workflow = pe.Workflow(name=power_analysis_name) main_workflow.base_dir = data_path ```