Skip to content

Phase 8: ICLabel extended properties dashboard - #109

Merged
suraj-ranganath merged 6 commits into
feature/eegbrowser-completionfrom
phase/eegbrowser-8-iclabel-dashboard
Jun 1, 2026
Merged

suraj-ranganath merged 6 commits into
feature/eegbrowser-completionfrom
phase/eegbrowser-8-iclabel-dashboard

Conversation

@suraj-ranganath

@suraj-ranganath suraj-ranganath commented Jun 1, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add EEGPrep-owned pop_prop_extended for the ICLabel/viewprops extended component-property dashboard
  • route pop_viewprops component mode to the extended dashboard when usable classifier data are present, while preserving lightweight fallback without classifier data
  • add EEGLAB-style component ACCEPT/REJECT, Cancel, Values, HELP, and OK controls that commit selected dashboard marks to EEG.reject.gcompreject and persist GUI-launched viewprops updates back to the shared session
  • render localized DIPFIT component models in the dashboard with native three-view standard-MNI MRI slices, dipole moments, RV/DMR metadata, and EEGPrep-packaged resources only
  • align inline activity events with EEGLAB scrollplot 1-based sample coordinates for continuous and epoched data, including visible epoch boundaries
  • add packaged help/docs, dashboard visual parity capture case, and focused unit/GUI coverage

Closes #108

Verification

  • QT_QPA_PLATFORM=offscreen uv run --no-sync pytest tests/test_gui_pop_prop_extended.py tests/test_pop_prop_extended.py tests/test_gui_rejection_dialogs.py tests/test_rejection_workflows.py
  • QT_QPA_PLATFORM=offscreen uv run --no-sync pytest tests/test_visual_parity.py
  • uv run --no-sync ruff check .
  • uv run --no-sync ruff format --check .
  • uv run --no-sync ty check
  • ./pre-commit.py
  • QT_QPA_PLATFORM=offscreen EEGPREP_SKIP_MATLAB=1 uv run --no-sync pytest -m "not slow"

Visual Evidence

  • Captured EEGPrep for iclabel_pop_prop_extended_dashboard with QT_QPA_PLATFORM=offscreen uv run --no-sync python tools/visual_parity/capture.py --case iclabel_pop_prop_extended_dashboard --target eegprep --timeout 60.
  • Captured EEGLAB with full local EEGLAB/DIPFIT assets using EEGPREP_EEGLAB_ROOT=/Users/suraj/Desktop/eeglab uv run --no-sync python tools/visual_parity/capture.py --case iclabel_pop_prop_extended_dashboard --target eeglab --timeout 180.
  • Generated comparison with uv run --no-sync python tools/visual_parity/compare.py --case iclabel_pop_prop_extended_dashboard (mean_abs_delta=0.146510, different_pixel_ratio=0.450519).
  • Updated images are attached in Phase 8: ICLabel extended properties dashboard #109 (comment); artifacts are not committed.

Accepted Deviations

  • EEGPrep uses a single navigable dashboard for multiple selected components instead of recursively opening one MATLAB figure per component. Pending rejection state is preserved per selected 1-based component across navigation and committed together with OK.
  • EEGPrep packages a converted standard-MNI MRI NPZ for dashboard visualization instead of reading EEGLAB/DIPFIT .mat assets at runtime; this preserves standalone EEGPrep behavior while matching the MRI-slice DIPFIT dashboard surface and metadata.

@claude

claude Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

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


Code review

  • Overall assessment: Needs minor changes. Implementation is clean and well-tested, but the event-marker mapping inside the dashboard has a real correctness gap for epoched data, plus a couple of small style/maintainability issues.
  • Highest-risk area: Event display logic in _plot_event_markers and the indirect EEG lookup via figure attribute.
  • Merge recommendation: Safe to merge after acknowledging the event-marker limitation (or applying a small fix); other items are nits.

Blocking

None.

