return raw raw_clean = preprocess_raw(raw) 5. ICA for artifact removal (eye blinks, heartbeats) ica = mne.preprocessing.ICA(n_components=20, random_state=42) ica.fit(raw_clean.copy().filter(1, 30)) # ICA works better on high-passed Identify EOG artifacts eog_indices, eog_scores = ica.find_bads_eog(raw_clean, ch_name='Fp1') ica.exclude = eog_indices raw_clean = ica.apply(raw_clean) Step 4: Epoching and Baseline Correction Events are automatically read from *_events.tsv :
Save source estimates in BIDS derivatives using mne-bids : mne bids pipeline
if == ' main ': parser = argparse.ArgumentParser() parser.add_argument('--subject', required=True) parser.add_argument('--config', default='config.yaml') args = parser.parse_args() return raw raw_clean = preprocess_raw(raw) 5
# 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') heartbeats) ica = mne.preprocessing.ICA(n_components=20
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: