ann, b = mne.preprocessing.annotate_amplitude(raw, peak = 1 ,flat=0.000, bad_percent=0.05, min_duration=5, picks='misc', verbose=None)
Dear MNE users,
I am trying to create an EEG preprocessing pipeline. I am currently struggling to remove and interpolate bad channels. Earlier, I have been told to use mne.preprocessing.annotate_amplitude but that is producing empty list instead of annotating the data and giving me list of flat channels. I have attached the code snippet that I am using to annotate the bad channels and the screenshot of the data.
raw = read_raw(fname, preload=True)
raw.set_channel_types({"Fp1": "eeg", "Fp2": "eeg", ...})
You can build the mapping dictionary programmatically:
raw = read_raw(fname, preload=True)
non_eeg_ch_names = ["AUX1", ...] # if you do have non EEG channels
ch_names = [ch for ch in raw.ch_names if ch not in non_eeg_ch_names]
raw.set_channel_types({ch: "eeg" for ch in ch_names})
It will annotate segments completely flat (exactly 0.) that are longer than min_duration or it will return the channel as bads if it is completely flat for more than bad_percent of the time.
import numpy as np
from mne import create_info
from mne.io import RawArray
from mne.preprocessing import annotate_amplitude
data = np.random.randn(3, 1024)
data[1, :] = 0.
raw = RawArray(data, create_info(3, 512, "eeg"))
annotations, bads = annotate_amplitude(raw, peak=None, flat=0.)
We get bads = ['1'] as expected.
On the dataset above, channels Cz, AFz seem completely flat, so they should be returned in bads.