Repository navigation
Run PREP in stages (backward-compatible), reviving #99 - #191
Merged
Merged
Conversation
(cherry picked from commit 8ba133b)
(cherry picked from commit 5191d85)
Adapt the staged-pipeline methods cherry-picked from Austin Hurst's work (gh #99) so that no existing public behavior changes: - remove_line_noise: restore the EEG_new/EEG_clean/EEG attributes and the original filter_kwargs semantics (None -> spectrum_fit defaults, otherwise use the kwargs verbatim, so e.g. method="fir" still works). line_freqs now defaults to prep_params["line_freqs"]. - robust_reference: max_iterations defaults to prep_params; warn with a UserWarning if line-noise removal was not performed first. fit() marks the line-noise stage as done even when line_freqs is empty, so the default pipeline never emits the warning. - Reference.interpolate_bads: use `is None`/`is not None` sentinels in the guards so that finding zero bad channels (an empty list) no longer raises during the default interpolating path. Co-authored-by: Austin Hurst <[email protected]>
- test_prep_pipeline_stages_match_fit: manual remove_line_noise + robust_reference is identical to fit(). - test_prep_pipeline_skip_interpolation: interpolate_bads=False leaves the post-interpolation outputs uncomputed while still detecting bads. - test_robust_reference_warns_without_line_noise / _without_line_freqs: the out-of-order UserWarning fires when expected and never during fit(). - test_interpolate_bads_guards: Reference.interpolate_bads raises before referencing and on a repeated call. Co-authored-by: Austin Hurst <[email protected]>
Normalize formatting of the cherry-picked and newly added code to satisfy the project's ruff-format gate. Co-authored-by: Austin Hurst <[email protected]>
Add an examples/run_prep_in_stages.py gallery example demonstrating the new remove_line_noise / robust_reference staged API and skipping interpolation via interpolate_bads=False, plus a changelog entry under 0.7.0. Co-authored-by: Austin Hurst <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #191 +/- ##
==========================================
+ Coverage 97.75% 97.85% +0.10%
==========================================
Files 7 7
Lines 802 840 +38
==========================================
+ Hits 784 822 +38
Misses 18 18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The changelog convention cites the PR number; the staged-PREP entry mistakenly cited the issue number (#73) instead of the PR (#191). Co-authored-by: Austin Hurst <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description
This implements PREP-in-stages and optional final interpolation, fully backward compatibly. It revives and modernizes the work in the now-closed #99 by @a-hurst — this PR supersedes #99 (which could not be merged: it was based on 2021-era code, carried breaking changes, and was never finished).
Credit: the two core commits are cherry-picked (with
-xprovenance) from Austin Hurst's original branch, preserving him as their git author; the remaining commits carryCo-authored-by: Austin Hursttrailers.What's new (all additive)
PrepPipeline.remove_line_noise(line_freqs=None)andPrepPipeline.robust_reference(max_iterations=None, interpolate_bads=True)— the individual PREP stages thatfit()runs in sequence. Running them manually is identical tofit()(verified by a test).interpolate_bads=Falseonrobust_reference()(andReference.perform_reference()), plus a standaloneReference.interpolate_bads()building block, to skip the final bad-channel interpolation and inspect/handle the bads yourself.robust_reference()emits aUserWarningif line-noise removal wasn't done first (suppressed insidefit(), including the empty-line_freqscase).Backward compatibility
This is the central design constraint:
fit()is byte-identical to before (verified: a manual staged run equalsfit()).EEG_new/EEG_clean/EEG,noisy_channels_*,bad_before_interpolation,still_noisy_channels,reference_*,interpolated_channelsall unchanged).filter_kwargssemantics preserved (e.g.method="fir"still works) — the existingtest_prep_pipeline_filter_kwargsand the fulltest_matprep_compare.pyMATLAB-strict suite pass unchanged.A latent bug in the original #99 guard was also fixed: it raised when robust referencing found zero bad channels (an empty list); the guards now use
is Nonesentinels.Intentionally deferred (out of scope, would be breaking)
The more ambitious parts of #99 are not included here, to keep this PR non-breaking. If wanted, they should go through an explicit deprecation cycle later:
noisy_channels_*/ bad-channel attributes intonoisy_info/bad_channelsdicts;get_raw(stage=...)and thecurrent_*getters;spectrum_fit.Tests / docs
fit();interpolate_bads=Falsepath; the out-of-order warning fires/doesn't;Reference.interpolate_badsguards. Existing tests pass unchanged (the BC proof).examples/run_prep_in_stages.py.🤖 Generated with Claude Code