Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e67aa1b
Merge remote-tracking branch 'origin/develop' into feat/tomographic-s…
cailmdaley Oct 30, 2026
b24536b
Order NaMaster covariance by SACC point labels
cailmdaley Oct 30, 2026
0610bcc
Write multiple bin pairs for SACC statistics
cailmdaley Oct 30, 2026
367999f
Seal tomographic pseudo-Cl pairs in one SACC part
cailmdaley Oct 30, 2026
402222a
Derive tomographic COSEBIs and pure E/B covariance
cailmdaley Oct 30, 2026
180b492
Write tomographic rho and tau SACC parts
cailmdaley Oct 30, 2026
c55250b
Wire tomographic statistics into workflow assembly
cailmdaley Oct 30, 2026
a6863e3
Restore pair-native SACC writer documentation
cailmdaley Oct 30, 2026
260641e
Test OneCovariance ordering through SACC assembly
cailmdaley Oct 30, 2026
bf57e2b
Test tomographic jackknife and assembled covariance order
cailmdaley Oct 30, 2026
ef37310
Make pseudo-Cl measurements private and retain only sealed spectra
cailmdaley Oct 30, 2026
1211131
Derive tomographic covariance dimensions from block FITS
cailmdaley Oct 30, 2026
a90395b
Merge develop and extend the blind leak gate to tomography
cailmdaley Oct 30, 2026
b27ec2c
Reuse tomographic ρ only when its cache records the current measurement
cailmdaley Oct 30, 2026
c0c2681
Allow BLAS round-off in the derived-covariance workflow test
cailmdaley Oct 30, 2026
d11a16e
Tomographic and whole-sample OneCovariance inputs from one catalogue …
Oct 30, 2026
a48d488
Refuse a tomographic covariance built from whole-sample cov_th
cailmdaley Oct 30, 2026
b1ccbed
Refuse a bin sum of unit-normalised per-bin n(z)
cailmdaley Oct 30, 2026
ee7798e
Read n_e as a float in the sigma_e convention test
cailmdaley Oct 31, 2026
26988c8
Merge remote-tracking branch 'origin/develop' into feat/tomographic-s…
cailmdaley Oct 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions src/sp_validation/b_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,37 @@ def covariance_label(npatch):
return "analytic" if npatch is None else f"jackknife ({npatch} patches)"


def calculate_cosebis(gg, nmodes=10, scale_cuts=None, cov_path=None):
def cosebis_operator(theta, left_edges, right_edges, scale_cut, nmodes):
"""COSEBIs map from full-grid ``[ξ+; ξ−]`` to ``[En; Bn]``.

The covariance convention sets all E×B blocks to zero after propagation,
matching cosmo_numba's single-pair covariance convention.
"""
from cosmo_numba.B_modes.cosebis import COSEBIS
from scipy.integrate import simpson

theta = np.asarray(theta)
start, stop = bins_from_edges(left_edges, right_edges, *scale_cut)
inds = np.arange(start, stop)
cut = theta[inds]
kernel = COSEBIS(
theta_min=cut.min(), theta_max=cut.max(), N_max=nmodes, precision=120
)
rad = np.deg2rad(cut / 60)
weights = simpson(np.eye(len(cut)), x=rad, axis=1) * rad / 2
plus = kernel.get_Tp_log(cut) * weights
minus = kernel.get_Tm_log(cut) * weights
operator = np.zeros((2 * nmodes, 2 * len(theta)))
operator[:nmodes, inds] = plus
operator[nmodes:, inds] = plus
operator[:nmodes, inds + len(theta)] = minus
operator[nmodes:, inds + len(theta)] = -minus
return operator


def calculate_cosebis(
gg, nmodes=10, scale_cuts=None, cov_path=None, *, cov_xi=None, npatch=None
):
"""
Calculate COSEBIs modes from a correlation function for multiple scale cuts.

Expand All @@ -409,7 +439,15 @@ def calculate_cosebis(gg, nmodes=10, scale_cuts=None, cov_path=None):
Each results dictionary contains 'En', 'Bn', 'cov', 'chi2_E', 'chi2_B',
'pte_B', 'scale_cut', and 'mask' entries.
"""
cov_xipm = np.loadtxt(cov_path) if cov_path is not None else gg.cov
if cov_xi is not None and cov_path is not None:
raise ValueError("give cov_xi or cov_path, not both")
cov_xipm = (
cov_xi
if cov_xi is not None
else np.loadtxt(cov_path)
if cov_path is not None
else gg.cov
)
return cosebis_scan_from_xi(
gg.meanr,
gg.xip,
Expand All @@ -420,7 +458,9 @@ def calculate_cosebis(gg, nmodes=10, scale_cuts=None, cov_path=None):
nmodes=nmodes,
scale_cuts=scale_cuts,
# A theory covariance has no jackknife realisations to debias.
npatch=None if cov_path is not None else gg.npatch1,
npatch=npatch
if cov_xi is not None
else (None if cov_path is not None else gg.npatch1),
)


Expand Down
18 changes: 0 additions & 18 deletions src/sp_validation/cosmo_val/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,24 +611,6 @@ def blind(self, version):
catalogues = self._config_as_read
return blinding.open_blind(blinding.blind_of(catalogues, entry), catalogues)

def _refuse_blinded_tomography(self, version):
"""Refuse to measure tomographic shear signal on a blinded catalogue.

A statistic is blinded by sealing its SACC part, whose tracers carry
the n(z) the blind's theory shifts it by. ξ± (and ⟨M_ap²⟩, derived from
it) is born as such a part for every tomographic bin pair; the
tomographic pseudo-Cℓ are still FITS tables with no per-bin tracer, so
on a blinded catalogue they would hold true values.
"""
blind = self.blind(version)
if blind.name != blinding.NONE.name:
raise blinding.BlindingError(
f"{version} is blinded under {blind.name}, and blinding covers "
"its tomographic ξ± and non-tomographic statistics only; other "
"tomographic shear statistics are measured on public "
"(`blind: none`) catalogues"
)

def basename(
self,
version,
Expand Down
41 changes: 24 additions & 17 deletions src/sp_validation/cosmo_val/cosebis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
plot_cosebis_scale_cut_heatmap,
save_cosebis_results,
)
from .derived_covariance import xi_covariance


class CosebisMixin:
Expand Down Expand Up @@ -61,9 +62,8 @@ def calculate_cosebis(
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 for a single pair. Cannot be combined with
``compute_tomography=True``.
Path to the OneCovariance integration-grid matrix, including all
pairs for tomography.
scale_cuts : list of tuples, optional
Explicit list of (min_theta, max_theta) scale cuts to evaluate.
Overrides evaluate_all_scale_cuts when provided.
Expand Down Expand Up @@ -93,12 +93,6 @@ def calculate_cosebis(
"""
self.print_start(f"Computing {version} COSEBIs")

if cov_path is not None and compute_tomography:
raise ValueError(
"cov_path holds a single ξ± covariance; it cannot serve every "
"tomographic bin pair."
)

# Calculate single fine-binned correlation function for COSEBIs, as the
# sealed part: on a blinded catalogue the COSEBIs are concealed with it.
print(
Expand All @@ -115,20 +109,24 @@ def calculate_cosebis(
max_sep=max_sep_int,
nbins=nbins_int,
)
results = {
bin_key: None for bin_key in ggs.keys()
} # Initialize results dictionary
parts = self.xi_tomo_parts if compute_tomography else self.xi_parts
part = parts[version, "integration"]
covariance, cov_npatch = xi_covariance(part, cov_path)
results = {bin_key: None for bin_key in ggs}

for bin_key in ggs.keys():
# LG TO-DO: account for tomographic scale-cuts
rows = ggs[bin_key]._rows
pair_cov = covariance[np.ix_(rows, rows)]
# The same scale cuts apply to each pair.
if scale_cuts is not None:
# Explicit scale cuts provided
print(f"Evaluating {len(scale_cuts)} explicit scale cuts")
results[bin_key] = calculate_cosebis(
gg=ggs[bin_key],
nmodes=nmodes,
scale_cuts=scale_cuts,
cov_path=cov_path,
cov_xi=pair_cov,
npatch=cov_npatch,
)
elif evaluate_all_scale_cuts:
# Use reporting binning parameters or inherit from class config
Expand All @@ -154,12 +152,17 @@ def calculate_cosebis(
gg=ggs[bin_key],
nmodes=nmodes,
scale_cuts=generated_cuts,
cov_path=cov_path,
cov_xi=pair_cov,
npatch=cov_npatch,
)
else:
# Single scale cut behavior: use full range
results[bin_key] = calculate_cosebis(
gg=ggs[bin_key], nmodes=nmodes, scale_cuts=None, cov_path=cov_path
gg=ggs[bin_key],
nmodes=nmodes,
scale_cuts=None,
cov_xi=pair_cov,
npatch=cov_npatch,
)
# Extract single results dict from scale_cuts dictionary
results[bin_key] = next(iter(results[bin_key].values()))
Expand Down Expand Up @@ -314,6 +317,10 @@ def plot_cosebis(
bin_stub + "_data.npz",
fiducial_scale_cut,
edges,
derived_from=[self.xi_parts[version, "integration"]],
derived_from=[
(self.xi_tomo_parts if compute_tomography else self.xi_parts)[
version, "integration"
]
],
)
self._cosebis_results[version] = results_tomo
43 changes: 43 additions & 0 deletions src/sp_validation/cosmo_val/derived_covariance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Covariance propagation for derived tomographic ξ± statistics."""

import numpy as np
from scipy.linalg import block_diag

from .. import sacc_io
from .sacc_writers import onecov_xi_covariance


def xi_pairs(part):
"""Source-bin pairs in the order in which the ξ± part holds them."""
pairs = []
for dp in part.data:
if dp.data_type == sacc_io.XI_PLUS:
pair = tuple(int(t.removeprefix("source_")) for t in dp.tracers)
if pair not in pairs:
pairs.append(pair)
return pairs


def xi_covariance(part, path=None):
"""Pair-major covariance and jackknife patch count, or analytic covariance."""
if path is not None:
return onecov_xi_covariance(part, np.loadtxt(path)), None
if part.covariance is None:
raise ValueError("the integration-grid ξ± part has no covariance")
return part.covariance.dense, int(part.metadata.get("npatch", 1))


def propagate(operators, covariance, *, cosebis=False):
"""Propagate all cross-pair blocks, with the COSEBIs E×B-zero convention."""
operator = block_diag(*operators)
result = operator @ covariance @ operator.T
if cosebis:
e, b, offset = [], [], 0
for op in operators:
n = op.shape[0] // 2
e.extend(range(offset, offset + n))
b.extend(range(offset + n, offset + 2 * n))
offset += 2 * n
result[np.ix_(e, b)] = 0
result[np.ix_(b, e)] = 0
return result
Loading
Loading