question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

get_montage and get_coordinates for Raw and Montage objects

See original GitHub issue

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: https://github.com/mne-tools/mne-bids/pull/393

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
agramfortcommented, Apr 21, 2020

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

1reaction
larsonercommented, Apr 21, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Montage: Group Video Gifts
Montage makes group video gifts easy. Make a happy birthday video Montage, a wedding video Montage, an employee appreciation gift... any excuse to...
Read more >
Working with sensor locations — MNE 1.3.dev0 documentation
The 3D coordinates of MEG sensors are included in the raw recordings from MEG ... Montage objects have a plot method for visualizing...
Read more >
NavigatorDlg.cpp
{ sinceLastDone = SEMTickInterval(mLastAcqDoneTime); // For a montage, ... the map will\n" "be assigned a new raw stage position at the current stage ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found