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

add channels in raw.info['bads'] to unusable channels in Reference class #146

Closed
john-veillette opened this issue May 31, 2024 · 5 comments · Fixed by #156
Closed

add channels in raw.info['bads'] to unusable channels in Reference class #146

john-veillette opened this issue May 31, 2024 · 5 comments · Fixed by #156
Labels
enhancement New feature or request
Milestone

Comments

@john-veillette
Copy link
Contributor

Currently, PREP assumes you have no prior information about which channels are bad. This isn't necessarily a bad design choice if it's philosophically important that all bad channel identification be automatic, but currently it will result in an error if you have any channels marked as bad in raw.info['bads'] before running PREP.

The culprit re: the error is in Reference.__init__:

self.raw.pick_types(eeg=True, eog=False, meg=False)

Raw.pick_types will not include bad channels in its output by default, and since Reference inherits self.prep_params["ref_chs"] = self.ch_names_eeg from the PrepPipeline class that initializes it (where channels manually marked as bad haven't been removed yet), then the self.raw.get_data(picks=self.reference_channels) in Reference.robust_reference will throw a missing value error.

So a quick solution would be to change the offending line to

self.raw.pick_types(eeg=True, eog=False, meg=False, exclude=[])

so that manually marked bad channels are not unintentionally removed. But they should probably also be added to Reference.unusable_channels, so users have the ability to manually tell PREP to leave out certain channels (e.g. if they know the channel is broken in their hardware).

In the meantime, users can circumvent the problem by just setting raw.info['bads'] = [] before running PREP. Hopefully that saves someone some trouble :)

@sappelhoff
Copy link
Owner

So a quick solution would be to change the offending line to

self.raw.pick_types(eeg=True, eog=False, meg=False, exclude=[])

so that manually marked bad channels are not unintentionally removed. But they should probably also be added to Reference.unusable_channels, so users have the ability to manually tell PREP to leave out certain channels (e.g. if they know the channel is broken in their hardware).

Thanks for the report, I'd be happy to receive a PR for this.

@sappelhoff sappelhoff added this to the 0.5.0 milestone Jun 1, 2024
@john-veillette
Copy link
Contributor Author

Great, I'll submit a pull request as a soon as I have time!

@sappelhoff
Copy link
Owner

@john-veillette any news on your expected timeline for this?

@john-veillette
Copy link
Contributor Author

Sorry @sappelhoff this slipped my mind, but I have time to work on it today so this week or next seems reasonable.

@john-veillette
Copy link
Contributor Author

john-veillette commented Aug 29, 2024

Okay, that didn't take long once I got to it. I've now opened PR #156 but some CI tests are failing.

Update: was just a formatting thing, fixed now!

@sappelhoff sappelhoff added the enhancement New feature or request label Aug 31, 2024
sappelhoff pushed a commit that referenced this issue Sep 17, 2024
… bad, closes #146 (#156)

* allows manually marked bad channels to be excluded from reference / interpolated, without being removed (which had been causing an error)

* adds new contributor to CITATION.cff

* adds new contributor ORCID

* Update authors.rst

* Update changelog.rst

* fixes some formatting issues flagged by CI

* adds manual bad channels to find_noisy_channels

* changes name of manual bads to match find_noisy_channels (which requires a specific format to work properly)

* adds test coverage

* fixes bug and formatting in test

* format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants