Note
Click here to download the full example code or to run this example in your browser via Binder
03. Interactive data inspection and bad channel selection¶
You can use MNE-BIDS interactively inspect your MEG or (i)EEG data. Problematic channels can be marked as “bad”, for example if the connected sensor produced mostly noise – or no signal at all. Similarly, you can declare channels as “good”, should you discover they were incorrectly marked as bad. Bad channel selection can also be performed non-interactively.
Furthermore, you can view and edit the experimental events and mark time segments as “bad”.
# Authors: Richard Höchenberger <richard.hoechenberger@gmail.com>
#
# License: BSD-3-Clause
We will demonstrate how to mark individual channels as bad on the MNE “sample” dataset. After that, we will mark channels as good again.
Let’s start by importing the required modules and functions, reading the “sample” data, and writing it in the BIDS format.
import os.path as op
import shutil
import mne
from mne_bids import (BIDSPath, write_raw_bids, read_raw_bids,
inspect_dataset, mark_channels)
data_path = mne.datasets.sample.data_path()
raw_fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis_raw.fif')
events_fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis_raw-eve.fif')
event_id = {'Auditory/Left': 1, 'Auditory/Right': 2, 'Visual/Left': 3,
'Visual/Right': 4, 'Smiley': 5, 'Button': 32}
bids_root = op.join(data_path, '..', 'MNE-sample-data-bids')
bids_path = BIDSPath(subject='01', session='01', task='audiovisual', run='01',
root=bids_root)
To ensure the output path doesn’t contain any leftover files from previous tests and example runs, we simply delete it.
Warning
Do not delete directories that may contain important data!
Now write the raw data to BIDS.
raw = mne.io.read_raw_fif(raw_fname, verbose=False)
raw.info['line_freq'] = 60 # Specify power line frequency as required by BIDS.
write_raw_bids(raw, bids_path=bids_path, events_data=events_fname,
event_id=event_id, overwrite=True, verbose=False)
Out:
BIDSPath(
root: /Users/hoechenberger/mne_data/MNE-sample-data/../MNE-sample-data-bids
datatype: meg
basename: sub-01_ses-01_task-audiovisual_run-01_meg.fif)
Interactive use¶
Using mne_bids.inspect_dataset()
, we can interactively explore the raw
data and toggle the channel status – bad
or good
– by clicking on the
respective traces or channel names. If there are any SSP projectors stored
with the data, a small popup window will allow you to toggle the projectors
on and off. If you changed the selection of bad channels, you will be
prompted whether you would like to save the changes when closing the main
window. Your raw data and the *_channels.tsv sidecar file will be updated
upon saving.
Out:
Reading 0 ... 166799 = 0.000 ... 277.714 secs...
Finding flat segments
0%| | Channels : 0/364 [00:00<?, ?it/s]
1%| | Channels : 2/364 [00:00<00:05, 71.36it/s]
1%|1 | Channels : 4/364 [00:00<00:04, 85.16it/s]
2%|1 | Channels : 6/364 [00:00<00:03, 91.32it/s]
2%|2 | Channels : 8/364 [00:00<00:03, 89.49it/s]
3%|2 | Channels : 10/364 [00:00<00:03, 93.15it/s]
3%|3 | Channels : 12/364 [00:00<00:03, 96.20it/s]
4%|3 | Channels : 14/364 [00:00<00:03, 95.19it/s]
4%|4 | Channels : 16/364 [00:00<00:03, 95.94it/s]
5%|4 | Channels : 18/364 [00:00<00:03, 98.02it/s]
5%|5 | Channels : 20/364 [00:00<00:03, 95.01it/s]
6%|6 | Channels : 22/364 [00:00<00:03, 96.87it/s]
7%|6 | Channels : 25/364 [00:00<00:03, 99.08it/s]
7%|7 | Channels : 27/364 [00:00<00:03, 100.06it/s]
8%|7 | Channels : 29/364 [00:00<00:03, 97.95it/s]
9%|8 | Channels : 31/364 [00:00<00:03, 99.35it/s]
9%|9 | Channels : 33/364 [00:00<00:03, 99.95it/s]
10%|9 | Channels : 35/364 [00:00<00:03, 99.59it/s]
10%|# | Channels : 37/364 [00:00<00:03, 99.76it/s]
11%|# | Channels : 39/364 [00:00<00:03, 100.17it/s]
11%|#1 | Channels : 41/364 [00:00<00:03, 98.68it/s]
12%|#2 | Channels : 44/364 [00:00<00:03, 100.69it/s]
13%|#2 | Channels : 46/364 [00:00<00:03, 102.00it/s]
13%|#3 | Channels : 48/364 [00:00<00:03, 102.77it/s]
14%|#3 | Channels : 50/364 [00:00<00:03, 101.84it/s]
14%|#4 | Channels : 52/364 [00:00<00:03, 102.92it/s]
15%|#4 | Channels : 54/364 [00:00<00:03, 103.17it/s]
15%|#5 | Channels : 56/364 [00:00<00:03, 101.37it/s]
16%|#5 | Channels : 58/364 [00:00<00:03, 101.54it/s]
16%|#6 | Channels : 60/364 [00:00<00:02, 102.27it/s]
17%|#7 | Channels : 62/364 [00:00<00:03, 97.13it/s]
18%|#7 | Channels : 64/364 [00:00<00:03, 94.82it/s]
18%|#7 | Channels : 65/364 [00:00<00:03, 92.92it/s]
18%|#8 | Channels : 67/364 [00:00<00:03, 93.75it/s]
19%|#8 | Channels : 69/364 [00:00<00:03, 94.94it/s]
20%|#9 | Channels : 71/364 [00:00<00:03, 93.89it/s]
20%|## | Channels : 73/364 [00:00<00:03, 93.69it/s]
21%|## | Channels : 75/364 [00:00<00:03, 94.60it/s]
21%|##1 | Channels : 77/364 [00:00<00:03, 94.38it/s]
22%|##1 | Channels : 79/364 [00:00<00:02, 95.34it/s]
22%|##2 | Channels : 81/364 [00:00<00:02, 95.91it/s]
23%|##2 | Channels : 83/364 [00:00<00:02, 95.07it/s]
23%|##3 | Channels : 85/364 [00:00<00:02, 96.29it/s]
24%|##3 | Channels : 87/364 [00:00<00:02, 96.97it/s]
24%|##4 | Channels : 89/364 [00:00<00:02, 95.97it/s]
25%|##5 | Channels : 91/364 [00:00<00:02, 96.30it/s]
26%|##5 | Channels : 93/364 [00:00<00:02, 96.62it/s]
26%|##6 | Channels : 95/364 [00:00<00:02, 95.87it/s]
27%|##6 | Channels : 97/364 [00:01<00:02, 95.82it/s]
27%|##7 | Channels : 99/364 [00:01<00:02, 96.19it/s]
28%|##7 | Channels : 101/364 [00:01<00:02, 95.30it/s]
28%|##8 | Channels : 103/364 [00:01<00:02, 95.76it/s]
29%|##8 | Channels : 105/364 [00:01<00:02, 96.07it/s]
29%|##9 | Channels : 107/364 [00:01<00:02, 95.64it/s]
30%|##9 | Channels : 109/364 [00:01<00:02, 96.53it/s]
30%|### | Channels : 111/364 [00:01<00:02, 97.47it/s]
31%|###1 | Channels : 113/364 [00:01<00:02, 96.54it/s]
32%|###1 | Channels : 115/364 [00:01<00:02, 97.29it/s]
32%|###2 | Channels : 117/364 [00:01<00:02, 97.72it/s]
33%|###2 | Channels : 119/364 [00:01<00:02, 97.06it/s]
33%|###3 | Channels : 121/364 [00:01<00:02, 97.84it/s]
34%|###3 | Channels : 123/364 [00:01<00:02, 98.67it/s]
34%|###4 | Channels : 125/364 [00:01<00:02, 98.78it/s]
35%|###4 | Channels : 127/364 [00:01<00:02, 99.33it/s]
35%|###5 | Channels : 129/364 [00:01<00:02, 99.17it/s]
36%|###5 | Channels : 131/364 [00:01<00:02, 98.84it/s]
37%|###6 | Channels : 133/364 [00:01<00:02, 99.25it/s]
37%|###7 | Channels : 135/364 [00:01<00:02, 100.11it/s]
38%|###7 | Channels : 137/364 [00:01<00:02, 98.74it/s]
38%|###8 | Channels : 139/364 [00:01<00:02, 99.21it/s]
39%|###8 | Channels : 141/364 [00:01<00:02, 99.85it/s]
39%|###9 | Channels : 143/364 [00:01<00:02, 99.53it/s]
40%|###9 | Channels : 145/364 [00:01<00:02, 100.56it/s]
41%|#### | Channels : 148/364 [00:01<00:02, 101.25it/s]
41%|####1 | Channels : 150/364 [00:01<00:02, 102.04it/s]
42%|####1 | Channels : 152/364 [00:01<00:02, 101.16it/s]
42%|####2 | Channels : 154/364 [00:01<00:02, 101.46it/s]
43%|####2 | Channels : 156/364 [00:01<00:02, 101.92it/s]
43%|####3 | Channels : 158/364 [00:01<00:02, 100.81it/s]
44%|####3 | Channels : 160/364 [00:01<00:02, 101.23it/s]
45%|####4 | Channels : 162/364 [00:01<00:01, 101.99it/s]
45%|####5 | Channels : 164/364 [00:01<00:01, 101.02it/s]
46%|####5 | Channels : 166/364 [00:01<00:01, 101.91it/s]
46%|####6 | Channels : 168/364 [00:01<00:01, 102.31it/s]
47%|####6 | Channels : 170/364 [00:01<00:01, 101.93it/s]
47%|####7 | Channels : 172/364 [00:01<00:01, 102.44it/s]
48%|####7 | Channels : 174/364 [00:01<00:01, 102.66it/s]
48%|####8 | Channels : 176/364 [00:01<00:01, 101.68it/s]
49%|####8 | Channels : 178/364 [00:01<00:01, 102.58it/s]
49%|####9 | Channels : 180/364 [00:01<00:01, 103.50it/s]
50%|##### | Channels : 182/364 [00:01<00:01, 103.18it/s]
51%|##### | Channels : 184/364 [00:01<00:01, 103.85it/s]
51%|#####1 | Channels : 187/364 [00:01<00:01, 104.57it/s]
52%|#####1 | Channels : 189/364 [00:01<00:01, 104.76it/s]
52%|#####2 | Channels : 191/364 [00:01<00:01, 104.20it/s]
53%|#####3 | Channels : 194/364 [00:01<00:01, 105.34it/s]
54%|#####4 | Channels : 197/364 [00:01<00:01, 105.94it/s]
55%|#####4 | Channels : 199/364 [00:01<00:01, 106.64it/s]
55%|#####5 | Channels : 201/364 [00:01<00:01, 107.02it/s]
56%|#####5 | Channels : 203/364 [00:02<00:01, 106.20it/s]
56%|#####6 | Channels : 205/364 [00:02<00:01, 106.39it/s]
57%|#####6 | Channels : 207/364 [00:02<00:01, 106.53it/s]
57%|#####7 | Channels : 209/364 [00:02<00:01, 106.43it/s]
58%|#####7 | Channels : 211/364 [00:02<00:01, 106.28it/s]
59%|#####8 | Channels : 213/364 [00:02<00:01, 106.00it/s]
59%|#####9 | Channels : 215/364 [00:02<00:01, 105.33it/s]
60%|#####9 | Channels : 217/364 [00:02<00:01, 105.16it/s]
60%|###### | Channels : 219/364 [00:02<00:01, 105.46it/s]
61%|###### | Channels : 221/364 [00:02<00:01, 104.78it/s]
61%|######1 | Channels : 223/364 [00:02<00:01, 104.84it/s]
62%|######1 | Channels : 225/364 [00:02<00:01, 103.64it/s]
62%|######2 | Channels : 227/364 [00:02<00:01, 101.74it/s]
63%|######2 | Channels : 229/364 [00:02<00:01, 102.13it/s]
63%|######3 | Channels : 231/364 [00:02<00:01, 102.90it/s]
64%|######4 | Channels : 233/364 [00:02<00:01, 102.06it/s]
65%|######4 | Channels : 235/364 [00:02<00:01, 102.12it/s]
65%|######5 | Channels : 237/364 [00:02<00:01, 102.42it/s]
66%|######5 | Channels : 239/364 [00:02<00:01, 101.59it/s]
66%|######6 | Channels : 241/364 [00:02<00:01, 101.80it/s]
67%|######6 | Channels : 243/364 [00:02<00:01, 101.79it/s]
67%|######7 | Channels : 245/364 [00:02<00:01, 100.64it/s]
68%|######7 | Channels : 247/364 [00:02<00:01, 101.07it/s]
68%|######8 | Channels : 249/364 [00:02<00:01, 101.92it/s]
69%|######8 | Channels : 251/364 [00:02<00:01, 101.39it/s]
70%|######9 | Channels : 253/364 [00:02<00:01, 101.69it/s]
70%|####### | Channels : 255/364 [00:02<00:01, 101.81it/s]
71%|####### | Channels : 257/364 [00:02<00:01, 101.11it/s]
71%|#######1 | Channels : 259/364 [00:02<00:01, 101.56it/s]
72%|#######1 | Channels : 261/364 [00:02<00:01, 102.37it/s]
72%|#######2 | Channels : 263/364 [00:02<00:00, 101.57it/s]
73%|#######2 | Channels : 265/364 [00:02<00:00, 101.61it/s]
73%|#######3 | Channels : 267/364 [00:02<00:00, 101.58it/s]
74%|#######3 | Channels : 269/364 [00:02<00:00, 100.95it/s]
74%|#######4 | Channels : 271/364 [00:02<00:00, 101.37it/s]
75%|#######5 | Channels : 273/364 [00:02<00:00, 101.80it/s]
76%|#######5 | Channels : 275/364 [00:02<00:00, 102.09it/s]
76%|#######6 | Channels : 277/364 [00:02<00:00, 102.91it/s]
77%|#######6 | Channels : 279/364 [00:02<00:00, 103.51it/s]
77%|#######7 | Channels : 281/364 [00:02<00:00, 103.72it/s]
78%|#######7 | Channels : 283/364 [00:02<00:00, 102.03it/s]
78%|#######8 | Channels : 285/364 [00:02<00:00, 102.22it/s]
79%|#######8 | Channels : 287/364 [00:02<00:00, 102.62it/s]
79%|#######9 | Channels : 289/364 [00:02<00:00, 101.81it/s]
80%|#######9 | Channels : 291/364 [00:02<00:00, 102.15it/s]
80%|######## | Channels : 293/364 [00:02<00:00, 102.51it/s]
81%|########1 | Channels : 295/364 [00:02<00:00, 102.03it/s]
82%|########1 | Channels : 297/364 [00:02<00:00, 102.68it/s]
82%|########2 | Channels : 299/364 [00:02<00:00, 102.29it/s]
83%|########2 | Channels : 301/364 [00:02<00:00, 101.88it/s]
83%|########3 | Channels : 303/364 [00:03<00:00, 102.59it/s]
84%|########3 | Channels : 305/364 [00:03<00:00, 103.27it/s]
86%|########6 | Channels : 314/364 [00:03<00:00, 121.82it/s]
88%|########8 | Channels : 322/364 [00:03<00:00, 136.81it/s]
91%|######### | Channels : 330/364 [00:03<00:00, 151.97it/s]
93%|#########2| Channels : 338/364 [00:03<00:00, 165.72it/s]
95%|#########4| Channels : 345/364 [00:03<00:00, 176.94it/s]
97%|#########6| Channels : 352/364 [00:03<00:00, 187.44it/s]
99%|#########8| Channels : 359/364 [00:03<00:00, 197.17it/s]
100%|##########| Channels : 364/364 [00:03<00:00, 115.36it/s]
Marking 0.00% of time points (0 segments) and 0/364 channels bad
You can even apply frequency filters when viewing the data: A high-pass filter can remove slow drifts, while a low-pass filter will get rid of high-frequency artifacts. This can make visual inspection easier. Let’s apply filters with a 1-Hz high-pass cutoff, and a 30-Hz low-pass cutoff:
inspect_dataset(bids_path, l_freq=1., h_freq=30.)
Out:
Reading 0 ... 166799 = 0.000 ... 277.714 secs...
Finding flat segments
0%| | Channels : 0/364 [00:00<?, ?it/s]
1%| | Channels : 2/364 [00:00<00:04, 76.02it/s]
1%|1 | Channels : 4/364 [00:00<00:04, 88.17it/s]
2%|1 | Channels : 6/364 [00:00<00:03, 94.37it/s]
2%|2 | Channels : 8/364 [00:00<00:03, 90.58it/s]
3%|2 | Channels : 10/364 [00:00<00:03, 95.09it/s]
3%|3 | Channels : 12/364 [00:00<00:03, 97.79it/s]
4%|3 | Channels : 14/364 [00:00<00:03, 96.30it/s]
4%|4 | Channels : 16/364 [00:00<00:03, 97.29it/s]
5%|4 | Channels : 18/364 [00:00<00:03, 99.48it/s]
5%|5 | Channels : 20/364 [00:00<00:03, 97.10it/s]
6%|6 | Channels : 22/364 [00:00<00:03, 99.25it/s]
7%|6 | Channels : 24/364 [00:00<00:03, 101.43it/s]
7%|7 | Channels : 26/364 [00:00<00:03, 100.78it/s]
8%|7 | Channels : 28/364 [00:00<00:03, 101.22it/s]
8%|8 | Channels : 30/364 [00:00<00:03, 102.14it/s]
9%|8 | Channels : 32/364 [00:00<00:03, 100.61it/s]
9%|9 | Channels : 34/364 [00:00<00:03, 102.17it/s]
10%|9 | Channels : 36/364 [00:00<00:03, 103.29it/s]
10%|# | Channels : 38/364 [00:00<00:03, 101.06it/s]
11%|# | Channels : 40/364 [00:00<00:03, 101.99it/s]
12%|#1 | Channels : 42/364 [00:00<00:03, 103.01it/s]
12%|#2 | Channels : 44/364 [00:00<00:03, 103.20it/s]
13%|#2 | Channels : 46/364 [00:00<00:03, 104.13it/s]
13%|#3 | Channels : 48/364 [00:00<00:03, 104.56it/s]
14%|#3 | Channels : 50/364 [00:00<00:03, 103.76it/s]
14%|#4 | Channels : 52/364 [00:00<00:02, 104.14it/s]
15%|#4 | Channels : 54/364 [00:00<00:02, 104.32it/s]
15%|#5 | Channels : 56/364 [00:00<00:03, 102.32it/s]
16%|#5 | Channels : 58/364 [00:00<00:02, 102.68it/s]
16%|#6 | Channels : 60/364 [00:00<00:02, 103.40it/s]
17%|#7 | Channels : 62/364 [00:00<00:02, 101.44it/s]
18%|#7 | Channels : 64/364 [00:00<00:02, 101.79it/s]
18%|#8 | Channels : 66/364 [00:00<00:02, 102.78it/s]
19%|#8 | Channels : 68/364 [00:00<00:02, 101.65it/s]
19%|#9 | Channels : 70/364 [00:00<00:02, 102.25it/s]
20%|#9 | Channels : 72/364 [00:00<00:02, 103.19it/s]
20%|## | Channels : 74/364 [00:00<00:02, 102.16it/s]
21%|## | Channels : 76/364 [00:00<00:02, 103.17it/s]
22%|##1 | Channels : 79/364 [00:00<00:02, 103.70it/s]
22%|##2 | Channels : 81/364 [00:00<00:02, 104.03it/s]
23%|##2 | Channels : 83/364 [00:00<00:02, 102.99it/s]
23%|##3 | Channels : 85/364 [00:00<00:02, 103.96it/s]
24%|##3 | Channels : 87/364 [00:00<00:02, 104.52it/s]
24%|##4 | Channels : 89/364 [00:00<00:02, 102.90it/s]
25%|##5 | Channels : 91/364 [00:00<00:02, 103.05it/s]
26%|##5 | Channels : 93/364 [00:00<00:02, 103.08it/s]
26%|##6 | Channels : 95/364 [00:00<00:02, 101.86it/s]
27%|##6 | Channels : 97/364 [00:00<00:02, 101.36it/s]
27%|##7 | Channels : 99/364 [00:00<00:02, 101.55it/s]
28%|##7 | Channels : 101/364 [00:00<00:02, 100.72it/s]
28%|##8 | Channels : 103/364 [00:01<00:02, 101.15it/s]
29%|##8 | Channels : 105/364 [00:01<00:02, 101.00it/s]
29%|##9 | Channels : 107/364 [00:01<00:02, 100.54it/s]
30%|##9 | Channels : 109/364 [00:01<00:02, 101.43it/s]
30%|### | Channels : 111/364 [00:01<00:02, 102.16it/s]
31%|###1 | Channels : 113/364 [00:01<00:02, 100.66it/s]
32%|###1 | Channels : 115/364 [00:01<00:02, 101.34it/s]
32%|###2 | Channels : 117/364 [00:01<00:02, 101.86it/s]
33%|###2 | Channels : 119/364 [00:01<00:02, 101.03it/s]
33%|###3 | Channels : 121/364 [00:01<00:02, 101.95it/s]
34%|###3 | Channels : 123/364 [00:01<00:02, 102.71it/s]
34%|###4 | Channels : 125/364 [00:01<00:02, 102.21it/s]
35%|###4 | Channels : 127/364 [00:01<00:02, 102.90it/s]
35%|###5 | Channels : 129/364 [00:01<00:02, 102.66it/s]
36%|###5 | Channels : 131/364 [00:01<00:02, 102.14it/s]
37%|###6 | Channels : 133/364 [00:01<00:02, 102.22it/s]
37%|###7 | Channels : 135/364 [00:01<00:02, 102.77it/s]
38%|###7 | Channels : 137/364 [00:01<00:02, 101.48it/s]
38%|###8 | Channels : 139/364 [00:01<00:02, 101.77it/s]
39%|###8 | Channels : 141/364 [00:01<00:02, 102.44it/s]
39%|###9 | Channels : 143/364 [00:01<00:02, 102.17it/s]
40%|#### | Channels : 146/364 [00:01<00:02, 103.45it/s]
41%|#### | Channels : 148/364 [00:01<00:02, 103.69it/s]
41%|####1 | Channels : 150/364 [00:01<00:02, 104.49it/s]
42%|####1 | Channels : 152/364 [00:01<00:02, 103.42it/s]
42%|####2 | Channels : 154/364 [00:01<00:02, 103.98it/s]
43%|####2 | Channels : 156/364 [00:01<00:01, 104.58it/s]
43%|####3 | Channels : 158/364 [00:01<00:01, 103.43it/s]
44%|####3 | Channels : 160/364 [00:01<00:01, 103.73it/s]
45%|####4 | Channels : 162/364 [00:01<00:01, 104.39it/s]
45%|####5 | Channels : 164/364 [00:01<00:01, 102.80it/s]
46%|####5 | Channels : 166/364 [00:01<00:01, 103.42it/s]
46%|####6 | Channels : 168/364 [00:01<00:01, 103.79it/s]
47%|####6 | Channels : 170/364 [00:01<00:01, 103.02it/s]
47%|####7 | Channels : 172/364 [00:01<00:01, 103.20it/s]
48%|####7 | Channels : 174/364 [00:01<00:01, 103.14it/s]
48%|####8 | Channels : 176/364 [00:01<00:01, 102.12it/s]
49%|####8 | Channels : 178/364 [00:01<00:01, 102.91it/s]
49%|####9 | Channels : 180/364 [00:01<00:01, 103.42it/s]
50%|##### | Channels : 182/364 [00:01<00:01, 102.65it/s]
51%|##### | Channels : 184/364 [00:01<00:01, 102.68it/s]
51%|#####1 | Channels : 186/364 [00:01<00:01, 103.35it/s]
52%|#####1 | Channels : 188/364 [00:01<00:01, 101.52it/s]
52%|#####2 | Channels : 190/364 [00:01<00:01, 102.04it/s]
53%|#####2 | Channels : 192/364 [00:01<00:01, 102.19it/s]
53%|#####3 | Channels : 194/364 [00:01<00:01, 101.91it/s]
54%|#####3 | Channels : 196/364 [00:01<00:01, 102.40it/s]
54%|#####4 | Channels : 198/364 [00:01<00:01, 102.50it/s]
55%|#####4 | Channels : 200/364 [00:01<00:01, 102.01it/s]
55%|#####5 | Channels : 202/364 [00:01<00:01, 102.64it/s]
56%|#####6 | Channels : 204/364 [00:01<00:01, 103.12it/s]
57%|#####6 | Channels : 206/364 [00:02<00:01, 102.05it/s]
57%|#####7 | Channels : 208/364 [00:02<00:01, 102.45it/s]
58%|#####7 | Channels : 210/364 [00:02<00:01, 102.74it/s]
58%|#####8 | Channels : 212/364 [00:02<00:01, 101.90it/s]
59%|#####8 | Channels : 214/364 [00:02<00:01, 101.84it/s]
59%|#####9 | Channels : 216/364 [00:02<00:01, 101.98it/s]
60%|#####9 | Channels : 218/364 [00:02<00:01, 101.06it/s]
60%|###### | Channels : 220/364 [00:02<00:01, 101.28it/s]
61%|###### | Channels : 222/364 [00:02<00:01, 101.95it/s]
62%|######1 | Channels : 224/364 [00:02<00:01, 100.87it/s]
62%|######2 | Channels : 226/364 [00:02<00:01, 100.87it/s]
63%|######2 | Channels : 228/364 [00:02<00:01, 100.58it/s]
63%|######3 | Channels : 230/364 [00:02<00:01, 100.87it/s]
64%|######3 | Channels : 232/364 [00:02<00:01, 101.20it/s]
64%|######4 | Channels : 234/364 [00:02<00:01, 101.29it/s]
65%|######4 | Channels : 236/364 [00:02<00:01, 100.63it/s]
65%|######5 | Channels : 238/364 [00:02<00:01, 100.83it/s]
66%|######5 | Channels : 240/364 [00:02<00:01, 101.23it/s]
66%|######6 | Channels : 242/364 [00:02<00:01, 100.45it/s]
67%|######7 | Channels : 244/364 [00:02<00:01, 101.34it/s]
68%|######7 | Channels : 246/364 [00:02<00:01, 101.92it/s]
68%|######8 | Channels : 248/364 [00:02<00:01, 101.58it/s]
69%|######8 | Channels : 250/364 [00:02<00:01, 102.49it/s]
69%|######9 | Channels : 252/364 [00:02<00:01, 103.32it/s]
70%|######9 | Channels : 254/364 [00:02<00:01, 102.22it/s]
70%|####### | Channels : 256/364 [00:02<00:01, 102.48it/s]
71%|####### | Channels : 258/364 [00:02<00:01, 103.09it/s]
71%|#######1 | Channels : 260/364 [00:02<00:01, 102.79it/s]
72%|#######1 | Channels : 262/364 [00:02<00:00, 103.25it/s]
73%|#######2 | Channels : 264/364 [00:02<00:00, 103.92it/s]
73%|#######3 | Channels : 266/364 [00:02<00:00, 102.41it/s]
74%|#######3 | Channels : 268/364 [00:02<00:00, 102.88it/s]
74%|#######4 | Channels : 270/364 [00:02<00:00, 103.08it/s]
75%|#######4 | Channels : 272/364 [00:02<00:00, 102.22it/s]
75%|#######5 | Channels : 274/364 [00:02<00:00, 103.14it/s]
76%|#######6 | Channels : 277/364 [00:02<00:00, 104.45it/s]
77%|#######6 | Channels : 279/364 [00:02<00:00, 105.28it/s]
77%|#######7 | Channels : 281/364 [00:02<00:00, 105.65it/s]
78%|#######7 | Channels : 283/364 [00:02<00:00, 104.08it/s]
78%|#######8 | Channels : 285/364 [00:02<00:00, 103.99it/s]
79%|#######8 | Channels : 287/364 [00:02<00:00, 104.27it/s]
79%|#######9 | Channels : 289/364 [00:02<00:00, 103.15it/s]
80%|#######9 | Channels : 291/364 [00:02<00:00, 103.51it/s]
80%|######## | Channels : 293/364 [00:02<00:00, 103.47it/s]
81%|########1 | Channels : 295/364 [00:02<00:00, 103.00it/s]
82%|########1 | Channels : 297/364 [00:02<00:00, 103.55it/s]
82%|########2 | Channels : 299/364 [00:02<00:00, 103.60it/s]
83%|########2 | Channels : 301/364 [00:02<00:00, 103.05it/s]
83%|########3 | Channels : 303/364 [00:02<00:00, 103.51it/s]
84%|########3 | Channels : 305/364 [00:02<00:00, 104.27it/s]
86%|########6 | Channels : 314/364 [00:02<00:00, 122.82it/s]
88%|########8 | Channels : 322/364 [00:03<00:00, 138.21it/s]
91%|######### | Channels : 330/364 [00:03<00:00, 153.23it/s]
93%|#########2| Channels : 337/364 [00:03<00:00, 165.23it/s]
95%|#########4| Channels : 345/364 [00:03<00:00, 178.89it/s]
97%|#########6| Channels : 352/364 [00:03<00:00, 189.71it/s]
99%|#########8| Channels : 359/364 [00:03<00:00, 199.95it/s]
100%|##########| Channels : 364/364 [00:03<00:00, 117.41it/s]
Marking 0.00% of time points (0 segments) and 0/364 channels bad
By pressing the A
key, you can toggle annotation mode to add, edit, or
remove experimental events, or to mark entire time periods as bad. Please see
the MNE-Python Annotations tutorial for an introduction to the interactive
interface. If you’re closing the main window after changing the annotations,
you will be prompted whether you wish to save the changes. Your raw data and
the *_events.tsv sidecar file will be updated upon saving.
Non-interactive (programmatic) bad channel selection¶
Read the (now BIDS-formatted) data and print a list of channels currently marked as bad.
raw = read_raw_bids(bids_path=bids_path, verbose=False)
print(f'The following channels are currently marked as bad:\n'
f' {", ".join(raw.info["bads"])}\n')
Out:
/Users/hoechenberger/Development/mne-bids/mne_bids/read.py:553: RuntimeWarning: The unit for channel(s) STI 001, STI 002, STI 003, STI 004, STI 005, STI 006, STI 014, STI 015, STI 016 has changed from V to NA.
raw.set_channel_types(ch_type_map_avail)
The following channels are currently marked as bad:
MEG 2443, EEG 053
So currently, two channels are marked as bad: EEG 053
and MEG 2443
.
Let’s assume that through visual data inspection, we found that two more
MEG channels are problematic, and we would like to mark them as bad as well.
To do that, we simply add them to a list, which we then pass to
mne_bids.mark_channels()
:
bads = ['MEG 0112', 'MEG 0131']
mark_channels(bids_path=bids_path, ch_names=bads, status='bad',
verbose=False)
That’s it! Let’s verify the result.
raw = read_raw_bids(bids_path=bids_path, verbose=False)
print(f'After marking MEG 0112 and MEG 0131 as bad, the following channels '
f'are now marked as bad:\n {", ".join(raw.info["bads"])}\n')
Out:
/Users/hoechenberger/Development/mne-bids/mne_bids/read.py:553: RuntimeWarning: The unit for channel(s) STI 001, STI 002, STI 003, STI 004, STI 005, STI 006, STI 014, STI 015, STI 016 has changed from V to NA.
raw.set_channel_types(ch_type_map_avail)
After marking MEG 0112 and MEG 0131 as bad, the following channels are now marked as bad:
MEG 0112, MEG 0131, MEG 2443, EEG 053
As you can see, now a total of four channels is marked as bad: the ones
that were already bad when we started – EEG 053
and MEG 2443
– and
the two channels we passed to mne_bids.mark_channels()
–
MEG 0112
and MEG 0131
. This shows that marking bad channels via
mne_bids.mark_channels()
, by default, is an additive procedure,
which allows you to mark additional channels as bad while retaining the
information about all channels that had previously been marked as bad.
If you instead would like to replace the collection of bad channels
entirely, pass the argument overwrite=True
:
bads = ['MEG 0112', 'MEG 0131']
mark_channels(bids_path=bids_path, ch_names=bads, status='bad', verbose=False)
raw = read_raw_bids(bids_path=bids_path, verbose=False)
print(f'After marking MEG 0112 and MEG 0131 as bad and passing '
f'`overwrite=True`, the following channels '
f'are now marked as bad:\n {", ".join(raw.info["bads"])}\n')
Out:
/Users/hoechenberger/Development/mne-bids/mne_bids/read.py:553: RuntimeWarning: The unit for channel(s) STI 001, STI 002, STI 003, STI 004, STI 005, STI 006, STI 014, STI 015, STI 016 has changed from V to NA.
raw.set_channel_types(ch_type_map_avail)
After marking MEG 0112 and MEG 0131 as bad and passing `overwrite=True`, the following channels are now marked as bad:
MEG 0112, MEG 0131, MEG 2443, EEG 053
Lastly, if you’re looking for a way to mark all channels as good, simply
pass an empty list as ch_names
, combined with overwrite=True
:
bads = []
mark_channels(bids_path=bids_path, ch_names=bads, status='bad', verbose=False)
raw = read_raw_bids(bids_path=bids_path, verbose=False)
print(f'After passing `ch_names=[]` and `overwrite=True`, the following '
f'channels are now marked as bad:\n {", ".join(raw.info["bads"])}\n')
Out:
/Users/hoechenberger/Development/mne-bids/mne_bids/read.py:553: RuntimeWarning: The unit for channel(s) STI 001, STI 002, STI 003, STI 004, STI 005, STI 006, STI 014, STI 015, STI 016 has changed from V to NA.
raw.set_channel_types(ch_type_map_avail)
After passing `ch_names=[]` and `overwrite=True`, the following channels are now marked as bad:
MEG 0113, MEG 0112, MEG 0111, MEG 0122, MEG 0123, MEG 0121, MEG 0132, MEG 0133, MEG 0131, MEG 0143, MEG 0142, MEG 0141, MEG 0213, MEG 0212, MEG 0211, MEG 0222, MEG 0223, MEG 0221, MEG 0232, MEG 0233, MEG 0231, MEG 0243, MEG 0242, MEG 0241, MEG 0313, MEG 0312, MEG 0311, MEG 0322, MEG 0323, MEG 0321, MEG 0333, MEG 0332, MEG 0331, MEG 0343, MEG 0342, MEG 0341, MEG 0413, MEG 0412, MEG 0411, MEG 0422, MEG 0423, MEG 0421, MEG 0432, MEG 0433, MEG 0431, MEG 0443, MEG 0442, MEG 0441, MEG 0513, MEG 0512, MEG 0511, MEG 0523, MEG 0522, MEG 0521, MEG 0532, MEG 0533, MEG 0531, MEG 0542, MEG 0543, MEG 0541, MEG 0613, MEG 0612, MEG 0611, MEG 0622, MEG 0623, MEG 0621, MEG 0633, MEG 0632, MEG 0631, MEG 0642, MEG 0643, MEG 0641, MEG 0713, MEG 0712, MEG 0711, MEG 0723, MEG 0722, MEG 0721, MEG 0733, MEG 0732, MEG 0731, MEG 0743, MEG 0742, MEG 0741, MEG 0813, MEG 0812, MEG 0811, MEG 0822, MEG 0823, MEG 0821, MEG 0913, MEG 0912, MEG 0911, MEG 0923, MEG 0922, MEG 0921, MEG 0932, MEG 0933, MEG 0931, MEG 0942, MEG 0943, MEG 0941, MEG 1013, MEG 1012, MEG 1011, MEG 1023, MEG 1022, MEG 1021, MEG 1032, MEG 1033, MEG 1031, MEG 1043, MEG 1042, MEG 1041, MEG 1112, MEG 1113, MEG 1111, MEG 1123, MEG 1122, MEG 1121, MEG 1133, MEG 1132, MEG 1131, MEG 1142, MEG 1143, MEG 1141, MEG 1213, MEG 1212, MEG 1211, MEG 1223, MEG 1222, MEG 1221, MEG 1232, MEG 1233, MEG 1231, MEG 1243, MEG 1242, MEG 1241, MEG 1312, MEG 1313, MEG 1311, MEG 1323, MEG 1322, MEG 1321, MEG 1333, MEG 1332, MEG 1331, MEG 1342, MEG 1343, MEG 1341, MEG 1412, MEG 1413, MEG 1411, MEG 1423, MEG 1422, MEG 1421, MEG 1433, MEG 1432, MEG 1431, MEG 1442, MEG 1443, MEG 1441, MEG 1512, MEG 1513, MEG 1511, MEG 1522, MEG 1523, MEG 1521, MEG 1533, MEG 1532, MEG 1531, MEG 1543, MEG 1542, MEG 1541, MEG 1613, MEG 1612, MEG 1611, MEG 1622, MEG 1623, MEG 1621, MEG 1632, MEG 1633, MEG 1631, MEG 1643, MEG 1642, MEG 1641, MEG 1713, MEG 1712, MEG 1711, MEG 1722, MEG 1723, MEG 1721, MEG 1732, MEG 1733, MEG 1731, MEG 1743, MEG 1742, MEG 1741, MEG 1813, MEG 1812, MEG 1811, MEG 1822, MEG 1823, MEG 1821, MEG 1832, MEG 1833, MEG 1831, MEG 1843, MEG 1842, MEG 1841, MEG 1912, MEG 1913, MEG 1911, MEG 1923, MEG 1922, MEG 1921, MEG 1932, MEG 1933, MEG 1931, MEG 1943, MEG 1942, MEG 1941, MEG 2013, MEG 2012, MEG 2011, MEG 2023, MEG 2022, MEG 2021, MEG 2032, MEG 2033, MEG 2031, MEG 2042, MEG 2043, MEG 2041, MEG 2113, MEG 2112, MEG 2111, MEG 2122, MEG 2123, MEG 2121, MEG 2133, MEG 2132, MEG 2131, MEG 2143, MEG 2142, MEG 2141, MEG 2212, MEG 2213, MEG 2211, MEG 2223, MEG 2222, MEG 2221, MEG 2233, MEG 2232, MEG 2231, MEG 2242, MEG 2243, MEG 2241, MEG 2312, MEG 2313, MEG 2311, MEG 2323, MEG 2322, MEG 2321, MEG 2332, MEG 2333, MEG 2331, MEG 2343, MEG 2342, MEG 2341, MEG 2412, MEG 2413, MEG 2411, MEG 2423, MEG 2422, MEG 2421, MEG 2433, MEG 2432, MEG 2431, MEG 2442, MEG 2443, MEG 2441, MEG 2512, MEG 2513, MEG 2511, MEG 2522, MEG 2523, MEG 2521, MEG 2533, MEG 2532, MEG 2531, MEG 2543, MEG 2542, MEG 2541, MEG 2612, MEG 2613, MEG 2611, MEG 2623, MEG 2622, MEG 2621, MEG 2633, MEG 2632, MEG 2631, MEG 2642, MEG 2643, MEG 2641, STI 001, STI 002, STI 003, STI 004, STI 005, STI 006, STI 014, STI 015, STI 016, EEG 001, EEG 002, EEG 003, EEG 004, EEG 005, EEG 006, EEG 007, EEG 008, EEG 009, EEG 010, EEG 011, EEG 012, EEG 013, EEG 014, EEG 015, EEG 016, EEG 017, EEG 018, EEG 019, EEG 020, EEG 021, EEG 022, EEG 023, EEG 024, EEG 025, EEG 026, EEG 027, EEG 028, EEG 029, EEG 030, EEG 031, EEG 032, EEG 033, EEG 034, EEG 035, EEG 036, EEG 037, EEG 038, EEG 039, EEG 040, EEG 041, EEG 042, EEG 043, EEG 044, EEG 045, EEG 046, EEG 047, EEG 048, EEG 049, EEG 050, EEG 051, EEG 052, EEG 053, EEG 054, EEG 055, EEG 056, EEG 057, EEG 058, EEG 059, EEG 060, EOG 061
Total running time of the script: ( 0 minutes 11.918 seconds)