8 from .cameraGeomLib
import PIXELS, TAN_PIXELS, FIELD_ANGLE, FOCAL_PLANE, SCIENCE, ACTUAL_PIXELS, \
9 CameraSys, Detector, Orientation
10 from .cameraConfig
import DetectorConfig, CameraConfig
11 from .cameraFactory
import makeCameraFromCatalogs
12 from .makePixelToTanPixel
import makePixelToTanPixel
13 from .transformConfig
import TransformMapConfig
15 __all__ = [
"DetectorWrapper",
"CameraWrapper"]
19 """!A Detector and the data used to construct it 21 Intended for use with unit tests, thus saves a copy of all input parameters. 22 Does not support setting details of amplifiers. 32 pixelSize=(0.02, 0.02),
36 radialDistortion=0.925,
40 """!Construct a DetectorWrapper 42 @param[in] name detector name 43 @param[in] id detector ID (int) 44 @param[in] detType detector type (an lsst.afw.cameraGeom.DetectorType) 45 @param[in] serial serial "number" (a string) 46 @param[in] bbox bounding box; defaults to (0, 0), (1024x1024) (an lsst.afw.geom.Box2I) 47 @param[in] numAmps number of amplifiers (int) 48 @param[in] pixelSize pixel size (mm) (an lsst.afw.geom.Point2D) 49 @param[in] ampExtent dimensions of amplifier image bbox (an lsst.afw.geom.Extent2I) 50 @param[in] orientation orientation of CCC in focal plane (lsst.afw.cameraGeom.Orientation) 51 @param[in] plateScale plate scale in arcsec/mm; 20.0 is for LSST 52 @param[in] radialDistortion radial distortion, in mm/rad^2 53 (the r^3 coefficient of the radial distortion polynomial 54 that converts FIELD_ANGLE in radians to FOCAL_PLANE in mm); 55 0.925 is the value Dave Monet measured for lsstSim data 56 @param[in] crosstalk crosstalk coefficient matrix 57 @param[in] modFunc a function that can modify attributes just before constructing the detector; 58 modFunc receives one argument: a DetectorWrapper with all attributes except detector set. 74 schema = afwTable.AmpInfoTable.makeMinimalSchema()
75 self.
ampInfo = afwTable.AmpInfoCatalog(schema)
76 for i
in range(numAmps):
78 ampName =
"amp %d" % (i + 1,)
79 record.setName(ampName)
82 record.setGain(1.71234e3)
83 record.setReadNoise(0.521237e2)
84 record.setReadoutCorner(afwTable.LL)
85 record.setHasRawInfo(
False)
90 radialDistortCoeffs = [0.0, 1.0/pScaleRad,
96 focalPlaneToField=focalPlaneToField,
105 if crosstalk
is None:
106 crosstalk = [[0.0
for _
in range(numAmps)]
for _
in range(numAmps)]
120 np.array(self.
crosstalk, dtype=np.float32),
125 """A simple Camera and the data used to construct it 127 Intended for use with unit tests, thus saves some interesting information. 130 def __init__(self, plateScale=20.0, radialDistortion=0.925, isLsstLike=False):
131 """!Construct a CameraWrapper 133 @param[in] plateScale plate scale in arcsec/mm; 20.0 is for LSST 134 @param[in] radialDistortion radial distortion, in mm/rad^2 135 (the r^3 coefficient of the radial distortion polynomial 136 that converts FIELD_ANGLE in radians to FOCAL_PLANE in mm); 137 0.925 is the value Dave Monet measured for lsstSim data 138 @param[in] isLsstLike make repository products with one raw image per amplifier (True) 139 or with one raw image per detector (False) 143 "cameraGeom",
"testData")
159 """!Return the number of detectors""" 163 """!Construct a list of DetectorConfig, one per detector 168 with open(detFile)
as fh:
169 names = fh.readline().rstrip().lstrip(
"#").split(
"|")
171 els = l.rstrip().split(
"|")
172 detectorProps = dict([(name, el)
173 for name, el
in zip(names, els)])
174 detectors.append(detectorProps)
176 for i, detector
in enumerate(detectors):
177 detectorId = (i + 1) * 10
178 detectorName = detector[
'name']
180 detConfig.name = detectorName
181 detConfig.id = detectorId
182 detConfig.bbox_x0 = 0
183 detConfig.bbox_y0 = 0
184 detConfig.bbox_x1 = int(detector[
'npix_x']) - 1
185 detConfig.bbox_y1 = int(detector[
'npix_y']) - 1
186 detConfig.serial = str(detector[
'serial'])
187 detConfig.detectorType = int(detector[
'detectorType'])
188 detConfig.offset_x = float(detector[
'x'])
189 detConfig.offset_y = float(detector[
'y'])
190 detConfig.refpos_x = float(detector[
'refPixPos_x'])
191 detConfig.refpos_y = float(detector[
'refPixPos_y'])
192 detConfig.yawDeg = float(detector[
'yaw'])
193 detConfig.pitchDeg = float(detector[
'pitch'])
194 detConfig.rollDeg = float(detector[
'roll'])
195 detConfig.pixelSize_x = float(detector[
'pixelSize'])
196 detConfig.pixelSize_y = float(detector[
'pixelSize'])
197 detConfig.transposeDetector =
False 198 detConfig.transformDict.nativeSys = PIXELS.getSysName()
199 detectorConfigs.append(detConfig)
202 return detectorConfigs
205 """!Construct a list of AmpInfoCatalog, one per detector 207 @param[in] ampFile path to amplifier data file 208 @param[in] isLsstLike if True then there is one raw image per amplifier; 209 if False then there is one raw image per detector 212 'LL': afwTable.ReadoutCorner.LL,
213 'LR': afwTable.ReadoutCorner.LR,
214 'UR': afwTable.ReadoutCorner.UR, 215 'UL': afwTable.ReadoutCorner.UL,
218 with open(ampFile)
as fh:
219 names = fh.readline().rstrip().lstrip(
"#").split(
"|")
221 els = l.rstrip().split(
"|")
222 ampProps = dict([(name, el)
for name, el
in zip(names, els)])
223 amps.append(ampProps)
225 schema = afwTable.AmpInfoTable.makeMinimalSchema()
226 linThreshKey = schema.addField(
'linearityThreshold', type=np.float64)
227 linMaxKey = schema.addField(
'linearityMaximum', type=np.float64)
228 linUnitsKey = schema.addField(
'linearityUnits', type=str, size=9)
231 if amp[
'ccd_name']
in ampTablesDict:
232 ampCatalog = ampTablesDict[amp[
'ccd_name']]
235 ampCatalog = afwTable.AmpInfoCatalog(schema)
236 ampTablesDict[amp[
'ccd_name']] = ampCatalog
237 self.
ampInfoDict[amp[
'ccd_name']] = {
'namps': 1,
'linInfo': {}}
238 record = ampCatalog.addNew()
240 int(amp[
'trimmed_ymin'])),
242 int(amp[
'trimmed_ymax'])))
244 int(amp[
'raw_ymin'])),
246 int(amp[
'raw_ymax'])))
249 int(amp[
'raw_data_ymin'])),
251 int(amp[
'raw_data_ymax'])))
254 int(amp[
'hoscan_ymin'])),
256 int(amp[
'hoscan_ymax'])))
259 int(amp[
'voscan_ymin'])),
261 int(amp[
'voscan_ymax'])))
264 int(amp[
'pscan_ymin'])),
266 int(amp[
'pscan_ymax'])))
267 xoffset = int(amp[
'x_offset'])
268 yoffset = int(amp[
'y_offset'])
269 flipx = bool(int(amp[
'flipx']))
270 flipy = bool(int(amp[
'flipy']))
275 xExt = rawBbox.getDimensions().getX()
277 rawDataBbox.flipLR(xExt)
278 rawHOverscanBbox.flipLR(xExt)
279 rawVOverscanBbox.flipLR(xExt)
280 rawPrescanBbox.flipLR(xExt)
282 yExt = rawBbox.getDimensions().getY()
284 rawDataBbox.flipTB(yExt)
285 rawHOverscanBbox.flipTB(yExt)
286 rawVOverscanBbox.flipTB(yExt)
287 rawPrescanBbox.flipTB(yExt)
288 if not flipx
and not flipy:
290 elif flipx
and not flipy:
292 elif flipx
and flipy:
294 elif not flipx
and flipy:
297 raise RuntimeError(
"Couldn't find read corner")
301 rawBbox.shift(offext)
302 rawDataBbox.shift(offext)
303 rawHOverscanBbox.shift(offext)
304 rawVOverscanBbox.shift(offext)
305 rawPrescanBbox.shift(offext)
310 record.setRawXYOffset(offset)
311 record.setName(str(amp[
'name']))
312 record.setReadoutCorner(readoutMap[readcorner])
313 record.setGain(float(amp[
'gain']))
314 record.setReadNoise(float(amp[
'readnoise']))
315 record.setLinearityCoeffs([float(amp[
'lin_coeffs']), ])
316 record.setLinearityType(str(amp[
'lin_type']))
317 record.setHasRawInfo(
True)
318 record.setRawFlipX(flipx)
319 record.setRawFlipY(flipy)
320 record.setRawBBox(rawBbox)
321 record.setRawDataBBox(rawDataBbox)
322 record.setRawHorizontalOverscanBBox(rawHOverscanBbox)
323 record.setRawVerticalOverscanBBox(rawVOverscanBbox)
324 record.setRawPrescanBBox(rawPrescanBbox)
325 record.set(linThreshKey, float(amp[
'lin_thresh']))
326 record.set(linMaxKey, float(amp[
'lin_max']))
327 record.set(linUnitsKey, str(amp[
'lin_units']))
329 saveCoeffs = (float(amp[
'lin_coeffs']),)
330 saveCoeffs += (np.nan, np.nan, np.nan)
331 self.
ampInfoDict[amp[
'ccd_name']][
'linInfo'][amp[
'name']] = \
332 {
'lincoeffs': saveCoeffs,
'lintype': str(amp[
'lin_type']),
333 'linthresh': float(amp[
'lin_thresh']),
'linmax': float(amp[
'lin_max']),
334 'linunits': str(amp[
'lin_units'])}
338 """!Make camera config and amp catalog dictionary, using default detector and amp files 340 @param[in] isLsstLike if True then there is one raw image per amplifier; 341 if False then there is one raw image per detector 343 detFile = os.path.join(self.
_afwTestDataDir,
"testCameraDetectors.dat")
348 camConfig.name =
"testCamera%s"%(
'LSST' if isLsstLike
else 'SC')
349 camConfig.detectorList = dict((i, detConfig)
350 for i, detConfig
in enumerate(detectorConfigs))
353 radialDistortCoeffs = [0.0, 1.0/pScaleRad,
356 tConfig.transform.name =
'inverted' 357 radialClass = afwGeom.transformRegistry[
'radial']
358 tConfig.transform.active.transform.retarget(radialClass)
359 tConfig.transform.active.transform.coeffs = radialDistortCoeffs
361 tmc.nativeSys = FOCAL_PLANE.getSysName()
362 tmc.transforms = {FIELD_ANGLE.getSysName(): tConfig}
363 camConfig.transformDict = tmc
364 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.
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.
std::shared_ptr< TransformPoint2ToPoint2 > makeRadialTransform(std::vector< double > const &forwardCoeffs, std::vector< double > const &inverseCoeffs)
A purely radial polynomial distortion.
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.