Skip to content

BUG: Epochs constructor (re-creates) and re-applies proj even if proj is False if raw.proj is True #2310

Open

Description

@haribharadwaj

This leads to problems in at least one use case where the user is interested in working with only a subset of channels. For example:

raw.apply_proj()  # Apply proj before selecting channels of interest

raw2 = raw.pick_channels([...], copy=True)   # Pick subset of channels
# Now raw2.proj is True

epochs = Epochs(raw2, ..., proj=False)
# The data in epochs is messed up owing to re-application
# of inappropriate projector without having all channels

There are several places here where at least warnings should have been thrown...

Activity

  1. haribharadwaj commented on Jul 17, 2015

    @haribharadwaj
    ContributorAuthor

    I think the issue is more general.. projs should be discarded when picks is used at anytime as the old proj definitions wont be valid anymore..

    What am I missing?

  2. haribharadwaj commented on Jul 17, 2015

    @haribharadwaj
    ContributorAuthor

    Example:

    # Let's say raw.proj is False
    epochs = Epochs(raw, ..., proj=True, picks=[...])  # Pick subset of channels
    

    Here picks happens before projections are activiated and data is messed up as result... Thus picks is not useable at all with projs!!

  3. agramfort commented on Jul 17, 2015

    @agramfort
    SponsorMember
  4. agramfort commented on Jul 17, 2015

    @agramfort
    SponsorMember
  5. teonbrooks commented on Jul 17, 2015

    @teonbrooks
    Member

    kinda related question, why is it that we cannot remove the projection once it's been applied? wouldn't it just be multiplying the inverse?

  6. larsoner commented on Jul 17, 2015

    @larsoner
    Member

    The projection matrix is non-invertible. You're basically creating a hole in the data, once it's there, there is no way to know what used to be there. Think about zeroing out a single time point (i.e., the [1, 0, 0, ..., 0] time basis vector) across all channels instead of a single spatial component across all times, and it will be clearer. Once you zero it out, you can't know what you need to put back.

  7. teonbrooks commented on Jul 17, 2015

    @teonbrooks
    Member

    ah, I forgot about the invertibility consideration. makes sense. thanks @Eric89GXL!

  8. haribharadwaj commented on Jul 17, 2015

    @haribharadwaj
    ContributorAuthor

    @teonlamont : Projection is like taking a pont in 3D space and mapping onto it's corresponding 2D (like, (2,3, 5) --> (2, 3)).. No way to recover lost info..

  9. haribharadwaj commented on Jul 17, 2015

    @haribharadwaj
    ContributorAuthor

    Anyways... I agree that picks/drops functions should by default ignore proj AND also warn user AND also rewrite the resulting instance's proj attribute (and delete projection definitions from resulting inst) so that other functions don't reapply them.. Seems like edits maybe needed in many places?

  10. agramfort commented on Jul 19, 2015

    @agramfort
    SponsorMember

    PR highly appreciated @haribharadwaj

  11. larsoner commented on Dec 21, 2015

    @larsoner
    Member

    I think currently we actually support applying projections if channels are missing -- see what mne_browse_raw does with MEG channels with the acquisiton projectors active, for example. Another thing to keep in mind is that this issue actually goes a bit beyond just picking and dropping, since bad channels are also removed from projection operations, and thus can modify what projection actually gets done. But maybe we shouldn't worry about that case for now.

    We add a parameter to drop_channels et al. methods. For example ignore_proj. If ignore_proj=False (default) and inst.proj ==True then throw an error. If the "User" sets ignore_proj=True then he can bypass the check

    I agree that picks/drops functions should by default ignore proj AND also warn user AND also rewrite the resulting instance's proj attribute (and delete projection definitions from resulting inst) so that other functions don't reapply them

    For @haribharadwaj's original use case:

    raw.apply_proj()  # Apply proj before selecting channels of interest
    raw2 = raw.pick_channels([...], copy=True)   # Pick subset of channels
    epochs = Epochs(raw2, ..., proj=False)
    

    Just to be clear, the proposal is to have pick_channels(..., ignore_proj=False) by default, so doing raw.pick_channels(...) as above would throw an error, because raw has some projectors applied that have missing channels, right?

    If the user did raw2 = raw.pick_channels(..., ignore_proj=True), does that mean that the offending projectors will be set to False, or removed from the instance altogether?

    This is a bit related to #2734, but should probably be addressed in a separate follow-up PR.

  12. added this to the 0.12 milestone on Dec 21, 2015
  13. agramfort commented on Dec 21, 2015

    @agramfort
    SponsorMember

    if we remove projections then they cannot be taken into account in
    inverse to be applied to the lead field matrix. this is bad.

    if we keep them then they could be reapplied on a subset of channels
    which is also bad.

    suggestions:

    • once a projection is applied, we need to know to what channels it
      was applied. So let's remove from the projection the channels ignored
      when the proj was applied. At least we have provenance.
    • we prevent reapplying a projection if the channels have changed.

    do I miss something? do we still need another parameter?

  14. dengemann commented on Dec 22, 2015

    @dengemann
    Member

    do I miss something? do we still need another parameter?

    HBM 2014: "Just don't use PCA" ;)

  15. jasmainak commented on Dec 22, 2015

    @jasmainak
    Member

    I'm going to say something very annoying here (yet again) ;) We need to document this. The docstrings are good, but it needs to be all in one place. It will also make the thought process clearer. Projections were the most confusing thing for me when I started on MNE. I am making an effort here: #2728 but with projections, I am clearly not the best person to describe it.

  16. larsoner commented on Dec 22, 2015

    @larsoner
    Member

    we prevent reapplying a projection if the channels have changed.

    I'm not sure practically how we would achieve this, though, when using e.g. pick_channels or pick_types.

  17. larsoner commented on Apr 20, 2016

    @larsoner
    Member

    I can't think of a great solution for this right now. Currently we at least raise a warning about projection being dangerous. I'm going to move it to 0.13 unless someone has a good proposal

  18. modified the milestones: 0.13, 0.12 on Apr 20, 2016
  19. larsoner commented on Sep 8, 2016

    @larsoner
    Member

    @agramfort the last suggestion was:

    • once a projection is applied, we need to know to what channels it was applied. So let's remove from the projection the channels ignored when the proj was applied. At least we have provenance.
    • we prevent reapplying a projection if the channels have changed.

    I think we need to add to this:

    • raise an error in places in the code (probably anything that uses whitening, like inversion and dipole fitting?) where projection information is necessary
    • don't set proj = True in Epochs constructor based on raw.proj anymore

    Does that make sense? If so I can try to tackle this for 0.13.

  20. self-assigned this
    on Sep 8, 2016
  21. agramfort commented on Sep 10, 2016

    @agramfort
    SponsorMember

    I 'think' it makes sense. But I would see by trying what are the consequences...

  22. removed this from the 0.13 milestone on Sep 22, 2016
  23. larsoner commented on Feb 14, 2017

    @larsoner
    Member

    See also #3664

  24. changed the title [-]Epochs constructor (re-creates) and re-applies proj even if proj is False if raw.proj is True[/-] [+]BUG: Epochs constructor (re-creates) and re-applies proj even if proj is False if raw.proj is True[/+] on Feb 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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