The find_bads_muscle algorithm does not take bad channels into account and throws an AssertionError

  • 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.['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:

File "***\lib\site-packages\mne\preprocessing\", 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.['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!