Repository navigation
[DIPFIT] Implement source-localization menu surfaces - #84
Conversation
|
Claude finished @suraj-ranganath's task in 8m 5s —— View job Code review
BlockingNone. Important
Nits
Test gaps
EEGLAB parity notes
Checked: changed files in |
|
🤖 DIPFIT Phase 3 implementation spec and visual evidence Problem: Phase 3 issue #63 still had bundled DIPFIT/source-localization menu actions registered as placeholders, so users could see EEGLAB DIPFIT menus but could not configure DIPFIT metadata, plot existing models, or get clear errors when FieldTrip-only workflows were unavailable. Approach: This PR adds EEGPrep-owned DIPFIT modules under Key code: Tests: Focused tests cover sample_data settings, missing channel locations, missing ICA/settings/model assets, multi-dataset settings GUI behavior, explicit FieldTrip limitation errors, standalone dipplot success/error paths, menu dispatch, visual parity case registration, and placeholder removal. Verified with ruff, format check, ty, focused Phase 3 tests, and Visual parity artifacts are attached below as GitHub user attachments and are not committed to the repo. Side-by-side images are EEGLAB on the left and EEGPrep on the right. The headmodel screenshot is EEGPrep-only because EEGLAB opens a native MRI file picker before the parameter dialog. |
| default_components = localized_components(EEG) | ||
| components = one_based_indices(comps, limit=len(models), default_all=not bool(comps)) | ||
| if not components: | ||
| components = default_components | ||
| if not components: | ||
| raise ValueError("No localized dipoles are available to plot") |
There was a problem hiding this comment.
Severity: Important — likely-broken default behavior.
When comps is empty (None, "", or []) — which happens for the bare pop_dipplot(EEG) console call and for the GUI default ("Components indices ([]=all available)") — one_based_indices(empty, ..., default_all=True) returns [1..len(models)], so components is never empty and the default_components = localized_components(EEG) fallback on line 44 is unreachable. _validate_components_have_positions then raises Localization not found... whenever any model in EEG.dipfit.model has an empty posxyz, which is normal for partially-fit datasets (and is what EEGLAB silently skips).
This means selecting "Component dipole plot" from the Tools menu, or running pop_dipplot(EEG) from the console, errors out whenever some ICs are unlocalized — even though the dialog hint says "[]=all available".
Fix: let the empty case fall through to default_components:
| default_components = localized_components(EEG) | |
| components = one_based_indices(comps, limit=len(models), default_all=not bool(comps)) | |
| if not components: | |
| components = default_components | |
| if not components: | |
| raise ValueError("No localized dipoles are available to plot") | |
| default_components = localized_components(EEG) | |
| components = one_based_indices(comps, limit=len(models), default_all=False) | |
| if not components: | |
| components = default_components | |
| if not components: | |
| raise ValueError("No localized dipoles are available to plot") | |
| _validate_components_have_positions(models, components) |
Worth adding a test that calls pop_dipplot(eeg) on a dataset where some models have empty posxyz and asserts the figure is built from only the localized ones.
| if name == "pop_dipplot": | ||
| from eegprep.plugins.dipfit.pop_dipplot import pop_dipplot | ||
|
|
||
| _figures, command = pop_dipplot(selection, return_com=True) | ||
| self._add_history_from_gui(command) | ||
| self._refresh() | ||
| return |
There was a problem hiding this comment.
Severity: Important — figure may never be shown from the GUI menu.
pop_dipplot builds a Matplotlib Figure via plt.figure(...) and returns it without calling fig.show() or plt.show(). Here the dispatcher unpacks _figures and immediately discards it. On non-interactive matplotlib backends (or when matplotlib's interactive mode is off, which is the default in plain CPython), the user clicks "Component dipole plot" → fills the dialog → nothing visible happens. Only history is recorded.
Two options:
- Call
figure.show()(orplt.show(block=False)) on each returned figure inside_run_dipfit_functionbefore discarding, so the dispatcher matches the other plot actions; or - Have
pop_dipplot._plot_dipolescallfig.show()itself when invoked from a GUI/interactive context (similar to how otherpop_*plot wrappers do).
Without one of these the menu action is a silent no-op outside of Jupyter / IPython interactive backends.
| if "coord_transform" in options: | ||
| dipfit["coord_transform"] = _numeric_list(options["coord_transform"]) | ||
| usable = coordinate_channel_indices(out) |
There was a problem hiding this comment.
Severity: Nit — clobbers template coord_transform on an empty GUI submit.
When the GUI runs with the BEM template (the default), _run_gui sets options["coord_transform"] to whatever text is in the coord_transform line edit unless "No Co-Reg." is checked. If the user clears that text (or it is somehow empty), _numeric_list("") returns [] and this assignment wipes the template's standard MNI rotation, leaving an unusable head-model registration.
Consider guarding with the same "skip when empty" rule used for the file fields above, so the template default survives an empty coord_transform submission:
if "coord_transform" in options:
transform = _numeric_list(options["coord_transform"])
if transform:
dipfit["coord_transform"] = transformIf you want the user to be able to intentionally clear the transform, the No-Co-Reg checkbox already covers that.
5473e8e to
7fed51f
Compare








Add EEGPrep DIPFIT settings storage, standalone dipole plotting, menu dispatch, help resources, and explicit missing-backend errors for FieldTrip-dependent source-localization workflows. Adds focused tests and visual parity cases for the bundled DIPFIT dialogs.
Closes #63