Repository navigation
Show component properties and the remaining DIPFIT dialogs - #591
Conversation
Make ICLabel, extended properties, and DIPFIT usable from the menus: install PyTorch with the GUI, replay flag history, show the property windows, and store the four-shell BESA volume the spherical fitter can use. Co-authored-by: Suraj Ranganath <[email protected]>
There was a problem hiding this comment.
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 finished @suraj-ranganath's task in 2m 31s —— View job Code review
BlockingNone. Important
Nits
Test gapsNone beyond the test placement above. Behavior tests already cover: F55 replay through EEGLAB parity notes
I checked correctness, EEGLAB parity, EEG dict handling, changed-behavior tests, and CLAUDE.md/AGENTS.md compliance. I posted three inline comments, one for each nit. |
| if kind == "besa" and _shell_radii(dipfit.get("vol")).size == 0: | ||
| dipfit["vol"] = besa_four_shell_volume() |
There was a problem hiding this comment.
Nit: this changes the caller's EEG in place. dipfit_record returns the caller's own EEG["dipfit"] dict, so this line edits it directly. pop_dipfit_gridsearch, pop_dipfit_nonlinear, pop_multifit and pop_dipfit_loreta all call ensure_dipfit_settings on the input EEG before copy_eeg. Example: a dataset whose settings name standard_BESA.mat but have no vol (any dataset configured before this PR, since apply_template only now stores vol). Running a coarse fit on it in eegprep-console adds EEG.dipfit.vol to the user's workspace EEG, and no history entry records the change.
Suggested fix: keep ensure_dipfit_settings as a pure check, and fill in the BESA vol on the copy inside the fitting path. Alternatively, call ensure_dipfit_settings only after copy_eeg in the callers. AGENTS.md asks for "explicit inputs and return values".
There was a problem hiding this comment.
🤖 ensure_dipfit_settings no longer writes vol. dipfit_gridsearch, dipfit_nonlinear, and pop_leadfield copy the dataset first and call fill_missing_besa_volume on that copy. test_besa_fit_stores_a_missing_volume_on_the_result_only checks that a coarse fit and a missing-leadfield LORETA call leave the input without vol, and that the fit result stores radii 71, 72, 79, and 85 mm.
| def _require_ica(EEG, feature: str) -> None: | ||
| weights = np.asarray(EEG.get("icaweights", [])) if isinstance(EEG, dict) else np.asarray([]) | ||
| if getattr(weights, "ndim", 0) != 2 or weights.size == 0: | ||
| raise ValueError(f"{feature} needs an ICA decomposition in EEG.icaweights. Run pop_runica first.") |
There was a problem hiding this comment.
Nit: this duplicates an existing helper. pop_iclabel.py:72 already defines _require_ica with the same purpose and the same "Run pop_runica first" message. This PR adds two more variants nearby: an inline check in pop_icflag._require_iclabel and pop_viewprops._has_ica_weights. That makes three slightly different rules for "has ICA" in one plugin: ndim == 2, len(w[0]) > 0, and size > 0.
AGENTS.md lists "Parallel implementations of existing helpers" as a failure pattern. Suggested fix: move one require_ica(EEG, caller) helper into the ICLabel plugin (for example _prop_numerics.py) and call it from iclabel, pop_iclabel, pop_icflag and pop_viewprops.
There was a problem hiding this comment.
🤖 require_ica_weights in _prop_numerics.py is now the only check: EEG.icaweights must be a non-empty 2-D matrix. iclabel, pop_iclabel, pop_icflag, and pop_viewprops call it. pop_icflag still checks that the classification row count matches that matrix.
| if not typecomp: | ||
| has_component_classifier(EEG, classifier_name) |
There was a problem hiding this comment.
Nit: the return value is thrown away. This call runs only so that resolve_classifier_data raises when the rows don't match. A reader will see a discarded boolean and could delete the line as dead code, which would silently undo the F7 guard. Suggested fix: name the intent, for example call resolve_classifier_data(EEG, classifier_name, component_total=component_count(EEG), require=False) directly. A small validate_component_classifier helper would also work.
There was a problem hiding this comment.
🤖 _plot_props now calls validate_component_classifier. That helper raises when stored classifier rows do not match the current ICA component count, so the F7 guard is not a discarded boolean.
ensure_dipfit_settings no longer writes EEG.dipfit.vol into the caller's dataset. Fitting stores the four-shell sphere on its copy. ICLabel uses one icaweights check, and component properties validate classifier rows by name. Behavior tests now live next to the DIPFIT, icflag, and viewprops suites. Co-authored-by: Suraj Ranganath <[email protected]>
|
🤖 Review notes are addressed on 267961f. The DIPFIT behavior tests moved into The three nits are fixed in the same commit: the BESA volume is written only on the fit copy, ICA presence uses The MATLAB reference suite is still not run here. Pins remain EEGLAB |
Keep the new component-property tests and the average-reference channel rejection test that landed on develop. Co-authored-by: Suraj Ranganath <[email protected]>
The dataset dialog timer was handling the same window on the next tick and consuming the following action. That failed the merge and edit-dataset GUI tests on the slower CI runners. Co-authored-by: Suraj Ranganath <[email protected]>
Co-authored-by: Suraj Ranganath <[email protected]>
Keep the Stream 8 changelog notes and the BIDS channel-coordinate note that landed on develop. Co-authored-by: Suraj Ranganath <[email protected]>
Accept and reject process Qt events, so the dialog timer could run again before the first handler returned and take the next action. Co-authored-by: Suraj Ranganath <[email protected]>
Co-authored-by: Suraj Ranganath <[email protected]> # Conflicts: # docs/source/changelog.rst
Accept processes Qt events before the window closes. Remember the window by its Qt object, including across a momentary gap with no modal, and still answer a different window that opens during accept. Co-authored-by: Suraj Ranganath <[email protected]>
Accept can hide the active modal for a timer tick and then show the same window again. Keep that window out of the next handler until its Qt object is gone. Co-authored-by: Suraj Ranganath <[email protected]>
The dialog timer was taking the next action for a window it had already answered. Remember the window name, and when a handler refuses a window close it without dropping the handler. Co-authored-by: Suraj Ranganath <[email protected]>
Merging opens the dataset dialog from inside the merge dialog's OK button. The timer has to claim that dataset handler before OK runs. Co-authored-by: Suraj Ranganath <[email protected]>
A dataset dialog can appear before its title is ready. Keep the handler and try that window again, and close the window only after it keeps refusing the handler. Co-authored-by: Suraj Ranganath <[email protected]>
A click can make a control the active modal while its dialog is still open. The timer was treating that control as the next dialog. Co-authored-by: Suraj Ranganath <[email protected]>
The merge window stayed active after OK and the timer answered it again with the dataset handler. A window title already claimed is left alone. Co-authored-by: Suraj Ranganath <[email protected]>
A window left open by an earlier test was taking the merge OK handler. The merge handler now checks the window title and leaves that earlier window to be closed. Co-authored-by: Suraj Ranganath <[email protected]>
…label-dipfit-03be Co-authored-by: Suraj Ranganath <[email protected]>
|
Claude finished @suraj-ranganath's task in 2m 58s —— View job Code review
BlockingNone. Important
NitsNone. Test gaps
EEGLAB parity notes
I checked |
| "Run pop_dipfit_settings and choose Template Spherical Four-Shell (BESA)." | ||
| ) | ||
| kind = _template_kind(dipfit) | ||
| if kind == "bem" and _shell_radii(dipfit.get("vol")).size == 0: |
There was a problem hiding this comment.
Important: an old BESA vol survives a head-model change, so this guard does not fire.
This guard raises only when there is no shell volume. This PR stores dipfit["vol"] for the BESA template. Later, _apply_settings in pop_dipfit_settings.py copies the existing dipfit. It removes vol only through apply_template, which runs only when a model= option is passed:
eegprep/src/eegprep/plugins/dipfit/pop_dipfit_settings.py
Lines 176 to 182 in 0b00192
Passing just hdmfile (the usual EEGLAB script form) keeps the old sphere. So does choosing "Custom model" in the dialog, which has an empty shortname, so apply_template is skipped. _head_radius then reads the stale vol["r"] (_fitting.py:434-436).
Example:
EEG = pop_dipfit_settings(EEG, model="standardBESA", gui=False) # stores BESA vol
EEG = pop_dipfit_settings(EEG, hdmfile="standard_BEM/standard_vol.mat",
coordformat="MNI", gui=False) # vol kept
EEG = pop_dipfit_gridsearch(EEG, [1], gui=False) # no error; fits the 85 mm BESA sphere in "MNI" coordsA custom hdmfile gets the same silent fallback to the BESA sphere. In EEGLAB, vol always comes from hdmfile, so the two cannot disagree.
Fix: in _apply_settings, when options sets hdmfile, drop vol unless the new file names the BESA template. fill_missing_besa_volume restores it for BESA at fit time. Example: if options.get("hdmfile") and _template_kind(dipfit) != "besa": dipfit.pop("vol", None), after making _template_kind public. Add a regression test in tests/test_dipfit_workflows.py that runs the three calls above and expects the "standard_vol.mat is not bundled" error.
There was a problem hiding this comment.
🤖 Valid. pop_dipfit_settings copied the existing DIPFIT record and only rebuilt vol when model= selected a template, so a later hdmfile= call kept the BESA sphere. The missing-volume check then saw a shell and the fit used the 85 mm radii.
The suggested model check would have missed this path: _template_kind treated a leftover standardBESA label as BESA before it looked at the new file, and fill_missing_besa_volume would have written the sphere back at fit time.
_apply_settings now syncs vol and model whenever this call sets hdmfile or model. The BESA file keeps the four-shell volume. Any other file drops vol. A boundary-element file is labeled standardBEM, and a custom file clears the model name. _template_kind classifies the file first, so a stale model name cannot restore the sphere.
test_replacing_the_besa_head_model_file_drops_the_stored_sphere runs the BESA settings call, then the standard_vol.mat call, then pop_dipfit_gridsearch, and expects standard_vol.mat is not bundled. The same test checks that a custom file does not keep the sphere. The original dataset is unchanged.
Settings copied the previous sphere onto a new head-model file, so a later fit kept the 85 mm BESA shell. The stored volume now follows the file, and the MNI boundary-element file still reports that it is missing. Co-authored-by: Suraj Ranganath <[email protected]>
GUI installs use onnxruntime. Torch stays the export-only extra. The spherical fitter is documented as an infinite homogeneous medium, and the BESA default stays until the MNI forward model lands. Co-authored-by: Suraj Ranganath <[email protected]>
…label-dipfit-03be Co-authored-by: Suraj Ranganath <[email protected]> # Conflicts: # docs/source/changelog.rst
|
Claude finished @suraj-ranganath's task in 1m 6s —— View job Code review
BlockingNone. Important
Nits
Test gapsNone. EEGLAB parity notes
I checked the 8765d51 diff (ICLabel runtime, extras and install messages, |
| if IS_EMSCRIPTEN: | ||
| raise RuntimeError( | ||
| "ICLabel synchronous ONNX execution is unavailable under Emscripten; use await run_iclabel_net_async(...)." | ||
| ) | ||
| session = _get_session() | ||
| inputs = { | ||
| INPUT_NAMES[0]: np.asarray(image, dtype=np.float32), | ||
| INPUT_NAMES[1]: np.asarray(psdmed, dtype=np.float32), | ||
| INPUT_NAMES[2]: np.asarray(autocorr, dtype=np.float32), | ||
| } | ||
| (output,) = session.run([OUTPUT_NAME], inputs) | ||
| return output | ||
|
|
||
|
|
||
| if IS_EMSCRIPTEN: | ||
| from eegprep.plugins.ICLabel.iclabel_net_onnx_web import run_iclabel_net_async as _run_iclabel_net_async | ||
| else: | ||
|
|
||
| async def _run_iclabel_net_async(image, psdmed, autocorr): | ||
| return run_iclabel_net(image, psdmed, autocorr) | ||
|
|
||
|
|
||
| async def run_iclabel_net_async(image, psdmed, autocorr): | ||
| """Run the platform-selected ICLabel backend asynchronously.""" | ||
| return await _run_iclabel_net_async(image, psdmed, autocorr) |
There was a problem hiding this comment.
Important: the Pyodide/async backend has no caller and points users to a file that does not exist.
run_iclabel_net_asyncand all oficlabel_net_onnx_web.pyare unreachable.iclabel()only calls the synchronousrun_iclabel_net(), and nothing else ineegprep/src/eegprep/plugins/ICLabel/iclabel.py
Lines 68 to 70 in 62f3c5f
src/,tests/ordocs/imports the async function.- Under Emscripten,
pop_iclabeltherefore always raises thisRuntimeError. The message tells the user toawait run_iclabel_net_async(...), but a user can't do that throughiclabel/pop_iclabel. MISSING_HOST_MESSAGEiniclabel_net_onnx_web.pynamestools/pyodide/iclabel_web_bridge.mjsandcreateIcLabelWebBridge(). That directory is not in this branch.- No test runs any of this code.
AGENTS.md says: "Do not add features beyond what was asked. No speculative configurability, future-proofing". This PR fixes the #553 menu findings. A browser runtime is not one of them.
Fix: delete iclabel_net_onnx_web.py, the IS_EMSCRIPTEN branch, and lines 67-77. Add the browser backend in its own PR, together with the JS bridge, a caller path from iclabel, and a test.
There was a problem hiding this comment.
🤖 Valid. run_iclabel_net_async and iclabel_net_onnx_web.py had no caller, and the error text named tools/pyodide/iclabel_web_bridge.mjs, which is not in this branch. Under Emscripten that path would only tell someone to await a function iclabel never exposes.
Those files and the IS_EMSCRIPTEN branch are removed. iclabel still classifies through the synchronous run_iclabel_net session. The browser bridge can land with its JavaScript host, a caller from iclabel, and a test. The native pieces that match the epic stay: run_iclabel_net, prepare_network_inputs, postprocess_network_output, and the iclabel extra.
| Algorithm to use for classification, passed to the MATLAB/Octave implementation. | ||
| Default is 'default'. | ||
| engine : str or None | ||
| engine : str or None |
There was a problem hiding this comment.
Nit: this edit indented engine : str or None by four more spaces. The numpydoc parser now reads it as part of the algorithm description, so engine disappears from the rendered Parameters list.
| engine : str or None | |
| engine : str or None |
There was a problem hiding this comment.
🤖 Valid. engine was indented with the algorithm description, so it was not a Parameters entry. It is back at the same indent as algorithm.
The async ONNX path had no caller and named a JavaScript bridge that is not in this branch. Classification stays on the synchronous onnxruntime session. Co-authored-by: Suraj Ranganath <[email protected]>
|
🤖 Agreed. |
|
Claude finished @suraj-ranganath's task in 33s —— View job Code review
BlockingNone. ImportantNone. NitsNone. Test gapsNone.
EEGLAB parity notesNone new.
Checked for correctness bugs, EEGLAB parity, data structure compatibility, changed-behavior tests, and CLAUDE.md/AGENTS.md compliance. I did not run pytest; this review only read the code. |
Keep component property windows and the DIPFIT dialog, leadfield, and plot behavior that the MNI boundary-element and four-shell pull requests do not cover. Co-authored-by: Suraj Ranganath <[email protected]>
Keep the component property windows, the head-model menu, empty DIPFIT settings, the LORETA-KEY grid, and autofit plot options. Co-authored-by: Suraj Ranganath <[email protected]>
There was a problem hiding this comment.
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 finished @suraj-ranganath's task in 2m 2s —— View job Code review
BlockingNone. ImportantNone. Nits
Test gapsNone that block. The new tests cover:
One gap is optional: component mode with no classifier is only exercised with EEGLAB parity notes
I did not run pytest because this job's permissions blocked the command. Checked: correctness, EEGLAB parity, EEG dict handling, changed-behavior tests, and CLAUDE.md/AGENTS.md compliance. |
| try: | ||
| coord_index = int(result.get("coordformat", state["coordformat"]) or state["coordformat"]) - 1 | ||
| except (TypeError, ValueError): | ||
| coord_index = int(state["coordformat"]) - 1 |
There was a problem hiding this comment.
Nit: this try/except guards a case that can't happen. coordformat is a popupmenu, so inputgui always returns a 1-based int for it (
eegprep/src/eegprep/plugins/dipfit/pop_dipfit_settings.py
Lines 161 to 167 in 88eb6f8
try/except blocks and defensive None checks for impossible states" as a failure pattern. If a renderer ever returns something else, the error should surface instead of silently falling back to the template's format.
| try: | |
| coord_index = int(result.get("coordformat", state["coordformat"]) or state["coordformat"]) - 1 | |
| except (TypeError, ValueError): | |
| coord_index = int(state["coordformat"]) - 1 | |
| coord_index = int(result.get("coordformat", state["coordformat"])) - 1 |
There was a problem hiding this comment.
Non-blocking. The popup returns a 1-based int, so the try/except is defensive. It does not change fitting or leadfields. Leaving it for a follow-up.
|
Jamming at 88eb6f8 is clean. 44 tests in test_dipfit_bem.py, test_dipfit_four_shell.py, and test_dipfit_workflows.py passed, including test_bem_leadfield_and_multifit_match_fieldtrip and test_fieldtrip_leadfields_and_pop_multifit_positions_match_eeglab. 21 tests in the component-property files also passed. There is no test that compares the LORETA-KEY leadfield to MATLAB; test_loreta_key_leadfield_and_missing_source_analysis only checks the in-head grid and the missing-analysis error. The two nits are non-blocking: the coordformat try/except does not change results, and the stream11 fixture changes are outside the DIPFIT and dashboard work. |
|
CI is red on the Python 3.12/3.13 test matrix (ubuntu, macos, and windows). I am holding the merge. On macos-latest and windows-latest, the async ICLabel menu-action test in tests/test_gui_main_window.py hit the 300s pytest timeout inside QtDialogRenderer.run at dialog.exec(), while opening the pop_iclabel dialog. Ubuntu 3.12 and 3.13 failed the same Run Python tests step with a similar runtime. Jamming DIPFIT/BEM/component-property MATLAB-engine tests at 88eb6f8 were clean (44 + 21). This hanging GUI test still needs a fix before merge. |
The Update Marks warning was shown with QMessageBox's default application modality and no dialog loop. The async ICLabel menu test then accepted that leftover warning and waited forever in pop_iclabel's dialog.exec(). Co-authored-by: Suraj Ranganath <[email protected]>
The selected head model builds that leadfield. Match standardBEM and standardBESA against ft_compute_leadfield through the MATLAB engine, using the same relative bounds as the existing DIPFIT engine tests. Co-authored-by: Suraj Ranganath <[email protected]>
…label-dipfit-03be Co-authored-by: Suraj Ranganath <[email protected]> # Conflicts: # docs/source/changelog.rst
Component property dashboards open for channels and components, and a map click opens that component. The head-model menu fills the file fields and enables Browse for a custom model. An empty EEG.dipfit array is missing settings, LORETA-KEY builds a 20 mm in-head grid, and autofit accepts 'normlen' 'on'. ICLabel was dropped because #386 covers it. The BESA volume and missing standard_vol.mat path were dropped because #610 and #611 cover them.
Fixes #553