Skip to content

v2 n(z) beyond the pure SOM: clustering redshifts against DESI DR1 and a spectroscopic-selection term - #486

Open
cailmdaley wants to merge 20 commits into
developfrom
feat/nz-selection-term
Open

cailmdaley wants to merge 20 commits into
developfrom
feat/nz-selection-term

Conversation

@cailmdaley

@cailmdaley cailmdaley commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

#468 calibrates the v2 n(z) with a SOM on DEEP2/3 spectra alone. This PR, stacked on it and meant for the release after 2.0.0, explores two things that pure-SOM calibration leaves open: a clustering-redshift check against DESI DR1, and an uncertainty term for the spectroscopic selection of the calibrators.
The delivered n(z) does not change.

Every number and figure below is from a run before #468's rework (old calibrator source, old edges). The code is now ported onto the reworked #468 (calibrators from the collection's spec-z extension, sp_validation.nz subpackage), and the numbers are to be replaced by a rerun of the recipe.
Clustering confirms where each bin's core sits but cannot tell the DEEP2/3 calibration from one on every survey in the field, so the selection term stays a prior. Nothing here updates the delivered n(z).

Where the clustering work is going (16 Nov). The SOM leaves 46% of the shear weight without a bin, 26% of it because no representative spectra exist (SOM groups without a spectrum 5.7%, galaxies missing one band 14.0%, Z_B ≥ 1.2 6.7%; #484). Clustering needs only overlap with DESI, so it is being tried as the calibration for those galaxies and as a second estimate for the gold bins. A first combination of the two is on branch feat/nz-combination, one commit on top of this PR (sp_validation/nz/combination.py): SOM realisations weighted by the clustering likelihood, with the source-bias slope marginalised. Preliminary, on the four gold bins of the 13 Nov run:

⟨z⟩ bin 1 bin 2 bin 3 bin 4
SOM, with the selection term 0.283 ± 0.050 0.451 ± 0.010 0.618 ± 0.017 0.923 ± 0.017
SOM × clustering 0.282 ± 0.049 0.447 ± 0.009 0.614 ± 0.016 0.938 ± 0.016
clustering alone, SOM shape free to shift and stretch, slope prior 1 ± 1 0.285 ± 0.014 0.421 ± 0.016 0.585 ± 0.017 0.929 ± 0.017

n(z) of the four gold bins: DESI clustering points, the SOM weighted by clustering, and clustering alone

Points: DESI DR1 cross-correlations divided by the fitted bias. Blue: the SOM ensemble weighted by the clustering likelihood. Orange: clustering alone, with the SOM's shape free to shift and stretch. The points follow the SOM in every bin and lean to lower redshift in bins 2 and 3.

Uncertainty and mean redshift per bin for each estimate

Left: uncertainty of the mean redshift per bin. Right: mean redshift relative to the SOM's.

  • The combination agrees with the SOM and tightens it by under 10%: the SOM's remaining error is in tails that clustering does not constrain.
  • Clustering alone is as tight as the SOM in bins 3 and 4 (0.022–0.026 with the slope free) and puts bins 2 and 3 about 0.03 lower, under 2σ each. Its bin-1 error is small only because it assumes the SOM's tail.
  • Not yet measured: the clustering n(z) of the galaxies the SOM cannot calibrate, and a known-answer test on a GLASS sky with clustered tracers. Both are queued on Nibi.

Clustering redshifts

sp_validation.nz.clustering (entry point scripts/calibration/clustering_nz.py, figures from scripts/calibration/plot_clustering.py, configured by a clustering section in the same recipe as the SOM run) cross-correlates the gold sources of each bin with DESI DR1 BGS, LRG, ELG and QSO in thin redshift slices, over the 3,610 deg² the two surveys share.
In each slice the annulus is fixed at 1.5–5 Mpc/h comoving; the slice's autocorrelation gives the reference bias, and the cross-correlation gives n(z) b(z) of the bin.
The sources' bias is unknown, modelled as b ∝ (1+z)^α, so the test is on each bin's shape inside a core window, with amplitude and α free.
Errors come from a 100-patch jackknife; fits use the full covariance with the Hartlap correction, and the shift is profiled over α, flagged when α reaches the edge of its grid anywhere inside the Δχ² = 1 interval.
An optional overlapping-tracer test (example: LRG and ELG over 0.80–1.10) checks that two tracers with different bias give the same n(z) where they overlap; window edges must sit on the slice grid and inside both catalogues' redshift support, checked before anything is measured.

Known answer first. A random half of DESI LRG plays the unknown sample against the other half, through the same code.

Known-answer gate

Recovered n(z) of the held-out LRG half (points) against its true redshift histogram (line). χ² = 16.8 for 14 slices; the preferred shift of the true n(z) is +0.005 (−0.007 to +0.018).

The bins.

Clustering n(z) of the four gold bins

Clustering n(z) per bin (points, divided by the best-fit bias slope and amplitude) against the SOM n(z) of the pre-rework #468 run (black) and the same gold sources calibrated on every survey in EGS (dashed). Each panel quotes χ² of the two inside the shaded fit window, and the shift Δz of the #468 n(z) preferred at α = 1 with its Δχ² = 1 range.

  • The bins are where the SOM puts them. χ² per bin is 4.7/7, 7.2/7, 6.8/8 and 7.8/14.
  • Clustering cannot separate the two calibrations. Their χ² differ by at most 0.7. They differ in the high-redshift tails, where the QSO slices are too noisy to help.
  • Shifts of about 0.03 are allowed. At α = 1, bins 2 to 4 prefer −0.033, −0.033 and +0.035 at about 2σ. The shift is degenerate with the bias slope (the free-α fit runs to the edge of its range in bins 2 and 3), so I don't read these as detections and nothing is changed for them.
  • Limits. Separations below 1.5 Mpc/h fail the gate. Magnification is not modelled; it matters outside the core windows.
  • These numbers predate the full-covariance, profiled fit. They come from diagonal errors at fixed α = 1 and are replaced by the rerun on Nibi.

Spectroscopic-selection term

DEEP2/3 are one spectroscopic selection, and other surveys put different redshifts at the same colours.
The recipe's ensemble.specz_selection.surveys names every survey with 100 or more spectra in EGS; the pipeline selects them from the collection's spec-z extension inside the same EGS bound as the fiducial calibrators (35,553 spectra, 17,069 of them DESI DR1, against 9,917).
In the pre-rework run (23,800 alternative spectra from a positional re-match), calibrating the same gold sources on them moved ⟨z⟩ by +0.098, +0.015, +0.024 and +0.025. ensemble.specz_selection.scale: 0.5 adds a Gaussian multiple of that difference to each realisation, which puts the alternative at 2σ before clipping.
Each draw is then clipped at zero and renormalised. Clipping narrows the term where the fiducial n(z) is near zero, as in bin 1's tail, so the ensemble records per bin the nominal and realised ⟨z⟩ scatter of the selection term and the fraction of mass clipped. The table below is nominal; the realised widths come with the rerun. Redefining the term as a mixture between the two calibrations would be positive by construction, at the cost of leaning only toward the alternative; that choice waits for the realised numbers.

σ⟨z⟩ bin 1 bin 2 bin 3 bin 4
#468 0.0045 0.0033 0.0037 0.0037
with the term 0.050 0.010 0.017 0.018

Bin 1 is set by catastrophic outliers: 0.4% of its DEEP2/3 calibrators lie above z = 1.5, against about 5% of the other surveys' spectra.
Without those objects its shift is +0.021 and σ⟨z⟩ is 0.011.
DEEP2 cannot measure most redshifts above 1.4 and targeted surveys over-represent them, so the truth for our sources is between the two; the factor 0.5 is a prior, and the main thing to discuss here.

The table and the bin-1 numbers are from that pre-rework run on Nibi and are replaced by the rerun.

Validate

  • pytest src/sp_validation/tests/test_nz_clustering.py src/sp_validation/tests/test_nz_ensemble.py in the container: known-answer tests of the estimator and of the term.
  • python scripts/calibration/clustering_nz.py config/calibration/nz/v2.yaml --prepare --measure --workers 32 after a step-5 run (about 80 minutes on 32 cores), then python scripts/calibration/plot_clustering.py config/calibration/nz/v2.yaml DIR. It needs the DESI DR1 LSS catalogues v1.5 under the desi_dr1 data root (today only on Nibi), unions_data to resolve for its output, and the step-5 run's calibration_arrays.npz and ensemble_inputs.npz in the recipe's output directory.
  • Not yet checked on data after the port: that with the term switched on the run reproduces v2 tomographic n(z): SOM calibration on ID-joined PhotoPipe photometry, with realisations #468's means and bin counts. In the test suite, a toy run with alternative calibrators shifted by +0.05 stores a shift that moves ⟨z⟩ by 0.05.
  • realisations.npz carries the selection term's nominal and realised ⟨z⟩ scatter and clipped-mass fraction per bin.

— Claude (Fable 5.2, revised by Opus 5.5 after review and after the port onto the reworked #468) on behalf of Cail

🤖 Generated with Claude Code

https://claude.ai/code/session_01JK7o9EnxYTbKnCgY2bUv5d

Cail Daley and others added 19 commits November 13, 2026 00:33
Each realisation adds a Gaussian multiple of the difference between the n(z)
calibrated on alternative calibrators (every survey of the compilation in the
field) and the calibration's own, on the same gold sources.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9DrKRWmYBVJKThNsk8
sp_validation.nz_clustering cross-correlates the gold bins with DESI DR1
tracers in thin redshift slices, driven by the recipe's clustering section:
prepare, measure, analyse, with a known-answer gate on half of DESI LRG.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9EnxYTbKnCgY2bUv5d
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… redshifts to sp_validation.nz

The n(z) code now lives in sp_validation.nz and reads the v2 release and
collection. #486's additions move with it:

- nz_clustering.py becomes nz/clustering.py; prepare reads the source
  catalogue through io.read_catalogue (the released HATS catalogue), the
  footprint from the release's masks/, and writes outside the release.
- The spectroscopic-selection term's alternative calibrators are
  nz.inputs.calibrators on the spec-z extension with the term's survey list
  and the fiducial field, z_min and z2 fill. The recipe keeps them with the
  term (ensemble.specz_selection: scale, surveys); pipeline.run loads them
  and calibrate writes calibrators_selection.npz and selection_shift.
- The ensemble recentres on the calibration's n(z), reports the raw mean,
  then clips negative cells and renormalises, with clipping diagnostics.
- New ASTRA decisions specz_selection and nonnegative_draws, tagged in the
  recipe and ensemble.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…at/nz-selection-term

# Conflicts:
#	docs/source/stages.md
#	scripts/calibration/README.md
…stering.py

analyse writes clustering.json only; the script draws clustering_gate.png and
clustering_nz.png from it and the run's SOM n(z), reusing plot_nz.py's style.
The package no longer imports matplotlib here, and --figures is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7o9J6AyWxjASXRUrZDsa
#468 now stacks on the v2 HATS collection build (#493); stages.md takes its
assembly row and keeps nz/clustering.py in the Calibrate row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cailmdaley added a commit that referenced this pull request Nov 15, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/source/stages.md
…on step: drop plot_clustering.py

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cailmdaley
cailmdaley changed the base branch from feat/som-nz-calibration to develop November 15, 2026 17:30
cailmdaley added a commit that referenced this pull request Nov 15, 2026
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.

1 participant