1 from __future__
import absolute_import, division, print_function
2 from builtins
import str
3 from builtins
import zip
4 from builtins
import range
5 from builtins
import object
13 from .cameraGeomLib
import PIXELS, TAN_PIXELS, FIELD_ANGLE, FOCAL_PLANE, SCIENCE, ACTUAL_PIXELS, \
14 CameraSys, Detector, Orientation
15 from .cameraConfig
import DetectorConfig, CameraConfig
16 from .cameraFactory
import makeCameraFromCatalogs
17 from .makePixelToTanPixel
import makePixelToTanPixel
18 from .transformConfig
import TransformMapConfig
20 __all__ = [
"DetectorWrapper",
"CameraWrapper"]
24 """!A Detector and the data used to construct it
26 Intended for use with unit tests, thus saves a copy of all input parameters.
27 Does not support setting details of amplifiers.
37 pixelSize=(0.02, 0.02),
41 radialDistortion=0.925,
45 """!Construct a DetectorWrapper
47 @param[in] name detector name
48 @param[in] id detector ID (int)
49 @param[in] detType detector type (an lsst.afw.cameraGeom.DetectorType)
50 @param[in] serial serial "number" (a string)
51 @param[in] bbox bounding box; defaults to (0, 0), (1024x1024) (an lsst.afw.geom.Box2I)
52 @param[in] numAmps number of amplifiers (int)
53 @param[in] pixelSize pixel size (mm) (an lsst.afw.geom.Point2D)
54 @param[in] ampExtent dimensions of amplifier image bbox (an lsst.afw.geom.Extent2I)
55 @param[in] orientation orientation of CCC in focal plane (lsst.afw.cameraGeom.Orientation)
56 @param[in] plateScale plate scale in arcsec/mm; 20.0 is for LSST
57 @param[in] radialDistortion radial distortion, in mm/rad^2
58 (the r^3 coefficient of the radial distortion polynomial
59 that converts FIELD_ANGLE in radians to FOCAL_PLANE in mm);
60 0.925 is the value Dave Monet measured for lsstSim data
61 @param[in] crosstalk crosstalk coefficient matrix
62 @param[in] modFunc a function that can modify attributes just before constructing the detector;
63 modFunc receives one argument: a DetectorWrapper with all attributes except detector set.
79 schema = afwTable.AmpInfoTable.makeMinimalSchema()
80 self.
ampInfo = afwTable.AmpInfoCatalog(schema)
81 for i
in range(numAmps):
82 record = self.ampInfo.addNew()
83 ampName =
"amp %d" % (i + 1,)
84 record.setName(ampName)
87 record.setGain(1.71234e3)
88 record.setReadNoise(0.521237e2)
89 record.setReadoutCorner(afwTable.LL)
90 record.setHasRawInfo(
False)
95 radialDistortCoeffs = [0.0, 1.0/pScaleRad,
101 focalPlaneToField = focalPlaneToField,
106 FOCAL_PLANE: self.orientation.makePixelFpTransform(self.
pixelSize),
110 if crosstalk
is None:
111 crosstalk = [[0.0
for _
in range(numAmps)]
for _
in range(numAmps)]
125 np.array(self.
crosstalk, dtype=np.float32),
130 """A simple Camera and the data used to construct it
132 Intended for use with unit tests, thus saves some interesting information.
135 def __init__(self, plateScale=20.0, radialDistortion=0.925, isLsstLike=False):
136 """!Construct a CameraWrapper
138 @param[in] plateScale plate scale in arcsec/mm; 20.0 is for LSST
139 @param[in] radialDistortion radial distortion, in mm/rad^2
140 (the r^3 coefficient of the radial distortion polynomial
141 that converts FIELD_ANGLE in radians to FOCAL_PLANE in mm);
142 0.925 is the value Dave Monet measured for lsstSim data
143 @param[in] isLsstLike make repository products with one raw image per amplifier (True)
144 or with one raw image per detector (False)
146 afwDir = lsst.utils.getPackageDir(
"afw")
163 """!Return the number of detectors"""
167 """!Construct a list of DetectorConfig, one per detector
172 with open(detFile)
as fh:
173 names = fh.readline().rstrip().lstrip(
"#").split(
"|")
175 els = l.rstrip().split(
"|")
176 detectorProps = dict([(name, el)
177 for name, el
in zip(names, els)])
178 detectors.append(detectorProps)
180 for i, detector
in enumerate(detectors):
181 detectorId = (i + 1) * 10
182 detectorName = detector[
'name']
183 detConfig = DetectorConfig()
184 detConfig.name = detectorName
185 detConfig.id = detectorId
186 detConfig.bbox_x0 = 0
187 detConfig.bbox_y0 = 0
188 detConfig.bbox_x1 = int(detector[
'npix_x']) - 1
189 detConfig.bbox_y1 = int(detector[
'npix_y']) - 1
190 detConfig.serial = str(detector[
'serial'])
191 detConfig.detectorType = int(detector[
'detectorType'])
192 detConfig.offset_x = float(detector[
'x'])
193 detConfig.offset_y = float(detector[
'y'])
194 detConfig.refpos_x = float(detector[
'refPixPos_x'])
195 detConfig.refpos_y = float(detector[
'refPixPos_y'])
196 detConfig.yawDeg = float(detector[
'yaw'])
197 detConfig.pitchDeg = float(detector[
'pitch'])
198 detConfig.rollDeg = float(detector[
'roll'])
199 detConfig.pixelSize_x = float(detector[
'pixelSize'])
200 detConfig.pixelSize_y = float(detector[
'pixelSize'])
201 detConfig.transposeDetector =
False
202 detConfig.transformDict.nativeSys = PIXELS.getSysName()
203 detectorConfigs.append(detConfig)
204 self.detectorNameList.append(detectorName)
205 self.detectorIdList.append(detectorId)
206 return detectorConfigs
209 """!Construct a list of AmpInfoCatalog, one per detector
211 @param[in] ampFile path to amplifier data file
212 @param[in] isLsstLike if True then there is one raw image per amplifier;
213 if False then there is one raw image per detector
216 'LL': afwTable.ReadoutCorner.LL,
217 'LR': afwTable.ReadoutCorner.LR,
218 'UR': afwTable.ReadoutCorner.UR,
219 'UL': afwTable.ReadoutCorner.UL,
222 with open(ampFile)
as fh:
223 names = fh.readline().rstrip().lstrip(
"#").split(
"|")
225 els = l.rstrip().split(
"|")
226 ampProps = dict([(name, el)
for name, el
in zip(names, els)])
227 amps.append(ampProps)
229 schema = afwTable.AmpInfoTable.makeMinimalSchema()
230 linThreshKey = schema.addField(
'linearityThreshold', type=np.float64)
231 linMaxKey = schema.addField(
'linearityMaximum', type=np.float64)
232 linUnitsKey = schema.addField(
'linearityUnits', type=str, size=9)
235 if amp[
'ccd_name']
in ampTablesDict:
236 ampCatalog = ampTablesDict[amp[
'ccd_name']]
239 ampCatalog = afwTable.AmpInfoCatalog(schema)
240 ampTablesDict[amp[
'ccd_name']] = ampCatalog
241 self.
ampInfoDict[amp[
'ccd_name']] = {
'namps': 1,
'linInfo': {}}
242 record = ampCatalog.addNew()
244 int(amp[
'trimmed_ymin'])),
246 int(amp[
'trimmed_ymax'])))
248 int(amp[
'raw_ymin'])),
250 int(amp[
'raw_ymax'])))
253 int(amp[
'raw_data_ymin'])),
255 int(amp[
'raw_data_ymax'])))
258 int(amp[
'hoscan_ymin'])),
260 int(amp[
'hoscan_ymax'])))
263 int(amp[
'voscan_ymin'])),
265 int(amp[
'voscan_ymax'])))
268 int(amp[
'pscan_ymin'])),
270 int(amp[
'pscan_ymax'])))
271 xoffset = int(amp[
'x_offset'])
272 yoffset = int(amp[
'y_offset'])
273 flipx = bool(int(amp[
'flipx']))
274 flipy = bool(int(amp[
'flipy']))
279 xExt = rawBbox.getDimensions().getX()
281 rawDataBbox.flipLR(xExt)
282 rawHOverscanBbox.flipLR(xExt)
283 rawVOverscanBbox.flipLR(xExt)
284 rawPrescanBbox.flipLR(xExt)
286 yExt = rawBbox.getDimensions().getY()
288 rawDataBbox.flipTB(yExt)
289 rawHOverscanBbox.flipTB(yExt)
290 rawVOverscanBbox.flipTB(yExt)
291 rawPrescanBbox.flipTB(yExt)
292 if not flipx
and not flipy:
294 elif flipx
and not flipy:
296 elif flipx
and flipy:
298 elif not flipx
and flipy:
301 raise RuntimeError(
"Couldn't find read corner")
305 rawBbox.shift(offext)
306 rawDataBbox.shift(offext)
307 rawHOverscanBbox.shift(offext)
308 rawVOverscanBbox.shift(offext)
309 rawPrescanBbox.shift(offext)
314 record.setRawXYOffset(offset)
315 record.setName(str(amp[
'name']))
316 record.setReadoutCorner(readoutMap[readcorner])
317 record.setGain(float(amp[
'gain']))
318 record.setReadNoise(float(amp[
'readnoise']))
319 record.setLinearityCoeffs([float(amp[
'lin_coeffs']), ])
320 record.setLinearityType(str(amp[
'lin_type']))
321 record.setHasRawInfo(
True)
322 record.setRawFlipX(flipx)
323 record.setRawFlipY(flipy)
324 record.setRawBBox(rawBbox)
325 record.setRawDataBBox(rawDataBbox)
326 record.setRawHorizontalOverscanBBox(rawHOverscanBbox)
327 record.setRawVerticalOverscanBBox(rawVOverscanBbox)
328 record.setRawPrescanBBox(rawPrescanBbox)
329 record.set(linThreshKey, float(amp[
'lin_thresh']))
330 record.set(linMaxKey, float(amp[
'lin_max']))
331 record.set(linUnitsKey, str(amp[
'lin_units']))
333 saveCoeffs = (float(amp[
'lin_coeffs']),)
334 saveCoeffs += (np.nan, np.nan, np.nan)
335 self.
ampInfoDict[amp[
'ccd_name']][
'linInfo'][amp[
'name']] = \
336 {
'lincoeffs': saveCoeffs,
'lintype': str(amp[
'lin_type']),
337 'linthresh': float(amp[
'lin_thresh']),
'linmax': float(amp[
'lin_max']),
338 'linunits': str(amp[
'lin_units'])}
342 """!Make camera config and amp catalog dictionary, using default detector and amp files
344 @param[in] isLsstLike if True then there is one raw image per amplifier;
345 if False then there is one raw image per detector
347 detFile = os.path.join(self.
_afwTestDir,
"testCameraDetectors.dat")
349 ampFile = os.path.join(self.
_afwTestDir,
"testCameraAmps.dat")
351 camConfig = CameraConfig()
352 camConfig.name =
"testCamera%s"%(
'LSST' if isLsstLike
else 'SC')
353 camConfig.detectorList = dict((i, detConfig)
354 for i, detConfig
in enumerate(detectorConfigs))
357 radialDistortCoeffs = [0.0, 1.0/pScaleRad,
359 tConfig = afwGeom.TransformConfig()
360 tConfig.transform.name =
'inverted'
361 radialClass = afwGeom.transformRegistry[
'radial']
362 tConfig.transform.active.transform.retarget(radialClass)
363 tConfig.transform.active.transform.coeffs = radialDistortCoeffs
364 tmc = TransformMapConfig()
365 tmc.nativeSys = FOCAL_PLANE.getSysName()
366 tmc.transforms = {FIELD_ANGLE.getSysName(): tConfig}
367 camConfig.transformDict = tmc
368 return camConfig, ampCatalogDict
Camera coordinate system; used as a key in in TransformMap.
def __init__
Construct a CameraWrapper.
TransformPoint2ToPoint2 makeRadialTransform(std::vector< double > const &forwardCoeffs, std::vector< double > const &inverseCoeffs)
A purely radial polynomial distortion.
def makeTestRepositoryItems
Make camera config and amp catalog dictionary, using default detector and amp files.
def nDetectors
Return the number of detectors.
A Detector and the data used to construct it.
def __init__
Construct a DetectorWrapper.
An integer coordinate rectangle.
Describe a detector's orientation in the focal plane.
def makePixelToTanPixel
Make a Transform whose forward direction converts PIXEL to TAN_PIXEL for one detector.
def makeDetectorConfigs
Construct a list of DetectorConfig, one per detector.
def makeAmpCatalogs
Construct a list of AmpInfoCatalog, one per detector.
Information about a CCD or other imaging detector.
def makeCameraFromCatalogs
Construct a Camera instance from a dictionary of detector name: AmpInfoCatalog.
constexpr double arcsecToRad(double x) noexcept