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