LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
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 a frame in ds9. More...
 
def showAmp
 Show an amp in a ds9 frame. More...
 
def showCcd
 Show a CCD on ds9. 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 ds9, with the specified frame. 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 or None if there is not enough information to calculate raw BBox
190  """
191  bbox = afwGeom.Box2I()
192  for amp in ccd:
193  if not amp.getHasRawInfo():
194  return None
195  tbbox = amp.getRawBBox()
196  tbbox.shift(amp.getRawXYOffset())
197  bbox.include(tbbox)
198  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 592 of file utils.py.

593 def findAmp(ccd, pixelPosition):
594  """!Find the Amp with the specified pixel position within the composite
595 
596  @param[in] ccd Detector to look in
597  @param[in] pixelPosition Point2I containing the pixel position
598  @return Amp record in which pixelPosition falls or None if no Amp found.
599  """
600 
601  for amp in ccd:
602  if amp.getBBox().contains(pixelPosition):
603  return amp
604 
605  return None
def findAmp
Find the Amp with the specified pixel position within the composite.
Definition: utils.py:592
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 441 of file utils.py.

442 def getCameraImageBBox(camBbox, pixelSize, bufferSize):
443  """!Get the bounding box of a camera sized image in pixels
444 
445  @param[in] camBbox Camera bounding box in focal plane coordinates (mm)
446  @param[in] pixelSize Size of a detector pixel in mm
447  @param[in] bufferSize Buffer around edge of image in pixels
448  @return the resulting bounding box
449  """
450  pixMin = afwGeom.Point2I(int(camBbox.getMinX()//pixelSize.getX()), int(camBbox.getMinY()//pixelSize.getY()))
451  pixMax = afwGeom.Point2I(int(camBbox.getMaxX()//pixelSize.getX()), int(camBbox.getMaxY()//pixelSize.getY()))
452  retBox = afwGeom.Box2I(pixMin, pixMax)
453  retBox.grow(bufferSize)
454  return retBox
def getCameraImageBBox
Get the bounding box of a camera sized image in pixels.
Definition: utils.py:441
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 412 of file utils.py.

413 def getCcdInCamBBoxList(ccdList, binSize, pixelSize_o, origin):
414  """!Get the bounding boxes of a list of Detectors within a camera sized pixel grid
415 
416  @param[in] ccdList List of Detector
417  @param[in] binSize Binning factor
418  @param[in] pixelSize_o Size of the pixel in mm.
419  @param[in] origin origin of the camera pixel grid in pixels
420  @return a list of bounding boxes in camera pixel coordinates
421  """
422  boxList = []
423  for ccd in ccdList:
424  if not pixelSize_o == ccd.getPixelSize():
425  raise RuntimeError("Cameras with detectors with different pixel scales are not currently supported")
426 
427  dbbox = afwGeom.Box2D()
428  for corner in ccd.getCorners(FOCAL_PLANE):
429  dbbox.include(corner)
430  llc = dbbox.getMin()
431  nQuarter = ccd.getOrientation().getNQuarter()
432  cbbox = ccd.getBBox()
433  ex = cbbox.getDimensions().getX()//binSize
434  ey = cbbox.getDimensions().getY()//binSize
435  bbox = afwGeom.Box2I(cbbox.getMin(), afwGeom.Extent2I(int(ex), int(ey)))
436  bbox = rotateBBoxBy90(bbox, nQuarter, bbox.getDimensions())
437  bbox.shift(afwGeom.Extent2I(int(llc.getX()//pixelSize_o.getX()/binSize), int(llc.getY()//pixelSize_o.getY()/binSize)))
438  bbox.shift(afwGeom.Extent2I(-int(origin.getX()//binSize), -int(origin.getY())//binSize))
439  boxList.append(bbox)
440  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:412
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 569 of file utils.py.

570 def makeFocalPlaneWcs(pixelSize, referencePixel):
571  """!Make a WCS for the focal plane geometry (i.e. returning positions in "mm")
572 
573  @param[in] pixelSize Size of the image pixels in physical units
574  @param[in] referencePixel Pixel for origin of WCS
575  @return Wcs object for mapping between pixels and focal plane.
576  """
577 
578  md = dafBase.PropertySet()
579  if referencePixel is None:
580  referencePixel = afwGeom.PointD(0,0)
581  for i in range(2):
582  md.set("CRPIX%d"%(i+1), referencePixel[i])
583  md.set("CRVAL%d"%(i+1), 0.)
584  md.set("CDELT1", pixelSize[0])
585  md.set("CDELT2", pixelSize[1])
586  md.set("CTYPE1", "CAMERA_X")
587  md.set("CTYPE2", "CAMERA_Y")
588  md.set("CUNIT1", "mm")
589  md.set("CUNIT2", "mm")
590 
591  return afwImage.makeWcs(md)
def makeFocalPlaneWcs
Make a WCS for the focal plane geometry (i.e.
Definition: utils.py:569
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:87
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 456 of file utils.py.

457  imageSource=FakeImageDataSource(), imageFactory=afwImage.ImageU, binSize=1):
458  """!Make an Image of a Camera
459 
460  @param[in] camera Camera object to use to make the image
461  @param[in] detectorNameList List of detector names to use in building the image.
462  Use all Detectors if None.
463  @param[in] background Value to use where there is no Detector
464  @param[in] bufferSize Size of border in binned pixels to make around the camera image
465  @param[in] imageSource Source to get ccd images. Must have a getCcdImage method
466  @param[in] imageFactory Type of image to build
467  @param[in] binSize bin factor
468  @return an image of the camera
469  """
470  if detectorNameList is None:
471  ccdList = camera
472  else:
473  ccdList = [camera[name] for name in detectorNameList]
474 
475  if detectorNameList is None:
476  camBbox = camera.getFpBBox()
477  else:
478  camBbox = afwGeom.Box2D()
479  for detName in detectorNameList:
480  for corner in camera[detName].getCorners(FOCAL_PLANE):
481  camBbox.include(corner)
482 
483  pixelSize_o = camera[camera.getNameIter().next()].getPixelSize()
484  camBbox = getCameraImageBBox(camBbox, pixelSize_o, bufferSize*binSize)
485  origin = camBbox.getMin()
486  # This segfaults for large images. It seems better to throw instead of segfaulting, but maybe that's not easy.
487  # This is DM-89
488  camIm = imageFactory(int(math.ceil(camBbox.getDimensions().getX()/binSize)),
489  int(math.ceil(camBbox.getDimensions().getY()/binSize)))
490  boxList = getCcdInCamBBoxList(ccdList, binSize, pixelSize_o, origin)
491  for det, bbox in itertools.izip(ccdList, boxList):
492  im = imageSource.getCcdImage(det, imageFactory, binSize)
493  nQuarter = det.getOrientation().getNQuarter()
494  im = afwMath.rotateImageBy90(im, nQuarter)
495  imView = camIm.Factory(camIm, bbox, afwImage.LOCAL)
496  imView <<= im
497 
498  return camIm
Edge * next
Definition: ImageUtils.cc:91
def getCameraImageBBox
Get the bounding box of a camera sized image in pixels.
Definition: utils.py:441
def getCcdInCamBBoxList
Get the bounding boxes of a list of Detectors within a camera sized pixel grid.
Definition: utils.py:412
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 199 of file utils.py.

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

Overlay bounding boxes on a frame in ds9.

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]frameds9 frame to display on
[in]binSizebinning factor

Definition at line 279 of file utils.py.

280 def overlayCcdBoxes(ccd, untrimmedCcdBbox, nQuarter, isTrimmed, ccdOrigin, frame, binSize):
281  """!Overlay bounding boxes on a frame in ds9
282 
283  @param[in] ccd Detector to iterate for the amp bounding boxes
284  @param[in] untrimmedCcdBbox Bounding box of the un-trimmed Detector
285  @param[in] nQuarter number of 90 degree rotations to apply to the bounding boxes
286  @param[in] isTrimmed Is the Detector image over which the boxes are layed trimmed?
287  @param[in] ccdOrigin Detector origin relative to the parent origin if in a larger pixel grid
288  @param[in] frame ds9 frame to display on
289  @param[in] binSize binning factor
290  """
291  with ds9.Buffering():
292  ccdDim = untrimmedCcdBbox.getDimensions()
293  ccdBbox = rotateBBoxBy90(untrimmedCcdBbox, nQuarter, ccdDim)
294  for amp in ccd:
295  if isTrimmed:
296  ampbbox = amp.getBBox()
297  else:
298  ampbbox = amp.getRawBBox()
299  ampbbox.shift(amp.getRawXYOffset())
300  if nQuarter != 0:
301  ampbbox = rotateBBoxBy90(ampbbox, nQuarter, ccdDim)
302 
303  displayUtils.drawBBox(ampbbox, origin=ccdOrigin, borderWidth=0.49,
304  frame=frame, bin=binSize)
305 
306  if not isTrimmed and amp.getHasRawInfo():
307  for bbox, ctype in ((amp.getRawHorizontalOverscanBBox(), ds9.RED), (amp.getRawDataBBox(), ds9.BLUE),
308  (amp.getRawVerticalOverscanBBox(), ds9.MAGENTA), (amp.getRawPrescanBBox(), ds9.YELLOW)):
309  if amp.getRawFlipX():
310  bbox.flipLR(amp.getRawBBox().getDimensions().getX())
311  if amp.getRawFlipY():
312  bbox.flipTB(amp.getRawBBox().getDimensions().getY())
313  bbox.shift(amp.getRawXYOffset())
314  if nQuarter != 0:
315  bbox = rotateBBoxBy90(bbox, nQuarter, ccdDim)
316  displayUtils.drawBBox(bbox, origin=ccdOrigin, borderWidth=0.49, ctype=ctype, frame=frame, bin=binSize)
317  # Label each Amp
318  xc, yc = (ampbbox.getMin()[0] + ampbbox.getMax()[0])//2, (ampbbox.getMin()[1] +
319  ampbbox.getMax()[1])//2
320  #
321  # Rotate the amp labels too
322  #
323  if nQuarter == 0:
324  c, s = 1, 0
325  elif nQuarter == 1:
326  c, s = 0, -1
327  elif nQuarter == 2:
328  c, s = -1, 0
329  elif nQuarter == 3:
330  c, s = 0, 1
331  c, s = 1, 0
332  ccdHeight = ccdBbox.getHeight()
333  ccdWidth = ccdBbox.getWidth()
334  xc -= 0.5*ccdHeight
335  yc -= 0.5*ccdWidth
336 
337  xc, yc = 0.5*ccdHeight + c*xc + s*yc, 0.5*ccdWidth + -s*xc + c*yc
338 
339  if ccdOrigin:
340  xc += ccdOrigin[0]
341  yc += ccdOrigin[1]
342  ds9.dot(str(amp.getName()), xc/binSize, yc/binSize, frame=frame, textAngle=nQuarter*90)
343 
344  displayUtils.drawBBox(ccdBbox, origin=ccdOrigin,
345  borderWidth=0.49, ctype=ds9.MAGENTA, frame=frame, bin=binSize)
def rotateBBoxBy90
Rotate a bounding box by an integer multiple of 90 degrees.
def overlayCcdBoxes
Overlay bounding boxes on a frame in ds9.
Definition: utils.py:279
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()
double min
Definition: attributes.cc:216
double max
Definition: attributes.cc:218
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),
  frame = None,
  overlay = True,
  imageFactory = afwImage.ImageU 
)

Show an amp in a ds9 frame.

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

Definition at line 346 of file utils.py.

347 def showAmp(amp, imageSource=FakeImageDataSource(isTrimmed=False), frame=None, overlay=True, imageFactory=afwImage.ImageU):
348  """!Show an amp in a ds9 frame
349 
350  @param[in] amp amp record to use in display
351  @param[in] imageSource Source for getting the amp image. Must have a getAmpImage method.
352  @param[in] frame ds9 frame to display on; defaults to frame zero
353  @param[in] overlay Overlay bounding boxes?
354  @param[in] imageFactory Type of image to display (only used if ampImage is None)
355  """
356 
357  ampImage = imageSource.getAmpImage(amp, imageFactory=imageFactory)
358  ampImSize = ampImage.getDimensions()
359  title = amp.getName()
360  ds9.mtv(ampImage, frame=frame, title=title)
361  if overlay:
362  with ds9.Buffering():
363  if amp.getHasRawInfo() and ampImSize == amp.getRawBBox().getDimensions():
364  bboxes = [(amp.getRawBBox(), 0.49, ds9.GREEN),]
365  xy0 = bboxes[0][0].getMin()
366  bboxes.append((amp.getRawHorizontalOverscanBBox(), 0.49, ds9.RED))
367  bboxes.append((amp.getRawDataBBox(), 0.49, ds9.BLUE))
368  bboxes.append((amp.getRawPrescanBBox(), 0.49, ds9.YELLOW))
369  bboxes.append((amp.getRawVerticalOverscanBBox(), 0.49, ds9.MAGENTA))
370  else:
371  bboxes = [(amp.getBBox(), 0.49, None),]
372  xy0 = bboxes[0][0].getMin()
373 
374  for bbox, borderWidth, ctype in bboxes:
375  if bbox.isEmpty():
376  continue
377  bbox = afwGeom.Box2I(bbox)
378  bbox.shift(-afwGeom.ExtentI(xy0))
379  displayUtils.drawBBox(bbox, borderWidth=borderWidth, ctype=ctype, frame=frame)
An integer coordinate rectangle.
Definition: Box.h:53
def showAmp
Show an amp in a ds9 frame.
Definition: utils.py:346
def lsst.afw.cameraGeom.utils.showCamera (   camera,
  imageSource = FakeImageDataSource(),
  imageFactory = afwImage.ImageU,
  detectorNameList = None,
  binSize = 10,
  bufferSize = 10,
  frame = None,
  overlay = True,
  title = "",
  ctype = ds9.GREEN,
  textSize = 1.25,
  originAtCenter = True,
  kwargs 
)

Show a Camera on ds9, with the specified frame.

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]frameds9 frame in which to display
[in]overlayOverlay Detector IDs and boundaries?
[in]titleTitle in ds9 frame
[in]ctypeColor to use when drawing Detector boundaries
[in]textSizeSize of detector labels
[in]originAtCenterPut the origin of the camera WCS at the center of the image? Else it will be LL
[in]**kwargsall remaining keyword arguments are passed to makeImageFromCamera
Returns
the mosaic image

Definition at line 501 of file utils.py.

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

Show a CCD on ds9.

Parameters
[in]ccdDetector to use in display
[in]imageSourceSource for producing images to display. Must have a getCcdImage method.
[in]frameds9 frame to use, defaults to frame zero
[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 380 of file utils.py.

381 def showCcd(ccd, imageSource=FakeImageDataSource(), frame=None, overlay=True, imageFactory=afwImage.ImageU, binSize=1, inCameraCoords=False):
382  """!Show a CCD on ds9
383 
384  @param[in] ccd Detector to use in display
385  @param[in] imageSource Source for producing images to display. Must have a getCcdImage method.
386  @param[in] frame ds9 frame to use, defaults to frame zero
387  @param[in] overlay Show amp bounding boxes on the displayed image?
388  @param[in] imageFactory The image factory to use in generating the images.
389  @param[in] binSize Binning factor
390  @param[in] inCameraCoords Show the Detector in camera coordinates?
391  """
392  ccdOrigin = afwGeom.Point2I(0,0)
393  nQuarter = 0
394  ccdImage = imageSource.getCcdImage(ccd, imageFactory=imageFactory, binSize=binSize)
395 
396  ccdBbox = ccdImage.getBBox()
397  if ccdBbox.getDimensions() == ccd.getBBox().getDimensions():
398  isTrimmed = True
399  else:
400  isTrimmed = False
401 
402  if inCameraCoords:
403  nQuarter = ccd.getOrientation().getNQuarter()
404  ccdImage = afwMath.rotateImageBy90(ccdImage, nQuarter)
405  title = ccd.getName()
406  if isTrimmed:
407  title += "(trimmed)"
408  ds9.mtv(ccdImage, frame=frame, title=title)
409 
410  if overlay:
411  overlayCcdBoxes(ccd, ccdBbox, nQuarter, isTrimmed, ccdOrigin, frame, binSize)
def showCcd
Show a CCD on ds9.
Definition: utils.py:380
ImageT::Ptr rotateImageBy90(ImageT const &image, int nQuarter)
Definition: rotateImage.cc:41
def overlayCcdBoxes
Overlay bounding boxes on a frame in ds9.
Definition: utils.py:279

Variable Documentation

lsst.afw.cameraGeom.utils.display = False

Definition at line 48 of file utils.py.