Skip to content

pop_precomp: Restore separate channel and component precomputation dialogs - #1037

Merged
arnodelorme merged 15 commits into
developfrom
agent/issue-973-precomp
Dec 1, 2026
Merged

arnodelorme merged 15 commits into
developfrom
agent/issue-973-precomp

Conversation

@arnodelorme

@arnodelorme arnodelorme commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

🤖 Part of #973 and #875. Restore separate channel and component precomputation dialogs. Stacked on #1027.

Live MATLAB, EEGPrep before and after

Component precomputation

Function output distances

Vertical control offsets

Native measurements and validation

On N400 the native channel and component windows are 458 and 405 px high in both applications. Maximum functional-control offsets are 0.515 and 0.604 px respectively. Qt paints the ERSP/ITC connector as one decoration, corresponding to four blank MATLAB buttons, excluded from functional-control distances. True Qt ERP submissions on sample recordings agree with the EEGLAB std_erp backend across every channel or component and every time point, with worst relative differences 3.54e-7 and 2.31e-7. Twenty-six tests passed. EEGPrep stores these results in memory, as indicated by its overwrite label. The ERP-image computation and separate parameter/test launchers remain unavailable in EEGPrep.

Full inventory report for the project team. pop_precomp (p. 54). PDF · Editable Word.

EEGLAB reference run (December 1, 2026)

Workflow EEGLAB reference (.github/workflows/eeglab-reference.yml, real MATLAB backend) on commit c920cf81 of the branch of #1041, which contains this pull request's final commit 9c99e0b8: https://github.com/sccn/eegprep/actions/runs/46605236026
EEGLAB d0963be9, eeglab_tests fec88f9f. Runtime 1 hour 16 minutes, most of it waiting in the queue.

Shard Passed Failed Skipped Time
core 3454 2 (and 2 teardown errors) 17 23 min 22 s
study 341 0 27 17 min 05 s
misc 683 0 8 7 min 21 s
stats 257 0 0 1 min 34 s
parity 10 0 2 22 min 27 s
hybrid 143 0 4 38 s
heavy 3 0 0 7 min 11 s

The two failures are on develop and not from this pull request: tests/test_stream11_datasets.py::test_f42_merge_opens_newset_and_cancel_preserves_datasets, failing since #904 gave the pop_mergeset dialog an empty title.

What changes in std_precomp. 'ntimesout' is now passed to newtimef (it was ignored, so the dialog's 200 time points became 80), and component scalp maps can be precomputed without another measure, as in EEGLAB.

@claude claude Bot left a comment

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.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@claude

claude Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @arnodelorme's task in 1m 35s —— View job


Code review

  • Overall assessment: Needs changes. The channel and component dialogs now follow EEGLAB's pop_precomp.m closely: same controls, geometry and defaults (ERP and spectrum start unchecked; ERSP fields are disabled until their box is ticked); 'ntimesout' replaces 'timesout'; and the cluster listbox has real cluster names. However, the ITC checkbox does not enable the parameter field it shares with ERSPs.
  • Highest-risk area: How the ERSP/ITC rows enable their shared parameter field (pop_precomp.py).
  • Merge recommendation: Needs changes.

Blocking

None.

Important

  • Ticking only the ITC checkbox leaves the ERSP/ITC parameter field disabled (pop_precomp.py L135, itc_on).
    • In EEGLAB, setitc and setersp share one handler, and it enables ersp_params when either box is checked (pop_precomp.m L307-L325).
    • Here only ersp_on toggles the field. A user who ticks only ITCs can't edit the parameters, yet they are still sent as erspparams.
    • Fix: base the enable state on ersp_on OR itc_on, for example with a multi-source toggle_enabled.

Nits

  • Dead GUI-mode code (pop_precomp.py L36-L37 and L207-L208). The mode control is gone, so the "mode" in result branch and _kind_from_gui can never run. Remove both, per AGENTS.md: "Remove … functions … that your change made unused."
  • Dead allcomps_on fallback (pop_precomp.py L192). The fallback points to a control this PR removed. Simplify to "off" if is_on(result.get("component_rv_on", True)) else "on", which matches EEGLAB's compallersp default of 1.
  • Unused vertexpand option (spec.py L72, supergui.py L45 and L171-L172, qt.py L394). Nothing sets vertexpand, so it is speculative configurability. Keep only vertshift until a dialog needs it.

Test gaps

  • Add a GUI test that ticks only itc_on and asserts that ersp_params becomes enabled. It would catch the parity issue above.

EEGLAB parity notes

  • The link2lines geometry (posx - width/2, about 1.45 rows) and the vertshift offset (-height/2) match the supergui.m logic at L264-L304.
  • Out of scope for this PR: _options_from_gui still ignores interpolate_on, rmica1_on and rmica2_on/rmica2_val. EEGLAB maps these to 'interp', 'rmicacomps' and 'rmclust', so for channel precompute these checkboxes have no effect. This was already true before this PR, and the PR text already lists this dialog's other unsupported controls. It is worth a follow-up issue.

Checked for correctness bugs, EEGLAB parity against pop_precomp.m and supergui.m, data structure compatibility, tests for the changed behaviour, and CLAUDE.md/AGENTS.md compliance.

),
ControlSpec("pushbutton", "...", tag="ersp_button", vertshift=True, enabled=False),
ControlSpec("pushbutton", "Test", tag="ersp_test", vertshift=True, enabled=False),
ControlSpec("checkbox", "", tag="itc_on", value=False),

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.

Important (EEGLAB parity / UX): itc_on has no callback, so the ERSP/ITC parameter field can only be enabled from ersp_on. If a user ticks ITCs but not ERSPs, ersp_params stays disabled. They can't edit the time-frequency parameters, yet _options_from_gui still sends them as erspparams.

In EEGLAB, both checkboxes run the same setitc/setersp handler, and it enables ersp_params when either box is checked (pop_precomp.m L307-L325: if (~set_ersp && ~set_itc) ... 'enable','off' else ... 'enable','on'). The connector this PR draws between the two rows presents them as sharing one field, so the UI currently contradicts itself.

Suggested fix: make the enable state depend on ersp_on OR itc_on. You could add a small multi-source variant of toggle_enabled in qt.py (for example "sources": [...]), or wire both checkboxes to one handler. Also add a test that ticks only itc_on and checks that ersp_params is enabled.

Comment on lines +36 to +37
if "mode" in result:
chanorcomp = _kind_from_gui(result)

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.

Nit (AGENTS.md): The dialog no longer has a mode control, so result can never contain "mode". This branch and _kind_from_gui (L207-L208) are now dead code. AGENTS.md says to "Remove imports, variables, functions, and files that your change made unused."

Fix: delete these two lines and the _kind_from_gui helper; chanorcomp stays as the caller passed it.

"itc": "on" if is_on(result.get("itc_on")) else "off",
"scalp": "on" if is_on(result.get("scalp_on")) else "off",
"allcomps": "on" if is_on(result.get("allcomps_on")) else "off",
"allcomps": "off" if is_on(result.get("component_rv_on", not is_on(result.get("allcomps_on")))) else "on",

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.

Nit: The PR removes the allcomps_on control, so the allcomps_on fallback here is dead. The nested default also makes this line hard to read. EEGLAB's logic is just "if compallersp is missing, treat it as 1" (pop_precomp.m: if ~isfield(os, 'compallersp'), os.compallersp = 1; end ... if os.compallersp == 0, 'allcomps' 'on').

Suggested change
"allcomps": "off" if is_on(result.get("component_rv_on", not is_on(result.get("allcomps_on")))) else "on",
"allcomps": "off" if is_on(result.get("component_rv_on", True)) else "on",

