Skip to content

[EEGBrowser] Integrate rejection workflows - #107

Merged
suraj-ranganath merged 3 commits into
feature/eegbrowser-completionfrom
phase/eegbrowser-5-workflows
Jun 1, 2026
Merged

suraj-ranganath merged 3 commits into
feature/eegbrowser-completionfrom
phase/eegbrowser-5-workflows

Conversation

@suraj-ranganath

Copy link
Copy Markdown
Member

Wire EEGBrowser into selection, rejection, and clean_rawdata workflows so display paths show EEGLAB-style marks and accepted browser edits update session and console state. Adds focused regression coverage for data/ICA marks, reject-on-close, cancel, superpose, continuous and epoched behavior.

Fixes #99

@claude

claude Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 4m 51s —— View job


PR Review: EEGBrowser rejection workflow integration

Overall this is a clean, well-tested integration. The shared _eegplot_rejection.py helper is a good consolidation point, history commands now respect superpose=2, and the command_callback plumbing through the seven pop_* rejection functions, menu_actions._BROWSER_ACCEPT_POP_ACTIONS, and the console workspace looks consistent. The regression suite covers the main golden paths (display-then-accept, reject-on-close, cancel, superpose, continuous + epoched, ICA components). A handful of small issues below — none blocking.


1. pop_rejcont records history before the user has done anything

