LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
Classes | Functions | Variables
lsst.afw.cameraGeom.utils Namespace Reference

Classes

class  FakeImageDataSource
 

Functions

def prepareWcsData
 
def plotFocalPlane
 
def makeImageFromAmp
 
def calcRawCcdBBox
 
def makeImageFromCcd
 
def overlayCcdBoxes
 
def showAmp
 
def showCcd
 
def getCcdInCamBBoxList
 
def getCameraImageBBox
 
def makeImageFromCamera
 
def showCamera
 
def makeFocalPlaneWcs
 
def findAmp
 

Variables

 display = False
 

Function Documentation

def lsst.afw.cameraGeom.utils.calcRawCcdBBox (   ccd)
Calculate the raw ccd bounding box
@param[in] ccd: Detector for with to calculate the un-trimmed bounding box
@return Box2I of the un-trimmed Detector or None if there is not enough information to calculate raw BBox

Definition at line 182 of file utils.py.

183 def calcRawCcdBBox(ccd):
184  """Calculate the raw ccd bounding box
185  @param[in] ccd: Detector for with to calculate the un-trimmed bounding box
186  @return Box2I of the un-trimmed Detector or None if there is not enough information to calculate raw BBox
187  """
188  bbox = afwGeom.Box2I()
189  for amp in ccd:
190  if not amp.getHasRawInfo():
191  return None
192  tbbox = amp.getRawBBox()
193  tbbox.shift(amp.getRawXYOffset())
194  bbox.include(tbbox)
195  return bbox
An integer coordinate rectangle.
Definition: Box.h:53
def lsst.afw.cameraGeom.utils.findAmp (   ccd,
  pixelPosition 
)
Find the Amp with the specified pixel position within the composite
@param[in] ccd: Detector to look in
@param[in] pixelPosition: Point2I containing the pixel position
@return amp: Amp record in which pixelPosition falls or None if no Amp found.

Definition at line 574 of file utils.py.

575 def findAmp(ccd, pixelPosition):
576  """Find the Amp with the specified pixel position within the composite
577  @param[in] ccd: Detector to look in
578  @param[in] pixelPosition: Point2I containing the pixel position
579  @return amp: Amp record in which pixelPosition falls or None if no Amp found.
580  """
581 
582  for amp in ccd:
583  if amp.getBBox().contains(pixelPosition):
584  return amp
585 
586  return None
def lsst.afw.cameraGeom.utils.getCameraImageBBox (   camBbox,
  pixelSize,
  bufferSize 
)
Get the bounding box of a camera sized image in pixels
@param[in] camBbox: Camera bounding box in focal plane coordinates (mm)
@param[in] pixelSize: Size of a detector pixel in mm
@param[in] bufferSize: Buffer around edge of image in pixels
@return the resulting bounding box

Definition at line 430 of file utils.py.

431 def getCameraImageBBox(camBbox, pixelSize, bufferSize):
432  """Get the bounding box of a camera sized image in pixels
433  @param[in] camBbox: Camera bounding box in focal plane coordinates (mm)
434  @param[in] pixelSize: Size of a detector pixel in mm
435  @param[in] bufferSize: Buffer around edge of image in pixels
436  @return the resulting bounding box
437  """
438  pixMin = afwGeom.Point2I(int(camBbox.getMinX()//pixelSize.getX()), int(camBbox.getMinY()//pixelSize.getY()))
439  pixMax = afwGeom.Point2I(int(camBbox.getMaxX()//pixelSize.getX()), int(camBbox.getMaxY()//pixelSize.getY()))
440  retBox = afwGeom.Box2I(pixMin, pixMax)
441  retBox.grow(bufferSize)
442  return retBox
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
@param[in] ccdList: List of Detector
@param[in] binSize: Binning factor
@param[in] pixelSize_o: Size of the pixel in mm.
@param[in] origin: origin of the camera pixel grid in pixels
@return a list of bounding boxes in camera pixel coordinates

Definition at line 402 of file utils.py.

403 def getCcdInCamBBoxList(ccdList, binSize, pixelSize_o, origin):
404  """Get the bounding boxes of a list of Detectors within a camera sized pixel grid
405  @param[in] ccdList: List of Detector
406  @param[in] binSize: Binning factor
407  @param[in] pixelSize_o: Size of the pixel in mm.
408  @param[in] origin: origin of the camera pixel grid in pixels
409  @return a list of bounding boxes in camera pixel coordinates
410  """
411  boxList = []
412  for ccd in ccdList:
413  if not pixelSize_o == ccd.getPixelSize():
414  raise RuntimeError("Cameras with detectors with different pixel scales are not currently supported")
415 
416  dbbox = afwGeom.Box2D()
417  for corner in ccd.getCorners(FOCAL_PLANE):
418  dbbox.include(corner)
419  llc = dbbox.getMin()
420  nQuarter = ccd.getOrientation().getNQuarter()
421  cbbox = ccd.getBBox()
422  ex = cbbox.getDimensions().getX()//binSize
423  ey = cbbox.getDimensions().getY()//binSize
424  bbox = afwGeom.Box2I(cbbox.getMin(), afwGeom.Extent2I(int(ex), int(ey)))
425  bbox = rotateBBoxBy90(bbox, nQuarter, bbox.getDimensions())
426  bbox.shift(afwGeom.Extent2I(int(llc.getX()//pixelSize_o.getX()/binSize), int(llc.getY()//pixelSize_o.getY()/binSize)))
427  bbox.shift(afwGeom.Extent2I(-int(origin.getX()//binSize), -int(origin.getY())//binSize))
428  boxList.append(bbox)
429  return boxList
An integer coordinate rectangle.
Definition: Box.h:53
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")
@param[in] pixelSize: Size of the image pixels in physical units
@param[in] referencePixel: Pixel for origin of WCS
@return Wcs object for mapping between pixels and focal plane.

Definition at line 552 of file utils.py.

553 def makeFocalPlaneWcs(pixelSize, referencePixel):
554  """Make a WCS for the focal plane geometry (i.e. returning positions in "mm")
555  @param[in] pixelSize: Size of the image pixels in physical units
556  @param[in] referencePixel: Pixel for origin of WCS
557  @return Wcs object for mapping between pixels and focal plane.
558  """
559 
560  md = dafBase.PropertySet()
561  if referencePixel is None:
562  referencePixel = afwGeom.PointD(0,0)
563  for i in range(2):
564  md.set("CRPIX%d"%(i+1), referencePixel[i])
565  md.set("CRVAL%d"%(i+1), 0.)
566  md.set("CDELT1", pixelSize[0])
567  md.set("CDELT2", pixelSize[1])
568  md.set("CTYPE1", "CAMERA_X")
569  md.set("CTYPE2", "CAMERA_Y")
570  md.set("CUNIT1", "mm")
571  md.set("CUNIT2", "mm")
572 
573  return afwImage.makeWcs(md)
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.
@param[in] amp: Amp record to use for constructing the raw amp image
@param[in] imValue: Value to assign to the constructed image scaleGain(gain) is used if not set
@param[in] imageFactory: Type of image to construct
@param[in] markSize: Size of mark at read corner in pixels
@param[in] markValue: Value of pixels in the read corner mark
@param[in] scaleGain: The function by which to scale the gain
@return 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. Since images are integer images by default, the gain needs
141  to be scaled to give enough dynamic range to see variation from amp to amp. The scaling algorithm
142  is assignable.
143  @param[in] amp: Amp record to use for constructing the raw amp image
144  @param[in] imValue: Value to assign to the constructed image scaleGain(gain) is used if not set
145  @param[in] imageFactory: Type of image to construct
146  @param[in] markSize: Size of mark at read corner in pixels
147  @param[in] markValue: Value of pixels in the read corner mark
148  @param[in] scaleGain: The function by which to scale the gain
149  @return an untrimmed amp image
150  """
151  if not amp.getHasRawInfo():
152  raise RuntimeError("Can't create a raw amp image without raw amp information")
153  bbox = amp.getRawBBox()
154  dbbox = amp.getRawDataBBox()
155  img = imageFactory(bbox)
156  if imValue is None:
157  img.set(scaleGain(amp.getGain()))
158  else:
159  img.set(imValue)
160  #Set the first pixel read to a different value
161  markbbox = afwGeom.Box2I()
162  if amp.getReadoutCorner() == 0:
163  markbbox.include(dbbox.getMin())
164  markbbox.include(dbbox.getMin()+afwGeom.Extent2I(markSize, markSize))
165  elif amp.getReadoutCorner() == 1:
166  cornerPoint = afwGeom.Point2I(dbbox.getMaxX(), dbbox.getMinY())
167  markbbox.include(cornerPoint)
168  markbbox.include(cornerPoint + afwGeom.Extent2I(-markSize, markSize))
169  elif amp.getReadoutCorner() == 2:
170  cornerPoint = afwGeom.Point2I(dbbox.getMax())
171  markbbox.include(cornerPoint)
172  markbbox.include(cornerPoint + afwGeom.Extent2I(-markSize, -markSize))
173  elif amp.getReadoutCorner() == 3:
174  cornerPoint = afwGeom.Point2I(dbbox.getMinX(), dbbox.getMaxY())
175  markbbox.include(cornerPoint)
176  markbbox.include(cornerPoint + afwGeom.Extent2I(markSize, -markSize))
177  else:
178  raise RuntimeError("Could not set readout corner")
179  mimg = imageFactory(img, markbbox, False)
180  mimg.set(markValue)
181  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
@param[in] camera: Camera object to use to make the image
@param[in] detectorNameList: List of detector names to use in building the image.
           Use all Detectors if None.
@param[in] background: Value to use where there is no Detector
@param[in] bufferSize: Size of border in binned pixels to make around the camera image
@param[in] imageSource: Source to get ccd images.  Must have a getCcdImage method
@param[in] imageFactory: Type of image to build
@param[in] binSize: bin factor
@return an image of the camera

Definition at line 444 of file utils.py.

445  imageSource=FakeImageDataSource(), imageFactory=afwImage.ImageU, binSize=1):
446  """Make an Image of a Camera
447  @param[in] camera: Camera object to use to make the image
448  @param[in] detectorNameList: List of detector names to use in building the image.
449  Use all Detectors if None.
450  @param[in] background: Value to use where there is no Detector
451  @param[in] bufferSize: Size of border in binned pixels to make around the camera image
452  @param[in] imageSource: Source to get ccd images. Must have a getCcdImage method
453  @param[in] imageFactory: Type of image to build
454  @param[in] binSize: bin factor
455  @return an image of the camera
456  """
457  if detectorNameList is None:
458  ccdList = camera
459  else:
460  ccdList = [camera[name] for name in detectorNameList]
461 
462  if detectorNameList is None:
463  camBbox = camera.getFpBBox()
464  else:
465  camBbox = afwGeom.Box2D()
466  for detName in detectorNameList:
467  for corner in camera[detName].getCorners(FOCAL_PLANE):
468  camBbox.include(corner)
469 
470  pixelSize_o = camera[camera.getNameIter().next()].getPixelSize()
471  camBbox = getCameraImageBBox(camBbox, pixelSize_o, bufferSize*binSize)
472  origin = camBbox.getMin()
473  # This segfaults for large images. It seems better to throw instead of segfaulting, but maybe that's not easy.
474  # This is DM-89
475  camIm = imageFactory(int(math.ceil(camBbox.getDimensions().getX()/binSize)),
476  int(math.ceil(camBbox.getDimensions().getY()/binSize)))
477  boxList = getCcdInCamBBoxList(ccdList, binSize, pixelSize_o, origin)
478  for det, bbox in itertools.izip(ccdList, boxList):
479  im = imageSource.getCcdImage(det, imageFactory, binSize)
480  nQuarter = det.getOrientation().getNQuarter()
481  im = afwMath.rotateImageBy90(im, nQuarter)
482  imView = camIm.Factory(camIm, bbox, afwImage.LOCAL)
483  imView <<= im
484 
485  return camIm
Edge * next
Definition: ImageUtils.cc:91
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
@param[in] ccd: Detector to use in making the image
@param[in] isTrimmed: Assemble a trimmed Detector image if True
@param[in] showAmpGain: Use the per amp gain to color the pixels in the image
@param[in] imageFactory: Image type to generate
@param[in] rcMarkSize: Size of the mark to make in the amp images at the read corner
@param[in] binSize: Bin the image by this factor in both dimensions
@return Image of the Detector

Definition at line 196 of file utils.py.

197 def makeImageFromCcd(ccd, isTrimmed=True, showAmpGain=True, imageFactory=afwImage.ImageU, rcMarkSize=10, binSize=1):
198  """Make an Image of a Ccd
199  @param[in] ccd: Detector to use in making the image
200  @param[in] isTrimmed: Assemble a trimmed Detector image if True
201  @param[in] showAmpGain: Use the per amp gain to color the pixels in the image
202  @param[in] imageFactory: Image type to generate
203  @param[in] rcMarkSize: Size of the mark to make in the amp images at the read corner
204  @param[in] binSize: Bin the image by this factor in both dimensions
205  @return Image of the Detector
206  """
207  ampImages = []
208  index = 0
209  if isTrimmed:
210  bbox = ccd.getBBox()
211  else:
212  bbox = calcRawCcdBBox(ccd)
213  for amp in ccd:
214  if amp.getHasRawInfo():
215  if showAmpGain:
216  ampImages.append(makeImageFromAmp(amp, imageFactory=imageFactory, markSize=rcMarkSize))
217  else:
218  ampImages.append(makeImageFromAmp(amp, imValue=(index+1)*1000, imageFactory=imageFactory, markSize=rcMarkSize))
219  index += 1
220 
221  if len(ampImages) > 0:
222  ccdImage = imageFactory(bbox)
223  for ampImage, amp in itertools.izip(ampImages, ccd):
224  if isTrimmed:
225  assembleAmplifierImage(ccdImage, ampImage, amp)
226  else:
227  assembleAmplifierRawImage(ccdImage, ampImage, amp)
228  else:
229  if not isTrimmed:
230  raise RuntimeError("Cannot create untrimmed CCD without amps with raw information")
231  ccdImage = imageFactory(ccd.getBBox())
232  ccdImage = afwMath.binImage(ccdImage, binSize)
233  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 lsst.afw.cameraGeom.utils.overlayCcdBoxes (   ccd,
  untrimmedCcdBbox,
  nQuarter,
  isTrimmed,
  ccdOrigin,
  frame,
  binSize 
)
Overlay bounding boxes on a frame in ds9
@param[in] ccd: Detector to iterate for the amp bounding boxes
@param[in] untrimmedCcdBbox: Bounding box of the un-trimmed Detector
@param[in] nQuarter: number of 90 degree rotations to apply to the bounding boxes
@param[in] isTrimmed: Is the Detector image over which the boxes are layed trimmed?
@param[in] ccdOrigin: Detector origin relative to the  parent origin if in a larger pixel grid
@param[in] frame: ds9 frame to display on
@param[in] binSize: binning factor

Definition at line 272 of file utils.py.

273 def overlayCcdBoxes(ccd, untrimmedCcdBbox, nQuarter, isTrimmed, ccdOrigin, frame, binSize):
274  """Overlay bounding boxes on a frame in ds9
275  @param[in] ccd: Detector to iterate for the amp bounding boxes
276  @param[in] untrimmedCcdBbox: Bounding box of the un-trimmed Detector
277  @param[in] nQuarter: number of 90 degree rotations to apply to the bounding boxes
278  @param[in] isTrimmed: Is the Detector image over which the boxes are layed trimmed?
279  @param[in] ccdOrigin: Detector origin relative to the parent origin if in a larger pixel grid
280  @param[in] frame: ds9 frame to display on
281  @param[in] binSize: binning factor
282  """
283  with ds9.Buffering():
284  ccdDim = untrimmedCcdBbox.getDimensions()
285  ccdBbox = rotateBBoxBy90(untrimmedCcdBbox, nQuarter, ccdDim)
286  for amp in ccd:
287  if isTrimmed:
288  ampbbox = amp.getBBox()
289  else:
290  ampbbox = amp.getRawBBox()
291  ampbbox.shift(amp.getRawXYOffset())
292  if nQuarter != 0:
293  ampbbox = rotateBBoxBy90(ampbbox, nQuarter, ccdDim)
294 
295  displayUtils.drawBBox(ampbbox, origin=ccdOrigin, borderWidth=0.49,
296  frame=frame, bin=binSize)
297 
298  if not isTrimmed and amp.getHasRawInfo():
299  for bbox, ctype in ((amp.getRawHorizontalOverscanBBox(), ds9.RED), (amp.getRawDataBBox(), ds9.BLUE),
300  (amp.getRawVerticalOverscanBBox(), ds9.MAGENTA), (amp.getRawPrescanBBox(), ds9.YELLOW)):
301  if amp.getRawFlipX():
302  bbox.flipLR(amp.getRawBBox().getDimensions().getX())
303  if amp.getRawFlipY():
304  bbox.flipTB(amp.getRawBBox().getDimensions().getY())
305  bbox.shift(amp.getRawXYOffset())
306  if nQuarter != 0:
307  bbox = rotateBBoxBy90(bbox, nQuarter, ccdDim)
308  displayUtils.drawBBox(bbox, origin=ccdOrigin, borderWidth=0.49, ctype=ctype, frame=frame, bin=binSize)
309  # Label each Amp
310  xc, yc = (ampbbox.getMin()[0] + ampbbox.getMax()[0])//2, (ampbbox.getMin()[1] +
311  ampbbox.getMax()[1])//2
312  #
313  # Rotate the amp labels too
314  #
315  if nQuarter == 0:
316  c, s = 1, 0
317  elif nQuarter == 1:
318  c, s = 0, -1
319  elif nQuarter == 2:
320  c, s = -1, 0
321  elif nQuarter == 3:
322  c, s = 0, 1
323  c, s = 1, 0
324  ccdHeight = ccdBbox.getHeight()
325  ccdWidth = ccdBbox.getWidth()
326  xc -= 0.5*ccdHeight
327  yc -= 0.5*ccdWidth
328 
329  xc, yc = 0.5*ccdHeight + c*xc + s*yc, 0.5*ccdWidth + -s*xc + c*yc
330 
331  if ccdOrigin:
332  xc += ccdOrigin[0]
333  yc += ccdOrigin[1]
334  ds9.dot(str(amp.getName()), xc/binSize, yc/binSize, frame=frame, textAngle=nQuarter*90)
335 
336  displayUtils.drawBBox(ccdBbox, origin=ccdOrigin,
337  borderWidth=0.49, ctype=ds9.MAGENTA, frame=frame, bin=binSize)
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
@param[in] camera: a camera object
@param[in] pupilSizeDeg_x: Amount of the pupil to sample in x in degrees
@param[in] pupilSizeDeg_y: Amount of the pupil to sample in y in degrees
@param[in] dx: Spacing of sample points in x in degrees
@param[in] dy: Spacing of sample points in y in degrees
@param[in] figsize: matplotlib style tuple indicating the size of the figure in inches
@param[in] showFig: Display the figure on the screen?
@param[in] savePath: If not None, save a copy of the figure to this name

Definition at line 71 of file utils.py.

71 
72 def plotFocalPlane(camera, pupilSizeDeg_x, pupilSizeDeg_y, dx=0.1, dy=0.1, figsize=(10., 10.), showFig=True, savePath=None):
73  """
74  Make a plot of the focal plane along with a set points that sample the Pupil
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
@param[in, out] wcs: WCS object to modify in place
@param[in] amp: Amp object to use
@param[in] isTrimmed: Is the image to which the WCS refers trimmed of non-imaging pixels?

Definition at line 51 of file utils.py.

51 
52 def prepareWcsData(wcs, amp, isTrimmed=True):
53  """
54  Put Wcs from an Amp image into CCD coordinates
55  @param[in, out] wcs: WCS object to modify in place
56  @param[in] amp: Amp object to use
57  @param[in] isTrimmed: Is the image to which the WCS refers trimmed of non-imaging pixels?
58  """
59  if not amp.getHasRawInfo():
60  raise RuntimeError("Cannot modify wcs without raw amp information")
61  if isTrimmed:
62  ampBox = amp.getRawDataBBox()
63  else:
64  ampBox = amp.getRawBBox()
65  wcs.flipImage(amp.getRawFlipX(), amp.getRawFlipY(), ampBox.getDimensions())
66  #Shift WCS for trimming
67  wcs.shiftReferencePixel(-ampBox.getMinX(), -ampBox.getMinY())
68  #Account for shift of amp data in larger ccd matrix
69  offset = amp.getRawXYOffset()
70  wcs.shiftReferencePixel(offset.getX(), offset.getY())
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
@param[in] amp: amp record to use in display
@param[in] imageSource: Source for getting the amp image.  Must have a getAmpImage method.
@param[in] frame: ds9 frame to display on; defaults to frame zero
@param[in] overlay: Overlay bounding boxes?
@param[in] imageFactory: Type of image to display (only used if ampImage is None)

Definition at line 338 of file utils.py.

339 def showAmp(amp, imageSource=FakeImageDataSource(isTrimmed=False), frame=None, overlay=True, imageFactory=afwImage.ImageU):
340  """Show an amp in a ds9 frame
341  @param[in] amp: amp record to use in display
342  @param[in] imageSource: Source for getting the amp image. Must have a getAmpImage method.
343  @param[in] frame: ds9 frame to display on; defaults to frame zero
344  @param[in] overlay: Overlay bounding boxes?
345  @param[in] imageFactory: Type of image to display (only used if ampImage is None)
346  """
347 
348  ampImage = imageSource.getAmpImage(amp, imageFactory=imageFactory)
349  ampImSize = ampImage.getDimensions()
350  title = amp.getName()
351  ds9.mtv(ampImage, frame=frame, title=title)
352  if overlay:
353  with ds9.Buffering():
354  if amp.getHasRawInfo() and ampImSize == amp.getRawBBox().getDimensions():
355  bboxes = [(amp.getRawBBox(), 0.49, ds9.GREEN),]
356  xy0 = bboxes[0][0].getMin()
357  bboxes.append((amp.getRawHorizontalOverscanBBox(), 0.49, ds9.RED))
358  bboxes.append((amp.getRawDataBBox(), 0.49, ds9.BLUE))
359  bboxes.append((amp.getRawPrescanBBox(), 0.49, ds9.YELLOW))
360  bboxes.append((amp.getRawVerticalOverscanBBox(), 0.49, ds9.MAGENTA))
361  else:
362  bboxes = [(amp.getBBox(), 0.49, None),]
363  xy0 = bboxes[0][0].getMin()
364 
365  for bbox, borderWidth, ctype in bboxes:
366  if bbox.isEmpty():
367  continue
368  bbox = afwGeom.Box2I(bbox)
369  bbox.shift(-afwGeom.ExtentI(xy0))
370  displayUtils.drawBBox(bbox, borderWidth=borderWidth, ctype=ctype, frame=frame)
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 = 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 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
@param[in] Camera: Camera to show
@param[in] ImageSource: Source to get Ccd images from.  Must have a getCcdImage method.
@param[in] ImageFactory: Type of image to make
@param[in] DetectorNameList: List of names of Detectors to use. If None use all
@param[in] BinSize: bin factor
@param[in] BufferSize: size of border in binned pixels to make around camera image.
@param[in] Frame: ds9 frame in which to display
@param[in] Overlay: Overlay Detector boundaries?
@param[in] Title: Title in ds9 frame
@param[in] Ctype: Color to use when drawing Detector boundaries
@param[in] TextSize: Size of detector labels
@param[in] OriginAtCenter: Put the origin of the camera WCS at the center of the image? Else it will be LL
@return the mosaic image

Definition at line 488 of file utils.py.

489  textSize=1.25, originAtCenter=True, **kwargs):
490  """Show a Camera on ds9 (with the specified frame). The rotation of the sensors is snapped to the nearest
491  multiple of 90 deg. Also note that the pixel size is constant over the image array. The LLC of each
492  sensor amp is snapped to the LLC of the pixel containing the LLC of the image.;
493  if overlay show the IDs and detector boundaries
494  @param[in] Camera: Camera to show
495  @param[in] ImageSource: Source to get Ccd images from. Must have a getCcdImage method.
496  @param[in] ImageFactory: Type of image to make
497  @param[in] DetectorNameList: List of names of Detectors to use. If None use all
498  @param[in] BinSize: bin factor
499  @param[in] BufferSize: size of border in binned pixels to make around camera image.
500  @param[in] Frame: ds9 frame in which to display
501  @param[in] Overlay: Overlay Detector boundaries?
502  @param[in] Title: Title in ds9 frame
503  @param[in] Ctype: Color to use when drawing Detector boundaries
504  @param[in] TextSize: Size of detector labels
505  @param[in] OriginAtCenter: Put the origin of the camera WCS at the center of the image? Else it will be LL
506  @return the mosaic image
507  """
508  if binSize < 1:
509  binSize = 1
510  cameraImage = makeImageFromCamera(camera, detectorNameList=detectorNameList, bufferSize=bufferSize,
511  imageSource=imageSource, imageFactory=imageFactory, binSize=binSize, **kwargs)
512 
513  if detectorNameList is None:
514  ccdList = [camera[name] for name in camera.getNameIter()]
515  else:
516  ccdList = [camera[name] for name in detectorNameList]
517 
518  if detectorNameList is None:
519  camBbox = camera.getFpBBox()
520  else:
521  camBbox = afwGeom.Box2D()
522  for detName in detectorNameList:
523  for corner in camera[detName].getCorners(FOCAL_PLANE):
524  camBbox.include(corner)
525  pixelSize = ccdList[0].getPixelSize()
526  if originAtCenter:
527  #Can't divide SWIGGED extent type things when division is imported
528  #from future. This is DM-83
529  ext = cameraImage.getBBox().getDimensions()
530 
531  wcsReferencePixel = afwGeom.PointI(ext.getX()//2, ext.getY()//2)
532  else:
533  wcsReferencePixel = afwGeom.Point2I(0,0)
534  wcs = makeFocalPlaneWcs(pixelSize*binSize, wcsReferencePixel)
535  if title == "":
536  title = camera.getName()
537  ds9.mtv(cameraImage, title=title, frame=frame, wcs=wcs)
538 
539  if overlay:
540  with ds9.Buffering():
541  camBbox = getCameraImageBBox(camBbox, pixelSize, bufferSize*binSize)
542  bboxList = getCcdInCamBBoxList(ccdList, binSize, pixelSize, camBbox.getMin())
543  for bbox, ccd in itertools.izip(bboxList, ccdList):
544  nQuarter = ccd.getOrientation().getNQuarter()
545  # borderWidth to 0.5 to align with the outside edge of the pixel
546  displayUtils.drawBBox(bbox, borderWidth=0.5, ctype=ctype, frame=frame)
547  dims = bbox.getDimensions()
548  ds9.dot(ccd.getName(), bbox.getMinX()+dims.getX()/2, bbox.getMinY()+dims.getY()/2, ctype=ctype,
549  frame=frame, size=textSize, textAngle=nQuarter*90)
550 
551  return cameraImage
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.  
@param[in] ccd: Detector to use in display
@param[in] imageSource: Source for producing images to display.  Must have a getCcdImage method.
@param[in] frame: ds9 frame to use, defaults to frame zero
@param[in] overlay: Show amp bounding boxes on the displayed image?
@param[in] imageFactory: The image factory to use in generating the images.
@param[in] binSize: Binning factor
@param[in] inCameraCoords: Show the Detector in camera coordinates?

Definition at line 371 of file utils.py.

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

Variable Documentation

lsst.afw.cameraGeom.utils.display = False

Definition at line 49 of file utils.py.