From aeba96cf905b60d357059e3763209be946e69b8c Mon Sep 17 00:00:00 2001 From: jaimerzp Date: Fri, 4 Jul 2025 13:45:27 +0100 Subject: [PATCH 1/2] bug --- heracles/dices/jackknife.py | 31 +++++++++++++------------------ tests/test_dices.py | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/heracles/dices/jackknife.py b/heracles/dices/jackknife.py index 6453c0e7..079f2a6c 100644 --- a/heracles/dices/jackknife.py +++ b/heracles/dices/jackknife.py @@ -327,15 +327,6 @@ def delete2_correction(cls0, cls1, cls2): Q_ii.append(qii) # Compute the correction from the ensemble Q = _jackknife_covariance(Q_ii, nd=2) - # Diagonalise the correction - for key in Q: - q = Q[key] - *_, length = q.shape - q_diag = np.diagonal(q, axis1=-2, axis2=-1) - q_diag_exp = np.zeros_like(q) - diag_indices = np.arange(length) # Indices for the diagonal - q_diag_exp[..., diag_indices, diag_indices] = q_diag - Q[key] = Result(q_diag_exp, axis=q.axis, ell=q.ell) return Q @@ -359,12 +350,16 @@ def _debias_covariance(cov_jk, Q): Internal method to debias the Jackknife covariance. Useful when the delete2 correction is already computed. """ - debiased_cov = {} - for key in list(cov_jk.keys()): - c = cov_jk[key].array - Q[key].array - debiased_cov[key] = Result( - c, - ell=cov_jk[key].ell, - axis=cov_jk[key].axis, - ) - return debiased_cov + debiased_cov = deepcopy(cov_jk) + for key in Q: + q = Q[key].array + c = debiased_cov[key].array + *_, length = q.shape + q_diag = np.diagonal(q, axis1=-2, axis2=-1) + c_diag = np.diagonal(c, axis1=-2, axis2=-1) + # Indices for the diagonal + diag_indices = np.arange(length) + # abs is only needed when too few Jackknife regions are used + c[..., diag_indices, diag_indices] = abs(c_diag-q_diag) + debiased_cov[key] = Result(c, axis=cov_jk[key].axis, ell=cov_jk[key].ell) + return debiased_cov \ No newline at end of file diff --git a/tests/test_dices.py b/tests/test_dices.py index 74b78b3c..0b9112a2 100644 --- a/tests/test_dices.py +++ b/tests/test_dices.py @@ -2,6 +2,7 @@ import numpy as np import heracles import pytest +from copy import deepcopy import heracles.dices as dices from heracles.healpy import HealpixMapper from heracles.fields import Positions, Shears, Visibility, Weights @@ -313,9 +314,18 @@ def test_debiasing(data_path): cqs1, cqs2, ) - _debiased_cov = {} + _debiased_cov = deepcopy(cov_jk) for key in list(cov_jk.keys()): - _debiased_cov[key] = cov_jk[key].array - Q[key] + q = Q[key].array + c = _debiased_cov[key].array + *_, length = q.shape + q_diag = np.diagonal(q, axis1=-2, axis2=-1) + c_diag = np.diagonal(c, axis1=-2, axis2=-1) + # Indices for the diagonal + diag_indices = np.arange(length) + # abs is only needed when too few Jackknife regions are used + c[..., diag_indices, diag_indices] = abs(c_diag-q_diag) + _debiased_cov[key] = c # Check diagonal for key in list(debiased_cov.keys()): From 6c2a41783100009b957c17249900a1b6ac1ec047 Mon Sep 17 00:00:00 2001 From: jaimerzp Date: Fri, 4 Jul 2025 13:48:32 +0100 Subject: [PATCH 2/2] ruff --- heracles/dices/jackknife.py | 4 ++-- tests/test_dices.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/heracles/dices/jackknife.py b/heracles/dices/jackknife.py index 079f2a6c..db5fa3b6 100644 --- a/heracles/dices/jackknife.py +++ b/heracles/dices/jackknife.py @@ -360,6 +360,6 @@ def _debias_covariance(cov_jk, Q): # Indices for the diagonal diag_indices = np.arange(length) # abs is only needed when too few Jackknife regions are used - c[..., diag_indices, diag_indices] = abs(c_diag-q_diag) + c[..., diag_indices, diag_indices] = abs(c_diag - q_diag) debiased_cov[key] = Result(c, axis=cov_jk[key].axis, ell=cov_jk[key].ell) - return debiased_cov \ No newline at end of file + return debiased_cov diff --git a/tests/test_dices.py b/tests/test_dices.py index 0b9112a2..0418722b 100644 --- a/tests/test_dices.py +++ b/tests/test_dices.py @@ -324,7 +324,7 @@ def test_debiasing(data_path): # Indices for the diagonal diag_indices = np.arange(length) # abs is only needed when too few Jackknife regions are used - c[..., diag_indices, diag_indices] = abs(c_diag-q_diag) + c[..., diag_indices, diag_indices] = abs(c_diag - q_diag) _debiased_cov[key] = c # Check diagonal