9 from .cameraGeomLib
import PIXELS, TAN_PIXELS, FIELD_ANGLE, FOCAL_PLANE, SCIENCE, ACTUAL_PIXELS, \
10 CameraSys, Detector, Orientation
11 from .cameraConfig
import DetectorConfig, CameraConfig
12 from .cameraFactory
import makeCameraFromCatalogs
13 from .makePixelToTanPixel
import makePixelToTanPixel
14 from .transformConfig
import TransformMapConfig
16 __all__ = [
"DetectorWrapper",
"CameraWrapper"]
20 """!A Detector and the data used to construct it 22 Intended for use with unit tests, thus saves a copy of all input parameters. 23 Does not support setting details of amplifiers. 33 pixelSize=(0.02, 0.02),
37 radialDistortion=0.925,
41 """!Construct a DetectorWrapper 43 @param[in] name detector name 44 @param[in] id detector ID (int) 45 @param[in] detType detector type (an lsst.afw.cameraGeom.DetectorType) 46 @param[in] serial serial "number" (a string) 47 @param[in] bbox bounding box; defaults to (0, 0), (1024x1024) (an lsst.geom.Box2I) 48 @param[in] numAmps number of amplifiers (int) 49 @param[in] pixelSize pixel size (mm) (an lsst.geom.Point2D) 50 @param[in] ampExtent dimensions of amplifier image bbox (an lsst.geom.Extent2I) 51 @param[in] orientation orientation of CCC in focal plane (lsst.afw.cameraGeom.Orientation) 52 @param[in] plateScale plate scale in arcsec/mm; 20.0 is for LSST 53 @param[in] radialDistortion radial distortion, in mm/rad^2 54 (the r^3 coefficient of the radial distortion polynomial 55 that converts FIELD_ANGLE in radians to FOCAL_PLANE in mm); 56 0.925 is the value Dave Monet measured for lsstSim data 57 @param[in] crosstalk crosstalk coefficient matrix 58 @param[in] modFunc a function that can modify attributes just before constructing the detector; 59 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)
81 record.setGain(1.71234e3)
82 record.setReadNoise(0.521237e2)
83 record.setReadoutCorner(afwTable.LL)
84 record.setHasRawInfo(
False)
89 radialDistortCoeffs = [0.0, 1.0/pScaleRad,
91 focalPlaneToField = afwGeom.makeRadialTransform(radialDistortCoeffs)
95 focalPlaneToField=focalPlaneToField,
102 CameraSys(ACTUAL_PIXELS, self.
name): afwGeom.makeRadialTransform([0, 0.95, 0.01]),
104 if crosstalk
is None:
105 crosstalk = [[0.0
for _
in range(numAmps)]
for _
in range(numAmps)]
119 np.array(self.
crosstalk, dtype=np.float32),
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) 142 "cameraGeom",
"testData")
158 """!Return the number of detectors""" 162 """!Construct a list of DetectorConfig, one per detector 167 with open(detFile)
as fh:
168 names = fh.readline().rstrip().lstrip(
"#").split(
"|")
170 els = l.rstrip().split(
"|")
171 detectorProps = dict([(name, el)
172 for name, el
in zip(names, els)])
173 detectors.append(detectorProps)
175 for i, detector
in enumerate(detectors):
176 detectorId = (i + 1) * 10
177 detectorName = detector[
'name']
179 detConfig.name = detectorName
180 detConfig.id = detectorId
181 detConfig.bbox_x0 = 0
182 detConfig.bbox_y0 = 0
183 detConfig.bbox_x1 = int(detector[
'npix_x']) - 1
184 detConfig.bbox_y1 = int(detector[
'npix_y']) - 1
185 detConfig.serial = str(detector[
'serial'])
186 detConfig.detectorType = int(detector[
'detectorType'])
187 detConfig.offset_x = float(detector[
'x'])
188 detConfig.offset_y = float(detector[
'y'])
189 detConfig.refpos_x = float(detector[
'refPixPos_x'])
190 detConfig.refpos_y = float(detector[
'refPixPos_y'])
191 detConfig.yawDeg = float(detector[
'yaw'])
192 detConfig.pitchDeg = float(detector[
'pitch'])
193 detConfig.rollDeg = float(detector[
'roll'])
194 detConfig.pixelSize_x = float(detector[
'pixelSize'])
195 detConfig.pixelSize_y = float(detector[
'pixelSize'])
196 detConfig.transposeDetector =
False 197 detConfig.transformDict.nativeSys = PIXELS.getSysName()
198 detectorConfigs.append(detConfig)
201 return detectorConfigs
204 """!Construct a list of AmpInfoCatalog, one per detector 206 @param[in] ampFile path to amplifier data file 207 @param[in] isLsstLike if True then there is one raw image per amplifier; 208 if False then there is one raw image per detector 211 'LL': afwTable.ReadoutCorner.LL,
212 'LR': afwTable.ReadoutCorner.LR,
213 'UR': afwTable.ReadoutCorner.UR, 214 'UL': afwTable.ReadoutCorner.UL,
217 with open(ampFile)
as fh:
218 names = fh.readline().rstrip().lstrip(
"#").split(
"|")
220 els = l.rstrip().split(
"|")
221 ampProps = dict([(name, el)
for name, el
in zip(names, els)])
222 amps.append(ampProps)
224 schema = afwTable.AmpInfoTable.makeMinimalSchema()
225 linThreshKey = schema.addField(
'linearityThreshold', type=np.float64)
226 linMaxKey = schema.addField(
'linearityMaximum', type=np.float64)
227 linUnitsKey = schema.addField(
'linearityUnits', type=str, size=9)
230 if amp[
'ccd_name']
in ampTablesDict:
231 ampCatalog = ampTablesDict[amp[
'ccd_name']]
234 ampCatalog = afwTable.AmpInfoCatalog(schema)
235 ampTablesDict[amp[
'ccd_name']] = ampCatalog
236 self.
ampInfoDict[amp[
'ccd_name']] = {
'namps': 1,
'linInfo': {}}
237 record = ampCatalog.addNew()
239 int(amp[
'trimmed_ymin'])),
241 int(amp[
'trimmed_ymax'])))
243 int(amp[
'raw_ymin'])),
245 int(amp[
'raw_ymax'])))
248 int(amp[
'raw_data_ymin'])),
250 int(amp[
'raw_data_ymax'])))
253 int(amp[
'hoscan_ymin'])),
255 int(amp[
'hoscan_ymax'])))
258 int(amp[
'voscan_ymin'])),
260 int(amp[
'voscan_ymax'])))
263 int(amp[
'pscan_ymin'])),
265 int(amp[
'pscan_ymax'])))
266 xoffset = int(amp[
'x_offset'])
267 yoffset = int(amp[
'y_offset'])
268 flipx = bool(int(amp[
'flipx']))
269 flipy = bool(int(amp[
'flipy']))
274 xExt = rawBbox.getDimensions().getX()
276 rawDataBbox.flipLR(xExt)
277 rawHOverscanBbox.flipLR(xExt)
278 rawVOverscanBbox.flipLR(xExt)
279 rawPrescanBbox.flipLR(xExt)
281 yExt = rawBbox.getDimensions().getY()
283 rawDataBbox.flipTB(yExt)
284 rawHOverscanBbox.flipTB(yExt)
285 rawVOverscanBbox.flipTB(yExt)
286 rawPrescanBbox.flipTB(yExt)
287 if not flipx
and not flipy:
289 elif flipx
and not flipy:
291 elif flipx
and flipy:
293 elif not flipx
and flipy:
296 raise RuntimeError(
"Couldn't find read corner")
300 rawBbox.shift(offext)
301 rawDataBbox.shift(offext)
302 rawHOverscanBbox.shift(offext)
303 rawVOverscanBbox.shift(offext)
304 rawPrescanBbox.shift(offext)
309 record.setRawXYOffset(offset)
310 record.setName(str(amp[
'name']))
311 record.setReadoutCorner(readoutMap[readcorner])
312 record.setGain(float(amp[
'gain']))
313 record.setReadNoise(float(amp[
'readnoise']))
314 record.setLinearityCoeffs([float(amp[
'lin_coeffs']), ])
315 record.setLinearityType(str(amp[
'lin_type']))
316 record.setHasRawInfo(
True)
317 record.setRawFlipX(flipx)
318 record.setRawFlipY(flipy)
319 record.setRawBBox(rawBbox)
320 record.setRawDataBBox(rawDataBbox)
321 record.setRawHorizontalOverscanBBox(rawHOverscanBbox)
322 record.setRawVerticalOverscanBBox(rawVOverscanBbox)
323 record.setRawPrescanBBox(rawPrescanBbox)
324 record.set(linThreshKey, float(amp[
'lin_thresh']))
325 record.set(linMaxKey, float(amp[
'lin_max']))
326 record.set(linUnitsKey, str(amp[
'lin_units']))
328 saveCoeffs = (float(amp[
'lin_coeffs']),)
329 saveCoeffs += (np.nan, np.nan, np.nan)
330 self.
ampInfoDict[amp[
'ccd_name']][
'linInfo'][amp[
'name']] = \
331 {
'lincoeffs': saveCoeffs,
'lintype': str(amp[
'lin_type']),
332 'linthresh': float(amp[
'lin_thresh']),
'linmax': float(amp[
'lin_max']),
333 'linunits': str(amp[
'lin_units'])}
337 """!Make camera config and amp catalog dictionary, using default detector and amp files 339 @param[in] isLsstLike if True then there is one raw image per amplifier; 340 if False then there is one raw image per detector 342 detFile = os.path.join(self.
_afwTestDataDir,
"testCameraDetectors.dat")
347 camConfig.name =
"testCamera%s"%(
'LSST' if isLsstLike
else 'SC')
348 camConfig.detectorList = dict((i, detConfig)
349 for i, detConfig
in enumerate(detectorConfigs))
352 radialDistortCoeffs = [0.0, 1.0/pScaleRad,
354 tConfig = afwGeom.TransformConfig()
355 tConfig.transform.name =
'inverted' 356 radialClass = afwGeom.transformRegistry[
'radial']
357 tConfig.transform.active.transform.retarget(radialClass)
358 tConfig.transform.active.transform.coeffs = radialDistortCoeffs
360 tmc.nativeSys = FOCAL_PLANE.getSysName()
361 tmc.transforms = {FIELD_ANGLE.getSysName(): tConfig}
362 camConfig.transformDict = tmc
363 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.
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.