Skip to content

Implement advanced EEGBrowser display modes - #106

Merged
suraj-ranganath merged 2 commits into
feature/eegbrowser-completionfrom
phase/eegbrowser-6-advanced
Jun 1, 2026
Merged

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

Conversation

@suraj-ranganath

Copy link
Copy Markdown
Member

Add EEGBrowser data2 overlays, linked/noui/frequency modes, eeg_multieegplot, and browser-backed property activity views. This also enables pop_subcomp(plotag=True) to show a before/after data2 browser and expands tests for advanced channel/component display behavior.

Fixes #100
Part of #94

@claude

claude Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 6m 54s —— View job


Code review

  • Overall assessment: needs minor changes (one silent feature regression, one perf issue on realistic EEG sizes).
  • Highest-risk area: eegplot option surface and pop_subcomp before/after preview construction.
  • Merge recommendation: needs changes (none are blocking; the plotdata2 and deepcopy items are the strongest).

Blocking

None.

Important

  1. plotdata2 is dead code — src/eegprep/functions/sigprocfunc/eegplot.py:34, 613. The PR adds "plotdata2" to _OPTION_NAMES and sets options.setdefault("plotdata2", "off"), but the value is never read anywhere downstream. The data2 overlay is rendered solely based on whether data2 was passed (see eegbrowser.py:864, _draw_overlay_trace). EEGLAB's plotdata2 flag controls whether data2 is rendered as an overlay vs. replaces the primary trace — users who pass plotdata2="on" will see no behavior change. Either wire it through to the canvas, or drop it from _OPTION_NAMES and the defaults so unsupported input is not silently swallowed. (inline)

  2. _plot_subcomp_confirmation deep-copies the entire EEG dict and then immediately throws the copied data away — src/eegprep/functions/popfunc/pop_subcomp.py:140-147. copy.deepcopy(input_eeg) walks the full data array (tens to hundreds of MB for a typical multi-channel multi-minute recording) just so the next line can replace it with the subset under icachansind. Build the preview dict explicitly with only what eegplot needs (data, nbchan, chanlocs, plus event/srate/xmin/xmax/pnts/trials if you want eegplot's _default_* paths to find them). (inline)

Nits

  1. Asymmetric old/new rejection-row ordering in eeg_multieegplot — src/eegprep/functions/popfunc/eeg_multieegplot.py:82-99 vs :110-117. Epoched builds [old, new]; continuous builds [new, old]. Where rejection rectangles overlap on screen, the later row paints over the earlier one — so the two modes produce opposite z-stacks. EEGLAB's eeg_multieegplot.m consistently draws old first so new marks visually take precedence; mirror that for continuous. (inline)

  2. EEGBrowserWindow.set_publication_view(False) won't restore hidden controls — src/eegprep/functions/guifunc/eegbrowser.py:179-204, 404-407. The non-noui branch of _layout_children only positions widgets; it never calls .show() on channel_slider, scale_indicator, controls, or menuBar() after they were hidden. There's no menu path to disable publication mode today, but the set_publication_view(enabled=True) signature implies a symmetric off-toggle — if/when that lands it'll bite.

Test gaps

  1. _trial_marks (eeg_multieegplot.py:139-149) accepts both a length-trials mask AND a list of 1-based trial indices. The added tests only cover the mask path. Add e.g. eeg_multieegplot(np.zeros((1, pnts, 4)), rej=[2, 4]) to lock the integer-index path.

  2. The new children= option on eegplot() (sigprocfunc/eegplot.py:184-189) is not exercised end-to-end. The linked-windows test calls EEGBrowserWindow.link_child directly. A smoke test that calls eegplot(data, children=other_window) and asserts the parent's _linked_windows contains the child would close that path.

EEGLAB parity notes

  • pop_subcomp before/after browser correctly mirrors EEGLAB's eegplot(EEG.data(EEG.icachansind,:), 'data2', TMP.data(EEG.icachansind,:), 'limits', [EEG.xmin EEG.xmax]*1000) invocation, including channel-set narrowing via icachansind. Title text matches EEGLAB.
  • eeg_multieegplot defaults (OLD = (0.8, 1.0, 0.8), NEW = (0.8, 0.8, 1.0), winlength=5, xgrid='off') match EEGLAB.
  • noui publication-view layout, linked-window scroll sync, and spectral-mode axis labels look correct against EEGLAB conventions.

Checked: bugs in changed lines, EEGLAB parity for pop_subcomp plotag flow / eeg_multieegplot / noui mode, data structure handling of chanlocs/event/icachansind, test coverage for changed behaviors, and CLAUDE.md/AGENTS.md compliance.
· branch phase/eegbrowser-6-advanced

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Spec

Problem
Issue #100 tracks the Phase 6 EEGBrowser gaps: eegplot accepted data2/frequency options but advanced browser flows were incomplete in src/eegprep/functions/sigprocfunc/eegplot.py:168, child-window scrolling was not represented in the Qt shell at src/eegprep/functions/guifunc/eegbrowser.py:130, pop_subcomp(plotag=True) still could not show the EEGLAB before/after browser path at src/eegprep/functions/popfunc/pop_subcomp.py:55, and property/viewprops flows did not expose scrolling activity views.

Approach
The browser model now normalizes data2 overlays, freqs/freqlimits axes, numeric component labels, noui state, and children links. The Qt window adds publication view hiding, child lifetime tracking, and graph-based synchronized time/channel scrolling. eeg_multieegplot is added as an EEGLAB-style popfunc helper with old/new rejection colors, pop_subcomp(plotag=True) opens a before/after data2 browser, and pop_prop/pop_viewprops attach browser-backed channel or component activity views without making runtime code depend on src/eegprep/eeglab.

Key code

def _apply_linked_scroll(self, source: Any, visited: set[int] | None = None) -> None:
    if visited is None:
        visited = {id(source)}
    visited.add(id(self))
    self._syncing_link = True
    try:
        self.model.state.time = source.model.state.time
        self.model.state.winlength = source.model.state.winlength
        self.model.state.channel_offset = source.model.state.channel_offset
        self._redraw_local()
    finally:
        self._syncing_link = False
    self._sync_linked_windows(visited)

Tests
Focused coverage exercises component mode labels, data2 drawing, linked parent/child/sibling sync, noui hiding, spectral frequency-axis rendering, eeg_multieegplot old/new epoched and continuous colors, sample_data component display, pop_subcomp(plotag=True), pop_prop activity attachment, pop_viewprops activity attachment, and package exports. Full local checks passed with Ruff, format check, ty, pre-commit, and EEGPREP_SKIP_MATLAB=1 pytest -m "not slow".

Visual evidence
Captured and compared the existing eegbrowser_continuous parity case with MATLAB R2026a and EEGPrep Qt. The side-by-side image is attached in a separate PR comment; report metrics were mean_abs_delta=0.039424 and different_pixel_ratio=0.101904.

@suraj-ranganath

suraj-ranganath commented Jun 1, 2026 •

Copy link
Copy Markdown
Member Author

🤖 Visual evidence

Attachments

EEGBrowser continuous visual parity

side_by_side.png
side_by_side.png

options.setdefault("xgrid", "off")
options.setdefault("ygrid", "off")
options.setdefault("data2", None)
options.setdefault("plotdata2", "off")

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

plotdata2 is added to _OPTION_NAMES (line 34) and given a default here, but its value is never read anywhere. The data2 overlay in EEGBrowserCanvas._draw_overlay_trace is rendered solely on the basis of flat_data2 is not None — passing plotdata2="on" or plotdata2="off" produces identical output.

EEGLAB's plotdata2 toggle controls whether data2 is rendered as a red overlay vs. acts as the primary trace. As-is the option is silently swallowed: users get no error and no behavior change, which is the worst of both worlds.

Either wire the value through to the canvas (e.g. an overlay_enabled flag on BrowserState) or drop "plotdata2" from _OPTION_NAMES and remove this default until the toggle is implemented.

"xgrid",
"ygrid",
"data2",
"plotdata2",
"command",
"command_callback",
"butlabel",
"winrej",
"wincolor",
"events",
"ploteventdur",
"submean",
"eloc_file",
"scale",
"color",
"freqs",
"freqlimits",
"component",

Comment on lines +140 to +147
def _plot_subcomp_confirmation(input_eeg: dict, output_eeg: dict) -> None:
icachansind = _icachansind(input_eeg)
preview = copy.deepcopy(input_eeg)
input_data = np.asarray(input_eeg["data"])
output_data = np.asarray(output_eeg["data"])
preview["data"] = np.array(input_data[icachansind], dtype=float, copy=True)
preview["nbchan"] = int(icachansind.size)
preview["chanlocs"] = _selected_chanlocs(input_eeg, icachansind)

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

copy.deepcopy(input_eeg) walks the entire EEG dict — including the full data array, which is the largest field in a typical recording (tens to hundreds of MB for multi-channel, multi-minute datasets). Two lines later preview["data"] = ... overwrites the copied array, so all of that work is thrown away on every plotag invocation.

Build the preview dict explicitly with only what eegplot actually reads (data, nbchan, chanlocs, plus event/srate/xmin/xmax/pnts/trials if you want eegplot's _default_* paths to find them) rather than deepcopying the full EEG.

def _plot_subcomp_confirmation(input_eeg: dict, output_eeg: dict) -> None:
icachansind = _icachansind(input_eeg)
preview = copy.deepcopy(input_eeg)
input_data = np.asarray(input_eeg["data"])
output_data = np.asarray(output_eeg["data"])
preview["data"] = np.array(input_data[icachansind], dtype=float, copy=True)
preview["nbchan"] = int(icachansind.size)
preview["chanlocs"] = _selected_chanlocs(input_eeg, icachansind)
eegplot(
preview,
srate=float(input_eeg.get("srate", 256) or 256),
title="Black = channel before rejection; red = after rejection -- eegplot()",
limits=[float(input_eeg.get("xmin", 0.0) or 0.0) * 1000.0, float(input_eeg.get("xmax", 0.0) or 0.0) * 1000.0],
data2=np.array(output_data[icachansind], dtype=float, copy=True),
)

Comment on lines +110 to +117
rows = []
new_rows = _continuous_rows(rej, n_channels, newcolor)
if new_rows.size:
rows.append(new_rows)
old_rows = _continuous_rows(oldrej, n_channels, oldcolor)
if old_rows.size:
rows.append(old_rows)
return np.vstack(rows) if rows else np.zeros((0, 5 + n_channels), dtype=float)

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: nit

The continuous path stacks rows as [new, old], but the epoched path right above stacks them as [old, new] (see _epoched_winrej). Where rejection rectangles overlap on screen, the later row paints over the earlier one — so the two modes produce opposite z-stacks.

EEGLAB's eeg_multieegplot.m consistently draws old marks first so new marks visually take precedence. Suggest mirroring the epoched order here so old marks sit below new ones in both modes.

Suggested change
rows = []
new_rows = _continuous_rows(rej, n_channels, newcolor)
if new_rows.size:
rows.append(new_rows)
old_rows = _continuous_rows(oldrej, n_channels, oldcolor)
if old_rows.size:
rows.append(old_rows)
return np.vstack(rows) if rows else np.zeros((0, 5 + n_channels), dtype=float)
def _continuous_winrej(
rej: Any,
oldrej: Any,
*,
n_channels: int,
oldcolor: tuple[float, float, float],
newcolor: tuple[float, float, float],
) -> np.ndarray:
rows = []
old_rows = _continuous_rows(oldrej, n_channels, oldcolor)
if old_rows.size:
rows.append(old_rows)
new_rows = _continuous_rows(rej, n_channels, newcolor)
if new_rows.size:
rows.append(new_rows)
return np.vstack(rows) if rows else np.zeros((0, 5 + n_channels), dtype=float)

The existing test_eeg_multieegplot_continuous_uses_old_and_new_colors will need to flip its expected order accordingly.

rows = []
old_rows = trial2eegplot(
_trial_marks(oldrej, trials),
_electrode_marks(oldrejE, n_channels, trials),
pnts,
oldcolor,
)
if old_rows.size:
rows.append(old_rows)
new_rows = trial2eegplot(
_trial_marks(rej, trials),
_electrode_marks(rejE, n_channels, trials),
pnts,
newcolor,
)
if new_rows.size:
rows.append(new_rows)
return np.vstack(rows) if rows else np.zeros((0, 5 + n_channels), dtype=float)
def _continuous_winrej(
rej: Any,
oldrej: Any,
*,
n_channels: int,
oldcolor: tuple[float, float, float],
newcolor: tuple[float, float, float],
) -> np.ndarray:
rows = []
new_rows = _continuous_rows(rej, n_channels, newcolor)
if new_rows.size:
rows.append(new_rows)
old_rows = _continuous_rows(oldrej, n_channels, oldcolor)
if old_rows.size:
rows.append(old_rows)
return np.vstack(rows) if rows else np.zeros((0, 5 + n_channels), dtype=float)

@suraj-ranganath
suraj-ranganath merged commit 4e3afb6 into feature/eegbrowser-completion Jun 1, 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