Skip to content

Commit

Permalink
Another couple of fixups
Browse files Browse the repository at this point in the history
1. Improved error message when the butler understood the dataId but
couldn't read the file
2. Explained allowRotate=False and made it's use slightly more accurate
  • Loading branch information
RobertLuptonTheGood committed Aug 10, 2018
1 parent 2bbf0fb commit a6c6597
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions python/lsst/afw/cameraGeom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
import warnings

import lsst.geom
from lsst.afw.fits import FitsError
import lsst.afw.geom as afwGeom
import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
import lsst.daf.base as dafBase
import lsst.log
import lsst.pex.exceptions as pexExceptions

from .rotateBBoxBy90 import rotateBBoxBy90
from .assembleImage import assembleAmplifierImage, assembleAmplifierRawImage
Expand Down Expand Up @@ -459,22 +461,28 @@ def getCcdImage(self, ccd, imageFactory=afwImage.ImageF, binSize=1):

im = None
if self.butler is not None:
im = None
err = None
for dataId in [dict(detector=ccd.getId()), dict(ccd=ccd.getId()), dict(ccd=ccd.getName())]:
try:
im = self.butler.get(self.type, dataId, **self.kwargs)
ccd = im.getDetector() # possibly modified by assembleCcdTask
except FitsError as e: # no point trying another dataId
err = IOError(e.args[0].split('\n')[0]) # It's a very chatty error
break
except Exception as e:
err = e
except Exception as e: # try a different dataId
if err is None:
err = e
continue
else:
ccd = im.getDetector() # possibly modified by assembleCcdTask
break

if im:
im = im.getMaskedImage().getImage()
else:
if self.verbose:
print("Reading %s: %s" % (ccd.getId(), err))
log.warn("Reading %s: %s" % (ccd.getId(), err))
print("Reading %s: %s" % (ccd.getId(), err)) # lost by jupyterLab

log.warn("Reading %s: %s", ccd.getId(), err)

if im is None:
return self._prepareImage(ccd, imageFactory(*bbox.getDimensions()), binSize), ccd
Expand All @@ -485,15 +493,18 @@ def getCcdImage(self, ccd, imageFactory=afwImage.ImageF, binSize=1):
if False and self.callback is None: # we need to trim the raw image
self.callback = rawCallback

allowRotate = True
if self.callback:
try:
im = self.callback(im, ccd, imageSource=self)
except Exception as e:
if self.verbose:
log.error("callback failed: %s" % e)
im = imageFactory(*bbox.getDimensions())
else:
allowRotate = False # the callback was responsible for any rotations

return self._prepareImage(ccd, im, binSize, allowRotate=False), ccd
return self._prepareImage(ccd, im, binSize, allowRotate=allowRotate), ccd


def rawCallback(im, ccd=None, imageSource=None,
Expand Down

0 comments on commit a6c6597

Please sign in to comment.