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 Attributes | List of all members
lsst.afw.cameraGeom.testUtils.CameraWrapper Class Reference
Inheritance diagram for lsst.afw.cameraGeom.testUtils.CameraWrapper:

Public Member Functions

def __init__
 Construct a CameraWrapper. More...
 
def nDetectors
 Return the number of detectors. More...
 
def makeDetectorConfigs
 Construct a list of DetectorConfig, one per detector. More...
 
def makeAmpCatalogs
 Construct a list of AmpInfoCatalog, one per detector. More...
 
def makeTestRepositoryItems
 Make camera config and amp catalog dictionary, using default detector and amp files. More...
 

Public Attributes

 plateScale
 
 radialDistortion
 
 detectorNameList
 
 detectorIdList
 
 ampInfoDict
 
 ampCatalogDict
 
 camera
 

Private Attributes

 _afwTestDir
 

Detailed Description

A simple Camera and the data used to construct it

Intended for use with unit tests, thus saves some interesting information.

Definition at line 112 of file testUtils.py.

Constructor & Destructor Documentation

def lsst.afw.cameraGeom.testUtils.CameraWrapper.__init__ (   self,
  plateScale = 20.0,
  radialDistortion = 0.925,
  isLsstLike = False 
)

Construct a CameraWrapper.

Parameters
[in]plateScaleplate scale in arcsec/mm; 20.0 is for LSST
[in]radialDistortionradial distortion, in mm/rad^2 (the r^3 coefficient of the radial distortion polynomial that converts PUPIL in radians to FOCAL_PLANE in mm); 0.925 is the value Dave Monet measured for lsstSim data
[in]isLsstLikemake repository products with one raw image per amplifier (True) or with one raw image per detector (False)

Definition at line 117 of file testUtils.py.

118  def __init__(self, plateScale=20.0, radialDistortion=0.925, isLsstLike=False):
119  """!Construct a CameraWrapper
120 
121  @param[in] plateScale plate scale in arcsec/mm; 20.0 is for LSST
122  @param[in] radialDistortion radial distortion, in mm/rad^2
123  (the r^3 coefficient of the radial distortion polynomial
124  that converts PUPIL in radians to FOCAL_PLANE in mm);
125  0.925 is the value Dave Monet measured for lsstSim data
126  @param[in] isLsstLike make repository products with one raw image per amplifier (True)
127  or with one raw image per detector (False)
128  """
129  afwDir = lsst.utils.getPackageDir("afw")
130  self._afwTestDir = os.path.join(afwDir, "tests")
131 
132  # Info to store for unit tests
133  self.plateScale = float(plateScale)
134  self.radialDistortion = float(radialDistortion)
136  self.detectorIdList = []
137  self.ampInfoDict = {}
139  self.camConfig, self.ampCatalogDict = self.makeTestRepositoryItems(isLsstLike)
140  self.camera = makeCameraFromCatalogs(self.camConfig, self.ampCatalogDict)
def __init__
Construct a CameraWrapper.
Definition: testUtils.py:117
def makeTestRepositoryItems
Make camera config and amp catalog dictionary, using default detector and amp files.
Definition: testUtils.py:299
std::string getPackageDir(std::string const &packageName)
return the root directory of a setup package
Definition: Utils.cc:66
def makeCameraFromCatalogs
Construct a Camera instance from a dictionary of detector name: AmpInfoCatalog.

Member Function Documentation

def lsst.afw.cameraGeom.testUtils.CameraWrapper.makeAmpCatalogs (   self,
  ampFile,
  isLsstLike = False 
)

Construct a list of AmpInfoCatalog, one per detector.

Parameters
[in]ampFilepath to amplifier data file
[in]isLsstLikeif True then there is one raw image per amplifier; if False then there is one raw image per detector

Definition at line 187 of file testUtils.py.

