I/O
HDF5 writer for summary statistics with units and provenance metadata.
- class sum_stat.io.writer.SummaryStatWriter(path, mode='w')[source]
Bases:
objectWrite summary statistics to an HDF5 file with full units and provenance.
Each statistic occupies a named group (e.g.
"angular_2pcf/DESI_BGS"). Every dataset carriesunitanddescriptionattributes. Every group carries anestimatorand survey provenance attributes. The cosmology is serialised inside each group so the file is self-contained.- Parameters:
path (str or Path) – Output HDF5 file path.
mode (str) –
"w"to overwrite,"a"to append to an existing file.
- Parameters:
Examples
>>> writer = SummaryStatWriter("results.h5") >>> writer.write_twopcf("angular_2pcf/BGS", theta, w, cov, edges, "landy-szalay", cosmo, {}) >>> writer.close()
- write_cl(group, ell_eff, cl, nl, cov, bin_edges, meta)[source]
Write angular power spectrum C_ℓ.
- Parameters:
group (str) – HDF5 group path, e.g.
"cl/DESI_BGS".ell_eff (ndarray, shape (n_ell,)) – Effective multipole per bin.
cl (ndarray, shape (n_ell,)) – Angular power spectrum [sr].
nl (ndarray, shape (n_ell,)) – Shot noise power spectrum [sr].
cov (ndarray, shape (n_ell, n_ell)) – Covariance matrix [sr^2].
bin_edges (ndarray, shape (n_ell+1,)) – Multipole bin edges.
meta (dict)
- Parameters:
- Return type:
None
- write_esd(group, rp_centres, delta_sigma, cov, bin_edges, cosmo, meta)[source]
Write excess surface mass density ΔΣ(r_p).
- Parameters:
group (str) – HDF5 group path, e.g.
"esd/DESI_BGS_KiDS".rp_centres (ndarray, shape (n_bins,)) – Projected separation bin centres [Mpc].
delta_sigma (ndarray, shape (n_bins,)) – ΔΣ(r_p) [M_sun/pc^2].
cov (ndarray, shape (n_bins, n_bins)) – Jackknife covariance matrix [(M_sun/pc^2)^2].
bin_edges (ndarray, shape (n_bins+1,)) – Projected separation bin edges [Mpc].
cosmo (FlatLambdaCDM)
meta (dict) – Should include lens_survey, source_survey, m_bias, R_mean, photo_z_correction, boost_correction flags.
- Parameters:
- Return type:
None
- write_knn(group, r_centres, F_k, F_k_poisson, bin_edges, k_values, cosmo, meta)[source]
Write kNN-CDF summary statistics.
- Parameters:
group (str) – HDF5 group path, e.g.
"knn/DESI_BGS".r_centres (ndarray, shape (n_r,)) – Separation bin centres [Mpc].
F_k (ndarray, shape (n_k, n_r)) – Empirical kNN-CDF for each k in k_values.
F_k_poisson (ndarray, shape (n_k, n_r)) – Erlang (Poisson) reference CDF for each k.
bin_edges (ndarray, shape (n_r+1,)) – Separation bin edges [Mpc].
k_values (ndarray, shape (n_k,)) – Neighbor orders used (e.g. [1, 2, 3, 4, 5]).
cosmo (FlatLambdaCDM)
meta (dict) – Extra attributes (estimator, n_query, n_gal, survey, etc.).
- Parameters:
- Return type:
None
- write_lf(group, mag_centres, phi, phi_err, cov, bin_edges, cosmo, meta)[source]
Write a luminosity function.
- Parameters:
group (str) – HDF5 group path, e.g.
"lf/DESI_BGS_r".mag_centres (ndarray, shape (n_bins,)) – Magnitude bin centres [mag].
phi (ndarray, shape (n_bins,)) – Luminosity function [Mpc^-3 mag^-1].
phi_err (ndarray, shape (n_bins,)) – Uncertainty on phi [Mpc^-3 mag^-1].
cov (ndarray, shape (n_bins, n_bins)) – Covariance matrix [(Mpc^-3 mag^-1)^2].
bin_edges (ndarray, shape (n_bins+1,)) – Magnitude bin edges [mag].
cosmo (FlatLambdaCDM) – Cosmology used for the V_max calculation.
meta (dict) – Extra attributes stored on the group (e.g. estimator, band, z_min, z_max).
- Parameters:
- Return type:
None
- write_multipoles(group, s_centres, xi_dict, cov, bin_edges, cosmo, meta, sep_unit='Mpc/h')[source]
Write redshift-space multipoles ξ_ℓ(s).
- Parameters:
group (str) – HDF5 group path.
s_centres (ndarray, shape (n_bins,)) – Separation bin centres.
xi_dict (dict) – Keys are multipole orders (0, 2, 4); values are shape (n_bins,).
cov (ndarray, shape (n_ell*n_bins, n_ell*n_bins)) – Stacked covariance matrix.
bin_edges (ndarray, shape (n_bins+1,)) – Separation bin edges.
cosmo (FlatLambdaCDM)
meta (dict)
sep_unit (str)
- Parameters:
- Return type:
None
- write_pk(group, k_centres, pk_dict, cov, bin_edges, cosmo, meta)[source]
Write power spectrum P(k) or multipoles P_ℓ(k).
- Parameters:
group (str) – HDF5 group path, e.g.
"pk3d/DESI_BGS".k_centres (ndarray, shape (n_k,)) – Wavenumber bin centres [h/Mpc].
pk_dict (dict) – Keys are multipole orders (0, 2, 4); values are shape (n_k,) [Mpc/h]^3.
cov (ndarray, shape (n_ell*n_k, n_ell*n_k)) – Stacked covariance matrix [(Mpc/h)^6].
bin_edges (ndarray, shape (n_k+1,)) – Wavenumber bin edges [h/Mpc].
cosmo (FlatLambdaCDM)
meta (dict)
- Parameters:
- Return type:
None
- write_smf(group, mstar_centres, phi, phi_err, cov, bin_edges, cosmo, meta)[source]
Write a stellar mass function.
- Parameters:
group (str) – HDF5 group path, e.g.
"smf/DESI_BGS".mstar_centres (ndarray, shape (n_bins,)) – log10(M_*/M_sun) bin centres [dex].
phi (ndarray, shape (n_bins,)) – Stellar mass function [Mpc^-3 dex^-1].
phi_err (ndarray, shape (n_bins,)) – Uncertainty [Mpc^-3 dex^-1].
cov (ndarray, shape (n_bins, n_bins)) – Covariance matrix [(Mpc^-3 dex^-1)^2].
bin_edges (ndarray, shape (n_bins+1,)) – log10(M_*/M_sun) bin edges [dex].
cosmo (FlatLambdaCDM)
meta (dict)
- Parameters:
- Return type:
None
- write_twopcf(group, sep_centres, xi, cov, bin_edges, estimator, cosmo, meta, sep_unit='Mpc', xi_unit='dimensionless')[source]
Write a two-point correlation function.
Handles w(θ), ξ(r), w_p(r_p), and individual multipoles ξ_ℓ(s).
- Parameters:
group (str) – HDF5 group path, e.g.
"angular_2pcf/DESI_BGS".sep_centres (ndarray, shape (n_bins,)) – Separation bin centres.
xi (ndarray, shape (n_bins,)) – Correlation function values.
cov (ndarray, shape (n_bins, n_bins)) – Covariance matrix.
bin_edges (ndarray, shape (n_bins+1,)) – Separation bin edges.
estimator (str) – Name of the estimator (e.g.
"landy-szalay").cosmo (FlatLambdaCDM)
meta (dict) – Extra attributes (e.g. pi_max_Mpc, ell, survey area).
sep_unit (str) – Physical unit string for separation axis (e.g.
"arcmin","Mpc").xi_unit (str) – Physical unit string for correlation values.
- Parameters:
- Return type:
None
HDF5 reader for summary statistics, reconstructing astropy Quantities.
- class sum_stat.io.reader.SummaryStatReader(path)[source]
Bases:
objectRead summary statistics from an HDF5 file written by
SummaryStatWriter.- Parameters:
path (str or Path) – Path to the HDF5 file.
- Parameters:
path (str | Path)
Examples
>>> reader = SummaryStatReader("results.h5") >>> groups = reader.list_statistics() >>> result = reader.read_esd("esd/DESI_BGS_KiDS") >>> result["delta_sigma"] # ndarray in M_sun/pc^2 >>> result["cov"] # covariance matrix >>> result["cosmology"] # FlatLambdaCDM instance >>> reader.close()
- cosmology(group)[source]
Reconstruct the astropy cosmology stored in a group.
- Parameters:
group (str) – HDF5 group path containing a
cosmologysubgroup.- Returns:
FlatLambdaCDM
- Parameters:
group (str)
- Return type: