mne-tools / mne-tools/mne-python

No mechanism for channel specific epoch removal

Open
#11,705 4 comments 0 reactions 1 assignee View on GitHub

@CarinaFo is already working on this.

Since Nov 16, 2023.

ENH sprint-2023
Dominant language
Python
Stars
3.5k
Forks
1.6k
Avg merge
1d 6h
Merged PRs (30d)
100

Description

Describe the new feature or enhancement

One step in my preprocessing workflow is to take the epoch my data, and then remove trial outliers for each channel, defined as epochs where there is a voltage value more than 10 standard deviations above the channel average at any time point. The outliers in this calculation are channel specific, but the epochs.drop method can only remove epochs for all channels.

Describe your proposed implementation

A new info field called 'outliers'. The field stores a boolean array of shape (channels X epochs) indicating whether a given epoch passes a given outlier test.

This field will be checked when creating an evoked object using epoch.average()

Describe possible alternatives

Include outlier function as a 'method' for the epochs averaging function. This does require that the outliers be recalculated at the time of averaging. If you want to determine the outliers for a broadband signal, passband filter that signal, and then find an average evoked response later this method won't work. additionally, it doesn't allow storage of the outlier mask in a epo.fif file.

Additional context

Outliers determination method:

def find_outliers(data: np.ndarray, outliers: float) -> np.ndarray[bool]:
    dat = np.abs(data)  # (trials X channels X (frequency) X time)
    max = np.max(dat, axis=-1)  # (trials X channels X (frequency))
    std = np.std(dat, axis=(-1, 0))  # (channels X (frequency))
    mean = np.mean(dat, axis=(-1, 0))  # (channels X (frequency))
    keep = max < ((outliers * std) + mean)  # (trials X channels X (frequency))
    return keep

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.