LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | Private Member Functions | List of all members
lsst.afw.cameraGeom.fitsUtils.DetectorBuilder Class Reference
Inheritance diagram for lsst.afw.cameraGeom.fitsUtils.DetectorBuilder:

Public Member Functions

def __init__
 
def buildDetector
 
def makeCalib
 
def makeExposure
 

Public Attributes

 inAmpCoords
 
 defaultAmpMap
 
 defaultDetectorMap
 
 detectorMetadata
 
 ampMetadataList
 
 detector
 
 doRaise
 
 plateScale
 
 focalPlaneToPupil
 

Private Member Functions

def _sanitizeHeaderMetadata
 
def _defaultSanitization
 
def _makeDefaultAmpMap
 
def _makeDefaultDetectorMap
 
def _makeExt
 
def _makeBbox
 
def _getBboxX0
 
def _getBboxX1
 
def _getBboxY0
 
def _getBboxY1
 
def _makeRadialTransform
 

Detailed Description

Definition at line 85 of file fitsUtils.py.

Constructor & Destructor Documentation

def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder.__init__ (   self,
  detectorFileName,
  ampFileNameList,
  inAmpCoords = True,
  plateScale = 1.,
  radialCoeffs = (0., 1.,
  clobberMetadata = False,
  doRaise = True 
)
@param[in] detectorFileName  FITS file containing the detector description. 
                         May use [] notation to specify an extension in an MEF.
    @param[in] ampFileNameList   List of FITS file names to use in building the amps.
                         May contain duplicate entries if the raw data are assembled.
    @param[in] inAmpCoords       Boolean, True if raw data are in amp coordinates, False if raw data
                         are assembled into pseudo detector pixel arrays
    @param[in] plateScale        Nominal platescale (arcsec/mm)
    @param[in] radialCoeffs      Radial distortion coefficients for a radial polynomial in normalized
                         units.
    @param[in] clobberMetadata   Clobber metadata from input files if overridden in the _sanitizeMetadata method
    @param[in] doRaise           Raise exception if not all non-defaulted keywords are defined?  Default is True.

Definition at line 87 of file fitsUtils.py.

87 
88  radialCoeffs=(0., 1.), clobberMetadata=False, doRaise=True):
89  ''' @param[in] detectorFileName FITS file containing the detector description.
90  May use [] notation to specify an extension in an MEF.
91  @param[in] ampFileNameList List of FITS file names to use in building the amps.
92  May contain duplicate entries if the raw data are assembled.
93  @param[in] inAmpCoords Boolean, True if raw data are in amp coordinates, False if raw data
94  are assembled into pseudo detector pixel arrays
95  @param[in] plateScale Nominal platescale (arcsec/mm)
96  @param[in] radialCoeffs Radial distortion coefficients for a radial polynomial in normalized
97  units.
98  @param[in] clobberMetadata Clobber metadata from input files if overridden in the _sanitizeMetadata method
99  @param[in] doRaise Raise exception if not all non-defaulted keywords are defined? Default is True.
100  '''
101  self.inAmpCoords = inAmpCoords
104  self.detectorMetadata = afwImage.readMetadata(detectorFileName)
105  self._sanitizeHeaderMetadata(self.detectorMetadata, clobber=clobberMetadata)
106  self.ampMetadataList = []
107  self.detector = None
108  self.doRaise = doRaise
109  for fileName in ampFileNameList:
110  self.ampMetadataList.append(afwImage.readMetadata(fileName))
111  self._sanitizeHeaderMetadata(self.ampMetadataList[-1], clobber=clobberMetadata)
112  self.plateScale = plateScale
113  self.focalPlaneToPupil = self._makeRadialTransform(radialCoeffs)
boost::shared_ptr< daf::base::PropertySet > readMetadata(std::string const &fileName, int hdu=0, bool strip=false)
Return the metadata (header entries) from a FITS file.

Member Function Documentation

def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder._defaultSanitization (   self,
  metadata,
  clobber 
)
private
Does the default sanitization of the header metadata.
   @param[in,out] metadata  Header metadata to extend/modify
   @param[in]     clobber   Override values in existing header cards?

Definition at line 123 of file fitsUtils.py.

124  def _defaultSanitization(self, metadata, clobber):
125  """Does the default sanitization of the header metadata.
126  @param[in,out] metadata Header metadata to extend/modify
127  @param[in] clobber Override values in existing header cards?
128  """
129 
130  if self.inAmpCoords:
131  #Deal with DTM to get flipX and flipY for assembly and add as 'FLIPX', 'FLIPY'
132  #The DTM array is a transformation matrix. As I understand it, it transforms between
133  #electronic and assembled coordintates. As such, a negative value in the DTM1_1 spot
134  #corresponds to a flip of the x-axis and a negative value in the DTM2_2 spot
135  #corresponds to a flip of the y-axis.
136  dtm1 = getByKey(metadata, 'DTM1_1')
137  dtm2 = getByKey(metadata, 'DTM2_2')
138  if dtm1 is not None and dtm2 is not None:
139  setByKey(metadata, 'FLIPX', dtm1 < 0, clobber)
140  setByKey(metadata, 'FLIPY', dtm2 < 0, clobber)
141  setByKey(metadata, 'RDCRNR', afwTable.LL, clobber)
142  else:
143  setByKey(metadata, 'FLIPX', False, clobber)
144  setByKey(metadata, 'FLIPY', True, clobber)
145  #I don't know how to figure out the read corner if already assembled
146  setByKey(metadata, 'RDCRNR', None, clobber)
147 
148  #Deal with NAXIS1, NAXIS2 to make rawBBox as 'RAWBBOX'
149  xext = getByKey(metadata, 'NAXIS1')
150  yext = getByKey(metadata, 'NAXIS2')
151  if xext is not None and yext is not None:
152  setByKey(metadata, 'RAWBBOX', '[%i:%i,%i:%i]'%(1, xext, 1, yext), clobber)
153  #Deal with DTV1, DTV2 to make 'XYOFF
154  dtv1 = getByKey(metadata, 'DTV1')
155  dtv2 = getByKey(metadata, 'DTV2')
156  if dtv1 is not None and dtv2 is not None:
157  setByKey(metadata, 'XYOFF', [dtv1, dtv2], clobber)
158  #map biassec[1] to HOSCAN
159  #map biassec[3] to VOSCAN
160  #map biassec[2] to PRESCAN
161  if metadata.isArray('BIASSEC'):
162  keylist = ['HOSCAN', 'PRESCAN', 'VOSCAN']
163  biassecs = getByKey(metadata, 'BIASSEC')
164  for i, biassec in enumerate(biassecs):
165  setByKey(metadata, keylist[i], biassec, clobber)
166  else:
167  biassec = getByKey(metadata, 'BIASSEC')
168  if biassec is not None:
169  setByKey(metadata, 'HOSCAN', biassec, clobber)
def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder._getBboxX0 (   self,
  boxString 
)
private

Definition at line 246 of file fitsUtils.py.

247  def _getBboxX0(self, boxString):
248  return self._makeBbox(boxString).getMinX()
def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder._getBboxX1 (   self,
  boxString 
)
private

Definition at line 249 of file fitsUtils.py.

250  def _getBboxX1(self, boxString):
251  return self._makeBbox(boxString).getMaxX()
def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder._getBboxY0 (   self,
  boxString 
)
private

Definition at line 252 of file fitsUtils.py.

253  def _getBboxY0(self, boxString):
254  return self._makeBbox(boxString).getMinY()
def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder._getBboxY1 (   self,
  boxString 
)
private

Definition at line 255 of file fitsUtils.py.

256  def _getBboxY1(self, boxString):
257  return self._makeBbox(boxString).getMaxY()
def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder._makeBbox (   self,
  boxString 
)
private
Helper funtion to make a bounding box from a string representing a FITS style bounding box
   @param[in] boxString  String describing the bounding box
   @return    Box2I for the bounding box

Definition at line 232 of file fitsUtils.py.

233  def _makeBbox(self, boxString):
234  """Helper funtion to make a bounding box from a string representing a FITS style bounding box
235  @param[in] boxString String describing the bounding box
236  @return Box2I for the bounding box
237  """
238  #strip off brackets and split into parts
239  x1, x2, y1, y2 = [int(el) for el in re.split('[:,]', boxString.strip()[1:-1])]
240  box = afwGeom.BoxI(afwGeom.PointI(x1, y1), afwGeom.PointI(x2, y2))
241  #account for the difference between FITS convention and LSST convention for
242  #index of LLC.
243  box.shift(afwGeom.Extent2I(-1, -1))
244  return box
245 
An integer coordinate rectangle.
Definition: Box.h:53
def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder._makeDefaultAmpMap (   self)
private
Make the default map from header information to amplifier information
   @return  The HeaderAmpMap object containing the mapping

Definition at line 170 of file fitsUtils.py.

171  def _makeDefaultAmpMap(self):
172  """Make the default map from header information to amplifier information
173  @return The HeaderAmpMap object containing the mapping
174  """
175  hMap = HeaderAmpMap()
176  emptyBBox = afwGeom.BoxI()
177  mapList = [('EXTNAME', 'setName'),
178  ('DETSEC', 'setBBox', None, self._makeBbox),
179  ('GAIN', 'setGain', 1.),
180  ('RDNOISE', 'setReadNoise', 0.),
181  ('SATURATE', 'setSaturation', 2<<15),
182  ('RDCRNR', 'setReadoutCorner', afwTable.LL),
183  ('LINCOEFF', 'setLinearityCoeffs', [0., 1.]),
184  ('LINTYPE', 'setLinearityType', 'POLY'),
185  ('RAWBBOX', 'setRawBBox', None, self._makeBbox),
186  ('DATASEC', 'setRawDataBBox', None, self._makeBbox),
187  ('FLIPX', 'setRawFlipX', False),
188  ('FLIPY', 'setRawFlipY', False),
189  ('XYOFF', 'setRawXYOffset', afwGeom.ExtentI(0,0), self._makeExt),
190  ('HOSCAN', 'setRawHorizontalOverscanBBox', emptyBBox, self._makeBbox),
191  ('VOSCAN', 'setRawVerticalOverscanBBox', emptyBBox, self._makeBbox),
192  ('PRESCAN', 'setRawPrescanBBox', emptyBBox, self._makeBbox),
193  ]
194  for tup in mapList:
195  hMap.addEntry(*tup)
196  return hMap
An integer coordinate rectangle.
Definition: Box.h:53
def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder._makeDefaultDetectorMap (   self)
private
Make the default map from header information to detector information
   @return  The HeaderDetectorMap object containing the mapping

Definition at line 197 of file fitsUtils.py.

198  def _makeDefaultDetectorMap(self):
199  """Make the default map from header information to detector information
200  @return The HeaderDetectorMap object containing the mapping
201  """
202  hMap = HeaderDetectorMap()
203  mapList = [('CCDNAME', 'name', 'ccdName'),
204  ('DETSIZE', 'bbox_x0', 0, self._getBboxX0),
205  ('DETSIZE', 'bbox_y0', 0, self._getBboxY0),
206  ('DETSIZE', 'bbox_x1', 0, self._getBboxX1),
207  ('DETSIZE', 'bbox_y1', 0, self._getBboxY1),
208  ('DETID', 'id', 0),
209  ('OBSTYPE', 'detectorType', afwCameraGeom.SCIENCE),
210  ('SERSTR', 'serial', 'none'),
211  ('XPOS', 'offset_x', 0.),
212  ('YPOS', 'offset_y', 0.),
213  ('XPIX', 'refpos_x', 0.),
214  ('YPIX', 'refpos_y', 0.),
215  ('YAWDEG', 'yawDeg', 0.),
216  ('PITCHDEG', 'pitchDeg', 0.),
217  ('ROLLDEG', 'rollDeg', 0.),
218  ('XPIXSIZE', 'pixelSize_x', 1.),
219  ('YPIXSIZE', 'pixelSize_y', 1.),
220  ('TRNSPOSE', 'transposeDetector', False),
221  ]
222  for tup in mapList:
223  hMap.addEntry(*tup)
224  return hMap
def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder._makeExt (   self,
  extArr 
)
private
Helper function to make an extent from an array
   @param[in] extArr Length 2 array to use in creating the Extent object
   @return  Extent2I constructed from the input list

Definition at line 225 of file fitsUtils.py.

226  def _makeExt(self, extArr):
227  """Helper function to make an extent from an array
228  @param[in] extArr Length 2 array to use in creating the Extent object
229  @return Extent2I constructed from the input list
230  """
231  return afwGeom.ExtentI(*extArr)
def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder._makeRadialTransform (   self,
  radialCoeffs 
)
private
Helper function to get the radial transform given the radial polynomial coefficients given in
   the constructor.
   @param[in]  radialCoeffs  List of coefficients describing a polynomial radial distortion in
                     normalized units.
   @return     RadialXYTransform object describing the radial distortion

Definition at line 258 of file fitsUtils.py.

259  def _makeRadialTransform(self, radialCoeffs):
260  """Helper function to get the radial transform given the radial polynomial coefficients given in
261  the constructor.
262  @param[in] radialCoeffs List of coefficients describing a polynomial radial distortion in
263  normalized units.
264  @return RadialXYTransform object describing the radial distortion
265  """
266  pScaleRad = afwGeom.arcsecToRad(self.plateScale)
267  return afwGeom.RadialXYTransform([el/pScaleRad for el in radialCoeffs])
A purely radial polynomial distortion, up to 6th order.
Definition: XYTransform.h:186
double arcsecToRad(double x)
Definition: Angle.h:41
def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder._sanitizeHeaderMetadata (   self,
  metadata,
  clobber 
)
private
This method is called for all metadata and gives an opportunity to add/modify
   header information for use downstream.
   Override this method if more than the default is needed.
   @param[in, out] metadata  Metadata to read/modify
   @param[in]      clobber   Clobber keys that exist with default keys?

Definition at line 114 of file fitsUtils.py.

115  def _sanitizeHeaderMetadata(self, metadata, clobber):
116  """This method is called for all metadata and gives an opportunity to add/modify
117  header information for use downstream.
118  Override this method if more than the default is needed.
119  @param[in, out] metadata Metadata to read/modify
120  @param[in] clobber Clobber keys that exist with default keys?
121  """
122  self._defaultSanitization(metadata, clobber)
def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder.buildDetector (   self)
Take all the information and build a Detector object.  The Detector object is necessary for doing
things like assembly.
@return  Detector object

Definition at line 268 of file fitsUtils.py.

269  def buildDetector(self):
270  """Take all the information and build a Detector object. The Detector object is necessary for doing
271  things like assembly.
272  @return Detector object
273  """
274  if self.detector is not None:
275  return self.detector
276 
277  schema = afwTable.AmpInfoTable.makeMinimalSchema()
278  ampInfo = afwTable.AmpInfoCatalog(schema)
279  for ampMetadata in self.ampMetadataList:
280  record = ampInfo.addNew()
281  self.defaultAmpMap.setAttributes(record, ampMetadata, self.doRaise)
282  record.setHasRawInfo(True)
283 
284  detConfig = afwCameraGeom.DetectorConfig()
285  self.defaultDetectorMap.setAttributes(detConfig, self.detectorMetadata, self.doRaise)
286  self.detector = afwCameraGeom.makeDetector(detConfig, ampInfo, self.focalPlaneToPupil,
287  self.plateScale)
288  return self.detector
A custom container class for records, based on std::vector.
Definition: Catalog.h:94
def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder.makeCalib (   self)
PLaceholder for subclasses to implement construction of a calib to associate with the exposure.
@return empty afwImage.Calib object

Definition at line 289 of file fitsUtils.py.

290  def makeCalib(self):
291  """PLaceholder for subclasses to implement construction of a calib to associate with the exposure.
292  @return empty afwImage.Calib object
293  """
294  return afwImage.Calib()
def lsst.afw.cameraGeom.fitsUtils.DetectorBuilder.makeExposure (   self,
  im,
  mask = None,
  variance = None 
)
Method for constructing an exposure object from an image and the information contained in this
   class to construct the Detector and Calib objects.
   @param[in]  im        Image used to construct the exposure
   @param[in]  mask      Optional mask plane as a <askU
   @param[in]  variance  Optional variance plance as an image of the same type as im
   @param[out] Exposure object

Definition at line 295 of file fitsUtils.py.

296  def makeExposure(self, im, mask=None, variance=None):
297  """Method for constructing an exposure object from an image and the information contained in this
298  class to construct the Detector and Calib objects.
299  @param[in] im Image used to construct the exposure
300  @param[in] mask Optional mask plane as a <askU
301  @param[in] variance Optional variance plance as an image of the same type as im
302  @param[out] Exposure object
303  """
304  if mask is None:
305  mask = afwImage.MaskU(im.getDimensions())
306  if variance is None:
307  variance = im
308  mi = afwImage.makeMaskedImage(im, mask, variance)
309  detector = self.buildDetector()
310 
312  calib = self.makeCalib()
313  exp = afwImage.makeExposure(mi, wcs)
314  exp.setCalib(calib)
315  exp.setDetector(detector)
316  return exp
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > * makeMaskedImage(typename Image< ImagePixelT >::Ptr image, typename Mask< MaskPixelT >::Ptr mask=typename Mask< MaskPixelT >::Ptr(), typename Image< VariancePixelT >::Ptr variance=typename Image< VariancePixelT >::Ptr())
Definition: MaskedImage.h:1067
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
Exposure< ImagePixelT, MaskPixelT, VariancePixelT >::Ptr makeExposure(MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > &mimage, boost::shared_ptr< Wcs const > wcs=boost::shared_ptr< Wcs const >())
Definition: Exposure.h:308

Member Data Documentation

lsst.afw.cameraGeom.fitsUtils.DetectorBuilder.ampMetadataList

Definition at line 105 of file fitsUtils.py.

lsst.afw.cameraGeom.fitsUtils.DetectorBuilder.defaultAmpMap

Definition at line 101 of file fitsUtils.py.

lsst.afw.cameraGeom.fitsUtils.DetectorBuilder.defaultDetectorMap

Definition at line 102 of file fitsUtils.py.

lsst.afw.cameraGeom.fitsUtils.DetectorBuilder.detector

Definition at line 106 of file fitsUtils.py.

lsst.afw.cameraGeom.fitsUtils.DetectorBuilder.detectorMetadata

Definition at line 103 of file fitsUtils.py.

lsst.afw.cameraGeom.fitsUtils.DetectorBuilder.doRaise

Definition at line 107 of file fitsUtils.py.

lsst.afw.cameraGeom.fitsUtils.DetectorBuilder.focalPlaneToPupil

Definition at line 112 of file fitsUtils.py.

lsst.afw.cameraGeom.fitsUtils.DetectorBuilder.inAmpCoords

Definition at line 100 of file fitsUtils.py.

lsst.afw.cameraGeom.fitsUtils.DetectorBuilder.plateScale

Definition at line 111 of file fitsUtils.py.


The documentation for this class was generated from the following file: