Skip to content

Fix stale motion after single-epoch refits; require 4 epochs for Parallax - #36

Open
wei-lingfeng wants to merge 4 commits into
MovingUniverseLab:devfrom
wei-lingfeng:fix-fixed-fastpath-stale-motion
Open

wei-lingfeng wants to merge 4 commits into
MovingUniverseLab:devfrom
wei-lingfeng:fix-fixed-fastpath-stale-motion

Conversation

@wei-lingfeng

@wei-lingfeng wei-lingfeng commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Two fixes for MosaicToRef/MosaicSelfRef runs that lost most of their matches on dev compared with mm_rework (OB150211 pass 1).

1. Stale motion after a single-epoch refit (introduced in cea7916). In iterations after the first, update_ref_table_aggregates sends stars with at most one epoch to combine_lists_xym, which sets x0/y0 to that epoch's position but leaves the motion model, t0, and the motion parameters from the previous fit. predict_positions then moves the star with its old velocity from the old t0, so it is misplaced at every other epoch. With clustered epochs, stars stop matching and split into several reference rows. Such a star now comes out as fit_motion_models leaves it, and as flystar did before cea7916: Fixed at its measured position, with NaN motion parameters, until a second epoch gives it a motion again. Models that can keep a star on its initial values (Orbit) are left alone.

An earlier version of this PR instead shifted x0/y0 so the old trajectory passed through the new position. That keeps the reference motions from one iteration to the next. In a self-referenced loop (MosaicToRef against the previous iteration's stars), a smooth pattern in those motions is invisible to polynomial transformations, so it grew each iteration and the loop stopped converging (Westerlund 1 pass 3). Dropping the motion, as before cea7916, anchors it, so no extra frame constraint is needed.

2. Parallax with 3 epochs. MotionModel gets a min_epochs class attribute: the default fewest epochs before the model is chosen (None means n_params). Parallax sets it to 4, as mm_rework did; 3 epochs within one season cannot separate parallax from proper motion. A run overrides it with the new min_epochs argument of MosaicSelfRef, MosaicToRef, and StarTable.fit_motion_models, a dict keyed by model name, e.g. MosaicToRef(..., min_epochs={'Parallax': 3}) to allow 3 epochs ({'Parallax': None} also means n_params). The override applies to that run only, including the bootstrap, and is written to the params log. Unknown model names and values below n_params raise. Only model selection uses it.

OB150211 pass 1, notebook settings (motion_models=['Parallax', 'Linear'], chi2 matching), stars detected in >= 6 of 12 epochs:

gaia3 gaia4
dev 4-6 8-9
this branch 203 202-203
earlier version (x0/y0 shift) 201-202 202-204
mm_rework 170-192 170-192

(ranges over the two dr_tol schedules used.) Median residual of each detection from its star's fit, gaia3: 0.98 mas with this branch, 2.0-2.4 mas with the shift; gaia4: 1.00 mas with both.

Tests: test_refit_from_one_epoch_drops_stale_motion (fails on dev: 437 reference rows for 150 stars), test_parallax_requires_min_epochs, test_check_min_epochs, and test_min_epochs_per_run. test_mosaic_fit_and_fixed_orbit_with_update_ref_orig is adjusted: its moving Linear star no longer sets the transformations (use_in_trans=False), and the period check compares with the fit's error (the initial period is 0.15 off; the error is about 0.8). It passes with both versions of the fix. Full suite: 140 passed. CHANGES.rst updated.

…llax

In iterations after the first, update_ref_table_aggregates sends stars
with at most one epoch to combine_lists_xym, which sets x0/y0 to that
epoch's position but leaves t0 and the motion parameters from the
previous fit (introduced in cea7916). predict_positions then moves the
star with its old velocity from the old t0, misplacing it at every other
epoch; with clustered epochs, stars stop matching and split into several
reference rows. x0/y0 are now shifted so that the star's existing
trajectory passes through the new position. t0 and the motion
parameters are kept, so catalog velocities still apply; a Fixed star is
unchanged.

MotionModel gets min_epochs, the fewest epochs before the model is
chosen (None means n_params), read through required_epochs(). Parallax
sets it to 4, as mm_rework did: 3 epochs in one season cannot separate
parallax from proper motion. Only model selection in
StarTable.fit_motion_models uses it.

OB150211 pass 1 with the notebook settings: stars detected in >= 6 of
12 epochs go from 4-9 on dev to 201-204 (mm_rework: 170-192).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wei-lingfeng and others added 3 commits December 2, 2026 16:29
MosaicSelfRef, MosaicToRef and StarTable.fit_motion_models take
min_epochs, a dict keyed by model name (e.g. {'Parallax': 3}), that sets
the fewest epochs before a model is chosen for that run only. The class
attribute stays as the default (4 for Parallax, n_params otherwise).
Unknown names and values below n_params raise. The aligners pass it to
every motion fit, including the bootstrap, and write it to the params log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the x0/y0 shift with the behavior fit_motion_models has, and that
flystar had before cea7916: a star with one valid epoch so far in an
iteration comes out of the fast path Fixed at its measured position, with
NaN motion parameters and infinite errors on them, until a second epoch
gives it a motion again. Only models that fit_motion_models demotes
outright (demote='always') are reset; Orbit keeps its elements, which are
the starting point of its fit.

Keeping the old motion (the shift) made the reference motions carry over
from one iteration to the next. In a self-referenced loop, such as the
Westerlund 1 pass 3 (MosaicToRef against the previous iteration's
members), a smooth motion pattern is invisible to the polynomial
transformations, so it then grows from iteration to iteration and the
loop no longer converges. Dropping the motion, as before, anchors it.

OB150211 pass 1 (Parallax + Linear, chi2, stars in >= 6 of 12 epochs):
202-203 with this change, 201-204 with the shift; median residual with
gaia3 0.98 mas, against 2.0-2.4 mas with the shift.

test_mosaic_fit_and_fixed_orbit_with_update_ref_orig: the moving Linear
star no longer sets the transformations (use_in_trans=False), and the
period check compares with the fit's error instead of requiring a value
closer to the truth than the initial guess, which is 0.15 off against an
error of about 0.8. It passes with both versions of the fix.

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

This branch has not been deployed

No deployments
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.

1 participant