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
We can make read_montage and read_dig_montage both return a new Digitization class that is a thin wrapper around what is already in info['dig'], namely a list of dicts storing locations of channels, fiducials, and extra (headshape) points. Methods:
EDIT: One additional thing this Digitization class will need to store that the info['dig'] does not is the channel names associated with digitized EEG points. The EEG points have a field for which number they correspond to, so the Digitization class would need to somehow include a number-to-name mapping. In Neuromag data this is not a problem because it just corresponds to REF (not a channel) and then the ascending-order EEG### channels.
btw I probably shouldn't be the one to implement this PR as I don't have much experience with the philosophy behind montages. Would a pick_channels method just change the selection and ch_names attributes? And in that case it should probably be a mixin that both DigMontage and Montage import from.
pinging @agramfort and @Eric89GXL as maybe they have thoughts
That sounds good to me. Is there any clear place in the docs where montage objects are explained? E.g., when to use montage vs. digmontage? And maybe explaining the proper way to use the objects after this PR is done? Not sure if that's something that comes up as a confusion point but it couldn't hurt. I might be able to spend time doing this at the docathon in March.
I have wondered lately if we should get rid of Montage and DigMontage altogether and just make a Digitization class. Really both Montage and DigMontage provide positions in space of some subset of: anatomical points, cHPI, electrodes, and extra points. We already have a complete way to store this information, and it's given by info['dig']. Each of Montage and DigMontage have bits of this functionality but are incomplete -- they aren't necessary careful or consistent in treatment of coordinate frames, channel names, etc. In the long run I think we'd benefit from a major refactoring here.
No strong feeling but I would not really know what exactly needs to be done.
Yeah that's part of the problem. The distinction between Montage and DigMontage comes up a lot, and the use cases aren't entirely clear so people seem to have trouble keeping them straight.
We currently have two functions, read_montage and read_dig_montage, that give rise to Montage and DigMontage, both of which overlap in terms of data they can contain (channel info).
Here is a starting proposal:
Create a Digitization class. This would be a light wrapper around list that essentially becomes what is in info['dig']. Additional functions
Provide function for transforming points to head coord frame.
Provide function for computing dev_head_t.
Deprecate read_montage and read_dig_montage in favor of read_digitization, which can read both standard montages and individualized digitizations.
Deprecate set_montage function in favor of set_digitization.
@teonbrooks you worked on these classes a lot, WDYT?
What is the conceptual difference between something like the montage classes, and the way that the nipy ecosystem (e.g. nibabel) handles coordinate frames etc? Would it be worth trying to create resemblances in the API between the two? Or is the usecase too different
Maybe. AFAIK they provide transformation matrices to get between frames -- we do this in some places like info['dev_head_t']. But I'm not sure if they have equivalent use cases to what we're going for here, which is to provide locations of specific points in multiple coordinate frames (sometimes the same point in multiple frames, or different points in different frames). Plus we already have something that does this tracking of locations, frames, and point types -- info['dig'] is a simple list of dicts that is used all over our code to do this, so there are advantages to staying close to this format.
cool - I agree it sounds like a big PITA to change the API and would probably confuse users. Maybe the answer is just some nicely-written tutorials and guides etc. (after a refactor if that's gonna happen)
I think that it if changes an API that is used in lots of other places in MNE, or that lots of other users are already used to, then probably not worth it. If it's more under-the-hood that wouldn't require a shift in how people conceptualize the code, but that streamlines things and reduces redundancy, while making it easier to add better features, then I think it's worth it. It sounds like a full nipy-like refactor would be the former, while your idea of refactoring is more the latter. WDYT?
Mine would be a bit of the former, too. But it would unify how we treat things in a nice way. I don't see any real advantages to doing what nipy does, I don't think people cross MNE and nipy enough to justify the extra work.
I am not against a single class but to me digitization refers to measured
locations and there can be more than the number of channels (eg dig points
on the face etc.) At least DigMontage and Montage were conceptually
different since using standard montage restricted to channel locations
differs from a arbitrary number of dig points obtained eg with a polhemus
system
At least DigMontage and Montage were conceptually different since using standard montage restricted to channel locations differs from a arbitrary number of dig points obtained eg with a polhemus system
This concept is nice, yeah. The trade-off we make for keeping it is that people get confused having two classes for storing the same type of information (channel/fiducial/hpi/other point locations in some coordinate frame) that both end up affecting similar things (e.g., layouts while plotting or forward solution calculation). We could keep this distinction at the function level (keep read_montage for standard and read_dig_montage or read_digitization for measured) but return a Digitization in both cases -- would that work? If it's still not worth unifying at least the return class I can live with it.
If we can't unify the return type using a new class, a more pressing problem is that every time I go to modify the DigMontage class, I have to think about or implement some hacky workaround for the fact that DigMontage does not provide as rich a representation as what the info['dig'] list-of-dict already gives. From looking at the code DigMontage seems like it was designed primarily to accommodate other systems and their conventions, but in doing so, ended up with representations that are not as general as what we already have available in info['dig']. I'd like to at least DigMontage to return something info['dig']-like more directly for data from other systems -- then all the things it's supposed to do (convert to head coordinates, compute dev_head_t, save/read, set info['dig']), become clear instead of complex.
Activity
agramfort commentedon Jan 11, 2017
choldgraf commentedon Jan 11, 2017
That sounds good to me. Is there any clear place in the docs where montage objects are explained? E.g., when to use montage vs. digmontage? And maybe explaining the proper way to use the objects after this PR is done? Not sure if that's something that comes up as a confusion point but it couldn't hurt. I might be able to spend time doing this at the docathon in March.
larsoner commentedon Jan 11, 2017
I have wondered lately if we should get rid of
MontageandDigMontagealtogether and just make aDigitizationclass. Really bothMontageandDigMontageprovide positions in space of some subset of: anatomical points, cHPI, electrodes, and extra points. We already have a complete way to store this information, and it's given byinfo['dig']. Each ofMontageandDigMontagehave bits of this functionality but are incomplete -- they aren't necessary careful or consistent in treatment of coordinate frames, channel names, etc. In the long run I think we'd benefit from a major refactoring here.agramfort commentedon Jan 11, 2017
choldgraf commentedon Jan 11, 2017
yeah I'm in the same boat, if you refactor some of this code under the hood I'm happy to help write some kind of tutorial that explains new behavior.
larsoner commentedon Jan 11, 2017
Yeah that's part of the problem. The distinction between
MontageandDigMontagecomes up a lot, and the use cases aren't entirely clear so people seem to have trouble keeping them straight.We currently have two functions,
read_montageandread_dig_montage, that give rise toMontageandDigMontage, both of which overlap in terms of data they can contain (channel info).Here is a starting proposal:
Digitizationclass. This would be a light wrapper aroundlistthat essentially becomes what is ininfo['dig']. Additional functionsdev_head_t.read_montageandread_dig_montagein favor ofread_digitization, which can read both standard montages and individualized digitizations.set_montagefunction in favor ofset_digitization.@teonbrooks you worked on these classes a lot, WDYT?
choldgraf commentedon Jan 11, 2017
What is the conceptual difference between something like the montage classes, and the way that the
nipyecosystem (e.g.nibabel) handles coordinate frames etc? Would it be worth trying to create resemblances in the API between the two? Or is the usecase too differentlarsoner commentedon Jan 11, 2017
Maybe. AFAIK they provide transformation matrices to get between frames -- we do this in some places like
info['dev_head_t']. But I'm not sure if they have equivalent use cases to what we're going for here, which is to provide locations of specific points in multiple coordinate frames (sometimes the same point in multiple frames, or different points in different frames). Plus we already have something that does this tracking of locations, frames, and point types --info['dig'] is a simple list of dicts that is used all over our code to do this, so there are advantages to staying close to this format.choldgraf commentedon Jan 11, 2017
cool - I agree it sounds like a big PITA to change the API and would probably confuse users. Maybe the answer is just some nicely-written tutorials and guides etc. (after a refactor if that's gonna happen)
larsoner commentedon Jan 11, 2017
You mean moving to a nipy-like change wouldn't be worth it, but a
Digitization-like refactoring (what I've proposed) would be?choldgraf commentedon Jan 11, 2017
I think that it if changes an API that is used in lots of other places in MNE, or that lots of other users are already used to, then probably not worth it. If it's more under-the-hood that wouldn't require a shift in how people conceptualize the code, but that streamlines things and reduces redundancy, while making it easier to add better features, then I think it's worth it. It sounds like a full nipy-like refactor would be the former, while your idea of refactoring is more the latter. WDYT?
larsoner commentedon Jan 11, 2017
Mine would be a bit of the former, too. But it would unify how we treat things in a nice way. I don't see any real advantages to doing what
nipydoes, I don't think people cross MNE andnipyenough to justify the extra work.agramfort commentedon Jan 11, 2017
larsoner commentedon Jan 11, 2017
This concept is nice, yeah. The trade-off we make for keeping it is that people get confused having two classes for storing the same type of information (channel/fiducial/hpi/other point locations in some coordinate frame) that both end up affecting similar things (e.g., layouts while plotting or forward solution calculation). We could keep this distinction at the function level (keep
read_montagefor standard andread_dig_montageorread_digitizationfor measured) but return aDigitizationin both cases -- would that work? If it's still not worth unifying at least the return class I can live with it.If we can't unify the return type using a new class, a more pressing problem is that every time I go to modify the
DigMontageclass, I have to think about or implement some hacky workaround for the fact thatDigMontagedoes not provide as rich a representation as what theinfo['dig']list-of-dict already gives. From looking at the codeDigMontageseems like it was designed primarily to accommodate other systems and their conventions, but in doing so, ended up with representations that are not as general as what we already have available ininfo['dig']. I'd like to at leastDigMontageto return somethinginfo['dig']-like more directly for data from other systems -- then all the things it's supposed to do (convert to head coordinates, compute dev_head_t, save/read, setinfo['dig']), become clear instead of complex.7 remaining items
larsoner commentedon Jun 7, 2017
Something else to consider:
MGH Easycap 70-channel translation into 10-20
Looking into the 60-channel montage now with @SherazKhan.
larsoner commentedon Oct 4, 2018
This one won't make 0.17, moving to 0.18
massich commentedon Aug 15, 2019
cross-reference #3893 (comment) and #6461
larsoner commentedon Sep 21, 2019
Closing this since hopefully most of this has been taken care of by the last set of PRs, and we are tracking things in #6461 now