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):
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,
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) 148 "cameraGeom",
"testData")
164 """!Return the number of detectors""" 168 """!Construct a list of DetectorConfig, one per detector 173 with open(detFile)
as fh:
174 names = fh.readline().rstrip().lstrip(
"#").split(
"|")
176 els = l.rstrip().split(
"|")
177 detectorProps = dict([(name, el)
178 for name, el
in zip(names, els)])
179 detectors.append(detectorProps)
181 for i, detector
in enumerate(detectors):
182 detectorId = (i + 1) * 10
183 detectorName = detector[
'name']
185 detConfig.name = detectorName
186 detConfig.id = detectorId
187 detConfig.bbox_x0 = 0
188 detConfig.bbox_y0 = 0
189 detConfig.bbox_x1 = int(detector[
'npix_x']) - 1
190 detConfig.bbox_y1 = int(detector[
'npix_y']) - 1
191 detConfig.serial = str(detector[
'serial'])
192 detConfig.detectorType = int(detector[
'detectorType'])
193 detConfig.offset_x = float(detector[
'x'])
194 detConfig.offset_y = float(detector[
'y'])
195 detConfig.refpos_x = float(detector[
'refPixPos_x'])
196 detConfig.refpos_y = float(detector[
'refPixPos_y'])
197 detConfig.yawDeg = float(detector[
'yaw'])
198 detConfig.pitchDeg = float(detector[
'pitch'])
199 detConfig.rollDeg = float(detector[
'roll'])
200 detConfig.pixelSize_x = float(detector[
'pixelSize'])
201 detConfig.pixelSize_y = float(detector[
'pixelSize'])
202 detConfig.transposeDetector =
False 203 detConfig.transformDict.nativeSys = PIXELS.getSysName()
204 detectorConfigs.append(detConfig)
207 return detectorConfigs
210 """!Construct a list of AmpInfoCatalog, one per detector 212 @param[in] ampFile path to amplifier data file 213 @param[in] isLsstLike if True then there is one raw image per amplifier; 214 if False then there is one raw image per detector 217 'LL': afwTable.ReadoutCorner.LL,
218 'LR': afwTable.ReadoutCorner.LR,
219 'UR': afwTable.ReadoutCorner.UR, 220 'UL': afwTable.ReadoutCorner.UL,
223 with open(ampFile)
as fh:
224 names = fh.readline().rstrip().lstrip(
"#").split(
"|")
226 els = l.rstrip().split(
"|")
227 ampProps = dict([(name, el)
for name, el
in zip(names, els)])
228 amps.append(ampProps)
230 schema = afwTable.AmpInfoTable.makeMinimalSchema()
231 linThreshKey = schema.addField(
'linearityThreshold', type=np.float64)
232 linMaxKey = schema.addField(
'linearityMaximum', type=np.float64)
233 linUnitsKey = schema.addField(
'linearityUnits', type=str, size=9)
236 if amp[
'ccd_name']
in ampTablesDict:
237 ampCatalog = ampTablesDict[amp[
'ccd_name']]
240 ampCatalog = afwTable.AmpInfoCatalog(schema)
241 ampTablesDict[amp[
'ccd_name']] = ampCatalog
242 self.
ampInfoDict[amp[
'ccd_name']] = {
'namps': 1,
'linInfo': {}}
243 record = ampCatalog.addNew()
245 int(amp[
'trimmed_ymin'])),
247 int(amp[
'trimmed_ymax'])))
249 int(amp[
'raw_ymin'])),
251 int(amp[
'raw_ymax'])))
254 int(amp[
'raw_data_ymin'])),
256 int(amp[
'raw_data_ymax'])))
259 int(amp[
'hoscan_ymin'])),
261 int(amp[
'hoscan_ymax'])))
264 int(amp[
'voscan_ymin'])),
266 int(amp[
'voscan_ymax'])))
269 int(amp[
'pscan_ymin'])),
271 int(amp[
'pscan_ymax'])))
272 xoffset = int(amp[
'x_offset'])
273 yoffset = int(amp[
'y_offset'])
274 flipx = bool(int(amp[
'flipx']))
275 flipy = bool(int(amp[
'flipy']))
280 xExt = rawBbox.getDimensions().getX()
282 rawDataBbox.flipLR(xExt)
283 rawHOverscanBbox.flipLR(xExt)
284 rawVOverscanBbox.flipLR(xExt)
285 rawPrescanBbox.flipLR(xExt)
287 yExt = rawBbox.getDimensions().getY()
289 rawDataBbox.flipTB(yExt)
290 rawHOverscanBbox.flipTB(yExt)
291 rawVOverscanBbox.flipTB(yExt)
292 rawPrescanBbox.flipTB(yExt)
293 if not flipx
and not flipy:
295 elif flipx
and not flipy:
297 elif flipx
and flipy:
299 elif not flipx
and flipy:
302 raise RuntimeError(
"Couldn't find read corner")
306 rawBbox.shift(offext)
307 rawDataBbox.shift(offext)
308 rawHOverscanBbox.shift(offext)
309 rawVOverscanBbox.shift(offext)
310 rawPrescanBbox.shift(offext)
315 record.setRawXYOffset(offset)
316 record.setName(str(amp[
'name']))
317 record.setReadoutCorner(readoutMap[readcorner])
318 record.setGain(float(amp[
'gain']))
319 record.setReadNoise(float(amp[
'readnoise']))
320 record.setLinearityCoeffs([float(amp[
'lin_coeffs']), ])
321 record.setLinearityType(str(amp[
'lin_type']))
322 record.setHasRawInfo(
True)
323 record.setRawFlipX(flipx)
324 record.setRawFlipY(flipy)
325 record.setRawBBox(rawBbox)
326 record.setRawDataBBox(rawDataBbox)
327 record.setRawHorizontalOverscanBBox(rawHOverscanBbox)
328 record.setRawVerticalOverscanBBox(rawVOverscanBbox)
329 record.setRawPrescanBBox(rawPrescanBbox)
330 record.set(linThreshKey, float(amp[
'lin_thresh']))
331 record.set(linMaxKey, float(amp[
'lin_max']))
332 record.set(linUnitsKey, str(amp[
'lin_units']))
334 saveCoeffs = (float(amp[
'lin_coeffs']),)
335 saveCoeffs += (np.nan, np.nan, np.nan)
336 self.
ampInfoDict[amp[
'ccd_name']][
'linInfo'][amp[
'name']] = \
337 {
'lincoeffs': saveCoeffs,
'lintype': str(amp[
'lin_type']),
338 'linthresh': float(amp[
'lin_thresh']),
'linmax': float(amp[
'lin_max']),
339 'linunits': str(amp[
'lin_units'])}
343 """!Make camera config and amp catalog dictionary, using default detector and amp files 345 @param[in] isLsstLike if True then there is one raw image per amplifier; 346 if False then there is one raw image per detector 348 detFile = os.path.join(self.
_afwTestDataDir,
"testCameraDetectors.dat")
353 camConfig.name =
"testCamera%s"%(
'LSST' if isLsstLike
else 'SC')
354 camConfig.detectorList = dict((i, detConfig)
355 for i, detConfig
in enumerate(detectorConfigs))
358 radialDistortCoeffs = [0.0, 1.0/pScaleRad,
361 tConfig.transform.name =
'inverted' 362 radialClass = afwGeom.transformRegistry[
'radial']
363 tConfig.transform.active.transform.retarget(radialClass)
364 tConfig.transform.active.transform.coeffs = radialDistortCoeffs
366 tmc.nativeSys = FOCAL_PLANE.getSysName()
367 tmc.transforms = {FIELD_ANGLE.getSysName(): tConfig}
368 camConfig.transformDict = tmc
369 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.
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)
Construct a DetectorWrapper.
std::shared_ptr< TransformPoint2ToPoint2 > makeRadialTransform(std::vector< double > const &forwardCoeffs, std::vector< double > const &inverseCoeffs)
A purely radial polynomial distortion.
A Detector and the data used to construct it.
An integer coordinate rectangle.
Describe a detector's orientation in the focal plane.
std::string getPackageDir(std::string const &packageName)
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, focalPlaneToField, pixelSizeMm)
Make a Transform whose forward direction converts PIXELS to TAN_PIXELS for one detector.
A configuration that represents (and can be used to construct) a Camera.
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.