# annotation of flat channels

**URL:** <https://mne.discourse.group/t/annotation-of-flat-channels/6008>\
**Category:** Support & Discussions\
**Created:** [November 29, 2022, 3:28pm UTC](https://mne.discourse.group/t/annotation-of-flat-channels/6008 "2022-11-29T15:28:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![BilalKhan](https://avatars.discourse-cdn.com/v4/letter/b/e36b37/32.png) [@BilalKhan](https://mne.discourse.group/u/BilalKhan)\
**Post date:** [November 29, 2022, 3:28pm UTC](https://mne.discourse.group/t/annotation-of-flat-channels/6008/1 "2022-11-29T15:28:23Z")

</div>

- MNE version: 1.2.2
- operating system: Windows 10

Data

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/1/168b1998db9f026fc079fb3fa09a18a071621b44.png)

```python
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

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [November 29, 2022, 10:35pm UTC](https://mne.discourse.group/t/annotation-of-flat-channels/6008/2 "2022-11-29T22:35:24Z")

</div>

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](https://mne.tools/dev/generated/mne.io.Raw.html#mne.io.Raw.set_channel_types)).

```python
raw = read_raw(fname, preload=True)
raw.set_channel_types({"Fp1": "eeg", "Fp2": "eeg", ...})

```

You can build the mapping dictionary programmatically:

```python
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](https://mne.tools/dev/generated/mne.io.Raw.html#mne.io.Raw.apply_function)). For instance from uV to Volts:

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

```

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [November 30, 2022, 6:54am UTC](https://mne.discourse.group/t/annotation-of-flat-channels/6008/3 "2022-11-30T06:54:53Z")

</div>

> [@BilalKhan](#):
>
> `flat=0.000`

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.

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [November 30, 2022, 10:14am UTC](https://mne.discourse.group/t/annotation-of-flat-channels/6008/4 "2022-11-30T10:14:56Z")

</div>

> [@richard](#):
>
> 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.

```python
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`.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [November 30, 2022, 11:19am UTC](https://mne.discourse.group/t/annotation-of-flat-channels/6008/5 "2022-11-30T11:19:15Z")

</div>

> [@mscheltienne](#):
>
> It will annotate segments completely flat (exactly 0.)

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

---

<div class="post-metadata">

**Author:** ![CJ-Wave](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cj-wave/32/2109_2.png) [@CJ-Wave](https://mne.discourse.group/u/CJ-Wave)\
**Post date:** [December 1, 2022, 12:31am UTC](https://mne.discourse.group/t/annotation-of-flat-channels/6008/6 "2022-12-01T00:31:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [December 1, 2022, 9:01am UTC](https://mne.discourse.group/t/annotation-of-flat-channels/6008/7 "2022-12-01T09:01:36Z")

</div>

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