src/eegprep/functions/popfunc/pop_rejcont.py:133-152 — when display=True, _apply_one opens the browser and returns out unmodified (no reject marks are persisted for continuous data, that's all in the _accept closure). In menu_actions._run_pop_function (src/eegprep/functions/guifunc/menu_actions.py:1137-1142) we then unconditionally do:

if command:
    self._store_current_from_gui(eeg_out, command=command)

So as soon as the user opens the pop_rejcont GUI, EEG = pop_rejcont(EEG, ...) is appended to history and a "new" dataset is stored, even if they then close the browser without rejecting. The other six wrappers tolerate this because _apply_one writes rej*/rej*E marks before returning (so the early-stored EEG actually has marks — useful state). pop_rejcont is the only family where the pre-accept EEG is byte-identical to the input, which makes the eager history entry misleading.

Suggested fix: for pop_rejcont only, defer the history append/store to the accept callback (skip the eager _store_current_from_gui if command is a pop_rejcont(...) call, or have pop_rejcont return "" for command when display=True and let the callback emit it). Fix this →

2. Duplicate assertion in new console test

tests/test_console_workspace.py:782-786 — assert session.ALLCOM == [command] appears twice with assert refresh.call_count >= 2 sandwiched between them. This looks like a leftover from how the new test was inserted before the next test that already ended with assert session.ALLCOM == [command]. Harmless, but the duplicate is dead weight; drop line 786.

3. pop_rejcont GUI checkbox label vs. window

src/eegprep/functions/popfunc/pop_rejcont.py:73-74 and _run_gui lines 90 — checkbox label is "Use hanning window before computing FFT" but _apply_one actually applies np.hamming(window) (and the GUI returns "hamming"). This is inherited EEGLAB labeling, so parity is preserved; not a regression in this PR. Mentioning only because it's right next to changes.

4. Minor: _eegplot_rejection._displayed_families doesn't carry "auto"

src/eegprep/functions/popfunc/_eegplot_rejection.py:16 — DISPLAY_REJECTION_FAMILIES omits "auto", so pop_autorej marks won't appear in another family's superposed view. This appears intentional (autorej is EEGPrep-only and shares the manual color via _AUTO_REJECTION_COLOR = MANUAL_REJECTION_COLOR), but worth a one-line comment so future readers don't add it without thinking.

5. menu_actions._BROWSER_ACCEPT_POP_ACTIONS list-selection edge case

src/eegprep/functions/guifunc/menu_actions.py:1063-1143 — for the rejection families that are also in _MULTIPLE_DATASET_ACTIONS (pop_eegthresh, pop_jointprob, pop_rejkurt, pop_rejspec, pop_rejtrend), selection can be a list. The wrappers handle that by skipping the browser, but eegplot_accept_creates_dataset(selection, eeg_out, reject=1) and _store_current_from_gui(eeg_out, ...) aren't obviously list-aware. The accept_browser_result closure would never fire for the list path (no browser opens), so this is latent rather than broken — but the outer if command: self._store_current_from_gui(eeg_out, command=command) will pass a list of EEGs to store_current. Consider an explicit branch for isinstance(selection, list) that mirrors the non-browser path (or document the assumption).


Things that look good

  • The shared _eegplot_rejection.open_epoched_rejection_browser cleanly captures the per-family color and superpose plumbing; the per-pop wrapper diffs are small and uniform.
  • History serialization fix in pop_rejkurt._history_command and pop_rejtrend._history_command switching from int(bool(superpose)) to int(superpose) preserves the 0/1/2 semantics — nice catch.
  • pop_rejmenu correctly uses copy_eeg(EEG) so cancelling the dialog doesn't mutate the input, and the scroll* buttons now hook through open_rejection_browser to update both the count widgets and EEG.reject.
  • pop_clean_rawdata._show_vis_artifacts is a tidy reuse of eegplot for the rejected-data preview, and the test now exercises the clean_sample_mask → winrej conversion (tests/test_gui_pop_clean_rawdata.py:152-153).
  • pop_select's Scroll dataset button now wires through open_eegplot with _scroll_dataset_enabled, removing a stale TODO.

  • Read PR diff against origin/feature/eegbrowser-completion
  • Inspect new _eegplot_rejection.py helper module
  • Audit pop_* rejection wrappers for EEGLAB parity & session sync
  • Check pop_clean_rawdata browser-preview path
  • Check menu_actions / qt / console wiring
  • Review regression tests
  • Post final review
    • Branch: phase/eegbrowser-5-workflows

@suraj-ranganath

suraj-ranganath commented Jun 1, 2026 •

Copy link
Copy Markdown
Member Author

🤖

Attachments

Phase 5 EEGPrep GUI evidence

eegbrowser_epoched_marked.png pop_clean_rawdata_dialog.png
eegbrowser_epoched_marked.png pop_clean_rawdata_dialog.png
pop_rejmenu_dialog.png pop_select_dialog.png
pop_rejmenu_dialog.png pop_select_dialog.png

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Phase 5 implementation spec

Problem
EEGBrowser landed in earlier phases, but workflow entry points still bypassed it: pop_select and pop_rejmenu scroll buttons were disabled, rejection pop functions computed marks without a browser-backed accept path, clean_rawdata only warned for the visual artifacts path, and GUI/console accept actions did not consistently store EEG/history/session state.

Approach
Added src/eegprep/functions/popfunc/_eegplot_rejection.py to translate EEGLAB reject fields into EEGBrowser winrej rows and apply accepted rows back into method-specific data/ICA fields. Wired pop_eegthresh, pop_jointprob, pop_rejkurt, pop_rejtrend, pop_rejspec, pop_rejcont, pop_autorej, pop_select, pop_rejmenu, and pop_clean_rawdata to use existing eegplot/pop_eegplot APIs while preserving no-display behavior. Added GUI and console callbacks so browser accept updates EEGPrepSession, ALLEEG/CURRENTSET, LASTCOM/ALLCOM, and visible GUI state through existing session helpers.

Key code

def apply_epoched_rejection_browser(eeg, *, winrej, fields, command, command_callback, reject):
    accepted = np.asarray(winrej, dtype=float)
    out = copy_eeg(eeg)
    _apply_current_family_rows(out, accepted, fields)
    _merge_manual_rows(out, accepted, fields)
    if reject:
        marks = np.asarray((out.get("reject") or {}).get(fields.epoch_field, []), dtype=bool)
        if marks.any():
            out, reject_command = pop_rejepoch(out, marks, return_com=True)
            command = _join_commands(command, reject_command)
    if command_callback is not None:
        command_callback(out, command)
    return out

Tests
Focused tests cover no-display preservation, display-only marks, reject-on-browser-accept, cancel/no-callback behavior, superpose, data and ICA reject fields, continuous and epoched rejection, pop_select/rejmenu browser launch callbacks, clean_rawdata visual highlights, GUI menu session storage, and console wrapper storage. Local runs passed ruff check, ruff format check, ty check, ./pre-commit.py, focused workflow tests, and EEGPREP_SKIP_MATLAB=1 pytest -m "not slow".

Visual evidence
Attached GUI evidence in the previous PR comment for EEGBrowser marked epochs, pop_select, pop_rejmenu, and pop_clean_rawdata. This is EEGPrep-only evidence because local EEGLAB/MATLAB visual capture was unavailable in this worktree.

Accepted deviations
pop_rejmenu Scroll Data/Scroll Acts and mark update flows are active, but Calc/Plot buttons remain disabled because the individual pop rejection dialogs now own browser-backed calculation and mark flows. clean_rawdata uses a single highlighted mask from clean_sample_mask; Phase 6 owns data2 overlays and advanced display layering.

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Addressed the actionable review feedback in 49d0c82: pop_rejcont display mode now returns no immediate history command and the GUI dispatch path relies on the browser Accept callback for session/history mutation. Added regression coverage for deferred continuous-browser history, removed the duplicate console assertion, and documented the autorej superpose choice in code.

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Addressed the remaining Claude review findings and nits in e7921d1.

Covered items:

  • pop_rejcont display mode now returns the original EEG object with no immediate command, so console and GUI paths do not store an unmodified copy before browser Accept.
  • Menu dispatch now handles multi-dataset rejection actions before installing browser callbacks and stores list results back to the selected CURRENTSET indices.
  • The EEGLAB hanning label vs Hamming taper behavior is documented in code while preserving visual/text parity with pop_rejcont.m.
  • Added regression tests for console deferred pop_rejcont storage, GUI multi-dataset rejection dispatch, and the display-mode return semantics.

Checks rerun locally: focused browser/workflow tests (183 passed, 2 skipped), ruff check, ruff format --check, ty check, ./pre-commit.py --fix, ./pre-commit.py, and EEGPREP_SKIP_MATLAB=1 pytest -m "not slow" (1508 passed, 230 skipped, 11 deselected). Thread-aware review fetch reports 0 inline review threads.

@suraj-ranganath
suraj-ranganath merged commit 5839f4f into feature/eegbrowser-completion Jun 1, 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