You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
get_montage and get_coordinates for Raw and Montage objects #7652
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:
ch_locs = raw.info['chs']['loc'][0:3]
or
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.
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.
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.
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.
Activity
larsoner commentedon Apr 21, 2020
I would not do
get_montage, amontageis just a way to set channel positions.I would add a
inst.get_channel_positions()that for example returned adictof the channel name: pos mapping. It would really just loop overinfo['chs']to look atlocbut indeed a user should not have to do this.agramfort commentedon Apr 21, 2020
larsoner commentedon Apr 21, 2020
Okay, fair enough
drammock commentedon Apr 21, 2020
I'd also note that
get_ch_positions(rather thanget_channel_positions) is more consistent with other methods likeinst.get_ch_types(). So if you end up doing bothget_montageandget_xxx_positionsthen I thinkxxxshould bech, notchannel.cbrnr commentedon Apr 22, 2020
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).
agramfort commentedon Apr 22, 2020
cbrnr commentedon Apr 22, 2020
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 likeinfo["montage_name"]would be nice to have. Maybe the value of this field could even be reset toNoneif 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.
agramfort commentedon Apr 22, 2020
adam2392 commentedon Apr 22, 2020
Okay so:
inst.get_ch_positions()-> dictionary of channels and their xyz positions. This is pretty clear to me.@agramfort what do you mean here? Implement a mne.get_montage() function, or an inst.get_montage()?
agramfort commentedon Apr 22, 2020
pchr-srf commentedon Mar 24, 2024
Sorry to dig up this PR, but what is
Instin your code snippet? 😅cbrnr commentedon Mar 24, 2024
This typically refers to
Raw,Epochs, orEvoked(depending on the context).pchr-srf commentedon Mar 24, 2024
Ah, super quick! Yes, I just found that out, too. Thanks! Helping my partner with some analysis and super confused by everything 😅