Comment thread src/eegprep/functions/guifunc/spec.py Outdated
# supergui.m then leaves the control out of the figure width (layout="supergui").
fit_width: bool = True
vertshift: bool = False
vertexpand: float = 1.0

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.

Nit (AGENTS.md: "No speculative configurability"): No control in the repo sets vertexpand; only vertshift is used, by pop_precomp. The field is threaded through ControlSpec, SuperguiControl, qt.measured and supergui_layout with no caller and no test.

Suggestion: drop vertexpand until a dialog needs it. supergui_layout then reduces to posy - (0.5 * height if control.vertshift else 0), with height unchanged.

@arnodelorme arnodelorme left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This review was written by an AI assistant during a nightly check, not by Arno.

Code review

  • Overall assessment: Needs changes. Two regressions arise where the updated dialog defaults meet std_precomp.
  • Highest-risk area: Forwarding dialog measure selections and ersp_params from pop_precomp into std_precomp.
  • Merge recommendation: Needs changes.

Blocking

None.

Important

  1. Changing default ersp_params from 'timesout' to 'ntimesout' silently drops the requested 200 time points (pop_precomp.py, std_precomp.py).

    • Why it matters: pop_precomp_dialog_spec now sets ersp_params to "'cycles', [3 0.8], 'nfreqs', 100, 'ntimesout', 200" to match EEGLAB pop_precomp.m line 68. However, std_precomp._newtimef only passes timesout=params.get("timesout", 80) and never passes ntimesout to newtimef. As a result, checking ERSPs or ITCs in the dialog now ignores 'ntimesout', 200 (as well as any user edit to 'ntimesout') and computes 80 output time points instead of 200.
    • Suggested fix: Pass ntimesout=params.get("ntimesout") alongside timesout=params.get("timesout", 80) in std_precomp._newtimef. newtimef._effective_timesout (newtimef.py) already applies EEGLAB's precedence rules (vector timesout over ntimesout, and ntimesout over scalar timesout=80).
  2. Selecting only Scalp maps in the component dialog raises ValueError (pop_precomp.py, pop_precomp.py, std_precomp.py).

    • Why it matters: Because erp_on and spectra_on now start unchecked (value=False), ticking only Scalp maps (scalp_on=True) in the restored component dialog calls std_precomp(..., "components", erp="off", spec="off", ersp="off", itc="off", scalp="on"), which fails with ValueError: std_precomp requires at least one measure enabled because _selected_measures only checks ("erp", "spec", "ersp", "itc"). In EEGLAB (pop_precomp.m lines 239 to 241 and std_precomp.m lines 496 to 524), precomputing component scalp maps alone is valid, and _precompute_components (std_precomp.py) already computes cluster["topo"] when scalp=True.
    • Suggested fix: In std_precomp, treat kind == "components" and is_on(scalp) as an enabled measure so component scalp topographies can be precomputed on their own.

Nits

  1. Disabled parameter boxes are still parsed and emitted into history (pop_precomp.py).
    • Why it matters: erp_params, spec_params, and ersp_params now start disabled (enabled=False) until their measure checkbox is ticked, but _options_from_gui always parses all three text fields. Submitting with only ERPs checked still emits specparams and erspparams in the history command, and an invalid edit in a box that the user subsequently unchecked and disabled will still raise a parse error on submission. EEGLAB pop_precomp.m lines 229 to 274 only parses parameter strings for checked measures.
    • Suggested fix: Only parse and attach erpparams when is_on(result.get("erp_on")), specparams when is_on(result.get("spectra_on")), and erspparams when is_on(result.get("ersp_on")) or is_on(result.get("itc_on")).

Test gaps

  • Add a test in tests/test_study_measures.py submitting pop_precomp in GUI mode with ersp_on=True and the default ersp_params string ('ntimesout', 200 on an epoch long enough for 200 frames, or a distinct 'ntimesout', 12) and asserting len(study["changrp"][0]["ersptimes"]) matches ntimesout rather than falling back to 80.
  • Add a test in tests/test_study_measures.py submitting pop_precomp(study, datasets, "components", gui=True, ...) with only scalp_on=True and asserting study["cluster"][0]["topo"] is populated.

