Skip to content

[Phase 2.1] Implement pop_rmbase baseline parity - #70

Merged
suraj-ranganath merged 3 commits into
feature/eeglab-completionfrom
phase/2-rmbase-baseline
May 27, 2026
Merged

suraj-ranganath merged 3 commits into
feature/eeglab-completionfrom
phase/2-rmbase-baseline

Conversation

@suraj-ranganath

Copy link
Copy Markdown
Member

Implement native pop_rmbase and low-level rmbase baseline removal with GUI, menu, console history, help, sample-data coverage, and EEGLAB parity scaffolding. This makes baseline removal a real Phase 2 signal-conditioning workflow instead of a placeholder.

Part of #62

@claude

claude Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 6m 33s —— View job


Code review

  • Overall assessment: Needs changes
  • Highest-risk area: Continuous-data baseline removal with boundary events differs from EEGLAB
  • Merge recommendation: Needs changes

The split of pop_rmbase into a high-level GUI/history wrapper plus a low-level sigprocfunc/rmbase.py is well-structured, the epoched parity test (atol/rtol = 1e-6) is a real improvement, and the 1‑based channel/point semantics now match EEGLAB throughout. One important behavior divergence from EEGLAB needs a decision, and a couple of small nits.

Blocking

None.

Important

  • pop_rmbase.py::_remove_continuous_baseline modifies whole inter-boundary segments instead of restricting modifications to samples inside pointrange (src/eegprep/functions/popfunc/pop_rmbase.py#L208-L233). EEGLAB's pop_rmbase.m (continuous + boundary branch) only writes back to EEG.data(chanlist, pointrange(tmprange)) — i.e., it only modifies samples inside the baseline window, splitting that window at boundaries. The new Python code instead splits the entire data at boundary samples, finds the subset of baseline_indices falling in each segment, and subtracts that mean from the whole segment. The no-boundary path is consistent with EEGLAB; the boundary path is a real semantic change. test_pop_rmbase_continuous_with_boundaries_is_segmentwise uses pointrange=range(1, 201) covering the entire record, so the divergence isn't exercised. Either restore the EEGLAB-equivalent in-pointrange-only update, or confirm the deviation is intentional and add a MATLAB parity test for continuous data with a boundary plus a baseline range smaller than the record. See inline comment.

Nits

  • Channel order is silently sorted in history output (src/eegprep/functions/popfunc/pop_rmbase.py#L292-L322). _resolve_channel_indices returns sorted(dict.fromkeys(history)), so chanlist=[3, 1] produces [1 3] in the history command rather than echoing the user's order. EEGLAB preserves user-supplied order. Use list(dict.fromkeys(...)) to keep order while still deduplicating. See inline comment.
  • _resolve_channel_indices(one_based=False) is unreachable in this PR — both call sites pass one_based=True. Per AGENTS.md "no speculative configurability", consider dropping the parameter and the not one_based branch.
  • history_pointrange work is discarded when timerange is supplied (src/eegprep/functions/popfunc/pop_rmbase.py#L67-L72). _baseline_indices always returns (indices + 1).tolist() for the timerange branch, and pop_rmbase unconditionally resets it to []. Minor — short-circuit in _baseline_indices or trust the caller.

Test gaps

  • No parity test for continuous + boundary. Given the divergence above, a parity test on a continuous dataset with at least one boundary event and pointrange strictly smaller than EEG.pnts would catch any future regression in either direction.
  • No history test for the timerange path. The pure-pointrange replayability test is great; an analogous assertion for pop_rmbase(EEG, timerange=[-200, 0], return_com=True) would pin the EEG = pop_rmbase( EEG, [-200 0], []); shape.

EEGLAB parity notes

  • eegprep.rmbase semantics change is correct. Re-pointing eegprep.rmbase from the previous pop_rmbase wrapper to the new low-level sigprocfunc.rmbase now matches EEGLAB's split between rmbase.m (numeric) and pop_rmbase.m (EEG struct). This is a breaking change for anyone calling eegprep.rmbase(EEG_dict) — worth a release-notes mention.
  • Multi-dataset channel disabling, GUI defaults (_default_baseline_timerange, blank vs [ ]), pophelp resource, and pop_rmbase_dialog_spec geometry all align with EEGLAB's pop_rmbase dialog.

Checked: correctness in rmbase/_apply_pop_rmbase_one, 1-based input handling, GUI cancel path, history command formatting, console keywordization expectation, multi-dataset path, sample-data + MATLAB parity tests, visual-parity capture wiring, AGENTS.md guidance on EEGLAB parity and minimal-scope changes.

Review checklist

  • Read PR diff and changed files
  • Compare against EEGLAB pop_rmbase / rmbase reference
  • Audit AGENTS.md / CLAUDE.md compliance
  • Check correctness, edge cases, and regressions
  • Verify test coverage for new behavior
  • Post review comment + inline findings (3 inline comments posted)
    · branch phase/2-rmbase-baseline

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Phase 2.1 implementation notes and evidence

Problem
pop_rmbase was still effectively a placeholder/partial implementation: it mixed Python and EEGLAB indexing semantics, had no real menu/GUI/help/console path, and did not expose the low-level rmbase signal-processing primitive needed for Phase 2.

Approach
Implemented standalone sigprocfunc.rmbase, rewrote pop_rmbase with EEGLAB-facing 1-based pointrange/chanlist, added GUI/menu dispatch, console-replayable history, help Markdown, sample-data coverage, and visual parity capture support. Continuous datasets respect boundary segments; epoched datasets use per-epoch baseline removal. ICA activations are invalidated while decomposition fields are preserved.

Coordination
This PR can merge independently after Phase 1a and before Phase 1b/3/4. It only removes the pop_rmbase placeholder and adds baseline-removal primitives; Phase 2.2 can build FIR filtering on the same conventions after this lands.

Verification

  • uv run --no-sync pytest tests/test_pop_rmbase.py tests/test_console_workspace.py tests/test_visual_parity.py::VisualParityConfigTests tests/test_visual_parity.py::VisualParityCaptureTests::test_matlab_capture_honors_eeglab_root_environment tests/test_visual_parity.py::VisualParityCaptureTests::test_matlab_dialog_capture_generates_simple_pop_function_script tests/test_gui_main_window.py tests/test_sample_data_pop_functions.py::test_pop_rmbase_zeroes_selected_sample_baseline_channels -q -> 126 passed, 2 skipped, 10 subtests passed
  • MATLAB Engine smoke for tests/test_pop_rmbase.py::TestPopRmbaseParity passed locally when the worktree was temporarily pointed at the main checkout's vendored EEGLAB reference
  • uv run --no-sync ruff check . -> pass
  • uv run --no-sync ruff format --check . -> pass
  • uv run --no-sync ty check -> pass
  • EEGPREP_SKIP_MATLAB=1 uv run --no-sync pytest -m "not slow" -> 1120 passed, 210 skipped, 11 deselected
  • ./pre-commit.py -> pass

Visual parity
side_by_side.png

@suraj-ranganath

Copy link
Copy Markdown
Member Author

@claude review this

@claude

claude Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 3m 19s —— View job


Claude PR Review (refresh after 5665e90 "Address pop_rmbase review feedback")

  • Overall assessment: Approve (modulo CI / a brief release note)
  • Highest-risk area: previously continuous + boundary semantics — now fixed and MATLAB-parity-covered
  • Merge recommendation: Ready to merge after CI runs

All four items from the prior review are addressed. The split into a high-level pop_rmbase plus low-level sigprocfunc/rmbase remains clean, EEGLAB 1-based semantics are consistent, and the new tests pin the behaviors that previously diverged.

Verifications

  • Sync branch & inspect diff vs origin/feature/eeglab-completion
  • Re-check the EEGLAB continuous+boundary parity question — resolved
  • Re-check history channel-order behavior — resolved
  • Re-check _resolve_channel_indices(one_based=False) reachability — resolved
  • Re-check history_pointrange reset when timerange is supplied — resolved
  • Spot-check rmbase low-level and help/menu/visual-parity wiring — looks correct
  • CI status — none reported on this branch yet (push will trigger)
  • Post refreshed review

Resolved items

  • Continuous + boundary parity (Important). _remove_continuous_baseline now writes only into the selected baseline samples per segment via np.ix_(channel_indices, segment_baseline), matching EEGLAB's EEG.data(chanlist, pointrange(tmprange)) = rmbase(...) exactly. The new test_parity_continuous_boundary_partial_pointrange (MATLAB) and test_pop_rmbase_continuous_boundary_partial_pointrange_only_changes_selected_samples (Python) both exercise pointrange strictly smaller than EEG.pnts with a boundary inside the record, asserting that samples outside pointrange are untouched. The 1-sample fast path correctly sets the single sample to 0 (equivalent to subtracting its own mean). (pop_rmbase.py#L206-L233)
  • Channel order in history (Nit). Both numeric and label branches of _resolve_channel_indices now use list(dict.fromkeys(...)) to preserve user-supplied order while deduplicating. test_pop_rmbase_return_com_preserves_channel_order asserts chanlist=[3, 1] → EEG = pop_rmbase( EEG, [], [1 2 3 4 5], [3 1]);. (pop_rmbase.py#L292-L313)
  • Unreachable one_based=False (Nit). The one_based parameter and dead branch are removed; the only signature is _resolve_channel_indices(EEG, chanlist). Matches AGENTS.md "no speculative configurability".
  • history_pointrange reset (Nit). _baseline_indices short-circuits to (indices, []) in the timerange branch; the redundant if _has_values(history_timerange): history_pointrange = [] is gone. test_pop_rmbase_return_com_timerange_uses_eeglab_history_shape pins the EEG = pop_rmbase( EEG, [10 19], []); shape. (pop_rmbase.py#L242-L254)

Nits (non-blocking)

  • Slight redundancy. In the boundary multi-sample branch (pop_rmbase.py:228-232), passing np.arange(1, segment_baseline.size + 1) is functionally equivalent to passing 0 / no basevector since the slice is exactly the baseline window. A bare rmbase(data[window]) reads more clearly, but the current form is explicit and harmless. Fix this →
  • Breaking change to eegprep.rmbase. Re-pointing the public eegprep.rmbase from the previous pop_rmbase wrapper to the new low-level sigprocfunc.rmbase is correct EEGLAB-style separation, but it changes the call shape (now rmbase(data, frames, basevector) rather than rmbase(EEG_dict, ...)). Worth a one-line entry in release notes/changelog.

EEGLAB parity notes

  • _remove_continuous_baseline no-boundary branch demeans the entire row using the baseline-window mean; the boundary branch demeans only the baseline samples in each segment. That asymmetry mirrors EEGLAB's pop_rmbase.m itself, not an EEGPrep choice.
  • Channel resolution, GUI defaults, sample-data coverage, visual parity capture wiring, console replay, and menu dispatch are all in place.

Review checklist

  • Read PR diff and changed files since prior review
  • Compare against EEGLAB pop_rmbase / rmbase reference semantics
  • Audit AGENTS.md / CLAUDE.md compliance (no speculative configurability, minimal scope, EEGLAB parity)
  • Check correctness on new boundary partial-pointrange path
  • Verify new test coverage (channel order, timerange history, partial pointrange with boundary, MATLAB parity)
  • Spot-check GUI/menu/visual-parity wiring
    · branch phase/2-rmbase-baseline

@suraj-ranganath
suraj-ranganath merged commit 119e946 into feature/eeglab-completion May 27, 2026
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

Successfully merging this pull request may close these issues.

1 participant