Repository navigation
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
Open
cailmdaley wants to merge 20 commits into
cailmdaley wants to merge 20 commits into
Conversation
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>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JK7o9EQE4s8gF6uVCUhDyr
… 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
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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#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.nzsubpackage), 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: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.
Left: uncertainty of the mean redshift per bin. Right: mean redshift relative to the SOM's.
Clustering redshifts
sp_validation.nz.clustering(entry pointscripts/calibration/clustering_nz.py, figures fromscripts/calibration/plot_clustering.py, configured by aclusteringsection 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.
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) 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.
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.surveysnames 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.5adds 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.
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.pyin 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 32after a step-5 run (about 80 minutes on 32 cores), thenpython scripts/calibration/plot_clustering.py config/calibration/nz/v2.yaml DIR. It needs the DESI DR1 LSS catalogues v1.5 under thedesi_dr1data root (today only on Nibi),unions_datato resolve for its output, and the step-5 run'scalibration_arrays.npzandensemble_inputs.npzin the recipe's output directory.realisations.npzcarries 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