pyprep icon indicating copy to clipboard operation
pyprep copied to clipboard

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

Open john-veillette opened this issue 1 year ago • 2 comments

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 :)

john-veillette avatar May 31 '24 20:05 john-veillette

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 avatar Jun 01 '24 14:06 sappelhoff

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

john-veillette avatar Jun 01 '24 23:06 john-veillette

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

sappelhoff avatar Aug 29 '24 09:08 sappelhoff

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

john-veillette avatar Aug 29 '24 19:08 john-veillette

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!

john-veillette avatar Aug 29 '24 20:08 john-veillette