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")
General
Filename(s) SNR=0.35481 contamination=25 clean_EEG_dataset_2.set + EOG_EMG_NOISE_dataset_1.set
MNE object type RawEEGLAB
Measurement date Unknown
Participant Unknown
Experimenter Unknown
Acquisition
Duration 00:01:00 (HH:MM:SS)
Sampling frequency 200.00 Hz
Time points 12,000
Channels
EEG
Head & sensor digitization 30 points
Filters
Highpass 0.00 Hz
Lowpass 100.00 Hz


Check that the locations of EEG electrodes is correct with respect to MRI

mne.viz.plot_alignment(
    raw.info,
    src=src,
    eeg=["projected"],
    trans=trans,
    show_axes=True,
    mri_fiducials=True,
    dig="fiducials",
)
<mne.viz.backends._pyvista.PyVistaFigure object at 0x7f0340294150>

generate the forward solution

fwd = mne.make_forward_solution(
    raw.info, trans=trans, src=src, bem=bem, eeg=True, mindist=5.0, n_jobs=None
)

compute the covariance matrix from the forward solution

Total running time of the script: (0 minutes 37.811 seconds)

Estimated memory usage: 1109 MB

Gallery generated by Sphinx-Gallery