Repository navigation
pop_clustedit: Restore cluster editing actions and content-sized rows - #1041
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 37s —— View job Code review
BlockingNone. Important
Nits
Test gaps
EEGLAB parity notes
|
| name = reply[0].strip() or "Cls" | ||
| elif action == "movecomp" and to_cluster is None: | ||
| targets = cluster_list(study) | ||
| options = [n for n in range(2, len(targets) + 1) if n != cluster] |
There was a problem hiding this comment.
Important: the reassign dialog lists clusters that std_movecomp rejects. The destination list excludes only the ParentCluster and the source cluster. But std_movecomp raises ValueError("Cannot move components if clusters have child clusters") for any cluster with children (
eegprep/src/eegprep/functions/studyfunc/std_movecomp.py
Lines 36 to 39 in b2575bd
movecomp branch also leaves out Notclust/Outliers clusters and clusters with children when it builds the destination list.
Suggested fix: build the list from leaf clusters that are not outlier clusters, for example:
| options = [n for n in range(2, len(targets) + 1) if n != cluster] | |
| options = [ | |
| n | |
| for n in range(2, len(targets) + 1) | |
| if n != cluster | |
| and not targets[n - 1]["child"] | |
| and not targets[n - 1]["name"].lower().startswith(("outliers", "notclust")) | |
| ] |
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. The restored dipole plotting actions fail or plot the wrong clusters on the default GUI selection and do not open plot windows in the desktop GUI.
- Highest-risk area: Dipole plotting (
dipolesandcomponentdipoles) and outlier cluster filtering inpop_clustedit.py. - Merge recommendation: Needs changes.
Blocking
None.
Important
-
Important:
Plot dipoleson the defaultAll cluster centroidsselection plotsParentClusterand outlier clusters, crashes on empty clusters, and writes unused arguments to history (src/eegprep/functions/studyfunc/pop_clustedit.py, lines 173 to 184 and line 230).
In the dialog,clus_listdefaults to[1](All cluster centroids), which_clusters_from_list_selectionexpands to[1, 2, ..., N]. Passing that list tostd_dipplotincludes cluster1(ParentCluster), any outlier orNotclustclusters, and any empty clusters. As a result, clicking Plot dipoles on a clustered STUDY plots a duplicateParentClustersubplot and writesSTUDY["cluster"][0]["dipole"]. Worse, right after creating an empty cluster with Create new cluster (action="create"), clicking Plot dipoles (or callingpop_clustedit(study, datasets, action="dipoles")withclusters=None) raisesValueError: STUDY cluster <N> has no localized dipoles in the selection. Line 184 also writes all three keys (cluster,clusters,comps) intocommand_kwargs, sodipolesrecords unusedcluster=1andcomps=[1]fromclust_comp, whilecomponentdipolesrecords unusedclustersfromclus_list(and passesclusters=[None]ifclusteris omitted in an API call).
Suggested fix: forcomponentdipoles, requirecluster is not None(raisingValueError("componentdipoles requires a cluster index")) and record only{"cluster": cluster, "comps": comps}. Fordipoles, whenclusters is NoneorAll cluster centroids(1inclus_list) is selected, filterselected_clustersto indices>= 2whose cluster hascompsand whose lowercased name does not start with("parentcluster", "outlier", "notclust")(matching EEGLABfunctions/studyfunc/pop_clustedit.m, lines 505 to 511), and record only{"clusters": selected_clusters}. -
Important:
dipolesandcomponentdipolesnever callshow_figures, so clicking the dipole buttons in the GUI opens no plot window (src/eegprep/functions/studyfunc/pop_clustedit.py, lines 176 to 183).
std_dipplotbuilds figures withplt.figure(...)without displaying them,menu_actions.pydiscards_figureon return, andeegprepconsole sessions turn interactive mode off (plt.ioff()inconsole.py, line 891) becausepop_*functions display viashow_figures(). In addition,dipmode="apart"creates one figure per cluster, sofigure = figures[0] if figures else Nonedrops the remaining figures if nothing displaysfigures.
Suggested fix: importshow_figuresfromeegprep.functions.popfunc.plot_utilsand callshow_figures(figures)afterstd_dipplot(...), matchingpop_dipplot.py(line 64) andpop_chanplot.py(line 72). -
Important: Outlier prefix checks match
"outliers"but miss"outlier <N>"clusters frompop_clust/std_createclust(src/eegprep/functions/studyfunc/pop_clustedit.py, lines 85 and 101).
std_moveoutlierandstd_rejectoutliersname outlier clusters"Outliers ...", whereasstd_createclust(and EEGLABstd_createclust.m, line 166) names k-means outlier clusters"outlier 1"(singular). Checking.startswith(("outliers", ...))therefore offers"outlier 1"as a destination in Reassign selected component(s) and allows renaming it in Rename selected cluster. Also, if the selected source cluster inmovecomphas child clusters,pop_clusteditopens the destination dialog first and only fails insidestd_movecompafter confirmation.
Suggested fix: match"outlier"instead of"outliers"(consistent with_cluster_utils.py, line 213), and returncancelledbefore opening the destination dialog whencluster is None,cluster == 1,not comps, ortargets[cluster - 1]["child"]is non-empty.
Nits
-
Nit:
Dipole plot parametersalways resets the dropdown toapart(src/eegprep/functions/studyfunc/pop_clustedit.py, line 133).
ControlSpec("popupmenu", "|".join(DIP_MODES), tag="mode", value=1)ignores any existingSTUDY["etc"]["dipparams"]["mode"]. Initializevaluefrom the stored mode index when present so reopening Params preserves the current choice. -
Nit:
has_dipolescan raise or misclassify non-listdipfit["model"]values (src/eegprep/functions/studyfunc/pop_clustedit.py, lines 220 to 222).
len(eeg["dipfit"].get("model", []))raisesTypeErrorifmodelisNone, treats a string template name or rejected empty dipole entries (posxyz == []) as localized dipoles, and misses a 1-ICdictstruct. Reusinglocalized_components(eeg)fromeegprep.plugins.dipfit._utilshandles all of those cases.
Test gaps
- Dipole actions and GUI button enablement (
tests/test_study_clustering.py).
The new tests cover APIcreate, GUImovecompfiltering, and missingdipmodevalidation, but none exerciseaction="dipoles",action="componentdipoles",action="dipparams"with a valid mode, orhas_dipolesinpop_clustedit_dialog_spec. Add a test with localizeddipfitmodels that runsaction="create"followed by GUIaction="dipoles"on the defaultclus_list=[1]selection and verifies that only non-empty, non-outlier child clusters are plotted.
EEGLAB parity notes
vertexpand=2.1insupergui.py(offset = control.vertexpand - 1, heightcontrol.vertexpand * height) matches EEGLABfunctions/guifunc/supergui.m(lines 302 to 304) andfunctions/studyfunc/pop_clustedit.m(line 392).- EEGLAB
pop_dipparams.mconfigures MRI projection and density toggles (density,projlines,centrline,projimg,axistight), whereas EEGPrep'sdipparamsaction configuresstd_dipplot's display mode (apart,together,multicolor,centroid) for the standalone 3D Matplotlib view and documents this insrc/eegprep/resources/help/pop_clustedit.md.
Tests run in a detached worktree (tests/test_study_clustering.py, tests/test_study_end_to_end.py, tests/test_gui_pop_study.py, tests/test_gui_geometry.py, tests/test_guifunc_primitives.py, tests/test_guifunc_pophelp_chansel.py, tests/test_study_dipplot_eeglab_tests.py): 213 passed, 67 skipped (Linux-measured MATLAB geometry references on macOS), 9 deselected. Checked for correctness bugs, EEGLAB parity, data structure compatibility, changed-behavior tests, and CLAUDE.md/AGENTS.md compliance.
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. One remaining issue in
componentdipolescorrupts the stored cluster dipole centroid and hides component dipoles whendipparamsis set tocentroid. - Highest-risk area:
action="componentdipoles"insrc/eegprep/functions/studyfunc/pop_clustedit.py. - Merge recommendation: Needs changes.
Blocking
None.
Important
- Important:
componentdipolesforwardsdipparams["mode"]instead ofmode="comps"and overwritesSTUDY.cluster[cluster - 1]["dipole"]with the selected subset (src/eegprep/functions/studyfunc/pop_clustedit.py, lines 199 to 205).
pop_clusteditcallsstudy, _, figures = std_dipplot(study, datasets, clusters=[cluster], comps=comps, mode=study.get("etc", {}).get("dipparams", {}).get("mode")). Two bugs follow from this call:- When the user sets Display mode to
"centroid"via Params (action="dipparams"),std_dipplotsetsinclude_dipoles = (mode != "centroid"), so Plot dipole(s) draws zero component dipoles and shows only a"centroid"marker computed fromcomps. Even in"apart"or default mode,std_dipplotdraws a"<cluster> centroid"diamond at the subset average (on top of the component when one component is selected). In EEGLABfunctions/studyfunc/std_dipplot.m(line 27 and lines 114 to 120),'mode'is ignored when'comps'is passed, and EEGPrep'sstd_dipplotprovidesmode="comps"specifically to plot component dipoles without a centroid marker. std_dipplotwritesselection["centroid"](computed only overcomps) back intostudy["cluster"][cluster - 1]["dipole"]. Callingaction="componentdipoles"withcomps=[1]afteraction="dipoles"therefore replaces the full cluster centroid with component 1's coordinates, andmenu_actions.pysaves that modifiedSTUDYinto the session. In EEGLABstd_plotcompdip(functions/studyfunc/std_dipplot.m, lines 626 to 630),STUDY.cluster(cls).dipoleis computed over the full cluster only when missing and is never overwritten by a component subset.
Suggested fix: passmode="comps"tostd_dipplotin thecomponentdipolesbranch and do not overwritestudywith the subset centroid returned by that call (for example,_unused, _, figures = std_dipplot(study, datasets, clusters=[cluster], comps=comps, mode="comps"), optionally populatingstudy["cluster"][cluster - 1]["dipole"]viastd_dipplot(study, datasets, clusters=[cluster], plot=False)first only if"dipole"is not already present).
- When the user sets Display mode to
Nits
None.
Test gaps
- Component dipole plotting under
dipmode="centroid"and cluster centroid preservation (tests/test_study_clustering.py, lines 682 to 694).
test_clustedit_dipole_actions_filter_all_centroids_and_record_minimal_historydiscards_comp_studyand checks onlycomp_fig is not None. Setplotted["etc"]["dipparams"] = {"mode": "centroid"}before theaction="componentdipoles"call and assert both thatcomp_fig.axes[0]labels the selected component dipole ("Cls 1: S01 IC2 (RV 4.0%)") rather than"Cls 1 centroid"and that_comp_study["cluster"][2]["dipole"]["posxyz"]still equalsplotted["cluster"][2]["dipole"]["posxyz"].
EEGLAB parity notes
vertexpand=2.1insupergui.py(offset = control.vertexpand - 1, heightcontrol.vertexpand * height) matches EEGLABfunctions/guifunc/supergui.m(lines 302 to 304) andfunctions/studyfunc/pop_clustedit.m(line 392).- Filtering
All cluster centroidsin_dipole_all_clustersto non-empty clusters whose names do not start with("parentcluster", "outlier", "notclust"), and matching singular"outlier"prefixes fromstd_createclust, matches EEGLABfunctions/studyfunc/pop_clustedit.m(lines 505 to 511) andfunctions/studyfunc/std_createclust.m(line 166).
Tests run in a detached worktree at commit c920cf815c7539c9868fe99d7ac81fb419adc763 (tests/test_study_clustering.py, tests/test_study_end_to_end.py, tests/test_study_dipplot_eeglab_tests.py, tests/test_gui_pop_study.py, tests/test_gui_geometry.py, tests/test_guifunc_primitives.py, plus ruff check on the modified Python files): 215 passed, 70 skipped (MATLAB geometry references measured on Linux), 7 deselected, and ruff check passed. Checked for correctness bugs, EEGLAB parity, data structure compatibility, tests for changed behavior, and CLAUDE.md/AGENTS.md compliance.
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. Checked
pop_clusteditactions (create,rename,movecomp,dipoles,componentdipoles,dipparams),superguivertexpandlayout, dialog specs, history command generation, documentation, and changed tests at commitaca3f837b6d1c35297f7a781f500727e1e096956. - Highest-risk area: None identified.
- Merge recommendation: Safe to merge.
Blocking
None.
Important
None.
Nits
None.
Test gaps
None.
EEGLAB parity notes
vertexpand=2.1insupergui.pyshifts the vertical origin by(vertexpand - 1) * heightand scales height byvertexpand, matching EEGLABfunctions/guifunc/supergui.m(lines 302 to 304) andfunctions/studyfunc/pop_clustedit.m(line 392).action="componentdipoles"populatesSTUDY.cluster[cluster - 1]["dipole"]over the full cluster when missing and plots selected component dipoles withmode="comps"without overwriting the stored cluster centroid, matching EEGLABstd_plotcompdipinfunctions/studyfunc/std_dipplot.m(lines 626 to 635)._dipole_all_clustersand outlier guards excludeParentCluster,Notclust, singular and pluraloutlierprefixes, and empty clusters, matching EEGLABfunctions/studyfunc/pop_clustedit.m(lines 505 to 511 and lines 656 to 660) andfunctions/studyfunc/std_createclust.m(line 166).
Tests run in a detached worktree at commit aca3f837b6d1c35297f7a781f500727e1e096956 (tests/test_study_clustering.py, tests/test_study_end_to_end.py, tests/test_study_dipplot_eeglab_tests.py, tests/test_gui_pop_study.py, tests/test_gui_geometry.py, tests/test_guifunc_primitives.py, tests/test_guifunc_pophelp_chansel.py, plus ruff check and ruff format --check on the modified Python files): 226 passed, 70 skipped (MATLAB geometry references measured on Linux), 9 deselected, and ruff checks passed. Checked for correctness bugs, EEGLAB parity, data structure compatibility, tests for changed behavior, and CLAUDE.md/AGENTS.md compliance.
🤖 Part of #972 and #875. Restore cluster editing actions and content-sized rows. Stacked on #1037.
Native measurements and validation
Window height is 498 px in both applications. The maximum vertical offset is 0.407 px. On both real GUIs the N400 rename and create operations produced identical names, dataset indices and ICA component membership across all 11 or 12 resulting clusters. Twenty-seven workflow tests passed. With the EEGPrep dialog, select an action and press OK to apply it. Dipole buttons use std_dipplot when the loaded datasets contain fitted dipoles.
Full inventory report for the project team. pop_clustedit (p. 50). PDF · Editable Word.