Skip to content
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

Merged
merged 8 commits into from
Dec 23, 2024

Conversation

scott-huberty
Copy link
Member

@scott-huberty scott-huberty commented Dec 16, 2024

Following up from #212. I realized a couple things...

First of all, isinstance(inst, mne.io.Raw) is still wrong. It should have been isinstance(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 from my_pipeline.raw (via pipeline.get_epochs()), and uses that in outlier detection ...

This would lead to unexpected results if my_raw and my_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.

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.
@scott-huberty scott-huberty marked this pull request as draft December 16, 2024 18:17
Copy link

codecov bot commented Dec 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.43%. Comparing base (1297027) to head (c03a3fb).
Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@christian-oreilly christian-oreilly left a 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().

pylossless/pipeline.py Outdated Show resolved Hide resolved
@christian-oreilly
Copy link
Collaborator

I think this method was probably written that way when we were still passing a raw object around instead of making it an attribute of the class and we failed to see that this change was breaking this functionality. But you are right that this code is currently broke insofar as the raw object passed as an argument is not used for the processing. We should then rename inst and epochs. We could also used a None default values like this

def find_outlier_chs(self, epochs, picks="eeg"):

    [...]

    if epochs is None:
        epochs = self.get_epochs(rereference=False, picks=picks)

scott-huberty and others added 2 commits December 20, 2024 13:41
- 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]>
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)}."
Copy link
Collaborator

@christian-oreilly christian-oreilly Dec 20, 2024

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!

Suggested change
"inst must be an instance of mne.Epochs," f" but got {type(inst)}."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed in 2a747c2 🙂

@scott-huberty scott-huberty marked this pull request as ready for review December 20, 2024 22:28
@scott-huberty
Copy link
Member Author

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 pick on the epochs regardless of whether we create epochs with self.get_epochs or if the user passes epochs in themselves.

Before this change, if the user passes in their own epochs, then pick would never be called..

@scott-huberty
Copy link
Member Author

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().

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 self.find_outlier_chs()

@scott-huberty scott-huberty merged commit c985968 into lina-usc:main Dec 23, 2024
8 checks passed
@scott-huberty scott-huberty deleted the fix_type_again branch December 23, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants