Interpolate bad channels for MEG/EEG channels#
This example shows how to interpolate bad MEG/EEG channels
Using spherical splines from 1 for EEG data.
Using field interpolation for MEG and EEG data.
In this example, the bad channels will still be marked as bad. Only the data in those channels is replaced.
# Authors: Denis A. Engemann <email@example.com> # Mainak Jas <firstname.lastname@example.org> # # License: BSD-3-Clause
import mne from mne.datasets import sample print(__doc__) data_path = sample.data_path() meg_path = data_path / "MEG" / "sample" fname = meg_path / "sample_audvis-ave.fif" evoked = mne.read_evokeds(fname, condition="Left Auditory", baseline=(None, 0)) # plot with bads evoked.plot(exclude=, picks=("grad", "eeg"))
Reading /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis-ave.fif ... Read a total of 4 projection items: PCA-v1 (1 x 102) active PCA-v2 (1 x 102) active PCA-v3 (1 x 102) active Average EEG reference (1 x 60) active Found the data of interest: t = -199.80 ... 499.49 ms (Left Auditory) 0 CTF compensation matrices available nave = 55 - aspect type = 100 Projections have already been applied. Setting proj attribute to True. Applying baseline correction (mode: mean)
Compute interpolation (also works with Raw and Epochs objects)
Interpolating bad channels Automatic origin fit: head of radius 91.0 mm Computing interpolation matrix from 59 sensor positions Interpolating 1 sensors Computing dot products for 305 MEG channels... Computing cross products for 305 → 1 MEG channel... Preparing the mapping matrix... Truncating at 85/305 components to omit less than 0.0001 (9.4e-05)
You can also use minimum-norm for EEG as well as MEG
Interpolating bad channels Automatic origin fit: head of radius 91.0 mm Computing dot products for 305 MEG channels... Computing cross products for 305 → 1 MEG channel... Preparing the mapping matrix... Truncating at 85/305 components to omit less than 0.0001 (9.4e-05) Computing dot products for 59 EEG channels... Computing cross products for 59 → 60 EEG channels... Preparing the mapping matrix... Truncating at 58/59 components and regularizing with α=1.0e-01 The map has an average electrode reference (60 channels)
Total running time of the script: (0 minutes 15.678 seconds)
Estimated memory usage: 44 MB