Skip to content

Commit

Permalink
Fixup: Even cleaner exception handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
parejkoj committed Nov 21, 2018
1 parent 065ec21 commit 7cf2bef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions python/lsst/pipe/tasks/makeCoaddTempExp.py
Expand Up @@ -35,7 +35,7 @@
__all__ = ["MakeCoaddTempExpTask"]


class MissingExposure(Exception):
class MissingExposureError(Exception):
"""Raised when data cannot be retrieved for an exposure.
When processing patches, sometimes one exposure is missing; this lets us
distinguish bewteen that case, and other errors.
Expand Down Expand Up @@ -457,7 +457,7 @@ def getCalibratedExposure(self, dataRef, bgSubtracted):
try:
exposure = dataRef.get("calexp", immediate=True)
except dafPersist.NoResults as e:
raise MissingExposure('"calexp" not found: %s ' % str(e)) from e
raise MissingExposureError('Exposure not found: %s ' % str(e)) from e

if not bgSubtracted:
background = dataRef.get("calexpBackground", immediate=True)
Expand All @@ -471,7 +471,10 @@ def getCalibratedExposure(self, dataRef, bgSubtracted):
# NOTE: this changes exposure in-place, updating its Calib and Wcs.
# Save the calibration error, as it gets overwritten with zero.
fluxMag0Err = exposure.getCalib().getFluxMag0()[1]
applyMosaicResultsExposure(dataRef, calexp=exposure)
try:
applyMosaicResultsExposure(dataRef, calexp=exposure)
except dafPersist.NoResults as e:
raise MissingExposureError('Mosaic calibration not found: %s ' % str(e)) from e
fluxMag0 = exposure.getCalib().getFluxMag0()[0]
photoCalib = afwImage.PhotoCalib(1.0/fluxMag0,
fluxMag0Err/fluxMag0**2,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_makeCoaddTempExp.py
Expand Up @@ -30,7 +30,7 @@
from lsst.daf.persistence import NoResults, ButlerDataRef
from lsst.pipe.tasks.makeCoaddTempExp import (MakeCoaddTempExpTask,
MakeCoaddTempExpConfig,
MissingExposure)
MissingExposureError)


class GetCalibratedExposureTestCase(lsst.utils.tests.TestCase):
Expand Down Expand Up @@ -90,10 +90,10 @@ def test_getCalibratedExposureGetCalexpRaises(self):

self.raiseOnGetCalexp = True

with self.assertRaises(MissingExposure) as cm:
with self.assertRaises(MissingExposureError) as cm:
task.getCalibratedExposure(self.dataRef, True)
self.assertIsInstance(cm.exception.__cause__, NoResults)
self.assertIn('"calexp" not found', str(cm.exception))
self.assertIn('Exposure not found', str(cm.exception))

def test_getCalibratedExposure(self):
task = MakeCoaddTempExpTask(config=self.config)
Expand Down

0 comments on commit 7cf2bef

Please sign in to comment.