Skip to content

API: picks as list of string #4502

Closed
Closed

Description

@kingjr

Picking a particular channel is currently relatively complex for new users.

It either involves pythonic tricks:

picks = [ii for ii, ch in enumerate(epochs.ch_names) if ch == 'mychan']
epochs.plot(picks=picks)

Or master of MNE's functions:

picks = mne.pick_channels(evoked.info. [`my_chan`])
epochs.plot(picks=picks)

Proposal 1

👍 0
Since picks is always referring to a list of int and ch_names is always a list of str, I propose that we accept picks ot be a list of str:

evoked.plot(picks=list(range(10)))
epochs.plot(picks=['my_chan'])

Proposal 2

👍 0

Accepting the parameter picks to be a list of int (for indexing), a list of str (to find channel names) or a dict (to quickly select channel types).

evoked.plot(picks=list(range(10)))
evoked.plot(picks=['MEG 1132', 'MEG 1022'])
evoked.plot(picks=dict(grad=True, eeg=False))
  • advantage: no deprecation, simplification of channel picking
  • disadvantage: keep clunky pick_type API

Proposal 3

👍 0

Same as proposal 2, but change pick_types to accept a types key that would accept list of str. This would allow

evoked.plot(picks=list(range(10)))
evoked.plot(picks=['MEG 1132', 'MEG 1022'])
evoked.plot(picks=dict(grad=True, eeg=False))
evoked.plot(picks=dict(types=('eeg', 'mag')))
mne.pick_types(info, types=('eeg', 'mag'))
  • advantage: easier to loop across channel types, no deprecation
  • disadvantage: more than one way to do pick_types

Proposal 4:

👍 4 (@larsoner, @kingjr, @nbara, @choldgraf)

Same as proposal 1, but automatically detect if str refer to ch_names of ch_types.

evoked.plot(picks=list(range(10)))
evoked.plot(picks=['MEG 1132', 'MEG 1022'])
evoked.plot(picks=('eeg', 'meg'))
  • inconvenient: risk of conflict between channel names and channel types
  • advantage: easier to loop across channel types

