Skip to content

Phase 3: Interactive marking, winrej, and rejection conversion parity #97

Closed

Description

@suraj-ranganath

🤖 Phase 3 for the EEGBrowser epic. Target branch: feature/eegbrowser-completion.

Dependency

Start after Phase 1 merges. This can run in parallel with Phase 2, then integrate after Phase 2.

Goal

Implement the user interaction and rejection semantics that make EEGBrowser useful for visual marking and rejection.

Implementation scope

  • Mouse drag/click marking and unmarking for continuous data and epoched data.
  • Channel/electrode-specific marks in the winrej trailing columns.
  • Color handling for new, old, and superposed marks.
  • Python ports of trial2eegplot, eegplot2event, and eegplot2trial.
  • Command callback contract for accepting/rejecting marked regions.
  • Session-safe cancel/failure behavior.

Acceptance criteria

  • Marking behavior matches EEGLAB for continuous regions, whole epochs, reversed drags, duplicate marks, overlapping marks, single-click unmarking, and channel-specific toggles.
  • Conversion helpers have MATLAB parity tests.
  • Rejected continuous regions flow through eeg_eegrej with correct event/urevent/boundary semantics.
  • Failed/cancelled browser actions do not mutate session or history.
  • No runtime code depends on src/eegprep/eeglab.

Tests and evidence

  • Unit tests for winrej, trial2eegplot, eegplot2event, and eegplot2trial edge cases.
  • MATLAB parity tests for deterministic helper conversions.
  • GUI interaction tests for marking/unmarking and accept/cancel.
  • Console/session history tests for accept/reject/cancel paths.
  • uv run --no-sync ruff check .
  • uv run --no-sync ruff format --check .
  • uv run --no-sync ty check
  • Focused pytest for changed tests.

/goal prompt

/goal Implement interactive EEGBrowser marking and rejection conversion from this issue. Port winrej, trial2eegplot, eegplot2event, and eegplot2trial semantics from EEGLAB, including continuous/epoched/channel-specific marks and superposed colors. Verify with MATLAB parity tests, sample_data, GUI interaction tests, console/session history tests, ruff/format/ty, and focused pytest.

Required references for every phase

  • AGENTS.md
  • .agents/skills/eegprep-feature-development/SKILL.md
  • .agents/skills/eeglab-gui-visual-parity/SKILL.md for GUI features
  • .agents/skills/gui-agent-flow-qa/SKILL.md for end-user flow QA
  • EEGLAB reference under src/eegprep/eeglab, used only as development/parity input.

Core EEGLAB references

  • src/eegprep/eeglab/functions/sigprocfunc/eegplot.m
  • src/eegprep/eeglab/functions/sigprocfunc/eegplotlegacy.m
  • src/eegprep/eeglab/functions/sigprocfunc/eegplot2event.m
  • src/eegprep/eeglab/functions/sigprocfunc/eegplot2trial.m
  • src/eegprep/eeglab/functions/sigprocfunc/trial2eegplot.m
  • src/eegprep/eeglab/functions/popfunc/pop_eegplot.m
  • src/eegprep/eeglab/functions/popfunc/eeg_rejmacro.m
  • src/eegprep/eeglab/functions/popfunc/eeg_multieegplot.m

