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,
44 """!Construct a DetectorWrapper
46 @param[in] name detector name
47 @param[in] id detector ID (int)
48 @param[in] detType detector type (an lsst.afw.cameraGeom.DetectorType)
49 @param[in] serial serial "number" (a string)
50 @param[in] bbox bounding box; defaults to (0, 0), (1024x1024) (an lsst.afw.geom.Box2I)
51 @param[in] numAmps number of amplifiers (int)
52 @param[in] pixelSize pixel size (mm) (an lsst.afw.geom.Point2D)
53 @param[in] ampExtent dimensions of amplifier image bbox (an lsst.afw.geom.Extent2I)
54 @param[in] orientation orientation of CCC in focal plane (lsst.afw.cameraGeom.Orientation)
55 @param[in] plateScale plate scale in arcsec/mm; 20.0 is for LSST
56 @param[in] radialDistortion radial distortion, in mm/rad^2
57 (the r^3 coefficient of the radial distortion polynomial
58 that converts FIELD_ANGLE in radians to FOCAL_PLANE in mm);
59 0.925 is the value Dave Monet measured for lsstSim data
60 @param[in] modFunc a function that can modify attributes just before constructing the detector;
61 modFunc receives one argument: a DetectorWrapper with all attributes except detector set.
77 schema = afwTable.AmpInfoTable.makeMinimalSchema()
78 self.
ampInfo = afwTable.AmpInfoCatalog(schema)
79 for i
in range(numAmps):
80 record = self.ampInfo.addNew()
81 ampName =
"amp %d" % (i + 1,)
82 record.setName(ampName)
85 record.setGain(1.71234e3)
86 record.setReadNoise(0.521237e2)
87 record.setReadoutCorner(afwTable.LL)
88 record.setHasRawInfo(
False)
93 radialDistortCoeffs = [0.0, 1.0/pScaleRad,
99 focalPlaneToField = focalPlaneToField,
104 FOCAL_PLANE: self.orientation.makePixelFpTransform(self.
pixelSize),
124 """A simple Camera and the data used to construct it
126 Intended for use with unit tests, thus saves some interesting information.
129 def __init__(self, plateScale=20.0, radialDistortion=0.925, isLsstLike=False):
130 """!Construct a CameraWrapper
132 @param[in] plateScale plate scale in arcsec/mm; 20.0 is for LSST
133 @param[in] radialDistortion radial distortion, in mm/rad^2
134 (the r^3 coefficient of the radial distortion polynomial
135 that converts FIELD_ANGLE in radians to FOCAL_PLANE in mm);
136 0.925 is the value Dave Monet measured for lsstSim data
137 @param[in] isLsstLike make repository products with one raw image per amplifier (True)
138 or with one raw image per detector (False)
140 afwDir = lsst.utils.getPackageDir(
"afw")
157 """!Return the number of detectors"""
161 """!Construct a list of DetectorConfig, one per detector
166 with open(detFile)
as fh:
167 names = fh.readline().rstrip().lstrip(
"#").split(
"|")
169 els = l.rstrip().split(
"|")
170 detectorProps = dict([(name, el)
171 for name, el
in zip(names, els)])
172 detectors.append(detectorProps)
174 for i, detector
in enumerate(detectors):
175 detectorId = (i + 1) * 10
176 detectorName = detector[
'name']
177 detConfig = DetectorConfig()
178 detConfig.name = detectorName
179 detConfig.id = detectorId
180 detConfig.bbox_x0 = 0
181 detConfig.bbox_y0 = 0
182 detConfig.bbox_x1 = int(detector[
'npix_x']) - 1
183 detConfig.bbox_y1 = int(detector[
'npix_y']) - 1
184 detConfig.serial = str(detector[
'serial'])
185 detConfig.detectorType = int(detector[
'detectorType'])
186 detConfig.offset_x = float(detector[
'x'])
187 detConfig.offset_y = float(detector[
'y'])
188 detConfig.refpos_x = float(detector[
'refPixPos_x'])
189 detConfig.refpos_y = float(detector[
'refPixPos_y'])
190 detConfig.yawDeg = float(detector[
'yaw'])
191 detConfig.pitchDeg = float(detector[
'pitch'])
192 detConfig.rollDeg = float(detector[
'roll'])
193 detConfig.pixelSize_x = float(detector[
'pixelSize'])
194 detConfig.pixelSize_y = float(detector[
'pixelSize'])
195 detConfig.transposeDetector =
False
196 detConfig.transformDict.nativeSys = PIXELS.getSysName()
197 detectorConfigs.append(detConfig)
198 self.detectorNameList.append(detectorName)
199 self.detectorIdList.append(detectorId)
200 return detectorConfigs
203 """!Construct a list of AmpInfoCatalog, one per detector
205 @param[in] ampFile path to amplifier data file
206 @param[in] isLsstLike if True then there is one raw image per amplifier;
207 if False then there is one raw image per detector
210 'LL': afwTable.ReadoutCorner.LL,
211 'LR': afwTable.ReadoutCorner.LR,
212 'UR': afwTable.ReadoutCorner.UR,
213 'UL': afwTable.ReadoutCorner.UL,
216 with open(ampFile)
as fh:
217 names = fh.readline().rstrip().lstrip(
"#").split(
"|")
219 els = l.rstrip().split(
"|")
220 ampProps = dict([(name, el)
for name, el
in zip(names, els)])
221 amps.append(ampProps)
223 schema = afwTable.AmpInfoTable.makeMinimalSchema()
224 linThreshKey = schema.addField(
'linearityThreshold', type=np.float64)
225 linMaxKey = schema.addField(
'linearityMaximum', type=np.float64)
226 linUnitsKey = schema.addField(
'linearityUnits', type=str, size=9)
229 if amp[
'ccd_name']
in ampTablesDict:
230 ampCatalog = ampTablesDict[amp[
'ccd_name']]
233 ampCatalog = afwTable.AmpInfoCatalog(schema)
234 ampTablesDict[amp[
'ccd_name']] = ampCatalog
235 self.
ampInfoDict[amp[
'ccd_name']] = {
'namps': 1,
'linInfo': {}}
236 record = ampCatalog.addNew()
238 int(amp[
'trimmed_ymin'])),
240 int(amp[
'trimmed_ymax'])))
242 int(amp[
'raw_ymin'])),
244 int(amp[
'raw_ymax'])))
247 int(amp[
'raw_data_ymin'])),
249 int(amp[
'raw_data_ymax'])))
252 int(amp[
'hoscan_ymin'])),
254 int(amp[
'hoscan_ymax'])))
257 int(amp[
'voscan_ymin'])),
259 int(amp[
'voscan_ymax'])))
262 int(amp[
'pscan_ymin'])),
264 int(amp[
'pscan_ymax'])))
265 xoffset = int(amp[
'x_offset'])
266 yoffset = int(amp[
'y_offset'])
267 flipx = bool(int(amp[
'flipx']))
268 flipy = bool(int(amp[
'flipy']))
273 xExt = rawBbox.getDimensions().getX()
275 rawDataBbox.flipLR(xExt)
276 rawHOverscanBbox.flipLR(xExt)
277 rawVOverscanBbox.flipLR(xExt)
278 rawPrescanBbox.flipLR(xExt)
280 yExt = rawBbox.getDimensions().getY()
282 rawDataBbox.flipTB(yExt)
283 rawHOverscanBbox.flipTB(yExt)
284 rawVOverscanBbox.flipTB(yExt)
285 rawPrescanBbox.flipTB(yExt)
286 if not flipx
and not flipy:
288 elif flipx
and not flipy:
290 elif flipx
and flipy:
292 elif not flipx
and flipy:
295 raise RuntimeError(
"Couldn't find read corner")
299 rawBbox.shift(offext)
300 rawDataBbox.shift(offext)
301 rawHOverscanBbox.shift(offext)
302 rawVOverscanBbox.shift(offext)
303 rawPrescanBbox.shift(offext)
308 record.setRawXYOffset(offset)
309 record.setName(str(amp[
'name']))
310 record.setReadoutCorner(readoutMap[readcorner])
311 record.setGain(float(amp[
'gain']))
312 record.setReadNoise(float(amp[
'readnoise']))
313 record.setLinearityCoeffs([float(amp[
'lin_coeffs']), ])
314 record.setLinearityType(str(amp[
'lin_type']))
315 record.setHasRawInfo(
True)
316 record.setRawFlipX(flipx)
317 record.setRawFlipY(flipy)
318 record.setRawBBox(rawBbox)
319 record.setRawDataBBox(rawDataBbox)
320 record.setRawHorizontalOverscanBBox(rawHOverscanBbox)
321 record.setRawVerticalOverscanBBox(rawVOverscanBbox)
322 record.setRawPrescanBBox(rawPrescanBbox)
323 record.set(linThreshKey, float(amp[
'lin_thresh']))
324 record.set(linMaxKey, float(amp[
'lin_max']))
325 record.set(linUnitsKey, str(amp[
'lin_units']))
327 saveCoeffs = (float(amp[
'lin_coeffs']),)
328 saveCoeffs += (np.nan, np.nan, np.nan)
329 self.
ampInfoDict[amp[
'ccd_name']][
'linInfo'][amp[
'name']] = \
330 {
'lincoeffs': saveCoeffs,
'lintype': str(amp[
'lin_type']),
331 'linthresh': float(amp[
'lin_thresh']),
'linmax': float(amp[
'lin_max']),
332 'linunits': str(amp[
'lin_units'])}
336 """!Make camera config and amp catalog dictionary, using default detector and amp files
338 @param[in] isLsstLike if True then there is one raw image per amplifier;
339 if False then there is one raw image per detector
341 detFile = os.path.join(self.
_afwTestDir,
"testCameraDetectors.dat")
343 ampFile = os.path.join(self.
_afwTestDir,
"testCameraAmps.dat")
345 camConfig = CameraConfig()
346 camConfig.name =
"testCamera%s"%(
'LSST' if isLsstLike
else 'SC')
347 camConfig.detectorList = dict((i, detConfig)
348 for i, detConfig
in enumerate(detectorConfigs))
351 radialDistortCoeffs = [0.0, 1.0/pScaleRad,
353 tConfig = afwGeom.TransformConfig()
354 tConfig.transform.name =
'inverted'
355 radialClass = afwGeom.transformRegistry[
'radial']
356 tConfig.transform.active.transform.retarget(radialClass)
357 tConfig.transform.active.transform.coeffs = radialDistortCoeffs
358 tmc = TransformMapConfig()
359 tmc.nativeSys = FOCAL_PLANE.getSysName()
360 tmc.transforms = {FIELD_ANGLE.getSysName(): tConfig}
361 camConfig.transformDict = tmc
362 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