sp_validation.cosmo_val

class CosmologyValidation(versions, catalog_config='./cat_config.yaml', output_dir=None, rho_tau_method='lsq', cov_estimate_method='th', compute_cov_rho=True, n_cov=100, theta_min=0.1, theta_max=250, nbins=20, var_method='jackknife', npatch=20, quantile=0.1587, theta_min_plot=0.08, theta_max_plot=250, ylim_alpha=[-0.005, 0.05], ylim_xi_sys_ratio=[-0.02, 0.5], nside=1024, nside_mask=4096, binning='powspace', power=0.5, n_ell_bins=32, ell_step=10, pol_factor=True, cell_method='map', noise_bias_method='analytic', fiducial_input_inka='coupled', nrandom_cell=10, path_onecovariance=None, cosmo_params=None, blind=None)[source]

Bases: object

Framework for cosmic shear validation and systematics analysis.

Handles two-point correlation function measurements, PSF systematics (rho/tau), pseudo-C_ell analysis, and covariance estimation for weak lensing surveys. Supports multiple catalog versions with automatic leakage-corrected variants.

Parameters:
  • versions (list of str) – Catalog version identifiers to analyze. Appending ‘_leak_corr’ to a base version creates a virtual catalog using leakage-corrected ellipticity columns (e1_col_corrected/e2_col_corrected) from the base version configuration.

  • catalog_config (str, default './cat_config.yaml') – Path to catalog configuration YAML defining survey metadata, file paths, and analysis settings for each version.

  • output_dir (str, optional) – Override for output directory. If None, uses catalog config’s paths.output.

  • rho_tau_method ({'lsq', 'mcmc'}, default 'lsq') – Fitting method for PSF leakage systematics parameters.

  • cov_estimate_method ({'th', 'jk'}, default 'th') – Covariance estimation: ‘th’ for semi-analytic theory, ‘jk’ for jackknife.

  • compute_cov_rho (bool, default True) – Whether to compute covariance for rho statistics during PSF analysis.

  • n_cov (int, default 100) – Number of realizations for covariance estimation when using theory method.

  • theta_min (float, default 0.1) – Minimum angular separation in arcminutes for correlation function binning.

  • theta_max (float, default 250) – Maximum angular separation in arcminutes for correlation function binning.

  • nbins (int, default 20) – Number of angular bins for TreeCorr real-space correlation functions.

  • var_method ({'jackknife', 'sample', 'bootstrap', 'marked_bootstrap'}, default 'jackknife') – TreeCorr variance estimation method.

  • npatch (int, default 20) – Number of spatial patches for jackknife variance estimation.

  • quantile (float, default 0.1587) – Quantile for uncertainty bands in plots (default: 1-sigma ≈ 0.159).

  • theta_min_plot (float, default 0.08) – Minimum angular scale for plotting (may differ from analysis cut).

  • theta_max_plot (float, default 250) – Maximum angular scale for plotting.

  • ylim_alpha (list of float, default [-0.005, 0.05]) – Y-axis limits for alpha systematic parameter plots.

  • ylim_xi_sys_ratio (list of float, default [-0.02, 0.5]) – Y-axis limits for xi systematics ratio plots.

  • nside (int, default 1024) – HEALPix resolution for pseudo-C_ell analysis and area computation.

  • binning ({'powspace', 'linspace', 'logspace'}, default 'powspace') – Ell binning scheme for pseudo-C_ell (powspace = ell^power spacing).

  • power (float, default 0.5) – Exponent for power-law binning when binning=’powspace’.

  • n_ell_bins (int, default 32) – Number of ell bins for pseudo-C_ell analysis (used with binning=’powspace’).

  • ell_step (int, default 10) – Bin width in ell for linear binning (used with binning=’linear’).

  • pol_factor (bool, default True) – Apply polarization correction factor in pseudo-C_ell calculations.

  • nrandom_cell (int, default 10) – Number of random realizations for C_ell error estimation.

  • cosmo_params (dict, optional) – Cosmological parameters to pass to get_cosmo(). If None, uses Planck 2018.

versions

Validated catalog versions after processing _leak_corr variants.

Type:

list of str

cc

Loaded catalog configuration with resolved absolute paths.

Type:

dict

catalog_config_path

Resolved path to the catalog configuration file.

Type:

Path

treecorr_config

Configuration dictionary passed to TreeCorr correlation objects.

Type:

dict

cosmo

Cosmology object for theory predictions.

Type:

pyccl.Cosmology

