sp_validation.mocks.painted¶
Catalogue-painted GLASS mocks: a known lensing signal on a real catalogue.
A painted mock keeps everything about a real shear catalogue except the
cosmological signal: its galaxy positions, weights, PSF columns and the
modulus of each calibrated ellipticity. Each ellipticity is rotated to a
random angle, which erases the real shear, and a lognormal GLASS sky is
sheared onto it. Every seed draws an independent sky and independent
rotations; only the geometry is fixed, as it is for the one real data vector,
so the scatter across seeds is the variance conditional on the survey’s
geometry. The sampled mocks of mocks.glass draw synthetic galaxies
instead.
Two stages, each with its own CLI and workflow rule:
generate_lensing_mapsmakes one sky per seed: lognormal matter shells frommocks.glass’s cosmology, projected through a single source n(z). Its product is the convergence alm (kappa_alm.npz);spectra.npzholds that alm’s realised spectra beside the shell-ensemble theory. Seed-independent shell spectra are solved once and cached (prepare_lensing_spectra).paint_cataloguestreams a catalogue and evaluates convergence and shear at each galaxy position with a non-uniform spherical-harmonic transform (evaluate_alm). No pixel window enters anywhere: the shells are drawn from unwindowed spectra and the sky is never read off a pixel grid. Optional injections, PSF leakagealpha e_PSF, a constant additive term and a pure-B field, are added on top of the same noise, so a catalogue with an injection differs from the clean one by exactly the injection.
Skies are kept as alms in npz: they are inputs to painting, not data vectors.
Anything measured on a painted catalogue goes through cosmo_val to SACC.
Maps follow HEALPix; catalogue e2 is pol_factor times HEALPix gamma2
(-1 for UNIONS, as in cosmo_val), and every output records it.
glass and ducc0 are imported inside the functions that use them.
- source_shell_weights(z, nz, shells)[source]¶
Normalized non-negative GLASS partition of a single source n(z).
- projected_convergence_weights(pars, shells, weights)[source]¶
Linear response of the n(z)-averaged convergence to matter shells.
- projected_theory(cls, transfer, lmax, ncorr=3)[source]¶
Exact shell-ensemble convergence and shear-E spectra.
The source partition and the finite
ncorrcovariance are identical to the map generator’s. The spin-2 / convergence conversion is spherical, including its low-ell factor (not the flat-sky approximation).
- solve_shell_spectra(fields, cls, workers=1)[source]¶
GLASS’s padded solver, parallel over independent shell pairs.
Returns Gaussian spectra, achieved matter spectra, and solver status. Spawned processes each use one native thread; the caller’s OpenMP setting is restored before map generation. No fork follows CAMB’s OpenMP runtime.
- check_gaussian_solve(requested, achieved)[source]¶
Worst residual of the lognormal solve; raises above
SOLVER_TOLERANCE.The residual of each pair is
max_l |achieved - requested| / sqrt(C_ii C_jj). Scaling by the autos rather than the pair’s own spectrum keeps it finite where a cross-spectrum crosses zero, which is where GLASS’s own convergence flag misfires.
- prepare_lensing_spectra(config, cache_dir, workers=1)[source]¶
Cache seed-independent matter/Gaussian spectra and source theory.
A lock serializes writers. The key includes cosmology, shell geometry, resolution, n(z) contents, GLASS version and the correlation truncation. No seed enters the key. Cache files contain numeric arrays only. The spectra are unwindowed: the shells are sampled at pixel centres, never averaged over pixels, so the map’s alm carries no pixel window. Every call checks the cached solve (
check_gaussian_solve) and returns its worst residual asspectra["solver_residual"].
- shear_alm(kappa_alm)[source]¶
Shear E-mode alm of a convergence alm.
The spherical spin factor
-sqrt((l+2)(l-1)/(l(l+1))), as GLASS’sshear_from_convergenceapplies it. The shear maps and the painted catalogue both derive from this function.
- evaluate_alm(alm, ra, dec, *, epsilon=1e-10, nthreads=1)[source]¶
Non-uniform spherical-harmonic synthesis at sky positions (degrees).
almhas shape(1, nalm)for a scalar field or(2, nalm)for the(E, B)pair of a spin-2 field, in healpy ordering. Returns(1, N)or HEALPix-convention(Q, U)=(gamma1, gamma2)of shape(2, N). This isducc0.sht.experimental.synthesis_general: the band-limited sum at each position to relative accuracyepsilon, with no pixel window (a nearest-pixel lookup of a map would add one). Each call has a fixed setup of about one full-sky synthesis (~4 s at lmax 8192 on 28 threads, ~75 s on one) and a negligible per-point cost (16M points in under 5 s on 28 threads), so callers pass millions of positions at a time.
- generate_lensing_maps(config, output_dir, cache_dir, workers=1)[source]¶
Save the projected convergence alm, its maps, and its spectra.
Matter shells are lognormal, with three neighbouring cross-correlations. Source-plane convergence is integrated before the linear shear transform, avoiding a spherical transform for every source shell.
kappa_alm.npz(complex128 healpy-orderedalmof the convergence map up tolmax, andnside) is the sky thatpaint_catalogueevaluates. The float32gamma1/gamma2maps are its shear E mode synthesised on the grid;kappais GLASS’s pixel convergence, of which the alm is the band-limited transform. Therealization_*spectra are the alm’s own full-sky power (KK, EE, KE; gamma has no B mode), what a catalogue painted withshear='gamma'carries;cl_kk/cl_eeare the shell-ensemble theory they scatter around, with no pixel window. A statistic measured on a footprint scatters around the realisation by that footprint’s sample variance; the same statistic of the noise-freeg*_truecolumns is the exact answer for one footprint. Reduced shear adds its own EE and BB.
- draw_b_mode_alm(cl_bb, seed)[source]¶
Seeded Gaussian B-mode alm with power spectrum
cl_bb.Painting evaluates the alm at each galaxy, so
cl_bbis the injected spectrum with no pixel window. This uses a local Generator, not healpy’s process-global RNG.
- b_mode_cl(lmax, amplitude=0.0, path=None)[source]¶
Injected C_BB on
ell = 0..lmax, orNonewhen nothing is injected.amplitudegivesA exp[-(ell/2000)^2];pathnames a two-columnell C_BBtext file, interpolated linearly and zero outside its range.
- paint_shear(e1, e2, signal, rng, *, psf=None, alpha=0.0, additive=(0.0, 0.0), b_signal=None, shear='gamma', pol_factor=-1)[source]¶
Paint one block of rows, with all returned components in catalogue convention.
signal=(kappa, gamma1, gamma2)andb_signal=(b1, b2)are the HEALPix-convention fields at the rows’ positions (evaluate_alm). The calibrated input |e| is preserved by the uniform spin-2 rotation, onerng.uniformdraw per row in row order.shear='gamma'applies gamma directly for pure-E unit-test skies;shear='reduced'applies gamma/(1-kappa). The selected signal is stored asg1_true/g2_truein either case.e_noiseis the intrinsic rotated epsilon, not e_mock minus g, because ellipticity composition is nonlinear.e_injectedis added afterwards. Catalogue e2 ispol_factortimes the HEALPix component.
- paint_catalogue(input_path, output_path, maps_dir, seed, *, ra_col='RA', dec_col='Dec', e1_col='e1', e2_col='e2', w_col='w_des', psf_cols=('e1_PSF', 'e2_PSF'), alpha=0.0, additive=(0.0, 0.0), b_cl=None, b_seed=None, chunk_size=250000, block_size=8000000, nthreads=None, epsilon=1e-10, column_map=None, overwrite=False, shear='gamma', pol_factor=-1, keep=())[source]¶
Stream a FITS/HDF5 catalogue into an HDF5 mock (root
datatable).Uses the same lazy
Cataloguereader asread_cataloguewith bounded row slices, including single-dataset 138M-row HDF5 catalogues. The sky is the convergence alm inmaps_dir(kappa_alm.npz). Its convergence, shear E mode (shear_alm) and any injected B mode are evaluated at each galaxy position (evaluate_alm), so the sky’srealization_*spectra and the B alm’s power are what the catalogue carries (seegenerate_lensing_maps). Rotation angles come fromSeedSequence(seed, spawn_key=(1,)), a stream independent of the sky’sdefault_rng(seed), one uniform per row in row order, so a seed gives the same noise whatever the chunk and block sizes. Rows are read inchunk_sizeslices of the needed columns and evaluated in blocks ofblock_sizerows onnthreadsthreads (defaultdefault_threads()): each evaluation pays a fixed setup of about one full-sky synthesis (~4 s at lmax 8192 on 28 threads) and almost nothing per row; memory grows by a few hundred bytes per block row on top of an lmax-dependent constant (~7 GB at lmax 8192). The mock carries an allowlist of input columns, in the reader’s canonical grammar: position, weight, PSF ellipticities and anykeepnames. Every other column is dropped. A mock is measured under its own throwaway blind, so a measured shape passed through (e*_uncal, say) would reach cosmo_val outside the data blind; the allowlist is what prevents that, and it gives the mock a fixed schema.e1_col/e2_colande*_leak_correctedhold the mock shapes. Catalogue e2 ispol_factortimes HEALPix gamma2 (-1for UNIONS). Output is atomic; the HDF5 attributes and a JSON sidecar record the injection andpol_factor.