22 __all__ = [
"DetectorWrapper",
"CameraWrapper"]
33 from .cameraGeomLib
import PIXELS, TAN_PIXELS, FIELD_ANGLE, FOCAL_PLANE, SCIENCE, ACTUAL_PIXELS, \
34 CameraSys, Detector, Orientation
35 from .cameraConfig
import DetectorConfig, CameraConfig
36 from .cameraFactory
import makeCameraFromCatalogs
37 from .makePixelToTanPixel
import makePixelToTanPixel
38 from .transformConfig
import TransformMapConfig
42 """A Detector and the data used to construct it 44 Intended for use with unit tests, thus saves a copy of all input parameters. 45 Does not support setting details of amplifiers. 49 name : `str` (optional) 53 detType : `lsst.afw.cameraGeom.DetectorType` (optional) 55 serial : `str` (optional) 57 bbox : `lsst.geom.Box2I` (optional) 58 Bounding box; defaults to (0, 0), (1024x1024). 59 numAmps : `int` (optional) 61 pixelSize : `lsst.geom.Point2D` (optional) 63 ampExtent : `lsst.geom.Extent2I` (optional) 64 Dimensions of amplifier image bbox. 65 orientation : `lsst.afw.cameraGeom.Orientation` (optional) 66 Orientation of CCC in focal plane. 67 plateScale : `float` (optional) 68 Plate scale in arcsec/mm; 20.0 is for LSST. 69 radialDistortion : `float` (optional) 70 Radial distortion, in mm/rad^2. 71 The r^3 coefficient of the radial distortion polynomial 72 that converts FIELD_ANGLE in radians to FOCAL_PLANE in mm; 73 0.925 is the value Dave Monet measured for lsstSim data 74 crosstalk : `iterable` (optional) 75 Crosstalk coefficient matrix. If None, then no crosstalk correction 77 modFunc : `callable` (optional) 78 A function that can modify attributes just before constructing the 79 detector; modFunc receives one argument: a DetectorWrapper with all 80 attributes except detector set. 90 pixelSize=(0.02, 0.02),
94 radialDistortion=0.925,
111 schema = afwTable.AmpInfoTable.makeMinimalSchema()
112 self.
ampInfo = afwTable.AmpInfoCatalog(schema)
113 for i
in range(numAmps):
115 ampName =
"amp %d" % (i + 1,)
116 record.setName(ampName)
118 record.setGain(1.71234e3)
119 record.setReadNoise(0.521237e2)
120 record.setReadoutCorner(afwTable.LL)
121 record.setHasRawInfo(
False)
126 radialDistortCoeffs = [0.0, 1.0/pScaleRad,
128 focalPlaneToField = afwGeom.makeRadialTransform(radialDistortCoeffs)
132 focalPlaneToField=focalPlaneToField,
139 CameraSys(ACTUAL_PIXELS, self.
name): afwGeom.makeRadialTransform([0, 0.95, 0.01]),
141 if crosstalk
is None:
142 crosstalk = [[0.0
for _
in range(numAmps)]
for _
in range(numAmps)]
156 np.array(self.
crosstalk, dtype=np.float32),
161 """A simple Camera and the data used to construct it 163 Intended for use with unit tests, thus saves some interesting information. 168 Plate scale in arcsec/mm; 20.0 is for LSST. 169 radialDistortion : `float` 170 Radial distortion, in mm/rad^2. 171 The r^3 coefficient of the radial distortion polynomial 172 that converts FIELD_ANGLE in radians to FOCAL_PLANE in mm; 173 0.925 is the value Dave Monet measured for lsstSim data. 175 Make repository products with one raw image per amplifier (True) 176 or with one raw image per detector (False). 179 def __init__(self, plateScale=20.0, radialDistortion=0.925, isLsstLike=False):
182 "cameraGeom",
"testData")
198 """Return the number of detectors""" 202 """Construct a list of DetectorConfig, one per detector 207 with open(detFile)
as fh:
208 names = fh.readline().rstrip().lstrip(
"#").split(
"|")
210 els = l.rstrip().split(
"|")
211 detectorProps = dict([(name, el)
212 for name, el
in zip(names, els)])
213 detectors.append(detectorProps)
215 for i, detector
in enumerate(detectors):
216 detectorId = (i + 1) * 10
217 detectorName = detector[
'name']
219 detConfig.name = detectorName
220 detConfig.id = detectorId
221 detConfig.bbox_x0 = 0
222 detConfig.bbox_y0 = 0
223 detConfig.bbox_x1 = int(detector[
'npix_x']) - 1
224 detConfig.bbox_y1 = int(detector[
'npix_y']) - 1
225 detConfig.serial = str(detector[
'serial'])
226 detConfig.detectorType = int(detector[
'detectorType'])
227 detConfig.offset_x = float(detector[
'x'])
228 detConfig.offset_y = float(detector[
'y'])
229 detConfig.refpos_x = float(detector[
'refPixPos_x'])
230 detConfig.refpos_y = float(detector[
'refPixPos_y'])
231 detConfig.yawDeg = float(detector[
'yaw'])
232 detConfig.pitchDeg = float(detector[
'pitch'])
233 detConfig.rollDeg = float(detector[
'roll'])
234 detConfig.pixelSize_x = float(detector[
'pixelSize'])
235 detConfig.pixelSize_y = float(detector[
'pixelSize'])
236 detConfig.transposeDetector =
False 237 detConfig.transformDict.nativeSys = PIXELS.getSysName()
238 detectorConfigs.append(detConfig)
241 return detectorConfigs
244 """Construct a dict of AmpInfoCatalog, one per detector. 249 Path to amplifier data file. 251 If True then there is one raw image per amplifier; 252 if False then there is one raw image per detector. 255 'LL': afwTable.ReadoutCorner.LL,
256 'LR': afwTable.ReadoutCorner.LR,
257 'UR': afwTable.ReadoutCorner.UR, 258 'UL': afwTable.ReadoutCorner.UL,
261 with open(ampFile)
as fh:
262 names = fh.readline().rstrip().lstrip(
"#").split(
"|")
264 els = l.rstrip().split(
"|")
265 ampProps = dict([(name, el)
for name, el
in zip(names, els)])
266 amps.append(ampProps)
268 schema = afwTable.AmpInfoTable.makeMinimalSchema()
269 linThreshKey = schema.addField(
'linearityThreshold', type=np.float64)
270 linMaxKey = schema.addField(
'linearityMaximum', type=np.float64)
271 linUnitsKey = schema.addField(
'linearityUnits', type=str, size=9)
274 if amp[
'ccd_name']
in ampTablesDict:
275 ampCatalog = ampTablesDict[amp[
'ccd_name']]
278 ampCatalog = afwTable.AmpInfoCatalog(schema)
279 ampTablesDict[amp[
'ccd_name']] = ampCatalog
280 self.
ampInfoDict[amp[
'ccd_name']] = {
'namps': 1,
'linInfo': {}}
281 record = ampCatalog.addNew()
283 int(amp[
'trimmed_ymin'])),
285 int(amp[
'trimmed_ymax'])))
287 int(amp[
'raw_ymin'])),
289 int(amp[
'raw_ymax'])))
292 int(amp[
'raw_data_ymin'])),
294 int(amp[
'raw_data_ymax'])))
297 int(amp[
'hoscan_ymin'])),
299 int(amp[
'hoscan_ymax'])))
302 int(amp[
'voscan_ymin'])),
304 int(amp[
'voscan_ymax'])))
307 int(amp[
'pscan_ymin'])),
309 int(amp[
'pscan_ymax'])))
310 xoffset = int(amp[
'x_offset'])
311 yoffset = int(amp[
'y_offset'])
312 flipx = bool(int(amp[
'flipx']))
313 flipy = bool(int(amp[
'flipy']))
318 xExt = rawBbox.getDimensions().getX()
320 rawDataBbox.flipLR(xExt)
321 rawHOverscanBbox.flipLR(xExt)
322 rawVOverscanBbox.flipLR(xExt)
323 rawPrescanBbox.flipLR(xExt)
325 yExt = rawBbox.getDimensions().getY()
327 rawDataBbox.flipTB(yExt)
328 rawHOverscanBbox.flipTB(yExt)
329 rawVOverscanBbox.flipTB(yExt)
330 rawPrescanBbox.flipTB(yExt)
331 if not flipx
and not flipy:
333 elif flipx
and not flipy:
335 elif flipx
and flipy:
337 elif not flipx
and flipy:
340 raise RuntimeError(
"Couldn't find read corner")
344 rawBbox.shift(offext)
345 rawDataBbox.shift(offext)
346 rawHOverscanBbox.shift(offext)
347 rawVOverscanBbox.shift(offext)
348 rawPrescanBbox.shift(offext)
353 record.setRawXYOffset(offset)
354 record.setName(str(amp[
'name']))
355 record.setReadoutCorner(readoutMap[readcorner])
356 record.setGain(float(amp[
'gain']))
357 record.setReadNoise(float(amp[
'readnoise']))
358 record.setLinearityCoeffs([float(amp[
'lin_coeffs']), ])
359 record.setLinearityType(str(amp[
'lin_type']))
360 record.setHasRawInfo(
True)
361 record.setRawFlipX(flipx)
362 record.setRawFlipY(flipy)
363 record.setRawBBox(rawBbox)
364 record.setRawDataBBox(rawDataBbox)
365 record.setRawHorizontalOverscanBBox(rawHOverscanBbox)
366 record.setRawVerticalOverscanBBox(rawVOverscanBbox)
367 record.setRawPrescanBBox(rawPrescanBbox)
368 record.set(linThreshKey, float(amp[
'lin_thresh']))
369 record.set(linMaxKey, float(amp[
'lin_max']))
370 record.set(linUnitsKey, str(amp[
'lin_units']))
372 saveCoeffs = (float(amp[
'lin_coeffs']),)
373 saveCoeffs += (np.nan, np.nan, np.nan)
374 self.
ampInfoDict[amp[
'ccd_name']][
'linInfo'][amp[
'name']] = \
375 {
'lincoeffs': saveCoeffs,
'lintype': str(amp[
'lin_type']),
376 'linthresh': float(amp[
'lin_thresh']),
'linmax': float(amp[
'lin_max']),
377 'linunits': str(amp[
'lin_units'])}
381 """Make camera config and amp catalog dictionary, using default 382 detector and amp files. 387 If True then there is one raw image per amplifier; 388 if False then there is one raw image per detector. 390 detFile = os.path.join(self.
_afwTestDataDir,
"testCameraDetectors.dat")
395 camConfig.name =
"testCamera%s"%(
'LSST' if isLsstLike
else 'SC')
396 camConfig.detectorList = dict((i, detConfig)
397 for i, detConfig
in enumerate(detectorConfigs))
400 radialDistortCoeffs = [0.0, 1.0/pScaleRad,
402 tConfig = afwGeom.TransformConfig()
403 tConfig.transform.name =
'inverted' 404 radialClass = afwGeom.transformRegistry[
'radial']
405 tConfig.transform.active.transform.retarget(radialClass)
406 tConfig.transform.active.transform.coeffs = radialDistortCoeffs
408 tmc.nativeSys = FOCAL_PLANE.getSysName()
409 tmc.transforms = {FIELD_ANGLE.getSysName(): tConfig}
410 camConfig.transformDict = tmc
411 return camConfig, ampCatalogDict
416 """Compare two Point2D(Point2D) functions by evaluating them over a 421 dVal = (maxVal - minVal) / (nVal - 1)
422 for xInd
in range(nVal):
423 x = minVal + (xInd * dVal)
424 for yInd
in range(nVal):
425 y = minVal + (yInd * dVal)
427 res1 = func1(fromPoint)
428 res2 = func2(fromPoint)
429 self.assertPairsAlmostEqual(res1, res2)
434 """Compare two TransformMaps. 436 self.assertEqual(
list(map1),
list(map2))
439 with self.subTest(sysFrom=sysFrom, sysTo=sysTo):
440 transform1 = map1.getTransform(sysFrom, sysTo)
441 transform2 = map2.getTransform(sysFrom, sysTo)
442 self.compare2DFunctions(transform1.applyForward, transform2.applyForward, **kwds)
443 self.compare2DFunctions(transform1.applyInverse, transform2.applyInverse, **kwds)
448 """Compare two Detectors. 450 self.assertEqual(detector1.getName(), detector2.getName())
451 self.assertEqual(detector1.getId(), detector2.getId())
452 self.assertEqual(detector1.getSerial(), detector2.getSerial())
453 self.assertEqual(detector1.getBBox(), detector2.getBBox())
454 self.assertEqual(detector1.getPixelSize(), detector2.getPixelSize())
455 orientationIn = detector1.getOrientation()
456 orientationOut = detector2.getOrientation()
457 self.assertEqual(orientationIn.getFpPosition(), orientationOut.getFpPosition())
458 self.assertEqual(orientationIn.getReferencePoint(), orientationOut.getReferencePoint())
459 self.assertEqual(orientationIn.getYaw(), orientationOut.getYaw())
460 self.assertEqual(orientationIn.getPitch(), orientationOut.getPitch())
461 self.assertEqual(orientationIn.getRoll(), orientationOut.getRoll())
462 self.assertFloatsEqual(detector1.getCrosstalk(), detector2.getCrosstalk())
463 self.assertTransformMapsEqual(detector1.getTransformMap(), detector2.getTransformMap(), **kwds)
468 """Compare two DetectorCollections. 470 self.assertCountEqual(
list(collection1.getNameIter()),
list(collection2.getNameIter()))
471 for k
in collection1.getNameIter():
472 self.assertDetectorsEqual(collection1[k], collection2[k], **kwds)
477 """Compare two Camers. 479 self.assertDetectorCollectionsEqual(camera1, camera2, **kwds)
480 self.assertTransformMapsEqual(camera1.getTransformMap(), camera2.getTransformMap())
481 self.assertEqual(camera1.getName(), camera2.getName())
482 self.assertEqual(camera1.getPupilFactoryName(), camera2.getPupilFactoryName())
def assertDetectorCollectionsEqual(self, collection1, collection2, kwds)
Camera coordinate system; used as a key in in TransformMap.
def makeTestRepositoryItems(self, isLsstLike=False)
def makeCameraFromCatalogs(cameraConfig, ampInfoCatDict, pupilFactoryClass=PupilFactory)
def __init__(self, name="detector 1", id=1, detType=SCIENCE, serial="xkcd722", bbox=None, numAmps=3, pixelSize=(0.02, 0.02), ampExtent=(5, 6), orientation=Orientation(), plateScale=20.0, radialDistortion=0.925, crosstalk=None, modFunc=None)
def assertDetectorsEqual(self, detector1, detector2, kwds)
def assertTransformMapsEqual(self, map1, map2, kwds)
Describe a detector's orientation in the focal plane.
std::string getPackageDir(std::string const &packageName)
def assertCamerasEqual(self, camera1, camera2, kwds)
def makeAmpCatalogs(self, ampFile, isLsstLike=False)
def compare2DFunctions(self, func1, func2, minVal=-10, maxVal=None, nVal=5)
Information about a CCD or other imaging detector.
def makePixelToTanPixel(bbox, orientation, focalPlaneToField, pixelSizeMm)
daf::base::PropertyList * list
constexpr double arcsecToRad(double x) noexcept
def makeDetectorConfigs(self, detFile)
def __init__(self, plateScale=20.0, radialDistortion=0.925, isLsstLike=False)