Skip to content

The calibrated v2 sample, built by sp_validation and checked against its snapshot - #490

Open
cailmdaley wants to merge 30 commits into
feat/consistent-response-weightsfrom
feat/calibrated-sample-build
Open

cailmdaley wants to merge 30 commits into
feat/consistent-response-weightsfrom
feat/calibrated-sample-build

Conversation

@cailmdaley

@cailmdaley cailmdaley commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

The calibrated v2 sample is now built by sp_validation itself, from one recipe and one Snakemake rule, and the build reproduces the released v2.0.0 catalogue object by object. Closes #480.

It also calibrates each galaxy with the response of its own tomographic bin.
The bins' responses are 0.855, 0.859, 0.832 and 0.776 against 0.787 for the whole sample, so one R for everything puts the shear of bins 1–3 high by 6–9%.
Once the n(z) stage has assigned the bins, a second step measures each bin's R and c and rewrites the catalogue's e1, e2 with them.
Open, and to settle before merging: whether the per-bin calibrated shear is written into the catalogue, as here, or the catalogue keeps one calibration and each bin's response is applied when a statistic is measured, as DES Y3 does. The numbers are the same either way. The release on VOSpace is not changed by this PR.

Stacked on #425, which defines the weights, response, c and m once in sp_validation.response; this PR builds the sample with that module and reads the HATS collection of #493 (merged).

Why

The released sample (191,016,178 galaxies on 22,901 tiles) was built by run scripts outside the repository, against two sp_validation checkouts that are not develop. Nothing checked its tile set against the ShapePipe snapshot, which is how the first version missed a ~540 deg² wedge (#480).

What changed

  • sp_validation.sample: the build as library code. pipeline.run(recipe, output, workers) reads the collection's shapes one HEALPix pixel at a time, cuts tile overlaps against the whole snapshot's tile set, applies the selection, sums the moments that give the DES weight table and the global response and additive bias, then writes each pixel calibrated, with OBJECT_ID. It writes no comprehensive intermediate. compare pairs two calibrated catalogues on the DR6 object ID (OBJECT_ID, or computed from TILE_ID and NUMBER; on position when neither gives one) and reports the largest difference per column.
  • Recipe and rule: config/calibration/sample/v2.yaml names the snapshot, shapes, selection config and release directory. workflow/calibrate/Snakefile (or the main workflow, when its config has a calibrate block) runs it in the image, optionally followed by the comparison. The commands are in scripts/calibration/README.md.
  • The snapshot is checked twice. The build stops unless the shapes name the manifest's SHA-256 and hold exactly each tile's manifest object count. The catalogue records the snapshot (name, tile count, manifest SHA-256) in its HATS properties. A cat_config.yaml entry names the snapshot it expects under shear.snapshot, and cosmo_val stops at start if the catalogue records a different one.
  • The response and weights come from One definition of shear response, weights, additive bias and image-sim m (DES case d) #425's sp_validation.response, summed pixel by pixel. Besides the catalogue, the build writes catalogs/response_sums.npz (the per-tile sums the response is estimated from) and the tile-jackknife covariance of R in response.json.
  • sp_validation.sample.bins and the rule bin_responses: the response of each tomographic bin. One pass over the collection gives every preselected galaxy its bin from its photometry with the n(z) stage's saved model, held fixed across the metacal branches, and reduces the rows to sums per (tile, bin) with the sample's weight table held fixed. It stops unless the bins are those of nz/tom_bin.parquet and the bins' sums add to the sample's. Each bin's record (R, its shear and selection parts, c, tile-jackknife covariance) goes into catalogs/response.json under bins, the galaxies in no bin included as bin 0. The step then rewrites the catalogue: each row gets its TOM_BIN_ID and e = R_k⁻¹(g − c_k) with its own bin's R_k and c_k. The rewrite is staged whole and installed together with the record, so an interrupted run cannot leave a catalogue its record does not describe.
  • Decisions (snapshot record, overlap cut, selection cuts, weights and response, per-bin calibration, additive bias, leakage correction, footprint, orchestrator) are recorded in the dr6_catalogue ASTRA record, with their alternatives.

Why Snakemake and not Lightcone. Lightcone (lc 0.5.1) does not run recipes in an existing image: it builds its own, which apptainer cannot do on Fir. lc init also turns the project into a git-annex dataset, which every clone of this repository would inherit. A Snakemake rule runs in the same image as every validation rule. The ASTRA record keeps Lightcone as the alternative.

Validation

rebuilt vs released

Rebuilt from 03d5cc1 (on #425's sp_validation.response; 3 min on 60 cores on Fir) and compared with data/v2.x/v2.0.0/catalogs/calibrated:

  • 191,016,178 rows in each; every row is paired, 191,016,152 on OBJECT_ID and 26 on exact position (the release's NUMBER = −1 rows); none in only one catalogue.
  • RA, Dec, PSF ellipticity, SIZE_RATIO, SNR, N_EPOCH, TILE_KEY are identical. |Δe| ≤ 3e-14, |Δw|/w ≤ 1.1e-14 (tolerance 1e-10); R agrees to 1e-16.
  • The footprint (25,491,778 pixels at nside 4096) is identical, and so is the count after every cut:

cut flow

  • No difference from the two release checkouts changed a row or a value.
  • Run from the README alone: an agent with no other context followed scripts/calibration/README.md on a fresh working directory, without reading source, and got the same 191,016,178 rows with agree: true (6.5 min on 16 cores). The nine places it had to guess are now written into the README.
  • Tests (test_sample.py, test_sample_record.py): the chunked build equals in-memory metacal on synthetic data; an end-to-end HATS run; the snapshot guards (manifest SHA, status, per-tile counts); compare with missing rows and NaN; response sums with non-finite coordinates. Fast suite on this branch: 882 passed.
  • An independent review found that Snakemake would have deleted an existing release before rebuilding it (it removes a job's declared outputs). The rule now declares only the build's last file, and the build refuses to write over an existing catalogue.

Per-bin calibration

R_shear, R_sel and R of the whole sample and of each tomographic bin

Sample share of weight R_shear R_sel R
Whole sample 1 0.758 +0.029 0.787
Bin 1 0.143 0.870 −0.015 0.855
Bin 2 0.136 0.835 +0.024 0.859
Bin 3 0.124 0.801 +0.031 0.832
Bin 4 0.141 0.736 +0.041 0.776
In no bin 0.456 0.696 +0.040 0.735

Means of the diagonal; tile-jackknife errors are 1–4 × 10⁻⁴. The selection part is 2–5% of R and changes sign between bins.

The bins step run on a copy of the release (4 minutes on 64 cores, reading the 772,677,301-object collection and rewriting the 191,016,178-row catalogue):

  • Positions, weights, row counts and TOM_BIN_ID are identical to the release in all 1,817 files, and the new shear equals R_k⁻¹(R_all e + c_all − c_k) of the released shear to 2 × 10⁻¹⁶.
  • It reproduces the tomographic data vector measured with the response applied at measurement. That measurement (the blinded tomographic SACC now in the release) gave per-bin σ_e = 0.26518, 0.26179, 0.27293, 0.27744; the rewritten catalogue gives the same five digits. In that measurement every B-mode statistic of bin pair (i, j) changed by the predicted factor (R_all/R_i)(R_all/R_j): 50 fits over ten pairs and five statistics, largest pull 2.1σ.
  • The whole-catalogue σ_e moves from 0.28899 to 0.28807.
  • The weighted mean shear of each bin is below 5 × 10⁻⁸. It is not exactly zero because 9 galaxies without a released object ID sit in bin 0 in the catalogue and in bins 2–4 in the sums.
  • An independent review reproduced one defect, now fixed with a test: a run interrupted between rewriting the catalogue and writing its record made the next run calibrate twice.

Not checked: the build on a tile set other than run1-snap3, a rebuild on another machine, the response of the bin assignment itself (a galaxy's bin is held fixed across the metacal branches), and the same per-bin step on mocks.

Caveats

  • The SP_v2.0.0 entry now names its snapshot, and the released catalogue records none, so cosmo_val on that entry fails until the release's catalogs/calibrated is replaced by a rebuild. On edge this one cat_config.yaml block is left out until then.
  • The SP_v2.0.0 entry here describes the per-bin calibrated catalogue (its cov_th σ_e values are those of the per-bin shear). The catalogue now in the release is calibrated with the whole sample's R.
  • The sample build's output has OBJECT_ID, which the release lacks, and no TOM_BIN_ID; the bins step adds it.

— Claude (Opus, then Fable) on behalf of Cail

🤖 Generated with Claude Code

https://claude.ai/code/session_01JK7o9ESjsJpK9G5wRraxC1

cailmdaley and others added 11 commits November 14, 2026 13:03
… feat/calibrated-sample-build

# Conflicts:
#	src/sp_validation/tests/test_column_schema.py
sp_validation.sample reads a snapshot's shapes (the v2 collection), selects
with the committed mask config, sums the weight-table moments and response
sums over HEALPix pixels, and writes the calibrated HATS catalogue with
OBJECT_ID and a record of the snapshot it was built from.

- response: the DES table is fitted from per-cell moments, and the response
  from per-cell sums, both additive over chunks of a catalogue.
- metacal: global_response=False stops after the branch selections and the
  per-object shear response.
- galaxy: the tile-overlap cut takes the survey's tile set, so a chunk of a
  catalogue finds its neighbours.
- io: an entry that names a snapshot is checked against its catalogue's.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9GGvpp2uq6JnvoG4Pa
…k an entry's snapshot at cosmo_val start

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9GGvpp2uq6JnvoG4Pa
…EADME and orchestrator decision

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9GGvpp2uq6JnvoG4Pa
…d what the comparison writes

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9GGvpp2uq6JnvoG4Pa
… feat/calibrated-sample-build

# Conflicts:
#	docs/source/stages.md
#	src/sp_validation/tests/test_column_schema.py
…n counts NaN and missing rows, NUMBER keeps its type

The rule declares only the build's last file, so Snakemake's removal of
declared outputs cannot reach catalogs/calibrated and the build's own refusal
to overwrite holds on the workflow route. Tests pin the per-tile manifest
check, unpaired rows and NaN in the comparison, the survey statistics, and the
response sums on nonfinite coordinates.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9GGvpp2uq6JnvoG4Pa
… feat/calibrated-sample-build

# Conflicts:
#	docs/source/stages.md
cailmdaley and others added 2 commits November 15, 2026 07:14
…ample-build

The assembly files take #493's versions; stages.md keeps the sample's
calibrate entries on #493's layout.

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

The n(z) (nz_*.py, its recipe, calibrate_nz.py, tests, README section and the
TOM_BIN_ID change to the Gaussian-sims script) came in with the earlier
collection branch and is #468's; the assembly wrappers are replaced by #493's
recipe and rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cailmdaley
cailmdaley changed the base branch from develop to feat/hats-collection-index November 15, 2026 14:25
cailmdaley added a commit that referenced this pull request Nov 15, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	config/calibration/nz/v2.yaml
#	docs/source/stages.md
#	scripts/calibration/README.md
#	scripts/calibration/calibrate_nz.py
#	src/sp_validation/nz/calibration.py
#	src/sp_validation/nz/ensemble.py
#	src/sp_validation/tests/test_column_schema.py
#	src/sp_validation/tests/test_nz_calibration.py
#	src/sp_validation/tests/test_nz_ensemble.py
#	src/sp_validation/tests/test_nz_inputs.py
@cailmdaley
cailmdaley changed the base branch from feat/hats-collection-index to develop November 15, 2026 15:52
cailmdaley and others added 5 commits November 15, 2026 09:51
…ple build

Conflicts resolved with #425's response.py and calibration.py as the
truth; io.py and cosmo_val/core.py keep the sample's snapshot check
beside #425's weight check and additive_bias import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9ESEcatXjL8bDkTC5c
…ir rows

A chunk accumulated over the tiles it holds stays small; gather places
each into the full label set in place, so a catalogue read pixel by pixel
never builds a dense per-chunk array over every tile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9ESEcatXjL8bDkTC5c
Each pixel accumulates response.Sums over the tiles it holds (Cuts and
table_edges from the metacal block, the dat cuts as preselection);
Sums.gather adds them into every snapshot tile; fit_table, estimate and
the refitted delete-one-tile jackknife give the table, R, c_e and their
covariance; each pixel is written with response.calibrate and the
table's weights. New product catalogs/response_sums.npz keeps the sums,
grouped by TILE_KEY. Tests compare the build with
response.calibrate_catalogue on all rows at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9ESEcatXjL8bDkTC5c
…ibrated sample port

The n(z) modules are develop's (#468) and stay. response.py is #425's.
In the dr6_catalogue record, #425's response, weight, table, uncertainty
and additive-bias decisions are the definitions; the sample's
weights_and_response becomes sample_wide_calibration (one table and one
R for the whole sample, from sums that add over pixels), and #425's
additive_bias takes the sample's note on patch scatter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9ESEcatXjL8bDkTC5c
#425's weight_table decision pins response.calibrate_catalogue#des_min_count,
the default of metacal.get("des_min_count", 3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9ESEcatXjL8bDkTC5c
@cailmdaley
cailmdaley changed the base branch from develop to feat/consistent-response-weights November 15, 2026 18:14
cailmdaley added a commit that referenced this pull request Nov 15, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cailmdaley and others added 5 commits November 15, 2026 15:44
sp_validation.sample.bins passes over the collection once, gives every
preselected row its TOM_BIN_ID from its photometry with the n(z) stage's
saved model (fixed across metacal branches), accumulates response.Sums per
(tile, bin) with the release's cuts, edges and weight table, and writes each
bin's response.record under "bins" in catalogs/response.json. It stops
unless every tom_bin.parquet galaxy with an object ID is selected with its
released bin (the galaxies it does not name by ID being as many as its rows
without one), and unless the bins' sums add to response_sums.npz.

Rule bin_responses (workflow/rules/calibrate.smk), script
scripts/calibration/bin_responses.py, synthetic tests, docs, ASTRA note.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
…mo_val, scripts pass) into the calibrated sample build

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9E2jzNjuJU8HV3b13n
…librated sample build

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9ESjsJpK9G5wRraxC1

# Conflicts:
#	scratch/cdaley/unions_astra/analyses/dr6_catalogue/astra.yaml
#	src/sp_validation/cosmo_val/core.py
#	src/sp_validation/io.py
cailmdaley and others added 7 commits November 16, 2026 05:43
… response

bins.run measures a record for every bin, bin 0 (no bin) included, then
rewrites the catalogue: each row gets its TOM_BIN_ID from nz/tom_bin.parquet
and e = R_k^-1 (g - c_e,k), g recovered from the shear and the calibration the
file carries, so a second run leaves it as it is. A record with bins says the
catalogue carries each row's bin's R and c_e. The sample's record names its
weights.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9ESjsJpK9G5wRraxC1
…etakes the sample's survey statistics

Every file and then the record are staged before any is installed, and a run
that finds a staged record installs it first, so an interrupted run cannot
leave a catalogue its record does not describe. Object IDs come from TILE_ID
and NUMBER, as the sample build makes them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9ESjsJpK9G5wRraxC1
…ne weight table for the sample

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9ESjsJpK9G5wRraxC1
…uild

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9ESjsJpK9G5wRraxC1

# Conflicts:
#	scratch/cdaley/unions_astra/analyses/dr6_catalogue/astra.yaml
…s calibration

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9ESjsJpK9G5wRraxC1
cailmdaley added a commit that referenced this pull request Nov 23, 2026
…les hold, calibrated-sample provenance, fetch manifest without local paths and with a fresh checksum list

survey_stats.py needs sp_validation.response (#490) and goes with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9FJPrhcYFM7drXAZcJ

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.

Calibrated sample: build in sp_validation, and check its tile set against the snapshot manifest

1 participant