LSST Applications g0fba68d861+2e894914a0,g1ec0fe41b4+e220e2fb2f,g1f759649c2+d3ce33c3e0,g1fd858c14a+2b9bf32e51,g35bb328faa+fcb1d3bbc8,g4d2262a081+1dc91b7776,g53246c7159+fcb1d3bbc8,g56a49b3a55+1053ce1741,g60b5630c4e+d3ce33c3e0,g67b6fd64d1+fad15079a7,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g8180f54f50+9253e245c2,g8352419a5c+fcb1d3bbc8,g8852436030+f11a5d3b0b,g89139ef638+fad15079a7,g9125e01d80+fcb1d3bbc8,g94187f82dc+d3ce33c3e0,g989de1cb63+fad15079a7,g9ccd5d7f00+44d9ee3d90,g9d31334357+d3ce33c3e0,g9f33ca652e+9a8c17f5f6,gabe3b4be73+1e0a283bba,gabf8522325+94c30d56e9,gb1101e3267+90933e15fb,gb58c049af0+f03b321e39,gb89ab40317+fad15079a7,gc0af124501+26f6120d90,gcf25f946ba+f11a5d3b0b,gd6cbbdb0b4+8d7f1baacb,gd794735e4e+4bba874dfe,gdb1c4ca869+16879ca1a6,gde0f65d7ad+0609b2c34e,ge278dab8ac+4d6e48c014,ge410e46f29+fad15079a7,gf5e32f922b+fcb1d3bbc8,gf618743f1b+dd10d22602,gf67bdafdda+fad15079a7,w.2025.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.afw.cameraGeom.utils.ButlerImage Class Reference
Inheritance diagram for lsst.afw.cameraGeom.utils.ButlerImage:
lsst.afw.cameraGeom.utils.FakeImageDataSource

Public Member Functions

 __init__ (self, butler=None, type="raw", isTrimmed=True, verbose=False, background=numpy.nan, callback=None, *args, **kwargs)
 
 getCcdImage (self, ccd, imageFactory=afwImage.ImageF, binSize=1, asMaskedImage=False)
 
 getAmpImage (self, amp, imageFactory)
 

Public Attributes

str type = type
 
 butler = butler
 
 kwargs = kwargs
 
bool isRaw = False
 
 callback = callback
 
 isTrimmed = isTrimmed
 
 verbose = verbose
 
 background = background
 
 showAmpGain = showAmpGain
 
 markSize = markSize
 
 markValue = markValue
 
 ampImValue = ampImValue
 
 scaleGain = scaleGain
 

Protected Member Functions

 _prepareImage (self, ccd, im, binSize, allowRotate=True)
 

Detailed Description

A class to return an Image of a given Ccd using the butler.

Parameters
----------
butler : `lsst.daf.butler.Butler` or `None`
    The butler to use. If `None`, an empty image is returned. Assumes that
    the instrument was specified during butler construction or is included
    in the ``kwargs`` parameter.
type : `str`
    The type of image to read (e.g. raw, bias, flat, calexp).
isTrimmed : `bool`
    If true, the showCamera command expects to be given trimmed images.
verbose : `bool`
    Be chatty (in particular, log any error messages from the butler)?
background : `float`
    The value of any pixels that lie outside the CCDs.
callback : callable
    A function called with (image, detector, butler) for every image, which
    returns the image to be displayed (e.g. rawCallback). The image must
    be of the correct size, allowing for the value of isTrimmed.
*args : `list`
    Passed to the base class constructor.
**kwargs : `dict`
    Passed to the butler.

Notes
-----
You can define a short named function as a callback::

    def callback(im, ccd, imageSource):
        return cameraGeom.utils.rawCallback(im, ccd, imageSource, correctGain=True)

Definition at line 403 of file utils.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.afw.cameraGeom.utils.ButlerImage.__init__ ( self,
butler = None,
type = "raw",
isTrimmed = True,
verbose = False,
background = numpy.nan,
callback = None,
* args,
** kwargs )

Definition at line 436 of file utils.py.

438 callback=None, *args, **kwargs):
439 super().__init__(*args)
440 self.isTrimmed = isTrimmed
441 self.type = type
442 self.butler = butler
443 self.kwargs = kwargs
444 self.isRaw = False
445 self.background = background
446 self.verbose = verbose
447 self.callback = callback
448

Member Function Documentation

◆ _prepareImage()

lsst.afw.cameraGeom.utils.ButlerImage._prepareImage ( self,
ccd,
im,
binSize,
allowRotate = True )
protected

Definition at line 449 of file utils.py.

449 def _prepareImage(self, ccd, im, binSize, allowRotate=True):
450 if binSize > 1:
451 im = afwMath.binImage(im, binSize)
452
453 if allowRotate:
455 im, ccd.getOrientation().getNQuarter())
456
457 return im
458
std::shared_ptr< ImageT > rotateImageBy90(ImageT const &image, int nQuarter)
Rotate an image by an integral number of quarter turns.
std::shared_ptr< ImageT > binImage(ImageT const &inImage, int const binX, int const binY, lsst::afw::math::Property const flags=lsst::afw::math::MEAN)
Definition binImage.cc:44

◆ getAmpImage()

lsst.afw.cameraGeom.utils.FakeImageDataSource.getAmpImage ( self,
amp,
imageFactory )
inherited
Return an amp segment image.

Parameters
----------
amp : `lsst.afw.table.AmpInfoTable`
    AmpInfoTable for this amp.
imageFactory : callable like `lsst.afw.image.Image`
    Image constructor for making the image.

Returns
-------
ampImage : `lsst.afw.image.Image`
    The constructed image.

Definition at line 380 of file utils.py.

380 def getAmpImage(self, amp, imageFactory):
381 """Return an amp segment image.
382
383 Parameters
384 ----------
385 amp : `lsst.afw.table.AmpInfoTable`
386 AmpInfoTable for this amp.
387 imageFactory : callable like `lsst.afw.image.Image`
388 Image constructor for making the image.
389
390 Returns
391 -------
392 ampImage : `lsst.afw.image.Image`
393 The constructed image.
394 """
395 ampImage = makeImageFromAmp(amp, imValue=self.ampImValue, imageFactory=imageFactory,
396 markSize=self.markSize, markValue=self.markValue,
397 scaleGain=self.scaleGain)
398 if self.isTrimmed:
399 ampImage = ampImage.Factory(ampImage, amp.getRawDataBBox())
400 return ampImage
401
402

◆ getCcdImage()

lsst.afw.cameraGeom.utils.ButlerImage.getCcdImage ( self,
ccd,
imageFactory = afwImage.ImageF,
binSize = 1,
asMaskedImage = False )
Return an image of the specified ccd, and also the (possibly updated) ccd

Reimplemented from lsst.afw.cameraGeom.utils.FakeImageDataSource.

Definition at line 459 of file utils.py.

459 def getCcdImage(self, ccd, imageFactory=afwImage.ImageF, binSize=1, asMaskedImage=False):
460 """Return an image of the specified ccd, and also the (possibly updated) ccd"""
461
462 log = _LOG.getChild("ButlerImage")
463
464 if self.isTrimmed:
465 bbox = ccd.getBBox()
466 else:
467 bbox = calcRawCcdBBox(ccd)
468
469 im = None
470 if self.butler is not None:
471 err = None
472 try:
473 im = self.butler.get(self.type, detector=ccd.getId(), **self.kwargs)
474 except FitsError as e:
475 err = IOError(e.args[0].split('\n')[0]) # It's a very chatty error
476 except Exception as e: # try a different dataId
477 err = e
478 else:
479 ccd = im.getDetector() # possibly modified by assembleCcdTask
480
481 if im:
482 if asMaskedImage:
483 im = im.getMaskedImage()
484 else:
485 im = im.getMaskedImage().getImage()
486 else:
487 if self.verbose:
488 # Lost by jupyterlab.
489 print(f"Reading {ccd.getId()}: {err}")
490
491 log.warning("Reading %s: %s", ccd.getId(), err)
492
493 if im is None:
494 return self._prepareImage(ccd, imageFactory(*bbox.getDimensions()), binSize), ccd
495
496 if self.type == "raw":
497 if hasattr(im, 'convertF'):
498 im = im.convertF()
499 if False and self.callback is None: # we need to trim the raw image
500 self.callback = rawCallback
501
502 allowRotate = True
503 if self.callback:
504 try:
505 im = self.callback(im, ccd, imageSource=self)
506 except Exception:
507 if self.verbose:
508 log.exception("callback failed.")
509 im = imageFactory(*bbox.getDimensions())
510 else:
511 allowRotate = False # the callback was responsible for any rotations
512
513 return self._prepareImage(ccd, im, binSize, allowRotate=allowRotate), ccd
514
515

Member Data Documentation

◆ ampImValue

lsst.afw.cameraGeom.utils.FakeImageDataSource.ampImValue = ampImValue
inherited

Definition at line 356 of file utils.py.

◆ background

lsst.afw.cameraGeom.utils.FakeImageDataSource.background = background
inherited

Definition at line 352 of file utils.py.

◆ butler

lsst.afw.cameraGeom.utils.ButlerImage.butler = butler

Definition at line 442 of file utils.py.

◆ callback

lsst.afw.cameraGeom.utils.ButlerImage.callback = callback

Definition at line 447 of file utils.py.

◆ isRaw

bool lsst.afw.cameraGeom.utils.ButlerImage.isRaw = False

Definition at line 444 of file utils.py.

◆ isTrimmed

lsst.afw.cameraGeom.utils.FakeImageDataSource.isTrimmed = isTrimmed
inherited

Definition at line 350 of file utils.py.

◆ kwargs

lsst.afw.cameraGeom.utils.ButlerImage.kwargs = kwargs

Definition at line 443 of file utils.py.

◆ markSize

lsst.afw.cameraGeom.utils.FakeImageDataSource.markSize = markSize
inherited

Definition at line 354 of file utils.py.

◆ markValue

lsst.afw.cameraGeom.utils.FakeImageDataSource.markValue = markValue
inherited

Definition at line 355 of file utils.py.

◆ scaleGain

lsst.afw.cameraGeom.utils.FakeImageDataSource.scaleGain = scaleGain
inherited

Definition at line 357 of file utils.py.

◆ showAmpGain

lsst.afw.cameraGeom.utils.FakeImageDataSource.showAmpGain = showAmpGain
inherited

Definition at line 353 of file utils.py.

◆ type

str lsst.afw.cameraGeom.utils.ButlerImage.type = type

Definition at line 441 of file utils.py.

◆ verbose

lsst.afw.cameraGeom.utils.FakeImageDataSource.verbose = verbose
inherited

Definition at line 351 of file utils.py.


The documentation for this class was generated from the following file: