sp_validation.cosmo_val.psf_systematics

PSF systematics diagnostics.

Rho/tau statistics, their fits, and PSF leakage tests (scale-dependent and object-wise) for catalogue validation.

class PSFSystematicsMixin[source]

Bases: object

property rho_stat_handler
property tau_stat_handler
property psf_fitter
property rho_tau_fits
property xi_psf_sys
calculate_rho_tau_stats(tomography=True)[source]

Measure ρ/τ statistics per version and tomographic bin.

Without tomography the single bin is "all", and its SACC part is written per version (rho_tau_to_sacc_part).

rho_tau_to_sacc_part(version, out_dir, base, rho_stat_handler, tau_stat_handler)[source]

Write the ρ/τ SACC part for one version, under the version’s blind.

ρ_0…ρ_5 autos and τ_0/τ_2/τ_5 leakage from the handler tables. The CovTauTh theory covariance cov_tau_{base}_th.npy is passed as tau_cov_th when it exists; without it the τ block falls back — loudly — to a variance diagonal.

calculate_rho_tau_fits(tomography=True, track_result=True)[source]
calculate_scale_dependent_leakage()[source]
calculate_objectwise_leakage(tomography=False)[source]

Fit the object-wise PSF leakage, per version and tomographic bin.

Stores a11, a22 and aii_mean (as ufloats) in self.leakage_coeff[ver]["tomo_bin_<id>"], with <id> all when tomography is False. A version whose catalogue lacks a required column is dropped from results_objectwise and leakage_coeff.

_objectwise_leakage_bin(results_obj, ver, tomo_bin_id, mix, order)[source]

Object-wise leakage coefficients of one tomographic bin.

calculate_alpha_leakage_summaries(tomography=False, cov_type=None)[source]

Summarise the scale-dependent leakage alpha(theta) = tau_0 / rho_0.

For each version in leakage_coeff and each of its tomographic bins, stores alpha_mean, alpha_1 and alpha_0 (see _alpha_summaries) next to the object-wise coefficients in self.leakage_coeff[ver]["tomo_bin_<id>"].

_get_galaxy_mask(ver, tomo_bin_id)[source]
_get_star_mask(ver)[source]
set_params_rho_tau(ver, params, params_psf)[source]
set_params_leakage_scale(ver)[source]
set_params_leakage_object(ver)[source]
set_psf_parameter_sampling_method(rho_tau_method)[source]
set_psf_parameter_nsamples(nsamples)[source]
set_psf_parameter_nwalkers(nwalkers)[source]
get_samples(version, params, tomo_bin_id, track_result=False)[source]
get_xi_psf_sys_samples(ver, params, tomo_bin_a, tomo_bin_b)[source]
_load_alpha_leakage(ver, tomo_bin_id, cov_type=None, seed=0)[source]

Alpha(theta) of one version and tomographic bin from its rho/tau files.

With cov_type None the errors use the variances in the rho/tau files; otherwise the cov_tau_*_<cov_type>.npy and jackknife cov_rho_*_jk.npy covariances under rho_tau_stats/.

_get_alpha_leakage(rho_stat_handler, tau_stat_handler, cov_rho=None, cov_tau=None, n_samples=10000, seed=0)[source]

Compute the alpha leakage parameter from the rho and tau statistics.

alpha(theta) = tau_0,+(theta) / rho_0,+(theta); its error is the standard deviation of that ratio over Gaussian draws of rho_0,+ and tau_0,+.

Parameters:
  • rho_stat_handler (RhoStatHandler) – The handler for the rho statistics.

  • tau_stat_handler (TauStatHandler) – The handler for the tau statistics.

  • cov_rho (np.ndarray, optional) – The covariance matrix for the rho statistics; its leading block is the rho_0,+ covariance. If None, the variances in the rho-statistics table are used.

  • cov_tau (np.ndarray, optional) – The covariance matrix for the tau statistics; its leading block is the tau_0,+ covariance. If None, the variances in the tau-statistics table are used.

  • n_samples (int, optional) – Number of Gaussian draws for the error.

  • seed (int or np.random.Generator, optional) – Seed (or generator) for the draws, so that errors are reproducible.

Returns:

theta, alpha, alpha_err – Angular scales, alpha leakage and its error.

Return type:

np.ndarray

static _alpha_summaries(theta, alpha, alpha_err)[source]

Scalar summaries of alpha(theta), as ufloats.

Returns:

alpha_mean: inverse-variance weighted mean of alpha(theta), with the weighted standard deviation; alpha_1: alpha and its error at the smallest theta; alpha_0: intercept c of the weighted least-squares affine fit alpha(theta) = c + m theta, with its error from the fit covariance (errors taken as absolute).

Return type:

dict

_compute_scale_dependent_xi_psf_sys(rho_0, tau_0_a, tau_0_b, cov_rho, cov_tau_a, cov_tau_b, n_samples=10000, same_bin=False, seed=0)[source]

Compute the scale-dependent xi_psf_sys from the rho and tau statistics.

