Skip to content

Instantly share code, notes, and snippets.

@wmvanvliet
Created February 12, 2020 16:22
Show Gist options
  • Save wmvanvliet/db1a5c615f90b03053e4150c8c7ca19b to your computer and use it in GitHub Desktop.
Save wmvanvliet/db1a5c615f90b03053e4150c8c7ca19b to your computer and use it in GitHub Desktop.
Performing MEG source estimation without an MRI, using the 'fsaverage' template MRI instead
import mne
# MEG data we take from the MNE-Sample dataset
data_path = mne.datasets.sample.data_path()
subjects_dir = f'{data_path}/subjects'
evoked = mne.read_evokeds(f'{data_path}/MEG/sample/sample_audvis-ave.fif', condition='Left Auditory').apply_baseline()
noise_cov = mne.read_cov(f'{data_path}/MEG/sample/sample_audvis-cov.fif')
# MRI data we will take from the 'fsaverage' template brain
fs_dir = mne.datasets.fetch_fsaverage(verbose=True) # Download the files
src = mne.read_source_spaces(f'{fs_dir}/bem/fsaverage-ico-5-src.fif')
trans = mne.read_trans(f'{fs_dir}/bem/fsaverage-trans.fif')
# We'll use a spherical head model instead of a BEM, because the MRI doesn't match the subject anyway
bem = mne.make_sphere_model(r0='auto', head_radius='auto', info=evoked.info)
# Perform the source estimation
fwd = mne.make_forward_solution(evoked.info, trans=trans, src=src, bem=bem, meg=True, eeg=False, mindist=5, n_jobs=4)
inv = mne.minimum_norm.make_inverse_operator(evoked.info, fwd, noise_cov)
stc = mne.minimum_norm.apply_inverse(evoked, inv)
# Plot the result
peak_time = stc.get_peak()[1]
stc.plot(subjects_dir=subjects_dir, initial_time=peak_time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment