Skip to content

sacc_io converters: SACC → CosmoSIS 2pt-FITS (byte-verified) + SACC ↔ OneCovariance#249

Draft
cailmdaley wants to merge 5 commits into
feat/sacc-2-sacc-iofrom
feat/sacc-3-2pt-converter
Draft

sacc_io converters: SACC → CosmoSIS 2pt-FITS (byte-verified) + SACC ↔ OneCovariance#249
cailmdaley wants to merge 5 commits into
feat/sacc-2-sacc-iofrom
feat/sacc-3-2pt-converter

Conversation

@cailmdaley

@cailmdaley cailmdaley commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Closes #246. PR 3 of the PRD #241 series (base: #245, sacc_io).

What & why

Extends sp_validation.sacc_io with converters between the SACC data product and external analysis-tool file formats. SACC stays the standard product; the current CosmoSIS inference chain runs unchanged behind it (PRD #241 §2: "converter first, native likelihood later"). One module now carries the whole SACC surface: format contract, guarded selection, and converters.

  • CosmoSIS 2pt-FITS: sacc_to_twopoint_fits(s, path, *, rho_stats_hdu=None, tau_stats_hdu=None, n_bins=1) converts an analysis SACC into the 2pt-FITS read by 2pt_like and the ρ/τ 2pt_like_xi_sys fork. Single-bin v1: it raises on n_bins != 1 and on any ξ pair beyond (source_0, source_0). Tomographic emission lands with the tomographic round. RHO_STATS is copied verbatim from a sidecar FITS; the 2pt layout carries per-mode varrho_* variances the SACC does not store, and no consumer reads them.
  • OneCovariance: writers for the combined-n(z) file and the [redshift] config stanza, plus a covariance_list_*.dat reader that produces dense blocks paired with SACC selectors for assemble_covariance. Coupled to OneCovariance only through its file formats, not as a dependency.

Every data and covariance selection goes through the guarded selection with grid="reporting" (loud on empty). Integration-grid points in the analysis SACC can never leak into the 2pt-FITS. (SACC covariances carry no tags of their own; blocks are addressed through data-point indices, which do — filtering the points filters the covariance with them.)

No public API outside sacc_io changes; no existing behavior is modified.

Validation

Byte equality against the current writer (astropy writes FITS deterministically): build a reference with cosmosis_fitting.py's own HDU-builders, build a SACC from the same inputs, convert, assert byte-for-byte identity.

  • test_sacc_io_twopoint.py (CI): all three product shapes (plain-ξ; ξ+Cℓ; ξ+ρ/τ), the truncated-but-cross-correlated [τ₀+; τ₂+] covariance block, perturbation teeth, sidecar fail-fast, an encoded-covariance test that fails on any transposition, and byte-identity with integration-grid points present (regression pinning the grid-filtered covariance gather).
  • test_sacc_io_realdata.py (candide-local skipif): byte-equal observed for real SP_v1.4.6_leak_corr and glass_mock products. No real data committed.
  • test_sacc_io_one_covariance.py: reshaping, column selection, n(z) round-trip, fail-fast paths.

81 tests green, including the 4 real-data byte-compares on candide.

Legacy writer

cosmo_inference/scripts/cosmosis_fitting.py remains the pipeline's 2pt-FITS writer for now; this converter is its byte-verified equivalent. PR 4 (#251) migrates the pipeline onto the SACC path and retires it. The swap happens downstream, not here.

— Claude (Fable, with Opus/Sonnet implementation agents) on behalf of Cail.

🤖 Generated with Claude Code

https://claude.ai/code/session_016Ko89uZF84ez6HEDcTWbJe

Adds twopoint_convert (SACC → 2pt-FITS, byte-compatible with
cosmosis_fitting) and one_covariance_io (SACC ↔ OneCovariance glue),
with their test suites. Rebuilt on feat/sacc-2-sacc-io so the diff is
converter-only; adapted to that branch's canonical sacc_io — ξ reads use
grid='reporting' (was 'coarse'). Optional-block probing (pseudo-Cℓ, τ)
stays on raw s.indices behind get_data_types/use_rho_tau guards, so the
new fail-loud sacc_io readers don't trip on absent blocks.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzUt7VbtXwr2SCHUdiQTyt
@cailmdaley
cailmdaley force-pushed the feat/sacc-3-2pt-converter branch from 700a885 to 64b2b5f Compare July 16, 2026 09:34
@cailmdaley cailmdaley linked an issue Jul 19, 2026 that may be closed by this pull request
One module whose job is converting between the SACC product and
external analysis-tool file formats (CosmoSIS 2pt-FITS, OneCovariance).
Public API unchanged; sacc_io untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01766vawzi2XqrgoyHmeHEY9
@cailmdaley cailmdaley changed the title Converters: SACC→2pt-FITS (byte-compared) + SACC↔OneCovariance glue sacc_interop: converters between SACC and external-tool formats (CosmoSIS 2pt-FITS, OneCovariance) Jul 19, 2026
Cail's ruling: a single sacc_io.py carries the format contract and the
external-tool converters (CosmoSIS 2pt-FITS, OneCovariance). Public API
unchanged; the sacc_io import name every downstream branch uses is untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01766vawzi2XqrgoyHmeHEY9
@cailmdaley cailmdaley changed the title sacc_interop: converters between SACC and external-tool formats (CosmoSIS 2pt-FITS, OneCovariance) sacc_io converters: SACC → CosmoSIS 2pt-FITS (byte-verified) + SACC ↔ OneCovariance Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Converters: SACC->2pt-FITS + SACC<->OneCovariance

1 participant