Skip to content
28 changes: 24 additions & 4 deletions pylossless/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,16 +771,36 @@ def _flag_volt_std(self, flag_dim, threshold=5e-5, picks="eeg"):
self.flags[flag_dim].add_flag_cat("volt_std", above_threshold, epochs)

def find_outlier_chs(self, inst, picks="eeg"):
"""Detect outlier Channels to leave out of rereference."""
"""Detect outlier Channels to leave out of rereference.

Parameters
----------
inst : mne.Epochs
an instance of mne.Epochs.
picks : str (default "eeg")
Channels to include in the outlier detection process. You can pass any
argument that is valid for the :meth:`~mne.Epochs.pick` method, but
you should avoid passing a mix of channel types with differing units of
measurement (e.g. EEG and MEG), as this would likely lead to incorrect
outlier detection (e.g. all MEG channels would be flagged as outliers).

Returns
-------
list
a list of channel names that are considered outliers.

Notes
-----
- This method is used to detect channels that are so noisy that they
should be left out of the robust average rereference process.
"""
# TODO: Reuse _detect_outliers here.
logger.info("🔍 Detecting channels to leave out of reference.")
if isinstance(inst, mne.Epochs):
epochs = inst
elif isinstance(inst, mne.io.Raw):
epochs = self.get_epochs(rereference=False, picks=picks)
else:
raise TypeError(
"inst must be an MNE Raw or Epochs object," f" but got {type(inst)}."
"inst must be an instance of mne.Epochs," f" but got {type(inst)}."
Copy link
Member

@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 🙂

)
epochs_xr = epochs_to_xr(epochs, kind="ch")

Expand Down
Loading