ValueError: All picks must be < n_channels (20), got 20

Hello

I am writting this code and get this error: All picks must be < n_channels (20), got 20.

EEG is an array with EDF signlas.

I hope anyone can help me

rereferenced_raw=

for i in range(len(EEG)):
referenced_raw = mne.io.RawArray(EEG[i], info)
referenced_raw.add_events(events_array, stim_channel= β€˜DC7’, replace= True)
referenced_raw.set_montage(montage = montage)
rereferenced_raw.append(referenced_raw)
rereferenced_raw[i].plot(duration=5.,start = 0.0,scalings=dic)

plt.show()

  • MNE version: e.g. 0.24.0
  • operating system: e.g. Windows 10

Hello,

All picks must be < n_channels (20), got 20 means that you provided the value 20 to select channels in a recording which only includes 20 channels. As indexing is 0-indexed, the maximum value is 19 (note the strictly inferior to n_channels (20) in the error message).
I can not tell you which indexing or which line in your code is the culprit based on the information in your question. If you share a code snippet, please share a valid and complete code snippet.

What is EEG? A list? An array? Of what shape?
What is the correct indentation?
What is the complete error traceback (message)?

Also, you should probably consider updating your version of MNE, the 0.24.0 is 1.5 years old and many bugfixes and new features have been added.

Mathieu

EEG is a list, I wanto to read the list of the EEG signals

Complet error is follow:


ValueError Traceback (most recent call last)
in
1 rereferenced_raw=
2 for i in range(len(EEG)):
----> 3 referenced_raw = mne.io.RawArray(EEG[i], info)

in init(self, data, info, first_samp, copy, verbose)

6 frames
/usr/local/lib/python3.9/dist-packages/mne/io/pick.py in picks_to_idx(info, picks, none, exclude, allow_empty, with_ref_meg, return_kind, picks_on)
1044 % (-n_chan, orig_picks))
1045 if (picks >= n_chan).any():
β†’ 1046 raise ValueError('All picks must be < n
%s (%d), got %r’
1047 % (picks_on, n_chan, orig_picks))
1048 picks %= n_chan # ensure positive

ValueError: All picks must be < n_channels (20), got 20

What is EEG signals? Numpy arrays I expect? And of what shape?

I think you are providing an info with a given number of channels and an array with a different number of channels, thus an error is raised due to the mismatch.

In the figures I show you whay shape is EEG and the error.

I hope you can help me to solve.
Thank you



Please don’t post screenshots, they are difficult to work with. You can provide code directly in the message and format it with Ctrl+E or the associated button in the edition bar.
Those code snippets don’t make a lot of sense to me, each element in your list EEG seems to be a Raw object returned by read_raw_edf. RawArray is used to create a Raw object from a numpy array of shape (n_channels, n_times) and an Info, while in your case you are providing EEG[i] which seems to be already a Raw object.

Maybe have a look through this tutorial: Creating MNE-Python data structures from scratch β€” MNE 1.3.1 documentation

It might help you understand the data structure concepts.

1 Like

Dear Mathieu, I already solved it. Thank you very much

Hi Isabel. I am trying to work with an EEG signal and am having the same error thrown. Can you please help me out?

@Mel please open a separate question thread for your question β€” this particular error can arise from many different causes and the best way to solve it is for you to provide a reproducible code sample of your own (the fix that worked for @isabelceo might not work for your case)