annotation of flat channels

  • MNE version: 1.2.2
  • operating system: Windows 10

Data

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.

I would appreciate any help in this direction!

Thanks

I will not reply on the old thread but on this one instead.

Several points strike me:

  • Your data is not in Volts
  • You run the function on picks='misc'
  • Cz seems clearly flat. Is it by any chance the reference of your EEG system? (in which case you do NOT want to set it as ‘bad’)

To set the channel type to EEG, you can use raw.set_channel_types (mne.io.Raw — MNE 1.3.dev0 documentation).

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})

To change the scaling, you can use raw.apply_function (mne.io.Raw — MNE 1.3.dev0 documentation). For instance from uV to Volts:

raw = ...
raw.apply_function(lambda x: x*1e-6, picks="eeg", channel_wise=False)

This really won’t do anything, as no peak-to-peak amplitude can be smaller than zero. You must set this to something greater than zero.

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.

1 Like

Interesting, I always thought this was a half-open interval! TIL!

I’ve worked with a lot of eeg with flat/bad channels and none of them are EXACTLY flat unless you’re using it as a reference channel.

@CJ In this case, you can provide flat=threshold instead of flat=0. and the function will annotate the channel sub-thresholds.