Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mne.channels.read_ch_adjacency 'picks' argument does not function as described #11608

Closed
aaronjnewman opened this issue Mar 28, 2023 · 3 comments
Labels
DOC ENH sprint-2023 Issues reserved for the 2023 Intermediate Dev Training

Comments

@aaronjnewman
Copy link

Proposed documentation enhancement

The explanation of the picks for mne.channels.read_ch_adjacency reads:

Channels to include. Slices and lists of integers will be interpreted as channel indices. In lists, channel type strings (e.g., ['meg', 'eeg']) will pick channels of those types, channel name strings (e.g., ['MEG0111', 'MEG2623'] will pick the given channels. Can also be the string values “all” to pick all channels, or “data” to pick data channels. None (default) will pick all channels. Note that channels in info['bads'] will be included if their names or indices are explicitly provided. Picks must match the template.

However, mne.channels.read_ch_adjacency('elec1005', picks=['eeg']) generates an error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-81-6e28f3bd522a> in <module>
----> 1 mne.channels.read_ch_adjacency('elec1005', picks=['eeg'])

/opt/conda/lib/python3.9/site-packages/mne/channels/channels.py in read_ch_adjacency(fname, picks)
   1504     nb = loadmat(fname)['neighbours']
   1505     ch_names = _recursive_flatten(nb['label'], str)
-> 1506     picks = _picks_to_idx(len(ch_names), picks)
   1507     neighbors = [_recursive_flatten(c, str) for c in
   1508                  nb['neighblabel'].flatten()]

/opt/conda/lib/python3.9/site-packages/mne/io/pick.py in _picks_to_idx(info, picks, none, exclude, allow_empty, with_ref_meg, return_kind)
   1011         raise ValueError('picks must be 1D, got %sD' % (picks.ndim,))
   1012     if picks.dtype.char in ('S', 'U'):
-> 1013         picks = _picks_str_to_idx(info, picks, exclude, with_ref_meg,
   1014                                   return_kind, extra_repr, allow_empty,
   1015                                   orig_picks)

/opt/conda/lib/python3.9/site-packages/mne/io/pick.py in _picks_str_to_idx(info, picks, exclude, with_ref_meg, return_kind, extra_repr, allow_empty, orig_picks)
   1046     # special case for _picks_to_idx w/no info: shouldn't really happen
   1047     if isinstance(info, int):
-> 1048         raise ValueError('picks as str can only be used when measurement '
   1049                          'info is available')
   1050 

ValueError: picks as str can only be used when measurement info is available

The same error is generated if I provide a list of channel names, e.g.:

chs = ['Fp1', 'Fp2', 'F7', 'F3', 'Fz', 'F4', 'F8', 'FC5', 'FC1', 'FC2', 'FC6', 'T7', 'C3', 'Cz', 'C4', 'T8', 'TP9', 'CP5', 'CP1', 'CP2', 'CP6', 'TP10', 'P7', 'P3', 'Pz', 'P4', 'P8', 'PO9', 'O1', 'Oz', 'O2', 'PO10']
mne.channels.read_ch_adjacency('elec1005', picks=chs)

Am I mis-reading the docs, or is this an error either in the code or the docs?

@drammock
Copy link
Member

I think the docstring is wrong. The built-in neighbor files don't keep track of channel type information, so picking by channel type can't work. The second case (giving a list of channel names) could work though... easiest might be to create a fake Info from the ch_names present in the neighbors file, and pass that to _picks_to_idx instead of passing len(ch_names). @aaronjnewman do you feel up to making a PR that does that?

@drammock drammock added the ENH label Mar 28, 2023
@drammock drammock added the sprint-2023 Issues reserved for the 2023 Intermediate Dev Training label Jul 5, 2023
zubara added a commit to zubara/mne-python that referenced this issue Oct 4, 2023
larsoner added a commit that referenced this issue Oct 5, 2023
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Daniel McCloy <dan@mccloy.info>
larsoner added a commit to larsoner/mne-python that referenced this issue Oct 10, 2023
* upstream/main: (37 commits)
  Use constrained layout in matplotlib visualization (mne-tools#12050)
  Add raw stc (mne-tools#12001)
  [MRG] update codeowners (mne-tools#12089)
  DOC: Morlet wavelet length in tfr_morlet (mne-tools#12073)
  BUG: Fix bug with mne browser backend (mne-tools#12078)
  Cache avatars (mne-tools#12077)
  BUG: Fix bug with ch_name resolution (mne-tools#12086)
  add unicode roundtrip for FIF (mne-tools#12080)
  add Ivan to names.inc (mne-tools#12081)
  MAINT: Work around PySide 6.5.3 event loop error (mne-tools#12076)
  mne-tools#11608, buggfix and docstring update (mne-tools#12066)
  MAINT: Fix broken examples (mne-tools#12074)
  Add UI Event linking to DraggableColorbar (mne-tools#12057)
  handle lazy loading through .pyi type stubs (mne-tools#12072)
  BUG: Fix bug with sensor_colors (mne-tools#12068)
  clean  up some deprecations (mne-tools#12067)
  Allow not dropping bads when creating or plotting Spectrum objs (mne-tools#12006)
  Collapsible html repr for raw/info (mne-tools#12064)
  BUG: Fix bug with pickling MNEBadsList (mne-tools#12063)
  add details for Denis (mne-tools#12065)
  ...
@sappelhoff
Copy link
Member

Note: @dominikwelke is working on this

@dominikwelke
Copy link
Contributor

dominikwelke commented Nov 13, 2023

actually, I just see that this has already been adressed (also the docstring was changed, I just missed this as I first looked at the stable doc).

so this can be closed I guess
@larsoner - you did this, right? anything still open about this?

snwnde pushed a commit to snwnde/mne-python that referenced this issue Mar 20, 2024
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Daniel McCloy <dan@mccloy.info>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DOC ENH sprint-2023 Issues reserved for the 2023 Intermediate Dev Training
Development

No branches or pull requests

4 participants