Skip to content

PyPREP excludes interpolated NaN/flat/low-SNR channels from average referencing #90

Closed

Description

@a-hurst

While pulling together a fix for #77, I ended up catching another PyPREP/MatPREP difference I didn't notice before. Essentially, PyPREP re-uses a class attribute (self.reference_channels) to do the same job as two separate variables in MatPREP's performReference and robustReference, which ends up causing any channels flagged as bad-by-SNR, bad-by-NaN, or bad-by-flat on the initial NoisyChannels pass to be excluded from the average reference signal even after they've been interpolated.

Specifically, the self.reference_channels here:

pyprep/pyprep/reference.py

Lines 231 to 238 in 6abe0bc

# Determine channels to use/exclude from initial reference estimation
self.unusable_channels = _union(
noisy_detector.bad_by_nan + noisy_detector.bad_by_flat,
noisy_detector.bad_by_SNR,
)
self.reference_channels = _set_diff(
self.reference_channels, self.unusable_channels
)

gets reused here:

pyprep/pyprep/reference.py

Lines 114 to 119 in 6abe0bc

dummy = self.raw.copy()
dummy.info["bads"] = self.noisy_channels["bad_all"]
dummy.interpolate_bads()
self.reference_signal = (
np.nanmean(dummy.get_data(picks=self.reference_channels), axis=0) * 1e6
)

whereas in MATLAB PREP the former is a local variable and doesn't affect the latter.

Activity

  1. added
    bug
    on Jun 18, 2021
  2. added this to the 0.4.0 milestone on Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions