-
Notifications
You must be signed in to change notification settings - Fork 10
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
FIX, DOC: Pipeline methods shouldn't accept just any instance of raw #213
Conversation
Following up from lina-usc#212. I realized that if one did do `my_pipeline.find_outlier_chs(my_raw), then under the hood this method would actually create an epochs instance from my_pipeline.raw ... this would lead to unexpected results if my_raw and my_pipeline.raw are not the same object of memory (i.e. they are different raw objects). Since in our codebase we never do pipeline.find_outlier_chs(raw), I dont think we should support this. Instead, we should either always expect an instanc of mne.Epochs OR We should change the method signature to be def find_outlier_chs(epochs=None) , where if it is None, the method creates epochs from pipeline.raw under the hood.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #213 +/- ##
==========================================
+ Coverage 83.27% 83.43% +0.15%
==========================================
Files 26 26
Lines 1698 1696 -2
==========================================
+ Hits 1414 1415 +1
+ Misses 284 281 -3 ☔ View full report in Codecov by Sentry. |
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.
If you agree with these proposed changes, then any place in the pipeline where we us self.find_outlier_chs(epochs)
could be replace by self.find_outlier_chs()
.
I think this method was probably written that way when we were still passing a def find_outlier_chs(self, epochs, picks="eeg"):
[...]
if epochs is None:
epochs = self.get_epochs(rereference=False, picks=picks) |
- Change API form `inst` to `epochs | None` - if `None`, then make epochs from self.raw - No need check and raise type error now. Co-authored-by: Christian O'Reilly <[email protected]>
pylossless/pipeline.py
Outdated
else: | ||
raise TypeError( | ||
if epochs is None: | ||
epochs = self.get_epochs(rereference=False, picks=picks) | ||
"inst must be an instance of mne.Epochs," f" but got {type(inst)}." |
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.
Oups! I think I left a line that was meant to be removed!
"inst must be an instance of mne.Epochs," f" but got {type(inst)}." |
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.
Already fixed in 2a747c2 🙂
Alright @christian-oreilly thanks for the review, I think your suggestions made things a lot nicer. FYI please do see 56a2242, I added a line to ensure that we call Before this change, if the user passes in their own epochs, then |
Oops I missed this part. Sure I’m fine with this, would just need to change the function signature to epochs=None so that you can do |
Following up from #212. I realized a couple things...
First of all,
isinstance(inst, mne.io.Raw)
is still wrong. It should have beenisinstance(inst, mne.io.BaseRaw)
.More importantly, I don't think that we should actually support passing a
raw
object to this method...Because for example, if one does
my_pipeline.find_outlier_chs(my_raw)
, then under the hood this method actually creates an epochs instance frommy_pipeline.raw
(viapipeline.get_epochs()
), and uses that in outlier detection ...This would lead to unexpected results if
my_raw
andmy_pipeline.raw
are not the same object in memory (i.e. they are different raw objects).Since in our codebase we never do
pipeline.find_outlier_chs(raw)
, I dont think we should support this.Instead, I think that always expecting an instance of mne.Epochs is OK.
Marking this PR as draft because I need to make sure the new docstring renders OK, but Opening the PR now so that others have time to comment.