EEGLAB parity notes

  • supergui_layout (link2lines and vertshift), _LinkedRows, and multi-source toggle_enabled match supergui.m lines 264 to 301 and pop_precomp.m lines 308 to 325.
  • Pre-existing and out of scope for this PR: channel controls interpolate_on, rmica1_on, and rmica2_on/rmica2_val remain display-only in _options_from_gui (std_precomp currently ignores interp, rmicacomps, and rmclust).

Tests run

Ran on detached worktree at commit 940d30e28f621a6c8844623b10153f187f1066b6 (note: b641193704bca016de157b5f289011ee6057b3c8 merged stacked PR #1036 without modifying pop_precomp.py or std_precomp.py):

  • PYTHONPATH=<worktree>/src .venv/bin/python -m pytest <worktree>/tests/test_study_measures.py: 10 passed in 11.91s.
  • PYTHONPATH=<worktree>/src .venv/bin/python -m pytest <worktree>/tests/test_gui_geometry.py <worktree>/tests/test_guifunc_primitives.py <worktree>/tests/test_gui_pop_study.py: 178 passed, 67 skipped (Linux MATLAB reference geometry), 1 deselected in 12.44s.

@arnodelorme
arnodelorme changed the base branch from agent/issue-968-studydesign to develop December 1, 2026 08:19

@arnodelorme arnodelorme left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This review was written by an AI assistant during a nightly check, not by Arno.

Code review

  • Overall assessment: Looks good.
  • Highest-risk area: Forwarding dialog measure options from pop_precomp to std_precomp and STUDY.changrp channel row mapping in pop_chanplot.
  • Merge recommendation: Safe to merge.

Blocking

None.

Important

None.

Nits

None.

Test gaps

None.

EEGLAB parity notes

  • Verified separate channel and component dialog controls, supergui geometry and geomvert, link2lines and vertshift placement, shared ERSP and ITC parameter enablement, ntimesout forwarding to newtimef, component scalp precomputation, ignoring unchecked parameter boxes, and pop_chanplot channel row and subject list behavior against functions/studyfunc/pop_precomp.m, functions/studyfunc/pop_chanplot.m, and functions/guifunc/supergui.m.
  • Unchanged and out of scope for this PR: channel controls interpolate_on, rmica1_on, and rmica2_on (rmica2_val) remain display only in pop_precomp while std_precomp ignores interp, rmicacomps, and rmclust.

Checked for correctness bugs, EEGLAB parity, data structure compatibility, tests for changed behavior, and CLAUDE.md/AGENTS.md compliance at commit 9c99e0b8571fcecc103321f41e25a9d74a8b1a8a.

Tests run

Ran in a detached worktree at 9c99e0b8571fcecc103321f41e25a9d74a8b1a8a:

  • PYTHONPATH=<worktree>/src .venv/bin/python -m pytest <worktree>/tests/test_study_measures.py <worktree>/tests/test_study_end_to_end.py <worktree>/tests/test_gui_pop_study.py <worktree>/tests/test_guifunc_primitives.py <worktree>/tests/test_gui_geometry.py: 203 passed, 70 skipped (Linux MATLAB reference geometry), 1 deselected in 14.20s.
  • .venv/bin/ruff check and .venv/bin/ruff format --check on changed files: passed.
  • .venv/bin/ty check on changed modules: passed.

@arnodelorme

Copy link
Copy Markdown
Collaborator Author

🤖 The third review finds no blocking or important problem (commit 9c99e0b8), and this pull request now waits for the EEGLAB reference run before it is merged.

@arnodelorme
arnodelorme merged commit 47eea62 into develop Dec 1, 2026
3 checks passed
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