xi_psf_sys = tau_0_a * tau_0_b / rho_0; its error is the standard deviation over Gaussian draws of rho_0, tau_0_a and tau_0_b.

Parameters:
  • rho_0 (np.ndarray) – The rho_0 statistics.

  • tau_0_a (np.ndarray) – The tau_0 statistics for tomographic bin a.

  • tau_0_b (np.ndarray) – The tau_0 statistics for tomographic bin b.

  • cov_rho (np.ndarray) – The covariance matrix for the rho statistics.

  • cov_tau_a (np.ndarray) – The covariance matrix for the tau statistics for tomographic bin a.

  • cov_tau_b (np.ndarray) – The covariance matrix for the tau statistics for tomographic bin b.

  • n_samples (int, optional) – Number of Gaussian draws for the error.

  • same_bin (bool, optional) – True when a and b are the same bin: tau_0_a and tau_0_b are then one measurement, and each draw uses a single tau sample (tau^2 / rho).

  • seed (int or np.random.Generator, optional) – Seed (or generator) for the draws, so that errors are reproducible.

plot_rho_stats(versions=None, colors=None, abs=False, offset=0, savefig=None, show=True, close=True)[source]

Plot the Rho statistics.

Parameters:
  • versions (list, optional) – List of versions to plot. If None, all versions are plotted.

  • abs (bool, optional) – If True, plot the absolute values of the Rho statistics.

  • offset (float, optional) – Offset to apply to the versions for better visualisation.

  • savefig (str, optional) – If provided, save the figure to this file.

  • show (bool, optional) – If True, show the figure.

  • close (bool, optional) – If True, close the figure after saving or showing.

plot_tau_stats(tomography=False, cov_type=None, versions=None, colors=None, offset=0, savefig=None, show=True, close=True, plot_tau_m=False, plot_theta_times_tau=False, fmt='', capsize=2)[source]
plot_rho_tau_fits(tomography=False, versions=None, colors=None, savefig_contours=None, savefig_xi_psf_sys=None, savefig_format='png', tomo_bin_label_position=None, nsamples_to_plot=100, offset=0, alpha=0.3, times_theta=False, show=True, close=True)[source]

Plot the Rho/Tau fits and the xi_psf_sys samples.

Parameters:
  • versions (list, optional) – List of versions to plot. If None, all versions are plotted.

  • colors (list, optional) – List of colors for each version. If None, default colors are used.

  • savefig_contours (str, optional) – If provided, save the contour plot to this file.

  • savefig_xi_psf_sys (str, optional) – If provided, save the xi_psf_sys samples plot to this file.

  • nsamples_to_plot (int, optional) – Number of xi_psf_sys samples to plot. Default is 100.

  • offset (float, optional) – Offset to apply to the versions for better visualisation.

  • alpha (float, optional) – Alpha value for the xi_psf_sys samples plot. Default is 0.3.

  • times_theta (bool, optional) – If True, plot the xi_psf_sys multiplied by theta.

  • show (bool, optional) – If True, show the figure.

  • close (bool, optional) – If True, close the figure after saving or showing.

plot_scale_dependent_leakage(tomography=False, cov_type=None, versions=None, colors=None, offset=0, savefig=None, show=True, close=True, plot_theta_times_tau=False, ylim_alpha=False, fmt='', capsize=2)[source]
plot_scale_dependent_alpha(tomography=False, cov_type=None, versions=None, colors=None, offset=0, savefig=None, show=True, close=True, fmt='', capsize=2, ylim_alpha=False)[source]
plot_objectwise_leakage(tomography=False, cov_type=None)[source]

Plot object-wise leakage against the scale-dependent alpha.

x is the object-wise <a_ii>, y the alpha(theta) summaries from the rho/tau products (fill style: mean, smallest scale, affine intercept). Marker shape is the version; colour is the version (non-tomographic) or the tomographic bin. Saved to leakage_coefficients.png, or leakage_coefficients_tomo.png when tomography is True.

_xi_psf_sys_sample_x_y_plot_function(ax_plus, ax_minus, version, tomo_bin_a, tomo_bin_b, idx, versions, color, offset, nsamples_to_plot, times_theta, alpha)[source]
_xi_psf_sys_mean_and_std_x_y_plot_function(ax_plus, ax_minus, version, tomo_bin_a, tomo_bin_b, idx, versions, color, offset, times_theta, alpha)[source]
_scale_dependent_xi_psf_sys_x_y_plot_function(ax_plus, ax_minus, version, tomo_bin_a, tomo_bin_b, idx, versions, color, offset, cov_type, times_theta, fmt, capsize)[source]
_get_jittered_theta(theta, idx, n_versions, offset)[source]

Get the jittered theta values for better visualisation.

_get_ax_plus(axs, tomo_bin_a, tomo_bin_b)[source]
_get_ax_minus(axs, tomo_bin_a, tomo_bin_b)[source]
_set_ax_visibility_to_false(axs, n_tomo_bins_plot)[source]

Set the visibility of empty axes to False for better visualization.