Important

  • _plot_event_markers mis-maps event latencies on epoched data — pop_prop_extended.py:670-678 does sample = int(round(latency)) - 1 and then dashboard.times_ms[sample], treating EEG.event[].latency as a sample index into a single-epoch times_ms (length pnts). EEGLAB stores event.latency as a continuous-stream sample index, so for epoched data any event with latency > pnts is silently dropped, and events that happen to fall in [0, pnts) but belong to a later epoch get drawn at the wrong time. The activity-image panel and property_activity_browser (which forwards events to eegplot) handle this correctly, so the dashboard's "scrolling" panel is the only place this regression appears. Two reasonable fixes: (a) iterate EEG.epoch[trial].event and use per-epoch event arrays, or (b) skip the static event overlay entirely on epoched data and rely on the browser-backed view. At minimum, gate the loop with if data.shape[2] > 1: return so epoched data doesn't render misleading markers.

Nits

  • Dead defensive check + indirect EEG access — pop_prop_extended.py:658-662 reaches events via axis.figure.eegprep_dashboard_state["EEG"] and guards with hasattr(axis.figure, "eegprep_dashboard_state"). _plot_event_markers is only called from _plot_activity, which is only called from _render_dashboard, which always sets figure.eegprep_dashboard_state before plotting. Per AGENTS.md ("Don't add error handling, fallbacks, or validation for scenarios that can't happen"), drop the hasattr branch and pass events (and times_ms) as explicit arguments. This also removes the hidden coupling between _plot_activity and the figure's eegprep_dashboard_state attribute.

  • Redundant nan filtering in spectrum y-limits — pop_prop_extended.py:485-489 already masks with finite = np.isfinite(...), so np.nanmin/nanmax over the already-filtered slice is redundant — np.min/np.max would do, and the additional branch handles equal min/max (which produces a matplotlib warning today). Trivial.

Test gaps

  • The new case-insensitive matching in classifier_name_from_gui (pop_prop_extended.py:206-222) replaces the previous case-sensitive value in classifiers behavior used by pop_viewprops. No test exercises a string popup value with a non-canonical case (e.g., "iclabel" vs "ICLabel"). Consider one assertion in test_pop_prop_extended.py confirming that classifier_name_from_gui(EEG, "iclabel") resolves to "ICLabel", so future regressions in either direction are caught.

EEGLAB parity notes

  • The known_differences text on the dialog spec (pop_prop_extended.py:180-184) is accurate: EEGPrep collapses N components into one navigable dashboard rather than spawning N MATLAB figures. The "Accepted Deviations" in the PR description also calls out DIPFIT three-view and rejection button propagation. Worth noting in the dashboard's pop_prop_extended.md help text that the scroll-event overlay is only meaningful for continuous data until the epoched mapping is fixed.

Review checklist
  • Pre-review gate
  • Find repository instructions
  • Read changed files and analyze PR
  • Run review (correctness, EEGLAB parity, conventions, AGENTS.md compliance, tests)
  • Validate findings against source
  • Post review summary + inline comments
· [Branch](https://github.com/sccn/eegprep/tree/phase/eegbrowser-8-iclabel-dashboard)

@suraj-ranganath

suraj-ranganath commented Jun 1, 2026 •

Copy link
Copy Markdown
Member Author

🤖 ICLabel dashboard visual parity

side_by_side.png eeglab.png
side_by_side.png eeglab.png
eegprep.png
eegprep.png

Comment on lines +650 to +679
def _plot_event_markers(
axis: Any,
x_values: np.ndarray,
dashboard: ExtendedPropertyData,
scroll_event: bool,
) -> None:
if not scroll_event:
return
events = (
(axis.figure.eegprep_dashboard_state["EEG"].get("event") or [])
if hasattr(axis.figure, "eegprep_dashboard_state")
else []
)
if not events:
return
first = float(np.nanmin(x_values))
last = float(np.nanmax(x_values))
for event in events:
if not isinstance(event, dict):
continue
try:
sample = int(round(float(event.get("latency", 1)))) - 1
except (TypeError, ValueError):
continue
if sample < 0 or sample >= dashboard.times_ms.size:
continue
x_value = float(dashboard.times_ms[sample])
if first <= x_value <= last:
axis.axvline(x_value, color="red", linestyle="--", linewidth=0.75)
axis.text(x_value, 0.98, str(event.get("type", "")), transform=axis.get_xaxis_transform(), rotation=45)

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 — Event-marker mapping is incorrect for epoched data.

event["latency"] in EEGLAB is the continuous-stream sample index (1-based across the whole recording), but this loop treats it as an index into the single-epoch dashboard.times_ms (length pnts). For epoched datasets:

  • events whose latency > pnts are silently dropped (sample >= times_ms.size), and
  • events that happen to fall in [1, pnts] but actually belong to a later epoch are drawn at the wrong time.

property_activity_browser forwards events to eegplot, which handles this correctly, so the dashboard's static activity panel is the only place this regresses.

Two reasonable fixes:

  1. Walk EEG.epoch[trial].event (per-trial event indices) and only draw markers for the currently displayed trial.
  2. Skip the static overlay on epoched data and rely on the browser-backed view:
Suggested change
def _plot_event_markers(
axis: Any,
x_values: np.ndarray,
dashboard: ExtendedPropertyData,
scroll_event: bool,
) -> None:
if not scroll_event:
return
events = (
(axis.figure.eegprep_dashboard_state["EEG"].get("event") or [])
if hasattr(axis.figure, "eegprep_dashboard_state")
else []
)
if not events:
return
first = float(np.nanmin(x_values))
last = float(np.nanmax(x_values))
for event in events:
if not isinstance(event, dict):
continue
try:
sample = int(round(float(event.get("latency", 1)))) - 1
except (TypeError, ValueError):
continue
if sample < 0 or sample >= dashboard.times_ms.size:
continue
x_value = float(dashboard.times_ms[sample])
if first <= x_value <= last:
axis.axvline(x_value, color="red", linestyle="--", linewidth=0.75)
axis.text(x_value, 0.98, str(event.get("type", "")), transform=axis.get_xaxis_transform(), rotation=45)
def _plot_event_markers(
axis: Any,
x_values: np.ndarray,
dashboard: ExtendedPropertyData,
scroll_event: bool,
) -> None:
if not scroll_event or dashboard.activity.shape[2] > 1:
return
events = (
(axis.figure.eegprep_dashboard_state["EEG"].get("event") or [])
if hasattr(axis.figure, "eegprep_dashboard_state")
else []
)
if not events:
return
first = float(np.nanmin(x_values))
last = float(np.nanmax(x_values))
for event in events:
if not isinstance(event, dict):
continue
try:
sample = int(round(float(event.get("latency", 1)))) - 1
except (TypeError, ValueError):
continue
if sample < 0 or sample >= dashboard.times_ms.size:
continue
x_value = float(dashboard.times_ms[sample])
if first <= x_value <= last:
axis.axvline(x_value, color="red", linestyle="--", linewidth=0.75)
axis.text(x_value, 0.98, str(event.get("type", "")), transform=axis.get_xaxis_transform(), rotation=45)

The above is the minimal-risk change (gate on trials > 1); a per-epoch implementation would be richer but requires walking EEG.epoch and is a larger change.

Ref:

def _plot_event_markers(
axis: Any,
x_values: np.ndarray,
dashboard: ExtendedPropertyData,
scroll_event: bool,
) -> None:
if not scroll_event:
return
events = (
(axis.figure.eegprep_dashboard_state["EEG"].get("event") or [])
if hasattr(axis.figure, "eegprep_dashboard_state")
else []
)
if not events:
return
first = float(np.nanmin(x_values))
last = float(np.nanmax(x_values))
for event in events:
if not isinstance(event, dict):
continue
try:
sample = int(round(float(event.get("latency", 1)))) - 1
except (TypeError, ValueError):
continue
if sample < 0 or sample >= dashboard.times_ms.size:
continue
x_value = float(dashboard.times_ms[sample])
if first <= x_value <= last:
axis.axvline(x_value, color="red", linestyle="--", linewidth=0.75)
axis.text(x_value, 0.98, str(event.get("type", "")), transform=axis.get_xaxis_transform(), rotation=45)

Comment on lines +485 to +489
finite = np.isfinite(dashboard.spectrum_power)
if np.any(finite):
axis.set_ylim(
float(np.nanmin(dashboard.spectrum_power[finite])), float(np.nanmax(dashboard.spectrum_power[finite]))
)

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 — Redundant nan-handling and degenerate ylim.

finite already masks out NaN/inf, so dashboard.spectrum_power[finite] is finite by construction — np.min/np.max are sufficient. Also, when the spectrum is constant (e.g., all zeros for a flat trace), set_ylim(v, v) emits a UserWarning and yields a degenerate axis. A small padding (or letting matplotlib autoscale) avoids both:

Suggested change
finite = np.isfinite(dashboard.spectrum_power)
if np.any(finite):
axis.set_ylim(
float(np.nanmin(dashboard.spectrum_power[finite])), float(np.nanmax(dashboard.spectrum_power[finite]))
)
finite = np.isfinite(dashboard.spectrum_power)
if np.any(finite):
finite_values = dashboard.spectrum_power[finite]
low = float(np.min(finite_values))
high = float(np.max(finite_values))
if high == low:
high = low + 1.0
axis.set_ylim(low, high)

Ref:

finite = np.isfinite(dashboard.spectrum_power)
if np.any(finite):
axis.set_ylim(
float(np.nanmin(dashboard.spectrum_power[finite])), float(np.nanmax(dashboard.spectrum_power[finite]))
)

@suraj-ranganath

suraj-ranganath commented Jun 1, 2026 •

Copy link
Copy Markdown
Member Author

Attachments

🤖 Updated ICLabel dashboard visual parity (DIPFIT/events)

side_by_side.png eeglab.png
side_by_side.png eeglab.png
eegprep.png
eegprep.png

🤖 Updated ICLabel DIPFIT MRI-slice parity

side_by_side.png eeglab.png
side_by_side.png eeglab.png
eegprep.png
eegprep.png

🤖 Updated ICLabel dashboard rejection controls parity

side_by_side.png eeglab.png
side_by_side.png eeglab.png
eegprep.png
eegprep.png

@suraj-ranganath

Copy link
Copy Markdown
Member Author

@claude review this

@claude

claude Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 3m 34s —— View job


Code review

  • Overall assessment: Looks good — ready to merge. This is the follow-up pass after my earlier review on 8875bbc, and the four most recent commits (ced4a0b, 165b8b9, 5dcc9fa, 062f7e3) cleanly address every prior finding plus the test gap. New surface area (rejection controls + DIPFIT MRI slices) is well-scoped and well-tested.
  • Highest-risk area: nothing remaining. Static event marker mapping for epoched data is now correct; DIPFIT MRI slicing now lives in a small, packaged module with explicit tests.
  • Merge recommendation: ship it.

Prior findings — all addressed

  • Epoched event mapping (was Important) — _plot_event_markers now consumes ActivityTraceData whose x_values are 1-based EEGLAB-flattened sample coordinates (pop_prop_extended.py:1085-1109), and events use the same coordinate space (pop_prop_extended.py:1112-1142). test_gui_dashboard_epoched_static_events_use_flattened_event_latencies (tests/test_gui_pop_prop_extended.py:187-213) asserts markers at samples 25 and 125 across two 100-sample epochs, which is exactly the EEGLAB convention. Epoch boundaries are also rendered via _plot_epoch_markers (pop_prop_extended.py:1145-1163). Help text in src/eegprep/resources/help/pop_prop_extended.md calls this out.
  • Dead hasattr + indirect EEG access (was Nit) — gone. Events flow _render_dashboard → _plot_activity(axis, dashboard, events) → _plot_event_markers(axis, trace, events); no axis.figure.eegprep_dashboard_state indirection (pop_prop_extended.py:521-522, 605-615, 1112).
  • Spectrum y-lim degenerate axis (was Nit) — fixed. _plot_spectrum masks with finite, uses np.min/np.max over the filtered slice, and pads when low == high so matplotlib no longer emits the UserWarning (pop_prop_extended.py:633-648).
  • Case-insensitive classifier match (was Test gap) — covered by test_classifier_name_from_gui_matches_string_values_case_insensitively (tests/test_pop_prop_extended.py:74-78), which exercises both "iclabel" and "OTHER".

New surface area — looks correct

  • Rejection controls (_add_rejection_controls, _commit_rejection_state in pop_prop_extended.py:758-880) keep all pending marks in state["rejection_pending"] keyed by 1-based component index. Cancel discards (verified by test_gui_dashboard_rejection_cancel_discards_pending_flags), OK commits via set_component_rejection_flag and fires the optional reject_callback(EEG, states) exactly once (verified by test_gui_dashboard_rejection_commit_updates_callback_and_origin_button). Navigation preserves pending state across components (verified by test_gui_dashboard_rejection_controls_commit_selected_component_flags). The session integration in MenuActionDispatcher._run_pop_function (menu_actions.py:1122-1148) stores the updated EEG and re-renders the workspace without duplicating the history line — and the unit test test_viewprops_reject_callback_stores_dashboard_component_marks (tests/test_gui_rejection_dialogs.py:199-219) pins that contract.
  • DIPFIT three-view MRI dashboard — plugins/dipfit/_mri.py is small (133 lines), uses lru_cache to load the packaged standard_mri_mni.npz once, returns immutable dataclasses, and clips voxel indices to anatomy shape. Tests in tests/test_dipfit_workflows.py:61-73 pin the canonical slice indices (87, 108, 109) for [0, -20, 40] and the expected slice shapes/extent — that's a real EEGLAB-parity oracle, not a tautology. The packaged NPZ is explicitly documented as conversion-of-source in resources/dipfit/standard_BEM/README.md, license preserved next to it. Good way to keep the runtime EEGLAB-checkout-independent per AGENTS.md.
  • pop_viewprops redirect — component mode now opens pop_prop_extended when has_component_classifier(EEG, classifier_name) is true and otherwise falls back to the lightweight thumbnail + activity-browser path (pop_viewprops.py:122-150). test_missing_classifier_falls_back_to_lightweight_viewprops_display confirms the fallback path and that eegprep_dashboard_data is absent.

Nits (non-blocking, optional)

  • _event_items in pop_prop_extended.py:1180-1206 quietly returns [events] for a dict that has no latency key, but _plot_event_markers then skips that entry because of the if "latency" not in event guard. Functionally correct, but the special case is a bit surprising — a comment or a stricter shape check would help future readers.
  • _set_window_title (pop_prop_extended.py:1332-1336) and other figure expandos (figure.eegprep_dashboard_state, figure.eegprep_activity_view) are an established pattern in this repo, but they make the figure object effectively a typed bag. Not worth refactoring here; flagging only for future GUI consolidation.

EEGLAB parity notes

  • pop_prop_extended_dialog_spec carries the right EEGLAB anchors (function_name, eeglab_source = plugins/ICLabel/viewprops/pop_prop_extended.m, help_text = pophelp('pop_prop_extended')) and a known_differences entry explaining the single-dashboard-vs-many-figures choice (pop_prop_extended.py:224-236). Help markdown explains the deviation for end users.
  • Static activity panel is now consistent with EEGLAB scrollplot 1-based sample coordinates for both continuous and epoched data — the inline trace, event overlay, and epoch boundaries all live in the same coordinate space. Browser-backed view still uses property_activity_browser, so both surfaces stay in sync.

Risk-adjusted summary

The PR is large (2259 / -54), but the bulk is well-factored: one new dashboard module, one small MRI helper, packaged resources, focused tests, and tightly scoped GUI wiring in menu_actions.py. Tests cover the navigation, rejection commit, cancel-discard, callback, classifier resolution, DIPFIT data shape/values, and visual-parity case. Approving the substance — no blocking changes requested.


  • Pre-review gate
  • Find repository instructions
  • Read changed files and analyze PR
  • Verify prior review feedback was addressed
  • Validate new surface area (rejection controls, DIPFIT MRI)
  • Post review summary
    · Branch

@suraj-ranganath
suraj-ranganath merged commit a356207 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