Skip to content

Phase 1: Browser data model, rendering foundation, and eegplot API #95

Closed

Description

@suraj-ranganath

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

Goal

Build the standalone browser foundation under EEGPrep conventions. This phase defines the shared data model, state model, rendering foundation, and public eegplot(...) API used by later phases.

Implementation scope

  • Add the Python eegplot(...) surface in the locally appropriate split between functions/sigprocfunc and functions/guifunc.
  • Add data normalization for continuous, epoched, component, spectral, and overlay inputs.
  • Add winrej data model support, visible-window state, event overlay state, scaling state, channel-label state, and decimation for large datasets.
  • Use PySide6/QPainter or Qt-native painting first; do not add a rendering dependency unless implementation proves Qt-native rendering cannot meet responsiveness requirements.
  • Add packaged help resource src/eegprep/resources/help/eegplot.md.
  • Maintain .notes/implementation-notes.html with parity decisions and open questions.

Acceptance criteria

  • eegplot(data, key=value, ...) accepts EEGLAB-compatible core options: srate, spacing, limits, winlength, time, dispchans, title, plottitle, xgrid, ygrid, data2, winrej, events, submean, eloc_file, scale, and color.
  • Basic viewer opens without mutating EEG data.
  • Headless tests cover option parsing, data normalization, window bounds, event/time conversion, and decimation.
  • GUI tests verify a nonblank rendered browser with sample_data/eeglab_data.set.
  • No runtime code depends on src/eegprep/eeglab.

