Skip to content

Commit

Permalink
Avoid propagating initial PSF, WCS, PhotoCalib on error.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Jan 6, 2025
1 parent 4df4dc7 commit 106db94
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions python/lsst/pipe/tasks/calibrateImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,21 @@ def run(self, *, exposures, id_generator=None, result=None):

result.exposure = self.snap_combine.run(exposures).exposure
self._recordMaskedPixelFractions(result.exposure)
self.log.info("Initial PhotoCalib: %s", result.exposure.getPhotoCalib())

result.background = None
summary_stat_catalog = None
# Some exposure components are set to initial placeholder objects
# while we try to bootstrap them. If we fail before we fit for them,
# we want to reset those components to None so the placeholders don't
# masquerade as the real thing.
have_fit_psf = False
have_fit_astrometry = False
have_fit_photometry = False
try:
result.psf_stars_footprints, result.background, _ = self._compute_psf(result.exposure,
id_generator)
have_fit_psf = True
summary_stat_catalog = result.psf_stars_footprints
self._measure_aperture_correction(result.exposure, result.psf_stars_footprints)
result.psf_stars = result.psf_stars_footprints.asAstropy()
Expand All @@ -659,13 +668,15 @@ def run(self, *, exposures, id_generator=None, result=None):
astrometry_matches, astrometry_meta = self._fit_astrometry(
result.exposure, result.stars_footprints
)
have_fit_astrometry = True
self.metadata["astrometry_matches_count"] = len(astrometry_matches)
if "astrometry_matches" in self.config.optional_outputs:
result.astrometry_matches = lsst.meas.astrom.denormalizeMatches(astrometry_matches,
astrometry_meta)

result.stars_footprints, photometry_matches, \
photometry_meta, photo_calib = self._fit_photometry(result.exposure, result.stars_footprints)
have_fit_photometry = True
self.metadata["photometry_matches_count"] = len(photometry_matches)
# fit_photometry returns a new catalog, so we need a new astropy table view.
result.stars = result.stars_footprints.asAstropy()
Expand All @@ -676,13 +687,19 @@ def run(self, *, exposures, id_generator=None, result=None):
if "photometry_matches" in self.config.optional_outputs:
result.photometry_matches = lsst.meas.astrom.denormalizeMatches(photometry_matches,
photometry_meta)
# Summary stat calculations can handle missing components gracefully,
# but we want to run them as late as possible (but still before we
# calibrate pixels, if we do that at all).
# So we run them after we succeed or if we get an AlgorithmError. We
# intentionally don't use 'finally' here because we don't want to run
# them if we get some other kind of error.
except pipeBase.AlgorithmError:
if not have_fit_psf:
result.exposure.setPsf(None)
if not have_fit_astrometry:
result.exposure.setWcs(None)
if not have_fit_photometry:
result.exposure.setPhotoCalib(None)
# Summary stat calculations can handle missing components gracefully,
# but we want to run them as late as possible (but still before we
# calibrate pixels, if we do that at all).
# So we run them after we succeed or if we get an AlgorithmError. We
# intentionally don't use 'finally' here because we don't want to run
# them if we get some other kind of error.
self._summarize(result.exposure, summary_stat_catalog, result.background)
raise
else:
Expand Down

0 comments on commit 106db94

Please sign in to comment.