Skip to content

Fix EEGBrowser visual parity axes - #130

Merged
arnodelorme merged 3 commits into
developfrom
fix/eegbrowser-visual-parity-129
Jun 11, 2026
Merged

arnodelorme merged 3 commits into
developfrom
fix/eegbrowser-visual-parity-129

Conversation

@suraj-ranganath

Copy link
Copy Markdown
Member

Align EEGBrowser channel visibility and epoched x-axis rendering with EEGLAB captures. This restores EEGLAB-style extra visible rows, separates epoched epoch labels from latency ticks, and keeps visual parity captures using comparable raw data.

Fixes #129

@claude

claude Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

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


Code review

  • Overall assessment: Safe to merge — small, well-targeted, fully test-backed.
  • Highest-risk area: Epoched latency-axis math (_latency_ticks / _epoch_latency_increment_ms) and the EEGLAB "+2 extra rows" heuristic.
  • Merge recommendation: Safe to merge (two parity items to confirm below, neither blocking).

What I checked

  • Rename _x_ticks → _bottom_x_ticks: all call sites updated (eegbrowser.py:745, :1106, test), no stale references remain.
  • New imports resolve: eeg_point2lat (functions/popfunc/eeg_point2lat.py), browser_visible_channel_count, browser_max_channel_offset. QtCore is already imported and QtCore.Qt.PenStyle.DashLine matches existing usage in this module.
  • Latency math: traced _latency_ticks against eeg_point2lat semantics and the new test fixture (srate 250, xmin −0.2, xmax 0.796). x_value = 50.0/300.0/550.0 → label "0" is correct (0 ms sits at (0-(-0.2))*250 = 50 within each epoch). Consistent with state.limits being stored in ms.
  • state.limits is read in exactly one place (eegbrowser.py:1025, epoched-only), so widening the build_eegplot_model default-limits path to all raw arrays is harmless for continuous data — confirmed by grep across src/eegprep.
  • browser_visible_channel_count edge behavior: offset 0 → all 8 visible (dispchans+2 capped by remaining); max offset 2 → 6 visible. Matches the updated GUI tests, and the (3,100)→(4,100) test-fixture bumps are the necessary consequence of the extra rows.

Blocking

None.

Important

None.

Nits

None.

Test gaps

None blocking. _epoch_latency_increment_ms is only exercised indirectly via _bottom_x_ticks; if you want to lock the EEGLAB divisor selection, a tiny unit test asserting the chosen increment for a known (winlength, epoch_width_ms) would make future regressions obvious. Optional.

EEGLAB parity notes

  1. visual_capture.py epoched captures now drop xmin/xmax. Switching data = eeg → data = np.asarray(eeg["data"]) means the epoched demo (which sets xmin=-0.2, xmax=0.796) no longer carries those limits; with source_eeg is None, the new default path yields limits = (0.0, 996.0), so the captured bottom axis runs 0…996 ms instead of −200…796 ms. This is fine iff the EEGLAB side of the side-by-side comparison is also invoked with a raw array (so both default to a 0-based latency origin) — which matches the PR's "comparable raw data" intent. Please confirm the EEGLAB capture is fed a raw matrix too; otherwise the epoched latency axis won't line up. Not a runtime concern (dev tooling only).
  2. "+2 extra visible rows" and the _epoch_latency_increment_ms divisor table are EEGLAB visual-parity heuristics. The vendored EEGLAB source isn't present in this checkout, so I verified them against the new tests rather than eegplot.m directly. The dispchans+2 reasoning (EEGLAB's ylim = [0 dispchans+1] exposing partial neighbor traces) is sound; just flagging that the exact constants rest on the screenshot loop, not a MATLAB diff.

Did not run the suite (uv run pytest requires interactive approval in this environment), but the assertions were validated by reading through the changed logic. Static review only.

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Added side-by-side visual parity evidence for the two issue #129 cases.

EEGBrowser visual parity captures

Reject data browser Rejection epochs browser
eegbrowser_pop_eegplot_reject_data_side_by_side.png eegbrowser_rejection_epochs_side_by_side.png

What this fixes:

  • The reject-data browser now shows the EEGLAB-style extra visible channel rows, so the 8-channel / dispchans=6 capture no longer drops channels 7 and 8.
  • The epoched rejection browser now uses a separate top epoch axis and bottom within-epoch latency axis, with trial-boundary grid lines separated from ordinary x-grid ticks.

Why the wave traces still look slightly different:

  • EEGLAB renders these traces through MATLAB figures, while EEGPrep renders them through Qt/pyqtgraph. Thin 1px traces are antialiased and sampled differently by the two renderers, so line texture can differ even when the arrays match.
  • EEGPrep’s browser has trace decimation/downsampling for responsiveness on large EEG datasets. That is intentional product behavior, but it can make visual parity screenshots look less like MATLAB’s direct figure line rendering.
  • The visual parity cases currently build matching synthetic data separately in MATLAB and Python rather than loading one shared fixture file. The formulas are intended to be equivalent, but because each runtime constructs and renders its own array, tiny differences in dtype, axis defaults, flattening/window interpretation, and renderer sampling can show up as trace-shape differences. For strict pixel-level trace parity, the next improvement would be to drive both captures from a single checked fixture and then tune only the renderer behavior.

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Updated the Rejection Epochs browser parity capture after matching EEGLAB's dense epoched x-axis treatment. EEGPrep now suppresses pyqtgraph's horizontal epoched bottom labels and draws rotated latency labels below the plot, while preserving the separate top epoch-number axis and trial-boundary grid lines.

eegbrowser_rejection_epochs_diagonal_labels_side_by_side.png

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.

eegplot issue

2 participants