sp_validation.pseudo_cl

Pseudo-Cl / harmonic-space estimator primitives for cosmology validation.

Stateless shared primitives for the pseudo-Cl (harmonic-space) estimator, mirroring b_modes.py and rho_tau.py: the orchestrator mixin in sp_validation.cosmo_val.pseudo_cl (and analysis scripts directly) call these free functions. Everything here is pure computation – NaMaster binning, weighted galaxy number-density maps, random-rotation noise debiasing, and the map-/catalog-based pseudo-Cl estimators. Depends on pymaster (NaMaster) and healpy.

The harmonic geometry the estimators use is fixed by nside: lmin = 8, lmax = 2 * nside, b_lmax = lmax - 1. pseudo_cl_geometry returns that triple so the binning and the fields stay in lockstep.

pseudo_cl_geometry(nside)[source]

Return (lmin, lmax, b_lmax) for the pseudo-Cl estimator at nside.

lmax = 2 * nside is the NaMaster band-power ceiling; b_lmax = lmax - 1 is the field/binning lmax. lmin is the fixed low-ell floor.

make_namaster_bin(lmin, lmax, b_lmax, binning, *, ell_step=10, n_ell_bins=32, power=0.5)[source]

Build a NaMaster binning object for one of the supported schemes.

Parameters:
  • lmin (int) – Multipole range.

  • lmax (int) – Multipole range.

  • b_lmax (int) – Maximum multipole for the NmtBin object.

  • binning ({'linear', 'logspace', 'powspace'}) – Binning scheme.

  • ell_step (int, optional) – Bin width in ell for 'linear' binning.

  • n_ell_bins (int, optional) – Number of ell bins for 'logspace' / 'powspace' binning.

  • power (float, optional) – Exponent for 'powspace' binning.

Return type:

nmt.NmtBin

get_n_gal_map(nside, ra, dec, weights=None)[source]

Weighted galaxy number-density HEALPix map plus pixel bookkeeping.

Bins (ra, dec) (degrees) onto an nside HEALPix grid. With weights=None each object counts as 1 (galaxy counts); pass per-object weights for a weight-summed occupancy map.

Returns:

  • n_gal (np.ndarray) – Map of summed weights (or counts) per pixel, shape (npix,).

  • unique_pix (np.ndarray) – Sorted unique occupied pixel indices.

  • idx (np.ndarray) – First-occurrence indices into the input from np.unique.

  • idx_rep (np.ndarray) – Inverse map: pixel-group index for each input object.

apply_random_rotation(e1, e2, rng=None)[source]

Apply a uniform random rotation to ellipticity components.

Parameters:
  • e1 (np.ndarray) – Ellipticity components.

  • e2 (np.ndarray) – Ellipticity components.

  • rng (np.random.Generator, optional) – Random generator for the rotation angles. Pass a seeded generator (e.g. np.random.default_rng(seed)) for reproducible draws; when None a fresh entropy-seeded generator is used (non-reproducible).

Returns:

e1_out, e2_out – Rotated ellipticity components.

Return type:

np.ndarray

get_pseudo_cls_map(shear_map, mask, nside, binning, *, pol_factor=True, wsp=None, ell_step=10, n_ell_bins=32, power=0.5)[source]

Map-based pseudo-Cl for a complex shear map.

Parameters:
  • shear_map (np.ndarray) – Complex shear map (e1 + 1j * e2).

  • mask (np.ndarray) – Field mask (the galaxy number-density map).

  • nside (int) – HEALPix resolution; fixes the harmonic geometry.

  • binning (str) – Binning scheme passed to make_namaster_bin().

  • pol_factor (bool, optional) – If True flip the sign of the imaginary (e2) component.

  • wsp (nmt.NmtWorkspace, optional) – Reuse a coupling workspace; built from the field if None.

  • ell_step (optional) – Binning-scheme parameters forwarded to make_namaster_bin().

  • n_ell_bins (optional) – Binning-scheme parameters forwarded to make_namaster_bin().

  • power (optional) – Binning-scheme parameters forwarded to make_namaster_bin().

Returns:

  • ell_eff (np.ndarray) – Effective multipoles of the bandpowers.

  • cl_all (np.ndarray) – Decoupled EE/EB/BE/BB spectra, shape (4, n_bands).

  • wsp (nmt.NmtWorkspace) – The coupling workspace (newly built or the one passed in).

get_pseudo_cls_catalog(catalog, params, nside, binning, *, pol_factor=True, wsp=None, ell_step=10, n_ell_bins=32, power=0.5)[source]

Catalog-based pseudo-Cl via NaMaster’s NmtFieldCatalog.

Parameters:
  • catalog (np.ndarray) – Structured catalog array with the columns named in params.

  • params (dict) – Column-name mapping (ra_col, dec_col, w_col, e1_col, e2_col).

  • nside (int) – HEALPix resolution; fixes the harmonic geometry.

  • binning (str) – Binning scheme passed to make_namaster_bin().

  • pol_factor (bool, optional) – If True flip the sign of the e2 component.

  • wsp (nmt.NmtWorkspace, optional) – Reuse a coupling workspace; built from the field if None.

  • ell_step (optional) – Binning-scheme parameters forwarded to make_namaster_bin().

  • n_ell_bins (optional) – Binning-scheme parameters forwarded to make_namaster_bin().

  • power (optional) – Binning-scheme parameters forwarded to make_namaster_bin().

Returns:

  • ell_eff (np.ndarray) – Effective multipoles of the bandpowers.

  • cl_all (np.ndarray) – Decoupled EE/EB/BE/BB spectra, shape (4, n_bands).

  • wsp (nmt.NmtWorkspace) – The coupling workspace (newly built or the one passed in).