From 2f78932d02df73e80161479eb048550ca02c6cb5 Mon Sep 17 00:00:00 2001 From: Cail Daley Date: Sat, 11 Jul 2026 14:30:57 +0200 Subject: [PATCH] =?UTF-8?q?Remove=20vestigial=20FHP/MK=20NOSHEAR=E2=86=901?= =?UTF-8?q?P=20Tpsf=20substitution=20(#257)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The metacal estimator and calibrate_comprehensive_cat.py carried a workaround that overwrote the metacal no-shear reconvolution-PSF size with the 1P value. It was a real fix for an older ShapePipe catalogue whose no-shear PSF was wrong, but is a guaranteed no-op under the current stack: ngmix builds one magnitude-dilated reconv PSF and reuses it across all metacal types, and ShapePipe fits it once per object and broadcasts the same scalar into every per-type column, so NOSHEAR and 1P are bit-identical for every object. - calibration.py: replace the silent overwrite with an np.testing.assert_array_equal(NOSHEAR, 1P) regression guard, so any future producer-side divergence fails loudly instead of being patched. - calibrate_comprehensive_cat.py: drop the override and the now-redundant NGMIX_T_PSF_RECONV_NOSHEAR_orig column. - test_calibration.py: update the estimator-stdout note (no hack line now). No output changes under the current stack. test_calibration.py: 8 passed. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Xthu9uZC17TsaeXh899fhc --- .../calibration/calibrate_comprehensive_cat.py | 10 ---------- src/sp_validation/calibration.py | 15 ++++++++------- src/sp_validation/tests/test_calibration.py | 4 ++-- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/scripts/calibration/calibrate_comprehensive_cat.py b/scripts/calibration/calibrate_comprehensive_cat.py index 4b15ed89..fb3ef3ca 100644 --- a/scripts/calibration/calibrate_comprehensive_cat.py +++ b/scripts/calibration/calibrate_comprehensive_cat.py @@ -191,16 +191,6 @@ for key in add_cols: add_cols_data[key] = cat.get_col(dat, key, mask_combined._mask, mask_metacal) -# Keep original NOSHEAR column, override with 1P PSF values (FHP/MK hack) -print( - "FHP/MK hack: explicit copying of the metacal no-shear (updated from 1p)" - + " PSF size" -) -add_cols_data["NGMIX_T_PSF_RECONV_NOSHEAR_orig"] = add_cols_data[ - "NGMIX_T_PSF_RECONV_NOSHEAR" -] -add_cols_data["NGMIX_T_PSF_RECONV_NOSHEAR"] = gal_metacal.ns["Tpsf"][mask_metacal] - # %% # Additional post-processing columns to write to output cat add_cols_post = [ diff --git a/src/sp_validation/calibration.py b/src/sp_validation/calibration.py index 9032bc63..a6e1e06c 100644 --- a/src/sp_validation/calibration.py +++ b/src/sp_validation/calibration.py @@ -789,13 +789,14 @@ def _read_data(self, data, mask): f"Unsupported shape prefix '{self._prefix}'; only 'NGMIX' is supported" ) - print("FHP/MK hack using p1 PSF for ns in cuts") - indices = np.where(mask)[0] - col_1p = f"{self._prefix}_T_PSF_RECONV_1P" - new_psf = data[col_1p][indices] - - # Overwriting incorrect no-shear PSF size to the one from 1p - ns["Tpsf"] = new_psf + # The reconvolution-PSF size is identical across all metacal types by + # construction: ngmix builds one magnitude-dilated reconv PSF and reuses + # it for noshear/1p/1m/2p/2m, and ShapePipe broadcasts that one scalar + # into every per-type column. Guard the invariant so any producer-side + # divergence fails loudly. + np.testing.assert_array_equal( + ns["Tpsf"], masked_data[f"{self._prefix}_T_PSF_RECONV_1P"] + ) self.m1 = m1 self.p1 = p1 diff --git a/src/sp_validation/tests/test_calibration.py b/src/sp_validation/tests/test_calibration.py index 40621c19..0a66aed5 100644 --- a/src/sp_validation/tests/test_calibration.py +++ b/src/sp_validation/tests/test_calibration.py @@ -296,8 +296,8 @@ def test_metacal_R_matrix_recovers_injected_response(): re-runs with slope 5.0 and confirms R11 tracks it (5.0 != 2.0), so a change that decouples R from the input numbers fails. - NOTE: the estimator prints an 'FHP/MK hack' line and an unweighted / - weighted response line; these are expected stdout, not errors. + NOTE: the estimator prints an unweighted / weighted response line; this + is expected stdout, not an error. """ data, n = _build_ngmix_catalog(slope_11=2.0, slope_22=3.0, step=0.01) mask = np.ones(n, dtype=bool)