Skip to content

[GUI] Match the pop_dipfit_nonlinear dialog on configured MRI data - #1040

Merged
arnodelorme merged 3 commits into
developfrom
agent/issue-1004-dipfit_nonlinear
Dec 1, 2026
Merged

arnodelorme merged 3 commits into
developfrom
agent/issue-1004-dipfit_nonlinear

Conversation

@arnodelorme

@arnodelorme arnodelorme commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

The manual dipole fit now has the native symmetry row, separate fit actions, explicit Cancel, Help and OK row, and MATLAB position, moment and variance precision. The largest vertical offset after the change was 0.50 px. This PR stacks on #1039.

pop_dipfit_nonlinear.fit-triptych

distances

Three nonlinear fits from the same MNI coarse model agreed within 2.38e−7 on the concatenated position, moment and residual variance array. This PR changes display, actions and formatting.

Native captures and verification

The clean jamming capture verified the checkout imports before opening each window. Focused geometry and DIPFIT test results were 210 passed in 4.00s.

Fixes #1004. Part of #875.

Full inventory report for the project team. pop_dipfit_nonlinear (p. 85). PDF · Editable Word.

@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 15s —— View job


Code review

  • Overall assessment: Needs one small fix. The layout, the new Cancel/Help/OK row and the 3-decimal position and 2-decimal residual variance formatting look right. The new close_dialog Qt callback works for this dialog: it has no validate hook, so skipping _accept_if_valid changes nothing here.
  • Highest-risk area: moment formatting in the Flip action. Whatever the text fields show is what OK writes to EEG.dipfit.model.
  • Merge recommendation: needs changes. The fix is small.

Blocking

None.

Important

  • Flip rounds CTF moments to 3 decimals (src/eegprep/plugins/dipfit/pop_dipfit_nonlinear.py:300). The dialog and the post-fit update show CTF moments with 6 decimals (lines 84 and 337), but the flip branch always formats with .3f. OK parses the widget text, so flipping a CTF dipole and pressing OK saves a moment rounded to 3 decimals in EEG.dipfit.model and in the history. Small values can become 0.000. Fix: use the CTF-aware precision in the flip branch (params["eeg"] is already there). I posted the details as an inline comment.

Nits

  • The expression 6 if str(dipfit_record(...).get("coordformat", "")).upper() == "CTF" else 3 appears twice in this diff, and the flip fix would add a third copy. A _moment_precision(EEG) helper avoids the copies drifting apart, which is exactly what happened in the flip branch.

Test gaps

  • No test covers the CTF moment precision. Extend test_nonlinear_ok_keeps_the_flipped_moment (or add a parametrized case) with coordformat="CTF" and a small moment such as 1e-4. Check that the flipped text is -0.000100 and that OK keeps it.

EEGLAB parity notes

  • pop_dipfit_nonlinear.m is not vendored under src/eegprep/eeglab/ in this checkout, so I couldn't cite line numbers. The 3-decimal positions, CTF-only 6-decimal moments and 2-decimal residual variance match what the PR description says about EEGLAB. Because OK reads the edit text back, as in EEGLAB, the stored positions are now rounded to 3 decimals; they used to keep 6 significant digits. That is consistent with EEGLAB, but it is worth knowing.

Checked: the diff against origin/agent/issue-1002-dipfit_settings, the OK path through _apply_nonlinear_gui_model, the close_dialog callback against _dialog_buttons/_accept_if_valid in qt.py, the updated test expectations, and AGENTS.md compliance (the docs page is updated, there is no Help markdown change, and the help resource is unchanged).

tag = "dip1mom" if action == "flip1" else "dip2mom"
flipped = -numeric_vector(widgets[tag].text(), dtype=float)
widgets[tag].setText(" ".join(format(float(value), "g") for value in flipped))
widgets[tag].setText(" ".join(f"{float(value):.3f}" for value in flipped))

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: Flip rounds CTF moments to 3 decimals, even though the dialog shows 6.

This PR shows moments with 6 decimals when coordformat is CTF (lines 84 and 337). This flip branch always formats with .3f, so on a CTF dataset, Flip (in|out) silently drops the last three decimals. On OK, _apply_nonlinear_gui_model parses dip1mom/dip2mom from the widget text, so the rounded moment ends up in EEG.dipfit.model and in the history command. Small CTF moments can round to 0.000.

Suggested fix: use the same precision for flipping. params["eeg"] is already available in this function, so pull the CTF check into one helper and use it in all three places:

def _moment_precision(EEG: dict[str, Any]) -> int:
    return 6 if str(dipfit_record(EEG).get("coordformat", "")).upper() == "CTF" else 3
precision = _moment_precision(params["eeg"])
widgets[tag].setText(" ".join(f"{float(value):.{precision}f}" for value in flipped))

Then add a CTF case to test_nonlinear_ok_keeps_the_flipped_moment: a dataset with coordformat="CTF" and a moment such as 1e-4. It should come back as -0.000100, not -0.000.

@arnodelorme

Copy link
Copy Markdown
Collaborator Author

🤖 Second round on the review above: the Flip precision change is held for Arno's decision. The branch now only carries its fixed parent (#1038, through #1039).

  • What the review asked: format a flipped CTF moment with 6 decimals, because OK reads the text back and a 3-decimal text loses small moments.
  • What EEGLAB does: the same rounding. pop_dipfit_nonlinear.m (EEGLAB 5e0be870) line 339 writes the flipped moment with '%0.3f %0.3f %0.3f' for every coordinate format, and OK reads the edit boxes back (dialog_getvalue, lines 220 and 314 to 321). Only dialog_setvalue uses %f for CTF (lines 301 to 303). So EEGLAB also stores a flipped CTF moment rounded to 3 decimals.
  • Why it is not applied here: the reviewer's fix is more precise than EEGLAB, so EEGPrep would store a different number from EEGLAB after a CTF flip. A numerical difference with EEGLAB needs Arno's explicit approval.
  • Ready if approved: the change with its test (one helper _moment_precision, a CTF case with a moment of 1e-4 that must read -0.000100 after Flip and survive OK) is prepared locally and is one commit. The same rounding could be reported to EEGLAB.

@arnodelorme
arnodelorme changed the base branch from agent/issue-1002-dipfit_settings to develop December 1, 2026 17:43
@arnodelorme
arnodelorme merged commit 1d39b49 into develop Dec 1, 2026
@arnodelorme

Copy link
Copy Markdown
Collaborator Author

Arno's decision (email of December 1, 2026): keep EEGLAB's three-decimal rounding of flipped CTF moments, as this branch does (option a). The six-decimal commit is not used. Merged into develop the same day. — orchestrator

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.

[GUI] Match the pop_dipfit_nonlinear dialog to EEGLAB

1 participant