LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Classes | Functions | Variables
lsst.afw.cameraGeom.utils Namespace Reference

Classes

class  FakeImageDataSource
 

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...
 

Variables

 display = False
 

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 184 of file utils.py.

185 def calcRawCcdBBox(ccd):
186  """!Calculate the raw ccd bounding box
187 
188  @param[in] ccd Detector for with to calculate the un-trimmed bounding box
189  @return Box2I of the un-trimmed Detector,
190  or None if there is not enough information to calculate raw BBox
191  """
192  bbox = afwGeom.Box2I()
193  for amp in ccd:
194  if not amp.getHasRawInfo():
195  return None
196  tbbox = amp.getRawBBox()
197  tbbox.shift(amp.getRawXYOffset())
198  bbox.include(tbbox)
199  return bbox
An integer coordinate rectangle.
Definition: Box.h:53
def calcRawCcdBBox
Calculate the raw ccd bounding box.
Definition: utils.py:184
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 612 of file utils.py.

613 def findAmp(ccd, pixelPosition):
614  """!Find the Amp with the specified pixel position within the composite
615 
616  @param[in] ccd Detector to look in
617  @param[in] pixelPosition Point2I containing the pixel position
618  @return Amp record in which pixelPosition falls or None if no Amp found.
619  """
620 
621  for amp in ccd:
622  if amp.getBBox().contains(pixelPosition):
623  return amp
624 
625  return None
def findAmp
Find the Amp with the specified pixel position within the composite.
Definition: utils.py:612
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 456 of file utils.py.

457 def getCameraImageBBox(camBbox, pixelSize, bufferSize):
458  """!Get the bounding box of a camera sized image in pixels
459 
460  @param[in] camBbox Camera bounding box in focal plane coordinates (mm)
461  @param[in] pixelSize Size of a detector pixel in mm
462  @param[in] bufferSize Buffer around edge of image in pixels
463  @return the resulting bounding box
464  """
465  pixMin = afwGeom.Point2I(int(camBbox.getMinX()//pixelSize.getX()),
466  int(camBbox.getMinY()//pixelSize.getY()))
467  pixMax = afwGeom.Point2I(int(camBbox.getMaxX()//pixelSize.getX()),
468  int(camBbox.getMaxY()//pixelSize.getY()))
469  retBox = afwGeom.Box2I(pixMin, pixMax)
470  retBox.grow(bufferSize)
471  return retBox
def getCameraImageBBox
Get the bounding box of a camera sized image in pixels.
Definition: utils.py:456
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 425 of file utils.py.

426 def getCcdInCamBBoxList(ccdList, binSize, pixelSize_o, origin):
427  """!Get the bounding boxes of a list of Detectors within a camera sized pixel grid
428 
429  @param[in] ccdList List of Detector
430  @param[in] binSize Binning factor
431  @param[in] pixelSize_o Size of the pixel in mm.
432  @param[in] origin origin of the camera pixel grid in pixels
433  @return a list of bounding boxes in camera pixel coordinates
434  """
435  boxList = []
436  for ccd in ccdList:
437  if not pixelSize_o == ccd.getPixelSize():
438  raise RuntimeError(
439  "Cameras with detectors with different pixel scales are not currently supported")
440 
441  dbbox = afwGeom.Box2D()
442  for corner in ccd.getCorners(FOCAL_PLANE):
443  dbbox.include(corner)
444  llc = dbbox.getMin()
445  nQuarter = ccd.getOrientation().getNQuarter()
446  cbbox = ccd.getBBox()
447  ex = cbbox.getDimensions().getX()//binSize
448  ey = cbbox.getDimensions().getY()//binSize
449  bbox = afwGeom.Box2I(cbbox.getMin(), afwGeom.Extent2I(int(ex), int(ey)))
450  bbox = rotateBBoxBy90(bbox, nQuarter, bbox.getDimensions())
451  bbox.shift(afwGeom.Extent2I(int(llc.getX()//pixelSize_o.getX()/binSize),
452  int(llc.getY()//pixelSize_o.getY()/binSize)))
453  bbox.shift(afwGeom.Extent2I(-int(origin.getX()//binSize), -int(origin.getY())//binSize))
454  boxList.append(bbox)
455  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:425
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 589 of file utils.py.

590 def makeFocalPlaneWcs(pixelSize, referencePixel):
591  """!Make a WCS for the focal plane geometry (i.e. returning positions in "mm")
592 
593  @param[in] pixelSize Size of the image pixels in physical units
594  @param[in] referencePixel Pixel for origin of WCS
595  @return Wcs object for mapping between pixels and focal plane.
596  """
597 
598  md = dafBase.PropertySet()
599  if referencePixel is None:
600  referencePixel = afwGeom.PointD(0,0)
601  for i in range(2):
602  md.set("CRPIX%d"%(i+1), referencePixel[i])
603  md.set("CRVAL%d"%(i+1), 0.)
604  md.set("CDELT1", pixelSize[0])
605  md.set("CDELT2", pixelSize[1])
606  md.set("CTYPE1", "CAMERA_X")
607  md.set("CTYPE2", "CAMERA_Y")
608  md.set("CUNIT1", "mm")
609  md.set("CUNIT2", "mm")
610 
611  return afwImage.makeWcs(md)
def makeFocalPlaneWcs
Make a WCS for the focal plane geometry (i.e.
Definition: utils.py:589
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 138 of file utils.py.

139  scaleGain = lambda gain: (gain*1000)//10):
140  """!Make an image from an amp object
141 
142  Since images are integer images by default, the gain needs to be scaled to give enough dynamic range
143  to see variation from amp to amp. The scaling algorithm is assignable.
144 
145  @param[in] amp Amp record to use for constructing the raw amp image
146  @param[in] imValue Value to assign to the constructed image scaleGain(gain) is used if not set
147  @param[in] imageFactory Type of image to construct
148  @param[in] markSize Size of mark at read corner in pixels
149  @param[in] markValue Value of pixels in the read corner mark
150  @param[in] scaleGain The function by which to scale the gain
151  @return an untrimmed amp image
152  """
153  if not amp.getHasRawInfo():
154  raise RuntimeError("Can't create a raw amp image without raw amp information")
155  bbox = amp.getRawBBox()
156  dbbox = amp.getRawDataBBox()
157  img = imageFactory(bbox)
158  if imValue is None:
159  img.set(scaleGain(amp.getGain()))
160  else:
161  img.set(imValue)
162  #Set the first pixel read to a different value
163  markbbox = afwGeom.Box2I()
164  if amp.getReadoutCorner() == 0:
165  markbbox.include(dbbox.getMin())
166  markbbox.include(dbbox.getMin()+afwGeom.Extent2I(markSize, markSize))
167  elif amp.getReadoutCorner() == 1:
168  cornerPoint = afwGeom.Point2I(dbbox.getMaxX(), dbbox.getMinY())
169  markbbox.include(cornerPoint)
170  markbbox.include(cornerPoint + afwGeom.Extent2I(-markSize, markSize))
171  elif amp.getReadoutCorner() == 2:
172  cornerPoint = afwGeom.Point2I(dbbox.getMax())
173  markbbox.include(cornerPoint)
174  markbbox.include(cornerPoint + afwGeom.Extent2I(-markSize, -markSize))
175  elif amp.getReadoutCorner() == 3:
176  cornerPoint = afwGeom.Point2I(dbbox.getMinX(), dbbox.getMaxY())
177  markbbox.include(cornerPoint)
178  markbbox.include(cornerPoint + afwGeom.Extent2I(markSize, -markSize))
179  else:
180  raise RuntimeError("Could not set readout corner")
181  mimg = imageFactory(img, markbbox, False)
182  mimg.set(markValue)
183  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 473 of file utils.py.

474  imageSource=FakeImageDataSource(), imageFactory=afwImage.ImageU, binSize=1):
475  """!Make an Image of a Camera
476 
477  @param[in] camera Camera object to use to make the image
478  @param[in] detectorNameList List of detector names to use in building the image.
479  Use all Detectors if None.
480  @param[in] background Value to use where there is no Detector
481  @param[in] bufferSize Size of border in binned pixels to make around the camera image
482  @param[in] imageSource Source to get ccd images. Must have a getCcdImage method
483  @param[in] imageFactory Type of image to build
484  @param[in] binSize bin factor
485  @return an image of the camera
486  """
487  if detectorNameList is None:
488  ccdList = camera
489  else:
490  ccdList = [camera[name] for name in detectorNameList]
491 
492  if detectorNameList is None:
493  camBbox = camera.getFpBBox()
494  else:
495  camBbox = afwGeom.Box2D()
496  for detName in detectorNameList:
497  for corner in camera[detName].getCorners(FOCAL_PLANE):
498  camBbox.include(corner)
499 
500  pixelSize_o = camera[camera.getNameIter().next()].getPixelSize()
501  camBbox = getCameraImageBBox(camBbox, pixelSize_o, bufferSize*binSize)
502  origin = camBbox.getMin()
503 
504  camIm = imageFactory(int(math.ceil(camBbox.getDimensions().getX()/binSize)),
505  int(math.ceil(camBbox.getDimensions().getY()/binSize)))
506  boxList = getCcdInCamBBoxList(ccdList, binSize, pixelSize_o, origin)
507  for det, bbox in itertools.izip(ccdList, boxList):
508  im = imageSource.getCcdImage(det, imageFactory, binSize)
509  nQuarter = det.getOrientation().getNQuarter()
510  im = afwMath.rotateImageBy90(im, nQuarter)
511  imView = camIm.Factory(camIm, bbox, afwImage.LOCAL)
512  imView <<= im
513 
514  return camIm
def getCameraImageBBox
Get the bounding box of a camera sized image in pixels.
Definition: utils.py:456
def getCcdInCamBBoxList
Get the bounding boxes of a list of Detectors within a camera sized pixel grid.
Definition: utils.py:425
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 201 of file utils.py.

202  binSize=1):
203  """!Make an Image of a Ccd
204 
205  @param[in] ccd Detector to use in making the image
206  @param[in] isTrimmed Assemble a trimmed Detector image if True
207  @param[in] showAmpGain Use the per amp gain to color the pixels in the image
208  @param[in] imageFactory Image type to generate
209  @param[in] rcMarkSize Size of the mark to make in the amp images at the read corner
210  @param[in] binSize Bin the image by this factor in both dimensions
211  @return Image of the Detector
212  """
213  ampImages = []
214  index = 0
215  if isTrimmed:
216  bbox = ccd.getBBox()
217  else:
218  bbox = calcRawCcdBBox(ccd)
219  for amp in ccd:
220  if amp.getHasRawInfo():
221  if showAmpGain:
222  ampImages.append(makeImageFromAmp(amp, imageFactory=imageFactory, markSize=rcMarkSize))
223  else:
224  ampImages.append(makeImageFromAmp(amp, imValue=(index+1)*1000,
225  imageFactory=imageFactory, markSize=rcMarkSize))
226  index += 1
227 
228  if len(ampImages) > 0:
229  ccdImage = imageFactory(bbox)
230  for ampImage, amp in itertools.izip(ampImages, ccd):
231  if isTrimmed:
232  assembleAmplifierImage(ccdImage, ampImage, amp)
233  else:
234  assembleAmplifierRawImage(ccdImage, ampImage, amp)
235  else:
236  if not isTrimmed:
237  raise RuntimeError("Cannot create untrimmed CCD without amps with raw information")
238  ccdImage = imageFactory(ccd.getBBox())
239  ccdImage = afwMath.binImage(ccdImage, binSize)
240  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:138
def calcRawCcdBBox
Calculate the raw ccd bounding box.
Definition: utils.py:184
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 284 of file utils.py.

285 def overlayCcdBoxes(ccd, untrimmedCcdBbox, nQuarter, isTrimmed, ccdOrigin, display, binSize):
286  """!Overlay bounding boxes on an image display
287 
288  @param[in] ccd Detector to iterate for the amp bounding boxes
289  @param[in] untrimmedCcdBbox Bounding box of the un-trimmed Detector
290  @param[in] nQuarter number of 90 degree rotations to apply to the bounding boxes
291  @param[in] isTrimmed Is the Detector image over which the boxes are layed trimmed?
292  @param[in] ccdOrigin Detector origin relative to the parent origin if in a larger pixel grid
293  @param[in] display image display to display on
294  @param[in] binSize binning factor
295  """
296  with afwDisplay.Buffering():
297  ccdDim = untrimmedCcdBbox.getDimensions()
298  ccdBbox = rotateBBoxBy90(untrimmedCcdBbox, nQuarter, ccdDim)
299  for amp in ccd:
300  if isTrimmed:
301  ampbbox = amp.getBBox()
302  else:
303  ampbbox = amp.getRawBBox()
304  ampbbox.shift(amp.getRawXYOffset())
305  if nQuarter != 0:
306  ampbbox = rotateBBoxBy90(ampbbox, nQuarter, ccdDim)
307 
308  displayUtils.drawBBox(ampbbox, origin=ccdOrigin, borderWidth=0.49,
309  display=display, bin=binSize)
310 
311  if not isTrimmed and amp.getHasRawInfo():
312  for bbox, ctype in ((amp.getRawHorizontalOverscanBBox(), afwDisplay.RED),
313  (amp.getRawDataBBox(), afwDisplay.BLUE),
314  (amp.getRawVerticalOverscanBBox(), afwDisplay.MAGENTA),
315  (amp.getRawPrescanBBox(), afwDisplay.YELLOW)):
316  if amp.getRawFlipX():
317  bbox.flipLR(amp.getRawBBox().getDimensions().getX())
318  if amp.getRawFlipY():
319  bbox.flipTB(amp.getRawBBox().getDimensions().getY())
320  bbox.shift(amp.getRawXYOffset())
321  if nQuarter != 0:
322  bbox = rotateBBoxBy90(bbox, nQuarter, ccdDim)
323  displayUtils.drawBBox(bbox, origin=ccdOrigin, borderWidth=0.49, ctype=ctype,
324  display=display, bin=binSize)
325  # Label each Amp
326  xc, yc = (ampbbox.getMin()[0] + ampbbox.getMax()[0])//2, (ampbbox.getMin()[1] +
327  ampbbox.getMax()[1])//2
328  #
329  # Rotate the amp labels too
330  #
331  if nQuarter == 0:
332  c, s = 1, 0
333  elif nQuarter == 1:
334  c, s = 0, -1
335  elif nQuarter == 2:
336  c, s = -1, 0
337  elif nQuarter == 3:
338  c, s = 0, 1
339  c, s = 1, 0
340  ccdHeight = ccdBbox.getHeight()
341  ccdWidth = ccdBbox.getWidth()
342  xc -= 0.5*ccdHeight
343  yc -= 0.5*ccdWidth
344 
345  xc, yc = 0.5*ccdHeight + c*xc + s*yc, 0.5*ccdWidth + -s*xc + c*yc
346 
347  if ccdOrigin:
348  xc += ccdOrigin[0]
349  yc += ccdOrigin[1]
350  display.dot(str(amp.getName()), xc/binSize, yc/binSize, textAngle=nQuarter*90)
351 
352  displayUtils.drawBBox(ccdBbox, origin=ccdOrigin,
353  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:284
def lsst.afw.cameraGeom.utils.plotFocalPlane (   camera,
  pupilSizeDeg_x,
  pupilSizeDeg_y,
  dx = 0.1,
  dy = 0.1,
  figsize = (10., 10.,
  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]showFigDisplay the figure on the screen?
[in]savePathIf not None, save a copy of the figure to this name

Definition at line 71 of file utils.py.

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

50 
51 def prepareWcsData(wcs, amp, isTrimmed=True):
52  """!Put Wcs from an Amp image into CCD coordinates
53 
54  @param[in, out] wcs WCS object to modify in place
55  @param[in] amp Amp object to use
56  @param[in] isTrimmed Is the image to which the WCS refers trimmed of non-imaging pixels?
57  """
58  if not amp.getHasRawInfo():
59  raise RuntimeError("Cannot modify wcs without raw amp information")
60  if isTrimmed:
61  ampBox = amp.getRawDataBBox()
62  else:
63  ampBox = amp.getRawBBox()
64  wcs.flipImage(amp.getRawFlipX(), amp.getRawFlipY(), ampBox.getDimensions())
65  #Shift WCS for trimming
66  wcs.shiftReferencePixel(-ampBox.getMinX(), -ampBox.getMinY())
67  #Account for shift of amp data in larger ccd matrix
68  offset = amp.getRawXYOffset()
69  wcs.shiftReferencePixel(offset.getX(), offset.getY())
def prepareWcsData
Put Wcs from an Amp image into CCD coordinates.
Definition: utils.py:50
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 355 of file utils.py.

356  imageFactory=afwImage.ImageU):
357  """!Show an amp in an image display
358 
359  @param[in] amp amp record to use in display
360  @param[in] imageSource Source for getting the amp image. Must have a getAmpImage method.
361  @param[in] display image display to use
362  @param[in] overlay Overlay bounding boxes?
363  @param[in] imageFactory Type of image to display (only used if ampImage is None)
364  """
365 
366  if not display:
367  display = afwDisplay.getDisplay()
368 
369  ampImage = imageSource.getAmpImage(amp, imageFactory=imageFactory)
370  ampImSize = ampImage.getDimensions()
371  title = amp.getName()
372  display.mtv(ampImage, title=title)
373  if overlay:
374  with afwDisplay.Buffering():
375  if amp.getHasRawInfo() and ampImSize == amp.getRawBBox().getDimensions():
376  bboxes = [(amp.getRawBBox(), 0.49, afwDisplay.GREEN),]
377  xy0 = bboxes[0][0].getMin()
378  bboxes.append((amp.getRawHorizontalOverscanBBox(), 0.49, afwDisplay.RED))
379  bboxes.append((amp.getRawDataBBox(), 0.49, afwDisplay.BLUE))
380  bboxes.append((amp.getRawPrescanBBox(), 0.49, afwDisplay.YELLOW))
381  bboxes.append((amp.getRawVerticalOverscanBBox(), 0.49, afwDisplay.MAGENTA))
382  else:
383  bboxes = [(amp.getBBox(), 0.49, None),]
384  xy0 = bboxes[0][0].getMin()
385 
386  for bbox, borderWidth, ctype in bboxes:
387  if bbox.isEmpty():
388  continue
389  bbox = afwGeom.Box2I(bbox)
390  bbox.shift(-afwGeom.ExtentI(xy0))
391  displayUtils.drawBBox(bbox, borderWidth=borderWidth, ctype=ctype, display=display)
An integer coordinate rectangle.
Definition: Box.h:53
def lsst.afw.cameraGeom.utils.showCamera (   camera,
  imageSource = FakeImageDataSource(),
  imageFactory = afwImage.ImageU,
  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 517 of file utils.py.

518  ctype=afwDisplay.GREEN, textSize=1.25, originAtCenter=True, display=None, **kwargs):
519  """!Show a Camera on display, with the specified display
520 
521  The rotation of the sensors is snapped to the nearest multiple of 90 deg.
522  Also note that the pixel size is constant over the image array. The lower left corner (LLC) of each
523  sensor amp is snapped to the LLC of the pixel containing the LLC of the image.
524  if overlay show the IDs and detector boundaries
525 
526  @param[in] camera Camera to show
527  @param[in] imageSource Source to get Ccd images from. Must have a getCcdImage method.
528  @param[in] imageFactory Type of image to make
529  @param[in] detectorNameList List of names of Detectors to use. If None use all
530  @param[in] binSize bin factor
531  @param[in] bufferSize size of border in binned pixels to make around camera image.
532  @param[in] frame specify image display (@deprecated; new code should use display)
533  @param[in] overlay Overlay Detector IDs and boundaries?
534  @param[in] title Title in display
535  @param[in] ctype Color to use when drawing Detector boundaries
536  @param[in] textSize Size of detector labels
537  @param[in] originAtCenter Put origin of the camera WCS at the center of the image? Else it will be LL
538  @param[in] display image display on which to display
539  @param[in] **kwargs all remaining keyword arguments are passed to makeImageFromCamera
540  @return the mosaic image
541  """
542  display = displayUtils.getDisplay(display, frame)
543 
544  if binSize < 1:
545  binSize = 1
546  cameraImage = makeImageFromCamera(camera, detectorNameList=detectorNameList, bufferSize=bufferSize,
547  imageSource=imageSource, imageFactory=imageFactory, binSize=binSize,
548  **kwargs)
549 
550  if detectorNameList is None:
551  ccdList = [camera[name] for name in camera.getNameIter()]
552  else:
553  ccdList = [camera[name] for name in detectorNameList]
554 
555  if detectorNameList is None:
556  camBbox = camera.getFpBBox()
557  else:
558  camBbox = afwGeom.Box2D()
559  for detName in detectorNameList:
560  for corner in camera[detName].getCorners(FOCAL_PLANE):
561  camBbox.include(corner)
562  pixelSize = ccdList[0].getPixelSize()
563  if originAtCenter:
564  #Can't divide SWIGGED extent type things when division is imported
565  #from future. This is DM-83
566  ext = cameraImage.getBBox().getDimensions()
567 
568  wcsReferencePixel = afwGeom.PointI(ext.getX()//2, ext.getY()//2)
569  else:
570  wcsReferencePixel = afwGeom.Point2I(0,0)
571  wcs = makeFocalPlaneWcs(pixelSize*binSize, wcsReferencePixel)
572  if title == "":
573  title = camera.getName()
574  display.mtv(cameraImage, title=title, wcs=wcs)
575 
576  if overlay:
577  with afwDisplay.Buffering():
578  camBbox = getCameraImageBBox(camBbox, pixelSize, bufferSize*binSize)
579  bboxList = getCcdInCamBBoxList(ccdList, binSize, pixelSize, camBbox.getMin())
580  for bbox, ccd in itertools.izip(bboxList, ccdList):
581  nQuarter = ccd.getOrientation().getNQuarter()
582  # borderWidth to 0.5 to align with the outside edge of the pixel
583  displayUtils.drawBBox(bbox, borderWidth=0.5, ctype=ctype, display=display)
584  dims = bbox.getDimensions()
585  display.dot(ccd.getName(), bbox.getMinX()+dims.getX()/2, bbox.getMinY()+dims.getY()/2,
586  ctype=ctype, size=textSize, textAngle=nQuarter*90)
587 
588  return cameraImage
def getCameraImageBBox
Get the bounding box of a camera sized image in pixels.
Definition: utils.py:456
def makeFocalPlaneWcs
Make a WCS for the focal plane geometry (i.e.
Definition: utils.py:589
def getCcdInCamBBoxList
Get the bounding boxes of a list of Detectors within a camera sized pixel grid.
Definition: utils.py:425
def makeImageFromCamera
Make an Image of a Camera.
Definition: utils.py:473
A floating-point coordinate rectangle geometry.
Definition: Box.h:271
def lsst.afw.cameraGeom.utils.showCcd (   ccd,
  imageSource = FakeImageDataSource(),
  display = None,
  overlay = True,
  imageFactory = afwImage.ImageU,
  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 393 of file utils.py.

394  imageFactory=afwImage.ImageU, binSize=1, inCameraCoords=False):
395  """!Show a CCD on display
396 
397  @param[in] ccd Detector to use in display
398  @param[in] imageSource Source for producing images to display. Must have a getCcdImage method.
399  @param[in] display image display to use
400  @param[in] overlay Show amp bounding boxes on the displayed image?
401  @param[in] imageFactory The image factory to use in generating the images.
402  @param[in] binSize Binning factor
403  @param[in] inCameraCoords Show the Detector in camera coordinates?
404  """
405  ccdOrigin = afwGeom.Point2I(0,0)
406  nQuarter = 0
407  ccdImage = imageSource.getCcdImage(ccd, imageFactory=imageFactory, binSize=binSize)
408 
409  ccdBbox = ccdImage.getBBox()
410  if ccdBbox.getDimensions() == ccd.getBBox().getDimensions():
411  isTrimmed = True
412  else:
413  isTrimmed = False
414 
415  if inCameraCoords:
416  nQuarter = ccd.getOrientation().getNQuarter()
417  ccdImage = afwMath.rotateImageBy90(ccdImage, nQuarter)
418  title = ccd.getName()
419  if isTrimmed:
420  title += "(trimmed)"
421  display.mtv(ccdImage, title=title)
422 
423  if overlay:
424  overlayCcdBoxes(ccd, ccdBbox, nQuarter, isTrimmed, ccdOrigin, display, binSize)
ImageT::Ptr rotateImageBy90(ImageT const &image, int nQuarter)
Definition: rotateImage.cc:41
def overlayCcdBoxes
Overlay bounding boxes on an image display.
Definition: utils.py:284

Variable Documentation

lsst.afw.cameraGeom.utils.display = False

Definition at line 48 of file utils.py.