Repository navigation
Implement pop_eegplot menu session workflows - #105
suraj-ranganath merged 2 commits into
Conversation
|
Claude finished @suraj-ranganath's task in 7m 28s —— View job PR Review
SummaryOverall the wiring is in good shape: Posted four inline comments. The first is the only one that looks like a behavior bug; the rest are robustness/maintainability notes. High priority
Medium priority
Low priority / nits
|
|
🤖 Phase 4 implementation evidence\n\nImplemented and verified pop_eegplot menu/session workflows for issue #98. Focused tests: 207 passed, 1 skipped, 19 subtests passed. Broad non-slow suite with MATLAB disabled: 1490 passed, 230 skipped, 11 deselected. Static checks passed: ruff check, ruff format --check, ty check, and ./pre-commit.py.\n\nVisual/menu evidence: macOS open-menu screenshot capture did not reliably open the EEGLAB native menu, so I used the visual parity skill's supported menu-inventory path for menu work. Targeted EEGLAB and EEGPrep enabled/separator states match for the Phase 4 pop_eegplot entries across startup, continuous, epoched, and multiple-dataset states.\n\n |
| def _pop_eegplot_variant_options(variant: str) -> tuple[int, int, int]: | ||
| if variant == "components": | ||
| return 0, 1, 1 | ||
| if variant == "reject_ica": | ||
| return 0, 0, 1 | ||
| if variant == "channels": | ||
| return 1, 1, 1 | ||
| return 1, 0, 1 |
There was a problem hiding this comment.
EEGLAB parity: please double-check the variant matrix against eeglab.m
These defaults look intentional (the test hard-codes the same tuples), but they don't line up with the EEGLAB menu callbacks I recall:
| Menu | EEGPrep (this PR) | EEGLAB eeglab.m (typical) |
|---|---|---|
| Plot > Channel data (scroll) | (1, 1, 1) |
(1, 1, 0) – view-only, Reject disabled, button reads "Update Marks" |
| Plot > Component activations (scroll) | (0, 1, 1) |
(0, 1, 0) – view-only |
| Tools > Inspect/reject data by eye | (1, 0, 1) |
(1, 1, 1) – superpose=1 so prior rejections (epoched) or thresh/jp marks are visible |
| Tools > Reject data epochs > Reject by inspection | (1, 0, 1) |
(1, 1, 1) |
| Tools > Reject data using ICA > Reject by inspection | (0, 0, 1) |
(0, 1, 1) |
Two concrete consequences if I'm right:
- The Plot menu items currently produce a "Reject" button that, if clicked, will create a new dataset with samples deleted via
eeg_eegrej— but EEGLAB's Plot scroll is supposed to be display-only. A user clicking through "just to look" can accidentally truncate the dataset. - With
superpose=0,_initial_epoch_winrejonly paintsEEG.reject.rejmanual; it skipsrejthresh/rejjp/.... The "Reject by inspection" dialog therefore won't show the marks from other reject methods that EEGLAB does.
Worth re-checking against src/eegprep/eeglab/eeglab.m (not in this checkout). If the new behavior is deliberate, please add a brief comment here pointing to where the deviation is decided.
| def accept_eegplot(eeg_out: Any, command: str) -> None: | ||
| with self.session.gui_action("pop_eegplot"): | ||
| if command: | ||
| self._store_current_from_gui(eeg_out, command=command) | ||
| store_new = eegplot_accept_creates_dataset(selection, eeg_out, reject) | ||
| store_command = "" if command == self.session.LASTCOM else command | ||
| self._store_current_from_gui(eeg_out, new=store_new, command=store_command) | ||
| self._refresh() | ||
|
|
||
| pop_eegplot( | ||
| out = pop_eegplot( | ||
| selection, | ||
| icacomp=0 if variant in {"components", "reject_ica"} else 1, | ||
| icacomp=icacomp, | ||
| superpose=superpose, | ||
| reject=reject, | ||
| command_callback=accept_eegplot, | ||
| return_com=True, | ||
| ) | ||
| command = out[1] if isinstance(out, tuple) and len(out) > 1 else "" | ||
| if command: | ||
| self._add_history_from_gui(command) | ||
| self._refresh() |
There was a problem hiding this comment.
Dedup is fragile and the closure captures stale state
Two related concerns about the accept-callback wiring:
-
LASTCOMdedup can break. History is added immediately on line 1040 (_add_history_from_gui(command)). The browser's Accept callback may run seconds or minutes later. The dedup at line 1026 ("" if command == self.session.LASTCOM else command) only works if nothing else has touchedLASTCOMin between — e.g. the user opens another menu, the console echoes a command, or an autosave runs. When dedup fails the samepop_eegplot(EEG, ...)line ends up inALLCOMtwice. The dispatcher already knows it added the history; it would be more robust to pass that knowledge into the callback (e.g. via a flag closed over here) instead of inferring it from a stringly-typed comparison. -
selectionandrejectare snapshot at dispatch time. If the user changesCURRENTSET(selects a different dataset) between opening the browser and clicking Reject,eegplot_accept_creates_dataset(selection, eeg_out, reject)uses the originalselection, but_store_current_from_gui(eeg_out, new=False, ...)then writeseeg_outinto the currently selected slot. This is unlikely for a modal browser, but if multi-window inspection is supported it would silently overwrite the wrong dataset. Capturing the targetCURRENTSET[0]here and routing through it explicitly would be safer.
| def _pop_eegplot_reject_argument(args: tuple[Any, ...], kwargs: Mapping[str, Any]) -> int: | ||
| if "reject" in kwargs: | ||
| return int(kwargs["reject"]) | ||
| if len(args) >= 4: | ||
| return int(args[3]) | ||
| return 1 |
There was a problem hiding this comment.
Hard-coded positional index 3 is brittle
This relies on reject being the 4th positional parameter of pop_eegplot. The signature today is pop_eegplot(EEG, icacomp, superpose, reject, topcommand, *args, ...), so this works — but the next refactor that reorders or inserts a parameter (or moves reject keyword-only) will silently start reading the wrong value, since the only test that exercises this path passes via kwargs (tests/test_console_workspace.py:_fake_pop_eegplot).
A safer pattern is to bind via inspect.signature(pop_eegplot).bind_partial(*args, **kwargs).arguments.get("reject", 1), or at minimum to name the index as a constant tied to the signature. As-is, please add a test that calls the wrapper positionally with reject explicitly set, so any future signature drift fails loudly.
| def eegplot_accept_creates_dataset(input_eeg: dict[str, Any], output_eeg: dict[str, Any], reject: int = 1) -> bool: | ||
| """Return whether an accepted ``pop_eegplot`` result should be stored as a new dataset.""" | ||
| if not int(bool(reject)): | ||
| return False | ||
| input_trials = int(input_eeg.get("trials", 1) or 1) | ||
| output_trials = int(output_eeg.get("trials", 1) or 1) | ||
| if input_trials > 1: | ||
| return output_trials < input_trials | ||
| return _dataset_pnts(output_eeg) < _dataset_pnts(input_eeg) |
There was a problem hiding this comment.
Heuristic only catches sample/trial deletion
eegplot_accept_creates_dataset decides "new dataset vs. update in place" purely by comparing pnts / trials. This works for the rejection path in apply_eegplot_rejections, but it has two soft spots:
- If the user marks at least one window then clicks Reject, but the marks are zero-width or otherwise produce no
eeg_eegrejcut,output_pnts == input_pntsandstore_newis False, so the dataset is overwritten in place. That's probably fine, but it means a user clicking "Reject" after marking nothing produces a silent re-store with no visible change — worth verifying that downstream listeners (notify_changed) don't trigger spurious refreshes. reject=1is the only branch that ever returns True. If you later add a path wherereject=0mutates the dataset (e.g. some new EEGLAB-style "save marks as new dataset" flow), this helper will quietly classify it as an in-place edit.
Optional: a docstring example mapping (input.shape, output.shape, reject) → bool would make the intended semantics easy to spot-check from the callers.

Wire pop_eegplot into the EEGBrowser menu workflows with EEGLAB-style variant arguments, command echo, history, and session synchronization. Add ICA gating and regression coverage for GUI, console, and menu state behavior.\n\nFixes #98