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, PUPIL, 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
19 __all__ = [
"DetectorWrapper",
"CameraWrapper"]
23 """!A Detector and the data used to construct it 25 Intended for use with unit tests, thus saves a copy of all input parameters. 26 Does not support setting details of amplifiers. 36 pixelSize=(0.02, 0.02),
40 radialDistortion=0.925,
43 """!Construct a DetectorWrapper 45 @param[in] name detector name 46 @param[in] id detector ID (int) 47 @param[in] detType detector type (an lsst.afw.cameraGeom.DetectorType) 48 @param[in] serial serial "number" (a string) 49 @param[in] bbox bounding box; defaults to (0, 0), (1024x1024) (an lsst.afw.geom.Box2I) 50 @param[in] numAmps number of amplifiers (int) 51 @param[in] pixelSize pixel size (mm) (an lsst.afw.geom.Point2D) 52 @param[in] ampExtent dimensions of amplifier image bbox (an lsst.afw.geom.Extent2I) 53 @param[in] orientation orientation of CCC in focal plane (lsst.afw.cameraGeom.Orientation) 54 @param[in] plateScale plate scale in arcsec/mm; 20.0 is for LSST 55 @param[in] radialDistortion radial distortion, in mm/rad^2 56 (the r^3 coefficient of the radial distortion polynomial 57 that converts PUPIL in radians to FOCAL_PLANE in mm); 58 0.925 is the value Dave Monet measured for lsstSim data 59 @param[in] modFunc a function that can modify attributes just before constructing the detector; 60 modFunc receives one argument: a DetectorWrapper with all attributes except detector set. 76 schema = afwTable.AmpInfoTable.makeMinimalSchema()
77 self.
ampInfo = afwTable.AmpInfoCatalog(schema)
78 for i
in range(numAmps):
80 ampName =
"amp %d" % (i + 1,)
81 record.setName(ampName)
84 record.setGain(1.71234e3)
85 record.setReadNoise(0.521237e2)
86 record.setReadoutCorner(afwTable.LL)
87 record.setHasRawInfo(
False)
92 radialDistortCoeffs = [0.0, 1.0/pScaleRad,
98 focalPlaneToPupil = focalPlaneToPupil,
123 """A simple Camera and the data used to construct it 125 Intended for use with unit tests, thus saves some interesting information. 128 def __init__(self, plateScale=20.0, radialDistortion=0.925, isLsstLike=False):
129 """!Construct a CameraWrapper 131 @param[in] plateScale plate scale in arcsec/mm; 20.0 is for LSST 132 @param[in] radialDistortion radial distortion, in mm/rad^2 133 (the r^3 coefficient of the radial distortion polynomial 134 that converts PUPIL in radians to FOCAL_PLANE in mm); 135 0.925 is the value Dave Monet measured for lsstSim data 136 @param[in] isLsstLike make repository products with one raw image per amplifier (True) 137 or with one raw image per detector (False) 139 afwDir = lsst.utils.getPackageDir(
"afw")
156 """!Return the number of detectors""" 160 """!Construct a list of DetectorConfig, one per detector 165 with open(detFile)
as fh:
166 names = fh.readline().rstrip().lstrip(
"#").split(
"|")
168 els = l.rstrip().split(
"|")
169 detectorProps = dict([(name, el)
170 for name, el
in zip(names, els)])
171 detectors.append(detectorProps)
173 for i, detector
in enumerate(detectors):
174 detectorId = (i + 1) * 10
175 detectorName = detector[
'name']
177 detConfig.name = detectorName
178 detConfig.id = detectorId
179 detConfig.bbox_x0 = 0
180 detConfig.bbox_y0 = 0
181 detConfig.bbox_x1 = int(detector[
'npix_x']) - 1
182 detConfig.bbox_y1 = int(detector[
'npix_y']) - 1
183 detConfig.serial = str(detector[
'serial'])
184 detConfig.detectorType = int(detector[
'detectorType'])
185 detConfig.offset_x = float(detector[
'x'])
186 detConfig.offset_y = float(detector[
'y'])
187 detConfig.refpos_x = float(detector[
'refPixPos_x'])
188 detConfig.refpos_y = float(detector[
'refPixPos_y'])
189 detConfig.yawDeg = float(detector[
'yaw'])
190 detConfig.pitchDeg = float(detector[
'pitch'])
191 detConfig.rollDeg = float(detector[
'roll'])
192 detConfig.pixelSize_x = float(detector[
'pixelSize'])
193 detConfig.pixelSize_y = float(detector[
'pixelSize'])
194 detConfig.transposeDetector =
False 195 detConfig.transformDict.nativeSys = PIXELS.getSysName()
196 detectorConfigs.append(detConfig)
199 return detectorConfigs
202 """!Construct a list of AmpInfoCatalog, one per detector 204 @param[in] ampFile path to amplifier data file 205 @param[in] isLsstLike if True then there is one raw image per amplifier; 206 if False then there is one raw image per detector 209 'LL': afwTable.ReadoutCorner.LL,
210 'LR': afwTable.ReadoutCorner.LR,
211 'UR': afwTable.ReadoutCorner.UR, 212 'UL': afwTable.ReadoutCorner.UL,
215 with open(ampFile)
as fh:
216 names = fh.readline().rstrip().lstrip(
"#").split(
"|")
218 els = l.rstrip().split(
"|")
219 ampProps = dict([(name, el)
for name, el
in zip(names, els)])
220 amps.append(ampProps)
222 schema = afwTable.AmpInfoTable.makeMinimalSchema()
223 linThreshKey = schema.addField(
'linearityThreshold', type=np.float64)
224 linMaxKey = schema.addField(
'linearityMaximum', type=np.float64)
225 linUnitsKey = schema.addField(
'linearityUnits', type=str, size=9)
228 if amp[
'ccd_name']
in ampTablesDict:
229 ampCatalog = ampTablesDict[amp[
'ccd_name']]
232 ampCatalog = afwTable.AmpInfoCatalog(schema)
233 ampTablesDict[amp[
'ccd_name']] = ampCatalog
234 self.
ampInfoDict[amp[
'ccd_name']] = {
'namps': 1,
'linInfo': {}}
235 record = ampCatalog.addNew()
237 int(amp[
'trimmed_ymin'])),
239 int(amp[
'trimmed_ymax'])))
241 int(amp[
'raw_ymin'])),
243 int(amp[
'raw_ymax'])))
246 int(amp[
'raw_data_ymin'])),
248 int(amp[
'raw_data_ymax'])))
251 int(amp[
'hoscan_ymin'])),
253 int(amp[
'hoscan_ymax'])))
256 int(amp[
'voscan_ymin'])),
258 int(amp[
'voscan_ymax'])))
261 int(amp[
'pscan_ymin'])),
263 int(amp[
'pscan_ymax'])))
264 xoffset = int(amp[
'x_offset'])
265 yoffset = int(amp[
'y_offset'])
266 flipx = bool(int(amp[
'flipx']))
267 flipy = bool(int(amp[
'flipy']))
272 xExt = rawBbox.getDimensions().getX()
274 rawDataBbox.flipLR(xExt)
275 rawHOverscanBbox.flipLR(xExt)
276 rawVOverscanBbox.flipLR(xExt)
277 rawPrescanBbox.flipLR(xExt)
279 yExt = rawBbox.getDimensions().getY()
281 rawDataBbox.flipTB(yExt)
282 rawHOverscanBbox.flipTB(yExt)
283 rawVOverscanBbox.flipTB(yExt)
284 rawPrescanBbox.flipTB(yExt)
285 if not flipx
and not flipy:
287 elif flipx
and not flipy:
289 elif flipx
and flipy:
291 elif not flipx
and flipy:
294 raise RuntimeError(
"Couldn't find read corner")
298 rawBbox.shift(offext)
299 rawDataBbox.shift(offext)
300 rawHOverscanBbox.shift(offext)
301 rawVOverscanBbox.shift(offext)
302 rawPrescanBbox.shift(offext)
307 record.setRawXYOffset(offset)
308 record.setName(str(amp[
'name']))
309 record.setReadoutCorner(readoutMap[readcorner])
310 record.setGain(float(amp[
'gain']))
311 record.setReadNoise(float(amp[
'readnoise']))
312 record.setLinearityCoeffs([float(amp[
'lin_coeffs']), ])
313 record.setLinearityType(str(amp[
'lin_type']))
314 record.setHasRawInfo(
True)
315 record.setRawFlipX(flipx)
316 record.setRawFlipY(flipy)
317 record.setRawBBox(rawBbox)
318 record.setRawDataBBox(rawDataBbox)
319 record.setRawHorizontalOverscanBBox(rawHOverscanBbox)
320 record.setRawVerticalOverscanBBox(rawVOverscanBbox)
321 record.setRawPrescanBBox(rawPrescanBbox)
322 record.set(linThreshKey, float(amp[
'lin_thresh']))
323 record.set(linMaxKey, float(amp[
'lin_max']))
324 record.set(linUnitsKey, str(amp[
'lin_units']))
326 saveCoeffs = (float(amp[
'lin_coeffs']),)
327 saveCoeffs += (np.nan, np.nan, np.nan)
328 self.
ampInfoDict[amp[
'ccd_name']][
'linInfo'][amp[
'name']] = \
329 {
'lincoeffs': saveCoeffs,
'lintype': str(amp[
'lin_type']),
330 'linthresh': float(amp[
'lin_thresh']),
'linmax': float(amp[
'lin_max']),
331 'linunits': str(amp[
'lin_units'])}
335 """!Make camera config and amp catalog dictionary, using default detector and amp files 337 @param[in] isLsstLike if True then there is one raw image per amplifier; 338 if False then there is one raw image per detector 340 detFile = os.path.join(self.
_afwTestDir,
"testCameraDetectors.dat")
342 ampFile = os.path.join(self.
_afwTestDir,
"testCameraAmps.dat")
345 camConfig.name =
"testCamera%s"%(
'LSST' if isLsstLike
else 'SC')
346 camConfig.detectorList = dict((i, detConfig)
347 for i, detConfig
in enumerate(detectorConfigs))
350 radialDistortCoeffs = [0.0, 1.0/pScaleRad,
353 tConfig.transform.name =
'inverted' 354 radialClass = afwGeom.xyTransformRegistry[
'radial']
355 tConfig.transform.active.transform.retarget(radialClass)
356 tConfig.transform.active.transform.coeffs = radialDistortCoeffs
358 tmc.nativeSys = FOCAL_PLANE.getSysName()
359 tmc.transforms = {PUPIL.getSysName(): tConfig}
360 camConfig.transformDict = tmc
361 return camConfig, ampCatalogDict
Camera coordinate system; used as a key in in TransformMap.
def makeTestRepositoryItems(self, isLsstLike=False)
Make camera config and amp catalog dictionary, using default detector and amp files.
def makeCameraFromCatalogs(cameraConfig, ampInfoCatDict, pupilFactoryClass=PupilFactory)
Construct a Camera instance from a dictionary of detector name: AmpInfoCatalog.
A configuration that represents (and can be used to construct) a Detector.
A Detector and the data used to construct it.
An integer coordinate rectangle.
Describe a detector's orientation in the focal plane.
def nDetectors(self)
Return the number of detectors.
def makeAmpCatalogs(self, ampFile, isLsstLike=False)
Construct a list of AmpInfoCatalog, one per detector.
Information about a CCD or other imaging detector.
def makePixelToTanPixel(bbox, orientation, focalPlaneToPupil, pixelSizeMm)
Make an XYTransform whose forward direction converts PIXEL to TAN_PIXEL for one detector.
A configuration that represents (and can be used to construct) a Camera.
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, modFunc=None)
Construct a DetectorWrapper.
constexpr double arcsecToRad(double x) noexcept
def makeDetectorConfigs(self, detFile)
Construct a list of DetectorConfig, one per detector.
def __init__(self, plateScale=20.0, radialDistortion=0.925, isLsstLike=False)
Construct a CameraWrapper.