sp_validation.cosmo_val.pseudo_cl

Pseudo-Cl / harmonic-space diagnostic for cosmology validation.

This mixin holds the pseudo-Cl (harmonic-space) machinery: NaMaster field/workspace construction, the analytic (iNKA) Gaussian covariance, the OneCovariance Gaussian + non-Gaussian covariance, map- and catalog-based pseudo-Cl estimation, random-rotation noise debiasing, and plotting. It depends on pymaster (NaMaster), healpy, and OneCovariance.

_apply_pixel_window_to_fiducial_cl(fiducial_cl, nside, cell_method)[source]

Apply pw²(ℓ) to fiducial spectra only for HEALPix-map measurements.

Each spectrum array uses index ell, so the window spans the matching ell = 0..len(spectrum)-1 grid. Catalogue spectra are point-sampled and must remain unchanged.

plot_pseudo_cl_spectrum(datasets, spectrum, output_path)[source]

Two-panel ℓC_ℓ / C_ℓ figure for one spectrum across catalogue versions.

datasets maps a version to {"ell", "cl", "cov", "style"}, where style carries the marker and colour the version is drawn with.

_spectra(part)[source]

The ELL/EE/EB/BE/BB dict of a single-field pseudo-Cl part, whose BE is EB.

class PseudoClMixin[source]

Bases: object

property pseudo_cls
property pseudo_cls_onecov
calculate_pseudo_cl(compute_tomography=True, out_path=None)[source]

Compute the pseudo-Cl of a CosmologyValidation inputs with tomography.

With compute_tomography=False the single ("all", "all") pair is computed and written as a SACC part sealed under the version’s blind, by default to pseudo_cl_{ver}.sacc; out_path overrides that destination (one version only). An existing part is reused only if it was sealed under the blind declared now. With compute_tomography=True every tomographic bin pair is written to its own FITS file and out_path is not accepted; tomographic pairs are measured only on a public catalogue (_refuse_blinded_tomography()).

calculate_pseudo_cl_map(ver, nside, out_path, tomo_bin_a, tomo_bin_b)[source]
calculate_pseudo_cl_catalog(ver, out_path, tomo_bin_a, tomo_bin_b)[source]
calculate_pseudo_cl_inka_cov(compute_tomography=True, load_all_block=False)[source]

Compute the Gaussian iNKA covariance for EE, EB, and BB.

Apply the HEALPix pixel window pw²(ℓ) to each fiducial spectrum only when cell_method == "map". Catalogue-based spectra have no pixel window and use the unmodified fiducial.

calculate_pseudo_cl_onecovariance(tomography=False)[source]

Compute the pseudo-Cl covariance using OneCovariance.

calculate_pseudo_cl_g_ng_cov(tomography=False, gaussian_part='iNKA')[source]
get_namaster_bin(lmin, lmax, b_lmax)[source]

Build NaMaster binning object (thin wrapper, state -> primitive).

get_pixels(params, nside, cat_gal)[source]

Get unique pixels and indices for a catalog (thin wrapper -> primitive).

get_n_gal_map(params, nside, cat_gal, unique_pix=None, idx=None, idx_rep=None)[source]

Weighted galaxy number-density map (thin wrapper -> primitive).

get_shear_map(params, nside, cat_gal, unique_pix=None, idx=None, idx_rep=None, n_gal_map=None)[source]

Weighted shear map (thin wrapper -> primitive).

get_noise_realisation(params, nside, cat_gal, n_gal=None, unique_pix=None, idx=None, idx_rep=None, rng=None)[source]

Get a single Gaussian noise realization (thin wrapper -> primitive).

get_noise_bias_from_gaussian_real(params, nside, cat_gal, unique_pix=None, idx=None, idx_rep=None, n_gal_map=None, wsp=None)[source]

Noise-bias from Gaussian realisations (thin wrapper, state -> primitive)

get_noise_bias_analytical(params, nside, cat_gal, unique_pix=None, idx=None, idx_rep=None)[source]

Noise-bias from analytical prescription (thin wrapper, state -> primitive)

get_noise_bias(params, nside, cat_gal)[source]

Noise-bias estimation (thin wrapper, state -> primitive)

get_pseudo_cls_map(map_a, mask_a, wsp=None, shear_map_b=None, mask_b=None)[source]

Map-based pseudo-cl (thin wrapper, state -> primitive).

get_pseudo_cls_catalog(catalog, params, wsp=None, tomo_bin_a='all', tomo_bin_b='all')[source]

Catalog-based pseudo-cl (thin wrapper, state -> primitive).

read_redshift_distribution(ver, is_tomography)[source]
get_fiducial_cl(ver, is_tomography)[source]

Get a theory prediction for the angular power spectra (thin wrapper, state -> primitive).

_modify_onecov_config(template_config, config_path, out_dir, mask_path, redshift_distr_path, ver, tomography)[source]

Modify OneCovariance configuration file with correct mask, redshift distribution, and ellipticity dispersion parameters.