Activity

  1. dengemann commented on Aug 18, 2017

    @dengemann
    Member
  2. kingjr commented on Aug 18, 2017

    @kingjr
    MemberAuthor

    @dengemann For pick_types we could accept picks to be a dict

  3. dengemann commented on Aug 18, 2017

    @dengemann
    Member
  4. kingjr commented on Aug 18, 2017

    @kingjr
    MemberAuthor

    Proposal 2

    Sorry, I meant accepting the parameter picks to be a list of int (for indexing), a list of str (to find channel names) or a dict (to quickly select channel types).

    evoked.plot(picks=list(range(10)))
    evoked.plot(picks=['MEG 1132', 'MEG 1022'])
    evoked.plot(picks=dict(grad=True, eeg=False))

    EDIT: Copied to top

  5. dengemann commented on Aug 18, 2017

    @dengemann
    Member
  6. kingjr commented on Aug 18, 2017

    @kingjr
    MemberAuthor

    I see. However, the issue is that a list of types would conflict with a list of names.

    evoked.plot(picks=['MEG 1132', 'MEG 1022'])
    evoked.plot(picks=['mag', 'grad'])

    I'm thus in favor of Proposal 2, i.e. accepting list of string and dict.

    I'll update the above description.

  7. larsoner commented on Aug 18, 2017

    @larsoner
    Member

    @kingjr I updated your proposal to to be Py3k-friendly, and to reorder with list(range(...)) first (since it's what we have now)

  8. larsoner commented on Aug 18, 2017

    @larsoner
    Member

    It does seem like proposal 2 would just require a ~6-line private function anytime we use picks, so it's not so bad from an implementation standpoint. And from a user standpoint it's pretty simple.

    It does have overlap, e.g. inst.pick_types(['EEG 001', 'EEG 002']) will be the same as inst.pick_channels(['EEG 001', 'EEG 002']), but I can live with that.

    @kingjr if your sense is that this will reduce pain substantially for new users, +1 from me

  9. dengemann commented on Aug 18, 2017

    @dengemann
    Member
  10. kingjr commented on Aug 18, 2017

    @kingjr
    MemberAuthor

    I would still prefer proposal 1 (list of channel types). It would allow me to kill lots of code in virtually any project.

    Can you describe in what way Proposal 2 wouldn't?

    I don't think we would ever hit a case where channel names and type names are identical.

    This would still require a "smart" guess; not safe IMO.

    For updating mne.pick_types along these lines we would anyways have to add a new keyword.

    Why? We wouldn't need to update pick_types in any of these proposal

  11. larsoner commented on Aug 18, 2017

    @larsoner
    Member

    Why? We wouldn't need to update pick_types in any of these proposal

    Agreed, we would just update any function that has picks argument. Instead of taking only list of int, take the other things, too. pick_types and pick_channels would remain the same.

  12. dengemann commented on Aug 18, 2017

    @dengemann
    Member
  13. kingjr commented on Aug 18, 2017

    @kingjr
    MemberAuthor

    I agree; although for this we can propose an orthogonal PR where mne.pick_types accepts a list of str

    mne.pick_types(info, types=('mag', 'grad', 'eog'))
  14. dengemann commented on Aug 18, 2017

    @dengemann
    Member
  15. choldgraf commented on Aug 18, 2017

    @choldgraf
    Contributor

    I'm +1 with

    mne.pick_types(info, types=('mag', 'grad', 'eog'))

    I think this is much more descriptive than having a gigantic list of true/false.

    I'm also +1 for allowing lists of strings. I'm a little hesitant to allow for dict(eeg=True) since I agree that is a clunky API already.

    What if instead of dict(grad=True.., we allowed dict(types=['eeg', 'meg', ...])?

  16. 37 remaining items

  17. agramfort commented on Aug 21, 2017

    @agramfort
    SponsorMember
  18. jasmainak commented on Aug 21, 2017

    @jasmainak
    Member

    I honestly find the existing picks API quite intuitive and well designed, but what I find missing is a clear documentation or tutorial.

    For me, picks is nothing but a list of indices and all the pick_xxx functions are helpers to compute these indices. If you are using a scripting language like Matlab or Python, indexing is one of the first thing you learn.

    If you change the semantics of what picks is (e.g., in Proposal 4), this will require a change in the code not just in code but also in other repos (like autoreject). [@dengemann up for another PR? :P ]

    Please consider carefully the implications of this change

  19. dengemann commented on Aug 21, 2017

    @dengemann
    Member
  20. nbara commented on Aug 21, 2017

    @nbara
    Contributor

    @jasmainak Not sure I agree with you.

    Like many others I'm guessing, I spend most of my analysis time doing exploratory work, i.e. quickly looking at my data to get a "feel" of how they look, or check that e.g. an basic ERP is here or not.

    And to do this the current system is particularly unintuitive. For instance I'll want to look at channel Oz, or Cz, and I don't care what index they correspond to (esp. given that these indices might change depending on the layout), ideally I'd just want to do evoked.plot('Cz'), and then quickly see I I get something similar in another channel evoked.plot('Cz'). Then I might wan to try new filter settings on all my channels before plotting again. This takes quite a lot of keystrokes currently. Not to mention that the process of copy-picking before plotting is just... weird.

  21. agramfort commented on Aug 21, 2017

    @agramfort
    SponsorMember
  22. choldgraf commented on Aug 21, 2017

    @choldgraf
    Contributor

    *and ECoG people have 0 ability to predict their channel names ahead of time

  23. larsoner commented on Aug 21, 2017

    @larsoner
    Member
  24. jasmainak commented on Aug 21, 2017

    @jasmainak
    Member

    @nbara have you used evoked.plot_topo? It seems to be exactly for your requirement.

  25. jasmainak commented on Aug 21, 2017

    @jasmainak
    Member

    No, proposal 4 adds functionality, it does not remove existing functionality of None or list of int, i.e. it is backward compatible, unless you have some code that relies on errors being thrown for non-int lists.

    I think we would have to handle non-int lists as you correctly anticipate. When it is int, it's really easy to index matrices without thinking twice. You're probably proposing that picks is internally handled still as an int list but I guess that would need additional code ...

  26. nbara commented on Aug 21, 2017

    @nbara
    Contributor

    @jasmainak No I wasn't aware of plot_topo, thanks ! Does it work for TF data?
    @agramfort #4221 looks very neat indeed!

    MEG people don't.... they are just stupid names andnumbers.

    O_O I used to work with MEG and I knew exactly where my channels were (on a CTF system, I used to plot a bunch of channels together using wildcards such as MRT* to get all right temporal sensors etc.).
    As for ECoG, well yes... But wouldn't you just have some kind of map/image showing electrode implantation and use that to look at your activations for each patient ? I mean, it's not about knowing the location in advance, in some cases it's just more convenient to plot stuff by some kind of label instead of by number. Or maybe that's just me :)

    Anyway, I don't mean to pollute this thread too much. Still in favour of Proposal 4.

  27. jasmainak commented on Aug 21, 2017

    @jasmainak
    Member

    @jasmainak No I wasn't aware of plot_topo, thanks ! Does it work for TF data?

    yep, take a look here :)

  28. agramfort commented on Aug 22, 2017

    @agramfort
    SponsorMember
  29. larsoner commented on Aug 22, 2017

    @larsoner
    Member
  30. kingjr commented on Aug 22, 2017

    @kingjr
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions