Neuroimaging#

Note: You can download this individual file as a Jupyter Notebook (.ipynb) file by clicking the download button at the top.

Exercise 1: Functional connectivity with nilearn#

  1. Get fMRI and confounds data for one participant from the ADHD dataset

  2. Parcellate the fMRI image with the Schäfer 100 atlas and clean in with the corresponding confounds file

  3. Estimate functional connectivity with Pearson correlation (try the nilearn ConnectivityMeasure class)

  4. Plot the connectivity matrix

Useful documentation pages will be:

from nilearn import datasets, plotting
from nilearn.maskers import NiftiLabelsMasker
from nilearn.connectome import ConnectivityMeasure

# 1. Load data
adhd = ...
func = ...
confounds = ...

# 2. Parcellate and clean
atlas = ...
masker = NiftiLabelsMasker(...)
time_series = masker.fit_transform(...)

# 3. Estimate functional connectivity
conn_measure = ...
conn_matrix  = ...

# 4. Plot the connectivity matrix
plotting.plot_matrix(...);

Exercise 2: Plotting ERP waveforms#

For the EEG exercise, we will use data provided in the workshop.

A template for loading data from a single participant is provided below, but you will need to modify the path accordingly. You can use it as is, but any other participant will also work. The data was already cleaned and filtered.

Goal: Plot the condition-average ERP waveforms for condition “S 48” (happiness) and “S 56” (neutral)

Please implement the following steps:

  1. Load the data (already implemented, only needs the correct path)

  2. Define the events

  3. Epoch “S 48” and “S 56” trials

    • Epochs: -0.2 to 0.8 seconds after the stimulus

    • Baseline correction: -0.2 to 0 seconds

    • Epoch rejection: >150 μV

  4. Average the epochs for each condition (already implemented)

  5. Plot the condition-average ERP waveforms for each channel

Useful documentation pages will be:

import mne

# 1. Load data
subject = "21013"
fname = f"<INSERT_PATH>/data/eeg/{subject}_E4/{subject}_E4_postICA_interpolated_fixed.set"
raw = mne.io.read_raw_eeglab(fname, preload=True)

# 2. Define events
event_map = {f"S {i:2d}": i for i in [18, 19, 28, 29, 38, 39, 48, 49, 56, 58, 68, 69, 78, 79]}
events, event_id = mne.events_from_annotations(...)

# 3. Epoch the relevant conditions
conds = {'happiness': event_id['S 48'], 'neutral': event_id['S 56']}
epochs = mne.Epochs(...)

# 4. Compute condition-average ERP waveforms
evokeds = {cond: epochs[cond].average() for cond in conds}

# 5. Plot the ERP waveforms (butterfly + spatial coloring)
for cond, ev in evokeds.items():
    ev.plot(...)