# The find\_bads\_muscle algorithm does not take bad channels into account and throws an AssertionError

**URL:** <https://mne.discourse.group/t/the-find-bads-muscle-algorithm-does-not-take-bad-channels-into-account-and-throws-an-assertionerror/5967>\
**Category:** Support & Discussions\
**Tags:** eeg, ica\
**Created:** [November 21, 2022, 11:57am UTC](https://mne.discourse.group/t/the-find-bads-muscle-algorithm-does-not-take-bad-channels-into-account-and-throws-an-assertionerror/5967 "2022-11-21T11:57:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jruiz](https://avatars.discourse-cdn.com/v4/letter/j/48db29/32.png) [@jruiz](https://mne.discourse.group/u/jruiz)\
**Post date:** [November 21, 2022, 11:57am UTC](https://mne.discourse.group/t/the-find-bads-muscle-algorithm-does-not-take-bad-channels-into-account-and-throws-an-assertionerror/5967/1 "2022-11-21T11:57:16Z")

</div>

- MNE version: e.g. 1.2.1
- operating system: Windows 10

Hi everyone!

I think I’ve found a bug in the _find\_bads\_muscle_ algorithm.

I have a 19 channel raw eeg file, 2 of which I have manually marked as bad channels, i.e. `raw.info['bads'] = ['Fp4', 'C3']`. When I pass it to the ICA these two channels are excluded correctly: `Fitting ICA to data using 17 channels (please be patient, this may take a while)`.

However, when I call the `ica.find_bads_muscle(raw)` function, the following _AssertionError_ is thrown:

```python
File "***\lib\site-packages\mne\preprocessing\ica.py", line 1791, in find_bads_muscle
    assert pos.shape[0] == components.shape[0] # pos for each sensor

```

When debugging, I check that `shape(components) == (17, 17)` and `shape(pos) == (19, 2)`. Logic tells me that pos should have 17 rows, not 19, so it is not taking into account the bad channels.

For my code to work, it is not enough to temporarily remove the bad channels, i.e. `raw.info['bads'] = []`, but I must remove them completely by `drop_channels` (using a `raw.copy()`).

Can you tell me if this is indeed a bug?

Thank you very much!
