23 Support for displaying cameraGeom objects. 26 __all__ = [
'prepareWcsData',
'plotFocalPlane',
'makeImageFromAmp',
'calcRawCcdBBox',
'makeImageFromCcd',
27 'FakeImageDataSource',
'ButlerImage',
'rawCallback',
'overlayCcdBoxes',
28 'showAmp',
'showCcd',
'getCcdInCamBBoxList',
'getCameraImageBBox',
29 'makeImageFromCamera',
'showCamera',
'makeFocalPlaneWcs',
'findAmp']
44 from .rotateBBoxBy90
import rotateBBoxBy90
45 from .assembleImage
import assembleAmplifierImage, assembleAmplifierRawImage
46 from .cameraGeomLib
import FIELD_ANGLE, FOCAL_PLANE
54 """Put Wcs from an Amp image into CCD coordinates 58 wcs : `lsst.afw.geom.SkyWcs` 59 The WCS object to start from. 60 amp : `lsst.afw.table.AmpInfoRecord` 63 Is the image to which the WCS refers trimmed of non-imaging pixels? 67 ampWcs : `lsst.afw.geom.SkyWcs` 70 if not amp.getHasRawInfo():
71 raise RuntimeError(
"Cannot modify wcs without raw amp information")
73 ampBox = amp.getRawDataBBox()
75 ampBox = amp.getRawBBox()
77 wcs = afwGeom.makeFlippedWcs(wcs, amp.getRawFlipX(), amp.getRawFlipY(), ampCenter)
80 trim_shift = ampBox.getMin() - amp.getBBox().getMin()
81 wcs = wcs.copyAtShiftedPixelOrigin(
lsst.geom.Extent2D(-trim_shift.getX(), -trim_shift.getY()))
83 offset = amp.getRawXYOffset()
87 def plotFocalPlane(camera, fieldSizeDeg_x=0, fieldSizeDeg_y=None, dx=0.1, dy=0.1, figsize=(10., 10.),
88 useIds=
False, showFig=
True, savePath=
None):
89 """Make a plot of the focal plane along with a set points that sample 94 camera : `lsst.afw.cameraGeom.Camera` 96 fieldSizeDeg_x : `float` 97 Amount of the field to sample in x in degrees 98 fieldSizeDeg_y : `float` or None 99 Amount of the field to sample in y in degrees 101 Spacing of sample points in x in degrees 103 Spacing of sample points in y in degrees 104 figsize : `tuple` containing two `float` 105 Matplotlib style tuple indicating the size of the figure in inches 107 Label detectors by name, not id? 109 Display the figure on the screen? 110 savePath : `str` or None 111 If not None, save a copy of the figure to this name. 114 from matplotlib.patches
import Polygon
115 from matplotlib.collections
import PatchCollection
116 import matplotlib.pyplot
as plt
119 "Can't run plotFocalPlane: matplotlib has not been set up")
122 if fieldSizeDeg_y
is None:
123 fieldSizeDeg_y = fieldSizeDeg_x
125 field_gridx, field_gridy = numpy.meshgrid(numpy.arange(0., fieldSizeDeg_x+dx, dx) - fieldSizeDeg_x/2.,
126 numpy.arange(0., fieldSizeDeg_y+dy, dy) - fieldSizeDeg_y/2.)
127 field_gridx, field_gridy = field_gridx.flatten(), field_gridy.flatten()
129 field_gridx, field_gridy = [], []
137 for x, y
in zip(field_gridx, field_gridy)]
138 posFocalPlaneList = camera.transform(posFieldAngleList, FIELD_ANGLE, FOCAL_PLANE)
139 for posFocalPlane
in posFocalPlaneList:
140 xs.append(posFocalPlane.getX())
141 ys.append(posFocalPlane.getY())
142 dets = camera.findDetectors(posFocalPlane, FOCAL_PLANE)
148 colorMap = {0:
'b', 1:
'y', 2:
'g', 3:
'r'} 152 plt.figure(figsize=figsize) 157 corners = [(c.getX(), c.getY())
for c
in det.getCorners(FOCAL_PLANE)]
158 for corner
in corners:
159 xvals.append(corner[0])
160 yvals.append(corner[1])
161 colors.append(colorMap[det.getType()])
162 patches.append(Polygon(corners,
True))
163 center = det.getOrientation().getFpPosition()
164 ax.text(center.getX(), center.getY(), det.getId()
if useIds
else det.getName(),
165 horizontalalignment=
'center', size=6)
167 patchCollection = PatchCollection(patches, alpha=0.6, facecolor=colors)
168 ax.add_collection(patchCollection)
169 ax.scatter(xs, ys, s=10, alpha=.7, linewidths=0., c=pcolors)
170 ax.set_xlim(
min(xvals) - abs(0.1*
min(xvals)),
171 max(xvals) + abs(0.1*
max(xvals)))
172 ax.set_ylim(
min(yvals) - abs(0.1*
min(yvals)),
173 max(yvals) + abs(0.1*
max(yvals)))
174 ax.set_xlabel(
'Focal Plane X (mm)')
175 ax.set_ylabel(
'Focal Plane Y (mm)')
176 if savePath
is not None:
177 plt.savefig(savePath)
182 def makeImageFromAmp(amp, imValue=None, imageFactory=afwImage.ImageU, markSize=10, markValue=0,
183 scaleGain=lambda gain: (gain*1000)//10):
184 """Make an image from an amp object. 186 Since images are integer images by default, the gain needs to be scaled to 187 give enough dynamic range to see variation from amp to amp. 188 The scaling algorithm is assignable. 192 amp : `lsst.afw.table.AmpInfoRecord` 193 Amp record to use for constructing the raw amp image. 194 imValue : `float` or None 195 Value to assign to the constructed image, or scaleGain(gain) if None. 196 imageFactory : callable like `lsst.afw.image.Image` 197 Type of image to construct. 199 Size of mark at read corner in pixels. 201 Value of pixels in the read corner mark. 203 The function by which to scale the gain (must take a single argument). 207 ampImage : `lsst.afw.image` 208 An untrimmed amp image, of the type produced by ``imageFactory``. 210 if not amp.getHasRawInfo():
212 "Can't create a raw amp image without raw amp information")
213 bbox = amp.getRawBBox()
214 dbbox = amp.getRawDataBBox()
215 img = imageFactory(bbox)
217 img.set(scaleGain(amp.getGain()))
222 if amp.getReadoutCorner() == 0:
223 markbbox.include(dbbox.getMin())
225 elif amp.getReadoutCorner() == 1:
227 markbbox.include(cornerPoint)
229 elif amp.getReadoutCorner() == 2:
231 markbbox.include(cornerPoint)
233 elif amp.getReadoutCorner() == 3:
235 markbbox.include(cornerPoint)
238 raise RuntimeError(
"Could not set readout corner")
239 mimg = imageFactory(img, markbbox)
245 """Calculate the raw ccd bounding box. 249 ccd : `lsst.afw.cameraGeom.Detector` 250 Detector for which to calculate the un-trimmed bounding box. 254 box : `Box2I` or None 255 Bounding box of the un-trimmed Detector, or None if there is not enough 256 information to calculate raw BBox. 260 if not amp.getHasRawInfo():
262 tbbox = amp.getRawBBox()
263 tbbox.shift(amp.getRawXYOffset())
268 def makeImageFromCcd(ccd, isTrimmed=True, showAmpGain=True, imageFactory=afwImage.ImageU, rcMarkSize=10,
270 """Make an Image of a CCD. 274 ccd : `lsst.afw.cameraGeom.Detector` 275 Detector to use in making the image. 277 Assemble a trimmed Detector image. 279 Use the per-amp gain to color the pixels in the image? 280 imageFactory : callable like `lsst.afw.image.Image` 281 Image type to generate. 283 Size of the mark to make in the amp images at the read corner. 285 Bin the image by this factor in both dimensions. 289 image : `lsst.afw.image.Image` 290 Image of the Detector (type returned by ``imageFactory``). 299 if amp.getHasRawInfo():
302 amp, imageFactory=imageFactory, markSize=rcMarkSize))
305 imageFactory=imageFactory, markSize=rcMarkSize))
308 if len(ampImages) > 0:
309 ccdImage = imageFactory(bbox)
310 for ampImage, amp
in zip(ampImages, ccd):
318 "Cannot create untrimmed CCD without amps with raw information")
319 ccdImage = imageFactory(ccd.getBBox())
325 """A class to retrieve synthetic images for display by the show* methods 330 Should amps be trimmed? 334 The value of any pixels that lie outside the CCDs. 336 Color the amp segments with the gain of the amp? 338 Size of the side of the box used to mark the read corner. 340 Value to assign the read corner mark. 341 ampImValue : `float` or None 342 Value to assign to amps; scaleGain(gain) is used if None. 344 Function to scale the gain by. 347 def __init__(self, isTrimmed=True, verbose=False, background=numpy.nan,
348 showAmpGain=True, markSize=10, markValue=0,
349 ampImValue=None, scaleGain=lambda gain: (gain*1000)//10):
360 """Return a CCD image for the detector and the (possibly updated) Detector. 364 det : `lsst.afw.cameraGeom.Detector` 365 Detector to use for making the image. 366 imageFactory : callable like `lsst.afw.image.Image` 367 Image constructor for making the image. 369 Bin the image by this factor in both dimensions. 373 ccdImage : `lsst.afw.image.Image` 374 The constructed image. 377 imageFactory=imageFactory, binSize=binSize), det
380 """Return an amp segment image. 384 amp : `lsst.afw.table.AmpInfoTable` 385 AmpInfoTable for this amp. 386 imageFactory : callable like `lsst.afw.image.Image` 387 Image constructor for making the image. 391 ampImage : `lsst.afw.image.Image` 392 The constructed image. 398 ampImage = ampImage.Factory(ampImage, amp.getRawDataBBox())
403 """A class to return an Image of a given Ccd using the butler. 407 butler : `lsst.daf.persistence.Butler` or None 408 The butler to use. If None, an empty image is returned. 410 The type of image to read (e.g. raw, bias, flat, calexp). 412 If true, the showCamera command expects to be given trimmed images. 414 Be chatty (in particular, log any error messages from the butler)? 416 The value of any pixels that lie outside the CCDs. 418 A function called with (image, ccd, butler) for every image, which 419 returns the image to be displayed (e.g. rawCallback). The image must 420 be of the correct size, allowing for the value of isTrimmed. 422 Passed to the butler. 424 Passed to the butler. 428 You can define a short named function as a callback:: 430 def callback(im, ccd, imageSource): 431 return cameraGeom.utils.rawCallback(im, ccd, imageSource, correctGain=True) 434 def __init__(self, butler=None, type="raw",
435 isTrimmed=True, verbose=False, background=numpy.nan,
436 callback=None, *args, **kwargs):
437 super(ButlerImage, self).
__init__(*args)
447 def _prepareImage(self, ccd, im, binSize, allowRotate=True):
453 im, ccd.getOrientation().getNQuarter())
457 def getCcdImage(self, ccd, imageFactory=afwImage.ImageF, binSize=1, asMaskedImage=False):
458 """Return an image of the specified ccd, and also the (possibly updated) ccd""" 468 if self.
butler is not None:
470 for dataId
in [dict(detector=ccd.getId()), dict(ccd=ccd.getId()), dict(ccd=ccd.getName())]:
473 except FitsError
as e:
474 err = IOError(e.args[0].split(
'\n')[0])
476 except Exception
as e:
481 ccd = im.getDetector()
486 im = im.getMaskedImage()
488 im = im.getMaskedImage().getImage()
491 print(
"Reading %s: %s" % (ccd.getId(), err))
493 log.warn(
"Reading %s: %s", ccd.getId(), err)
496 return self.
_prepareImage(ccd, imageFactory(*bbox.getDimensions()), binSize), ccd
498 if self.
type ==
"raw":
499 if hasattr(im,
'convertF'):
507 im = self.
callback(im, ccd, imageSource=self)
508 except Exception
as e:
510 log.error(
"callback failed: %s" % e)
511 im = imageFactory(*bbox.getDimensions())
515 return self.
_prepareImage(ccd, im, binSize, allowRotate=allowRotate), ccd
519 correctGain=False, subtractBias=False, convertToFloat=False):
520 """A callback function that may or may not subtract bias/correct gain/trim 525 im : `lsst.afw.image.Image` or `lsst.afw.image.MaskedImage` or `lsst.afw.image.Exposure` 526 An image of a chip, ready to be binned and maybe rotated. 527 ccd : `lsst.afw.cameraGeom.Detector` or None 528 The Detector; if None assume that im is an exposure and extract its Detector. 529 imageSource : `FakeImageDataSource` or None 530 Source to get ccd images. Must have a `getCcdImage()` method. 532 Correct each amplifier for its gain? 533 subtractBias : `bool` 534 Subtract the bias from each amplifier? 535 convertToFloat : `bool` 536 Convert im to floating point if possible. 540 image : `lsst.afw.image.Image` like 541 The constructed image (type returned by ``im.Factory``). 545 If imageSource is derived from ButlerImage, imageSource.butler is available. 548 ccd = im.getDetector()
549 if hasattr(im,
"getMaskedImage"):
550 im = im.getMaskedImage()
551 if convertToFloat
and hasattr(im,
"convertF"):
554 isTrimmed = imageSource.isTrimmed
563 data = im[a.getRawDataBBox()]
568 bias = im[a.getRawHorizontalOverscanBBox()]
573 ampImages.append(data)
575 ccdImage = im.Factory(bbox)
576 for ampImage, amp
in zip(ampImages, ccd):
586 isTrimmed=False, ccdOrigin=(0, 0), display=
None, binSize=1):
587 """Overlay bounding boxes on an image display. 591 ccd : `lsst.afw.cameraGeom.Detector` 592 Detector to iterate for the amp bounding boxes. 593 untrimmedCcdBbox : `lsst.geom.Box2I` or None 594 Bounding box of the un-trimmed Detector. 596 number of 90 degree rotations to apply to the bounding boxes (used for rotated chips). 598 Is the Detector image over which the boxes are layed trimmed? 599 ccdOrigin : `tuple` of `float` 600 Detector origin relative to the parent origin if in a larger pixel grid. 601 display : `lsst.afw.display.Display` 602 Image display to display on. 604 Bin the image by this factor in both dimensions. 609 - Entire detector GREEN 610 - All data for amp GREEN 611 - HorizontalPrescan YELLOW 612 - HorizontalOverscan RED 614 - VerticalOverscan MAGENTA 615 - VerticalOverscan MAGENTA 618 raise RuntimeError(
"Please specify a display")
620 if untrimmedCcdBbox
is None:
622 untrimmedCcdBbox = ccd.getBBox()
625 for a
in ccd.getAmpInfoCatalog():
626 bbox = a.getRawBBox()
627 untrimmedCcdBbox.include(bbox)
629 with display.Buffering():
630 ccdDim = untrimmedCcdBbox.getDimensions()
634 ampbbox = amp.getBBox()
636 ampbbox = amp.getRawBBox()
640 displayUtils.drawBBox(ampbbox, origin=ccdOrigin, borderWidth=0.49,
641 display=display, bin=binSize)
643 if not isTrimmed
and amp.getHasRawInfo():
644 for bbox, ctype
in ((amp.getRawHorizontalOverscanBBox(), afwDisplay.RED),
645 (amp.getRawDataBBox(), afwDisplay.BLUE),
646 (amp.getRawVerticalOverscanBBox(),
648 (amp.getRawPrescanBBox(), afwDisplay.YELLOW)):
651 displayUtils.drawBBox(bbox, origin=ccdOrigin, borderWidth=0.49, ctype=ctype,
652 display=display, bin=binSize)
654 xc, yc = (ampbbox.getMin()[0] + ampbbox.getMax()[0])//2, (ampbbox.getMin()[1] +
655 ampbbox.getMax()[1])//2
668 ccdHeight = ccdBbox.getHeight()
669 ccdWidth = ccdBbox.getWidth()
673 xc, yc = 0.5*ccdHeight + c*xc + s*yc, 0.5*ccdWidth + -s*xc + c*yc
678 display.dot(str(amp.getName()), xc/binSize,
679 yc/binSize, textAngle=nQuarter*90)
681 displayUtils.drawBBox(ccdBbox, origin=ccdOrigin,
682 borderWidth=0.49, ctype=afwDisplay.MAGENTA, display=display, bin=binSize)
685 def showAmp(amp, imageSource=FakeImageDataSource(isTrimmed=
False), display=
None, overlay=
True,
686 imageFactory=afwImage.ImageU):
687 """Show an amp in an image display. 691 amp : `lsst.afw.tables.AmpInfoRecord` 692 Amp record to use in display. 693 imageSource : `FakeImageDataSource` or None 694 Source for getting the amp image. Must have a ``getAmpImage()`` method. 695 display : `lsst.afw.display.Display` 696 Image display to use. 698 Overlay bounding boxes? 699 imageFactory : callable like `lsst.afw.image.Image` 700 Type of image to display (only used if ampImage is None). 704 display = _getDisplayFromDisplayOrFrame()
706 ampImage = imageSource.getAmpImage(amp, imageFactory=imageFactory)
707 ampImSize = ampImage.getDimensions()
708 title = amp.getName()
709 display.mtv(ampImage, title=title)
711 with display.Buffering():
712 if amp.getHasRawInfo()
and ampImSize == amp.getRawBBox().getDimensions():
713 bboxes = [(amp.getRawBBox(), 0.49, afwDisplay.GREEN), ]
714 xy0 = bboxes[0][0].getMin()
716 (amp.getRawHorizontalOverscanBBox(), 0.49, afwDisplay.RED))
717 bboxes.append((amp.getRawDataBBox(), 0.49, afwDisplay.BLUE))
718 bboxes.append((amp.getRawPrescanBBox(),
719 0.49, afwDisplay.YELLOW))
720 bboxes.append((amp.getRawVerticalOverscanBBox(),
721 0.49, afwDisplay.MAGENTA))
723 bboxes = [(amp.getBBox(), 0.49,
None), ]
724 xy0 = bboxes[0][0].getMin()
726 for bbox, borderWidth, ctype
in bboxes:
731 displayUtils.drawBBox(
732 bbox, borderWidth=borderWidth, ctype=ctype, display=display)
735 def showCcd(ccd, imageSource=FakeImageDataSource(), display=
None, frame=
None, overlay=
True,
736 imageFactory=afwImage.ImageF, binSize=1, inCameraCoords=
False):
737 """Show a CCD on display. 741 ccd : `lsst.afw.cameraGeom.Detector` 742 Detector to use in display. 743 imageSource : `FakeImageDataSource` or None 744 Source to get ccd images. Must have a ``getCcdImage()`` method. 745 display : `lsst.afw.display.Display` 746 image display to use. 748 frame ID on which to display. **Deprecated** in v12. 750 Show amp bounding boxes on the displayed image? 751 imageFactory : callable like `lsst.afw.image.Image` 752 The image factory to use in generating the images. 754 Bin the image by this factor in both dimensions. 755 inCameraCoords : `bool` 756 Show the Detector in camera coordinates? 758 if frame
is not None:
759 warnings.warn(
"The frame kwarg is deprecated; use the `lsst.afw.display` system instead.",
762 display = _getDisplayFromDisplayOrFrame(display, frame)
766 ccdImage, ccd = imageSource.getCcdImage(
767 ccd, imageFactory=imageFactory, binSize=binSize)
769 ccdBbox = ccdImage.getBBox()
770 if ccdBbox.getDimensions() == ccd.getBBox().getDimensions():
776 nQuarter = ccd.getOrientation().getNQuarter()
778 title = ccd.getName()
783 display.mtv(ccdImage, title=title)
787 ccdOrigin, display, binSize)
793 """Get the bounding boxes of a list of Detectors within a camera sized pixel grid 797 ccdList : `lsst.afw.cameraGeom.Detector` 800 Bin the image by this factor in both dimensions. 801 pixelSize_o : `float` 802 Size of the pixel in mm. 804 Origin of the camera pixel grid in pixels. 808 boxList : `list` of `lsst.geom.Box2I` 809 A list of bounding boxes in camera pixel coordinates. 813 if not pixelSize_o == ccd.getPixelSize():
815 "Cameras with detectors with different pixel scales are not currently supported")
818 for corner
in ccd.getCorners(FOCAL_PLANE):
819 dbbox.include(corner)
821 nQuarter = ccd.getOrientation().getNQuarter()
822 cbbox = ccd.getBBox()
823 ex = cbbox.getDimensions().getX()//binSize
824 ey = cbbox.getDimensions().getY()//binSize
829 int(llc.getY()//pixelSize_o.getY()/binSize)))
831 -int(origin.getY())//binSize))
837 """Get the bounding box of a camera sized image in pixels 841 camBbox : `lsst.geom.Box2D` 842 Camera bounding box in focal plane coordinates (mm). 844 Size of a detector pixel in mm. 846 Buffer around edge of image in pixels. 850 box : `lsst.geom.Box2I` 851 The resulting bounding box. 854 int(camBbox.getMinY()//pixelSize.getY()))
856 int(camBbox.getMaxY()//pixelSize.getY()))
858 retBox.grow(bufferSize)
862 def makeImageFromCamera(camera, detectorNameList=None, background=numpy.nan, bufferSize=10,
863 imageSource=FakeImageDataSource(), imageFactory=afwImage.ImageU, binSize=1):
864 """Make an Image of a Camera. 866 Put each detector's image in the correct location and orientation on the 867 focal plane. The input images can be binned to an integer fraction of their 872 camera : `lsst.afw.cameraGeom.Camera` 873 Camera object to use to make the image. 874 detectorNameList : `list` of `str` 875 List of detector names from `camera` to use in building the image. 876 Use all Detectors if None. 878 Value to use where there is no Detector. 880 Size of border in binned pixels to make around the camera image. 881 imageSource : `FakeImageDataSource` or None 882 Source to get ccd images. Must have a ``getCcdImage()`` method. 883 imageFactory : callable like `lsst.afw.image.Image` 884 Type of image to build. 886 Bin the image by this factor in both dimensions. 890 image : `lsst.afw.image.Image` 891 Image of the entire camera. 895 if detectorNameList
is None:
898 ccdList = [camera[name]
for name
in detectorNameList]
900 if detectorNameList
is None:
901 camBbox = camera.getFpBBox()
904 for detName
in detectorNameList:
905 for corner
in camera[detName].getCorners(FOCAL_PLANE):
906 camBbox.include(corner)
908 pixelSize_o = camera[next(camera.getNameIter())].getPixelSize()
910 origin = camBbox.getMin()
912 camIm = imageFactory(int(math.ceil(camBbox.getDimensions().getX()/binSize)),
913 int(math.ceil(camBbox.getDimensions().getY()/binSize)))
914 camIm[:] = imageSource.background
916 assert imageSource.isTrimmed,
"isTrimmed is False isn't supported by getCcdInCamBBoxList" 919 for det, bbox
in zip(ccdList, boxList):
920 im = imageSource.getCcdImage(det, imageFactory, binSize)[0]
924 nQuarter = det.getOrientation().getNQuarter()
927 imView = camIm.Factory(camIm, bbox, afwImage.LOCAL)
931 log.error(
"Unable to fit image for detector \"%s\" into image of camera: %s" % (det.getName(), e))
936 def showCamera(camera, imageSource=FakeImageDataSource(), imageFactory=afwImage.ImageF,
937 detectorNameList=
None, binSize=10, bufferSize=10, frame=
None, overlay=
True, title=
"",
938 showWcs=
None, ctype=afwDisplay.GREEN, textSize=1.25, originAtCenter=
True, display=
None,
940 """Show a Camera on display, with the specified display. 942 The rotation of the sensors is snapped to the nearest multiple of 90 deg. 943 Also note that the pixel size is constant over the image array. The lower 944 left corner (LLC) of each sensor amp is snapped to the LLC of the pixel 945 containing the LLC of the image. 949 camera : `lsst.afw.cameraGeom.Camera` 950 Camera object to use to make the image. 951 imageSource : `FakeImageDataSource` or None 952 Source to get ccd images. Must have a ``getCcdImage()`` method. 953 imageFactory : `lsst.afw.image.Image` 954 Type of image to make 955 detectorNameList : `list` of `str` 956 List of detector names from `camera` to use in building the image. 957 Use all Detectors if None. 959 Bin the image by this factor in both dimensions. 961 Size of border in binned pixels to make around the camera image. 963 specify image display. **Deprecated** in v12. 965 Overlay Detector IDs and boundaries? 967 Title to use in display. 969 Include a WCS in the display? 970 ctype : `lsst.afw.display.COLOR` or `str` 971 Color to use when drawing Detector boundaries. 973 Size of detector labels 974 originAtCenter : `bool` 975 Put origin of the camera WCS at the center of the image? 976 If False, the origin will be at the lower left. 977 display : `lsst.afw.display` 978 Image display on which to display. 980 All remaining keyword arguments are passed to makeImageFromCamera 984 image : `lsst.afw.image.Image` 987 if frame
is not None:
988 warnings.warn(
"The frame kwarg is deprecated; use the `lsst.afw.display` system instead.",
991 display = _getDisplayFromDisplayOrFrame(display, frame)
995 cameraImage =
makeImageFromCamera(camera, detectorNameList=detectorNameList, bufferSize=bufferSize,
996 imageSource=imageSource, imageFactory=imageFactory, binSize=binSize,
999 if detectorNameList
is None:
1000 ccdList = [camera[name]
for name
in camera.getNameIter()]
1002 ccdList = [camera[name]
for name
in detectorNameList]
1004 if detectorNameList
is None:
1005 camBbox = camera.getFpBBox()
1008 for detName
in detectorNameList:
1009 for corner
in camera[detName].getCorners(FOCAL_PLANE):
1010 camBbox.include(corner)
1011 pixelSize = ccdList[0].getPixelSize()
1016 cameraImage.getBBox()).getCenter()
1025 title = camera.getName()
1026 display.mtv(cameraImage, title=title, wcs=wcs)
1029 with display.Buffering():
1031 camBbox, pixelSize, bufferSize*binSize)
1033 ccdList, binSize, pixelSize, camBbox.getMin())
1034 for bbox, ccd
in zip(bboxList, ccdList):
1035 nQuarter = ccd.getOrientation().getNQuarter()
1038 displayUtils.drawBBox(
1039 bbox, borderWidth=0.5, ctype=ctype, display=display)
1040 dims = bbox.getDimensions()
1041 display.dot(ccd.getName(), bbox.getMinX()+dims.getX()/2, bbox.getMinY()+dims.getY()/2,
1042 ctype=ctype, size=textSize, textAngle=nQuarter*90)
1048 """Make a WCS for the focal plane geometry 1049 (i.e. one that returns positions in "mm") 1054 Size of the image pixels in physical units 1055 referencePixel : `lsst.geom.Point2D` 1056 Pixel for origin of WCS 1061 Wcs object for mapping between pixels and focal plane. 1065 if referencePixel
is None:
1068 md.set(
"CRPIX%d"%(i+1), referencePixel[i])
1069 md.set(
"CRVAL%d"%(i+1), 0.)
1070 md.set(
"CDELT1", pixelSize[0])
1071 md.set(
"CDELT2", pixelSize[1])
1072 md.set(
"CTYPE1",
"CAMERA_X")
1073 md.set(
"CTYPE2",
"CAMERA_Y")
1074 md.set(
"CUNIT1",
"mm")
1075 md.set(
"CUNIT2",
"mm")
1077 return afwGeom.makeSkyWcs(md)
1081 """Find the Amp with the specified pixel position within the composite 1085 ccd : `lsst.afw.cameraGeom.Detector` 1086 Detector to look in. 1087 pixelPosition : `lsst.geom.Point2I` 1088 The pixel position to find the amp for. 1092 `lsst.afw.table.AmpInfoCatalog` 1093 Amp record in which pixelPosition falls or None if no Amp found. 1097 if amp.getBBox().contains(pixelPosition):
def makeImageFromAmp(amp, imValue=None, imageFactory=afwImage.ImageU, markSize=10, markValue=0, scaleGain=lambda gain:(gain *1000)//10)
def makeFocalPlaneWcs(pixelSize, referencePixel)
def showCamera(camera, imageSource=FakeImageDataSource(), imageFactory=afwImage.ImageF, detectorNameList=None, binSize=10, bufferSize=10, frame=None, overlay=True, title="", showWcs=None, ctype=afwDisplay.GREEN, textSize=1.25, originAtCenter=True, display=None, kwargs)
def plotFocalPlane(camera, fieldSizeDeg_x=0, fieldSizeDeg_y=None, dx=0.1, dy=0.1, figsize=(10., 10.), useIds=False, showFig=True, savePath=None)
def showCcd(ccd, imageSource=FakeImageDataSource(), display=None, frame=None, overlay=True, imageFactory=afwImage.ImageF, binSize=1, inCameraCoords=False)
def getCcdInCamBBoxList(ccdList, binSize, pixelSize_o, origin)
def getCcdImage(self, det, imageFactory, binSize)
def findAmp(ccd, pixelPosition)
def getCameraImageBBox(camBbox, pixelSize, bufferSize)
Statistics makeStatistics(lsst::afw::math::MaskedVector< EntryT > const &mv, std::vector< WeightPixel > const &vweights, int const flags, StatisticsControl const &sctrl=StatisticsControl())
The makeStatistics() overload to handle lsst::afw::math::MaskedVector<>
def getAmpImage(self, amp, imageFactory)
def __init__(self, isTrimmed=True, verbose=False, background=numpy.nan, showAmpGain=True, markSize=10, markValue=0, ampImValue=None, scaleGain=lambda gain:(gain *1000)//10)
def rawCallback(im, ccd=None, imageSource=None, correctGain=False, subtractBias=False, convertToFloat=False)
def _prepareImage(self, ccd, im, binSize, allowRotate=True)
def makeImageFromCamera(camera, detectorNameList=None, background=numpy.nan, bufferSize=10, imageSource=FakeImageDataSource(), imageFactory=afwImage.ImageU, binSize=1)
def __init__(self, butler=None, type="raw", isTrimmed=True, verbose=False, background=numpy.nan, callback=None, args, kwargs)
def makeImageFromCcd(ccd, isTrimmed=True, showAmpGain=True, imageFactory=afwImage.ImageU, rcMarkSize=10, binSize=1)
std::shared_ptr< ImageT > rotateImageBy90(ImageT const &image, int nQuarter)
Rotate an image by an integral number of quarter turns.
def assembleAmplifierImage(destImage, rawImage, amplifier)
def showAmp(amp, imageSource=FakeImageDataSource(isTrimmed=False), display=None, overlay=True, imageFactory=afwImage.ImageU)
def prepareWcsData(wcs, amp, isTrimmed=True)
std::shared_ptr< ImageT > binImage(ImageT const &inImage, int const binsize, lsst::afw::math::Property const flags=lsst::afw::math::MEAN)
def assembleAmplifierRawImage(destImage, rawImage, amplifier)
static Log getLogger(std::string const &loggername)
def overlayCcdBoxes(ccd, untrimmedCcdBbox=None, nQuarter=0, isTrimmed=False, ccdOrigin=(0, 0), display=None, binSize=1)
def rotateBBoxBy90(bbox, n90, dimensions)
def getCcdImage(self, ccd, imageFactory=afwImage.ImageF, binSize=1, asMaskedImage=False)