Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 5 additions & 9 deletions papers/bmodes/rules/claims.smk
Original file line number Diff line number Diff line change
Expand Up @@ -355,25 +355,21 @@ rule pure_eb_covariance:


rule calculate_pure_eb_ptes:
"""Calculate PTE matrices for Pure E/B mode scale cut robustness.
"""PTE matrices for pure E/B-mode scale-cut robustness.

Per-blind: Uses blind-specific integration covariance for PTE calculation.
The pure_eb_data vectors are identical across blinds; only covariance differs.

In practice, BB covariance is blind-independent (validated by
bb_covariance_blind_independence), so downstream consumers (config_space_pte_matrices)
only request blind A. The per-blind wildcard is retained for the blind independence test.
Nothing here varies with the blind: the data vectors come from the blind-A
gather and the PTEs are Hartlap-debiased by the MC draw count, not by a
per-blind covariance. The wildcard survives as the filename slot the
consumer (config_space_pte_matrices) reads, and only blind A is ever built.
"""
input:
pure_eb_data="results/paper_plots/intermediate/{version}_A_pure_eb_semianalytic.npz",
cov_integration=lambda w: _cov_integration_path(w.version, w.blind),
output:
"results/paper_plots/intermediate/{version}_{blind}_pure_eb_ptes.npz",
wildcard_constraints:
blind=r"[ABC]",
params:
version="{version}",
npatch=FIDUCIAL["npatch"],
n_samples=config["covariance"]["n_samples"],
resources:
mem_mb=16000,
Expand Down
35 changes: 6 additions & 29 deletions papers/bmodes/scripts/calculate_pure_eb_ptes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
pure-E/B ``semianalytic.npz`` (data vectors + MC covariance), evaluates the
ξ_+^B / ξ_-^B / joint ξ_tot^B χ² PTE matrices over the scale-cut grid via
``sp_validation.b_modes.calculate_eb_statistics`` (Hartlap-corrected inverse
MC covariance), and writes the PTE matrices to
MC covariance, debiased by the draw count), and writes the PTE matrices to
``{out}/{version}_{blind}_pure_eb_ptes.npz``.

python calculate_pure_eb_ptes.py \
--version SP_v1.4.6.3_leak_corr --blind A \
--pure-eb-data <..._pure_eb_semianalytic.npz> \
--cov-integration <cov ..._processed.txt> \
--npatch 1 --n-samples 2000 --out <output_dir>
--n-samples 2000 --out <output_dir>
"""

import argparse
Expand All @@ -22,31 +21,21 @@
from sp_validation.b_modes import calculate_eb_statistics


class FakeGG:
"""Minimal GGCorrelation-like object for calculate_eb_statistics."""

def __init__(self, nbins, npatch):
self.nbins = nbins
self.npatch1 = npatch
self.npatch2 = npatch


def calculate_ptes(
version,
blind,
pure_eb_data,
cov_integration,
npatch,
n_samples,
output_dir,
):
dataset = np.load(pure_eb_data)

theta = dataset["theta"]
nbins = len(theta)

results = {
"gg": FakeGG(nbins, int(npatch)),
"theta": theta,
# The MC draws are the realisations behind this covariance.
"n_eff": int(n_samples),
"xip_E": dataset["xip_E"],
"xim_E": dataset["xim_E"],
"xip_B": dataset["xip_B"],
Expand All @@ -57,11 +46,7 @@ def calculate_ptes(
}

print(f"Calculating PTE matrices for {version}...")
results = calculate_eb_statistics(
results,
cov_path_int=cov_integration,
n_samples=int(n_samples),
)
results = calculate_eb_statistics(results)

pte_matrices = results["pte_matrices"]
output_data = {
Expand All @@ -83,21 +68,13 @@ def _from_cli(argv=None):
ap.add_argument("--version", required=True)
ap.add_argument("--blind", default="A")
ap.add_argument("--pure-eb-data", required=True, help="Gathered semianalytic .npz")
ap.add_argument(
"--cov-integration",
default=None,
help="Integration-grid covariance _processed.txt (optional)",
)
ap.add_argument("--npatch", type=int, default=1)
ap.add_argument("--n-samples", type=int, default=2000)
ap.add_argument("--out", required=True, help="Output directory (lc {output})")
a = ap.parse_args(argv)
calculate_ptes(
version=a.version,
blind=a.blind,
pure_eb_data=a.pure_eb_data,
cov_integration=a.cov_integration,
npatch=a.npatch,
n_samples=a.n_samples,
output_dir=a.out,
)
Expand Down
18 changes: 9 additions & 9 deletions papers/bmodes/scripts/precompute_pure_eb_chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ def compute_chunk(
row_sums = np.array(binning_matrix.sum(axis=1)).flatten()
binning_matrix = sparse.diags(1 / row_sums) @ binning_matrix

mean_int = np.concatenate(
get_theo_xi(
theta=theta_int,
z=z_dist[:, 0],
nz=z_dist[:, 1],
backend="ccl",
cosmo=cosmo_cov,
)
)
# One n(z) gives one tracer pair: get_theo_xi's single (xi+, xi-) entry.
(xi_pm,) = get_theo_xi(
theta=theta_int,
z=z_dist[:, 0],
nz=z_dist[:, 1],
backend="ccl",
cosmo=cosmo_cov,
).values()
mean_int = np.concatenate(xi_pm)

rng = np.random.default_rng(seed=42 + chunk_id)

Expand Down
26 changes: 9 additions & 17 deletions papers/bmodes/scripts/run_pure_eb_ptes_sweep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,27 @@
# Loops the non-fiducial version list (resolved via sweep_versions.py) and runs
# calculate_pure_eb_ptes.py once per version — the same χ² PTE-matrix compute the
# fiducial pure_eb_pte_per_cut recipe calls. Each version's gathered semi-analytic
# NPZ is read from the pure_eb_sweep output dir and its Gaussian integration
# covariance from the cov_sweep output dir (both by absolute path — lc does not
# wire cross-output deps, so the driver reads upstream sweeps directly; run
# pure_eb_sweep + cov_sweep before this). Each version emits the canonical
# ``{ver}_{blind}_pure_eb_ptes.npz`` — the exact name config_space_pte_matrices.py
# reconstructs from --pte-intermediate-dir — straight into --out. Serial over
# versions; each version is fast (206-pair grid, ~seconds).
# NPZ (data vectors + MC covariance) is read from the pure_eb_sweep output dir by
# absolute path — lc does not wire cross-output deps, so the driver reads the
# upstream sweep directly; run pure_eb_sweep before this. Each version emits the
# canonical ``{ver}_{blind}_pure_eb_ptes.npz`` — the exact name
# config_space_pte_matrices.py reconstructs from --pte-intermediate-dir — straight
# into --out. Serial over versions; each version is fast (206-pair grid, ~seconds).
#
# Usage:
# run_pure_eb_ptes_sweep.sh --config <config.yaml> --cat-config <cat_config.yaml> \
# --pure-eb-sweep-dir <pure_eb/.../pure_eb_sweep> \
# --cov-sweep-dir <covariance/.../cov_sweep> \
# --out <output_dir> [--blind A] [--versions "v1 v2 ..."]
set -euo pipefail

. "$(dirname "${BASH_SOURCE[0]}")/container_env.sh"

CONFIG=""; CATCONFIG=""; PUREEBSWEEP=""; COVSWEEP=""; OUT=""; BLIND="A"; VERSIONS=""
CONFIG=""; CATCONFIG=""; PUREEBSWEEP=""; OUT=""; BLIND="A"; VERSIONS=""
while [ $# -gt 0 ]; do
case "$1" in
--config) CONFIG="$2"; shift 2;;
--cat-config) CATCONFIG="$2"; shift 2;;
--pure-eb-sweep-dir) PUREEBSWEEP="$2"; shift 2;;
--cov-sweep-dir) COVSWEEP="$2"; shift 2;;
--out) OUT="$2"; shift 2;;
--blind) BLIND="$2"; shift 2;;
--versions) VERSIONS="$2"; shift 2;;
Expand All @@ -41,16 +38,11 @@ VERSIONS=$(sweep_versions "$CONFIG")

for ver in $VERSIONS; do
pureeb="$PUREEBSWEEP/${ver}_${BLIND}_pure_eb_semianalytic.npz"
covbase="covariance_${ver}_${BLIND}_g_minsep=0.5_maxsep=300.0_nbins=1000_masked"
covint="$COVSWEEP/$covbase/${covbase}_processed.txt"
for f in "$pureeb" "$covint"; do
[ -f "$f" ] || { echo "MISSING upstream input for $ver: $f" >&2; exit 1; }
done
[ -f "$pureeb" ] || { echo "MISSING upstream input for $ver: $pureeb" >&2; exit 1; }
echo "[pure_eb_ptes_sweep] $ver"
spv_python "$PSCRIPTS/calculate_pure_eb_ptes.py" \
--version "$ver" --blind "$BLIND" \
--pure-eb-data "$pureeb" --cov-integration "$covint" \
--npatch 1 --n-samples 2000 --out "$OUT"
--pure-eb-data "$pureeb" --n-samples 2000 --out "$OUT"
echo "[pure_eb_ptes_sweep] $ver -> $OUT/${ver}_${BLIND}_pure_eb_ptes.npz"
done
echo "[pure_eb_ptes_sweep] done -> $OUT"
Loading
Loading