Skip to content

API: Refactor montage classes #3893

Closed
Closed

Description

@choldgraf

mentioned in #3728

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:

  • pick_channels (and use it in ECoG example)
  • save (to FIF)
  • compute_dev_head_t
  • conversion to Neuromag head coordinates

Other things to take care of:

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

Activity

  1. agramfort commented on Jan 11, 2017

    @agramfort
    SponsorMember
  2. choldgraf commented on Jan 11, 2017

    @choldgraf
    ContributorAuthor

    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.

  3. larsoner commented on Jan 11, 2017

    @larsoner
    Member

    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.

  4. added this to the 0.15 milestone on Jan 11, 2017
  5. agramfort commented on Jan 11, 2017

    @agramfort
    SponsorMember
  6. choldgraf commented on Jan 11, 2017

    @choldgraf
    ContributorAuthor

    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.

  7. larsoner commented on Jan 11, 2017

    @larsoner
    Member

    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?

  8. choldgraf commented on Jan 11, 2017

    @choldgraf
    ContributorAuthor

    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

  9. larsoner commented on Jan 11, 2017

    @larsoner
    Member

    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.

  10. choldgraf commented on Jan 11, 2017

    @choldgraf
    ContributorAuthor

    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)

  11. larsoner commented on Jan 11, 2017

    @larsoner
    Member

    You mean moving to a nipy-like change wouldn't be worth it, but a Digitization-like refactoring (what I've proposed) would be?

  12. choldgraf commented on Jan 11, 2017

    @choldgraf
    ContributorAuthor

    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?

  13. larsoner commented on Jan 11, 2017

    @larsoner
    Member

    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.

  14. agramfort commented on Jan 11, 2017

    @agramfort
    SponsorMember
  15. larsoner commented on Jan 11, 2017

    @larsoner
    Member

    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.

  16. 7 remaining items

  17. larsoner commented on Jun 7, 2017

    @larsoner
    Member

    Something else to consider:

    MGH Easycap 70-channel translation into 10-20

    Looking into the 60-channel montage now with @SherazKhan.

  18. removed this from the 0.15 milestone on Aug 4, 2017
  19. added this to the 0.17 milestone on Aug 7, 2018
  20. larsoner commented on Oct 4, 2018

    @larsoner
    Member

    This one won't make 0.17, moving to 0.18

  21. modified the milestones: 0.17, 0.18 on Oct 4, 2018
  22. self-assigned this
    on Dec 20, 2018
  23. pinned this issue on Dec 20, 2018
  24. unpinned this issue on Apr 22, 2019
  25. modified the milestones: 0.18, 0.19 on May 15, 2019
  26. massich commented on Aug 15, 2019

    @massich
    Contributor

    cross-reference #3893 (comment) and #6461

  27. larsoner commented on Sep 21, 2019

    @larsoner
    Member

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions