Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-45002: Warn instead of raising with incomplete normalization aperture correction. #382

Merged
merged 1 commit into from
Jul 9, 2024
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
28 changes: 20 additions & 8 deletions python/lsst/meas/algorithms/normalizedCalibrationFlux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
13 changes: 9 additions & 4 deletions tests/test_normalizedCalibrationFlux.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import unittest

import numpy as np
import logging

import lsst.afw.image
import lsst.afw.table
Expand Down Expand Up @@ -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):
Expand Down
Loading