Note
Go to the end to download the full example code.
Preprocessing workflow with autoreject
and ICA#
This example demonstrates how to visualize data when preprocessing
with autoreject
and discusses decisions about when and which
other preprocessing steps to use in combination.
tldr: We recommend that you first highpass filter the data, then run autoreject (local) and supply the artifact-free epochs to the ICA algorithm for a robust fit, and finally run autoreject (local) again.
# Author: Alex Rockhill <aprockhill@mailbox.org>
# Mainak Jas <mjas@mgh.harvard.edu>
# Apoorva Karekal <apoorvak@uoregon.edu>
#
# License: BSD-3-Clause
# sphinx_gallery_thumbnail_number = 9
First, we download resting-state EEG data from a Parkinsonβs patient
from OpenNeuro. We will do this using openneuro-py
which can be
installed with the command pip install openneuro-py
.
import os
import matplotlib.pyplot as plt
import openneuro
import mne
import autoreject
dataset = 'ds002778' # The id code on OpenNeuro for this example dataset
subject_id = 'pd14'
target_dir = os.path.join(
os.path.dirname(autoreject.__file__), '..', 'examples', dataset)
os.makedirs(target_dir, exist_ok=True)
openneuro.download(dataset=dataset, target_dir=target_dir,
include=[f'sub-{subject_id}/ses-off'])
π Hello! This is openneuro-py 2024.2.0. Great to see you! π€
π Please report problems π€― and bugs πͺ² at
https://github.com/hoechenberger/openneuro-py/issues
π Preparing to download ds002778 β¦
π Traversing directories for ds002778 : 0 entities [00:00, ? entities/s]
π Traversing directories for ds002778 : 7 entities [00:00, 35.29 entities/s]
π Traversing directories for ds002778 : 11 entities [00:01, 8.60 entities/s]
π Traversing directories for ds002778 : 13 entities [00:01, 7.25 entities/s]
π Traversing directories for ds002778 : 15 entities [00:01, 6.41 entities/s]
π Traversing directories for ds002778 : 16 entities [00:02, 6.12 entities/s]
π Traversing directories for ds002778 : 17 entities [00:02, 5.89 entities/s]
π Traversing directories for ds002778 : 18 entities [00:02, 5.52 entities/s]
π Traversing directories for ds002778 : 19 entities [00:02, 5.28 entities/s]
π Traversing directories for ds002778 : 20 entities [00:02, 5.13 entities/s]
π Traversing directories for ds002778 : 21 entities [00:03, 5.06 entities/s]
π Traversing directories for ds002778 : 22 entities [00:03, 5.02 entities/s]
π Traversing directories for ds002778 : 23 entities [00:03, 4.93 entities/s]
π Traversing directories for ds002778 : 24 entities [00:03, 5.64 entities/s]
π Traversing directories for ds002778 : 25 entities [00:03, 5.53 entities/s]
π Traversing directories for ds002778 : 27 entities [00:04, 5.96 entities/s]
π Traversing directories for ds002778 : 28 entities [00:04, 6.55 entities/s]
π Traversing directories for ds002778 : 29 entities [00:04, 5.81 entities/s]
π Traversing directories for ds002778 : 30 entities [00:04, 5.43 entities/s]
π Traversing directories for ds002778 : 36 entities [00:04, 12.55 entities/s]
π Traversing directories for ds002778 : 38 entities [00:05, 11.49 entities/s]
π Traversing directories for ds002778 : 43 entities [00:05, 12.85 entities/s]
π Traversing directories for ds002778 : 45 entities [00:05, 10.58 entities/s]
π Traversing directories for ds002778 : 47 entities [00:06, 9.41 entities/s]
π Traversing directories for ds002778 : 49 entities [00:06, 8.48 entities/s]
π Traversing directories for ds002778 : 51 entities [00:06, 7.84 entities/s]
π Traversing directories for ds002778 : 52 entities [00:06, 8.03 entities/s]
π Traversing directories for ds002778 : 53 entities [00:07, 6.97 entities/s]
π Traversing directories for ds002778 : 54 entities [00:07, 7.27 entities/s]
π Traversing directories for ds002778 : 55 entities [00:07, 6.03 entities/s]
π Traversing directories for ds002778 : 56 entities [00:07, 6.45 entities/s]
π Traversing directories for ds002778 : 57 entities [00:07, 5.71 entities/s]
π Traversing directories for ds002778 : 59 entities [00:08, 6.20 entities/s]
π Traversing directories for ds002778 : 60 entities [00:08, 6.65 entities/s]
π Traversing directories for ds002778 : 61 entities [00:08, 6.00 entities/s]
π Traversing directories for ds002778 : 62 entities [00:08, 6.51 entities/s]
π Traversing directories for ds002778 : 63 entities [00:08, 5.61 entities/s]
π Traversing directories for ds002778 : 64 entities [00:08, 6.35 entities/s]
π Traversing directories for ds002778 : 64 entities [00:08, 7.20 entities/s]
π₯ Retrieving up to 12 files (5 concurrent downloads).
Skipping participants.tsv: already downloaded.: 100%|ββββββββββ| 1.62k/1.62k [00:00<?, ?B/s]
Skipping participants.json: already downloaded.: 100%|ββββββββββ| 1.24k/1.24k [00:00<?, ?B/s]
Skipping sub-pd14_ses-off_scans.tsv: already downloaded.: 100%|ββββββββββ| 76.0/76.0 [00:00<?, ?B/s]
Skipping sub-pd14_ses-off_task-rest_beh.tsv: already downloaded.: 100%|ββββββββββ| 10.0/10.0 [00:00<?, ?B/s]
Skipping sub-pd14_ses-off_task-rest_eeg.json: already downloaded.: 100%|ββββββββββ| 471/471 [00:00<?, ?B/s]
Skipping sub-pd14_ses-off_task-rest_events.tsv: already downloaded.: 100%|ββββββββββ| 65.0/65.0 [00:00<?, ?B/s]
Skipping sub-pd14_ses-off_task-rest_channels.tsv: already downloaded.: 100%|ββββββββββ| 2.22k/2.22k [00:00<?, ?B/s]
Skipping sub-pd14_ses-off_task-rest_eeg.bdf: already downloaded.: 100%|ββββββββββ| 17.5M/17.5M [00:00<?, ?B/s]
Re-downloading README: file size mismatch.: 0.00B [00:00, ?B/s]
Re-downloading sub-pd14_ses-off_task-rest_beh.json: file size mismatch.: 0.00B [00:00, ?B/s]
Re-downloading dataset_description.json: file size mismatch.: 0.00B [00:00, ?B/s]
Re-downloading CHANGES: file size mismatch.: 0.00B [00:00, ?B/s]
β
Finished downloading ds002778.
π§ Please enjoy your brains.
We will now load in the raw data from the bdf file downloaded from OpenNeuro and, since this is resting-state data without any events, make regularly spaced events with which to epoch the raw data. In the averaged plot, we can see that there may be some eyeblink artifact contamination but, overall, the data is typical of resting-state EEG.
raw_fname = os.path.join(target_dir, f'sub-{subject_id}', 'ses-off', 'eeg',
'sub-pd14_ses-off_task-rest_eeg.bdf')
raw = mne.io.read_raw_bdf(raw_fname, preload=True)
dig_montage = mne.channels.make_standard_montage('biosemi32')
raw.drop_channels([ch for ch in raw.ch_names
if ch not in dig_montage.ch_names])
raw.set_montage(dig_montage) # use the standard montage
epochs = mne.make_fixed_length_epochs(raw, duration=3, preload=True)
# plot the data
epochs.average().detrend().plot_joint()
Extracting EDF parameters from /home/circleci/project/examples/ds002778/sub-pd14/ses-off/eeg/sub-pd14_ses-off_task-rest_eeg.bdf...
BDF file detected
Setting channel info structure...
Creating raw.info structure...
Reading 0 ... 149503 = 0.000 ... 291.998 secs...
Not setting metadata
97 matching events found
No baseline correction applied
0 projection items activated
Using data from preloaded Raw for 97 events and 1536 original time points ...
0 bad epochs dropped
No projector specified for this dataset. Please consider the method self.add_proj.
<Figure size 800x420 with 6 Axes>
Autoreject without any other preprocessing#
Now, weβll naively apply autoreject as our first preprocessing step.
As we can see in the plot of the rejected epochs, there are many eyeblinks that caused the epoch to be dropped. This resulted in a lot of the data being lost.
The data looks fairly clean already and we donβt want to interpolate more than a few sensors since we only have 32 to start, so the number of channels to interpolate was set to check some low numbers
ar = autoreject.AutoReject(n_interpolate=[1, 2, 3, 4], random_state=11,
n_jobs=1, verbose=True)
ar.fit(epochs[:20]) # fit on a few epochs to save time
epochs_ar, reject_log = ar.transform(epochs, return_log=True)
Running autoreject on ch_type=eeg
0%| | Creating augmented epochs : 0/32 [00:00<?, ?it/s]
6%|β | Creating augmented epochs : 2/32 [00:00<00:00, 99.45it/s]
12%|ββ | Creating augmented epochs : 4/32 [00:00<00:00, 101.52it/s]
19%|ββ | Creating augmented epochs : 6/32 [00:00<00:00, 102.67it/s]
25%|βββ | Creating augmented epochs : 8/32 [00:00<00:00, 104.04it/s]
31%|ββββ | Creating augmented epochs : 10/32 [00:00<00:00, 103.20it/s]
38%|ββββ | Creating augmented epochs : 12/32 [00:00<00:00, 104.11it/s]
44%|βββββ | Creating augmented epochs : 14/32 [00:00<00:00, 104.26it/s]
50%|βββββ | Creating augmented epochs : 16/32 [00:00<00:00, 104.41it/s]
56%|ββββββ | Creating augmented epochs : 18/32 [00:00<00:00, 104.84it/s]
62%|βββββββ | Creating augmented epochs : 20/32 [00:00<00:00, 104.64it/s]
69%|βββββββ | Creating augmented epochs : 22/32 [00:00<00:00, 104.06it/s]
75%|ββββββββ | Creating augmented epochs : 24/32 [00:00<00:00, 104.44it/s]
81%|βββββββββ | Creating augmented epochs : 26/32 [00:00<00:00, 104.51it/s]
88%|βββββββββ | Creating augmented epochs : 28/32 [00:00<00:00, 104.30it/s]
94%|ββββββββββ| Creating augmented epochs : 30/32 [00:00<00:00, 104.31it/s]
100%|ββββββββββ| Creating augmented epochs : 32/32 [00:00<00:00, 104.04it/s]
100%|ββββββββββ| Creating augmented epochs : 32/32 [00:00<00:00, 103.98it/s]
0%| | Computing thresholds ... : 0/32 [00:00<?, ?it/s]
3%|β | Computing thresholds ... : 1/32 [00:00<00:09, 3.18it/s]
6%|β | Computing thresholds ... : 2/32 [00:00<00:09, 3.09it/s]
9%|β | Computing thresholds ... : 3/32 [00:00<00:09, 3.06it/s]
12%|ββ | Computing thresholds ... : 4/32 [00:01<00:09, 3.05it/s]
16%|ββ | Computing thresholds ... : 5/32 [00:01<00:08, 3.06it/s]
19%|ββ | Computing thresholds ... : 6/32 [00:01<00:08, 3.05it/s]
22%|βββ | Computing thresholds ... : 7/32 [00:02<00:08, 3.04it/s]
25%|βββ | Computing thresholds ... : 8/32 [00:02<00:07, 3.04it/s]
28%|βββ | Computing thresholds ... : 9/32 [00:02<00:07, 3.05it/s]
31%|ββββ | Computing thresholds ... : 10/32 [00:03<00:07, 3.04it/s]
34%|ββββ | Computing thresholds ... : 11/32 [00:03<00:06, 3.03it/s]
38%|ββββ | Computing thresholds ... : 12/32 [00:03<00:06, 3.03it/s]
41%|ββββ | Computing thresholds ... : 13/32 [00:04<00:06, 3.04it/s]
44%|βββββ | Computing thresholds ... : 14/32 [00:04<00:05, 3.04it/s]
47%|βββββ | Computing thresholds ... : 15/32 [00:04<00:05, 3.03it/s]
50%|βββββ | Computing thresholds ... : 16/32 [00:05<00:05, 3.03it/s]
53%|ββββββ | Computing thresholds ... : 17/32 [00:05<00:04, 3.03it/s]
56%|ββββββ | Computing thresholds ... : 18/32 [00:05<00:04, 3.03it/s]
59%|ββββββ | Computing thresholds ... : 19/32 [00:06<00:04, 3.03it/s]
62%|βββββββ | Computing thresholds ... : 20/32 [00:06<00:03, 3.03it/s]
66%|βββββββ | Computing thresholds ... : 21/32 [00:06<00:03, 3.03it/s]
69%|βββββββ | Computing thresholds ... : 22/32 [00:07<00:03, 3.03it/s]
72%|ββββββββ | Computing thresholds ... : 23/32 [00:07<00:02, 3.04it/s]
75%|ββββββββ | Computing thresholds ... : 24/32 [00:07<00:02, 3.03it/s]
78%|ββββββββ | Computing thresholds ... : 25/32 [00:08<00:02, 3.03it/s]
81%|βββββββββ | Computing thresholds ... : 26/32 [00:08<00:01, 3.03it/s]
84%|βββββββββ | Computing thresholds ... : 27/32 [00:08<00:01, 3.03it/s]
88%|βββββββββ | Computing thresholds ... : 28/32 [00:09<00:01, 3.03it/s]
91%|βββββββββ | Computing thresholds ... : 29/32 [00:09<00:00, 3.02it/s]
94%|ββββββββββ| Computing thresholds ... : 30/32 [00:09<00:00, 3.02it/s]
97%|ββββββββββ| Computing thresholds ... : 31/32 [00:10<00:00, 3.02it/s]
100%|ββββββββββ| Computing thresholds ... : 32/32 [00:10<00:00, 3.03it/s]
100%|ββββββββββ| Computing thresholds ... : 32/32 [00:10<00:00, 3.03it/s]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
15%|ββ | Repairing epochs : 3/20 [00:00<00:00, 143.96it/s]
30%|βββ | Repairing epochs : 6/20 [00:00<00:00, 142.58it/s]
45%|βββββ | Repairing epochs : 9/20 [00:00<00:00, 141.74it/s]
60%|ββββββ | Repairing epochs : 12/20 [00:00<00:00, 149.77it/s]
75%|ββββββββ | Repairing epochs : 15/20 [00:00<00:00, 155.68it/s]
90%|βββββββββ | Repairing epochs : 18/20 [00:00<00:00, 160.50it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 160.30it/s]
0%| | n_interp : 0/4 [00:00<?, ?it/s]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
15%|ββ | Repairing epochs : 3/20 [00:00<00:00, 146.90it/s]
35%|ββββ | Repairing epochs : 7/20 [00:00<00:00, 154.49it/s]
50%|βββββ | Repairing epochs : 10/20 [00:00<00:00, 151.56it/s]
70%|βββββββ | Repairing epochs : 14/20 [00:00<00:00, 162.61it/s]
80%|ββββββββ | Repairing epochs : 16/20 [00:00<00:00, 147.58it/s]
95%|ββββββββββ| Repairing epochs : 19/20 [00:00<00:00, 147.26it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 149.51it/s]
0%| | Fold : 0/10 [00:00<?, ?it/s]
10%|β | Fold : 1/10 [00:00<00:00, 11.25it/s]
20%|ββ | Fold : 2/10 [00:00<00:00, 11.15it/s]
30%|βββ | Fold : 3/10 [00:00<00:00, 11.24it/s]
40%|ββββ | Fold : 4/10 [00:00<00:00, 11.29it/s]
50%|βββββ | Fold : 5/10 [00:00<00:00, 11.23it/s]
60%|ββββββ | Fold : 6/10 [00:00<00:00, 11.22it/s]
70%|βββββββ | Fold : 7/10 [00:00<00:00, 11.22it/s]
80%|ββββββββ | Fold : 8/10 [00:00<00:00, 11.23it/s]
90%|βββββββββ | Fold : 9/10 [00:00<00:00, 11.24it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 11.24it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 11.23it/s]
25%|βββ | n_interp : 1/4 [00:01<00:03, 1.03s/it]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
15%|ββ | Repairing epochs : 3/20 [00:00<00:00, 144.65it/s]
35%|ββββ | Repairing epochs : 7/20 [00:00<00:00, 148.65it/s]
50%|βββββ | Repairing epochs : 10/20 [00:00<00:00, 147.16it/s]
70%|βββββββ | Repairing epochs : 14/20 [00:00<00:00, 160.26it/s]
80%|ββββββββ | Repairing epochs : 16/20 [00:00<00:00, 145.85it/s]
90%|βββββββββ | Repairing epochs : 18/20 [00:00<00:00, 140.53it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 145.32it/s]
0%| | Fold : 0/10 [00:00<?, ?it/s]
10%|β | Fold : 1/10 [00:00<00:00, 12.14it/s]
20%|ββ | Fold : 2/10 [00:00<00:00, 12.01it/s]
30%|βββ | Fold : 3/10 [00:00<00:00, 11.94it/s]
40%|ββββ | Fold : 4/10 [00:00<00:00, 11.81it/s]
50%|βββββ | Fold : 5/10 [00:00<00:00, 11.66it/s]
60%|ββββββ | Fold : 6/10 [00:00<00:00, 11.51it/s]
70%|βββββββ | Fold : 7/10 [00:00<00:00, 11.42it/s]
80%|ββββββββ | Fold : 8/10 [00:00<00:00, 11.44it/s]
90%|βββββββββ | Fold : 9/10 [00:00<00:00, 11.51it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 11.52it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 11.53it/s]
50%|βββββ | n_interp : 2/4 [00:02<00:02, 1.03s/it]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
15%|ββ | Repairing epochs : 3/20 [00:00<00:00, 145.44it/s]
35%|ββββ | Repairing epochs : 7/20 [00:00<00:00, 151.71it/s]
50%|βββββ | Repairing epochs : 10/20 [00:00<00:00, 149.19it/s]
65%|βββββββ | Repairing epochs : 13/20 [00:00<00:00, 155.79it/s]
80%|ββββββββ | Repairing epochs : 16/20 [00:00<00:00, 144.28it/s]
90%|βββββββββ | Repairing epochs : 18/20 [00:00<00:00, 140.19it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 144.38it/s]
0%| | Fold : 0/10 [00:00<?, ?it/s]
10%|β | Fold : 1/10 [00:00<00:00, 11.61it/s]
20%|ββ | Fold : 2/10 [00:00<00:00, 11.50it/s]
30%|βββ | Fold : 3/10 [00:00<00:00, 11.58it/s]
40%|ββββ | Fold : 4/10 [00:00<00:00, 11.70it/s]
50%|βββββ | Fold : 5/10 [00:00<00:00, 11.62it/s]
60%|ββββββ | Fold : 6/10 [00:00<00:00, 11.63it/s]
70%|βββββββ | Fold : 7/10 [00:00<00:00, 11.66it/s]
80%|ββββββββ | Fold : 8/10 [00:00<00:00, 11.64it/s]
90%|βββββββββ | Fold : 9/10 [00:00<00:00, 11.57it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 11.48it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 11.51it/s]
75%|ββββββββ | n_interp : 3/4 [00:03<00:01, 1.02s/it]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
10%|β | Repairing epochs : 2/20 [00:00<00:00, 123.67it/s]
25%|βββ | Repairing epochs : 5/20 [00:00<00:00, 151.37it/s]
35%|ββββ | Repairing epochs : 7/20 [00:00<00:00, 142.18it/s]
50%|βββββ | Repairing epochs : 10/20 [00:00<00:00, 140.13it/s]
65%|βββββββ | Repairing epochs : 13/20 [00:00<00:00, 148.75it/s]
75%|ββββββββ | Repairing epochs : 15/20 [00:00<00:00, 144.18it/s]
85%|βββββββββ | Repairing epochs : 17/20 [00:00<00:00, 139.82it/s]
95%|ββββββββββ| Repairing epochs : 19/20 [00:00<00:00, 135.89it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 138.46it/s]
0%| | Fold : 0/10 [00:00<?, ?it/s]
10%|β | Fold : 1/10 [00:00<00:00, 12.58it/s]
20%|ββ | Fold : 2/10 [00:00<00:00, 12.56it/s]
30%|βββ | Fold : 3/10 [00:00<00:00, 12.49it/s]
40%|ββββ | Fold : 4/10 [00:00<00:00, 12.48it/s]
50%|βββββ | Fold : 5/10 [00:00<00:00, 12.46it/s]
60%|ββββββ | Fold : 6/10 [00:00<00:00, 12.44it/s]
70%|βββββββ | Fold : 7/10 [00:00<00:00, 12.44it/s]
80%|ββββββββ | Fold : 8/10 [00:00<00:00, 12.35it/s]
90%|βββββββββ | Fold : 9/10 [00:00<00:00, 12.33it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 12.26it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 12.29it/s]
100%|ββββββββββ| n_interp : 4/4 [00:04<00:00, 1.01s/it]
100%|ββββββββββ| n_interp : 4/4 [00:04<00:00, 1.01s/it]
Estimated consensus=0.10 and n_interpolate=1
0%| | Repairing epochs : 0/97 [00:00<?, ?it/s]
1%| | Repairing epochs : 1/97 [00:00<00:01, 48.33it/s]
2%|β | Repairing epochs : 2/97 [00:00<00:02, 42.73it/s]
3%|β | Repairing epochs : 3/97 [00:00<00:02, 44.72it/s]
4%|β | Repairing epochs : 4/97 [00:00<00:02, 45.87it/s]
5%|β | Repairing epochs : 5/97 [00:00<00:01, 46.68it/s]
6%|β | Repairing epochs : 6/97 [00:00<00:01, 47.34it/s]
7%|β | Repairing epochs : 7/97 [00:00<00:01, 45.59it/s]
8%|β | Repairing epochs : 8/97 [00:00<00:01, 45.96it/s]
9%|β | Repairing epochs : 9/97 [00:00<00:01, 46.47it/s]
10%|β | Repairing epochs : 10/97 [00:00<00:01, 45.28it/s]
11%|ββ | Repairing epochs : 11/97 [00:00<00:01, 45.59it/s]
12%|ββ | Repairing epochs : 12/97 [00:00<00:01, 45.84it/s]
13%|ββ | Repairing epochs : 13/97 [00:00<00:01, 45.95it/s]
14%|ββ | Repairing epochs : 14/97 [00:00<00:01, 46.20it/s]
15%|ββ | Repairing epochs : 15/97 [00:00<00:01, 45.30it/s]
16%|ββ | Repairing epochs : 16/97 [00:00<00:01, 44.53it/s]
18%|ββ | Repairing epochs : 17/97 [00:00<00:01, 44.79it/s]
19%|ββ | Repairing epochs : 18/97 [00:00<00:01, 44.04it/s]
20%|ββ | Repairing epochs : 19/97 [00:00<00:01, 44.36it/s]
21%|ββ | Repairing epochs : 20/97 [00:00<00:01, 44.66it/s]
22%|βββ | Repairing epochs : 21/97 [00:00<00:01, 44.87it/s]
23%|βββ | Repairing epochs : 22/97 [00:00<00:01, 45.19it/s]
24%|βββ | Repairing epochs : 23/97 [00:00<00:01, 45.45it/s]
25%|βββ | Repairing epochs : 24/97 [00:00<00:01, 44.83it/s]
26%|βββ | Repairing epochs : 25/97 [00:00<00:01, 44.99it/s]
27%|βββ | Repairing epochs : 26/97 [00:00<00:01, 45.14it/s]
28%|βββ | Repairing epochs : 27/97 [00:00<00:01, 44.75it/s]
29%|βββ | Repairing epochs : 28/97 [00:00<00:01, 44.33it/s]
30%|βββ | Repairing epochs : 29/97 [00:00<00:01, 44.47it/s]
31%|βββ | Repairing epochs : 30/97 [00:00<00:01, 44.57it/s]
32%|ββββ | Repairing epochs : 31/97 [00:00<00:01, 44.04it/s]
33%|ββββ | Repairing epochs : 32/97 [00:00<00:01, 44.32it/s]
34%|ββββ | Repairing epochs : 33/97 [00:00<00:01, 44.64it/s]
35%|ββββ | Repairing epochs : 34/97 [00:00<00:01, 44.96it/s]
36%|ββββ | Repairing epochs : 35/97 [00:00<00:01, 44.64it/s]
37%|ββββ | Repairing epochs : 36/97 [00:00<00:01, 44.81it/s]
38%|ββββ | Repairing epochs : 37/97 [00:00<00:01, 44.43it/s]
39%|ββββ | Repairing epochs : 38/97 [00:00<00:01, 44.72it/s]
40%|ββββ | Repairing epochs : 39/97 [00:00<00:01, 44.37it/s]
41%|ββββ | Repairing epochs : 40/97 [00:00<00:01, 44.65it/s]
42%|βββββ | Repairing epochs : 41/97 [00:00<00:01, 44.89it/s]
43%|βββββ | Repairing epochs : 42/97 [00:00<00:01, 45.06it/s]
44%|βββββ | Repairing epochs : 43/97 [00:00<00:01, 44.67it/s]
45%|βββββ | Repairing epochs : 44/97 [00:00<00:01, 44.96it/s]
46%|βββββ | Repairing epochs : 45/97 [00:00<00:01, 45.22it/s]
47%|βββββ | Repairing epochs : 46/97 [00:01<00:01, 45.40it/s]
48%|βββββ | Repairing epochs : 47/97 [00:01<00:01, 44.96it/s]
49%|βββββ | Repairing epochs : 48/97 [00:01<00:01, 45.17it/s]
51%|βββββ | Repairing epochs : 49/97 [00:01<00:01, 45.44it/s]
52%|ββββββ | Repairing epochs : 50/97 [00:01<00:01, 45.67it/s]
53%|ββββββ | Repairing epochs : 51/97 [00:01<00:01, 45.32it/s]
54%|ββββββ | Repairing epochs : 52/97 [00:01<00:00, 45.48it/s]
55%|ββββββ | Repairing epochs : 53/97 [00:01<00:00, 45.62it/s]
56%|ββββββ | Repairing epochs : 54/97 [00:01<00:00, 45.18it/s]
57%|ββββββ | Repairing epochs : 55/97 [00:01<00:00, 44.89it/s]
58%|ββββββ | Repairing epochs : 56/97 [00:01<00:00, 45.14it/s]
59%|ββββββ | Repairing epochs : 57/97 [00:01<00:00, 45.37it/s]
60%|ββββββ | Repairing epochs : 58/97 [00:01<00:00, 45.02it/s]
61%|ββββββ | Repairing epochs : 59/97 [00:01<00:00, 44.65it/s]
62%|βββββββ | Repairing epochs : 60/97 [00:01<00:00, 44.77it/s]
63%|βββββββ | Repairing epochs : 61/97 [00:01<00:00, 44.89it/s]
64%|βββββββ | Repairing epochs : 62/97 [00:01<00:00, 44.99it/s]
65%|βββββββ | Repairing epochs : 63/97 [00:01<00:00, 44.55it/s]
66%|βββββββ | Repairing epochs : 64/97 [00:01<00:00, 44.18it/s]
67%|βββββββ | Repairing epochs : 65/97 [00:01<00:00, 43.86it/s]
68%|βββββββ | Repairing epochs : 66/97 [00:01<00:00, 43.51it/s]
69%|βββββββ | Repairing epochs : 67/97 [00:01<00:00, 43.18it/s]
70%|βββββββ | Repairing epochs : 68/97 [00:01<00:00, 42.89it/s]
71%|βββββββ | Repairing epochs : 69/97 [00:01<00:00, 42.69it/s]
72%|ββββββββ | Repairing epochs : 70/97 [00:01<00:00, 42.50it/s]
73%|ββββββββ | Repairing epochs : 71/97 [00:01<00:00, 42.30it/s]
74%|ββββββββ | Repairing epochs : 72/97 [00:01<00:00, 42.10it/s]
75%|ββββββββ | Repairing epochs : 73/97 [00:01<00:00, 41.87it/s]
76%|ββββββββ | Repairing epochs : 74/97 [00:01<00:00, 41.68it/s]
77%|ββββββββ | Repairing epochs : 75/97 [00:01<00:00, 41.50it/s]
78%|ββββββββ | Repairing epochs : 76/97 [00:01<00:00, 41.38it/s]
79%|ββββββββ | Repairing epochs : 77/97 [00:01<00:00, 41.30it/s]
80%|ββββββββ | Repairing epochs : 78/97 [00:01<00:00, 41.17it/s]
81%|βββββββββ | Repairing epochs : 79/97 [00:01<00:00, 41.05it/s]
82%|βββββββββ | Repairing epochs : 80/97 [00:01<00:00, 40.99it/s]
84%|βββββββββ | Repairing epochs : 81/97 [00:01<00:00, 40.89it/s]
85%|βββββββββ | Repairing epochs : 82/97 [00:01<00:00, 40.82it/s]
86%|βββββββββ | Repairing epochs : 83/97 [00:01<00:00, 40.78it/s]
87%|βββββββββ | Repairing epochs : 84/97 [00:01<00:00, 40.72it/s]
88%|βββββββββ | Repairing epochs : 85/97 [00:01<00:00, 40.61it/s]
89%|βββββββββ | Repairing epochs : 86/97 [00:01<00:00, 40.56it/s]
90%|βββββββββ | Repairing epochs : 87/97 [00:02<00:00, 40.49it/s]
91%|βββββββββ | Repairing epochs : 88/97 [00:02<00:00, 40.42it/s]
92%|ββββββββββ| Repairing epochs : 89/97 [00:02<00:00, 40.29it/s]
93%|ββββββββββ| Repairing epochs : 90/97 [00:02<00:00, 40.20it/s]
94%|ββββββββββ| Repairing epochs : 91/97 [00:02<00:00, 40.20it/s]
95%|ββββββββββ| Repairing epochs : 92/97 [00:02<00:00, 40.19it/s]
96%|ββββββββββ| Repairing epochs : 93/97 [00:02<00:00, 40.12it/s]
97%|ββββββββββ| Repairing epochs : 94/97 [00:02<00:00, 40.08it/s]
98%|ββββββββββ| Repairing epochs : 95/97 [00:02<00:00, 39.95it/s]
99%|ββββββββββ| Repairing epochs : 96/97 [00:02<00:00, 39.87it/s]
100%|ββββββββββ| Repairing epochs : 97/97 [00:02<00:00, 39.79it/s]
100%|ββββββββββ| Repairing epochs : 97/97 [00:02<00:00, 42.57it/s]
Dropped 27 epochs: 54, 58, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 86, 89, 91, 92, 95, 96
visualize the dropped epochs
epochs[reject_log.bad_epochs].plot(scalings=dict(eeg=100e-6))
Using matplotlib as 2D backend.
<MNEBrowseFigure size 800x800 with 4 Axes>
and the reject log
reject_log.plot('horizontal')
<Figure size 1200x600 with 1 Axes>
Autoreject with high-pass filter#
The data may be very valuable and the time for the experiment limited and so we may want to take steps to reduce the number of epochs dropped by first using other steps to preprocess the data. We will use a high-pass filter first to remove slow drift that could cause epochs to be dropped.
When making this decision to filter the data, we do want to be careful because filtering can spread sharp, high-frequency transients and distort the phase of the signal. Most evoked response potential analyses use filtering since the interest is in the time series, but if you are doing a frequency based analysis, filtering before the Fourier transform could potentially be avoided by detrending instead.
raw.filter(l_freq=1, h_freq=None)
epochs = mne.make_fixed_length_epochs(raw, duration=3, preload=True)
ar = autoreject.AutoReject(n_interpolate=[1, 2, 3, 4], random_state=11,
n_jobs=1, verbose=True)
ar.fit(epochs[:20]) # fit on a few epochs to save time
epochs_ar, reject_log = ar.transform(epochs, return_log=True)
Filtering raw data in 1 contiguous segment
Setting up high-pass filter at 1 Hz
FIR filter parameters
---------------------
Designing a one-pass, zero-phase, non-causal highpass filter:
- Windowed time-domain design (firwin) method
- Hamming window with 0.0194 passband ripple and 53 dB stopband attenuation
- Lower passband edge: 1.00
- Lower transition bandwidth: 1.00 Hz (-6 dB cutoff frequency: 0.50 Hz)
- Filter length: 1691 samples (3.303 s)
[Parallel(n_jobs=1)]: Done 17 tasks | elapsed: 0.1s
Not setting metadata
97 matching events found
No baseline correction applied
0 projection items activated
Using data from preloaded Raw for 97 events and 1536 original time points ...
0 bad epochs dropped
Running autoreject on ch_type=eeg
0%| | Creating augmented epochs : 0/32 [00:00<?, ?it/s]
6%|β | Creating augmented epochs : 2/32 [00:00<00:00, 109.72it/s]
12%|ββ | Creating augmented epochs : 4/32 [00:00<00:00, 107.81it/s]
19%|ββ | Creating augmented epochs : 6/32 [00:00<00:00, 107.59it/s]
25%|βββ | Creating augmented epochs : 8/32 [00:00<00:00, 108.38it/s]
31%|ββββ | Creating augmented epochs : 10/32 [00:00<00:00, 107.37it/s]
38%|ββββ | Creating augmented epochs : 12/32 [00:00<00:00, 107.90it/s]
44%|βββββ | Creating augmented epochs : 14/32 [00:00<00:00, 107.36it/s]
50%|βββββ | Creating augmented epochs : 16/32 [00:00<00:00, 106.75it/s]
56%|ββββββ | Creating augmented epochs : 18/32 [00:00<00:00, 107.27it/s]
62%|βββββββ | Creating augmented epochs : 20/32 [00:00<00:00, 106.93it/s]
69%|βββββββ | Creating augmented epochs : 22/32 [00:00<00:00, 106.18it/s]
75%|ββββββββ | Creating augmented epochs : 24/32 [00:00<00:00, 106.24it/s]
81%|βββββββββ | Creating augmented epochs : 26/32 [00:00<00:00, 106.25it/s]
88%|βββββββββ | Creating augmented epochs : 28/32 [00:00<00:00, 105.96it/s]
94%|ββββββββββ| Creating augmented epochs : 30/32 [00:00<00:00, 105.77it/s]
100%|ββββββββββ| Creating augmented epochs : 32/32 [00:00<00:00, 105.44it/s]
100%|ββββββββββ| Creating augmented epochs : 32/32 [00:00<00:00, 105.73it/s]
0%| | Computing thresholds ... : 0/32 [00:00<?, ?it/s]
3%|β | Computing thresholds ... : 1/32 [00:00<00:10, 2.83it/s]
6%|β | Computing thresholds ... : 2/32 [00:00<00:10, 2.74it/s]
9%|β | Computing thresholds ... : 3/32 [00:01<00:10, 2.71it/s]
12%|ββ | Computing thresholds ... : 4/32 [00:01<00:10, 2.70it/s]
16%|ββ | Computing thresholds ... : 5/32 [00:01<00:10, 2.69it/s]
19%|ββ | Computing thresholds ... : 6/32 [00:02<00:09, 2.68it/s]
22%|βββ | Computing thresholds ... : 7/32 [00:02<00:09, 2.67it/s]
25%|βββ | Computing thresholds ... : 8/32 [00:02<00:08, 2.67it/s]
28%|βββ | Computing thresholds ... : 9/32 [00:03<00:08, 2.67it/s]
31%|ββββ | Computing thresholds ... : 10/32 [00:03<00:08, 2.67it/s]
34%|ββββ | Computing thresholds ... : 11/32 [00:04<00:07, 2.67it/s]
38%|ββββ | Computing thresholds ... : 12/32 [00:04<00:07, 2.68it/s]
41%|ββββ | Computing thresholds ... : 13/32 [00:04<00:07, 2.68it/s]
44%|βββββ | Computing thresholds ... : 14/32 [00:05<00:06, 2.68it/s]
47%|βββββ | Computing thresholds ... : 15/32 [00:05<00:06, 2.68it/s]
50%|βββββ | Computing thresholds ... : 16/32 [00:05<00:05, 2.69it/s]
53%|ββββββ | Computing thresholds ... : 17/32 [00:06<00:05, 2.69it/s]
56%|ββββββ | Computing thresholds ... : 18/32 [00:06<00:05, 2.69it/s]
59%|ββββββ | Computing thresholds ... : 19/32 [00:07<00:04, 2.69it/s]
62%|βββββββ | Computing thresholds ... : 20/32 [00:07<00:04, 2.69it/s]
66%|βββββββ | Computing thresholds ... : 21/32 [00:07<00:04, 2.69it/s]
69%|βββββββ | Computing thresholds ... : 22/32 [00:08<00:03, 2.68it/s]
72%|ββββββββ | Computing thresholds ... : 23/32 [00:08<00:03, 2.68it/s]
75%|ββββββββ | Computing thresholds ... : 24/32 [00:08<00:02, 2.68it/s]
78%|ββββββββ | Computing thresholds ... : 25/32 [00:09<00:02, 2.68it/s]
81%|βββββββββ | Computing thresholds ... : 26/32 [00:09<00:02, 2.68it/s]
84%|βββββββββ | Computing thresholds ... : 27/32 [00:10<00:01, 2.68it/s]
88%|βββββββββ | Computing thresholds ... : 28/32 [00:10<00:01, 2.68it/s]
91%|βββββββββ | Computing thresholds ... : 29/32 [00:10<00:01, 2.68it/s]
94%|ββββββββββ| Computing thresholds ... : 30/32 [00:11<00:00, 2.68it/s]
97%|ββββββββββ| Computing thresholds ... : 31/32 [00:11<00:00, 2.67it/s]
100%|ββββββββββ| Computing thresholds ... : 32/32 [00:11<00:00, 2.67it/s]
100%|ββββββββββ| Computing thresholds ... : 32/32 [00:11<00:00, 2.68it/s]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
15%|ββ | Repairing epochs : 3/20 [00:00<00:00, 145.55it/s]
30%|βββ | Repairing epochs : 6/20 [00:00<00:00, 141.58it/s]
50%|βββββ | Repairing epochs : 10/20 [00:00<00:00, 163.15it/s]
70%|βββββββ | Repairing epochs : 14/20 [00:00<00:00, 173.69it/s]
90%|βββββββββ | Repairing epochs : 18/20 [00:00<00:00, 181.63it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 182.37it/s]
0%| | n_interp : 0/4 [00:00<?, ?it/s]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
10%|β | Repairing epochs : 2/20 [00:00<00:00, 94.17it/s]
25%|βββ | Repairing epochs : 5/20 [00:00<00:00, 107.00it/s]
35%|ββββ | Repairing epochs : 7/20 [00:00<00:00, 102.47it/s]
50%|βββββ | Repairing epochs : 10/20 [00:00<00:00, 114.73it/s]
60%|ββββββ | Repairing epochs : 12/20 [00:00<00:00, 115.78it/s]
75%|ββββββββ | Repairing epochs : 15/20 [00:00<00:00, 115.80it/s]
85%|βββββββββ | Repairing epochs : 17/20 [00:00<00:00, 112.16it/s]
95%|ββββββββββ| Repairing epochs : 19/20 [00:00<00:00, 108.98it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 108.03it/s]
0%| | Fold : 0/10 [00:00<?, ?it/s]
10%|β | Fold : 1/10 [00:00<00:00, 11.61it/s]
20%|ββ | Fold : 2/10 [00:00<00:00, 11.69it/s]
30%|βββ | Fold : 3/10 [00:00<00:00, 11.60it/s]
40%|ββββ | Fold : 4/10 [00:00<00:00, 11.61it/s]
50%|βββββ | Fold : 5/10 [00:00<00:00, 11.55it/s]
60%|ββββββ | Fold : 6/10 [00:00<00:00, 11.56it/s]
70%|βββββββ | Fold : 7/10 [00:00<00:00, 11.48it/s]
80%|ββββββββ | Fold : 8/10 [00:00<00:00, 11.37it/s]
90%|βββββββββ | Fold : 9/10 [00:00<00:00, 11.37it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 11.39it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 11.41it/s]
25%|βββ | n_interp : 1/4 [00:01<00:03, 1.10s/it]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
10%|β | Repairing epochs : 2/20 [00:00<00:00, 86.18it/s]
20%|ββ | Repairing epochs : 4/20 [00:00<00:00, 99.13it/s]
30%|βββ | Repairing epochs : 6/20 [00:00<00:00, 97.46it/s]
40%|ββββ | Repairing epochs : 8/20 [00:00<00:00, 101.80it/s]
55%|ββββββ | Repairing epochs : 11/20 [00:00<00:00, 111.78it/s]
65%|βββββββ | Repairing epochs : 13/20 [00:00<00:00, 111.75it/s]
75%|ββββββββ | Repairing epochs : 15/20 [00:00<00:00, 106.96it/s]
85%|βββββββββ | Repairing epochs : 17/20 [00:00<00:00, 104.67it/s]
95%|ββββββββββ| Repairing epochs : 19/20 [00:00<00:00, 102.97it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 102.39it/s]
0%| | Fold : 0/10 [00:00<?, ?it/s]
10%|β | Fold : 1/10 [00:00<00:00, 10.68it/s]
20%|ββ | Fold : 2/10 [00:00<00:00, 10.62it/s]
30%|βββ | Fold : 3/10 [00:00<00:00, 10.68it/s]
40%|ββββ | Fold : 4/10 [00:00<00:00, 10.68it/s]
50%|βββββ | Fold : 5/10 [00:00<00:00, 10.70it/s]
60%|ββββββ | Fold : 6/10 [00:00<00:00, 10.71it/s]
70%|βββββββ | Fold : 7/10 [00:00<00:00, 10.68it/s]
80%|ββββββββ | Fold : 8/10 [00:00<00:00, 10.69it/s]
90%|βββββββββ | Fold : 9/10 [00:00<00:00, 10.68it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 10.64it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 10.65it/s]
50%|βββββ | n_interp : 2/4 [00:02<00:02, 1.14s/it]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
10%|β | Repairing epochs : 2/20 [00:00<00:00, 89.15it/s]
25%|βββ | Repairing epochs : 5/20 [00:00<00:00, 102.48it/s]
35%|ββββ | Repairing epochs : 7/20 [00:00<00:00, 98.60it/s]
50%|βββββ | Repairing epochs : 10/20 [00:00<00:00, 108.44it/s]
60%|ββββββ | Repairing epochs : 12/20 [00:00<00:00, 110.12it/s]
70%|βββββββ | Repairing epochs : 14/20 [00:00<00:00, 111.47it/s]
80%|ββββββββ | Repairing epochs : 16/20 [00:00<00:00, 107.48it/s]
90%|βββββββββ | Repairing epochs : 18/20 [00:00<00:00, 105.30it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 103.32it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 103.69it/s]
0%| | Fold : 0/10 [00:00<?, ?it/s]
10%|β | Fold : 1/10 [00:00<00:00, 10.79it/s]
20%|ββ | Fold : 2/10 [00:00<00:00, 10.61it/s]
30%|βββ | Fold : 3/10 [00:00<00:00, 10.66it/s]
40%|ββββ | Fold : 4/10 [00:00<00:00, 10.69it/s]
50%|βββββ | Fold : 5/10 [00:00<00:00, 10.70it/s]
60%|ββββββ | Fold : 6/10 [00:00<00:00, 10.76it/s]
70%|βββββββ | Fold : 7/10 [00:00<00:00, 10.79it/s]
80%|ββββββββ | Fold : 8/10 [00:00<00:00, 10.88it/s]
90%|βββββββββ | Fold : 9/10 [00:00<00:00, 10.91it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 10.94it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 10.90it/s]
75%|ββββββββ | n_interp : 3/4 [00:03<00:01, 1.14s/it]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
10%|β | Repairing epochs : 2/20 [00:00<00:00, 98.89it/s]
25%|βββ | Repairing epochs : 5/20 [00:00<00:00, 108.84it/s]
35%|ββββ | Repairing epochs : 7/20 [00:00<00:00, 104.22it/s]
50%|βββββ | Repairing epochs : 10/20 [00:00<00:00, 115.37it/s]
60%|ββββββ | Repairing epochs : 12/20 [00:00<00:00, 115.88it/s]
70%|βββββββ | Repairing epochs : 14/20 [00:00<00:00, 116.82it/s]
80%|ββββββββ | Repairing epochs : 16/20 [00:00<00:00, 111.85it/s]
90%|βββββββββ | Repairing epochs : 18/20 [00:00<00:00, 108.87it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 106.72it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 107.39it/s]
0%| | Fold : 0/10 [00:00<?, ?it/s]
10%|β | Fold : 1/10 [00:00<00:00, 12.63it/s]
20%|ββ | Fold : 2/10 [00:00<00:00, 12.75it/s]
30%|βββ | Fold : 3/10 [00:00<00:00, 12.69it/s]
40%|ββββ | Fold : 4/10 [00:00<00:00, 12.73it/s]
50%|βββββ | Fold : 5/10 [00:00<00:00, 12.80it/s]
60%|ββββββ | Fold : 6/10 [00:00<00:00, 12.84it/s]
70%|βββββββ | Fold : 7/10 [00:00<00:00, 12.80it/s]
80%|ββββββββ | Fold : 8/10 [00:00<00:00, 12.78it/s]
90%|βββββββββ | Fold : 9/10 [00:00<00:00, 12.74it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 12.71it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 12.72it/s]
100%|ββββββββββ| n_interp : 4/4 [00:04<00:00, 1.10s/it]
100%|ββββββββββ| n_interp : 4/4 [00:04<00:00, 1.11s/it]
Estimated consensus=0.40 and n_interpolate=4
0%| | Repairing epochs : 0/97 [00:00<?, ?it/s]
1%| | Repairing epochs : 1/97 [00:00<00:02, 38.98it/s]
2%|β | Repairing epochs : 2/97 [00:00<00:02, 39.41it/s]
3%|β | Repairing epochs : 3/97 [00:00<00:02, 39.51it/s]
4%|β | Repairing epochs : 4/97 [00:00<00:02, 41.50it/s]
5%|β | Repairing epochs : 5/97 [00:00<00:02, 40.76it/s]
6%|β | Repairing epochs : 6/97 [00:00<00:02, 40.15it/s]
7%|β | Repairing epochs : 7/97 [00:00<00:02, 39.78it/s]
8%|β | Repairing epochs : 8/97 [00:00<00:02, 40.90it/s]
9%|β | Repairing epochs : 9/97 [00:00<00:02, 41.85it/s]
10%|β | Repairing epochs : 10/97 [00:00<00:02, 41.31it/s]
11%|ββ | Repairing epochs : 11/97 [00:00<00:02, 42.08it/s]
12%|ββ | Repairing epochs : 12/97 [00:00<00:02, 41.45it/s]
13%|ββ | Repairing epochs : 13/97 [00:00<00:01, 42.13it/s]
14%|ββ | Repairing epochs : 14/97 [00:00<00:01, 41.93it/s]
15%|ββ | Repairing epochs : 15/97 [00:00<00:01, 41.68it/s]
16%|ββ | Repairing epochs : 16/97 [00:00<00:01, 41.34it/s]
18%|ββ | Repairing epochs : 17/97 [00:00<00:01, 41.16it/s]
19%|ββ | Repairing epochs : 18/97 [00:00<00:01, 40.92it/s]
20%|ββ | Repairing epochs : 19/97 [00:00<00:01, 40.75it/s]
21%|ββ | Repairing epochs : 20/97 [00:00<00:01, 40.63it/s]
22%|βββ | Repairing epochs : 21/97 [00:00<00:01, 40.61it/s]
23%|βββ | Repairing epochs : 22/97 [00:00<00:01, 40.46it/s]
24%|βββ | Repairing epochs : 23/97 [00:00<00:01, 40.35it/s]
25%|βββ | Repairing epochs : 24/97 [00:00<00:01, 40.18it/s]
26%|βββ | Repairing epochs : 25/97 [00:00<00:01, 40.15it/s]
27%|βββ | Repairing epochs : 26/97 [00:00<00:01, 40.09it/s]
28%|βββ | Repairing epochs : 27/97 [00:00<00:01, 39.97it/s]
29%|βββ | Repairing epochs : 28/97 [00:00<00:01, 39.90it/s]
30%|βββ | Repairing epochs : 29/97 [00:00<00:01, 39.77it/s]
31%|βββ | Repairing epochs : 30/97 [00:00<00:01, 39.69it/s]
32%|ββββ | Repairing epochs : 31/97 [00:00<00:01, 39.61it/s]
33%|ββββ | Repairing epochs : 32/97 [00:00<00:01, 39.55it/s]
34%|ββββ | Repairing epochs : 33/97 [00:00<00:01, 39.49it/s]
35%|ββββ | Repairing epochs : 34/97 [00:00<00:01, 39.48it/s]
36%|ββββ | Repairing epochs : 35/97 [00:00<00:01, 39.35it/s]
37%|ββββ | Repairing epochs : 36/97 [00:00<00:01, 39.19it/s]
38%|ββββ | Repairing epochs : 37/97 [00:00<00:01, 39.15it/s]
39%|ββββ | Repairing epochs : 38/97 [00:00<00:01, 39.16it/s]
40%|ββββ | Repairing epochs : 39/97 [00:00<00:01, 39.07it/s]
41%|ββββ | Repairing epochs : 40/97 [00:01<00:01, 39.05it/s]
42%|βββββ | Repairing epochs : 41/97 [00:01<00:01, 38.98it/s]
43%|βββββ | Repairing epochs : 42/97 [00:01<00:01, 38.94it/s]
44%|βββββ | Repairing epochs : 43/97 [00:01<00:01, 38.82it/s]
45%|βββββ | Repairing epochs : 44/97 [00:01<00:01, 38.83it/s]
46%|βββββ | Repairing epochs : 45/97 [00:01<00:01, 38.88it/s]
47%|βββββ | Repairing epochs : 46/97 [00:01<00:01, 38.80it/s]
48%|βββββ | Repairing epochs : 47/97 [00:01<00:01, 38.80it/s]
49%|βββββ | Repairing epochs : 48/97 [00:01<00:01, 38.81it/s]
51%|βββββ | Repairing epochs : 49/97 [00:01<00:01, 38.85it/s]
52%|ββββββ | Repairing epochs : 50/97 [00:01<00:01, 38.75it/s]
53%|ββββββ | Repairing epochs : 51/97 [00:01<00:01, 38.73it/s]
54%|ββββββ | Repairing epochs : 52/97 [00:01<00:01, 38.77it/s]
55%|ββββββ | Repairing epochs : 53/97 [00:01<00:01, 38.81it/s]
56%|ββββββ | Repairing epochs : 54/97 [00:01<00:01, 38.62it/s]
57%|ββββββ | Repairing epochs : 55/97 [00:01<00:01, 38.65it/s]
58%|ββββββ | Repairing epochs : 56/97 [00:01<00:01, 38.71it/s]
59%|ββββββ | Repairing epochs : 57/97 [00:01<00:01, 38.70it/s]
60%|ββββββ | Repairing epochs : 58/97 [00:01<00:01, 38.72it/s]
61%|ββββββ | Repairing epochs : 59/97 [00:01<00:00, 38.77it/s]
62%|βββββββ | Repairing epochs : 60/97 [00:01<00:00, 38.73it/s]
63%|βββββββ | Repairing epochs : 61/97 [00:01<00:00, 38.64it/s]
64%|βββββββ | Repairing epochs : 62/97 [00:01<00:00, 38.60it/s]
65%|βββββββ | Repairing epochs : 63/97 [00:01<00:00, 38.55it/s]
66%|βββββββ | Repairing epochs : 64/97 [00:01<00:00, 38.60it/s]
67%|βββββββ | Repairing epochs : 65/97 [00:01<00:00, 38.56it/s]
68%|βββββββ | Repairing epochs : 66/97 [00:01<00:00, 38.54it/s]
69%|βββββββ | Repairing epochs : 67/97 [00:01<00:00, 38.57it/s]
70%|βββββββ | Repairing epochs : 68/97 [00:01<00:00, 38.63it/s]
71%|βββββββ | Repairing epochs : 69/97 [00:01<00:00, 38.70it/s]
72%|ββββββββ | Repairing epochs : 70/97 [00:01<00:00, 38.68it/s]
73%|ββββββββ | Repairing epochs : 71/97 [00:01<00:00, 38.65it/s]
74%|ββββββββ | Repairing epochs : 72/97 [00:01<00:00, 38.61it/s]
75%|ββββββββ | Repairing epochs : 73/97 [00:01<00:00, 38.66it/s]
76%|ββββββββ | Repairing epochs : 74/97 [00:01<00:00, 38.61it/s]
77%|ββββββββ | Repairing epochs : 75/97 [00:01<00:00, 38.65it/s]
78%|ββββββββ | Repairing epochs : 76/97 [00:01<00:00, 38.68it/s]
79%|ββββββββ | Repairing epochs : 77/97 [00:01<00:00, 38.60it/s]
80%|ββββββββ | Repairing epochs : 78/97 [00:01<00:00, 38.58it/s]
81%|βββββββββ | Repairing epochs : 79/97 [00:02<00:00, 38.64it/s]
82%|βββββββββ | Repairing epochs : 80/97 [00:02<00:00, 38.70it/s]
84%|βββββββββ | Repairing epochs : 81/97 [00:02<00:00, 38.73it/s]
85%|βββββββββ | Repairing epochs : 82/97 [00:02<00:00, 38.77it/s]
86%|βββββββββ | Repairing epochs : 83/97 [00:02<00:00, 38.81it/s]
87%|βββββββββ | Repairing epochs : 84/97 [00:02<00:00, 38.73it/s]
88%|βββββββββ | Repairing epochs : 85/97 [00:02<00:00, 38.79it/s]
89%|βββββββββ | Repairing epochs : 86/97 [00:02<00:00, 38.80it/s]
90%|βββββββββ | Repairing epochs : 87/97 [00:02<00:00, 38.78it/s]
91%|βββββββββ | Repairing epochs : 88/97 [00:02<00:00, 38.74it/s]
92%|ββββββββββ| Repairing epochs : 89/97 [00:02<00:00, 38.77it/s]
93%|ββββββββββ| Repairing epochs : 90/97 [00:02<00:00, 38.77it/s]
94%|ββββββββββ| Repairing epochs : 91/97 [00:02<00:00, 38.76it/s]
95%|ββββββββββ| Repairing epochs : 92/97 [00:02<00:00, 38.75it/s]
96%|ββββββββββ| Repairing epochs : 93/97 [00:02<00:00, 38.81it/s]
97%|ββββββββββ| Repairing epochs : 94/97 [00:02<00:00, 38.78it/s]
98%|ββββββββββ| Repairing epochs : 95/97 [00:02<00:00, 38.69it/s]
99%|ββββββββββ| Repairing epochs : 96/97 [00:02<00:00, 38.68it/s]
100%|ββββββββββ| Repairing epochs : 97/97 [00:02<00:00, 38.68it/s]
100%|ββββββββββ| Repairing epochs : 97/97 [00:02<00:00, 39.04it/s]
Dropped 23 epochs: 62, 63, 64, 65, 67, 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 80, 86, 89, 91, 92, 95, 96
visualize the dropped epochs
epochs[reject_log.bad_epochs].plot(scalings=dict(eeg=100e-6))
<MNEBrowseFigure size 800x800 with 4 Axes>
and the reject log. As we can see in the plot, high-pass filtering reduced the number of epochs marked as bad by autoreject. This is because low-frequency drifts can inflate peak-to-peak amplitude when an upward drift aligns with a peak.
reject_log.plot('horizontal')
<Figure size 1200x600 with 1 Axes>
ICA#
Finally, we can apply independent components analysis (ICA) to remove eyeblinks from the data. If our analysis were to be very dependent on sensors at the front of the head, we could skip ICA and use the previous result. However, ICA can increase the amount of usable data by applying a spatial filter that downscales the data in sensors most affected by eyeblink artifacts.
Note that ICA works best if bad segments of the data are removed Hence, we will remove the bad segments from the previous run of autoreject for the benefit of the ICA algorithm.
# compute ICA
ica = mne.preprocessing.ICA(random_state=99)
ica.fit(epochs[~reject_log.bad_epochs])
Fitting ICA to data using 32 channels (please be patient, this may take a while)
Selecting by non-zero PCA components: 32 components
Fitting ICA took 2.5s.
We can see in the plots below that ICA effectively removed eyeblink artifact.
plot source components to see which is made up of blinks
exclude = [0, # blinks
2 # saccades
]
ica.plot_components(exclude)
ica.exclude = exclude
plot with and without eyeblink component
Applying ICA to Evoked instance
Transforming to ICA space (32 components)
Zeroing out 2 ICA components
Projecting back using 32 PCA components
Applying ICA to Epochs instance
Transforming to ICA space (32 components)
Zeroing out 2 ICA components
Projecting back using 32 PCA components
Autoreject with highpass filter and ICA#
We can see in this section that preprocessing, especially ICA, can be made to do a lot of the heavy lifting. There isnβt a huge difference when viewing the averaged data because the ICA effectively limited the number of epochs that had to be dropped. However, there are still artifacts such as non-stereotypical blinks that werenβt able to be removed by ICA, channel βpopsβ (sharp transients with exponential RC decay), muscle artifact such as jaw clenches and gross movement artifact that could still impact analyses.
These are the basic steps for a workflow with decisions that must be
made based on what the data is being used for. Following this may help
you optimize your use of autoreject
in preprocessing.
# compute channel-level rejections
ar = autoreject.AutoReject(n_interpolate=[1, 2, 3, 4], random_state=11,
n_jobs=1, verbose=True)
ar.fit(epochs[:20]) # fit on the first 20 epochs to save time
epochs_ar, reject_log = ar.transform(epochs, return_log=True)
epochs[reject_log.bad_epochs].plot(scalings=dict(eeg=100e-6))
Running autoreject on ch_type=eeg
0%| | Creating augmented epochs : 0/32 [00:00<?, ?it/s]
6%|β | Creating augmented epochs : 2/32 [00:00<00:00, 108.64it/s]
12%|ββ | Creating augmented epochs : 4/32 [00:00<00:00, 107.08it/s]
19%|ββ | Creating augmented epochs : 6/32 [00:00<00:00, 106.04it/s]
25%|βββ | Creating augmented epochs : 8/32 [00:00<00:00, 106.60it/s]
31%|ββββ | Creating augmented epochs : 10/32 [00:00<00:00, 105.53it/s]
38%|ββββ | Creating augmented epochs : 12/32 [00:00<00:00, 106.07it/s]
44%|βββββ | Creating augmented epochs : 14/32 [00:00<00:00, 105.88it/s]
50%|βββββ | Creating augmented epochs : 16/32 [00:00<00:00, 105.57it/s]
56%|ββββββ | Creating augmented epochs : 18/32 [00:00<00:00, 105.95it/s]
62%|βββββββ | Creating augmented epochs : 20/32 [00:00<00:00, 105.62it/s]
69%|βββββββ | Creating augmented epochs : 22/32 [00:00<00:00, 105.17it/s]
75%|ββββββββ | Creating augmented epochs : 24/32 [00:00<00:00, 105.68it/s]
81%|βββββββββ | Creating augmented epochs : 26/32 [00:00<00:00, 105.98it/s]
88%|βββββββββ | Creating augmented epochs : 28/32 [00:00<00:00, 105.69it/s]
94%|ββββββββββ| Creating augmented epochs : 30/32 [00:00<00:00, 105.62it/s]
100%|ββββββββββ| Creating augmented epochs : 32/32 [00:00<00:00, 105.16it/s]
100%|ββββββββββ| Creating augmented epochs : 32/32 [00:00<00:00, 105.25it/s]
0%| | Computing thresholds ... : 0/32 [00:00<?, ?it/s]
3%|β | Computing thresholds ... : 1/32 [00:00<00:11, 2.76it/s]
6%|β | Computing thresholds ... : 2/32 [00:00<00:11, 2.68it/s]
9%|β | Computing thresholds ... : 3/32 [00:01<00:10, 2.66it/s]
12%|ββ | Computing thresholds ... : 4/32 [00:01<00:10, 2.65it/s]
16%|ββ | Computing thresholds ... : 5/32 [00:01<00:10, 2.65it/s]
19%|ββ | Computing thresholds ... : 6/32 [00:02<00:09, 2.64it/s]
22%|βββ | Computing thresholds ... : 7/32 [00:02<00:09, 2.64it/s]
25%|βββ | Computing thresholds ... : 8/32 [00:03<00:09, 2.64it/s]
28%|βββ | Computing thresholds ... : 9/32 [00:03<00:08, 2.64it/s]
31%|ββββ | Computing thresholds ... : 10/32 [00:03<00:08, 2.64it/s]
34%|ββββ | Computing thresholds ... : 11/32 [00:04<00:07, 2.63it/s]
38%|ββββ | Computing thresholds ... : 12/32 [00:04<00:07, 2.64it/s]
41%|ββββ | Computing thresholds ... : 13/32 [00:04<00:07, 2.64it/s]
44%|βββββ | Computing thresholds ... : 14/32 [00:05<00:06, 2.64it/s]
47%|βββββ | Computing thresholds ... : 15/32 [00:05<00:06, 2.64it/s]
50%|βββββ | Computing thresholds ... : 16/32 [00:06<00:06, 2.64it/s]
53%|ββββββ | Computing thresholds ... : 17/32 [00:06<00:05, 2.65it/s]
56%|ββββββ | Computing thresholds ... : 18/32 [00:06<00:05, 2.65it/s]
59%|ββββββ | Computing thresholds ... : 19/32 [00:07<00:04, 2.65it/s]
62%|βββββββ | Computing thresholds ... : 20/32 [00:07<00:04, 2.65it/s]
66%|βββββββ | Computing thresholds ... : 21/32 [00:07<00:04, 2.65it/s]
69%|βββββββ | Computing thresholds ... : 22/32 [00:08<00:03, 2.65it/s]
72%|ββββββββ | Computing thresholds ... : 23/32 [00:08<00:03, 2.64it/s]
75%|ββββββββ | Computing thresholds ... : 24/32 [00:09<00:03, 2.64it/s]
78%|ββββββββ | Computing thresholds ... : 25/32 [00:09<00:02, 2.64it/s]
81%|βββββββββ | Computing thresholds ... : 26/32 [00:09<00:02, 2.64it/s]
84%|βββββββββ | Computing thresholds ... : 27/32 [00:10<00:01, 2.64it/s]
88%|βββββββββ | Computing thresholds ... : 28/32 [00:10<00:01, 2.64it/s]
91%|βββββββββ | Computing thresholds ... : 29/32 [00:10<00:01, 2.63it/s]
94%|ββββββββββ| Computing thresholds ... : 30/32 [00:11<00:00, 2.63it/s]
97%|ββββββββββ| Computing thresholds ... : 31/32 [00:11<00:00, 2.63it/s]
100%|ββββββββββ| Computing thresholds ... : 32/32 [00:12<00:00, 2.63it/s]
100%|ββββββββββ| Computing thresholds ... : 32/32 [00:12<00:00, 2.64it/s]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
15%|ββ | Repairing epochs : 3/20 [00:00<00:00, 142.04it/s]
30%|βββ | Repairing epochs : 6/20 [00:00<00:00, 140.43it/s]
45%|βββββ | Repairing epochs : 9/20 [00:00<00:00, 149.00it/s]
65%|βββββββ | Repairing epochs : 13/20 [00:00<00:00, 161.65it/s]
85%|βββββββββ | Repairing epochs : 17/20 [00:00<00:00, 171.18it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 173.56it/s]
0%| | n_interp : 0/4 [00:00<?, ?it/s]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
20%|ββ | Repairing epochs : 4/20 [00:00<00:00, 204.47it/s]
30%|βββ | Repairing epochs : 6/20 [00:00<00:00, 147.47it/s]
50%|βββββ | Repairing epochs : 10/20 [00:00<00:00, 151.52it/s]
65%|βββββββ | Repairing epochs : 13/20 [00:00<00:00, 148.76it/s]
75%|ββββββββ | Repairing epochs : 15/20 [00:00<00:00, 135.41it/s]
85%|βββββββββ | Repairing epochs : 17/20 [00:00<00:00, 126.92it/s]
95%|ββββββββββ| Repairing epochs : 19/20 [00:00<00:00, 120.93it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 121.59it/s]
0%| | Fold : 0/10 [00:00<?, ?it/s]
10%|β | Fold : 1/10 [00:00<00:00, 11.44it/s]
20%|ββ | Fold : 2/10 [00:00<00:00, 11.26it/s]
30%|βββ | Fold : 3/10 [00:00<00:00, 11.14it/s]
40%|ββββ | Fold : 4/10 [00:00<00:00, 11.11it/s]
50%|βββββ | Fold : 5/10 [00:00<00:00, 11.15it/s]
60%|ββββββ | Fold : 6/10 [00:00<00:00, 11.18it/s]
70%|βββββββ | Fold : 7/10 [00:00<00:00, 11.24it/s]
80%|ββββββββ | Fold : 8/10 [00:00<00:00, 11.31it/s]
90%|βββββββββ | Fold : 9/10 [00:00<00:00, 11.31it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 11.24it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 11.24it/s]
25%|βββ | n_interp : 1/4 [00:01<00:03, 1.08s/it]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
20%|ββ | Repairing epochs : 4/20 [00:00<00:00, 208.37it/s]
30%|βββ | Repairing epochs : 6/20 [00:00<00:00, 146.18it/s]
50%|βββββ | Repairing epochs : 10/20 [00:00<00:00, 150.08it/s]
65%|βββββββ | Repairing epochs : 13/20 [00:00<00:00, 146.11it/s]
75%|ββββββββ | Repairing epochs : 15/20 [00:00<00:00, 134.04it/s]
85%|βββββββββ | Repairing epochs : 17/20 [00:00<00:00, 127.23it/s]
95%|ββββββββββ| Repairing epochs : 19/20 [00:00<00:00, 122.24it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 122.50it/s]
0%| | Fold : 0/10 [00:00<?, ?it/s]
10%|β | Fold : 1/10 [00:00<00:00, 11.61it/s]
20%|ββ | Fold : 2/10 [00:00<00:00, 11.52it/s]
30%|βββ | Fold : 3/10 [00:00<00:00, 11.52it/s]
40%|ββββ | Fold : 4/10 [00:00<00:00, 11.53it/s]
50%|βββββ | Fold : 5/10 [00:00<00:00, 11.51it/s]
60%|ββββββ | Fold : 6/10 [00:00<00:00, 11.52it/s]
70%|βββββββ | Fold : 7/10 [00:00<00:00, 11.54it/s]
80%|ββββββββ | Fold : 8/10 [00:00<00:00, 11.52it/s]
90%|βββββββββ | Fold : 9/10 [00:00<00:00, 11.41it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 11.33it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 11.36it/s]
50%|βββββ | n_interp : 2/4 [00:02<00:02, 1.08s/it]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
20%|ββ | Repairing epochs : 4/20 [00:00<00:00, 210.85it/s]
30%|βββ | Repairing epochs : 6/20 [00:00<00:00, 144.64it/s]
45%|βββββ | Repairing epochs : 9/20 [00:00<00:00, 156.53it/s]
55%|ββββββ | Repairing epochs : 11/20 [00:00<00:00, 148.66it/s]
70%|βββββββ | Repairing epochs : 14/20 [00:00<00:00, 137.58it/s]
80%|ββββββββ | Repairing epochs : 16/20 [00:00<00:00, 128.11it/s]
90%|βββββββββ | Repairing epochs : 18/20 [00:00<00:00, 121.94it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 117.17it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 120.15it/s]
0%| | Fold : 0/10 [00:00<?, ?it/s]
10%|β | Fold : 1/10 [00:00<00:00, 11.20it/s]
20%|ββ | Fold : 2/10 [00:00<00:00, 11.00it/s]
30%|βββ | Fold : 3/10 [00:00<00:00, 11.02it/s]
40%|ββββ | Fold : 4/10 [00:00<00:00, 11.02it/s]
50%|βββββ | Fold : 5/10 [00:00<00:00, 10.97it/s]
60%|ββββββ | Fold : 6/10 [00:00<00:00, 10.98it/s]
70%|βββββββ | Fold : 7/10 [00:00<00:00, 11.02it/s]
80%|ββββββββ | Fold : 8/10 [00:00<00:00, 11.07it/s]
90%|βββββββββ | Fold : 9/10 [00:00<00:00, 10.99it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 11.03it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 11.03it/s]
75%|ββββββββ | n_interp : 3/4 [00:03<00:01, 1.09s/it]
0%| | Repairing epochs : 0/20 [00:00<?, ?it/s]
20%|ββ | Repairing epochs : 4/20 [00:00<00:00, 207.74it/s]
30%|βββ | Repairing epochs : 6/20 [00:00<00:00, 144.33it/s]
50%|βββββ | Repairing epochs : 10/20 [00:00<00:00, 148.72it/s]
60%|ββββββ | Repairing epochs : 12/20 [00:00<00:00, 143.17it/s]
75%|ββββββββ | Repairing epochs : 15/20 [00:00<00:00, 133.98it/s]
85%|βββββββββ | Repairing epochs : 17/20 [00:00<00:00, 126.99it/s]
95%|ββββββββββ| Repairing epochs : 19/20 [00:00<00:00, 120.29it/s]
100%|ββββββββββ| Repairing epochs : 20/20 [00:00<00:00, 120.63it/s]
0%| | Fold : 0/10 [00:00<?, ?it/s]
10%|β | Fold : 1/10 [00:00<00:00, 12.55it/s]
20%|ββ | Fold : 2/10 [00:00<00:00, 12.51it/s]
30%|βββ | Fold : 3/10 [00:00<00:00, 12.50it/s]
40%|ββββ | Fold : 4/10 [00:00<00:00, 12.50it/s]
50%|βββββ | Fold : 5/10 [00:00<00:00, 12.44it/s]
60%|ββββββ | Fold : 6/10 [00:00<00:00, 12.42it/s]
70%|βββββββ | Fold : 7/10 [00:00<00:00, 12.36it/s]
80%|ββββββββ | Fold : 8/10 [00:00<00:00, 12.30it/s]
90%|βββββββββ | Fold : 9/10 [00:00<00:00, 12.20it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 12.24it/s]
100%|ββββββββββ| Fold : 10/10 [00:00<00:00, 12.26it/s]
100%|ββββββββββ| n_interp : 4/4 [00:04<00:00, 1.06s/it]
100%|ββββββββββ| n_interp : 4/4 [00:04<00:00, 1.06s/it]
Estimated consensus=0.40 and n_interpolate=2
0%| | Repairing epochs : 0/97 [00:00<?, ?it/s]
1%| | Repairing epochs : 1/97 [00:00<00:01, 48.46it/s]
2%|β | Repairing epochs : 2/97 [00:00<00:01, 48.07it/s]
3%|β | Repairing epochs : 3/97 [00:00<00:01, 48.01it/s]
4%|β | Repairing epochs : 4/97 [00:00<00:01, 48.07it/s]
5%|β | Repairing epochs : 5/97 [00:00<00:02, 45.69it/s]
6%|β | Repairing epochs : 6/97 [00:00<00:02, 44.34it/s]
7%|β | Repairing epochs : 7/97 [00:00<00:01, 45.25it/s]
8%|β | Repairing epochs : 8/97 [00:00<00:01, 46.03it/s]
9%|β | Repairing epochs : 9/97 [00:00<00:01, 46.44it/s]
10%|β | Repairing epochs : 10/97 [00:00<00:01, 45.49it/s]
11%|ββ | Repairing epochs : 11/97 [00:00<00:01, 45.87it/s]
12%|ββ | Repairing epochs : 12/97 [00:00<00:01, 44.97it/s]
13%|ββ | Repairing epochs : 13/97 [00:00<00:01, 45.48it/s]
14%|ββ | Repairing epochs : 14/97 [00:00<00:01, 44.80it/s]
15%|ββ | Repairing epochs : 15/97 [00:00<00:01, 44.17it/s]
16%|ββ | Repairing epochs : 16/97 [00:00<00:01, 43.76it/s]
18%|ββ | Repairing epochs : 17/97 [00:00<00:01, 43.29it/s]
19%|ββ | Repairing epochs : 18/97 [00:00<00:01, 42.95it/s]
20%|ββ | Repairing epochs : 19/97 [00:00<00:01, 42.60it/s]
21%|ββ | Repairing epochs : 20/97 [00:00<00:01, 42.26it/s]
22%|βββ | Repairing epochs : 21/97 [00:00<00:01, 42.13it/s]
23%|βββ | Repairing epochs : 22/97 [00:00<00:01, 41.87it/s]
24%|βββ | Repairing epochs : 23/97 [00:00<00:01, 41.76it/s]
25%|βββ | Repairing epochs : 24/97 [00:00<00:01, 41.65it/s]
26%|βββ | Repairing epochs : 25/97 [00:00<00:01, 41.49it/s]
27%|βββ | Repairing epochs : 26/97 [00:00<00:01, 41.35it/s]
28%|βββ | Repairing epochs : 27/97 [00:00<00:01, 40.99it/s]
29%|βββ | Repairing epochs : 28/97 [00:00<00:01, 40.66it/s]
30%|βββ | Repairing epochs : 29/97 [00:00<00:01, 40.66it/s]
31%|βββ | Repairing epochs : 30/97 [00:00<00:01, 40.59it/s]
32%|ββββ | Repairing epochs : 31/97 [00:00<00:01, 40.44it/s]
33%|ββββ | Repairing epochs : 32/97 [00:00<00:01, 40.38it/s]
34%|ββββ | Repairing epochs : 33/97 [00:00<00:01, 40.27it/s]
35%|ββββ | Repairing epochs : 34/97 [00:00<00:01, 40.30it/s]
36%|ββββ | Repairing epochs : 35/97 [00:00<00:01, 40.36it/s]
37%|ββββ | Repairing epochs : 36/97 [00:00<00:01, 40.35it/s]
38%|ββββ | Repairing epochs : 37/97 [00:00<00:01, 40.31it/s]
39%|ββββ | Repairing epochs : 38/97 [00:00<00:01, 40.17it/s]
40%|ββββ | Repairing epochs : 39/97 [00:00<00:01, 40.09it/s]
41%|ββββ | Repairing epochs : 40/97 [00:00<00:01, 40.55it/s]
42%|βββββ | Repairing epochs : 41/97 [00:00<00:01, 40.54it/s]
43%|βββββ | Repairing epochs : 42/97 [00:01<00:01, 40.48it/s]
44%|βββββ | Repairing epochs : 43/97 [00:01<00:01, 40.42it/s]
45%|βββββ | Repairing epochs : 44/97 [00:01<00:01, 40.35it/s]
46%|βββββ | Repairing epochs : 45/97 [00:01<00:01, 40.36it/s]
47%|βββββ | Repairing epochs : 46/97 [00:01<00:01, 40.34it/s]
48%|βββββ | Repairing epochs : 47/97 [00:01<00:01, 40.39it/s]
49%|βββββ | Repairing epochs : 48/97 [00:01<00:01, 40.34it/s]
51%|βββββ | Repairing epochs : 49/97 [00:01<00:01, 40.79it/s]
52%|ββββββ | Repairing epochs : 50/97 [00:01<00:01, 40.66it/s]
53%|ββββββ | Repairing epochs : 51/97 [00:01<00:01, 40.56it/s]
54%|ββββββ | Repairing epochs : 52/97 [00:01<00:01, 40.56it/s]
55%|ββββββ | Repairing epochs : 53/97 [00:01<00:01, 40.52it/s]
56%|ββββββ | Repairing epochs : 54/97 [00:01<00:01, 40.45it/s]
57%|ββββββ | Repairing epochs : 55/97 [00:01<00:01, 40.48it/s]
58%|ββββββ | Repairing epochs : 56/97 [00:01<00:01, 40.46it/s]
59%|ββββββ | Repairing epochs : 57/97 [00:01<00:00, 40.87it/s]
60%|ββββββ | Repairing epochs : 58/97 [00:01<00:00, 40.79it/s]
61%|ββββββ | Repairing epochs : 59/97 [00:01<00:00, 41.16it/s]
62%|βββββββ | Repairing epochs : 60/97 [00:01<00:00, 41.12it/s]
63%|βββββββ | Repairing epochs : 61/97 [00:01<00:00, 41.07it/s]
64%|βββββββ | Repairing epochs : 62/97 [00:01<00:00, 41.48it/s]
65%|βββββββ | Repairing epochs : 63/97 [00:01<00:00, 41.43it/s]
66%|βββββββ | Repairing epochs : 64/97 [00:01<00:00, 41.32it/s]
67%|βββββββ | Repairing epochs : 65/97 [00:01<00:00, 41.21it/s]
68%|βββββββ | Repairing epochs : 66/97 [00:01<00:00, 41.12it/s]
69%|βββββββ | Repairing epochs : 67/97 [00:01<00:00, 40.99it/s]
70%|βββββββ | Repairing epochs : 68/97 [00:01<00:00, 40.91it/s]
71%|βββββββ | Repairing epochs : 69/97 [00:01<00:00, 40.77it/s]
72%|ββββββββ | Repairing epochs : 70/97 [00:01<00:00, 40.69it/s]
73%|ββββββββ | Repairing epochs : 71/97 [00:01<00:00, 40.66it/s]
74%|ββββββββ | Repairing epochs : 72/97 [00:01<00:00, 40.62it/s]
75%|ββββββββ | Repairing epochs : 73/97 [00:01<00:00, 40.56it/s]
76%|ββββββββ | Repairing epochs : 74/97 [00:01<00:00, 40.50it/s]
77%|ββββββββ | Repairing epochs : 75/97 [00:01<00:00, 40.43it/s]
78%|ββββββββ | Repairing epochs : 76/97 [00:01<00:00, 40.45it/s]
79%|ββββββββ | Repairing epochs : 77/97 [00:01<00:00, 40.46it/s]
80%|ββββββββ | Repairing epochs : 78/97 [00:01<00:00, 40.38it/s]
81%|βββββββββ | Repairing epochs : 79/97 [00:01<00:00, 40.31it/s]
82%|βββββββββ | Repairing epochs : 80/97 [00:01<00:00, 40.23it/s]
84%|βββββββββ | Repairing epochs : 81/97 [00:01<00:00, 40.14it/s]
85%|βββββββββ | Repairing epochs : 82/97 [00:02<00:00, 40.09it/s]
86%|βββββββββ | Repairing epochs : 83/97 [00:02<00:00, 40.06it/s]
87%|βββββββββ | Repairing epochs : 84/97 [00:02<00:00, 39.96it/s]
88%|βββββββββ | Repairing epochs : 85/97 [00:02<00:00, 39.91it/s]
89%|βββββββββ | Repairing epochs : 86/97 [00:02<00:00, 39.90it/s]
90%|βββββββββ | Repairing epochs : 87/97 [00:02<00:00, 39.84it/s]
91%|βββββββββ | Repairing epochs : 88/97 [00:02<00:00, 39.79it/s]
92%|ββββββββββ| Repairing epochs : 89/97 [00:02<00:00, 39.76it/s]
93%|ββββββββββ| Repairing epochs : 90/97 [00:02<00:00, 39.67it/s]
94%|ββββββββββ| Repairing epochs : 91/97 [00:02<00:00, 39.68it/s]
95%|ββββββββββ| Repairing epochs : 92/97 [00:02<00:00, 39.57it/s]
96%|ββββββββββ| Repairing epochs : 93/97 [00:02<00:00, 39.54it/s]
97%|ββββββββββ| Repairing epochs : 94/97 [00:02<00:00, 39.55it/s]
98%|ββββββββββ| Repairing epochs : 95/97 [00:02<00:00, 39.59it/s]
99%|ββββββββββ| Repairing epochs : 96/97 [00:02<00:00, 39.56it/s]
100%|ββββββββββ| Repairing epochs : 97/97 [00:02<00:00, 39.49it/s]
100%|ββββββββββ| Repairing epochs : 97/97 [00:02<00:00, 40.57it/s]
Dropped 11 epochs: 62, 63, 64, 65, 69, 71, 72, 73, 80, 95, 96
<MNEBrowseFigure size 800x800 with 4 Axes>
We will do a few more visualizations to see that removing the bad epochs
found by autoreject
is still important even with preprocessing first.
This is especially important if your analyses include trial-level statistics
such as looking for bursting activity. Weβll visualize why autoreject
excluded these epochs and the effect that including these bad epochs would
have on the data.
First, we will visualize the reject log
reject_log.plot('horizontal')
<Figure size 1200x600 with 1 Axes>
Next, we will visualize the cleaned average data and compare it against the bad segments.
evoked_bad = epochs[reject_log.bad_epochs].average()
plt.figure()
plt.plot(evoked_bad.times, evoked_bad.data.T * 1e6, 'r', zorder=-1)
epochs_ar.average().plot(axes=plt.gca())
<Figure size 640x480 with 2 Axes>
As a last optional step, we can do inspect the reject_log and make manual corrections to the reject_log. For instance, if data is limited, we may not want to drop epochs but retain the list of bad epochs for quality assurance metrics.
reject_log = ar.get_reject_log(epochs)
bad_epochs = reject_log.bad_epochs.copy()
reject_log.bad_epochs[:] = False # no bad epochs
The modified reject log can be applied to the data as follows.
epochs_ar = ar.transform(epochs, reject_log=reject_log)
print(f'Number of epochs originally: {len(epochs)}, '
f'after autoreject: {len(epochs_ar)}')
0%| | Repairing epochs : 0/97 [00:00<?, ?it/s]
1%| | Repairing epochs : 1/97 [00:00<00:01, 51.25it/s]
2%|β | Repairing epochs : 2/97 [00:00<00:01, 50.84it/s]
3%|β | Repairing epochs : 3/97 [00:00<00:01, 50.78it/s]
4%|β | Repairing epochs : 4/97 [00:00<00:01, 50.61it/s]
5%|β | Repairing epochs : 5/97 [00:00<00:01, 47.34it/s]
6%|β | Repairing epochs : 6/97 [00:00<00:01, 45.71it/s]
7%|β | Repairing epochs : 7/97 [00:00<00:01, 46.37it/s]
8%|β | Repairing epochs : 8/97 [00:00<00:01, 46.91it/s]
9%|β | Repairing epochs : 9/97 [00:00<00:01, 47.28it/s]
10%|β | Repairing epochs : 10/97 [00:00<00:01, 45.96it/s]
11%|ββ | Repairing epochs : 11/97 [00:00<00:01, 46.41it/s]
12%|ββ | Repairing epochs : 12/97 [00:00<00:01, 45.49it/s]
13%|ββ | Repairing epochs : 13/97 [00:00<00:01, 45.91it/s]
14%|ββ | Repairing epochs : 14/97 [00:00<00:01, 45.25it/s]
15%|ββ | Repairing epochs : 15/97 [00:00<00:01, 44.61it/s]
16%|ββ | Repairing epochs : 16/97 [00:00<00:01, 44.11it/s]
18%|ββ | Repairing epochs : 17/97 [00:00<00:01, 43.63it/s]
19%|ββ | Repairing epochs : 18/97 [00:00<00:01, 43.19it/s]
20%|ββ | Repairing epochs : 19/97 [00:00<00:01, 42.86it/s]
21%|ββ | Repairing epochs : 20/97 [00:00<00:01, 42.33it/s]
22%|βββ | Repairing epochs : 21/97 [00:00<00:01, 42.12it/s]
23%|βββ | Repairing epochs : 22/97 [00:00<00:01, 41.93it/s]
24%|βββ | Repairing epochs : 23/97 [00:00<00:01, 41.84it/s]
25%|βββ | Repairing epochs : 24/97 [00:00<00:01, 41.64it/s]
26%|βββ | Repairing epochs : 25/97 [00:00<00:01, 41.50it/s]
27%|βββ | Repairing epochs : 26/97 [00:00<00:01, 41.46it/s]
28%|βββ | Repairing epochs : 27/97 [00:00<00:01, 41.27it/s]
29%|βββ | Repairing epochs : 28/97 [00:00<00:01, 41.05it/s]
30%|βββ | Repairing epochs : 29/97 [00:00<00:01, 40.96it/s]
31%|βββ | Repairing epochs : 30/97 [00:00<00:01, 40.83it/s]
32%|ββββ | Repairing epochs : 31/97 [00:00<00:01, 40.65it/s]
33%|ββββ | Repairing epochs : 32/97 [00:00<00:01, 40.59it/s]
34%|ββββ | Repairing epochs : 33/97 [00:00<00:01, 40.61it/s]
35%|ββββ | Repairing epochs : 34/97 [00:00<00:01, 40.58it/s]
36%|ββββ | Repairing epochs : 35/97 [00:00<00:01, 40.52it/s]
37%|ββββ | Repairing epochs : 36/97 [00:00<00:01, 40.42it/s]
38%|ββββ | Repairing epochs : 37/97 [00:00<00:01, 40.40it/s]
39%|ββββ | Repairing epochs : 38/97 [00:00<00:01, 40.33it/s]
40%|ββββ | Repairing epochs : 39/97 [00:00<00:01, 40.26it/s]
41%|ββββ | Repairing epochs : 40/97 [00:00<00:01, 40.67it/s]
42%|βββββ | Repairing epochs : 41/97 [00:00<00:01, 40.62it/s]
43%|βββββ | Repairing epochs : 42/97 [00:01<00:01, 40.50it/s]
44%|βββββ | Repairing epochs : 43/97 [00:01<00:01, 40.42it/s]
45%|βββββ | Repairing epochs : 44/97 [00:01<00:01, 40.35it/s]
46%|βββββ | Repairing epochs : 45/97 [00:01<00:01, 40.33it/s]
47%|βββββ | Repairing epochs : 46/97 [00:01<00:01, 40.31it/s]
48%|βββββ | Repairing epochs : 47/97 [00:01<00:01, 40.34it/s]
49%|βββββ | Repairing epochs : 48/97 [00:01<00:01, 40.22it/s]
51%|βββββ | Repairing epochs : 49/97 [00:01<00:01, 40.64it/s]
52%|ββββββ | Repairing epochs : 50/97 [00:01<00:01, 40.57it/s]
53%|ββββββ | Repairing epochs : 51/97 [00:01<00:01, 40.58it/s]
54%|ββββββ | Repairing epochs : 52/97 [00:01<00:01, 40.60it/s]
55%|ββββββ | Repairing epochs : 53/97 [00:01<00:01, 40.52it/s]
56%|ββββββ | Repairing epochs : 54/97 [00:01<00:01, 40.42it/s]
57%|ββββββ | Repairing epochs : 55/97 [00:01<00:01, 40.43it/s]
58%|ββββββ | Repairing epochs : 56/97 [00:01<00:01, 40.35it/s]
59%|ββββββ | Repairing epochs : 57/97 [00:01<00:00, 40.79it/s]
60%|ββββββ | Repairing epochs : 58/97 [00:01<00:00, 40.76it/s]
61%|ββββββ | Repairing epochs : 59/97 [00:01<00:00, 41.17it/s]
62%|βββββββ | Repairing epochs : 60/97 [00:01<00:00, 41.07it/s]
63%|βββββββ | Repairing epochs : 61/97 [00:01<00:00, 40.93it/s]
64%|βββββββ | Repairing epochs : 62/97 [00:01<00:00, 41.32it/s]
65%|βββββββ | Repairing epochs : 63/97 [00:01<00:00, 41.29it/s]
66%|βββββββ | Repairing epochs : 64/97 [00:01<00:00, 41.20it/s]
67%|βββββββ | Repairing epochs : 65/97 [00:01<00:00, 41.14it/s]
68%|βββββββ | Repairing epochs : 66/97 [00:01<00:00, 40.93it/s]
69%|βββββββ | Repairing epochs : 67/97 [00:01<00:00, 40.85it/s]
70%|βββββββ | Repairing epochs : 68/97 [00:01<00:00, 40.78it/s]
71%|βββββββ | Repairing epochs : 69/97 [00:01<00:00, 40.69it/s]
72%|ββββββββ | Repairing epochs : 70/97 [00:01<00:00, 40.66it/s]
73%|ββββββββ | Repairing epochs : 71/97 [00:01<00:00, 40.67it/s]
74%|ββββββββ | Repairing epochs : 72/97 [00:01<00:00, 40.59it/s]
75%|ββββββββ | Repairing epochs : 73/97 [00:01<00:00, 40.61it/s]
76%|ββββββββ | Repairing epochs : 74/97 [00:01<00:00, 40.56it/s]
77%|ββββββββ | Repairing epochs : 75/97 [00:01<00:00, 40.53it/s]
78%|ββββββββ | Repairing epochs : 76/97 [00:01<00:00, 40.54it/s]
79%|ββββββββ | Repairing epochs : 77/97 [00:01<00:00, 40.54it/s]
80%|ββββββββ | Repairing epochs : 78/97 [00:01<00:00, 40.46it/s]
81%|βββββββββ | Repairing epochs : 79/97 [00:01<00:00, 40.45it/s]
82%|βββββββββ | Repairing epochs : 80/97 [00:01<00:00, 40.37it/s]
84%|βββββββββ | Repairing epochs : 81/97 [00:01<00:00, 40.34it/s]
85%|βββββββββ | Repairing epochs : 82/97 [00:02<00:00, 40.26it/s]
86%|βββββββββ | Repairing epochs : 83/97 [00:02<00:00, 40.23it/s]
87%|βββββββββ | Repairing epochs : 84/97 [00:02<00:00, 40.17it/s]
88%|βββββββββ | Repairing epochs : 85/97 [00:02<00:00, 40.17it/s]
89%|βββββββββ | Repairing epochs : 86/97 [00:02<00:00, 40.16it/s]
90%|βββββββββ | Repairing epochs : 87/97 [00:02<00:00, 40.11it/s]
91%|βββββββββ | Repairing epochs : 88/97 [00:02<00:00, 39.98it/s]
92%|ββββββββββ| Repairing epochs : 89/97 [00:02<00:00, 39.94it/s]
93%|ββββββββββ| Repairing epochs : 90/97 [00:02<00:00, 39.84it/s]
94%|ββββββββββ| Repairing epochs : 91/97 [00:02<00:00, 39.84it/s]
95%|ββββββββββ| Repairing epochs : 92/97 [00:02<00:00, 39.72it/s]
96%|ββββββββββ| Repairing epochs : 93/97 [00:02<00:00, 39.71it/s]
97%|ββββββββββ| Repairing epochs : 94/97 [00:02<00:00, 39.66it/s]
98%|ββββββββββ| Repairing epochs : 95/97 [00:02<00:00, 39.65it/s]
99%|ββββββββββ| Repairing epochs : 96/97 [00:02<00:00, 39.48it/s]
100%|ββββββββββ| Repairing epochs : 97/97 [00:02<00:00, 39.41it/s]
100%|ββββββββββ| Repairing epochs : 97/97 [00:02<00:00, 40.63it/s]
No bad epochs were found for your data. Returning a copy of the data you wanted to clean. Interpolation may have been done.
Number of epochs originally: 97, after autoreject: 97
Finally, donβt forget that we are working with resting state data here. Here we used long epochs of 3 seconds so that frequency-domain analysis was possible with the epochs. However, this could also lead to longer segments of the data being rejected. If you want more fine-grained control over the artifacts, you can construct shorter epochs and use the autoreject log to mark annotations in MNE that can be used to reject the data during doing time-frequency analysis. We want to emphasize that there is no subsitute for visual inspection. Irrespective of the rejection method used, we highly recommend users to inspect their preprocessed data before further analyses.
Total running time of the script: (1 minutes 19.829 seconds)