Parameters:
  • template_config (str) – Path to the template configuration file

  • config_path (str) – Path where the modified configuration will be saved

  • mask_path (str) – Path to the mask file

  • redshift_distr_path (str) – Path to the redshift distribution file

  • ver (str) – Version identifier for the current analysis

  • tomography (bool) – Whether to compute tomography or not

_update_onecov_cosmo_params(config, cosmo)[source]

Update the cosmological parameters in the OneCovariance configuration.

Parameters:
  • config (configparser.ConfigParser) – The configuration object to update.

  • cosmo – The cosmology object containing the parameters to set.

_load_onecovariance_cov(out_dir, ver, tomography)[source]
_get_tomographic_bin(params, cat_gal, tomo_bin)[source]

Extract tomographic bin from a given catalogue

_output_path_pseudo_cl(ver, tomo_bin_pair)[source]

Default pseudo-Cl product path of one bin pair.

The ("all", "all") pair is the SACC part pseudo_cl_{ver}.sacc; a tomographic pair is a FITS table under pseudo_cl/.

_output_path_pseudo_cl_cov(ver, method, tomography)[source]
_output_path_iNKA_block_cov(ver, tomo_bin_quad)[source]
_save_pseudo_cl(ver, out_path, tomo_bin_pair, ell_eff, cl_all, wsp, nside=None)[source]

Write one pair as SACC or FITS and return its spectra as written.

Forwards nside for map spectra. The ("all", "all") spectra are those of the part as sealed under the version’s blind.

_load_pseudo_cl(ver, out_path, tomo_bin_pair)[source]

One bin pair’s pseudo-Cl product written by _save_pseudo_cl.

None for an ("all", "all") part sealed under a blind other than the one ver declares now, which must be measured again.

pseudo_cl_to_sacc_part(version, out_path, ell_eff, cl_all, wsp, nside=None)[source]

Write the pseudo-Cl SACC part with its shared bandpower window.

cl_all is NaMaster’s decoupled (4, nbp) array (EE, EB, BE, BB). Map-based callers pass nside so the window includes pw²(ℓ); catalogue-based callers leave it unset because their spectra have no HEALPix pixel window. No covariance is attached here. Returns the part as sealed under the version’s blind.

save_pseudo_cl(ell_eff, pseudo_cl, out_path)[source]

Save a tomographic bin pair’s pseudo-Cl’s to a FITS file.

Parameters:
  • pseudo_cl (np.array) – Pseudo-Cl’s to save.

  • out_path (str) – Path to save the pseudo-Cl’s to.

_save_iNKA_covariance(covar, out_path)[source]
_merge_iNKA_covariance(ver, tomography)[source]

Merge the iNKA covariance matrices for a given version to get the data vector covariance.

plot_pseudo_cl(pol_list, versions=None, ell_factor='ell', cov_type='iNKA', offset=0.15, tomography=True, savefig=None, show=True)[source]

Plot the pseudo-Cl for EE power spectrum.

Parameters:
  • pol_list (list) – List of polarization types to plot (e.g., [“EE”, “BB”]).

  • ell_factor ({"None", "ell", "ell(ell+1)"}) – Factor to multiply the ell values by.

  • cov_type ({"iNKA"}) – Type of covariance to use.

  • tomography (bool, optional) – Whether to plot tomographic power spectra.

  • savefig (str, optional) – Path to save the figure.

  • show (bool, optional) – Whether to show the figure.

Returns:

fig, ax – Figure and axes objects for the plot.

Return type:

matplotlib.figure.Figure, matplotlib.axes.Axes

_add_grouped_legend(fig, versions, cc, pol_list, fmt_dict, row_height=0.35, label_width=2, col_width=0.9, gap_below=0.1, capsize=2, fontsize=10)[source]
Add a custom legend below the figure with one row per version:

<version label> <marker> <pol> <marker> <pol> …

The box size (in inches) scales with the number of versions (rows) and polarizations (columns), then gets converted to figure-fraction coordinates so it works for any figsize.

Parameters:
  • row_height (float) – Height per row (per version), in inches.

  • label_width (float) – Width reserved for the version label column, in inches.

  • col_width (float) – Width per polarization column (marker + pol label), in inches.

  • gap_below (float) – Vertical gap between the bottom of the subplot grid and the top of the legend box, in inches.

get_pol_color(base_color, pol, pol_list, lightness_range=(-0.25, 0.25))[source]

Given a base version color, return a shade variant for a given polarization, by adjusting lightness in HLS space while keeping hue and saturation fixed.

Parameters:
  • base_color (str or tuple) – Any matplotlib-recognized color (hex, name, RGB tuple, etc.)

  • pol (str) – The polarization this color is for (e.g. “EE”).

  • pol_list (list) – Full list of polarizations being plotted, used to compute this pol’s relative position in the lightness range.

  • lightness_range (tuple of float) – (min_offset, max_offset) added to the base lightness, spread evenly across pol_list. Negative = darker, positive = lighter. Values are in HLS lightness units (0-1 scale), so keep these modest (e.g. +/-0.25) to avoid washing out to white or black.

Returns:

RGB color tuple in [0, 1] range, usable directly in matplotlib.

Return type:

tuple