188  def makeAmpCatalogs(self, ampFile, isLsstLike=False):
189  """!Construct a list of AmpInfoCatalog, one per detector
190 
191  @param[in] ampFile path to amplifier data file
192  @param[in] isLsstLike if True then there is one raw image per amplifier;
193  if False then there is one raw image per detector
194  """
195  readoutMap = {'LL':0, 'LR':1, 'UR':2, 'UL':3}
196  amps = []
197  with open(ampFile) as fh:
198  names = fh.readline().rstrip().lstrip("#").split("|")
199  for l in fh:
200  els = l.rstrip().split("|")
201  ampProps = dict([(name, el) for name, el in zip(names, els)])
202  amps.append(ampProps)
203  ampTablesDict = {}
204  schema = afwTable.AmpInfoTable.makeMinimalSchema()
205  linThreshKey = schema.addField('linearityThreshold', type=float)
206  linMaxKey = schema.addField('linearityMaximum', type=float)
207  linUnitsKey = schema.addField('linearityUnits', type=str, size=9)
208  self.ampInfoDict = {}
209  for amp in amps:
210  if amp['ccd_name'] in ampTablesDict:
211  ampCatalog = ampTablesDict[amp['ccd_name']]
212  self.ampInfoDict[amp['ccd_name']]['namps'] += 1
213  else:
214  ampCatalog = afwTable.AmpInfoCatalog(schema)
215  ampTablesDict[amp['ccd_name']] = ampCatalog
216  self.ampInfoDict[amp['ccd_name']] = {'namps':1, 'linInfo':{}}
217  record = ampCatalog.addNew()
218  bbox = afwGeom.Box2I(afwGeom.Point2I(int(amp['trimmed_xmin']), int(amp['trimmed_ymin'])),
219  afwGeom.Point2I(int(amp['trimmed_xmax']), int(amp['trimmed_ymax'])))
220  rawBbox = afwGeom.Box2I(afwGeom.Point2I(int(amp['raw_xmin']), int(amp['raw_ymin'])),
221  afwGeom.Point2I(int(amp['raw_xmax']), int(amp['raw_ymax'])))
222  rawDataBbox = afwGeom.Box2I(afwGeom.Point2I(int(amp['raw_data_xmin']), int(amp['raw_data_ymin'])),
223  afwGeom.Point2I(int(amp['raw_data_xmax']), int(amp['raw_data_ymax'])))
224  rawHOverscanBbox = afwGeom.Box2I(afwGeom.Point2I(int(amp['hoscan_xmin']), int(amp['hoscan_ymin'])),
225  afwGeom.Point2I(int(amp['hoscan_xmax']), int(amp['hoscan_ymax'])))
226  rawVOverscanBbox = afwGeom.Box2I(afwGeom.Point2I(int(amp['voscan_xmin']), int(amp['voscan_ymin'])),
227  afwGeom.Point2I(int(amp['voscan_xmax']), int(amp['voscan_ymax'])))
228  rawPrescanBbox = afwGeom.Box2I(afwGeom.Point2I(int(amp['pscan_xmin']), int(amp['pscan_ymin'])),
229  afwGeom.Point2I(int(amp['pscan_xmax']), int(amp['pscan_ymax'])))
230  xoffset = int(amp['x_offset'])
231  yoffset = int(amp['y_offset'])
232  flipx = bool(int(amp['flipx']))
233  flipy = bool(int(amp['flipy']))
234  readcorner = 'LL'
235  if not isLsstLike:
236  offext = afwGeom.Extent2I(xoffset, yoffset)
237  if flipx:
238  xExt = rawBbox.getDimensions().getX()
239  rawBbox.flipLR(xExt)
240  rawDataBbox.flipLR(xExt)
241  rawHOverscanBbox.flipLR(xExt)
242  rawVOverscanBbox.flipLR(xExt)
243  rawPrescanBbox.flipLR(xExt)
244  if flipy:
245  yExt = rawBbox.getDimensions().getY()
246  rawBbox.flipTB(yExt)
247  rawDataBbox.flipTB(yExt)
248  rawHOverscanBbox.flipTB(yExt)
249  rawVOverscanBbox.flipTB(yExt)
250  rawPrescanBbox.flipTB(yExt)
251  if not flipx and not flipy:
252  readcorner = 'LL'
253  elif flipx and not flipy:
254  readcorner = 'LR'
255  elif flipx and flipy:
256  readcorner = 'UR'
257  elif not flipx and flipy:
258  readcorner = 'UL'
259  else:
260  raise RuntimeError("Couldn't find read corner")
261 
262  flipx = False
263  flipy = False
264  rawBbox.shift(offext)
265  rawDataBbox.shift(offext)
266  rawHOverscanBbox.shift(offext)
267  rawVOverscanBbox.shift(offext)
268  rawPrescanBbox.shift(offext)
269  xoffset = 0
270  yoffset = 0
271  offset = afwGeom.Extent2I(xoffset, yoffset)
272  record.setBBox(bbox)
273  record.setRawXYOffset(offset)
274  record.setName(str(amp['name']))
275  record.setReadoutCorner(readoutMap[readcorner])
276  record.setGain(float(amp['gain']))
277  record.setReadNoise(float(amp['readnoise']))
278  record.setLinearityCoeffs([float(amp['lin_coeffs']),])
279  record.setLinearityType(str(amp['lin_type']))
280  record.setHasRawInfo(True)
281  record.setRawFlipX(flipx)
282  record.setRawFlipY(flipy)
283  record.setRawBBox(rawBbox)
284  record.setRawDataBBox(rawDataBbox)
285  record.setRawHorizontalOverscanBBox(rawHOverscanBbox)
286  record.setRawVerticalOverscanBBox(rawVOverscanBbox)
287  record.setRawPrescanBBox(rawPrescanBbox)
288  record.set(linThreshKey, float(amp['lin_thresh']))
289  record.set(linMaxKey, float(amp['lin_max']))
290  record.set(linUnitsKey, str(amp['lin_units']))
291  #The current schema assumes third order coefficients
292  saveCoeffs = (float(amp['lin_coeffs']),)
293  saveCoeffs += (numpy.nan, numpy.nan, numpy.nan)
294  self.ampInfoDict[amp['ccd_name']]['linInfo'][amp['name']] = \
295  {'lincoeffs':saveCoeffs, 'lintype':str(amp['lin_type']),
296  'linthresh':float(amp['lin_thresh']), 'linmax':float(amp['lin_max']),
297  'linunits':str(amp['lin_units'])}
298  return ampTablesDict
A custom container class for records, based on std::vector.
Definition: Catalog.h:94
An integer coordinate rectangle.
Definition: Box.h:53
def makeAmpCatalogs
Construct a list of AmpInfoCatalog, one per detector.
Definition: testUtils.py:187
def lsst.afw.cameraGeom.testUtils.CameraWrapper.makeDetectorConfigs (   self,
  detFile 
)

