Skip to content

Instantly share code, notes, and snippets.

@larsoner
Created July 19, 2024 20:19
Show Gist options
  • Save larsoner/42070b8836d131c53fdca1eb7288bc15 to your computer and use it in GitHub Desktop.
Save larsoner/42070b8836d131c53fdca1eb7288bc15 to your computer and use it in GitHub Desktop.
import mne
data_path = mne.datasets.sample.data_path()
sample_data_raw_file = data_path / "MEG" / "sample" / "sample_audvis_raw.fif"
subjects_dir = data_path / "subjects"
raw = mne.io.read_raw_fif(sample_data_raw_file, verbose=False).crop(tmax=60)
events = mne.find_events(raw, stim_channel="STI 014")
epochs = mne.Epochs(raw, events, event_id = {"auditory/left": 1}, tmin=-0.3, tmax=0.7)[:10]
inverse_operator_file = data_path / "MEG" / "sample" / "sample_audvis-meg-oct-6-meg-inv.fif"
inv_operator = mne.minimum_norm.read_inverse_operator(inverse_operator_file)
stcs = mne.minimum_norm.apply_inverse_epochs(epochs, inv_operator, lambda2=1/3, pick_ori=None)
stc_avg_abs = sum(abs(stc) for stc in stcs) / len(stcs)
stc_abs_avg = abs(sum(stc for stc in stcs) / len(stcs))
kwargs = dict(initial_time=0.09, subjects_dir=subjects_dir, clim=dict(kind="value", lims=[1, 2, 4]))
stc_avg_abs.plot(**kwargs, title="Mean of absolute values")
stc_abs_avg.plot(**kwargs, title="Absolute value of the mean")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment