Skip to content

fix(sextractor): tolerate WCS inversion divergence in post-process - #825

Merged
cailmdaley merged 1 commit into
developfrom
pr/sx-postprocess-wcs-divergence
Jul 14, 2026
Merged

cailmdaley merged 1 commit into
developfrom
pr/sx-postprocess-wcs-divergence

Conversation

@cailmdaley

Copy link
Copy Markdown
Contributor

Problem

During the Nibi test run in #808, the SExtractor post-processing step crashed on some tiles with astropy NoConvergence errors from inverse-WCS evaluation, while the same configuration had previously run cleanly. The regression appeared with the astropy 6 → 7 pin bump: astropy 7's epoch-matching changed which exposure footprints are evaluated, feeding positions far outside a CCD's valid WCS region into world_to_pix, where the iterative inversion diverges.

Root cause

Post-processing tests every object position against every exposure WCS with no footprint prefilter and no divergence tolerance; positions far off-CCD make the SIP inversion diverge and raise.

Fix

In sextractor_script.py / sextractor_runner.py (+95/-12 vs develop): prefilter objects against each exposure footprint before inversion, and tolerate residual divergence (quiet=True handling) instead of crashing, so far-off-CCD positions are simply counted as not-in-epoch.

Evidence / testing

  • A previously-succeeding tile reproduces bit-for-bit identical N_EPOCH values with the fix applied.
  • The previously-crashing tile now completes post-processing for all 31,927 objects with zero divergence warnings.

Found during the Nibi test run in #808.

— Claude (Fable) on behalf of Cail.

🤖 Generated with Claude Code

make_post_process epoch-matching inverse-projects every tile object
through every exposure CCD's WCS. With astropy 7 / wcslib 8.4 the
iterative de-distortion (disx2p) raises InvalidCoordinateError for
positions far outside a CCD's distortion domain - routine for tile
objects several CCDs away - killing the whole tile (7/10 CFIS P3
tiles failed; the astropy 6 stack used previously did not raise).
wcs_world2pix diverges identically, so there is no linear fallback.

Fix: forward-project (pixel to world, always well defined) the CCD
centre and corners to get its sky footprint, and inverse-project only
objects within 1.5x the footprint radius; everything else can never
pass the CCD bounds test. If the inversion still diverges for a
near-footprint batch, log how many objects were skipped for that
exposure/HDU and record no epoch for them instead of raising.

Validation on CFIS P3: a previously-succeeding tile reproduces its
N_EPOCH column bit-for-bit; a previously-crashing tile completes with
a sane epoch distribution (all objects >= 1 epoch, max = its 9
contributing exposures) and zero divergence warnings.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@martinkilbinger martinkilbinger 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.

Nice fix! I remember I saw this behaviour in the past but didn't know how to solve it.

@cailmdaley
cailmdaley merged commit 4a92a4c into develop Jul 14, 2026
3 checks passed
@cailmdaley
cailmdaley deleted the pr/sx-postprocess-wcs-divergence branch July 14, 2026 11:11
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