-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
MRG: When picking, remove inapplicable projectors #8002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a94dc1d to
75c7ffc
Compare
This actually shouldn't be a problem, it should just be |
Ok, since there's a MWE in my first comment, we can use this as a bug report :) |
|
… although the problem here is not exactly about applying a projector, but about plotting it! |
|
Actually looking at the code and the problem, this probably is the right way to go. Let's get #8007 in, rebase this, and then see if we can fix any errors that crop op |
75c7ffc to
44c8ffa
Compare
|
Rebased on In #8003, we changed the Note in Once this PR gets merged, however, the case "the channels [the projector] was applied to no longer exist in the data" shouldn't be possible anymore through use of the public API, right? Because the only way to remove channels is by picking, and this PR will ensure that picking also drops unusable projs. So I'm wondering if I should drop this part from the |
|
I tried to capture the warnings in a test but it doesn't seem to work -- pytest claims no warning of any kind has been emitted, even though the warnings do appear on stdout! with pytest.warns(RuntimeWarning, match='Removing projector.*'):
> raw.pick_types(meg=False, eeg=True)
E Failed: DID NOT WARN. No warnings of type (<class 'RuntimeWarning'>,) was emitted. The list of emitted warnings is: [].Any idea what might be the issue? |
mne/channels/channels.py
Outdated
| drop_idx.append(idx) | ||
|
|
||
| for idx in drop_idx: | ||
| logger.warning(f"Removing projector {self.info['projs'][idx]}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use logger.warning but rather warn from ..utils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird, ok… why is that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We always use warn. It does nice things like sets stacklevel automatically, and does or does not emit based on the logger.level, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that's good to know!
|
Ok let's see what CI says… I'm worried I will have to handle the new warning in 123456 different tests individually… |
|
… or I could just turn it into a |
|
This to me should just be |
|
CI is failing because |
|
I'm fine with keeping the drop projections as a separate function, but I don't see a good reason for _pick_drop_channels not to call it. I think it's less convoluted actually. pick_drop_channels should do everything required to pick and drop channels from an instance once you know the indices, one of which is (now) to drop irrelevant projectors. Going in the direction you're advocating, we shouldn't even have a _pick_drop_channels but instead split it into one that picks just from info, one that just drops data if preloaded, etc., and replicate these calls four or five places now and more later if we add another mixin method that needs to _pick_drop... |
@larsoner Any thoughts on this one? I've never worked with |
|
You could check to see if it has that attribute and only call it if it does |
|
@larsoner Done |
This case shouldn't occur anymore if using the public API, as picking channels now already trims projectors.
|
@larsoner This is good to go from my end. Let me know if you would like me to rebase. |
agramfort
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@larsoner merge if happy
|
Thanks @hoechenberger |
What does this implement/fix?
Pick'ing may entirely eliminate a certain channel type from the resulting object. However, the list of projectors in
info['projs']will remain unchanged. This can lead to problems in later processing steps, where situations may arise where one is trying to apply a projector for a channel type that is not present in the data anymore.MWE:
With
master:A problem arises because although we dropped all MEG data, the MEG projectors are still present.
With this PR:
The MEG projectors get removed during the pick:
WIP because
Thanks!