Construct a list of DetectorConfig, one per detector.

Definition at line 146 of file testUtils.py.

147  def makeDetectorConfigs(self, detFile):
148  """!Construct a list of DetectorConfig, one per detector
149  """
150  detectors = []
151  self.detectorNameList = []
152  self.detectorIdList = []
153  with open(detFile) as fh:
154  names = fh.readline().rstrip().lstrip("#").split("|")
155  for l in fh:
156  els = l.rstrip().split("|")
157  detectorProps = dict([(name, el) for name, el in zip(names, els)])
158  detectors.append(detectorProps)
159  detectorConfigs = []
160  for i, detector in enumerate(detectors):
161  detectorId = (i + 1) * 10 # to avoid simple 0, 1, 2...
162  detectorName = detector['name']
163  detConfig = DetectorConfig()
164  detConfig.name = detectorName
165  detConfig.id = detectorId
166  detConfig.bbox_x0 = 0
167  detConfig.bbox_y0 = 0
168  detConfig.bbox_x1 = int(detector['npix_x']) - 1
169  detConfig.bbox_y1 = int(detector['npix_y']) - 1
170  detConfig.serial = str(detector['serial'])
171  detConfig.detectorType = int(detector['detectorType'])
172  detConfig.offset_x = float(detector['x'])
173  detConfig.offset_y = float(detector['y'])
174  detConfig.refpos_x = float(detector['refPixPos_x'])
175  detConfig.refpos_y = float(detector['refPixPos_y'])
176  detConfig.yawDeg = float(detector['yaw'])
177  detConfig.pitchDeg = float(detector['pitch'])
178  detConfig.rollDeg = float(detector['roll'])
179  detConfig.pixelSize_x = float(detector['pixelSize'])
180  detConfig.pixelSize_y = float(detector['pixelSize'])
181  detConfig.transposeDetector = False
182  detConfig.transformDict.nativeSys = PIXELS.getSysName()
183  detectorConfigs.append(detConfig)
184  self.detectorNameList.append(detectorName)
185  self.detectorIdList.append(detectorId)
186  return detectorConfigs
def makeDetectorConfigs
Construct a list of DetectorConfig, one per detector.
Definition: testUtils.py:146
def lsst.afw.cameraGeom.testUtils.CameraWrapper.makeTestRepositoryItems (   self,
  isLsstLike = False 
)