Tests and evidence

  • Focused unit tests for model/state/parsing helpers.
  • GUI smoke tests for nonblank render and no mutation.
  • Sample-data test using sample_data/eeglab_data.set.
  • 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 the EEGPrep EEGBrowser/eegplot foundation from this issue, using EEGLAB eegplot.m/eegplotlegacy.m as parity references. Build the data model, rendering foundation, and public eegplot API without runtime EEGLAB dependency. Verify with unit tests, GUI smoke tests, sample_data, ruff/format/ty, and focused pytest. Maintain .notes/implementation-notes.html with parity decisions and open questions.

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:

    • Confirm issue actionability and scope
    • Duplicate-work preflight (PRs / branches / sibling phase issues)
    • Inventory current eegplot footprint in repo
    • Post Research + Proposed Approach (no PR — scope >100 LOC)
    • Await human direction on open questions before implementation

    Scope decision. This is the Phase-1 foundation for an entire scrolling-browser subsystem (data model + Qt renderer + public API + parsing + tests + help). The sibling merged phases (#68, #74, #75, etc.) each added 1k–10k LOC. Per the agent instructions, anything >100 LOC gets an analysis comment, not a drive-by PR. No open PR targets feature/eegbrowser-completion for browser work yet — that branch currently only carries STUDY work from #93. Sibling phases #96–#101 depend on this one.

    Research

    EEGPrep currently has no eegplot Python surface. pop_eegplot is registered as a permanent placeholder with excluded_reason=\"eegbrowser\" (src/eegprep/functions/guifunc/menu_placeholders.py#L39), and placeholder_message emits an EEGLAB-style "outside parity scope" string (#L62-L66). That exclusion must be lifted as part of this phase so menu actions can route to the new viewer instead of the coming-soon dialog.

    The vendored EEGLAB tree at `src/eegprep/eeglab/` is empty in this checkout (it is a submodule populated by contributors, not by CI). The issue's reference list (`eegplot.m`, `eegplotlegacy.m`, `pop_eegplot.m`, `eeg_rejmacro.m`, `eeg_multieegplot.m`, `eegplot2event.m`, `eegplot2trial.m`, `trial2eegplot.m`) is therefore a parity oracle the implementer must check out locally; AGENTS.md forbids the runtime package from depending on it (see AGENTS.md §EEGLAB Parity).

    Relevant code

    Proposed Approach

    This is a design-change comment (feature port), not a bug fix. Splitting Phase 1 along the structural boundary called out in the issue:

    1. Package layout. Two new modules — keep public API in sigprocfunc, keep Qt widgets in guifunc, mirroring how topoplot.py (compute) lives next to its Qt host.

    • src/eegprep/functions/sigprocfunc/eegplot.py — argument parser, data normalizer, state object, decimation, and the public eegplot(data, **kwargs) entry that constructs and shows the viewer.
    • src/eegprep/functions/guifunc/eegbrowser.py (new) — EEGBrowserWindow (QMainWindow) + EEGBrowserCanvas (QWidget with paintEvent doing the trace draw). No matplotlib, no pyqtgraph in Phase 1.

    2. Data model. Single immutable BrowserData dataclass that normalizes the five input modes into channel-major (nchan, npts, ntrials) with ntrials=1 for continuous:

    • continuous (nchan, npts) → trials=1
    • epoched (nchan, npts, ntrials) → passed through
    • component activations → routed via icaact/icawinv and tagged so axis labels switch to "Comp N"
    • spectral overlay → second-axis data2 with shared time/x-grid
    • overlay (data2) — same shape constraints as primary

    Reject (a) jagged inputs, (b) nbchan mismatch with eloc_file, (c) winrej rows whose [start,end] lie outside [0, pnts*trials]. Fail fast with ValueError, no silent reshape.

    3. State. Mutable BrowserState dataclass holding srate, spacing, winlength, time (window-start sec), dispchans, xgrid, ygrid, submean, scale, color theme, current winrej list, and the events overlay table. Time↔sample conversion goes through one helper (time_to_sample(state, t) -> int) so MATLAB 1-based latency boundaries are handled in exactly one place — covered by a dedicated test for xmin, xmin+1/srate, and the last sample.

    4. Rendering. QPainter-based draw in paintEvent:

    • Per visible channel: a QPainterPath of (x_px, y_px) pairs. Per-channel offset = (idx - dispchans/2) * spacing.
    • Decimation: if pnts_in_window > widget_width_px * 2, downsample by min/max pair per pixel column (the standard responsiveness pattern; matches EEGLAB's redraw cadence). Threshold lives as a single top-level constant.
    • Event overlays: vertical lines + labels above the top trace, hit-tested via a QRectF table for later phases.
    • winrej rectangles: translucent fill behind traces, color taken from row columns 3-5 like EEGLAB.

    5. Public API. eegplot(data, *, srate=1, spacing=None, limits=(0,0), winlength=5, time=0, dispchans=None, title='', plottitle='', xgrid='off', ygrid='off', data2=None, winrej=None, events=None, submean='off', eloc_file=None, scale='on', color='off') returning the window so callers can .show() / .close(). Does not mutate EEG dicts — accepts an np.ndarray or an EEG dict and copies what it needs.

    6. Acceptance-criteria mapping.

    • Option parsing → tests/test_eegplot_parser.py (headless, no Qt import).
    • Data normalization → same file, parametrize the 5 input modes.
    • Window bounds + event/time conversion → tests/test_eegplot_state.py.
    • Decimation → property test in same file: output length ≤ 2 * widget_width_px, first/last sample preserved.
    • GUI nonblank render → tests/test_eegplot_gui.py marked @pytest.mark.gui, uses QApplication, calls widget.grab(), asserts non-uniform pixel std.
    • Sample-data test → same file, loads sample_data/eeglab_data.set and asserts no-mutation on the source EEG dict.

    7. Help + notes.

    • src/eegprep/resources/help/eegplot.md — EEGLAB-parity option table.
    • .notes/eegplot-phase1.html (issue says implementation-notes.html) — record parity decisions, esp. anywhere we deviate from eegplot.m.

    8. Lift the placeholder. Replace the pop_eegplot entry in menu_placeholders.py with a stub pop_eegplot.py that calls into the new eegplot and returns (EEG, com). Update tests/test_menu_placeholder_inventory.py.

    Open Questions for Human Review

    1. Qt vs. pyqtgraph. Issue says "do not add a rendering dependency unless implementation proves Qt-native rendering cannot meet responsiveness requirements." Phase 1 will go QPainter-only. Acceptable to defer the pyqtgraph decision to Phase 2 if/when scrolling/marking latency becomes the bottleneck?
    2. Component mode in Phase 1. Acceptance criteria list eloc_file and channel-label state but not explicit component-mode rendering. Treat component activations as a labeled channel array (no scalp inset) in Phase 1, defer the inset to Phase 6?
    3. eeg_multieegplot / eegplot2event / eegplot2trial / trial2eegplot. Issue lists them as references but they are conversion utilities feeding marking/rejection workflows (Phase 3). Scope them out of Phase 1 — agreed?
    4. .notes/ filename. Issue says implementation-notes.html; sibling phases used per-phase filenames. Use .notes/eegplot-phase1.html to avoid collisions, or stick to the literal name from the issue?
    5. Branch target. Open Phase-1 PR against feature/eegbrowser-completion (currently STUDY-only) or directly against develop?

    Will not open a PR until these are settled.

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