Activity

  1. added
    phase
    on May 31, 2026
  2. claude commented on May 31, 2026

    @claude
    Contributor

    🤖 Plan:

    • Read AGENTS.md and fix-issue / pull-request skills
    • Actionability check
    • Duplicate-work preflight (no open PR for this issue)
    • Dependency status check (Phase 1 Phase 1: Browser data model, rendering foundation, and eegplot API #95 not merged)
    • Inventory existing rejection/browser scaffolding
    • Post research + proposed approach (this comment)
    • Awaiting human approval / Phase 1 merge before opening a PR

    Research

    Scope is large (>100 LOC, multi-module: sigprocfunc, popfunc, guifunc, session/history, MATLAB parity fixtures). Per repo policy I am posting analysis instead of a PR.

    Blocking dependency. Issue explicitly says "Start after Phase 1 merges". Phase 1 (#95) is still open; the foundation this issue builds on does not exist yet:

    • no eegplot(...) API
    • no winrej data model
    • no EEGBrowser window
    • src/eegprep/functions/sigprocfunc/ has no eegplot.py
    • src/eegprep/functions/guifunc/ has no browser widget
    • pop_eegplot is intentionally a placeholder with excluded_reason=\"eegbrowser\"

    EEGLAB references not vendored locally. src/eegprep/eeglab/functions/sigprocfunc/ is absent in this checkout, so MATLAB ports must be performed against sccn/eeglab upstream (eegplot.m, eegplot2event.m, eegplot2trial.m, trial2eegplot.m, eeg_rejmacro.m, eeg_multieegplot.m, pop_eegplot.m).

    Relevant existing code (anchor points for Phase 3, not yet wired to a browser):

    • src/eegprep/functions/popfunc/eeg_eegrej.py#L272-L319 — already accepts 4-column eegplot-style [ch_low ch_high beg end] rows and discards channel cols; this is the downstream sink Phase 3 must feed.
    • src/eegprep/functions/popfunc/eeg_rejsuperpose.py#L12-L77 — combines rejection mark families into EEG.reject.rejglobal/rejglobalE; superposed color logic must agree with this.
    • src/eegprep/functions/popfunc/_rejection.py (406 LOC) — shared copy_eeg, mark bookkeeping; reuse, do not duplicate.
    • src/eegprep/functions/guifunc/menu_placeholders.py#L39,L64 — pop_eegplot placeholder + EEGBrowser exclusion message; remove/replace once browser lands.
    • src/eegprep/functions/popfunc/pop_rejmenu.py#L264 and src/eegprep/plugins/ICLabel/pop_viewprops.py#L99-L100 — user-facing strings that disclaim missing browser; update when Phase 3 unblocks them.

    Proposed Approach (for human review before implementation)

    This is a design-change scope, not a bug fix. Recommend gating implementation on Phase 1 merge and splitting Phase 3 into three commits on feature/eegbrowser-completion:

    1. Pure helper ports (no Qt, fully unit-testable). Add to functions/sigprocfunc/:

      • eegplot2event.py — port of eegplot2event.m. Convert winrej (N×(5+nch) — [beg end r g b ch1..chN]) to EEG event rows with type='rejN', latency=beg, duration=end-beg+1, channel mask in trailing fields. 1-based MATLAB latencies preserved at the EEG-event boundary.
      • eegplot2trial.py — port of eegplot2trial.m. Convert continuous winrej rows into per-trial reject vectors using srate and pnts.
      • trial2eegplot.py — inverse of eegplot2trial; build winrej rows from per-trial / per-channel mark matrices.
      • Tests: MATLAB parity fixtures under tests/matlab/ (skipped without MATLAB/Octave via eeglabcompat), plus pure-Python edge cases (empty, reversed, overlapping, duplicate, channel-specific, boundary-of-window).
    2. Interactive marking on the browser widget (functions/guifunc/eegbrowser.py from Phase 1):

      • Mouse press/drag/release handlers; click-without-drag = unmark of the hit region.
      • Channel-row hit testing for channel-specific marks (writes the ch1..chN cols of winrej).
      • Color contract: new-marks color from pop_* caller, old-marks color from EEG.reject.rej*color, superposed color via blend matching eeg_rejmacro.m. Constants at module top.
      • Reversed drag, duplicate-region, overlap merging — match eegplot.m exactly (cross-checked via the helper ports above so logic isn't duplicated).
      • Tests use QTest mouse events on a headless QApplication; assert winrej state, not pixel state.
    3. Command callback contract & session safety:

      • pop_* callers pass a callback string (EEGLAB 'command' arg). Accept → run callback with current winrej materialized into globals expected by eeg_rejmacro (TMPREJ, etc.) — in Python, materialize as kwargs into eeg_eegrej / eeg_rejsuperpose / pop_rejepoch depending on caller.
      • Cancel/close-without-accept: zero mutation to EEGPrepSession (EEG, ALLEEG, CURRENTSET, LASTCOM, ALLCOM). Exception in callback → restore pre-action snapshot, leave LASTCOM untouched, surface the error.
      • tests/test_console_workspace.py gets accept/cancel/error coverage per AGENTS.md GUI And Console Workspace section.

    Open questions for the issue author before any code lands:

    1. Should Phase 3 begin on a sub-branch (phase/3-interactive-marking) off feature/eegbrowser-completion, opened as draft until Phase 1 merges? Or wait entirely?
    2. Color blending for superposed marks — replicate MATLAB additive blend exactly, or pick a Qt-native equivalent and capture the deviation in .notes/implementation-notes.html?
    3. eeg_rejmacro in MATLAB relies on evalin('base', ...) globals. The Python equivalent presumably routes through EEGPrepSession rather than re-implementing a global namespace dance — confirm?
    4. Channel-specific marks: Phase 3 owns the winrej[:, 5:] columns and the electrodes field surface in eegplot, but who owns rendering them as colored row segments — Phase 2 or Phase 3?

    Stopping here pending Phase 1 merge and answers to the above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

phase

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions