# Including bad channels in autoreject

**URL:** <https://mne.discourse.group/t/including-bad-channels-in-autoreject/7369>\
**Category:** Support & Discussions\
**Tags:** autoreject\
**Created:** [August 14, 2023, 4:28pm UTC](https://mne.discourse.group/t/including-bad-channels-in-autoreject/7369 "2023-08-14T16:28:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![eort](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@eort](https://mne.discourse.group/u/eort)\
**Post date:** [August 14, 2023, 4:28pm UTC](https://mne.discourse.group/t/including-bad-channels-in-autoreject/7369/1 "2023-08-14T16:28:09Z")

</div>

Hi all,

I use autoreject to find optimal peak-to-peak rejection thresholds on my MEG data. Before running autoreject (local), I exclude bad channels that are notoriously bad. For some parts, autoreject seems to respect this exclusion (there is a warning, that these bad channels will be ignored, and in the progress bars, the reduced number of good channels are shown).  
However, when I plot the channels x epoch rejection matrix (good, bad, interpolated), Two of the channels that I had marked as bad, are consistently shown in blue across all epochs, ie. they are interpolated (see figure below).

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/9/91630782884a685477614d2fdd3b06e91bb39490.png)

What is happening here? Is this just a problem with the illustration or are these channels used after all in the determination of the thresholds, which channels are interpolated, etc?

Thanks,  
Eduard

---

<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:** [August 15, 2023, 4:57pm UTC](https://mne.discourse.group/t/including-bad-channels-in-autoreject/7369/2 "2023-08-15T16:57:43Z")

</div>

Hello,

Could you share some code snippet to look at, and the output of the `.info` attribute on the objects passed to autoreject?

Mathieu

---

<div class="post-metadata">

**Author:** ![mainakjas](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mainakjas/32/34_2.png) [@mainakjas](https://mne.discourse.group/u/mainakjas)\
**Post date:** [August 16, 2023, 7:28pm UTC](https://mne.discourse.group/t/including-bad-channels-in-autoreject/7369/3 "2023-08-16T19:28:00Z")

</div>

Hi Eduard,

I would suggest starting with one of the examples and the sample dataset. Do you observe this problem also there? If yes, we might have a bug or compatibility issue with newer MNE versions. Sharing a short code snippet as Mathieu suggested would also help in pinpointing the issue.

Mainak

---

<div class="post-metadata">

**Author:** ![eort](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@eort](https://mne.discourse.group/u/eort)\
**Post date:** [August 16, 2023, 8:05pm UTC](https://mne.discourse.group/t/including-bad-channels-in-autoreject/7369/4 "2023-08-16T20:05:35Z")

</div>

Hi both of you,

Here the code snippet that produced the plot from my starting post:

```python
# set parameters for autoreject
n_interpolates = np.array((1, 2, 3, 5, 7, 9))
consensus_percs = np.linspace(0.2, 0.7, 11)

# init autoreject object, picks are grads or mags respectively
rej = AutoReject(n_interpolates, consensus_percs, picks=picks,
                    thresh_method='bayesian_optimization')

# run the autoreject (local) algorithm
rej.fit(epochs)

# extract the log file
rej_log = rej.get_reject_log(epochs)

# plot
xlabels = reject_log.ch_names
image = reject_log.labels
image[image == 2] = 0.5 # move interp to 0.5
legend_label = {0: 'good', 0.5: 'interpolated', 1: 'bad'}
cmap = colors.ListedColormap(['white', 'blue', 'red'])
img = axes.imshow(image.T, cmap=cmap, vmin=0, vmax=1, interpolation='none')
plt.setp(axes, yticks=range(0, len(xlabels)), yticklabels=xlabels)
plt.setp(axes.get_yticklabels(), fontsize=2)
#add red box around rejected epochs
for idx in np.where(reject_log.bad_epochs)[0]:
    axes.add_patch(patches.Rectangle((idx - 0.5, -0.5), 1, len(xlabels),
                 linewidth=1, edgecolor='r', facecolor='none'))

```

The output of info I shall provide in about 2 weeks, as I am out of office for the next 2 weeks.

Eduard

---

<div class="post-metadata">

**Author:** ![mainakjas](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mainakjas/32/34_2.png) [@mainakjas](https://mne.discourse.group/u/mainakjas)\
**Post date:** [August 23, 2023, 4:41am UTC](https://mne.discourse.group/t/including-bad-channels-in-autoreject/7369/5 "2023-08-23T04:41:22Z")

</div>

Hi Eduard,

Can you see this: [https://github.com/autoreject/autoreject/issues/309](https://github.com/autoreject/autoreject/issues/309)

looks like someone hit the same issue as you but didn’t get around to making a pull request. If you have bandwidth, any help would be welcome.

Mainak
