Skip to content

get_montage and get_coordinates for Raw and Montage objects #7652

@adam2392

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.

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