Error using ica.plot_sources - error says channel names are missing but they are not

Hi all,

I am trying to run an ICA decomposition on spinal electrophysiology data, it’s very simple code at the minute, and the relevant part of the code looks like this:

ICA

ica = mne.preprocessing.ICA(n_components=15, max_iter='auto', random_state=97)
ica.fit(raw_filtered)

raw.load_data()
ica.plot_sources(raw, show_scrollbars=False)
plt.show()

I’m essentially following the tutorial here at the moment (Repairing artifacts with ICA — MNE 0.24.1 documentation)

Unfortunately, the above code throws up the following error:
Traceback (most recent call last):
File “/data/pt_02569/python/main.py”, line 67, in
run_post_ica(subject, condition, srmr_nr, sampling_rate)
File “/data/pt_02569/python/Post_ICA.py”, line 66, in run_post_ica
ica.plot_sources(raw, show_scrollbars=False)
File “/data/pt_02569/python/venv/lib/python3.6/site-packages/mne/preprocessing/ica.py”, line 1852, in plot_sources
show_scrollbars=show_scrollbars)
File “/data/pt_02569/python/venv/lib/python3.6/site-packages/mne/viz/ica.py”, line 88, in plot_ica_sources
show_scrollbars=show_scrollbars)
File “/data/pt_02569/python/venv/lib/python3.6/site-packages/mne/viz/ica.py”, line 989, in _plot_sources
inst_array.set_annotations(inst.annotations)
File “”, line 24, in set_annotations
File “/data/pt_02569/python/venv/lib/python3.6/site-packages/mne/io/base.py”, line 659, in set_annotations
new_annotations._prune_ch_names(self.info, on_missing)
File “/data/pt_02569/python/venv/lib/python3.6/site-packages/mne/annotations.py”, line 422, in _prune_ch_names
on_missing, 'At least one channel name in ’
File “/data/pt_02569/python/venv/lib/python3.6/site-packages/mne/utils/check.py”, line 757, in _on_missing
raise error_klass(msg)
ValueError: At least one channel name in annotations missing from info: S35

I can’t find the reason for this error - if I print raw.ch_names and raw_filtered.ch_names, I get the following identical output:
[‘S35’, ‘S24’, ‘S36’, ‘Iz’, ‘S17’, ‘S15’, ‘S32’, ‘S22’, ‘S19’, ‘S26’, ‘S28’, ‘S9’, ‘S13’, ‘S11’, ‘S7’, ‘SC1’, ‘S4’, ‘S18’, ‘S8’, ‘S31’, ‘SC6’, ‘S12’, ‘S16’, ‘S5’, ‘S30’, ‘S20’, ‘S34’, ‘AC’, ‘S21’, ‘S25’, ‘L1’, ‘S29’, ‘S14’, ‘S33’, ‘S3’, ‘AL’, ‘L4’, ‘S6’, ‘S23’, ‘ECG’]

and if i print the ica.info variable, the ch_names are similarly given as:
ch_names: S35, S24, S36, Iz, S17, S15, S32, S22, S19, S26, S28, S9, S13, …

So evidently channel S35 is present in both the ica and the raw structures, so I can’t understand how this error (‘At least one channel name in annotations missing from info: S35’) comes to be.

Any help/advice would be greatly appreciated!

  • MNE version: 0.23.4
  • operating system: Ubuntu 18.04.6

Edit to add: ica.plot_overlay is working as expected so it is potentially just a bug in the plot_sources function

Sorry for the late reply, but I think this is the key info:

did you inspect raw.annotations and whether you have channel-specific annotations? This is possible in more recent versions of MNE-Python, see ch_names parameter here: mne.Annotations — MNE 1.6.0 documentation

1 Like