Repository navigation
[GUI] Match the pop_leadfield dialog on configured MRI data - #1038
Conversation
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 @arnodelorme's task in 1m 21s —— View job Code review
BlockingNone. Important
See the inline comment. Nits
Test gaps
EEGLAB parity notes
|
| source_files = ( | ||
| "head_modelColin27_5003_Standard-10-5-Cap339.mat", | ||
| "tess_cortex_mid_low_2000V.mat", | ||
| "loreta-key", | ||
| "TTatlas+tlrc.HEAD", | ||
| "", | ||
| ) |
There was a problem hiding this comment.
Important: unbundled atlas choices now fail with a raw scipy error after OK.
Before this change, the Colin27 and ICBM152 choices left the File name field empty. _leadfield_options_from_result then raised its clear message: "that source model file is not bundled". Now the callback fills in a bare name like head_modelColin27_5003_Standard-10-5-Cap339.mat, so that check never runs. On OK, the name goes to _source_points_from_option. The .mat branch at
eegprep/src/eegprep/plugins/dipfit/pop_leadfield.py
Lines 242 to 251 in c3c1955
is_file() check at eegprep/src/eegprep/plugins/dipfit/pop_leadfield.py
Lines 256 to 261 in c3c1955
loadmat raises scipy's own OSError. That error doesn't name pop_leadfield or give a fix, and the dialog has already closed. The AFNI choice now hits the generic AFNI DIPFITUnavailableError rather than the "not bundled" guidance.
Suggested fix: keep the displayed names. In _leadfield_options_from_result, raise the "not bundled" error for choices 1, 2 and 4 unless the text is a file that exists. Add a test that picks choice 1, accepts the dialog, and asserts that this message is raised.
arnodelorme
left a comment
There was a problem hiding this comment.
This review was written by an AI assistant during a nightly check, not by Arno.
Code review
- Overall assessment: Needs changes.
- Highest-risk area:
_preview_source_modelinsrc/eegprep/plugins/dipfit/pop_leadfield.py. - Merge recommendation: Needs changes.
Blocking
None.
Important
-
src/eegprep/plugins/dipfit/pop_leadfield.py(_preview_source_model, L180-L183): radian DIPFIT transform passed totraditionalinstead oftraditionaldipfit.
pop_leadfield_dialog_specsetssurface_transform = "0 -24 -45 0 0 -1.5707963 1000 1000 1000"(-pi/2radians, matchingplugins/dipfit/pop_leadfield.mlines 76 and 86), and EEGLAB's preview callbackplugins/dipfit/plot3dmeshalign.m(lines 169 and 228) appliestraditionaldipfit(transform)(as doesload_afni_atlas.pyline 52)._preview_source_modelinstead callstraditional(transform)(_coordinates.pyL151-L154), which treats rotations as degrees with the opposite Z rotation sign and rejects 6 element vectors. Onsurface_transform,[0.05, 0, 0.08]maps to[49.98, -25.37, 35.0]mm instead of[0.0, 26.0, 35.0]mm, leaving custom surface meshes rotated roughly 88 degrees off in the preview.
Suggested fix: Importtraditionaldipfitinstead oftraditionalfromeegprep.plugins.dipfit._coordinatesand callapply_transform(traditionaldipfit(transform), points). -
src/eegprep/plugins/dipfit/pop_leadfield.py(_preview_source_model, L185-L188): BEM preview plots the outer scalp (vol["bnd"][0]) instead of the inner brain mesh (vol["bnd"][vol["source"]]).
Instandard_vol.npz(standardBEM),vol["bnd"][0]is the scalp (176 x 208 x 174mm) whilevol["bnd"][2](vol["source"], computed byprepare_headmodel_sensinft_dipolefitting.pyL122-L123) is the brain surface (145 x 185 x 149mm). Both EEGLABplot3dmeshalign.m(lines 158 to 160,f.vol.bnd(3)) and the spherical branch right below (min(vol["r"])) draw the brain surface so the user can see whether source points lie inside the volume tested byinside_headmodel. Plottingvol["bnd"][0]makes points in the skull or scalp appear inside the brain mesh.
Suggested fix: Usesurface = vol["bnd"][vol["source"]].
Nits
src/eegprep/plugins/dipfit/pop_leadfield.py(_preview_source_model, L173-L179 and L201-L203): modal dialog parenting and unbundled preset error in the preview button.
Callingfig.show()directly skipsshow_figures(fig)(plot_utils.pyL24-L60), which parents the Matplotlib window above the active modalQDialogand suppresses warnings on file backends. Clicking...on the Colin27 or ICBM152 choices also calls_source_points_from_optionbefore_leadfield_options_from_result, showingscipy.io.loadmat's raw[Errno 2] No such file or directorywarning instead ofpop_leadfield's"that source model file is not bundled"message.
Suggested fix: Validateoptions = _leadfield_options_from_result(values)before loadingoptions["sourcemodel"], and display the figure withshow_figures(fig).
Test gaps
test_gui_leadfield_loreta_key_choice_fills_the_source_fieldexercises_preview_source_modelonly onstandardBESAwith an emptysourcemodel2mni. Add coverage with a nonzero radian rotation insourcemodel2mni(checking the scattered points againsttraditionaldipfit) and withmodel="standardBEM"(checking the plotted trisurf vertices matchvol["bnd"][vol["source"]]).
EEGLAB parity notes
_preview_source_modeltransforms source points withsourcemodel2mnifor display (matchingplot3dmeshalign.m), whilepop_leadfieldcomputes the leadfield on untransformedpointsand only storescoordtransform(existing behavior on lines 82 to 88). For a custom source file paired with a nonemptysourcemodel2mni, the previewed coordinates will differ from the coordinates used for the leadfield.
Tests run in a detached worktree at e5bcc9f3e9b1f185af9c88e4b5952c2e34439463: PYTHONPATH=<worktree>/src .venv/bin/python -m pytest tests/test_dipfit_workflows.py tests/test_dipfit_loreta_key.py (44 passed, 1 deselected in 17.28s).
arnodelorme
left a comment
There was a problem hiding this comment.
This review was written by an AI assistant during a nightly check, not by Arno.
Code review
- Overall assessment: Looks good.
- Highest-risk area: None identified.
- Merge recommendation: Safe to merge.
Blocking
None.
Important
None.
Nits
None.
Test gaps
None.
EEGLAB parity notes
None.
Checked pop_leadfield_dialog_spec and dipfit_source_model widget state transitions against plugins/dipfit/pop_leadfield.m, _preview_source_model coordinate transforms (traditionaldipfit), BEM brain mesh selection (vol["bnd"][vol["source"]]), spherical head model fallback, modal figure display (show_figures) against plugins/dipfit/plot3dmeshalign.m, unbundled source model error handling in _leadfield_options_from_result, Sphinx documentation in docs/source/api/ica_and_components.rst, changed behavior tests, and AGENTS.md compliance.
Tests run in a detached worktree at 9d59390537ca48025b1bc24e0daf3c8d51ca77c3:
PYTHONPATH=/Users/arno/.orchestrator/pr-reviews/eegprep-1038/src .venv/bin/python -m pytest /Users/arno/.orchestrator/pr-reviews/eegprep-1038/tests/test_dipfit_workflows.py /Users/arno/.orchestrator/pr-reviews/eegprep-1038/tests/test_dipfit_loreta_key.py: 47 passed, 1 deselected in 14.55s..venv/bin/ruff checkand.venv/bin/ruff format --checkon the modified Python files: passed.
The public leadfield dialog follows the selected atlas for the source file, coordinate transform, and downsampling. The transform button previews supported source positions with the configured head model. The largest vertical offset after the change was 0.49 px. This PR stacks on #1028.
The 30 registered sample electrodes gave the same BEM leadfields at three explicit MNI locations within 3.37e−15 relative to FieldTrip. The installed standalone LORETA grid is an approximation. The other bundled MATLAB atlas files are not distributed by EEGPrep.
Native captures and verification
The clean jamming capture verified the checkout imports before opening each window. Focused geometry and DIPFIT test results were 209 passed in 3.73s.
Fixes #1000. Part of #875.
Full inventory report for the project team. pop_leadfield (p. 88). PDF · Editable Word.