sp_validation.glass_mock¶
GLASS mock generation core for UNIONS weak-lensing simulations.
The reproducibility surface of the UNIONS GLASS mocks lives here: the fixed
cosmology (Planck18 + HMCode AGN feedback, sigma8-rescaled CAMB power
spectrum) and the lognormal matter / lensing-map generation that turns a seed
into a sky. Galaxy sampling and catalogue I/O are a thin layer downstream
(scripts/glass_mock/make_unions_glass_sim.py), so that the load-bearing
config can be characterized in isolation — see
tests/test_glass_mock.py.
This module also collects the reusable two-point and PSF-leakage helpers the
mock post-processing runners in scripts/glass_mock/ share (configuration-
space ξ±, NaMaster pseudo-Cℓ, harmonic rho/tau, footprint masks).
The glass dependency is imported lazily inside the map-generation functions
so that this module — and therefore the import guard — resolves in any
environment with CAMB, even one without GLASS installed.
- class GlassMockConfig(nside: int = 32, seed: int = 42, dx: float = 200.0, zmax: float = 3.0, h: float = 0.6766, Om: float = 0.30966, Ob: float = 0.04897, ns: float = 0.9665, sigma8: float = 0.8102, mnu: float = 0.06, log_T_AGN: float = 7.8, As_init: float = 2.1e-09, kmax: float = 20.0, n_arcmin2: float = 6.0905, sigma_e: float = 0.2684, bias: float = 1.2, phz_sigma_0: float = 0.03, nbins: int = 1, ia_bias: float | None = None)[source]¶
Bases:
objectFixed configuration for a UNIONS GLASS mock realization.
Every field here is a value that must not silently drift: the cosmology (a Planck18 base with explicit
ns/sigma8/AGN-feedback choices), the shell construction (dx,zmax), and the resolution/seed. The characterization test pins these against a committed reference.Cosmology defaults reproduce the fiducial UNIONS v1.4.6.3 mock. The
Planck18matter/baryon densities are read at construction time so the dataclass carries concrete numbers (not an astropy object) and round-trips cleanly to a reference.- classmethod from_planck18(**overrides) GlassMockConfig[source]¶
Build a config with matter/baryon densities pulled from Planck18.
Keeps the dataclass defaults and the production script in sync with the single source of truth (
astropy.cosmology.Planck18) without making the dataclass depend on astropy at import time.
- build_camb_params(config: GlassMockConfig)[source]¶
Build the CAMB parameters for a mock, with
Asrescaled tosigma8.This is the cosmological heart of the mock and is GLASS-free: it reproduces the exact CAMB setup of the production script — Planck18 densities, HMCode
mead2020_feedbacknon-linear model withHMCode_logT_AGN, neutrino mass subtracted from CDM, and an iterativeAsrescaling so the realizedsigma8(z=0)matchesconfig.sigma8.Returns the CAMB
CAMBparamsobject;camb_sigma8reads the realized value back out.
- build_shells(config: GlassMockConfig, pars)[source]¶
Linear-window matter shells on a comoving distance grid.
Returns the GLASS shell list (
(z, w, zeff)windows). Lazily imports GLASS; only callable where GLASS is installed.
- matter_shell_cls(config: GlassMockConfig, pars, shells)[source]¶
Matter angular power spectra for the shells, from CAMB via GLASS.
- generate_matter_maps(config: GlassMockConfig, pars, shells, cls)[source]¶
Yield
(delta, kappa, gamma1, gamma2)HEALPix maps, shell by shell.This is the deterministic core of the mock at the map level: a seeded RNG drives lognormal matter fields (
ncorr=3), accumulated into convergence viaMultiPlaneConvergenceand shear viashear_from_convergence. For a fixed config + seed the emitted maps are bit-for-bit reproducible within a GLASS/NumPy version, which is what the self-consistency test asserts.The galaxy sampling that consumes these maps lives in the production script; keeping it out of this generator is what makes the map level testable.
- downgrade_mask(mask, nside)[source]¶
Downgrade a HEALPix mask to a lower
nside(>=0.75 -> 1, else 0).Returns
maskunchanged when it is already atnside.
- ia_convergence(delta, shell, config)[source]¶
Intrinsic-alignment contribution to the convergence (NLA model).
Mirrors the production NLA prefactor:
-A_ia * rho_c1 * Om0 / D(z_eff)applied to the matter overdensitydeltaof one shell.
- create_mask_from_catalogue(nside, path, output, ra_col='RA', dec_col='DEC')[source]¶
Write a HEALPix footprint mask from the populated pixels of a catalogue.
Pixels containing at least one object get 1.0, everything else 0.0.
- compute_two_point_xi(cat, config=None)[source]¶
Configuration-space shear 2PCF (treecorr
GGCorrelation) for a mock.
- compute_two_point_cl(cat, nside=1024, lmin=8, n_bins=32)[source]¶
Catalogue-based NaMaster pseudo-Cl for a mock shear field.
Returns
(cl_coupled, cl_all), each with the ell axis prepended.Deliberately keeps its own
NmtFieldCatalogconstruction rather than delegating to thepseudo_cl.get_pseudo_cls_catalogprimitive: the mock field is UNWEIGHTED (weights = ones, no per-object shear weight) and this function returns the COUPLED pseudo-Cl alongside the decoupled one (both with an ell axis prepended), which the primitive’s(ell_eff, cl_all, wsp)contract does not expose. The shared piece — the powspace binning — is taken from_mock_powspace_binso the bandpower drift is gone.
- compute_two_point_cl_map(cat, nside=1024, lmin=8, n_bins=32)[source]¶
Map-based NaMaster pseudo-Cl for a mock shear field.
Bins the galaxies onto a HEALPix shear map (count-weighted mean per pixel) and runs the MCM on the resulting masked field. Returns
(cl_coupled, cl_all)with the ell axis prepended.Deliberately keeps its own
NmtFieldconstruction rather than delegating to thepseudo_cl.get_pseudo_cls_mapprimitive: the mock shear map is built from UNWEIGHTED galaxy counts (the mask is the count map and the per-pixel mean divides by counts, not summed shear weights), and this function returns the COUPLED pseudo-Cl alongside the decoupled one (both with an ell axis prepended), which the primitive’s(ell_eff, cl_all, wsp)contract does not expose. The shared pieces — the powspace binning and the galaxy-count map — come from_mock_powspace_binandget_n_gal_map.
- get_n_gal_map(nside, ra, dec)[source]¶
Galaxy-count HEALPix map plus the unique-pixel bookkeeping arrays.
The unweighted twin of the pseudo-Cl
get_n_gal_mapprimitive: delegates to it withweights=None(counts). Imported lazily so this module keeps resolving in CAMB-only environments without the harmonic stack.