Make camera config and amp catalog dictionary, using default detector and amp files.

Parameters
[in]isLsstLikeif True then there is one raw image per amplifier; if False then there is one raw image per detector

Definition at line 299 of file testUtils.py.

300  def makeTestRepositoryItems(self, isLsstLike=False):
301  """!Make camera config and amp catalog dictionary, using default detector and amp files
302 
303  @param[in] isLsstLike if True then there is one raw image per amplifier;
304  if False then there is one raw image per detector
305  """
306  detFile = os.path.join(self._afwTestDir, "testCameraDetectors.dat")
307  detectorConfigs = self.makeDetectorConfigs(detFile)
308  ampFile = os.path.join(self._afwTestDir, "testCameraAmps.dat")
309  ampCatalogDict = self.makeAmpCatalogs(ampFile, isLsstLike=isLsstLike)
310  camConfig = CameraConfig()
311  camConfig.name = "testCamera%s"%('LSST' if isLsstLike else 'SC')
312  camConfig.detectorList = dict((i, detConfig) for i, detConfig in enumerate(detectorConfigs))
313  camConfig.plateScale = self.plateScale
314  pScaleRad = afwGeom.arcsecToRad(self.plateScale)
315  radialDistortCoeffs = [0.0, 1.0/pScaleRad, 0.0, self.radialDistortion/pScaleRad]
316  tConfig = afwGeom.TransformConfig()
317  tConfig.transform.name = 'inverted'
318  radialClass = afwGeom.xyTransformRegistry['radial']
319  tConfig.transform.active.transform.retarget(radialClass)
320  tConfig.transform.active.transform.coeffs = radialDistortCoeffs
321  tmc = afwGeom.TransformMapConfig()
322  tmc.nativeSys = FOCAL_PLANE.getSysName()
323  tmc.transforms = {PUPIL.getSysName():tConfig}
324  camConfig.transformDict = tmc
325  return camConfig, ampCatalogDict
def makeTestRepositoryItems
Make camera config and amp catalog dictionary, using default detector and amp files.
Definition: testUtils.py:299
def makeDetectorConfigs
Construct a list of DetectorConfig, one per detector.
Definition: testUtils.py:146
def makeAmpCatalogs
Construct a list of AmpInfoCatalog, one per detector.
Definition: testUtils.py:187
double arcsecToRad(double x)
Definition: Angle.h:41
def lsst.afw.cameraGeom.testUtils.CameraWrapper.nDetectors (   self)

Return the number of detectors.

Definition at line 142 of file testUtils.py.

143  def nDetectors(self):
144  """!Return the number of detectors"""
145  return len(self.detectorNameList)
def nDetectors
Return the number of detectors.
Definition: testUtils.py:142

Member Data Documentation

lsst.afw.cameraGeom.testUtils.CameraWrapper._afwTestDir
private

Definition at line 129 of file testUtils.py.

lsst.afw.cameraGeom.testUtils.CameraWrapper.ampCatalogDict

Definition at line 138 of file testUtils.py.

lsst.afw.cameraGeom.testUtils.CameraWrapper.ampInfoDict

Definition at line 136 of file testUtils.py.

lsst.afw.cameraGeom.testUtils.CameraWrapper.camera

Definition at line 139 of file testUtils.py.

lsst.afw.cameraGeom.testUtils.CameraWrapper.detectorIdList

Definition at line 135 of file testUtils.py.

lsst.afw.cameraGeom.testUtils.CameraWrapper.detectorNameList

Definition at line 134 of file testUtils.py.

lsst.afw.cameraGeom.testUtils.CameraWrapper.plateScale

Definition at line 132 of file testUtils.py.

lsst.afw.cameraGeom.testUtils.CameraWrapper.radialDistortion

Definition at line 133 of file testUtils.py.


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