Skip to content

Make chi2 matching the default everywhere - #34

Merged
jluastro merged 1 commit into
MovingUniverseLab:devfrom
wei-lingfeng:chi2-default
Nov 6, 2026
Merged

jluastro merged 1 commit into
MovingUniverseLab:devfrom
wei-lingfeng:chi2-default

Conversation

@wei-lingfeng

Copy link
Copy Markdown
Collaborator

matching='chi2' (added in f40cc18) is now the default in MosaicSelfRef, MosaicToRef, match.match, match.match_name_override, transform_and_match and generic_match. The last two now take matching, dchi2_tol and the chi^2 scales, which they previously had no way to set.

With 'legacy', a star with several candidates inside the tolerances is matched only if its nearest candidate in position is also its nearest in magnitude. In crowded fields that discards good matches -- a candidate 20x closer in position loses to one a few hundredths of a magnitude nearer -- and each discarded star becomes a duplicate reference row that makes the next starlist ambiguous in turn. 'chi2' keeps the reciprocal best pair by chi^2 if it wins by dchi2_tol (default 9, a 3-sigma margin), and leaves truly ambiguous stars unmatched.

Behavior change: 'chi2' is more conservative when two candidates are both plausible. In test_generic_match, two stars 1.8 px apart lie 0.61 and 1.17 px from one counterpart; 'legacy' picks the nearer (also 0.04 mag nearer), while 'chi2' leaves it unmatched (chi^2 margin about 6). With dm_tol=None, chi2 uses position only, and with few stars its position scale falls back to dr_tol/10. matching='legacy' reproduces earlier results.

test_match_duplicates and test_generic_match now check both rules. All 135 tests pass. Docs (alignment.rst) and CHANGES.rst are updated.

A before/after comparison on real data will follow.

The legacy rule matched a star with several candidates only if its nearest
candidate in position was also its nearest in magnitude. In crowded fields
that discards good matches, and each discarded star becomes a duplicate
reference row. 'chi2' is now the default in MosaicSelfRef, MosaicToRef,
match.match, match.match_name_override, transform_and_match and
generic_match; the last two now take matching, dchi2_tol and the chi^2
scales. 'legacy' stays available.

test_match_duplicates and test_generic_match now check both rules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@jluastro jluastro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me.

@jluastro
jluastro merged commit da02684 into MovingUniverseLab:dev Nov 6, 2026
4 checks passed
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.

2 participants