sp_validation.cosmo_val.sacc_writers

Pair-native SACC writers and covariance helpers for cosmo_val products.

Each writer turns a computed statistic into a single-statistic SACC part. Pairs are inserted in the supplied order, typically (0, 0), (0, 1), …, with points and covariances pair-major. Covariance helpers map OneCovariance ξ± and NaMaster iNKA matrices to the part’s point order. assemble_analysis_sacc() combines the parts and their covariance blocks into an analysis file.

xi_pairs_to_sacc(nz, metadata, pairs, *, grid, variances=None, covariance=None)[source]

One ξ± part over one or more bin pairs, on a named angular grid.

pairs is a sequence of (bins, xi): bins a source bin pair (i, j) and xi a mapping with theta, xip, xim and, optionally, theta_nom, npairs, weight. Each pair goes in as [ξ+; ξ−] in the order given, so the data vector is pair-major, and the covariance is tied to that order by position: covariance is the dense block in it, variances the matching diagonal. At most one may be given. nz must hold an n(z) for every bin the pairs name.

xi_to_sacc(nz, metadata, theta, xip, xim, *, grid, theta_nom=None, npairs=None, weight=None, variances=None, covariance=None)[source]

One ξ± part (bins=(0, 0)) on a named angular grid.

The single-pair form of xi_pairs_to_sacc(). The grid’s covariance comes in one of two shapes: covariance, the dense [ξ+; ξ−]-ordered block (a jackknife estimate), or variances, the concatenated [varxip; varxim] diagonal. At most one may be given.

onecov_xi_covariance(s, cov)[source]

OneCovariance’s real-space ξ± matrix cov in the insertion order of s.

OneCovariance writes ξ± type-major: every ξ+ point, then every ξ− point; within each, bin pairs (i, j) with i <= j and i outermost, then θ ascending. A ξ± part is pair-major (xi_pairs_to_sacc()), so this finds each point of s in OneCovariance’s order and permutes cov to match. The two orders agree for a single bin pair. OneCovariance’s bin k is column k of the n(z) file, which must be the part’s source_k.

s must hold ξ± on one grid only, with the same θ points for every bin pair, as a part does.

namaster_cl_covariance(s, cov_fits)[source]

Map iNKA pair-major covariance HDUs to a pseudo-Cℓ part’s order.

Each same-polarisation HDU is ordered by source pair, then increasing ℓ. Cross-polarisation blocks are zero, including across source pairs.

pseudo_cl_to_sacc(nz, metadata, pairs, covariance=None)[source]

Write pair-major EE/BB/EB spectra and their bandpower windows.

Each payload contains ell_eff, NaMaster’s cl_all in row order [EE, EB, BE, BB], and wsp. Supply nside only for HEALPix-map spectra, to include the squared pixel window pw²(ℓ); catalogue spectra have no pixel window. Covariance follows the pair-major insertion order.

cosebis_to_sacc(nz, metadata, pairs, scale_cut, covariance=None)[source]

Write each pair’s COSEBIs in [En; Bn] order at the scale cut.

Each payload contains En and Bn. The supplied covariance follows that pair-major order and has its E×B and B×E blocks zeroed, including across pairs.

pure_eb_to_sacc(nz, metadata, pairs, covariance=None)[source]

Write each pair’s theta and six arrays in PURE_KEYS order.

The order is xip_E, xim_E, xip_B, xim_B, xip_amb, xim_amb; the covariance follows this order within each pair.

rho_tau_to_sacc(nz, metadata, rho_stats, tau_by_bin, tau_cov_th_by_bin=None)[source]

One ρ/τ part: ρ_0…ρ_5 autos and τ_0/τ_2/τ_5 leakage.

rho_stats contains theta, rho_{k}_p, rho_{k}_m, varrho_{k}_p and varrho_{k}_m for k=0,…,5. Each table in tau_by_bin contains theta, tau_{k}_p, tau_{k}_m, vartau_{k}_p and vartau_{k}_m for k=0,2,5. ρ carries a variance diagonal. Each τ block has a variance diagonal, with its optional CovTauTh matrix scattered into its plus rows. CovTauTh has shape (3·nθ, 3·nθ), ordered k-major (0, 2, 5), plus only. Cross-bin covariances are approximated as zero.

_copy_data_points(dst, src)[source]

Append every data point of src into dst (tags preserved).

assemble_analysis_sacc(parts)[source]

Rebuild the single {version}.sacc analysis file from parts.

Each part is a single-statistic Sacc (from a *_to_sacc writer, loaded from disk) carrying its own covariance = its block. Tracers and metadata are seeded from parts[0] (every part describes the same catalogue version). Data points are re-added in the order the parts are given, which must be the canonical order (ξ± reporting, pseudo-Cℓ, COSEBIs, pure-E/B, ρ/τ), and the per-part blocks become one BlockDiagonalCovariance. Insertion order and block order therefore agree by construction — validated by sp_validation.sacc_io.assemble_covariance().

Parameters:

parts (sequence of sacc.Sacc) – Single-statistic parts, each with a covariance, in canonical order.

Returns:

The analysis Sacc with a BlockDiagonalCovariance covering every point.

Return type:

sacc.Sacc