Skip to content

Implement EEGBrowser Phase 2 UI shell - #104

Merged
suraj-ranganath merged 6 commits into
feature/eegbrowser-completionfrom
phase/eegbrowser-2-ui
May 31, 2026
Merged

suraj-ranganath merged 6 commits into
feature/eegbrowser-completionfrom
phase/eegbrowser-2-ui

Conversation

@suraj-ranganath

@suraj-ranganath suraj-ranganath commented May 31, 2026 •

Copy link
Copy Markdown
Member

Add the EEGLAB-style EEGBrowser shell with navigation controls, display/settings menus, scale and stack controls, event display, and visual parity capture cases. Align navigation and capture behavior with EEGLAB while leaving mark conversion and rejection mutation to the parallel Phase 3 work. Adds focused GUI and model tests.

Fixes #96

@claude

claude Bot commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 7m 43s —— View job


Code review — EEGBrowser Phase 2 UI shell

  • Overall assessment: needs changes (two EEGLAB-parity issues; everything else looks solid)
  • Highest-risk area: navigation step semantics and the channel-label content of the parity captures
  • Merge recommendation: needs changes

Blocking

None.

Important

  1. Visual-parity captures will systematically disagree with EEGLAB on channel labels. _demo_eegbrowser_eeg in visual_capture.py always provides chanlocs, and BrowserState.channel_label_mode defaults to "labels", so the Python captures for eegbrowser_continuous, eegbrowser_epoched, eegbrowser_events, and eegbrowser_grid_off all render the y-axis as Fp1, Fp2, …. The matching MATLAB commands in cases.json call eegplot(data, …) with no eloc_file, so EEGLAB shows channel numbers. Only eegbrowser_labels passes eloc_file. Four of the five "parity" cases will diverge on every capture. The if variant == "labels": model.state.channel_label_mode = "labels" line is also a no-op (that's already the default), which suggests the inverse case was intended. Inline comment posted with a small fix. Fix this →

  2. Navigation step semantics differ from EEGLAB (please verify). </> step by 0.2 * winlength and <</>> by 0.9 * winlength (eegbrowser.py#L681-L684, keyboard equivalents at L202-L205). EEGLAB eegplot.m's callbacks use 1 * winlength for single arrows and 5 * winlength for double arrows. The PR also locks this in via test_gui_navigation_buttons_and_position_field_update_visible_window, so it becomes the new contract. If the deviation is intentional, please call it out; otherwise switch to ±1.0 / ±5.0 and update the two GUI tests accordingly. Inline comment posted.

Nits

  • EEGBrowserWindow._build_shortcuts early-returns when QtGui is None or QtCore is None, but _require_gui() in __init__ would already have raised in that case — the guard is dead. (eegbrowser.py:199-200)
  • _BrowserControls.spacing.setRange(0.001, 1_000_000.0) clamps the spinbox tighter than set_spacing's max(value, np.finfo(float).eps) floor. If - reduces spacing below 0.001, the spinbox will display 0.001 while state holds the smaller value. Either align the floors or clamp set_spacing to 0.001. (eegbrowser.py:276,720)
  • _normalize_rgb accepts any float-tuple of length 3 (no [0, 1] range check). EEGLAB wincolor is documented as normalized RGB; values like (255, 255, 255) will silently render as a clamped highlight. Optional. (eegplot.py:587-593)
  • _show_status_message reparents new QMessageBox instances each call but only retains the latest in self._message_window; prior instances accumulate as children of self. Fine for a session-lived viewer, but worth keeping in mind once printing/help dialogs are wired up. (eegbrowser.py:417-424)

Test gaps

  • The two Important findings above each have a test that would need to move in lockstep with the fix:
    • test_gui_navigation_buttons_and_position_field_update_visible_window (asserts time == 0.4 after forward_step with winlength=2)
    • test_gui_keyboard_shortcuts_match_navigation_and_scale (asserts time == 0.4 after Key_Right with winlength=2)
  • The wincolor option is plumbed all the way into BrowserState.mark_color but there's no test exercising it (e.g., a wincolor=(0.5, 0.2, 0.2) round-trip through build_eegplot_model to state.mark_color). Small but cheap to add and would catch the _normalize_rgb range nit if you decide to enforce [0, 1].

EEGLAB parity notes

  • Menu structure (Figure/Display/Settings/Help), Stack/Spread, Norm/Denorm toggle (with _pre_normalize_spacing save/restore), event legend, and accept/cancel button gating on command + butlabel all line up with eegplot.m's shapes.
  • The position field for epoched data correctly uses EEGLAB's 1-based epoch numbering (state.time + 1 for display, value - 1 on input).
  • Stack mode collapses all visible traces to baseline (dispchans - 1) / 2, matching EEGLAB's superimposed view.
  • Channels covered: spectral/component modes still flow through BrowserData.mode and bottom axis label, so the new normalize/stack/marks knobs don't regress earlier phase-1 behavior.

Checked: correctness/regression bugs in the diff, EEGLAB parity for menus/controls/keyboard, BrowserState/BrowserData invariants, test coverage for new behaviors, and AGENTS.md compliance (no src/eegprep/eeglab runtime dependency, dataclass-based state, EEGLAB-style option names).
· branch: phase/eegbrowser-2-ui

Comment on lines +359 to +369
has_events = variant in {"events", "labels"}
model = build_eegplot_model(
_demo_eegbrowser_eeg(epoched=epoched, events=has_events),
winlength=1.0 if epoched else 2.0,
dispchans=6,
spacing=1.2,
xgrid="on" if variant != "grid_off" else "off",
ygrid="on" if variant != "grid_off" else "off",
)
if variant == "labels":
model.state.channel_label_mode = "labels"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: important (EEGLAB visual parity)

_demo_eegbrowser_eeg always returns chanlocs with named labels, and BrowserState.channel_label_mode defaults to "labels" (see eegplot.py#L121). So all five capture variants render the channel axis as Fp1, Fp2, ….

But the MATLAB sides of eegbrowser_continuous/epoched/events/grid_off call eegplot(data, …) on a raw matrix with no eloc_file — EEGLAB's eegplot.m falls back to channel numbers in that case. Only eegbrowser_labels passes eloc_file = struct('labels', {...}).

Net effect: four of the five "parity" cases will systematically disagree with EEGLAB on the y-axis labels (named labels vs. numbers), undermining the visual evidence the PR is meant to produce.

The if variant == "labels": model.state.channel_label_mode = "labels" block on line 368-369 is also a no-op (it's the default) — looks like the inverse case was intended.

Concrete fix: force "numbers" for the non-labels variants so they match the MATLAB defaults:

Suggested change
has_events = variant in {"events", "labels"}
model = build_eegplot_model(
_demo_eegbrowser_eeg(epoched=epoched, events=has_events),
winlength=1.0 if epoched else 2.0,
dispchans=6,
spacing=1.2,
xgrid="on" if variant != "grid_off" else "off",
ygrid="on" if variant != "grid_off" else "off",
)
if variant == "labels":
model.state.channel_label_mode = "labels"
has_events = variant in {"events", "labels"}
model = build_eegplot_model(
_demo_eegbrowser_eeg(epoched=epoched, events=has_events),
winlength=1.0 if epoched else 2.0,
dispchans=6,
spacing=1.2,
xgrid="on" if variant != "grid_off" else "off",
ygrid="on" if variant != "grid_off" else "off",
)
if variant != "labels":
model.state.channel_label_mode = "numbers"

Alternatively, drop chanlocs from _demo_eegbrowser_eeg and only inject them for the labels variant — that more faithfully mirrors what the MATLAB call sees.

Comment on lines +681 to +684
self.back_page_button = self._button("<<", lambda: browser.scroll_time(-0.9))
self.back_step_button = self._button("<", lambda: browser.scroll_time(-0.2))
self.forward_step_button = self._button(">", lambda: browser.scroll_time(0.2))
self.forward_page_button = self._button(">>", lambda: browser.scroll_time(0.9))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: important (EEGLAB parity — please verify against eegplot.m)

< / > step by 0.2 * winlength and << / >> step by 0.9 * winlength. EEGLAB's eegplot.m single-arrow buttons advance by one full winlength and the double-arrow buttons by five winlengths (callback strings like eegplot('position', max(get(ED,'Value') - g.winlength, 0), …) and the equivalent 5 * g.winlength variant). 0.2/0.9 will feel like "scroll a fraction of the current window" rather than "next page / next 5 pages", and would be a noticeable behavioral regression for EEGLAB users.

The same fractions are also wired into keyboard shortcuts (line 202-205) and locked in by test_gui_navigation_buttons_and_position_field_update_visible_window, so this would become the contract once the PR lands.

Suggested fix (preserves the test by adjusting the input rather than the assertion):

Suggested change
self.back_page_button = self._button("<<", lambda: browser.scroll_time(-0.9))
self.back_step_button = self._button("<", lambda: browser.scroll_time(-0.2))
self.forward_step_button = self._button(">", lambda: browser.scroll_time(0.2))
self.forward_page_button = self._button(">>", lambda: browser.scroll_time(0.9))
self.back_page_button = self._button("<<", lambda: browser.scroll_time(-5.0))
self.back_step_button = self._button("<", lambda: browser.scroll_time(-1.0))
self.forward_step_button = self._button(">", lambda: browser.scroll_time(1.0))
self.forward_page_button = self._button(">>", lambda: browser.scroll_time(5.0))

…and analogous updates to the keyboard shortcuts (Left/Right ≈ ±1.0, PageUp/PageDown ≈ ±5.0), plus update test_gui_navigation_buttons_and_position_field_update_visible_window and test_gui_keyboard_shortcuts_match_navigation_and_scale to reflect a 1 * winlength step. If you have a deliberate reason for the smaller fractions (e.g. matplotlib-style "small nudge"), please call it out in the PR description so it's an intentional deviation rather than a parity drift.

@suraj-ranganath

suraj-ranganath commented May 31, 2026 •

Copy link
Copy Markdown
Member Author

Attachments

🤖 EEGBrowser Phase 2 visual parity evidence

eegbrowser_continuous_side_by_side_v2.png eegbrowser_epoched_side_by_side_v2.png
eegbrowser_continuous_side_by_side_v2.png eegbrowser_epoched_side_by_side_v2.png
eegbrowser_events_side_by_side_v2.png eegbrowser_grid_off_side_by_side_v2.png
eegbrowser_events_side_by_side_v2.png eegbrowser_grid_off_side_by_side_v2.png
eegbrowser_labels_side_by_side_v2.png
eegbrowser_labels_side_by_side_v2.png

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Updated event-overlay visual evidence after the targeted EEGBrowser parity fix.

Commit: 6dae92b

Changes covered:

  • Event labels now render outside the plotting box as scene overlays.
  • Event latency lines are drawn after traces with a high z-order, so stim remains visible.
  • Event color assignment now follows EEGLAB sorted unique event-type mapping, giving stim magenta and resp green in this case.

Visual reports:

  • eegbrowser_events: mean_abs_delta 0.037816, different_pixel_ratio 0.105117
  • eegbrowser_labels: mean_abs_delta 0.038645, different_pixel_ratio 0.106510

EEGBrowser event overlay parity v3

eegbrowser_events_v3_side_by_side.png eegbrowser_labels_v3_side_by_side.png
eegbrowser_events_v3_side_by_side.png eegbrowser_labels_v3_side_by_side.png

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Confirmed the plot box issue and pushed a fix.

Commit: fe4c716

What changed:

  • Added an explicit black scene-rectangle frame around the data view so the EEGLAB-style box is visible in continuous, event, and label cases.
  • Removed top/right tick marks from the hidden-value axes so those sides read as a clean box instead of faint pyqtgraph ticks.
  • Kept event labels above the frame and event latency lines visible.

Checks:

  • uv run --no-sync pytest tests/test_eegplot_gui.py -q: 12 passed
  • uv run --no-sync ruff check src/eegprep/functions/guifunc/eegbrowser.py tests/test_eegplot_gui.py: passed
  • uv run --no-sync ruff format --check src/eegprep/functions/guifunc/eegbrowser.py tests/test_eegplot_gui.py: passed
  • uv run --no-sync ty check src/eegprep/functions/guifunc/eegbrowser.py tests/test_eegplot_gui.py: passed
  • ./pre-commit.py --fix: passed

Visual reports after the box fix:

  • eegbrowser_continuous: mean_abs_delta 0.039424, different_pixel_ratio 0.101904
  • eegbrowser_events: mean_abs_delta 0.039061, different_pixel_ratio 0.106041
  • eegbrowser_labels: mean_abs_delta 0.039891, different_pixel_ratio 0.107433

EEGBrowser plot box parity v4

eegbrowser_continuous_v4_box_side_by_side.png eegbrowser_events_v4_box_side_by_side.png
eegbrowser_continuous_v4_box_side_by_side.png eegbrowser_events_v4_box_side_by_side.png
eegbrowser_labels_v4_box_side_by_side.png
eegbrowser_labels_v4_box_side_by_side.png

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Fixed the missing stim marker line.

Commit: 0598ad3

What changed:

  • Event latency strokes now render as Qt scene overlay lines spanning the plot frame, instead of pyqtgraph InfiniteLine data items.
  • The marker lines draw above traces and below the plot frame/labels, so the stim marker remains visible while the EEGLAB-style box stays intact.
  • The visible stim marker is magenta in this reference case because EEGLAB maps the sorted event types to colors that way.

Checks:

  • uv run --no-sync pytest tests/test_eegplot_gui.py -q: 12 passed
  • focused ruff check, ruff format --check, ty check: passed
  • ./pre-commit.py --fix: passed

Visual reports:

  • eegbrowser_events: mean_abs_delta 0.038884, different_pixel_ratio 0.105636
  • eegbrowser_labels: mean_abs_delta 0.039713, different_pixel_ratio 0.107028

EEGBrowser event marker lines v5

eegbrowser_events_v5_marker_lines_side_by_side.png eegbrowser_labels_v5_marker_lines_side_by_side.png
eegbrowser_events_v5_marker_lines_side_by_side.png eegbrowser_labels_v5_marker_lines_side_by_side.png

@suraj-ranganath
suraj-ranganath merged commit 6060357 into feature/eegbrowser-completion May 31, 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