Mne Bids Pipeline May 2026
# 4. Set average reference (EEG) if 'eeg' in raw: raw.set_eeg_reference('average', projection=False)
t_obs, clusters, p_values, H0 = cluster_stats Use a configuration file (YAML) # config.yaml subjects: ['001', '002', '003'] task: 'visual' preprocessing: l_freq: 0.1 h_freq: 40 notch: 50 epochs: tmin: -0.2 tmax: 0.8 baseline: [-0.2, 0] Python script with argparse import yaml, argparse from mne_bids import BIDSPath, read_raw_bids def main(subject, config): # load config # run pipeline for one subject pass mne bids pipeline
from mne_bids import write_anat write_anat(bids_root, subject='001', t1w_anat='sub-001_T1w.nii.gz') Assuming you have one evoked response per subject per condition: Filter (bandpass) raw
if == ' main ': parser = argparse.ArgumentParser() parser.add_argument('--subject', required=True) parser.add_argument('--config', default='config.yaml') args = parser.parse_args() Filter (bandpass) raw.filter(l_freq
# 3. Interpolate bad channels (defined in BIDS channels.tsv) # MNE automatically reads 'status' column as bad if 'bad' is present. raw.interpolate_bads(reset_bads=True)
import mne def preprocess_raw(raw, l_freq=0.1, h_freq=40, notch=50): """ Apply standard EEG preprocessing. Adjust parameters for MEG (e.g., high-pass 1 Hz, low-pass 100 Hz). """ # 1. Filter (bandpass) raw.filter(l_freq, h_freq, fir_design='firwin', verbose=True)
# Read events from BIDS events, event_id = mne.events_from_annotations(raw_clean) selected_events = ['stimulus/face', 'stimulus/car'] event_id_sel = k: v for k, v in event_id.items() if k in selected_events Create epochs epochs = mne.Epochs( raw_clean, events, event_id=event_id_sel, tmin=-0.2, # 200 ms pre-stimulus tmax=0.8, # 800 ms post-stimulus baseline=(-0.2, 0), reject=dict(eeg=100e-6), # reject epochs with >100 µV peak-to-peak preload=True, ) Drop bad epochs automatically epochs.drop_bad() print(f"Retained len(epochs) / len(epochs.events) epochs") Step 5: Sensor-Level Analysis – Evoked Responses # Compute evoked for each condition evoked_face = epochs['stimulus/face'].average() evoked_car = epochs['stimulus/car'].average() Plot butterfly plot evoked_face.plot_joint(title='Face condition') Difference wave evoked_diff = mne.combine_evoked([evoked_face, evoked_car], weights=[1, -1]) evoked_diff.plot_joint(title='Face - Car')