Note
Click here to download the full example code
This example demonstrates how to use autoreject
to automatically
repair epochs.
# Author: Mainak Jas <mainak.jas@telecom-paristech.fr>
# Denis A. Engemann <denis.engemann@gmail.com>
# License: BSD (3-clause)
Let us first define the parameters. n_interpolates are the \(\rho\)
values that we would like autoreject
to try and consensus_percs
are the \(\kappa\) values that autoreject
will try (see the
autoreject paper) for
more information on these parameters).
Epochs with more than \(\kappa * N\) sensors (\(N\) total sensors) bad are dropped. For the rest of the epochs, the worst \(\rho\) bad sensors (as determined by channel-level thresholds) are interpolated. The exact values of these parameters are not preselected but learned from the data. If the number of bad sensors for a particular trial is less than \(\rho\), all the bad sensors are interpolated.
import numpy as np
n_interpolates = np.array([1, 4, 32])
consensus_percs = np.linspace(0, 1.0, 11)
For the purposes of this example, we shall use the MNE sample dataset. Therefore, let us make some MNE related imports.
import mne # noqa
from mne.utils import check_random_state # noqa
from mne.datasets import sample # noqa
Now, we can import the class required for rejecting and repairing bad
epochs. autoreject.compute_thresholds()
is a callable which must be
provided to the autoreject.AutoReject
class for computing
the channel-level thresholds.
from autoreject import (AutoReject, set_matplotlib_defaults) # noqa
Let us now read in the raw fif file for MNE sample dataset.
check_random_state(42)
data_path = sample.data_path()
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
raw = mne.io.read_raw_fif(raw_fname, preload=True)
Out:
Opening raw data file /Users/mainak/mne_data/MNE-sample-data/MEG/sample/sample_audvis_filt-0-40_raw.fif...
Read a total of 4 projection items:
PCA-v1 (1 x 102) idle
PCA-v2 (1 x 102) idle
PCA-v3 (1 x 102) idle
Average EEG reference (1 x 60) idle
Range : 6450 ... 48149 = 42.956 ... 320.665 secs
Ready.
Current compensation grade : 0
Reading 0 ... 41699 = 0.000 ... 277.709 secs...
We can then read in the events
event_fname = data_path + ('/MEG/sample/sample_audvis_filt-0-40_raw-'
'eve.fif')
event_id = {'Auditory/Left': 1, 'Auditory/Right': 2}
tmin, tmax = -0.2, 0.5
events = mne.read_events(event_fname)
And pick MEG channels for repairing. Currently, autoreject
can repair
only one channel type at a time.
raw.info['bads'] = []
picks = mne.pick_types(raw.info, meg='grad', eeg=False, stim=False, eog=False,
include=[], exclude=[])
Now, we can create epochs. The reject
params will be set to None
because we do not want epochs to be dropped when instantiating
mne.Epochs
.
raw.info['projs'] = list() # remove proj, don't proj while interpolating
epochs = mne.Epochs(raw, events, event_id, tmin, tmax,
baseline=(None, 0), reject=None,
verbose=False, detrend=0, preload=True)
autoreject.AutoReject
internally does cross-validation to
determine the optimal values \(\rho^{*}\) and \(\kappa^{*}\)
Note that autoreject.AutoReject
by design supports
multiple channels.
If no picks are passed, separate solutions will be computed for each channel
type and internally combined. This then readily supports cleaning
unseen epochs from the different channel types used during fit.
Here we only use a subset of channels to save time.
ar = AutoReject(n_interpolates, consensus_percs, picks=picks,
thresh_method='random_search', random_state=42)
# Note that fitting and transforming can be done on different compatible
# portions of data if needed.
ar.fit(epochs['Auditory/Left'])
epochs_clean = ar.transform(epochs['Auditory/Left'])
evoked_clean = epochs_clean.average()
evoked = epochs['Auditory/Left'].average()
Out:
86 coil definitions read
Running autoreject on ch_type=grad
[ ] 0.00% Creating augmented epochs |
[ ] 0.49% Creating augmented epochs /
[ ] 0.98% Creating augmented epochs -
[ ] 1.47% Creating augmented epochs \
[ ] 1.96% Creating augmented epochs |
[ ] 2.45% Creating augmented epochs /
[. ] 2.94% Creating augmented epochs -
[. ] 3.43% Creating augmented epochs \
[. ] 3.92% Creating augmented epochs |
[. ] 4.41% Creating augmented epochs /
[. ] 4.90% Creating augmented epochs -
[.. ] 5.39% Creating augmented epochs \
[.. ] 5.88% Creating augmented epochs |
[.. ] 6.37% Creating augmented epochs /
[.. ] 6.86% Creating augmented epochs -
[.. ] 7.35% Creating augmented epochs \
[... ] 7.84% Creating augmented epochs |
[... ] 8.33% Creating augmented epochs /
[... ] 8.82% Creating augmented epochs -
[... ] 9.31% Creating augmented epochs \
[... ] 9.80% Creating augmented epochs |
[.... ] 10.29% Creating augmented epochs /
[.... ] 10.78% Creating augmented epochs -
[.... ] 11.27% Creating augmented epochs \
[.... ] 11.76% Creating augmented epochs |
[.... ] 12.25% Creating augmented epochs /
[..... ] 12.75% Creating augmented epochs -
[..... ] 13.24% Creating augmented epochs \
[..... ] 13.73% Creating augmented epochs |
[..... ] 14.22% Creating augmented epochs /
[..... ] 14.71% Creating augmented epochs -
[...... ] 15.20% Creating augmented epochs \
[...... ] 15.69% Creating augmented epochs |
[...... ] 16.18% Creating augmented epochs /
[...... ] 16.67% Creating augmented epochs -
[...... ] 17.16% Creating augmented epochs \
[....... ] 17.65% Creating augmented epochs |
[....... ] 18.14% Creating augmented epochs /
[....... ] 18.63% Creating augmented epochs -
[....... ] 19.12% Creating augmented epochs \
[....... ] 19.61% Creating augmented epochs |
[........ ] 20.10% Creating augmented epochs /
[........ ] 20.59% Creating augmented epochs -
[........ ] 21.08% Creating augmented epochs \
[........ ] 21.57% Creating augmented epochs |
[........ ] 22.06% Creating augmented epochs /
[......... ] 22.55% Creating augmented epochs -
[......... ] 23.04% Creating augmented epochs \
[......... ] 23.53% Creating augmented epochs |
[......... ] 24.02% Creating augmented epochs /
[......... ] 24.51% Creating augmented epochs -
[.......... ] 25.00% Creating augmented epochs \
[.......... ] 25.49% Creating augmented epochs |
[.......... ] 25.98% Creating augmented epochs /
[.......... ] 26.47% Creating augmented epochs -
[.......... ] 26.96% Creating augmented epochs \
[.......... ] 27.45% Creating augmented epochs |
[........... ] 27.94% Creating augmented epochs /
[........... ] 28.43% Creating augmented epochs -
[........... ] 28.92% Creating augmented epochs \
[........... ] 29.41% Creating augmented epochs |
[........... ] 29.90% Creating augmented epochs /
[............ ] 30.39% Creating augmented epochs -
[............ ] 30.88% Creating augmented epochs \
[............ ] 31.37% Creating augmented epochs |
[............ ] 31.86% Creating augmented epochs /
[............ ] 32.35% Creating augmented epochs -
[............. ] 32.84% Creating augmented epochs \
[............. ] 33.33% Creating augmented epochs |
[............. ] 33.82% Creating augmented epochs /
[............. ] 34.31% Creating augmented epochs -
[............. ] 34.80% Creating augmented epochs \
[.............. ] 35.29% Creating augmented epochs |
[.............. ] 35.78% Creating augmented epochs /
[.............. ] 36.27% Creating augmented epochs -
[.............. ] 36.76% Creating augmented epochs \
[.............. ] 37.25% Creating augmented epochs |
[............... ] 37.75% Creating augmented epochs /
[............... ] 38.24% Creating augmented epochs -
[............... ] 38.73% Creating augmented epochs \
[............... ] 39.22% Creating augmented epochs |
[............... ] 39.71% Creating augmented epochs /
[................ ] 40.20% Creating augmented epochs -
[................ ] 40.69% Creating augmented epochs \
[................ ] 41.18% Creating augmented epochs |
[................ ] 41.67% Creating augmented epochs /
[................ ] 42.16% Creating augmented epochs -
[................. ] 42.65% Creating augmented epochs \
[................. ] 43.14% Creating augmented epochs |
[................. ] 43.63% Creating augmented epochs /
[................. ] 44.12% Creating augmented epochs -
[................. ] 44.61% Creating augmented epochs \
[.................. ] 45.10% Creating augmented epochs |
[.................. ] 45.59% Creating augmented epochs /
[.................. ] 46.08% Creating augmented epochs -
[.................. ] 46.57% Creating augmented epochs \
[.................. ] 47.06% Creating augmented epochs |
[................... ] 47.55% Creating augmented epochs /
[................... ] 48.04% Creating augmented epochs -
[................... ] 48.53% Creating augmented epochs \
[................... ] 49.02% Creating augmented epochs |
[................... ] 49.51% Creating augmented epochs /
[.................... ] 50.00% Creating augmented epochs -
[.................... ] 50.49% Creating augmented epochs \
[.................... ] 50.98% Creating augmented epochs |
[.................... ] 51.47% Creating augmented epochs /
[.................... ] 51.96% Creating augmented epochs -
[.................... ] 52.45% Creating augmented epochs \
[..................... ] 52.94% Creating augmented epochs |
[..................... ] 53.43% Creating augmented epochs /
[..................... ] 53.92% Creating augmented epochs -
[..................... ] 54.41% Creating augmented epochs \
[..................... ] 54.90% Creating augmented epochs |
[...................... ] 55.39% Creating augmented epochs /
[...................... ] 55.88% Creating augmented epochs -
[...................... ] 56.37% Creating augmented epochs \
[...................... ] 56.86% Creating augmented epochs |
[...................... ] 57.35% Creating augmented epochs /
[....................... ] 57.84% Creating augmented epochs -
[....................... ] 58.33% Creating augmented epochs \
[....................... ] 58.82% Creating augmented epochs |
[....................... ] 59.31% Creating augmented epochs /
[....................... ] 59.80% Creating augmented epochs -
[........................ ] 60.29% Creating augmented epochs \
[........................ ] 60.78% Creating augmented epochs |
[........................ ] 61.27% Creating augmented epochs /
[........................ ] 61.76% Creating augmented epochs -
[........................ ] 62.25% Creating augmented epochs \
[......................... ] 62.75% Creating augmented epochs |
[......................... ] 63.24% Creating augmented epochs /
[......................... ] 63.73% Creating augmented epochs -
[......................... ] 64.22% Creating augmented epochs \
[......................... ] 64.71% Creating augmented epochs |
[.......................... ] 65.20% Creating augmented epochs /
[.......................... ] 65.69% Creating augmented epochs -
[.......................... ] 66.18% Creating augmented epochs \
[.......................... ] 66.67% Creating augmented epochs |
[.......................... ] 67.16% Creating augmented epochs /
[........................... ] 67.65% Creating augmented epochs -
[........................... ] 68.14% Creating augmented epochs \
[........................... ] 68.63% Creating augmented epochs |
[........................... ] 69.12% Creating augmented epochs /
[........................... ] 69.61% Creating augmented epochs -
[............................ ] 70.10% Creating augmented epochs \
[............................ ] 70.59% Creating augmented epochs |
[............................ ] 71.08% Creating augmented epochs /
[............................ ] 71.57% Creating augmented epochs -
[............................ ] 72.06% Creating augmented epochs \
[............................. ] 72.55% Creating augmented epochs |
[............................. ] 73.04% Creating augmented epochs /
[............................. ] 73.53% Creating augmented epochs -
[............................. ] 74.02% Creating augmented epochs \
[............................. ] 74.51% Creating augmented epochs |
[.............................. ] 75.00% Creating augmented epochs /
[.............................. ] 75.49% Creating augmented epochs -
[.............................. ] 75.98% Creating augmented epochs \
[.............................. ] 76.47% Creating augmented epochs |
[.............................. ] 76.96% Creating augmented epochs /
[.............................. ] 77.45% Creating augmented epochs -
[............................... ] 77.94% Creating augmented epochs \
[............................... ] 78.43% Creating augmented epochs |
[............................... ] 78.92% Creating augmented epochs /
[............................... ] 79.41% Creating augmented epochs -
[............................... ] 79.90% Creating augmented epochs \
[................................ ] 80.39% Creating augmented epochs |
[................................ ] 80.88% Creating augmented epochs /
[................................ ] 81.37% Creating augmented epochs -
[................................ ] 81.86% Creating augmented epochs \
[................................ ] 82.35% Creating augmented epochs |
[................................. ] 82.84% Creating augmented epochs /
[................................. ] 83.33% Creating augmented epochs -
[................................. ] 83.82% Creating augmented epochs \
[................................. ] 84.31% Creating augmented epochs |
[................................. ] 84.80% Creating augmented epochs /
[.................................. ] 85.29% Creating augmented epochs -
[.................................. ] 85.78% Creating augmented epochs \
[.................................. ] 86.27% Creating augmented epochs |
[.................................. ] 86.76% Creating augmented epochs /
[.................................. ] 87.25% Creating augmented epochs -
[................................... ] 87.75% Creating augmented epochs \
[................................... ] 88.24% Creating augmented epochs |
[................................... ] 88.73% Creating augmented epochs /
[................................... ] 89.22% Creating augmented epochs -
[................................... ] 89.71% Creating augmented epochs \
[.................................... ] 90.20% Creating augmented epochs |
[.................................... ] 90.69% Creating augmented epochs /
[.................................... ] 91.18% Creating augmented epochs -
[.................................... ] 91.67% Creating augmented epochs \
[.................................... ] 92.16% Creating augmented epochs |
[..................................... ] 92.65% Creating augmented epochs /
[..................................... ] 93.14% Creating augmented epochs -
[..................................... ] 93.63% Creating augmented epochs \
[..................................... ] 94.12% Creating augmented epochs |
[..................................... ] 94.61% Creating augmented epochs /
[...................................... ] 95.10% Creating augmented epochs -
[...................................... ] 95.59% Creating augmented epochs \
[...................................... ] 96.08% Creating augmented epochs |
[...................................... ] 96.57% Creating augmented epochs /
[...................................... ] 97.06% Creating augmented epochs -
[....................................... ] 97.55% Creating augmented epochs \
[....................................... ] 98.04% Creating augmented epochs |
[....................................... ] 98.53% Creating augmented epochs /
[....................................... ] 99.02% Creating augmented epochs -
[....................................... ] 99.51% Creating augmented epochs \
[........................................] 100.00% Creating augmented epochs |
[ ] 0.00% Computing thresholds ... |
[ ] 0.49% Computing thresholds ... /
[ ] 0.98% Computing thresholds ... -
[ ] 1.47% Computing thresholds ... \
[ ] 1.96% Computing thresholds ... |
[ ] 2.45% Computing thresholds ... /
[. ] 2.94% Computing thresholds ... -
[. ] 3.43% Computing thresholds ... \
[. ] 3.92% Computing thresholds ... |
[. ] 4.41% Computing thresholds ... /
[. ] 4.90% Computing thresholds ... -
[.. ] 5.39% Computing thresholds ... \
[.. ] 5.88% Computing thresholds ... |
[.. ] 6.37% Computing thresholds ... /
[.. ] 6.86% Computing thresholds ... -
[.. ] 7.35% Computing thresholds ... \
[... ] 7.84% Computing thresholds ... |
[... ] 8.33% Computing thresholds ... /
[... ] 8.82% Computing thresholds ... -
[... ] 9.31% Computing thresholds ... \
[... ] 9.80% Computing thresholds ... |
[.... ] 10.29% Computing thresholds ... /
[.... ] 10.78% Computing thresholds ... -
[.... ] 11.27% Computing thresholds ... \
[.... ] 11.76% Computing thresholds ... |
[.... ] 12.25% Computing thresholds ... /
[..... ] 12.75% Computing thresholds ... -
[..... ] 13.24% Computing thresholds ... \
[..... ] 13.73% Computing thresholds ... |
[..... ] 14.22% Computing thresholds ... /
[..... ] 14.71% Computing thresholds ... -
[...... ] 15.20% Computing thresholds ... \
[...... ] 15.69% Computing thresholds ... |
[...... ] 16.18% Computing thresholds ... /
[...... ] 16.67% Computing thresholds ... -
[...... ] 17.16% Computing thresholds ... \
[....... ] 17.65% Computing thresholds ... |
[....... ] 18.14% Computing thresholds ... /
[....... ] 18.63% Computing thresholds ... -
[....... ] 19.12% Computing thresholds ... \
[....... ] 19.61% Computing thresholds ... |
[........ ] 20.10% Computing thresholds ... /
[........ ] 20.59% Computing thresholds ... -
[........ ] 21.08% Computing thresholds ... \
[........ ] 21.57% Computing thresholds ... |
[........ ] 22.06% Computing thresholds ... /
[......... ] 22.55% Computing thresholds ... -
[......... ] 23.04% Computing thresholds ... \
[......... ] 23.53% Computing thresholds ... |
[......... ] 24.02% Computing thresholds ... /
[......... ] 24.51% Computing thresholds ... -
[.......... ] 25.00% Computing thresholds ... \
[.......... ] 25.49% Computing thresholds ... |
[.......... ] 25.98% Computing thresholds ... /
[.......... ] 26.47% Computing thresholds ... -
[.......... ] 26.96% Computing thresholds ... \
[.......... ] 27.45% Computing thresholds ... |
[........... ] 27.94% Computing thresholds ... /
[........... ] 28.43% Computing thresholds ... -
[........... ] 28.92% Computing thresholds ... \
[........... ] 29.41% Computing thresholds ... |
[........... ] 29.90% Computing thresholds ... /
[............ ] 30.39% Computing thresholds ... -
[............ ] 30.88% Computing thresholds ... \
[............ ] 31.37% Computing thresholds ... |
[............ ] 31.86% Computing thresholds ... /
[............ ] 32.35% Computing thresholds ... -
[............. ] 32.84% Computing thresholds ... \
[............. ] 33.33% Computing thresholds ... |
[............. ] 33.82% Computing thresholds ... /
[............. ] 34.31% Computing thresholds ... -
[............. ] 34.80% Computing thresholds ... \
[.............. ] 35.29% Computing thresholds ... |
[.............. ] 35.78% Computing thresholds ... /
[.............. ] 36.27% Computing thresholds ... -
[.............. ] 36.76% Computing thresholds ... \
[.............. ] 37.25% Computing thresholds ... |
[............... ] 37.75% Computing thresholds ... /
[............... ] 38.24% Computing thresholds ... -
[............... ] 38.73% Computing thresholds ... \
[............... ] 39.22% Computing thresholds ... |
[............... ] 39.71% Computing thresholds ... /
[................ ] 40.20% Computing thresholds ... -
[................ ] 40.69% Computing thresholds ... \
[................ ] 41.18% Computing thresholds ... |
[................ ] 41.67% Computing thresholds ... /
[................ ] 42.16% Computing thresholds ... -
[................. ] 42.65% Computing thresholds ... \
[................. ] 43.14% Computing thresholds ... |
[................. ] 43.63% Computing thresholds ... /
[................. ] 44.12% Computing thresholds ... -
[................. ] 44.61% Computing thresholds ... \
[.................. ] 45.10% Computing thresholds ... |
[.................. ] 45.59% Computing thresholds ... /
[.................. ] 46.08% Computing thresholds ... -
[.................. ] 46.57% Computing thresholds ... \
[.................. ] 47.06% Computing thresholds ... |
[................... ] 47.55% Computing thresholds ... /
[................... ] 48.04% Computing thresholds ... -
[................... ] 48.53% Computing thresholds ... \
[................... ] 49.02% Computing thresholds ... |
[................... ] 49.51% Computing thresholds ... /
[.................... ] 50.00% Computing thresholds ... -
[.................... ] 50.49% Computing thresholds ... \
[.................... ] 50.98% Computing thresholds ... |
[.................... ] 51.47% Computing thresholds ... /
[.................... ] 51.96% Computing thresholds ... -
[.................... ] 52.45% Computing thresholds ... \
[..................... ] 52.94% Computing thresholds ... |
[..................... ] 53.43% Computing thresholds ... /
[..................... ] 53.92% Computing thresholds ... -
[..................... ] 54.41% Computing thresholds ... \
[..................... ] 54.90% Computing thresholds ... |
[...................... ] 55.39% Computing thresholds ... /
[...................... ] 55.88% Computing thresholds ... -
[...................... ] 56.37% Computing thresholds ... \
[...................... ] 56.86% Computing thresholds ... |
[...................... ] 57.35% Computing thresholds ... /
[....................... ] 57.84% Computing thresholds ... -
[....................... ] 58.33% Computing thresholds ... \
[....................... ] 58.82% Computing thresholds ... |
[....................... ] 59.31% Computing thresholds ... /
[....................... ] 59.80% Computing thresholds ... -
[........................ ] 60.29% Computing thresholds ... \
[........................ ] 60.78% Computing thresholds ... |
[........................ ] 61.27% Computing thresholds ... /
[........................ ] 61.76% Computing thresholds ... -
[........................ ] 62.25% Computing thresholds ... \
[......................... ] 62.75% Computing thresholds ... |
[......................... ] 63.24% Computing thresholds ... /
[......................... ] 63.73% Computing thresholds ... -
[......................... ] 64.22% Computing thresholds ... \
[......................... ] 64.71% Computing thresholds ... |
[.......................... ] 65.20% Computing thresholds ... /
[.......................... ] 65.69% Computing thresholds ... -
[.......................... ] 66.18% Computing thresholds ... \
[.......................... ] 66.67% Computing thresholds ... |
[.......................... ] 67.16% Computing thresholds ... /
[........................... ] 67.65% Computing thresholds ... -
[........................... ] 68.14% Computing thresholds ... \
[........................... ] 68.63% Computing thresholds ... |
[........................... ] 69.12% Computing thresholds ... /
[........................... ] 69.61% Computing thresholds ... -
[............................ ] 70.10% Computing thresholds ... \
[............................ ] 70.59% Computing thresholds ... |
[............................ ] 71.08% Computing thresholds ... /
[............................ ] 71.57% Computing thresholds ... -
[............................ ] 72.06% Computing thresholds ... \
[............................. ] 72.55% Computing thresholds ... |
[............................. ] 73.04% Computing thresholds ... /
[............................. ] 73.53% Computing thresholds ... -
[............................. ] 74.02% Computing thresholds ... \
[............................. ] 74.51% Computing thresholds ... |
[.............................. ] 75.00% Computing thresholds ... /
[.............................. ] 75.49% Computing thresholds ... -
[.............................. ] 75.98% Computing thresholds ... \
[.............................. ] 76.47% Computing thresholds ... |
[.............................. ] 76.96% Computing thresholds ... /
[.............................. ] 77.45% Computing thresholds ... -
[............................... ] 77.94% Computing thresholds ... \
[............................... ] 78.43% Computing thresholds ... |
[............................... ] 78.92% Computing thresholds ... /
[............................... ] 79.41% Computing thresholds ... -
[............................... ] 79.90% Computing thresholds ... \
[................................ ] 80.39% Computing thresholds ... |
[................................ ] 80.88% Computing thresholds ... /
[................................ ] 81.37% Computing thresholds ... -
[................................ ] 81.86% Computing thresholds ... \
[................................ ] 82.35% Computing thresholds ... |
[................................. ] 82.84% Computing thresholds ... /
[................................. ] 83.33% Computing thresholds ... -
[................................. ] 83.82% Computing thresholds ... \
[................................. ] 84.31% Computing thresholds ... |
[................................. ] 84.80% Computing thresholds ... /
[.................................. ] 85.29% Computing thresholds ... -
[.................................. ] 85.78% Computing thresholds ... \
[.................................. ] 86.27% Computing thresholds ... |
[.................................. ] 86.76% Computing thresholds ... /
[.................................. ] 87.25% Computing thresholds ... -
[................................... ] 87.75% Computing thresholds ... \
[................................... ] 88.24% Computing thresholds ... |
[................................... ] 88.73% Computing thresholds ... /
[................................... ] 89.22% Computing thresholds ... -
[................................... ] 89.71% Computing thresholds ... \
[.................................... ] 90.20% Computing thresholds ... |
[.................................... ] 90.69% Computing thresholds ... /
[.................................... ] 91.18% Computing thresholds ... -
[.................................... ] 91.67% Computing thresholds ... \
[.................................... ] 92.16% Computing thresholds ... |
[..................................... ] 92.65% Computing thresholds ... /
[..................................... ] 93.14% Computing thresholds ... -
[..................................... ] 93.63% Computing thresholds ... \
[..................................... ] 94.12% Computing thresholds ... |
[..................................... ] 94.61% Computing thresholds ... /
[...................................... ] 95.10% Computing thresholds ... -
[...................................... ] 95.59% Computing thresholds ... \
[...................................... ] 96.08% Computing thresholds ... |
[...................................... ] 96.57% Computing thresholds ... /
[...................................... ] 97.06% Computing thresholds ... -
[....................................... ] 97.55% Computing thresholds ... \
[....................................... ] 98.04% Computing thresholds ... |
[....................................... ] 98.53% Computing thresholds ... /
[....................................... ] 99.02% Computing thresholds ... -
[....................................... ] 99.51% Computing thresholds ... \
[........................................] 100.00% Computing thresholds ... |
[ ] 0.00% Repairing epochs |
[ ] 1.39% Repairing epochs /
[. ] 2.78% Repairing epochs -
[. ] 4.17% Repairing epochs \
[.. ] 5.56% Repairing epochs |
[.. ] 6.94% Repairing epochs /
[... ] 8.33% Repairing epochs -
[... ] 9.72% Repairing epochs \
[.... ] 11.11% Repairing epochs |
[..... ] 12.50% Repairing epochs /
[..... ] 13.89% Repairing epochs -
[...... ] 15.28% Repairing epochs \
[...... ] 16.67% Repairing epochs |
[....... ] 18.06% Repairing epochs /
[....... ] 19.44% Repairing epochs -
[........ ] 20.83% Repairing epochs \
[........ ] 22.22% Repairing epochs |
[......... ] 23.61% Repairing epochs /
[.......... ] 25.00% Repairing epochs -
[.......... ] 26.39% Repairing epochs \
[........... ] 27.78% Repairing epochs |
[........... ] 29.17% Repairing epochs /
[............ ] 30.56% Repairing epochs -
[............ ] 31.94% Repairing epochs \
[............. ] 33.33% Repairing epochs |
[............. ] 34.72% Repairing epochs /
[.............. ] 36.11% Repairing epochs -
[............... ] 37.50% Repairing epochs \
[............... ] 38.89% Repairing epochs |
[................ ] 40.28% Repairing epochs /
[................ ] 41.67% Repairing epochs -
[................. ] 43.06% Repairing epochs \
[................. ] 44.44% Repairing epochs |
[.................. ] 45.83% Repairing epochs /
[.................. ] 47.22% Repairing epochs -
[................... ] 48.61% Repairing epochs \
[.................... ] 50.00% Repairing epochs |
[.................... ] 51.39% Repairing epochs /
[..................... ] 52.78% Repairing epochs -
[..................... ] 54.17% Repairing epochs \
[...................... ] 55.56% Repairing epochs |
[...................... ] 56.94% Repairing epochs /
[....................... ] 58.33% Repairing epochs -
[....................... ] 59.72% Repairing epochs \
[........................ ] 61.11% Repairing epochs |
[......................... ] 62.50% Repairing epochs /
[......................... ] 63.89% Repairing epochs -
[.......................... ] 65.28% Repairing epochs \
[.......................... ] 66.67% Repairing epochs |
[........................... ] 68.06% Repairing epochs /
[........................... ] 69.44% Repairing epochs -
[............................ ] 70.83% Repairing epochs \
[............................ ] 72.22% Repairing epochs |
[............................. ] 73.61% Repairing epochs /
[.............................. ] 75.00% Repairing epochs -
[.............................. ] 76.39% Repairing epochs \
[............................... ] 77.78% Repairing epochs |
[............................... ] 79.17% Repairing epochs /
[................................ ] 80.56% Repairing epochs -
[................................ ] 81.94% Repairing epochs \
[................................. ] 83.33% Repairing epochs |
[................................. ] 84.72% Repairing epochs /
[.................................. ] 86.11% Repairing epochs -
[................................... ] 87.50% Repairing epochs \
[................................... ] 88.89% Repairing epochs |
[.................................... ] 90.28% Repairing epochs /
[.................................... ] 91.67% Repairing epochs -
[..................................... ] 93.06% Repairing epochs \
[..................................... ] 94.44% Repairing epochs |
[...................................... ] 95.83% Repairing epochs /
[...................................... ] 97.22% Repairing epochs -
[....................................... ] 98.61% Repairing epochs \
[........................................] 100.00% Repairing epochs |
[ ] 0.00% n_interp |
[ ] 0.00% Repairing epochs |
[ ] 1.39% Repairing epochs /
[. ] 2.78% Repairing epochs -
[. ] 4.17% Repairing epochs \
[.. ] 5.56% Repairing epochs |
[.. ] 6.94% Repairing epochs /
[... ] 8.33% Repairing epochs -
[... ] 9.72% Repairing epochs \
[.... ] 11.11% Repairing epochs |
[..... ] 12.50% Repairing epochs /
[..... ] 13.89% Repairing epochs -
[...... ] 15.28% Repairing epochs \
[...... ] 16.67% Repairing epochs |
[....... ] 18.06% Repairing epochs /
[....... ] 19.44% Repairing epochs -
[........ ] 20.83% Repairing epochs \
[........ ] 22.22% Repairing epochs |
[......... ] 23.61% Repairing epochs /
[.......... ] 25.00% Repairing epochs -
[.......... ] 26.39% Repairing epochs \
[........... ] 27.78% Repairing epochs |
[........... ] 29.17% Repairing epochs /
[............ ] 30.56% Repairing epochs -
[............ ] 31.94% Repairing epochs \
[............. ] 33.33% Repairing epochs |
[............. ] 34.72% Repairing epochs /
[.............. ] 36.11% Repairing epochs -
[............... ] 37.50% Repairing epochs \
[............... ] 38.89% Repairing epochs |
[................ ] 40.28% Repairing epochs /
[................ ] 41.67% Repairing epochs -
[................. ] 43.06% Repairing epochs \
[................. ] 44.44% Repairing epochs |
[.................. ] 45.83% Repairing epochs /
[.................. ] 47.22% Repairing epochs -
[................... ] 48.61% Repairing epochs \
[.................... ] 50.00% Repairing epochs |
[.................... ] 51.39% Repairing epochs /
[..................... ] 52.78% Repairing epochs -
[..................... ] 54.17% Repairing epochs \
[...................... ] 55.56% Repairing epochs |
[...................... ] 56.94% Repairing epochs /
[....................... ] 58.33% Repairing epochs -
[....................... ] 59.72% Repairing epochs \
[........................ ] 61.11% Repairing epochs |
[......................... ] 62.50% Repairing epochs /
[......................... ] 63.89% Repairing epochs -
[.......................... ] 65.28% Repairing epochs \
[.......................... ] 66.67% Repairing epochs |
[........................... ] 68.06% Repairing epochs /
[........................... ] 69.44% Repairing epochs -
[............................ ] 70.83% Repairing epochs \
[............................ ] 72.22% Repairing epochs |
[............................. ] 73.61% Repairing epochs /
[.............................. ] 75.00% Repairing epochs -
[.............................. ] 76.39% Repairing epochs \
[............................... ] 77.78% Repairing epochs |
[............................... ] 79.17% Repairing epochs /
[................................ ] 80.56% Repairing epochs -
[................................ ] 81.94% Repairing epochs \
[................................. ] 83.33% Repairing epochs |
[................................. ] 84.72% Repairing epochs /
[.................................. ] 86.11% Repairing epochs -
[................................... ] 87.50% Repairing epochs \
[................................... ] 88.89% Repairing epochs |
[.................................... ] 90.28% Repairing epochs /
[.................................... ] 91.67% Repairing epochs -
[..................................... ] 93.06% Repairing epochs \
[..................................... ] 94.44% Repairing epochs |
[...................................... ] 95.83% Repairing epochs /
[...................................... ] 97.22% Repairing epochs -
[....................................... ] 98.61% Repairing epochs \
[........................................] 100.00% Repairing epochs |
[ ] 0.00% Fold |
[.... ] 10.00% Fold /
[........ ] 20.00% Fold -
[............ ] 30.00% Fold \
[................ ] 40.00% Fold |
[.................... ] 50.00% Fold /
[........................ ] 60.00% Fold -
[............................ ] 70.00% Fold \
[................................ ] 80.00% Fold |
[.................................... ] 90.00% Fold /
[........................................] 100.00% Fold -
[............. ] 33.33% n_interp /
[ ] 0.00% Repairing epochs |
[ ] 1.39% Repairing epochs /
[. ] 2.78% Repairing epochs -
[. ] 4.17% Repairing epochs \
[.. ] 5.56% Repairing epochs |
[.. ] 6.94% Repairing epochs /
[... ] 8.33% Repairing epochs -
[... ] 9.72% Repairing epochs \
[.... ] 11.11% Repairing epochs |
[..... ] 12.50% Repairing epochs /
[..... ] 13.89% Repairing epochs -
[...... ] 15.28% Repairing epochs \
[...... ] 16.67% Repairing epochs |
[....... ] 18.06% Repairing epochs /
[....... ] 19.44% Repairing epochs -
[........ ] 20.83% Repairing epochs \
[........ ] 22.22% Repairing epochs |
[......... ] 23.61% Repairing epochs /
[.......... ] 25.00% Repairing epochs -
[.......... ] 26.39% Repairing epochs \
[........... ] 27.78% Repairing epochs |
[........... ] 29.17% Repairing epochs /
[............ ] 30.56% Repairing epochs -
[............ ] 31.94% Repairing epochs \
[............. ] 33.33% Repairing epochs |
[............. ] 34.72% Repairing epochs /
[.............. ] 36.11% Repairing epochs -
[............... ] 37.50% Repairing epochs \
[............... ] 38.89% Repairing epochs |
[................ ] 40.28% Repairing epochs /
[................ ] 41.67% Repairing epochs -
[................. ] 43.06% Repairing epochs \
[................. ] 44.44% Repairing epochs |
[.................. ] 45.83% Repairing epochs /
[.................. ] 47.22% Repairing epochs -
[................... ] 48.61% Repairing epochs \
[.................... ] 50.00% Repairing epochs |
[.................... ] 51.39% Repairing epochs /
[..................... ] 52.78% Repairing epochs -
[..................... ] 54.17% Repairing epochs \
[...................... ] 55.56% Repairing epochs |
[...................... ] 56.94% Repairing epochs /
[....................... ] 58.33% Repairing epochs -
[....................... ] 59.72% Repairing epochs \
[........................ ] 61.11% Repairing epochs |
[......................... ] 62.50% Repairing epochs /
[......................... ] 63.89% Repairing epochs -
[.......................... ] 65.28% Repairing epochs \
[.......................... ] 66.67% Repairing epochs |
[........................... ] 68.06% Repairing epochs /
[........................... ] 69.44% Repairing epochs -
[............................ ] 70.83% Repairing epochs \
[............................ ] 72.22% Repairing epochs |
[............................. ] 73.61% Repairing epochs /
[.............................. ] 75.00% Repairing epochs -
[.............................. ] 76.39% Repairing epochs \
[............................... ] 77.78% Repairing epochs |
[............................... ] 79.17% Repairing epochs /
[................................ ] 80.56% Repairing epochs -
[................................ ] 81.94% Repairing epochs \
[................................. ] 83.33% Repairing epochs |
[................................. ] 84.72% Repairing epochs /
[.................................. ] 86.11% Repairing epochs -
[................................... ] 87.50% Repairing epochs \
[................................... ] 88.89% Repairing epochs |
[.................................... ] 90.28% Repairing epochs /
[.................................... ] 91.67% Repairing epochs -
[..................................... ] 93.06% Repairing epochs \
[..................................... ] 94.44% Repairing epochs |
[...................................... ] 95.83% Repairing epochs /
[...................................... ] 97.22% Repairing epochs -
[....................................... ] 98.61% Repairing epochs \
[........................................] 100.00% Repairing epochs |
[ ] 0.00% Fold |
[.... ] 10.00% Fold /
[........ ] 20.00% Fold -
[............ ] 30.00% Fold \
[................ ] 40.00% Fold |
[.................... ] 50.00% Fold /
[........................ ] 60.00% Fold -
[............................ ] 70.00% Fold \
[................................ ] 80.00% Fold |
[.................................... ] 90.00% Fold /
[........................................] 100.00% Fold -
[.......................... ] 66.67% n_interp -
[ ] 0.00% Repairing epochs |
[ ] 1.39% Repairing epochs /
[. ] 2.78% Repairing epochs -
[. ] 4.17% Repairing epochs \
[.. ] 5.56% Repairing epochs |
[.. ] 6.94% Repairing epochs /
[... ] 8.33% Repairing epochs -
[... ] 9.72% Repairing epochs \
[.... ] 11.11% Repairing epochs |
[..... ] 12.50% Repairing epochs /
[..... ] 13.89% Repairing epochs -
[...... ] 15.28% Repairing epochs \
[...... ] 16.67% Repairing epochs |
[....... ] 18.06% Repairing epochs /
[....... ] 19.44% Repairing epochs -
[........ ] 20.83% Repairing epochs \
[........ ] 22.22% Repairing epochs |
[......... ] 23.61% Repairing epochs /
[.......... ] 25.00% Repairing epochs -
[.......... ] 26.39% Repairing epochs \
[........... ] 27.78% Repairing epochs |
[........... ] 29.17% Repairing epochs /
[............ ] 30.56% Repairing epochs -
[............ ] 31.94% Repairing epochs \
[............. ] 33.33% Repairing epochs |
[............. ] 34.72% Repairing epochs /
[.............. ] 36.11% Repairing epochs -
[............... ] 37.50% Repairing epochs \
[............... ] 38.89% Repairing epochs |
[................ ] 40.28% Repairing epochs /
[................ ] 41.67% Repairing epochs -
[................. ] 43.06% Repairing epochs \
[................. ] 44.44% Repairing epochs |
[.................. ] 45.83% Repairing epochs /
[.................. ] 47.22% Repairing epochs -
[................... ] 48.61% Repairing epochs \
[.................... ] 50.00% Repairing epochs |
[.................... ] 51.39% Repairing epochs /
[..................... ] 52.78% Repairing epochs -
[..................... ] 54.17% Repairing epochs \
[...................... ] 55.56% Repairing epochs |
[...................... ] 56.94% Repairing epochs /
[....................... ] 58.33% Repairing epochs -
[....................... ] 59.72% Repairing epochs \
[........................ ] 61.11% Repairing epochs |
[......................... ] 62.50% Repairing epochs /
[......................... ] 63.89% Repairing epochs -
[.......................... ] 65.28% Repairing epochs \
[.......................... ] 66.67% Repairing epochs |
[........................... ] 68.06% Repairing epochs /
[........................... ] 69.44% Repairing epochs -
[............................ ] 70.83% Repairing epochs \
[............................ ] 72.22% Repairing epochs |
[............................. ] 73.61% Repairing epochs /
[.............................. ] 75.00% Repairing epochs -
[.............................. ] 76.39% Repairing epochs \
[............................... ] 77.78% Repairing epochs |
[............................... ] 79.17% Repairing epochs /
[................................ ] 80.56% Repairing epochs -
[................................ ] 81.94% Repairing epochs \
[................................. ] 83.33% Repairing epochs |
[................................. ] 84.72% Repairing epochs /
[.................................. ] 86.11% Repairing epochs -
[................................... ] 87.50% Repairing epochs \
[................................... ] 88.89% Repairing epochs |
[.................................... ] 90.28% Repairing epochs /
[.................................... ] 91.67% Repairing epochs -
[..................................... ] 93.06% Repairing epochs \
[..................................... ] 94.44% Repairing epochs |
[...................................... ] 95.83% Repairing epochs /
[...................................... ] 97.22% Repairing epochs -
[....................................... ] 98.61% Repairing epochs \
[........................................] 100.00% Repairing epochs |
[ ] 0.00% Fold |
[.... ] 10.00% Fold /
[........ ] 20.00% Fold -
[............ ] 30.00% Fold \
[................ ] 40.00% Fold |
[.................... ] 50.00% Fold /
[........................ ] 60.00% Fold -
[............................ ] 70.00% Fold \
[................................ ] 80.00% Fold |
[.................................... ] 90.00% Fold /
[........................................] 100.00% Fold -
[........................................] 100.00% n_interp \
Estimated consensus=0.50 and n_interpolate=4
[ ] 0.00% Repairing epochs |
[ ] 1.39% Repairing epochs /
[. ] 2.78% Repairing epochs -
[. ] 4.17% Repairing epochs \
[.. ] 5.56% Repairing epochs |
[.. ] 6.94% Repairing epochs /
[... ] 8.33% Repairing epochs -
[... ] 9.72% Repairing epochs \
[.... ] 11.11% Repairing epochs |
[..... ] 12.50% Repairing epochs /
[..... ] 13.89% Repairing epochs -
[...... ] 15.28% Repairing epochs \
[...... ] 16.67% Repairing epochs |
[....... ] 18.06% Repairing epochs /
[....... ] 19.44% Repairing epochs -
[........ ] 20.83% Repairing epochs \
[........ ] 22.22% Repairing epochs |
[......... ] 23.61% Repairing epochs /
[.......... ] 25.00% Repairing epochs -
[.......... ] 26.39% Repairing epochs \
[........... ] 27.78% Repairing epochs |
[........... ] 29.17% Repairing epochs /
[............ ] 30.56% Repairing epochs -
[............ ] 31.94% Repairing epochs \
[............. ] 33.33% Repairing epochs |
[............. ] 34.72% Repairing epochs /
[.............. ] 36.11% Repairing epochs -
[............... ] 37.50% Repairing epochs \
[............... ] 38.89% Repairing epochs |
[................ ] 40.28% Repairing epochs /
[................ ] 41.67% Repairing epochs -
[................. ] 43.06% Repairing epochs \
[................. ] 44.44% Repairing epochs |
[.................. ] 45.83% Repairing epochs /
[.................. ] 47.22% Repairing epochs -
[................... ] 48.61% Repairing epochs \
[.................... ] 50.00% Repairing epochs |
[.................... ] 51.39% Repairing epochs /
[..................... ] 52.78% Repairing epochs -
[..................... ] 54.17% Repairing epochs \
[...................... ] 55.56% Repairing epochs |
[...................... ] 56.94% Repairing epochs /
[....................... ] 58.33% Repairing epochs -
[....................... ] 59.72% Repairing epochs \
[........................ ] 61.11% Repairing epochs |
[......................... ] 62.50% Repairing epochs /
[......................... ] 63.89% Repairing epochs -
[.......................... ] 65.28% Repairing epochs \
[.......................... ] 66.67% Repairing epochs |
[........................... ] 68.06% Repairing epochs /
[........................... ] 69.44% Repairing epochs -
[............................ ] 70.83% Repairing epochs \
[............................ ] 72.22% Repairing epochs |
[............................. ] 73.61% Repairing epochs /
[.............................. ] 75.00% Repairing epochs -
[.............................. ] 76.39% Repairing epochs \
[............................... ] 77.78% Repairing epochs |
[............................... ] 79.17% Repairing epochs /
[................................ ] 80.56% Repairing epochs -
[................................ ] 81.94% Repairing epochs \
[................................. ] 83.33% Repairing epochs |
[................................. ] 84.72% Repairing epochs /
[.................................. ] 86.11% Repairing epochs -
[................................... ] 87.50% Repairing epochs \
[................................... ] 88.89% Repairing epochs |
[.................................... ] 90.28% Repairing epochs /
[.................................... ] 91.67% Repairing epochs -
[..................................... ] 93.06% Repairing epochs \
[..................................... ] 94.44% Repairing epochs |
[...................................... ] 95.83% Repairing epochs /
[...................................... ] 97.22% Repairing epochs -
[....................................... ] 98.61% Repairing epochs \
[........................................] 100.00% Repairing epochs |No bad epochs were found for your data. Returning a copy of the data you wanted to clean. Interpolation may have been done.
Now, we will manually mark the bad channels just for plotting.
evoked.info['bads'] = ['MEG 2443']
evoked_clean.info['bads'] = ['MEG 2443']
Let us plot the results.
import matplotlib.pyplot as plt # noqa
set_matplotlib_defaults(plt)
fig, axes = plt.subplots(2, 1, figsize=(6, 6))
for ax in axes:
ax.tick_params(axis='x', which='both', bottom='off', top='off')
ax.tick_params(axis='y', which='both', left='off', right='off')
ylim = dict(grad=(-170, 200))
evoked.pick_types(meg='grad', exclude=[])
evoked.plot(exclude=[], axes=axes[0], ylim=ylim, show=False)
axes[0].set_title('Before autoreject')
evoked_clean.pick_types(meg='grad', exclude=[])
evoked_clean.plot(exclude=[], axes=axes[1], ylim=ylim)
axes[1].set_title('After autoreject')
plt.tight_layout()
To top things up, we can also visualize the bad sensors for each trial using a heatmap.
ar.get_reject_log(epochs['Auditory/Left']).plot()
Out:
/Users/mainak/Documents/github_repos/autoreject/autoreject/autoreject.py:1268: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
plt.show()
Total running time of the script: ( 2 minutes 44.328 seconds)