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

Weird handling of initial bad-by-SNR channels during robust referencing #94

Open
a-hurst opened this issue Jun 26, 2021 · 1 comment
Open
Milestone

Comments

@a-hurst
Copy link
Collaborator

a-hurst commented Jun 26, 2021

(came first up in #93 (comment) and following comment in that thread.)

This isn't a PyPREP bug so much as a weirdness in the original PREP that PyPREP now matches. Essentially, during robust referencing, PREP performs an initial NoisyChannels pass and flags any bad-by-NaN, bad-by-flat, and bad-by-SNR channels as "unusable", permanently excluding them from being included in the calculated average reference signals:

pyprep/pyprep/reference.py

Lines 230 to 235 in 1abda4d

# 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,
)
reference_channels = _set_diff(self.reference_channels, self.unusable_channels)

pyprep/pyprep/reference.py

Lines 324 to 329 in 1abda4d

self.reference_signal = (
np.nanmean(raw_tmp.get_data(picks=reference_channels), axis=0) * 1e6
)
signal_tmp = self.remove_reference(
signal, self.reference_signal, reference_index

However, PREP doesn't include initial bad-by-SNR channels in the full set of bad channels to interpolate (see #91), so a channel that's initially bad-by-SNR prior to initial average referencing but is no longer bad afterwards will still get used for interpolating bads during the reference loop, despite being fully excluded from the average reference signal itself. This seems wrong, and like something worth fixing.

My gut instinct here would be to default to only marking initial bad-by-flat and bad-by-NaN channels as fully "unusable". I'd imagine that the original intent was to removing channels that contribute more noise than signal from contaminating the average reference, but given how sensitive the 'bad-by-correlation' default settings are (if over 1% of all correlation windows are below threshold, the whole channel is considered bad) and how that can change after average referencing, I don't think initial bad-by-SNR channels should be treated as permanently bad.

@a-hurst a-hurst added this to the 0.5.0 milestone Jun 26, 2021
@a-hurst
Copy link
Collaborator Author

a-hurst commented Jul 3, 2021

As an additional note, because bad-by-SNRs are included in the set of "unusable" channels, that means they also get interpolated during re-referencing no matter what, even if they're totally fine after re-referencing.

Oh, and also: since unusable channels always get interpolated, doesn't that mean flat channels will be made no longer flat when the robust reference signal is applied, but will then immediately be interpolated? On its face it seems like this would be undesirable, but maybe I'm missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant