diff --git a/python/lsst/meas/algorithms/normalizedCalibrationFlux.py b/python/lsst/meas/algorithms/normalizedCalibrationFlux.py index c3ba669d..9b6c97c5 100644 --- a/python/lsst/meas/algorithms/normalizedCalibrationFlux.py +++ b/python/lsst/meas/algorithms/normalizedCalibrationFlux.py @@ -175,16 +175,28 @@ def run(self, *, exposure, catalog): if self.config.do_measure_ap_corr: ap_corr_field, ap_corr_err_field = self._measure_aperture_correction(exposure, catalog) else: + use_identity = False ap_corr_map = exposure.info.getApCorrMap() if ap_corr_map is None: - raise RuntimeError("NormalizedCalibrationFluxTask is configured with " - "do_measure_ap_corr=False but exposure has no aperture correction map.") - ap_corr_field = ap_corr_map.get(raw_flux_name) - ap_corr_err_field = ap_corr_map.get(raw_fluxerr_name) - if not ap_corr_field or not ap_corr_err_field: - raise RuntimeError("NormalizedCalibrationFlux is configured with " - f"do_measure_ap_corr=False but {raw_flux_name}/{raw_fluxerr_name} " - "not in exposure aperture correction map.") + self.log.warning( + "Exposure does not have a valid normalization map; using identity normalization.", + ) + use_identity = True + else: + ap_corr_field = ap_corr_map.get(raw_flux_name) + ap_corr_err_field = ap_corr_map.get(raw_fluxerr_name) + if not ap_corr_field or not ap_corr_err_field: + self.log.warning( + "Exposure aperture correction map is missing %s/%s for normalization; " + "using identity normalization.", + raw_flux_name, + raw_fluxerr_name, + ) + use_identity = True + + if use_identity: + ap_corr_field = ChebyshevBoundedField(exposure.getBBox(), np.array([[1.0]])) + ap_corr_err_field = ChebyshevBoundedField(exposure.getBBox(), np.array([[0.0]])) corrections = ap_corr_field.evaluate( catalog["slot_Centroid_x"], diff --git a/tests/test_normalizedCalibrationFlux.py b/tests/test_normalizedCalibrationFlux.py index 7dcef359..78c2e581 100644 --- a/tests/test_normalizedCalibrationFlux.py +++ b/tests/test_normalizedCalibrationFlux.py @@ -22,6 +22,7 @@ import unittest import numpy as np +import logging import lsst.afw.image import lsst.afw.table @@ -245,15 +246,19 @@ def testNormalizedCalibrationFluxApplyOnlyFail(self): catalog_run2 = self._make_catalog(norm_task.schema) # Try without setting an aperture correction map at all. - with self.assertRaisesRegex(RuntimeError, "no aperture correction map"): - norm_task2.run(catalog=catalog_run2, exposure=exposure_run1) + with self.assertLogs(level=logging.WARNING) as cm: + _ = norm_task2.run(catalog=catalog_run2, exposure=exposure_run1) + warnings = '\n'.join(cm.output) + self.assertIn("does not have a valid normalization", warnings) # Try again after setting an incomplete aperture correction map. ap_corr_map_blank = lsst.afw.image.ApCorrMap() exposure_run1.info.setApCorrMap(ap_corr_map_blank) - with self.assertRaisesRegex(RuntimeError, "not in exposure aperture correction map"): - norm_task2.run(catalog=catalog_run2, exposure=exposure_run1) + with self.assertLogs(level=logging.WARNING) as cm: + _ = norm_task2.run(catalog=catalog_run2, exposure=exposure_run1) + warnings = '\n'.join(cm.output) + self.assertIn("aperture correction map is missing base_CompensatedTophatFlux_12_instFlux", warnings) class TestMemory(lsst.utils.tests.MemoryTestCase):