Note
Go to the end to download the full example code.
GEDAI forward🔗
This tutorial demonstrates how to compute a custom covariance
matrix using a mne.Forward solution.
import mne
from mne.datasets import fetch_fsaverage
from mne.io import read_raw
from gedai.covariance import compute_covariance_from_forward
from gedai.data import get_contaminated_eeg_set_path
Download fsaverage files
fs_dir = fetch_fsaverage(verbose=True)
subjects_dir = fs_dir.parent
# The files live in:
subject = "fsaverage"
trans = "fsaverage" # MNE has a built-in fsaverage transformation
src = fs_dir / "bem" / "fsaverage-ico-5-src.fif"
bem = fs_dir / "bem" / "fsaverage-5120-5120-5120-bem-sol.fif"
0 files missing from root.txt in /home/runner/mne_data/MNE-fsaverage-data
0 files missing from bem.txt in /home/runner/mne_data/MNE-fsaverage-data/fsaverage
Load EEG data
raw = read_raw(str(get_contaminated_eeg_set_path()), preload=True)
Set the EEG electrode locations
raw.set_montage("standard_1005")
Check that the locations of EEG electrodes is correct with respect to MRI
<mne.viz.backends._pyvista.PyVistaFigure object at 0x7f0340294150>
generate the forward solution
compute the covariance matrix from the forward solution
Total running time of the script: (0 minutes 37.811 seconds)
Estimated memory usage: 1109 MB