Skip to content

Cut postage stamps in-house and reuse their exact centroid in ngmix (drop sf_tools)#811

Open
cailmdaley wants to merge 3 commits into
developfrom
feat/inhouse-stamp-extraction
Open

Cut postage stamps in-house and reuse their exact centroid in ngmix (drop sf_tools)#811
cailmdaley wants to merge 3 commits into
developfrom
feat/inhouse-stamp-extraction

Conversation

@cailmdaley

@cailmdaley cailmdaley commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Closes #767.

ShapePipe cuts a small "postage stamp" image around every object before measuring its shape with ngmix. Until now the cutting was done by sf_tools (unmaintained for years), and ngmix independently re-computed the object's position — through a different WCS library — to place its centroid prior. Two computations of the same number can disagree: near a rounding tie, a milli-pixel WCS difference rounds to a different pixel and puts the prior a full pixel off the stamp it was cut from (#767).

What changes

  • In-house cutter. vignetmaker.get_stamps() replaces sf_tools.FetchStamps: zero-pad by the stamp radius, slice around round(pos). Bit-identical to sf_tools for in-bounds objects (tested directly against it, plus a hand-computed golden test that keeps the behavior pinned once sf_tools is uninstalled). An out-of-bounds centre now raises instead of being silently wrapped modulo the image shape.
  • One centroid, shared. The cutter records the rounded pixel (INT_POS) and sub-pixel offset (OFFSET) alongside each vignette in the same sqlite entry — no sidecar file. ngmix's wcs centroid consumes the stored OFFSET instead of re-projecting and re-rounding: one projection, one rounding, so the stamp and the centroid prior cannot disagree. This is Axel's condition on ngmix centroid: switched to WCS in #741 — confirm correct, and any reason to keep HSM? #767, met by construction.
  • CENTROID_SOURCE hsm|wcs stays selectable, so the eventual real-data hsm-vs-wcs comparison runs against a single pipeline.
  • sf_tools dropped from pyproject.toml, uv.lock, and the module depends.

Note: vignette files produced before this change carry no OFFSET; running new ngmix on them with CENTROID_SOURCE wcs fails fast with a message saying to regenerate the vignettes. Intended — a propagated offset genuinely doesn't exist for old files.

Out of scope: the real-data hsm-vs-wcs A/B (needs a real-data run), and removing the HSM path (the open question on #767).

— Claude on behalf of Cail

🤖 Generated with Claude Code

cailmdaley and others added 3 commits July 12, 2026 23:25
vignetmaker's postage-stamp extraction no longer calls sf_tools'
FetchStamps. A shapepipe-owned get_stamps() zero-pads by the stamp radius
and slices around the rounded integer pixel — bit-identical to
FetchStamps for in-bounds objects (checked against it directly in the
tests), but an out-of-bounds centre now raises instead of being silently
wrapped modulo the image shape.

The extractor also records, per object per epoch, the integer extraction
pixel and the sub-pixel offset (catalog float minus rounded int). Both
ride on the multi-epoch vignette — in its sqlite entry alongside VIGNET,
no sidecar file. ngmix's "wcs" (coadd) centroid source now consumes that
stored OFFSET instead of re-projecting the sky position through galsim
and re-rounding: one projection, one rounding, so a milli-pixel WCS
disagreement can no longer flip a rounding tie and put the centroid prior
a whole pixel off (#767).

CENTROID_SOURCE hsm|wcs stays selectable. sf_tools is removed from
pyproject.toml, uv.lock, and the two module depends lists.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KusTeTS6EHFXkwevF4vqaX
- Drop sf_tools from docs/source/dependencies.md (the one tracked file the
  dep removal missed).
- prepare_postage_stamps reads OFFSET with .get() rather than [] so the
  "hsm" path, which never uses it, is not coupled to the field. The "wcs"
  path still fails fast on a missing offset — the error now fires precisely
  where the data matters instead of as an incidental KeyError in the shared
  stamp-prep loop.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KusTeTS6EHFXkwevF4vqaX
… gone

The bit-identity test importorskips sf_tools, which this branch uninstalls —
so CI would silently skip it forever. The golden test hand-derives expected
stamps arithmetically (value = 10*row + col), covering round-half-to-even
ties and edge zero-padding, independent of the pad/slice implementation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T1af8cuFLwE9MsHkAiYHJG
@cailmdaley cailmdaley changed the title Own the stamp extraction in-house; propagate the coadd centroid (drop sf_tools) Cut postage stamps in-house and reuse their exact centroid in ngmix (drop sf_tools) Jul 12, 2026
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.

ngmix centroid: switched to WCS in #741 — confirm correct, and any reason to keep HSM?

1 participant