Skip to content

get_montage and get_coordinates for Raw and Montage objects #7652

Closed

Description

@adam2392

Describe the problem

Once a user has set the montage, then getting the montage itself and data from it is not trivial.

Ideally, the users can get the actual xyz coordinates whether its an array, or dictionary via just a get function.

You have to do things like:

  1. ch_locs = raw.info['chs']['loc'][0:3]
    or
  2. ch_locs = [raw.info['dig'][idx]['r'][0:3] for idx in len(raw.info['dig'])]

In 1., it took me a bit to end up figuring out that the 12 point locations in are not relevant for the most part if I need the xyz coordinates. And the xyz are stored in the first 3 indices. This is at least for iEEG.

Note: In addition, idk if this is on purpose, but the raw.info['dig'] can be not in the same order as raw.info['ch_names'] especially if there was some reordering done when making ch_pos for the DigMontage. I don't think it affects internal code, but it further makes it non-trivial if you need access to the coordinates you want to work w/.

Describe your solution

An implementation at the Raw level for get_montage(), it simply returns the montage that is set for a Raw object, or returns an error message if no montage.

An implementation at the Montage level for get_coordinates(), which returns the xyz coordinates in it's 'm' form as a 3D array.

Ideally it looks like this:

montage = raw.montage
ch_locs = montage.get_coordinates()

Describe possible alternatives

get_coordinates could also be at the Raw level?

Additional context

See related discussion: mne-tools/mne-bids#393

Happy to submit a PR after discussion of if this is valid.

Activity

  1. larsoner commented on Apr 21, 2020

    @larsoner
    Member

    I would not do get_montage, a montage is just a way to set channel positions.

    I would add a inst.get_channel_positions() that for example returned a dict of the channel name: pos mapping. It would really just loop over info['chs'] to look at loc but indeed a user should not have to do this.

  2. agramfort commented on Apr 21, 2020

    @agramfort
    SponsorMember
  3. larsoner commented on Apr 21, 2020

    @larsoner
    Member

    Okay, fair enough

  4. drammock commented on Apr 21, 2020

    @drammock
    Member

    I'd also note that get_ch_positions (rather than get_channel_positions) is more consistent with other methods like inst.get_ch_types(). So if you end up doing both get_montage and get_xxx_positions then I think xxx should be ch, not channel.

  5. cbrnr commented on Apr 22, 2020

    @cbrnr
    Contributor

    Although it would be useful if we could extract the name of the original montage somehow (maybe just for the standard montages shipped with MNE).

  6. agramfort commented on Apr 22, 2020

    @agramfort
    SponsorMember
  7. cbrnr commented on Apr 22, 2020

    @cbrnr
    Contributor

    We could add a new info field, which contains the montage name every time the user does raw.set_montage. Of course, this does not mean that the name and the coordinates match (because the coordinates might have been changed after setting the montage), but something like info["montage_name"] would be nice to have. Maybe the value of this field could even be reset to None if someone tinkers with the coords, but I don't know if we have setters in place.

    Anyway, if this is not feasible it's not that important.

  8. agramfort commented on Apr 22, 2020

    @agramfort
    SponsorMember
  9. adam2392 commented on Apr 22, 2020

    @adam2392
    MemberAuthor

    Okay so:

    • inst.get_ch_positions() -> dictionary of channels and their xyz positions. This is pretty clear to me.

    Get_montage that returns a dig montage that could be fed to set_montage is to me the most consistent. I would like to get all dig points etc

    @agramfort what do you mean here? Implement a mne.get_montage() function, or an inst.get_montage()?

  10. agramfort commented on Apr 22, 2020

    @agramfort
    SponsorMember
  11. pchr-srf commented on Mar 24, 2024

    @pchr-srf

    Sorry to dig up this PR, but what is Inst in your code snippet? 😅

  12. cbrnr commented on Mar 24, 2024

    @cbrnr
    Contributor

    This typically refers to Raw, Epochs, or Evoked (depending on the context).

  13. pchr-srf commented on Mar 24, 2024

    @pchr-srf

    Ah, super quick! Yes, I just found that out, too. Thanks! Helping my partner with some analysis and super confused by everything 😅

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