Skip to content

Reject ngmix epochs only when a defect touches the object's own footprint (D0) - #983

Draft
cailmdaley wants to merge 2 commits into
developfrom
feat/defect-veto-footprint
Draft

cailmdaley wants to merge 2 commits into
developfrom
feat/defect-veto-footprint

Conversation

@cailmdaley

@cailmdaley cailmdaley commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Blocked: footprint registration. SEG_VIGNET is cut on the tile grid around the tile barycentre. The epoch stamps are cut on the exposure grid around a separately projected, rounded centroid, and only MegaCamFlip relates the two. On 188.307 (object 5422, epoch 2254827-27), a zero-weight defect 2 px from the centre lies inside the object's footprint according to the WCSs, but the overlay labels it sky, so D0 keeps the epoch. The census and the survey's D0 numbers use the same overlay, so neither validates the decision. The same overlay feeds uberseg neighbour masking and #973's footprint diagnostics on develop. Its size is being measured before this PR is reworked.

Reject an epoch when a raw defect pixel touches the object's own ISO footprint (SEG_VIGNET == NUMBER), without dilation.
This removes the fixed 7/13-px central veto and its constants, with no configuration flag or radius fallback.
Both interpolated and noise-filled defects count, including unflagged zero-weight pixels, invalid background RMS and off-tile pixels; neighbours and clean symmetry copies do not.
The 10% masked-fraction cut runs first.

Cail decided to remove the fixed veto (25 Oct). D0 is the replacement this PR proposes, chosen from a catalogue-level bias/loss scan of five rules.
The scan combines modeled fixture biases with measured prevalence and multi-epoch dilution on tile 188.307.
These are nominal, unweighted, one-tile estimates, not a survey calibration or a guarantee for every retained defect.

Rule Max |m| Max |c| Loss
Fixed 7/13-px veto 2×10⁻⁵ 5×10⁻⁷ 2.2% of epochs
Keep everything, flag only 5×10⁻⁵ 2×10⁻⁵ None
Cut flagged objects 1×10⁻⁵ 5×10⁻⁶ 5.7% of objects
D0: footprint touch 1×10⁻⁵ 5×10⁻⁶ 1.3% of epochs
D2: footprint dilated 2 px 2×10⁻⁵ 2×10⁻⁶ 2.0% of epochs

The catalogue limits are 1×10⁻² for m and 5×10⁻⁴ for c.
Every nominal value passes by more than 10×; the keep-everything arm's conservative fixture envelope crosses the additive limit.

Catalogue-level bias relative to requirements

What to weigh. The margin is wide at nominal values and narrow under stress. With the unrestricted-size stress fixtures (open diamonds), D0's multiplicative bias reaches about 0.9 of the requirement, whereas the fixed veto (A) stays near 0.01 of it. D0's margin therefore rests on the size-matched fixtures being representative. The trade is about one percentage point of epochs (1.6% lost against 2.2%) for a much thinner worst case. Flag-only (B) is ruled out: its size-matched envelope already crosses the additive limit.

Edge cases and diagnostic contract

A border-touching footprint is tested within the stamp, the same domain used for the fit.
A missing or empty footprint rejects the epoch because overlap cannot be established; an absent object label is an upstream inconsistency, not clean data.
A shape mismatch raises; uberseg also requires the SEG_VIGNET column before the object loop.
These policies need no fixed radius.

The epoch-cut counter is footprint_defect throughout ngmix logs, workflow parsing, manifests, aggregation, completeness checks and cleaning.
The durable aggregate schema is 2; schema-1 records fail completeness rather than having their counts relabelled.
Affected chunks/manifests need regeneration.
The ASTRA decision, its code markers and the committed universe pin select shape_measurement.footprint_defect_veto: d0.

The #973 defect records and final-catalogue columns stay available.
Complete kept footprints have zero ISO defect hits under D0; clipped footprints retain the -1 unknown sentinel, and never-fit rows retain zero counts.
Stamp-wide interpolation counts and minimum defect distances still support stricter downstream cuts.
The fill/weighting shear-recovery fixtures test their stated geometries independently of epoch selection.
Footprint-based selection still needs shear-selection calibration.

188.307 production check

Validation uses the retained survey catalogue, flags, weights, RMS, images, backgrounds, PSFs and WCS stores, with blend_handling=uberseg and defect_fill=interpolate.
It invokes the real prepare_postage_stamps path without fitting galaxies or modifying input stores.
D0 rejects 1,791/115,299 eligible epochs (1.553%) and retains 113,508.
The 120,421 considered epochs and 5,122 masked-fraction rejections match the survey census.
There are zero mismatches with the survey's cached raw-footprint overlap decisions.

Footprint case Objects / 36,051 Considered epochs / 120,421 Eligible epochs / 115,299
Empty 0 0 0
Border-touching 633 (1.756%) 2,121 (1.761%) 2,028 (1.759%)

D0 rejects 316 eligible border epochs.
The survey's D0 row uses a fixed-radius fallback for clipped footprints and rejects 1,550/115,299 (1.344%).
The production border policy rejects 246 epochs that fallback keeps and keeps 5 it rejects: 251 changed decisions, all at the border, and 241 net extra rejections. The survey's in-stamp sensitivity run (optimistic_unknown_footprints.D0 in the survey's combined.json) applies the same border policy as production. It rejects the same 1,791 epochs, loses 50 objects (against 15 with the fallback), and gives nominal max |m| ≈ 1.4×10⁻⁵ and max |c| ≈ 5.2×10⁻⁶ within the same transport model.
Thus the table's 1.3% and the production 1.553% use different border policies, not different defect definitions.
The fixed-radius arm loses 2,565/115,299 (2.225%).
The eligible denominator is 113,749 kept + 1,550 rejected = 115,299; 113,749 alone is the survey D0 kept count.

The reproducible census is committed as scripts/validation/masked_pixels/d0_prevalence_188307.json; the full output and per-epoch comparison arrays are /scratch/cdaley/veto-d0/188.307.{json,npz}.

Reproduction and test receipts

All tests and measurements run in Slurm allocation 25321432, account def-waerbeke, 4 CPUs, 16 GiB, node c647, using /project/6001537/cdaley/containers/shapepipe-develop-240b37e4.sif.
From /scratch/cdaley/wt-veto-d0, with PYTHONPATH=$PWD/src:$PWD:

python scripts/validation/masked_pixels/d0_prevalence.py \
  --inputs /scratch/cdaley/veto-survey/prevalence_checks.json \
  --survey /scratch/cdaley/veto-survey/prevalence.npz \
  --out /scratch/cdaley/veto-d0/188.307.json --nproc 2
python -m pytest -m 'not slow' -o addopts='' -q
python scripts/validation/masked_pixels/mutate_d0.py \
  --out /scratch/cdaley/veto-d0/mutant.log

/scratch/cdaley/veto-d0/run-sif.sh runs the census with the allocation, SIF, paths and single-threaded BLAS settings.
run-local-sif.sh runs the suites with the same environment and node-local /tmp for temporary files.
Workflow tests use Snakemake 9.23.1 from /project/6001537/cdaley/snakemake-env/lib/python3.12/site-packages, appended to PYTHONPATH, with PYTEST_DISABLE_PLUGIN_AUTOLOAD=1.
SHAPEPIPE_ON_CANDIDE=1 is scoped to the workflow suite so both profile fixtures execute; the generic off-Candide guard otherwise skips the fixture named candide even though it only parses configuration.

SHAPEPIPE_ON_CANDIDE=1 PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 \
  python -m pytest tests/workflow -o addopts='' -q -rs

The checked-in radius mutant runs only against a private source copy.
It is killed by 9 failing tests (11 pass, 39 deselected), including a close defect outside the footprint, a distant footprint hit, border hits, unavailable footprints and off-tile overlap.
These are assertion failures, not collection failures.

At the pushed head, the full not-slow suite passes 1,160 tests, with 4 skips and 2 slow deselections (229.84 s).
At the same head, the workflow suite passes 50 tests, with no skips, under Snakemake 9.23.1 (19.13 s).
The focused footprint/fill/counter/decision run passes 156 tests.
Logs are not-slow-clean.log, targeted.log, workflow-final.log, mutant-final.log, prevalence-final.log, decisions-final.log and astra-validation.log under /scratch/cdaley/veto-d0/.
ASTRA Tools 0.2.17 validates both astra.yaml and universes/committed.yaml.


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

🤖 Generated with Claude Code

https://claude.ai/code/session_01JK7o9Hh6QZraQK3Vr2diyz

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