Notes

  • Path resolution: Relative paths in catalog config are resolved using each version’s ‘subdir’ field as the base directory.

  • Virtual _leak_corr versions: These create deep copies of the base version config, swapping e1_col/e2_col with e1_col_corrected/e2_col_corrected.

  • TreeCorr cross_patch_weight: Automatically set to ‘match’ for jackknife, ‘simple’ otherwise, following TreeCorr best practices.

static _split_seed_variant(version)[source]

Return the base version and seed label if version encodes a seed.

static _materialize_seed_path(base_cfg, seed_label, version, base_version, catalog_config)[source]

Render the seed-specific shear path using Python string formatting.

get_redshift(version)[source]

Load redshift distribution for a catalog version.

Parameters:

version (str) – Catalog version identifier

Returns:

  • z (ndarray) – Redshift values

  • nz (ndarray) – n(z) probability density

Notes

If self.blind is set, the redshift path is modified to use the specified blind (A, B, or C) by replacing the blind suffix in the configured path.

compute_survey_stats(ver, weights_key_override=None, mask_path=None, nside=None, overwrite_config=False)[source]

Compute effective survey statistics for a catalog version.

Parameters:
  • ver (str) – Version string registered in the catalog config.

  • weights_key_override (str, optional) – Override the weight column key (defaults to the configured w_col).

  • mask_path (str, optional) – Explicit mask path to use when measuring survey area.

  • nside (int, optional) – If provided, compute survey area from the catalog using this NSIDE when no mask path is available.

  • overwrite_config (bool, optional) – If True, persist the derived statistics back to the catalog configuration.

Returns:

Dictionary containing: - area_deg2: Survey area in square degrees. - n_eff: Effective number density per arcmin^2. - sigma_e: Per-component shape noise. - sum_w: Sum of weights. - sum_w2: Sum of squared weights. - catalog_size: Number of galaxies processed.

Return type:

dict

_area_from_catalog(catalog_path, nside)[source]
_area_from_mask(mask_map_path)[source]
_write_catalog_config()[source]
color_reset()[source]
print_blue(msg, end='\n')[source]
print_start(msg, end='\n')[source]
print_done(msg)[source]
print_magenta(msg)[source]
print_green(msg)[source]
print_cyan(msg)[source]
set_params_leakage_scale(ver)[source]
set_params_leakage_object(ver)[source]
init_results(objectwise=False)[source]
property results
property results_objectwise
basename(version, treecorr_config=None, npatch=None)[source]
calculate_rho_tau_stats()[source]
property rho_stat_handler
property tau_stat_handler
property colors
property area
property n_eff_gal
property ellipticity_dispersion
property pseudo_cls_onecov
calculate_area()[source]
calculate_area_from_binned_catalog(ver)[source]
calculate_n_eff_gal()[source]
calculate_ellipticity_dispersion()[source]
plot_rho_stats(abs=False)[source]
plot_tau_stats(plot_tau_m=False)[source]
set_params_rho_tau(params, params_psf, survey='other')[source]
property psf_fitter
calculate_rho_tau_fits()[source]
property rho_tau_fits
plot_rho_tau_fits()[source]
property xi_psf_sys
plot_footprints()[source]
calculate_scale_dependent_leakage()[source]
plot_scale_dependent_leakage()[source]
calculate_objectwise_leakage()[source]
plot_objectwise_leakage()[source]
plot_ellipticity(nbins=200)[source]
plot_weights(nbins=200)[source]
plot_separation(nbins=200)[source]
calculate_additive_bias()[source]
property c1
property c2
calculate_2pcf(ver, npatch=None, save_fits=False, **treecorr_config)[source]

Calculate the two-point correlation function (2PCF) ξ± for a given catalog version with TreeCorr.

By default the class instance’s npatch and treecorr_config entries are used to initialize the TreeCorr Catalog and GGCorrelation objects, but may be overridden by passing keyword arguments.

