31 __all__ = [
"makeCamera"]
35 """An imaging camera (e.g. the LSST 3Gpix camera)
40 Camera description YAML file.
44 camera : `lsst.afw.cameraGeom.Camera`
48 with open(cameraFile)
as fd:
49 cameraParams = yaml.load(fd, Loader=yaml.CLoader)
51 cameraName = cameraParams[
"name"]
56 plateScale =
geom.Angle(cameraParams[
"plateScale"], geom.arcseconds)
57 nativeSys = cameraGeom.CameraSys(cameraParams[
"transforms"].pop(
"nativeSys"))
60 ccdParams = cameraParams[
"CCDs"]
64 for ccdName, ccdValues
in ccdParams.items():
71 """Make a list of detector configs
75 detectorConfig : `list` of `lsst.afw.cameraGeom.DetectorConfig`
76 A list of detector configs.
79 for name, ccd
in ccdParams.items():
80 detectorConfig = cameraGeom.DetectorConfig()
81 detectorConfigs.append(detectorConfig)
83 detectorConfig.name = name
84 detectorConfig.id = ccd[
'id']
85 detectorConfig.serial = ccd[
'serial']
86 detectorConfig.detectorType = ccd[
'detectorType']
87 if 'physicalType' in ccd:
88 detectorConfig.physicalType = ccd[
'physicalType']
90 detectorConfig.bbox_x0, detectorConfig.bbox_y0 = ccd[
'bbox'][0]
91 detectorConfig.bbox_x1, detectorConfig.bbox_y1 = ccd[
'bbox'][1]
92 detectorConfig.pixelSize_x, detectorConfig.pixelSize_y = ccd[
'pixelSize']
93 detectorConfig.transformDict.nativeSys = ccd[
'transformDict'][
'nativeSys']
94 transforms = ccd[
'transformDict'][
'transforms']
95 detectorConfig.transformDict.transforms =
None if transforms ==
'None' else transforms
96 detectorConfig.refpos_x, detectorConfig.refpos_y = ccd[
'refpos']
97 detectorConfig.offset_x, detectorConfig.offset_y = ccd[
'offset']
98 detectorConfig.transposeDetector = ccd[
'transposeDetector']
99 detectorConfig.pitchDeg = ccd[
'pitch']
100 detectorConfig.yawDeg = ccd[
'yaw']
101 detectorConfig.rollDeg = ccd[
'roll']
102 if 'crosstalk' in ccd:
103 detectorConfig.crosstalk = ccd[
'crosstalk']
105 return detectorConfigs
109 """Construct a list of AmplifierBuilder objects
113 amp =
list(ccd[
'amplifiers'].values())[0]
116 xRawExtent, yRawExtent = rawBBox.getDimensions()
118 readCorners = {
"LL": ReadoutCorner.LL,
119 "LR": ReadoutCorner.LR,
120 "UL": ReadoutCorner.UL,
121 "UR": ReadoutCorner.UR}
124 for name, amp
in sorted(ccd[
'amplifiers'].
items(), key=
lambda x: x[1][
'hdu']):
126 amplifier.setName(name)
129 perAmpData = amp[
'perAmpData']
133 x0, y0 = ix*xRawExtent, iy*yRawExtent
136 xDataExtent, yDataExtent = rawDataBBox.getDimensions()
138 geom.PointI(ix*xDataExtent, iy*yDataExtent), rawDataBBox.getDimensions()))
142 amplifier.setRawBBox(rawBBox)
146 amplifier.setRawDataBBox(rawDataBBox)
150 amplifier.setRawHorizontalOverscanBBox(rawSerialOverscanBBox)
154 amplifier.setRawVerticalOverscanBBox(rawParallelOverscanBBox)
158 amplifier.setRawPrescanBBox(rawSerialPrescanBBox)
161 amplifier.setRawXYOffset(
geom.Extent2I(ix*xRawExtent, iy*yRawExtent))
165 amplifier.setReadoutCorner(readCorners[amp[
'readCorner']])
166 amplifier.setGain(amp[
'gain'])
167 amplifier.setReadNoise(amp[
'readNoise'])
168 amplifier.setSaturation(amp[
'saturation'])
169 amplifier.setSuspectLevel(amp.get(
'suspect', np.nan))
172 flipX, flipY = amp.get(
"flipXY")
174 amplifier.setRawFlipX(flipX)
175 amplifier.setRawFlipY(flipY)
177 amplifier.setLinearityCoeffs([float(val)
for val
in amp[
'linearityCoeffs']])
178 amplifier.setLinearityType(amp[
'linearityType'])
179 amplifier.setLinearityThreshold(float(amp[
'linearityThreshold']))
180 amplifier.setLinearityMaximum(float(amp[
'linearityMax']))
181 amplifier.setLinearityUnits(
"DN")
182 amplifierList.append(amplifier)
187 """Backward compatible name.
193 """Given a list [(x0, y0), (xsize, ysize)], probably from a yaml file,
196 (x0, y0), (xsize, ysize) = ylist
201 """Make a dictionary of TransformPoint2ToPoint2s from yaml, mapping from nativeSys
205 nativeSys : `lsst.afw.cameraGeom.CameraSys`
206 transformDict : `dict`
207 A dict specifying parameters of transforms; keys are camera system names.
208 plateScale : `lsst.geom.Angle`
209 The size of a pixel in angular units/mm (e.g. 20 arcsec/mm for LSST)
214 A dict of `lsst.afw.cameraGeom.CameraSys` : `lsst.afw.geom.TransformPoint2ToPoint2`
216 The resulting dict's keys are `~lsst.afw.cameraGeom.CameraSys`,
217 and the values are Transforms *from* NativeSys *to* CameraSys
220 assert nativeSys == cameraGeom.FOCAL_PLANE,
"Cameras with nativeSys != FOCAL_PLANE are not supported."
224 for key, transform
in transformDict.items():
225 transformType = transform[
"transformType"]
226 knownTransformTypes = [
"affine",
"radial"]
227 if transformType
not in knownTransformTypes:
228 raise RuntimeError(
"Saw unknown transform type for %s: %s (known types are: [%s])" % (
229 key, transform[
"transformType"],
", ".join(knownTransformTypes)))
231 if transformType ==
"affine":
233 np.array(transform[
"translation"]))
236 elif transformType ==
"radial":
241 radialCoeffs = np.array(transform[
"coeffs"])
243 radialCoeffs *= plateScale.asRadians()
246 raise RuntimeError(
"Impossible condition \"%s\" is not in: [%s])" % (
247 transform[
"transformType"],
", ".join(knownTransformTypes)))
249 resMap[cameraGeom.CameraSys(key)] = transform
255 pupilFactoryClass=cameraGeom.pupil.PupilFactory):
256 """Construct a Camera instance from a dictionary of
257 detector name : `lsst.afw.cameraGeom.amplifier`
262 The name of the camera
263 detectorConfigList : `list`
264 A list of `lsst.afw.cameraGeom.cameraConfig.DetectorConfig`
265 nativeSys : `lsst.afw.cameraGeom.CameraSys`
266 The native transformation type; must be `lsst.afw.cameraGeom.FOCAL_PLANE`
267 transformDict : `dict`
268 A dict of lsst.afw.cameraGeom.CameraSys : `lsst.afw.geom.TransformPoint2ToPoint2`
269 amplifierDict : `dict`
270 A dictionary of detector name :
271 `lsst.afw.cameraGeom.Amplifier.Builder`
272 pupilFactoryClass : `type`, optional
273 Class to attach to camera;
274 `lsst.default afw.cameraGeom.PupilFactory`
278 camera : `lsst.afw.cameraGeom.Camera`
283 Copied from `lsst.afw.cameraGeom.cameraFactory` with permission and encouragement
292 assert nativeSys == cameraGeom.FOCAL_PLANE,
"Cameras with nativeSys != FOCAL_PLANE are not supported."
294 focalPlaneToField = transformDict[cameraGeom.FIELD_ANGLE]
297 cameraBuilder.setPupilFactoryClass(pupilFactoryClass)
300 for toSys, transform
in transformDict.items():
301 cameraBuilder.setTransformFromFocalPlaneTo(toSys, transform)
303 for detectorConfig
in detectorConfigList:
305 cameraGeom.addDetectorBuilderFromConfig(cameraBuilder, detectorConfig,
306 amplifierDict[detectorConfig.name],
313 detectorNativeSys = detectorConfig.transformDict.nativeSys
314 detectorNativeSys = (cameraGeom.PIXELS
if detectorNativeSys
is None else
315 cameraGeom.CameraSysPrefix(detectorNativeSys))
324 assert detectorNativeSys == cameraGeom.PIXELS, \
325 "Detectors with nativeSys != PIXELS are not supported."
326 detectorNativeSys = cameraGeom.CameraSys(detectorNativeSys, detectorConfig.name)
328 return cameraBuilder.finish()