LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Classes | Functions
lsst.afw.cameraGeom.utils Namespace Reference

Classes

class  FakeImageDataSource
 
class  ButlerImage
 

Functions

def prepareWcsData
 Put Wcs from an Amp image into CCD coordinates. More...
 
def plotFocalPlane
 Make a plot of the focal plane along with a set points that sample the Pupil. More...
 
def makeImageFromAmp
 Make an image from an amp object. More...
 
def calcRawCcdBBox
 Calculate the raw ccd bounding box. More...
 
def makeImageFromCcd
 Make an Image of a Ccd. More...
 
def overlayCcdBoxes
 Overlay bounding boxes on an image display. More...
 
def showAmp
 Show an amp in an image display. More...
 
def showCcd
 Show a CCD on display. More...
 
def getCcdInCamBBoxList
 Get the bounding boxes of a list of Detectors within a camera sized pixel grid. More...
 
def getCameraImageBBox
 Get the bounding box of a camera sized image in pixels. More...
 
def makeImageFromCamera
 Make an Image of a Camera. More...
 
def showCamera
 Show a Camera on display, with the specified display. More...
 
def makeFocalPlaneWcs
 Make a WCS for the focal plane geometry (i.e. More...
 
def findAmp
 Find the Amp with the specified pixel position within the composite. More...
 

Function Documentation

def lsst.afw.cameraGeom.utils.calcRawCcdBBox (   ccd)

Calculate the raw ccd bounding box.

Parameters
[in]ccdDetector for with to calculate the un-trimmed bounding box
Returns
Box2I of the un-trimmed Detector, or None if there is not enough information to calculate raw BBox

Definition at line 191 of file utils.py.

192 def calcRawCcdBBox(ccd):
193  """!Calculate the raw ccd bounding box
194 
195  @param[in] ccd Detector for with to calculate the un-trimmed bounding box
196  @return Box2I of the un-trimmed Detector,
197  or None if there is not enough information to calculate raw BBox
198  """
199  bbox = afwGeom.Box2I()
200  for amp in ccd:
201  if not amp.getHasRawInfo():
202  return None
203  tbbox = amp.getRawBBox()
204  tbbox.shift(amp.getRawXYOffset())
205  bbox.include(tbbox)
206  return bbox
An integer coordinate rectangle.
Definition: Box.h:53
def calcRawCcdBBox
Calculate the raw ccd bounding box.
Definition: utils.py:191
def lsst.afw.cameraGeom.utils.findAmp (   ccd,
  pixelPosition 
)

Find the Amp with the specified pixel position within the composite.

Parameters
[in]ccdDetector to look in
[in]pixelPositionPoint2I containing the pixel position
Returns
Amp record in which pixelPosition falls or None if no Amp found.

Definition at line 735 of file utils.py.

736 def findAmp(ccd, pixelPosition):
737  """!Find the Amp with the specified pixel position within the composite
738 
739  @param[in] ccd Detector to look in
740  @param[in] pixelPosition Point2I containing the pixel position
741  @return Amp record in which pixelPosition falls or None if no Amp found.
742  """
743 
744  for amp in ccd:
745  if amp.getBBox().contains(pixelPosition):
746  return amp
747 
748  return None
def findAmp
Find the Amp with the specified pixel position within the composite.
Definition: utils.py:735
def lsst.afw.cameraGeom.utils.getCameraImageBBox (   camBbox,
  pixelSize,
  bufferSize 
)

Get the bounding box of a camera sized image in pixels.

Parameters
[in]camBboxCamera bounding box in focal plane coordinates (mm)
[in]pixelSizeSize of a detector pixel in mm
[in]bufferSizeBuffer around edge of image in pixels
Returns
the resulting bounding box

Definition at line 568 of file utils.py.

569 def getCameraImageBBox(camBbox, pixelSize, bufferSize):
570  """!Get the bounding box of a camera sized image in pixels
571 
572  @param[in] camBbox Camera bounding box in focal plane coordinates (mm)
573  @param[in] pixelSize Size of a detector pixel in mm
574  @param[in] bufferSize Buffer around edge of image in pixels
575  @return the resulting bounding box
576  """
577  pixMin = afwGeom.Point2I(int(camBbox.getMinX()//pixelSize.getX()),
578  int(camBbox.getMinY()//pixelSize.getY()))
579  pixMax = afwGeom.Point2I(int(camBbox.getMaxX()//pixelSize.getX()),
580  int(camBbox.getMaxY()//pixelSize.getY()))
581  retBox = afwGeom.Box2I(pixMin, pixMax)
582  retBox.grow(bufferSize)
583  return retBox
def getCameraImageBBox
Get the bounding box of a camera sized image in pixels.
Definition: utils.py:568
An integer coordinate rectangle.
Definition: Box.h:53
def lsst.afw.cameraGeom.utils.getCcdInCamBBoxList (   ccdList,
  binSize,
  pixelSize_o,
  origin 
)

Get the bounding boxes of a list of Detectors within a camera sized pixel grid.

Parameters
[in]ccdListList of Detector
[in]binSizeBinning factor
[in]pixelSize_oSize of the pixel in mm.
[in]originorigin of the camera pixel grid in pixels
Returns
a list of bounding boxes in camera pixel coordinates

Definition at line 537 of file utils.py.

538 def getCcdInCamBBoxList(ccdList, binSize, pixelSize_o, origin):
539  """!Get the bounding boxes of a list of Detectors within a camera sized pixel grid
540 
541  @param[in] ccdList List of Detector
542  @param[in] binSize Binning factor
543  @param[in] pixelSize_o Size of the pixel in mm.
544  @param[in] origin origin of the camera pixel grid in pixels
545  @return a list of bounding boxes in camera pixel coordinates
546  """
547  boxList = []
548  for ccd in ccdList:
549  if not pixelSize_o == ccd.getPixelSize():
550  raise RuntimeError(
551  "Cameras with detectors with different pixel scales are not currently supported")
552 
553  dbbox = afwGeom.Box2D()
554  for corner in ccd.getCorners(FOCAL_PLANE):
555  dbbox.include(corner)
556  llc = dbbox.getMin()
557  nQuarter = ccd.getOrientation().getNQuarter()
558  cbbox = ccd.getBBox()
559  ex = cbbox.getDimensions().getX()//binSize
560  ey = cbbox.getDimensions().getY()//binSize
561  bbox = afwGeom.Box2I(cbbox.getMin(), afwGeom.Extent2I(int(ex), int(ey)))
562  bbox = rotateBBoxBy90(bbox, nQuarter, bbox.getDimensions())
563  bbox.shift(afwGeom.Extent2I(int(llc.getX()//pixelSize_o.getX()/binSize),
564  int(llc.getY()//pixelSize_o.getY()/binSize)))
565  bbox.shift(afwGeom.Extent2I(-int(origin.getX()//binSize), -int(origin.getY())//binSize))
566  boxList.append(bbox)
567  return boxList
An integer coordinate rectangle.
Definition: Box.h:53
def getCcdInCamBBoxList
Get the bounding boxes of a list of Detectors within a camera sized pixel grid.
Definition: utils.py:537
def rotateBBoxBy90
Rotate a bounding box by an integer multiple of 90 degrees.
A floating-point coordinate rectangle geometry.
Definition: Box.h:271
def lsst.afw.cameraGeom.utils.makeFocalPlaneWcs (   pixelSize,
  referencePixel 
)

Make a WCS for the focal plane geometry (i.e.

returning positions in "mm")

Parameters
[in]pixelSizeSize of the image pixels in physical units
[in]referencePixelPixel for origin of WCS
Returns
Wcs object for mapping between pixels and focal plane.

Definition at line 712 of file utils.py.

713 def makeFocalPlaneWcs(pixelSize, referencePixel):
714  """!Make a WCS for the focal plane geometry (i.e. returning positions in "mm")
715 
716  @param[in] pixelSize Size of the image pixels in physical units
717  @param[in] referencePixel Pixel for origin of WCS
718  @return Wcs object for mapping between pixels and focal plane.
719  """
720 
721  md = dafBase.PropertySet()
722  if referencePixel is None:
723  referencePixel = afwGeom.PointD(0,0)
724  for i in range(2):
725  md.set("CRPIX%d"%(i+1), referencePixel[i])
726  md.set("CRVAL%d"%(i+1), 0.)
727  md.set("CDELT1", pixelSize[0])
728  md.set("CDELT2", pixelSize[1])
729  md.set("CTYPE1", "CAMERA_X")
730  md.set("CTYPE2", "CAMERA_Y")
731  md.set("CUNIT1", "mm")
732  md.set("CUNIT2", "mm")
733 
734  return afwImage.makeWcs(md)
def makeFocalPlaneWcs
Make a WCS for the focal plane geometry (i.e.
Definition: utils.py:712
Wcs::Ptr makeWcs(coord::Coord const &crval, geom::Point2D const &crpix, double CD11, double CD12, double CD21, double CD22)
Create a Wcs object from crval, crpix, CD, using CD elements (useful from python) ...
Definition: makeWcs.cc:141
Class for storing generic metadata.
Definition: PropertySet.h:82
def lsst.afw.cameraGeom.utils.makeImageFromAmp (   amp,
  imValue = None,
  imageFactory = afwImage.ImageU,
  markSize = 10,
  markValue = 0,
  scaleGain = lambda gain: (gain*1000)//10 
)

Make an image from an amp object.

Since images are integer images by default, the gain needs to be scaled to give enough dynamic range to see variation from amp to amp. The scaling algorithm is assignable.

Parameters
[in]ampAmp record to use for constructing the raw amp image
[in]imValueValue to assign to the constructed image scaleGain(gain) is used if not set
[in]imageFactoryType of image to construct
[in]markSizeSize of mark at read corner in pixels
[in]markValueValue of pixels in the read corner mark
[in]scaleGainThe function by which to scale the gain
Returns
an untrimmed amp image

Definition at line 145 of file utils.py.

146  scaleGain = lambda gain: (gain*1000)//10):
147  """!Make an image from an amp object
148 
149  Since images are integer images by default, the gain needs to be scaled to give enough dynamic range
150  to see variation from amp to amp. The scaling algorithm is assignable.
151 
152  @param[in] amp Amp record to use for constructing the raw amp image
153  @param[in] imValue Value to assign to the constructed image scaleGain(gain) is used if not set
154  @param[in] imageFactory Type of image to construct
155  @param[in] markSize Size of mark at read corner in pixels
156  @param[in] markValue Value of pixels in the read corner mark
157  @param[in] scaleGain The function by which to scale the gain
158  @return an untrimmed amp image
159  """
160  if not amp.getHasRawInfo():
161  raise RuntimeError("Can't create a raw amp image without raw amp information")
162  bbox = amp.getRawBBox()
163  dbbox = amp.getRawDataBBox()
164  img = imageFactory(bbox)
165  if imValue is None:
166  img.set(scaleGain(amp.getGain()))
167  else:
168  img.set(imValue)
169  #Set the first pixel read to a different value
170  markbbox = afwGeom.Box2I()
171  if amp.getReadoutCorner() == 0:
172  markbbox.include(dbbox.getMin())
173  markbbox.include(dbbox.getMin()+afwGeom.Extent2I(markSize, markSize))
174  elif amp.getReadoutCorner() == 1:
175  cornerPoint = afwGeom.Point2I(dbbox.getMaxX(), dbbox.getMinY())
176  markbbox.include(cornerPoint)
177  markbbox.include(cornerPoint + afwGeom.Extent2I(-markSize, markSize))
178  elif amp.getReadoutCorner() == 2:
179  cornerPoint = afwGeom.Point2I(dbbox.getMax())
180  markbbox.include(cornerPoint)
181  markbbox.include(cornerPoint + afwGeom.Extent2I(-markSize, -markSize))
182  elif amp.getReadoutCorner() == 3:
183  cornerPoint = afwGeom.Point2I(dbbox.getMinX(), dbbox.getMaxY())
184  markbbox.include(cornerPoint)
185  markbbox.include(cornerPoint + afwGeom.Extent2I(markSize, -markSize))
186  else:
187  raise RuntimeError("Could not set readout corner")
188  mimg = imageFactory(img, markbbox, False)
189  mimg.set(markValue)
190  return img
An integer coordinate rectangle.
Definition: Box.h:53
def lsst.afw.cameraGeom.utils.makeImageFromCamera (   camera,
  detectorNameList = None,
  background = numpy.nan,
  bufferSize = 10,
  imageSource = FakeImageDataSource(),
  imageFactory = afwImage.ImageU,
  binSize = 1 
)

Make an Image of a Camera.

Parameters
[in]cameraCamera object to use to make the image
[in]detectorNameListList of detector names to use in building the image. Use all Detectors if None.
[in]backgroundValue to use where there is no Detector
[in]bufferSizeSize of border in binned pixels to make around the camera image
[in]imageSourceSource to get ccd images. Must have a getCcdImage method
[in]imageFactoryType of image to build
[in]binSizebin factor
Returns
an image of the camera

Definition at line 585 of file utils.py.

586  imageSource=FakeImageDataSource(), imageFactory=afwImage.ImageU, binSize=1):
587  """!Make an Image of a Camera
588 
589  @param[in] camera Camera object to use to make the image
590  @param[in] detectorNameList List of detector names to use in building the image.
591  Use all Detectors if None.
592  @param[in] background Value to use where there is no Detector
593  @param[in] bufferSize Size of border in binned pixels to make around the camera image
594  @param[in] imageSource Source to get ccd images. Must have a getCcdImage method
595  @param[in] imageFactory Type of image to build
596  @param[in] binSize bin factor
597  @return an image of the camera
598  """
599  if detectorNameList is None:
600  ccdList = camera
601  else:
602  ccdList = [camera[name] for name in detectorNameList]
603 
604  if detectorNameList is None:
605  camBbox = camera.getFpBBox()
606  else:
607  camBbox = afwGeom.Box2D()
608  for detName in detectorNameList:
609  for corner in camera[detName].getCorners(FOCAL_PLANE):
610  camBbox.include(corner)
611 
612  pixelSize_o = camera[camera.getNameIter().next()].getPixelSize()
613  camBbox = getCameraImageBBox(camBbox, pixelSize_o, bufferSize*binSize)
614  origin = camBbox.getMin()
615 
616  camIm = imageFactory(int(math.ceil(camBbox.getDimensions().getX()/binSize)),
617  int(math.ceil(camBbox.getDimensions().getY()/binSize)))
618  camIm[:] = imageSource.background
619 
620  assert imageSource.isTrimmed, "isTrimmed is False isn't supported by getCcdInCamBBoxList"
621 
622  boxList = getCcdInCamBBoxList(ccdList, binSize, pixelSize_o, origin)
623  for det, bbox in itertools.izip(ccdList, boxList):
624  im = imageSource.getCcdImage(det, imageFactory, binSize)
625 
626  nQuarter = det.getOrientation().getNQuarter()
627  im = afwMath.rotateImageBy90(im, nQuarter)
628 
629  imView = camIm.Factory(camIm, bbox, afwImage.LOCAL)
630  try:
631  imView <<= im
632  except Exception as e:
633  pass
634 
635  return camIm
def getCameraImageBBox
Get the bounding box of a camera sized image in pixels.
Definition: utils.py:568
def getCcdInCamBBoxList
Get the bounding boxes of a list of Detectors within a camera sized pixel grid.
Definition: utils.py:537
ImageT::Ptr rotateImageBy90(ImageT const &image, int nQuarter)
Definition: rotateImage.cc:41
A floating-point coordinate rectangle geometry.
Definition: Box.h:271
def lsst.afw.cameraGeom.utils.makeImageFromCcd (   ccd,
  isTrimmed = True,
  showAmpGain = True,
  imageFactory = afwImage.ImageU,
  rcMarkSize = 10,
  binSize = 1 
)

Make an Image of a Ccd.

Parameters
[in]ccdDetector to use in making the image
[in]isTrimmedAssemble a trimmed Detector image if True
[in]showAmpGainUse the per amp gain to color the pixels in the image
[in]imageFactoryImage type to generate
[in]rcMarkSizeSize of the mark to make in the amp images at the read corner
[in]binSizeBin the image by this factor in both dimensions
Returns
Image of the Detector

Definition at line 208 of file utils.py.

209  binSize=1):
210  """!Make an Image of a Ccd
211 
212  @param[in] ccd Detector to use in making the image
213  @param[in] isTrimmed Assemble a trimmed Detector image if True
214  @param[in] showAmpGain Use the per amp gain to color the pixels in the image
215  @param[in] imageFactory Image type to generate
216  @param[in] rcMarkSize Size of the mark to make in the amp images at the read corner
217  @param[in] binSize Bin the image by this factor in both dimensions
218  @return Image of the Detector
219  """
220  ampImages = []
221  index = 0
222  if isTrimmed:
223  bbox = ccd.getBBox()
224  else:
225  bbox = calcRawCcdBBox(ccd)
226  for amp in ccd:
227  if amp.getHasRawInfo():
228  if showAmpGain:
229  ampImages.append(makeImageFromAmp(amp, imageFactory=imageFactory, markSize=rcMarkSize))
230  else:
231  ampImages.append(makeImageFromAmp(amp, imValue=(index+1)*1000,
232  imageFactory=imageFactory, markSize=rcMarkSize))
233  index += 1
234 
235  if len(ampImages) > 0:
236  ccdImage = imageFactory(bbox)
237  for ampImage, amp in itertools.izip(ampImages, ccd):
238  if isTrimmed:
239  assembleAmplifierImage(ccdImage, ampImage, amp)
240  else:
241  assembleAmplifierRawImage(ccdImage, ampImage, amp)
242  else:
243  if not isTrimmed:
244  raise RuntimeError("Cannot create untrimmed CCD without amps with raw information")
245  ccdImage = imageFactory(ccd.getBBox())
246  ccdImage = afwMath.binImage(ccdImage, binSize)
247  return ccdImage
boost::shared_ptr< ImageT > binImage(ImageT const &inImage, int const binsize, lsst::afw::math::Property const flags=lsst::afw::math::MEAN)
Definition: binImage.cc:39
def assembleAmplifierRawImage
Assemble the amplifier region of a raw CCD image.
def makeImageFromAmp
Make an image from an amp object.
Definition: utils.py:145
def calcRawCcdBBox
Calculate the raw ccd bounding box.
Definition: utils.py:191
def assembleAmplifierImage
Assemble the amplifier region of an image from a raw image.
def lsst.afw.cameraGeom.utils.overlayCcdBoxes (   ccd,
  untrimmedCcdBbox,
  nQuarter,
  isTrimmed,
  ccdOrigin,
  display,
  binSize 
)

Overlay bounding boxes on an image display.

Parameters
[in]ccdDetector to iterate for the amp bounding boxes
[in]untrimmedCcdBboxBounding box of the un-trimmed Detector
[in]nQuarternumber of 90 degree rotations to apply to the bounding boxes
[in]isTrimmedIs the Detector image over which the boxes are layed trimmed?
[in]ccdOriginDetector origin relative to the parent origin if in a larger pixel grid
[in]displayimage display to display on
[in]binSizebinning factor

Definition at line 390 of file utils.py.

391 def overlayCcdBoxes(ccd, untrimmedCcdBbox, nQuarter, isTrimmed, ccdOrigin, display, binSize):
392  """!Overlay bounding boxes on an image display
393 
394  @param[in] ccd Detector to iterate for the amp bounding boxes
395  @param[in] untrimmedCcdBbox Bounding box of the un-trimmed Detector
396  @param[in] nQuarter number of 90 degree rotations to apply to the bounding boxes
397  @param[in] isTrimmed Is the Detector image over which the boxes are layed trimmed?
398  @param[in] ccdOrigin Detector origin relative to the parent origin if in a larger pixel grid
399  @param[in] display image display to display on
400  @param[in] binSize binning factor
401  """
402  with display.Buffering():
403  ccdDim = untrimmedCcdBbox.getDimensions()
404  ccdBbox = rotateBBoxBy90(untrimmedCcdBbox, nQuarter, ccdDim)
405  for amp in ccd:
406  if isTrimmed:
407  ampbbox = amp.getBBox()
408  else:
409  ampbbox = amp.getRawBBox()
410  ampbbox.shift(amp.getRawXYOffset())
411  if nQuarter != 0:
412  ampbbox = rotateBBoxBy90(ampbbox, nQuarter, ccdDim)
413 
414  displayUtils.drawBBox(ampbbox, origin=ccdOrigin, borderWidth=0.49,
415  display=display, bin=binSize)
416 
417  if not isTrimmed and amp.getHasRawInfo():
418  for bbox, ctype in ((amp.getRawHorizontalOverscanBBox(), afwDisplay.RED),
419  (amp.getRawDataBBox(), afwDisplay.BLUE),
420  (amp.getRawVerticalOverscanBBox(), afwDisplay.MAGENTA),
421  (amp.getRawPrescanBBox(), afwDisplay.YELLOW)):
422  if amp.getRawFlipX():
423  bbox.flipLR(amp.getRawBBox().getDimensions().getX())
424  if amp.getRawFlipY():
425  bbox.flipTB(amp.getRawBBox().getDimensions().getY())
426  bbox.shift(amp.getRawXYOffset())
427  if nQuarter != 0:
428  bbox = rotateBBoxBy90(bbox, nQuarter, ccdDim)
429  displayUtils.drawBBox(bbox, origin=ccdOrigin, borderWidth=0.49, ctype=ctype,
430  display=display, bin=binSize)
431  # Label each Amp
432  xc, yc = (ampbbox.getMin()[0] + ampbbox.getMax()[0])//2, (ampbbox.getMin()[1] +
433  ampbbox.getMax()[1])//2
434  #
435  # Rotate the amp labels too
436  #
437  if nQuarter == 0:
438  c, s = 1, 0
439  elif nQuarter == 1:
440  c, s = 0, -1
441  elif nQuarter == 2:
442  c, s = -1, 0
443  elif nQuarter == 3:
444  c, s = 0, 1
445  c, s = 1, 0
446  ccdHeight = ccdBbox.getHeight()
447  ccdWidth = ccdBbox.getWidth()
448  xc -= 0.5*ccdHeight
449  yc -= 0.5*ccdWidth
450 
451  xc, yc = 0.5*ccdHeight + c*xc + s*yc, 0.5*ccdWidth + -s*xc + c*yc
452 
453  if ccdOrigin:
454  xc += ccdOrigin[0]
455  yc += ccdOrigin[1]
456  display.dot(str(amp.getName()), xc/binSize, yc/binSize, textAngle=nQuarter*90)
457 
458  displayUtils.drawBBox(ccdBbox, origin=ccdOrigin,
459  borderWidth=0.49, ctype=afwDisplay.MAGENTA, display=display, bin=binSize)
def rotateBBoxBy90
Rotate a bounding box by an integer multiple of 90 degrees.
def overlayCcdBoxes
Overlay bounding boxes on an image display.
Definition: utils.py:390
def lsst.afw.cameraGeom.utils.plotFocalPlane (   camera,
  pupilSizeDeg_x = 0,
  pupilSizeDeg_y = None,
  dx = 0.1,
  dy = 0.1,
  figsize = (10., 10.,
  useIds = False,
  showFig = True,
  savePath = None 
)

Make a plot of the focal plane along with a set points that sample the Pupil.

Parameters
[in]cameraa camera object
[in]pupilSizeDeg_xAmount of the pupil to sample in x in degrees
[in]pupilSizeDeg_yAmount of the pupil to sample in y in degrees
[in]dxSpacing of sample points in x in degrees
[in]dySpacing of sample points in y in degrees
[in]figsizematplotlib style tuple indicating the size of the figure in inches
[in]useIdsLabel detectors by name, not id
[in]showFigDisplay the figure on the screen?
[in]savePathIf not None, save a copy of the figure to this name

Definition at line 67 of file utils.py.

67 
68  useIds=False, showFig=True, savePath=None):
69  """!Make a plot of the focal plane along with a set points that sample the Pupil
70 
71  @param[in] camera a camera object
72  @param[in] pupilSizeDeg_x Amount of the pupil to sample in x in degrees
73  @param[in] pupilSizeDeg_y Amount of the pupil to sample in y in degrees
74  @param[in] dx Spacing of sample points in x in degrees
75  @param[in] dy Spacing of sample points in y in degrees
76  @param[in] figsize matplotlib style tuple indicating the size of the figure in inches
77  @param[in] useIds Label detectors by name, not id
78  @param[in] showFig Display the figure on the screen?
79  @param[in] savePath If not None, save a copy of the figure to this name
80  """
81  try:
82  from matplotlib.patches import Polygon
83  from matplotlib.collections import PatchCollection
84  import matplotlib.pyplot as plt
85  except ImportError:
86  raise ImportError("Can't run plotFocalPlane: matplotlib has not been set up")
87 
88  if pupilSizeDeg_x:
89  if pupilSizeDeg_y is None:
90  pupilSizeDeg_y = pupilSizeDeg_x
91 
92  pupil_gridx, pupil_gridy = numpy.meshgrid(numpy.arange(0., pupilSizeDeg_x+dx, dx) - pupilSizeDeg_x/2.,
93  numpy.arange(0., pupilSizeDeg_y+dy, dy) - pupilSizeDeg_y/2.)
94  pupil_gridx, pupil_gridy = pupil_gridx.flatten(), pupil_gridy.flatten()
95  else:
96  pupil_gridx, pupil_gridy = [], []
97 
98  xs = []
99  ys = []
100  pcolors = []
101  for pos in zip(pupil_gridx, pupil_gridy):
102  posRad = afwGeom.Point2D(math.radians(pos[0]), math.radians(pos[1]))
103  cp = camera.makeCameraPoint(posRad, PUPIL)
104  ncp = camera.transform(cp, FOCAL_PLANE)
105  xs.append(ncp.getPoint().getX())
106  ys.append(ncp.getPoint().getY())
107  dets = camera.findDetectors(cp)
108  if len(dets) > 0:
109  pcolors.append('w')
110  else:
111  pcolors.append('k')
112 
113 
114  colorMap = {0:'b', 1:'y', 2:'g', 3:'r'}
115 
116  patches = []
117  colors = []
118  plt.figure(figsize=figsize)
119  ax = plt.gca()
120  xvals = []
121  yvals = []
122  for det in camera:
123  corners = [(c.getX(), c.getY()) for c in det.getCorners(FOCAL_PLANE)]
124  for corner in corners:
125  xvals.append(corner[0])
126  yvals.append(corner[1])
127  colors.append(colorMap[det.getType()])
128  patches.append(Polygon(corners, True))
129  center = det.getOrientation().getFpPosition()
130  ax.text(center.getX(), center.getY(), det.getId() if useIds else det.getName(),
131  horizontalalignment='center', size=6)
132 
133  patchCollection = PatchCollection(patches, alpha=0.6, facecolor=colors)
134  ax.add_collection(patchCollection)
135  ax.scatter(xs, ys, s=10, alpha=.7, linewidths=0., c=pcolors)
136  ax.set_xlim(min(xvals) - abs(0.1*min(xvals)), max(xvals) + abs(0.1*max(xvals)))
137  ax.set_ylim(min(yvals) - abs(0.1*min(yvals)), max(yvals) + abs(0.1*max(yvals)))
138  ax.set_xlabel('Focal Plane X (mm)')
139  ax.set_ylabel('Focal Plane Y (mm)')
140  if savePath is not None:
141  plt.savefig(savePath)
142  if showFig:
143  plt.show()
def lsst.afw.cameraGeom.utils.prepareWcsData (   wcs,
  amp,
  isTrimmed = True 
)

Put Wcs from an Amp image into CCD coordinates.

Parameters
[in,out]wcsWCS object to modify in place
[in]ampAmp object to use
[in]isTrimmedIs the image to which the WCS refers trimmed of non-imaging pixels?

Definition at line 46 of file utils.py.

46 
47 def prepareWcsData(wcs, amp, isTrimmed=True):
48  """!Put Wcs from an Amp image into CCD coordinates
49 
50  @param[in, out] wcs WCS object to modify in place
51  @param[in] amp Amp object to use
52  @param[in] isTrimmed Is the image to which the WCS refers trimmed of non-imaging pixels?
53  """
54  if not amp.getHasRawInfo():
55  raise RuntimeError("Cannot modify wcs without raw amp information")
56  if isTrimmed:
57  ampBox = amp.getRawDataBBox()
58  else:
59  ampBox = amp.getRawBBox()
60  wcs.flipImage(amp.getRawFlipX(), amp.getRawFlipY(), ampBox.getDimensions())
61  #Shift WCS for trimming
62  wcs.shiftReferencePixel(-ampBox.getMinX(), -ampBox.getMinY())
63  #Account for shift of amp data in larger ccd matrix
64  offset = amp.getRawXYOffset()
65  wcs.shiftReferencePixel(offset.getX(), offset.getY())
def prepareWcsData
Put Wcs from an Amp image into CCD coordinates.
Definition: utils.py:46
def lsst.afw.cameraGeom.utils.showAmp (   amp,
  imageSource = FakeImageDataSource(isTrimmed=False),
  display = None,
  overlay = True,
  imageFactory = afwImage.ImageU 
)

Show an amp in an image display.

Parameters
[in]ampamp record to use in display
[in]imageSourceSource for getting the amp image. Must have a getAmpImage method.
[in]displayimage display to use
[in]overlayOverlay bounding boxes?
[in]imageFactoryType of image to display (only used if ampImage is None)

Definition at line 461 of file utils.py.

462  imageFactory=afwImage.ImageU):
463  """!Show an amp in an image display
464 
465  @param[in] amp amp record to use in display
466  @param[in] imageSource Source for getting the amp image. Must have a getAmpImage method.
467  @param[in] display image display to use
468  @param[in] overlay Overlay bounding boxes?
469  @param[in] imageFactory Type of image to display (only used if ampImage is None)
470  """
471 
472  if not display:
474 
475  ampImage = imageSource.getAmpImage(amp, imageFactory=imageFactory)
476  ampImSize = ampImage.getDimensions()
477  title = amp.getName()
478  display.mtv(ampImage, title=title)
479  if overlay:
480  with display.Buffering():
481  if amp.getHasRawInfo() and ampImSize == amp.getRawBBox().getDimensions():
482  bboxes = [(amp.getRawBBox(), 0.49, afwDisplay.GREEN),]
483  xy0 = bboxes[0][0].getMin()
484  bboxes.append((amp.getRawHorizontalOverscanBBox(), 0.49, afwDisplay.RED))
485  bboxes.append((amp.getRawDataBBox(), 0.49, afwDisplay.BLUE))
486  bboxes.append((amp.getRawPrescanBBox(), 0.49, afwDisplay.YELLOW))
487  bboxes.append((amp.getRawVerticalOverscanBBox(), 0.49, afwDisplay.MAGENTA))
488  else:
489  bboxes = [(amp.getBBox(), 0.49, None),]
490  xy0 = bboxes[0][0].getMin()
491 
492  for bbox, borderWidth, ctype in bboxes:
493  if bbox.isEmpty():
494  continue
495  bbox = afwGeom.Box2I(bbox)
496  bbox.shift(-afwGeom.ExtentI(xy0))
497  displayUtils.drawBBox(bbox, borderWidth=borderWidth, ctype=ctype, display=display)
An integer coordinate rectangle.
Definition: Box.h:53
def _getDisplayFromDisplayOrFrame
Return an afwDisplay.Display given either a display or a frame ID.
Definition: utils.py:36
def lsst.afw.cameraGeom.utils.showCamera (   camera,
  imageSource = FakeImageDataSource(),
  imageFactory = afwImage.ImageF,
  detectorNameList = None,
  binSize = 10,
  bufferSize = 10,
  frame = None,
  overlay = True,
  title = "",
  ctype = afwDisplay.GREEN,
  textSize = 1.25,
  originAtCenter = True,
  display = None,
  kwargs 
)

Show a Camera on display, with the specified display.

The rotation of the sensors is snapped to the nearest multiple of 90 deg. Also note that the pixel size is constant over the image array. The lower left corner (LLC) of each sensor amp is snapped to the LLC of the pixel containing the LLC of the image. if overlay show the IDs and detector boundaries

Parameters
[in]cameraCamera to show
[in]imageSourceSource to get Ccd images from. Must have a getCcdImage method.
[in]imageFactoryType of image to make
[in]detectorNameListList of names of Detectors to use. If None use all
[in]binSizebin factor
[in]bufferSizesize of border in binned pixels to make around camera image.
[in]framespecify image display (
Deprecated:
; new code should use display)
Parameters
[in]overlayOverlay Detector IDs and boundaries?
[in]titleTitle in display
[in]ctypeColor to use when drawing Detector boundaries
[in]textSizeSize of detector labels
[in]originAtCenterPut origin of the camera WCS at the center of the image? Else it will be LL
[in]displayimage display on which to display
[in]**kwargsall remaining keyword arguments are passed to makeImageFromCamera
Returns
the mosaic image

Definition at line 638 of file utils.py.

639  ctype=afwDisplay.GREEN, textSize=1.25, originAtCenter=True, display=None, **kwargs):
640  """!Show a Camera on display, with the specified display
641 
642  The rotation of the sensors is snapped to the nearest multiple of 90 deg.
643  Also note that the pixel size is constant over the image array. The lower left corner (LLC) of each
644  sensor amp is snapped to the LLC of the pixel containing the LLC of the image.
645  if overlay show the IDs and detector boundaries
646 
647  @param[in] camera Camera to show
648  @param[in] imageSource Source to get Ccd images from. Must have a getCcdImage method.
649  @param[in] imageFactory Type of image to make
650  @param[in] detectorNameList List of names of Detectors to use. If None use all
651  @param[in] binSize bin factor
652  @param[in] bufferSize size of border in binned pixels to make around camera image.
653  @param[in] frame specify image display (@deprecated; new code should use display)
654  @param[in] overlay Overlay Detector IDs and boundaries?
655  @param[in] title Title in display
656  @param[in] ctype Color to use when drawing Detector boundaries
657  @param[in] textSize Size of detector labels
658  @param[in] originAtCenter Put origin of the camera WCS at the center of the image? Else it will be LL
659  @param[in] display image display on which to display
660  @param[in] **kwargs all remaining keyword arguments are passed to makeImageFromCamera
661  @return the mosaic image
662  """
663  display = _getDisplayFromDisplayOrFrame(display, frame)
664 
665  if binSize < 1:
666  binSize = 1
667  cameraImage = makeImageFromCamera(camera, detectorNameList=detectorNameList, bufferSize=bufferSize,
668  imageSource=imageSource, imageFactory=imageFactory, binSize=binSize,
669  **kwargs)
670 
671  if detectorNameList is None:
672  ccdList = [camera[name] for name in camera.getNameIter()]
673  else:
674  ccdList = [camera[name] for name in detectorNameList]
675 
676  if detectorNameList is None:
677  camBbox = camera.getFpBBox()
678  else:
679  camBbox = afwGeom.Box2D()
680  for detName in detectorNameList:
681  for corner in camera[detName].getCorners(FOCAL_PLANE):
682  camBbox.include(corner)
683  pixelSize = ccdList[0].getPixelSize()
684  if originAtCenter:
685  #Can't divide SWIGGED extent type things when division is imported
686  #from future. This is DM-83
687  ext = cameraImage.getBBox().getDimensions()
688 
689  wcsReferencePixel = afwGeom.PointI(ext.getX()//2, ext.getY()//2)
690  else:
691  wcsReferencePixel = afwGeom.Point2I(0,0)
692  wcs = makeFocalPlaneWcs(pixelSize*binSize, wcsReferencePixel)
693 
694  if display:
695  if title == "":
696  title = camera.getName()
697  display.mtv(cameraImage, title=title, wcs=wcs)
698 
699  if overlay:
700  with display.Buffering():
701  camBbox = getCameraImageBBox(camBbox, pixelSize, bufferSize*binSize)
702  bboxList = getCcdInCamBBoxList(ccdList, binSize, pixelSize, camBbox.getMin())
703  for bbox, ccd in itertools.izip(bboxList, ccdList):
704  nQuarter = ccd.getOrientation().getNQuarter()
705  # borderWidth to 0.5 to align with the outside edge of the pixel
706  displayUtils.drawBBox(bbox, borderWidth=0.5, ctype=ctype, display=display)
707  dims = bbox.getDimensions()
708  display.dot(ccd.getName(), bbox.getMinX()+dims.getX()/2, bbox.getMinY()+dims.getY()/2,
709  ctype=ctype, size=textSize, textAngle=nQuarter*90)
710 
711  return cameraImage
def getCameraImageBBox
Get the bounding box of a camera sized image in pixels.
Definition: utils.py:568
def makeFocalPlaneWcs
Make a WCS for the focal plane geometry (i.e.
Definition: utils.py:712
def getCcdInCamBBoxList
Get the bounding boxes of a list of Detectors within a camera sized pixel grid.
Definition: utils.py:537
def makeImageFromCamera
Make an Image of a Camera.
Definition: utils.py:585
def _getDisplayFromDisplayOrFrame
Return an afwDisplay.Display given either a display or a frame ID.
Definition: utils.py:36
A floating-point coordinate rectangle geometry.
Definition: Box.h:271
def lsst.afw.cameraGeom.utils.showCcd (   ccd,
  imageSource = FakeImageDataSource(),
  display = None,
  frame = None,
  overlay = True,
  imageFactory = afwImage.ImageF,
  binSize = 1,
  inCameraCoords = False 
)

Show a CCD on display.

Parameters
[in]ccdDetector to use in display
[in]imageSourceSource for producing images to display. Must have a getCcdImage method.
[in]displayimage display to use
[in]overlayShow amp bounding boxes on the displayed image?
[in]imageFactoryThe image factory to use in generating the images.
[in]binSizeBinning factor
[in]inCameraCoordsShow the Detector in camera coordinates?

Definition at line 499 of file utils.py.

500  imageFactory=afwImage.ImageF, binSize=1, inCameraCoords=False):
501  """!Show a CCD on display
502 
503  @param[in] ccd Detector to use in display
504  @param[in] imageSource Source for producing images to display. Must have a getCcdImage method.
505  @param[in] display image display to use
506  @param[in] overlay Show amp bounding boxes on the displayed image?
507  @param[in] imageFactory The image factory to use in generating the images.
508  @param[in] binSize Binning factor
509  @param[in] inCameraCoords Show the Detector in camera coordinates?
510  """
511  display = _getDisplayFromDisplayOrFrame(display, frame)
512 
513  ccdOrigin = afwGeom.Point2I(0,0)
514  nQuarter = 0
515  ccdImage = imageSource.getCcdImage(ccd, imageFactory=imageFactory, binSize=binSize)
516 
517  ccdBbox = ccdImage.getBBox()
518  if ccdBbox.getDimensions() == ccd.getBBox().getDimensions():
519  isTrimmed = True
520  else:
521  isTrimmed = False
522 
523  if inCameraCoords:
524  nQuarter = ccd.getOrientation().getNQuarter()
525  ccdImage = afwMath.rotateImageBy90(ccdImage, nQuarter)
526  title = ccd.getName()
527  if isTrimmed:
528  title += "(trimmed)"
529 
530  if display:
531  display.mtv(ccdImage, title=title)
532 
533  if overlay:
534  overlayCcdBoxes(ccd, ccdBbox, nQuarter, isTrimmed, ccdOrigin, display, binSize)
535 
536  return ccdImage
ImageT::Ptr rotateImageBy90(ImageT const &image, int nQuarter)
Definition: rotateImage.cc:41
def _getDisplayFromDisplayOrFrame
Return an afwDisplay.Display given either a display or a frame ID.
Definition: utils.py:36
def overlayCcdBoxes
Overlay bounding boxes on an image display.
Definition: utils.py:390