Skip to content

Line neighbour masks up with each exposure's own pixels - #985

Open
cailmdaley wants to merge 1 commit into
developfrom
fix/seg-exposure-grid
Open

cailmdaley wants to merge 1 commit into
developfrom
fix/seg-exposure-grid

Conversation

@cailmdaley

@cailmdaley cailmdaley commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #984.

ngmix now masks neighbours, off-tile pixels and the object's own footprint on each exposure's own pixels, not on a flipped copy of the tile stamp.

ngmix fits every galaxy on single-exposure stamps at native pixels, but those masks come from detection on the coadded tile. On develop the tile's VIGNET markers and SEG_VIGNET stamp are rotated for upside-down CCDs and pasted onto the exposure stamp. The tile and exposure grids are offset and slightly rotated relative to each other, so the pasted masks are misplaced: on tile 188.307 by 0.56 px at the median and 1.1 px at P95, with up to 1.8° of rotation. UberSeg masks differ in about half of all stamps.

displacement between flip-only and registered masks

The misplacement also mis-assigns defects. Here a bad column 2 px from the centre of object 5422 lies inside its footprint, but the flipped overlay puts it outside:

object 5422: flip-only vs registered footprint

What changes

  • Tile detection writes SEG_LABEL, each object's label in the SExtractor segmentation check image. The catalogue join renumbers NUMBER but keeps SEG_LABEL, so the check image can be relabelled to the final NUMBER (−1 for detections the join drops). make_cat drops it with the other stamp columns.
  • The multi-epoch vignetmaker takes segmentation.fits as a fourth input. For each image epoch, register_categories maps every stamp pixel centre through the exposure WCS and the tile WCS, takes the nearest tile pixel's label, and stores SEG_VIGNET (int32), NEIGHBOUR and OFF_TILE (bool) beside the stamp. Only integer labels are sampled; image, weight and flag stamps are untouched.
  • ngmix reads those three maps. It no longer reads the tile VIGNET or applies the MegaCam flip, and Postage_stamp loses its megacam_flip argument. Neighbours are every other nonzero label; UberSeg computes its partition on the registered labels.
  • astra.yaml records preparation.categorical_registration and drops shape_measurement.megacam_ccd_flip.

tests/module/test_register_categories.py checks the lookup against known answers: an exposure WCS shifted by whole pixels gives an exact slice of the tile segmentation, and a 180° WCS gives the rotated tile stamp. Subpixel offsets, a 17° rotation, a flipped CCD with SIP distortion and a stamp hanging over a rotated tile edge are checked against a per-pixel astropy round trip, and an end-to-end vignetmaker case checks the SEG_LABEL relabelling.

Effect on shapes

On 188.307 every object passing FLAGS=0, 10≤SNR_WIN≤500 was fitted twice, with the flipped overlay and registered, with identical seeds. For the 7,923 resolved, well-measured objects the response-only m-like shift is −1.9×10⁻³ ± 0.9×10⁻³, and the calibrated mean shifts are consistent with zero (−2.2×10⁻⁵ ± 3.4×10⁻⁵ and +3.9×10⁻⁵ ± 3.8×10⁻⁵ for the two components). Requirements are |m| < 10⁻² and |c| < 5×10⁻⁴. All 5,506 objects whose masks don't change reproduce all five metacal shapes bit for bit. This is one tile without known shear, so it measures how much shapes move, not a calibrated bias; treat it as a working number.

paired ellipticity differences

response shift and mask-area dependence

The study and a full sp run of 188.307 (tile detection to tile_make_cat; tile_vignets 6m26s, 14.1 GiB peak) used an earlier revision of this branch with the same lookup arithmetic. That revision also checked that tile and exposure celestial frames agree, which never changes a coordinate; this revision drops the check. The two operational bugs that run exposed are fixed separately in #1016.

Adoption

This belongs at a campaign boundary, including the calibration image simulations. Rerun from tile detection: image vignette stores made before this lack the three maps, and ngmix stops on them with a KeyError. The maps add about 1.9 GB per 120k epochs to the image vignette store.


Claude (Opus 5.5) on behalf of Cail; implemented and measured by GPT-6.1 Sol.

🤖 Generated with Claude Code

cailmdaley added a commit to cailmdaley/shapepipe that referenced this pull request Nov 1, 2026
cailmdaley added a commit to cailmdaley/shapepipe that referenced this pull request Nov 1, 2026
@cailmdaley cailmdaley changed the title Register tile segmentation and neighbour maps on each exposure stamp's own grid Line neighbour masks up with each exposure's own pixels Nov 1, 2026
cailmdaley added a commit that referenced this pull request Nov 6, 2026
Conflicts: only tests/workflow/params_pin.json and params_pin_noisefill.json,
both generated digests. Took neither side: regenerated both with
--update-params-pin on the merged tree. tile_vignets, tile_ngmix and
tile_make_cat move from edge's values, the three rules whose prologue carries
#985's mktemp WCS staging; every other rule keeps edge's digest, so #994's and
#997's exposure and tile-store changes stand as they were.

Everything else merged cleanly and needed no adaptation. #997's Snakefile
tile_store_root bind and #985's tile_local() edit touch separate lines, and the
vignetmaker configs #985 changed are not the exposure configs #994 changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9HXHK2JHphJN9p7BYu
ngmix fits each galaxy on single-exposure stamps at native pixels, but its
neighbour, footprint and off-tile masks come from detection on the tile.
They were the tile's VIGNET markers and SEG_VIGNET stamp, rotated for
upside-down CCDs and laid on the exposure stamp. The tile and exposure grids
differ by subpixel offsets and small rotations (median 0.56 px, P95 1.1 px,
up to 1.8 deg on tile 188.307), so the masks were misplaced.

- Tile detection writes SEG_LABEL, each object's check-image label, which
  the catalogue join keeps.
- The multi-epoch vignetmaker takes the segmentation check image as a fourth
  input. For every image epoch, register_categories maps each stamp pixel
  centre through the exposure and tile WCSs, takes the nearest tile label
  (relabelled to NUMBER through SEG_LABEL), and stores SEG_VIGNET,
  NEIGHBOUR and OFF_TILE beside the stamp.
- ngmix reads those maps instead of flipping tile stamps; it no longer reads
  the tile VIGNET, and Postage_stamp loses its megacam_flip switch.
- astra.yaml records preparation.categorical_registration and drops
  megacam_ccd_flip.

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.

ngmix overlays tile-grid segmentation and neighbour maps on exposure stamps without WCS registration

1 participant