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: object

Fixed 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 Planck18 matter/baryon densities are read at construction time so the dataclass carries concrete numbers (not an astropy object) and round-trips cleanly to a reference.

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
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.

property lmax: int

lmax is tied to nside in the production mocks.

property Oc: float

Cold dark matter density (CDM = matter - baryons), pre-neutrino.

build_camb_params(config: GlassMockConfig)[source]

Build the CAMB parameters for a mock, with As rescaled to sigma8.

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_feedback non-linear model with HMCode_logT_AGN, neutrino mass subtracted from CDM, and an iterative As rescaling so the realized sigma8(z=0) matches config.sigma8.

Returns the CAMB CAMBparams object; camb_sigma8 reads the realized value back out.

camb_sigma8(pars) float[source]

Realized sigma8(z=0) for a CAMB parameter set.

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 via MultiPlaneConvergence and shear via shear_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 mask unchanged when it is already at nside.

growth_factor(z, om0)[source]

Normalised linear growth factor D(z) (scalar or array z).

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 overdensity delta of 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 NmtFieldCatalog construction rather than delegating to the pseudo_cl.get_pseudo_cls_catalog primitive: 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_bin so 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 NmtField construction rather than delegating to the pseudo_cl.get_pseudo_cls_map primitive: 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_bin and get_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_map primitive: delegates to it with weights=None (counts). Imported lazily so this module keeps resolving in CAMB-only environments without the harmonic stack.

compute_leakage_harmony(cat, cat_star, nside=1024, lmin=8, n_bins=32)[source]

Harmonic-space PSF-leakage rho_0 / tau_0 from galaxy + star catalogues.

Returns (rho_cl, tau_cl): the PSF-PSF (rho_0) and galaxy-PSF (tau_0) decoupled pseudo-Cl, each with the effective-ell axis prepended.