Skip to content

ENH: helper to warn about bad coregistration - #14599

Merged
larsoner merged 6 commits into
mne-tools:mainfrom
Mal-1702:enh-warn
Dec 1, 2026
Merged

larsoner merged 6 commits into
mne-tools:mainfrom
Mal-1702:enh-warn

Conversation

@Mal-1702

@Mal-1702 Mal-1702 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6552

What does this implement/fix?

In the issue as it was said that, it should give a warning if distances are above 5mm
so the fix I added is :
built an independent helper function _warn_bad_coregistration with limit=0.005 by default in the function and not calling it in dig_mri_distances and compute_dig_mri_distances in which I chose the median method to work on and also ran tests in
mne/tests/test_surface.py which validates it

Additional information

Usage of Claude AI has been used in this for reviewing the code and understanding the issue in more detail also credits to @TzionaN as I have been taking it as an reference to solve this

Called in Report.add_trans as @larsoner suggested and performed the test which conveyed the message median 6.9mm on the wrong fsaverage. The warning fires in test_manual_report_3d in mne/report/tests/test_report.py

@welcome

welcome Bot commented Nov 25, 2026

Copy link
Copy Markdown

Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴

@larsoner

Copy link
Copy Markdown
Member

I think it makes sense to use _warn_bad_coregistration in Report.add_trans only (skip plot_alignment and make_forward_solution). Coreg GUI already rates the fit and the class already logs it so I don't think we need them there, either.

@Mal-1702
Mal-1702 marked this pull request as ready for review December 1, 2026 18:42
@Mal-1702

Mal-1702 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@larsoner Thanks for the help, I have added it in Report.add_trans just please check the changes and let me know if further changes are to be done.

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making the two suggested tweaks now and pushing, then I'll merge. Thanks @Mal-1702

Comment thread mne/tests/test_surface.py Outdated
)


def test_warn_bad_coregistration():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need the separate test since it's already tested in the report code...

Comment thread mne/surface.py Outdated
return dists


def _warn_bad_coregistration(dists, limits=0.005): # default 5 mm

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we don't ever set limits to anything else or use this elsewhere, so we can just simplify and move into report.py directly

@larsoner
larsoner enabled auto-merge (squash) December 1, 2026 18:51
@Mal-1702

Mal-1702 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews and tweaks @larsoner will keep these things in mind from here on.

@larsoner
larsoner merged commit e47bf55 into mne-tools:main Dec 1, 2026
26 checks passed
@Mal-1702
Mal-1702 deleted the enh-warn branch December 1, 2026 19:53
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.

ENH: Warn if distances are bad

2 participants