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:
objectFramework 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.
- catalog_config_path¶
Resolved path to the catalog configuration file.
- Type:
Path
- 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:
- property results¶
- property results_objectwise¶
- property rho_stat_handler¶
- property tau_stat_handler¶
- property colors¶
- property area¶
- property n_eff_gal¶
- property ellipticity_dispersion¶
- property pseudo_cls_onecov¶
- property psf_fitter¶
- property rho_tau_fits¶
- property xi_psf_sys¶
- 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.
- calculate_aperture_mass_dispersion(theta_min=0.3, theta_max=200, nbins=500, nbins_map=15, npatch=25)[source]¶
- property map2¶
- 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:
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:
- 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_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.
- _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.
- 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¶