Parameters:
  • ver (str) – The catalog version to process.

  • npatch (int, optional) – The number of patches to use for the calculation.

  • attribute. (Defaults to the instance's npatch)

  • save_fits (bool, optional) – Whether to save the ξ± results to FITS files.

  • False. (Defaults to)

  • **treecorr_config – Additional TreeCorr configuration parameters that will

  • example (override the instance's default treecorr_config. For)

  • min_sep=1.

Returns:

The TreeCorr GGCorrelation object containing the computed 2PCF results.

Return type:

treecorr.GGCorrelation

Notes

  • If the output file for the given configuration already exists, the calculation is skipped, and the results are loaded from the file.

  • If a patch file for the given configuration does not exist, it is created during the process.

  • FITS files for ξ+ and ξ− are saved with additional metadata in their headers if save_fits is True.

plot_2pcf()[source]
plot_ratio_xi_sys_xi(threshold=0.1, offset=0.02)[source]
calculate_aperture_mass_dispersion(theta_min=0.3, theta_max=200, nbins=500, nbins_map=15, npatch=25)[source]
property map2
plot_aperture_mass_dispersion()[source]
calculate_pure_eb(version, min_sep=None, max_sep=None, nbins=None, min_sep_int=0.08, max_sep_int=300, nbins_int=100, npatch=256, var_method='jackknife', cov_path_int=None, cosmo_cov=None, n_samples=1000)[source]

Calculate the pure E/B modes for the given catalog version. The class instance’s treecorr_config will be used for the “reporting” binning by default, but any kwargs passed to this function will overwrite the defaults.

Parameters:
  • version (str) – The catalog version to compute the pure E/B modes for.

  • min_sep (float, optional) – Minimum separation for the reporting binning. Defaults to the value in self.treecorr_config if not provided.

  • max_sep (float, optional) – Maximum separation for the reporting binning. Defaults to the value in self.treecorr_config if not provided.

  • nbins (int, optional) – Number of bins for the reporting binning. Defaults to the value in self.treecorr_config if not provided.

  • min_sep_int (float, optional) – Minimum separation for the integration binning. Defaults to 0.08.

  • max_sep_int (float, optional) – Maximum separation for the integration binning. Defaults to 300.

  • nbins_int (int, optional) – Number of bins for the integration binning. Defaults to 100.

  • npatch (int, optional) – Number of patches for the jackknife or bootstrap resampling. Defaults to the value in self.npatch if not provided.

  • var_method (str, optional) – Variance estimation method. Defaults to “jackknife”.

  • cov_path_int (str, optional) – Path to the covariance matrix for the reporting binning. Replaces the treecorr covariance matrix if provided, meaning that var_method has no effect on the results although it is still passed to CosmologyValidation.calculate_2pcf.

  • cosmo_cov (pyccl.Cosmology, optional) – Cosmology object to use for theoretical xi+/xi- predictions in the semi-analytical covariance calculation. Defaults to self.cosmo if not provided.

  • n_samples (int, optional) – Number of Monte Carlo samples for semi-analytical covariance propagation. Defaults to 1000.

Returns:

A dictionary containing the following keys:

  • ”xip_E”: Pure E-mode correlation function for xi+.

  • ”xim_E”: Pure E-mode correlation function for xi-.

  • ”xip_B”: Pure B-mode correlation function for xi+.

  • ”xim_B”: Pure B-mode correlation function for xi-.

  • ”xip_amb”: Ambiguity mode for xi+.

  • ”xim_amb”: Ambiguity mode for xi-.

  • ”cov”: Covariance matrix for the pure E/B modes.

  • ”gg”: The two-point correlation function object for the reporting binning.

  • ”gg_int”: The two-point correlation function object for the integration binning.

  • ”eb_samples”: (only when using semi-analytical covariance) Semi-analytic EB samples used for covariance calculation. Shape: (n_samples, 6*nbins)

Return type:

dict

Notes

  • A shared patch file is used for the reporting and integration binning, and is created if it does not exist.

plot_pure_eb(versions=None, output_dir=None, fiducial_xip_scale_cut=None, fiducial_xim_scale_cut=None, min_sep=None, max_sep=None, nbins=None, min_sep_int=0.08, max_sep_int=300, nbins_int=100, npatch=None, var_method='jackknife', cov_path_int=None, cosmo_cov=None, n_samples=1000, results=None, **kwargs)[source]

Generate comprehensive pure E/B mode analysis plots.

Creates four types of plots for each version: 1. Integration vs Reporting comparison 2. E/B/Ambiguous correlation functions 3. 2D PTE heatmaps 4. Covariance matrix visualization

Parameters:
  • versions (list, optional) – List of catalog versions to process. Uses self.versions if None.

  • output_dir (str, optional) – Output directory for plots. Uses configured output path if None.

  • fiducial_xip_scale_cut (tuple, optional) – (min_scale, max_scale) for xi+ fiducial analysis, shown as gray regions

  • fiducial_xim_scale_cut (tuple, optional) – (min_scale, max_scale) for xi- fiducial analysis, shown as gray regions

  • min_sep (float, float, int, optional) – Binning parameters for reporting scale. Uses treecorr_config if None.

  • max_sep (float, float, int, optional) – Binning parameters for reporting scale. Uses treecorr_config if None.

  • nbins (float, float, int, optional) – Binning parameters for reporting scale. Uses treecorr_config if None.

  • min_sep_int (float, float, int) – Binning parameters for integration scale (default: 0.08-300 arcmin, 100 bins)

  • max_sep_int (float, float, int) – Binning parameters for integration scale (default: 0.08-300 arcmin, 100 bins)

  • nbins_int (float, float, int) – Binning parameters for integration scale (default: 0.08-300 arcmin, 100 bins)

  • npatch (int, optional) – Number of patches for jackknife covariance. Uses self.npatch if None.

  • var_method (str) – Variance method (“jackknife” or “semi-analytic”). Automatically set to “semi-analytic” when cov_path_int is provided.

  • cov_path_int (str, optional) – Path to integration covariance matrix for semi-analytical calculation

  • cosmo_cov (pyccl.Cosmology, optional) – Cosmology for theoretical predictions in semi-analytical covariance

  • n_samples (int) – Number of Monte Carlo samples for semi-analytical covariance (default: 1000)

  • results (dict or list, optional) – Precalculated results to avoid recomputation. Can be a single results dict for one version, or a list of results dicts for multiple versions. If None (default), results will be calculated using calculate_pure_eb.

  • **kwargs (dict) – Additional arguments passed to calculate_eb_statistics

Notes

This function orchestrates the full E/B mode analysis workflow:

  • Uses instance configuration as defaults for unspecified parameters

  • Automatically switches to analytical variance when theoretical covariance provided

  • Generates standardized output file naming based on all analysis parameters

  • Delegates individual plot generation to specialized functions in b_modes module

calculate_cosebis(version, min_sep_int=0.5, max_sep_int=500, nbins_int=1000, npatch=None, nmodes=10, cov_path=None, scale_cuts=None, evaluate_all_scale_cuts=False, min_sep=None, max_sep=None, nbins=None)[source]

Calculate COSEBIs from a finely-binned correlation function.

COSEBIs fundamentally require fine binning for accurate transformations. This function computes a single, finely-binned correlation function using integration binning parameters and can evaluate either a single scale cut (full range) or multiple scale cuts systematically.

Parameters:
  • version (str) – The catalog version to compute the COSEBIs for.

  • min_sep_int (float, optional) – Minimum separation for integration binning (fine binning for COSEBIs). Defaults to 0.5 arcmin.

  • max_sep_int (float, optional) – Maximum separation for integration binning (fine binning for COSEBIs). Defaults to 500 arcmin.

  • nbins_int (int, optional) – Number of bins for integration binning (fine binning for COSEBIs). Defaults to 1000.

  • npatch (int, optional) – Number of patches for the jackknife resampling. Defaults to self.npatch.

  • nmodes (int, optional) – Number of COSEBIs modes to compute. Defaults to 10.

  • cov_path (str, optional) – Path to theoretical covariance matrix. When provided, enables analytic covariance calculation.

  • scale_cuts (list of tuples, optional) – Explicit list of (min_theta, max_theta) scale cuts to evaluate. Overrides evaluate_all_scale_cuts when provided.

  • evaluate_all_scale_cuts (bool, optional) – If True, evaluates COSEBIs for all possible scale cut combinations using the reporting binning parameters. Ignored when scale_cuts is provided. Defaults to False.

  • min_sep (float, optional) – Minimum separation for reporting binning (only used when evaluate_all_scale_cuts=True). Defaults to self.treecorr_config[“min_sep”].

  • max_sep (float, optional) – Maximum separation for reporting binning (only used when evaluate_all_scale_cuts=True). Defaults to self.treecorr_config[“max_sep”].

  • nbins (int, optional) – Number of bins for reporting binning (only used when evaluate_all_scale_cuts=True). Defaults to self.treecorr_config[“nbins”].

Returns:

When a single scale cut: Dictionary containing COSEBIs results with E/B modes, covariances, and statistics. When multiple scale cuts: Dictionary with scale cut tuples as keys and results dictionaries as values.

Return type:

dict

plot_cosebis(version=None, output_dir=None, min_sep_int=0.5, max_sep_int=500, nbins_int=1000, npatch=None, nmodes=10, cov_path=None, scale_cuts=None, evaluate_all_scale_cuts=False, min_sep=None, max_sep=None, nbins=None, fiducial_scale_cut=None, results=None)[source]

Generate comprehensive COSEBIs analysis plots for a single version.

Creates two types of plots: 1. COSEBIs E/B mode correlation functions 2. COSEBIs covariance matrix

Parameters:
  • version (str, optional) – Version string to process. Defaults to first version in self.versions.

  • output_dir (str, optional) – Output directory for plots. Defaults to self.cc[‘paths’][‘output’].

  • min_sep_int (float, float, int) – Integration binning parameters for correlation function (default: 0.5, 500, 1000)

  • max_sep_int (float, float, int) – Integration binning parameters for correlation function (default: 0.5, 500, 1000)

  • nbins_int (float, float, int) – Integration binning parameters for correlation function (default: 0.5, 500, 1000)

  • npatch (int, optional) – Number of patches for jackknife covariance. Defaults to instance value.

  • nmodes (int) – Number of COSEBIs modes to compute (default: 10)

  • cov_path (str, optional) – Path to theoretical covariance matrix. When provided, analytic covariance is used.

  • scale_cuts (list of tuples, optional) – Explicit list of (min_theta, max_theta) scale cuts to evaluate. Overrides evaluate_all_scale_cuts when provided.

  • evaluate_all_scale_cuts (bool) – Whether to evaluate all scale cuts from reporting binning grid (default: False). Ignored when scale_cuts is provided.

  • min_sep (float, float, int, optional) – Reporting binning parameters. Only used when evaluate_all_scale_cuts=True.

  • max_sep (float, float, int, optional) – Reporting binning parameters. Only used when evaluate_all_scale_cuts=True.

  • nbins (float, float, int, optional) – Reporting binning parameters. Only used when evaluate_all_scale_cuts=True.

  • fiducial_scale_cut (tuple, optional) – (min_scale, max_scale) reference scale cut for plotting

  • results (dict, optional) – Precalculated results to avoid recomputation. If None (default), results will be calculated using calculate_cosebis.

get_namaster_bin(lmin, lmax, b_lmax)[source]

Build NaMaster binning object.

Parameters:
  • lmin (int) – Multipole range.

  • lmax (int) – Multipole range.

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

Return type:

nmt.NmtBin

get_variance_map(nside, e1, e2, w, unique_pix, idx_rep)[source]

Create a variance map from the input catalog.

get_field_and_workspace_from_map(mask, lmax, b)[source]

Create a NaMaster field and workspace from the input map.

calculate_pseudo_cl_eb_cov()[source]

Compute a theoretical Gaussian covariance of the Pseudo-Cl for EE, EB and BB.

calculate_pseudo_cl_onecovariance()[source]

Compute the pseudo-Cl covariance using OneCovariance.

_modify_onecov_config(template_config, config_path, out_dir, mask_path, redshift_distr_path, ver)[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

get_cov_from_onecov(cov_one_cov, gaussian=True)[source]
_load_onecovariance_cov(out_dir, ver)[source]
calculate_pseudo_cl_g_ng_cov(gaussian_part='iNKA')[source]
calculate_pseudo_cl()[source]

Compute the pseudo-Cl of given catalogs.

calculate_pseudo_cl_map(ver, nside, out_path)[source]
calculate_pseudo_cl_catalog(ver, out_path)[source]
get_n_gal_map(params, nside, cat_gal)[source]

Compute the galaxy number density map.

get_gaussian_real(params, nside, lmax, cat_gal, n_gal, mask, unique_pix, idx_rep)[source]
get_sample(params, nside, lmax, b, cat_gal, n_gal, mask, unique_pix, idx_rep)[source]
get_pseudo_cls_map(map, mask, wsp=None)[source]

Compute the pseudo-cl for a given map.

get_pseudo_cls_catalog(catalog, params, wsp=None)[source]

Compute the pseudo-cl for a given catalog.

apply_random_rotation(e1, e2)[source]

Apply a random rotation to the ellipticity components e1 and e2.

Parameters:
  • e1 (np.array) – First component of the ellipticity.

  • e2 (np.array) – Second component of the ellipticity.

Returns:

  • np.array – First component of the rotated ellipticity.

  • np.array – Second component of the rotated ellipticity.

save_pseudo_cl(ell_eff, pseudo_cl, out_path)[source]

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

property pseudo_cls
plot_pseudo_cl()[source]

Plot pseudo-Cl’s for given catalogs.

summarize_bmodes(fiducial_scale_cut=(12, 83), versions=None)[source]

Print and return B-mode PTE summary across all statistics.

Collects PTEs from pure E/B, COSEBIs, and pseudo-Cl at the specified fiducial scale cut. Statistics that haven’t been computed show ‘–‘.

Parameters:
  • fiducial_scale_cut (tuple, optional) – (min_theta, max_theta) for extracting PTEs (default: (12, 83)).

  • versions (list, optional) – Versions to summarize. Uses self.versions if None.

Returns:

{version: {statistic: pte_value, ...}, ...}

Return type:

dict