LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
cameraFactory.py
Go to the documentation of this file.
1 import os.path
2 import lsst.afw.geom as afwGeom
3 from lsst.afw.table import AmpInfoCatalog
4 from .cameraGeomLib import FOCAL_PLANE, PUPIL, PIXELS, TAN_PIXELS, ACTUAL_PIXELS, CameraSys, \
5  Detector, Orientation, CameraTransformMap
6 from .camera import Camera
7 from .makePixelToTanPixel import makePixelToTanPixel
8 
9 __all__ = ["makeCameraFromPath", "makeCameraFromCatalogs", "makeDetector"]
10 
11 cameraSysList = [PUPIL, FOCAL_PLANE, PIXELS, TAN_PIXELS, ACTUAL_PIXELS]
12 cameraSysMap = dict((sys.getSysName(), sys) for sys in cameraSysList)
13 
14 def makeDetector(detectorConfig, ampInfoCatalog, focalPlaneToPupil, plateScale):
15  """Make a detector object:
16 
17  @param detectorConfig -- config for this detector (an lsst.pex.config.Config)
18  @param ampInfoCatalog -- amplifier information for this detector (an lsst.afw.table.AmpInfoCatalog)
19  @param focalPlaneToPupil -- FOCAL_PLANE to PUPIL XYTransform
20  @param plateScale -- nominal plate scale (arcsec/mm)
21  @return detector (an lsst.afw.cameraGeom.Detector)
22  """
23  orientation = makeOrientation(detectorConfig)
24  pixelSizeMm = afwGeom.Extent2D(detectorConfig.pixelSize_x, detectorConfig.pixelSize_y)
25  transforms = makeTransformDict(detectorConfig.transformDict.transforms)
26  transforms[FOCAL_PLANE] = orientation.makePixelFpTransform(pixelSizeMm)
27 
28  llPoint = afwGeom.Point2I(detectorConfig.bbox_x0, detectorConfig.bbox_y0)
29  urPoint = afwGeom.Point2I(detectorConfig.bbox_x1, detectorConfig.bbox_y1)
30  bbox = afwGeom.Box2I(llPoint, urPoint)
31 
32  tanPixSys = CameraSys(TAN_PIXELS, detectorConfig.name)
33  transforms[tanPixSys] = makePixelToTanPixel(
34  bbox = bbox,
35  orientation = orientation,
36  focalPlaneToPupil = focalPlaneToPupil,
37  pixelSizeMm = pixelSizeMm,
38  plateScale = plateScale,
39  )
40 
41  return Detector(
42  detectorConfig.name,
43  detectorConfig.id,
44  detectorConfig.detectorType,
45  detectorConfig.serial,
46  bbox,
47  ampInfoCatalog,
48  orientation,
49  pixelSizeMm,
50  transforms,
51  )
52 
53 def makeOrientation(detectorConfig):
54  """Make an instance of an Orientation class
55 
56  @param detectorConfig -- config for this detector (an lsst.pex.config.Config)
57  @return orientation (an lsst.afw.cameraGeom.Orientation)
58  """
59  offset = afwGeom.Point2D(detectorConfig.offset_x, detectorConfig.offset_y)
60  refPos = afwGeom.Point2D(detectorConfig.refpos_x, detectorConfig.refpos_y)
61  yaw = afwGeom.Angle(detectorConfig.yawDeg, afwGeom.degrees)
62  pitch = afwGeom.Angle(detectorConfig.pitchDeg, afwGeom.degrees)
63  roll = afwGeom.Angle(detectorConfig.rollDeg, afwGeom.degrees)
64  return Orientation(offset, refPos, yaw, pitch, roll)
65 
66 def makeTransformDict(transformConfigDict):
67  """Make a dictionary of CameraSys: XYTransform.
68 
69  @param transformConfigDict -- an lsst.pex.config.ConfigDictField from an XYTransform registry;
70  keys are camera system names.
71  @return a dict of CameraSys or CameraSysPrefix: XYTransform
72  """
73  resMap = dict()
74  if transformConfigDict is not None:
75  for key in transformConfigDict:
76  transform = transformConfigDict[key].transform.apply()
77  resMap[CameraSys(key)] = transform
78  return resMap
79 
80 def makeCameraFromPath(cameraConfig, ampInfoPath, shortNameFunc):
81  """Construct a camera (lsst.afw.cameraGeom Camera)
82 
83  @param[in] cameraConfig: an instance of CameraConfig
84  @param[in] ampInfoPath: path to ampInfo data files
85  @param[in] shortNameFunc: a function that converts a long detector name to a short one
86  @return camera (an lsst.afw.cameraGeom.Camera)
87  """
88  ampInfoCatDict = dict()
89  for detectorConfig in cameraConfig.detectorList.itervalues():
90  shortName = shortNameFunc(detectorConfig.name)
91  ampCatPath = os.path.join(ampInfoPath, shortName + ".fits")
92  ampInfoCatalog = AmpInfoCatalog.readFits(ampCatPath)
93  ampInfoCatDict[detectorConfig.name] = ampInfoCatalog
94 
95  return makeCameraFromCatalogs(cameraConfig, ampInfoCatDict)
96 
97 def makeCameraFromCatalogs(cameraConfig, ampInfoCatDict):
98  """Construct a camera (lsst.afw.cameraGeom Camera)
99 
100  @param[in] cameraConfig: an instance of CameraConfig
101  @param[in] ampInfoCatDict: a dictionary keyed on the detector name of AmpInfoCatalog objects
102  @return camera (an lsst.afw.cameraGeom.Camera)
103  """
104  nativeSys = cameraSysMap[cameraConfig.transformDict.nativeSys]
105  transformDict = makeTransformDict(cameraConfig.transformDict.transforms)
106  focalPlaneToPupil = transformDict[PUPIL]
107  transformMap = CameraTransformMap(nativeSys, transformDict)
108 
109  detectorList = []
110  for detectorConfig in cameraConfig.detectorList.itervalues():
111  ampInfoCatalog = ampInfoCatDict[detectorConfig.name]
112 
113  detectorList.append(makeDetector(
114  detectorConfig = detectorConfig,
115  ampInfoCatalog = ampInfoCatalog,
116  focalPlaneToPupil = focalPlaneToPupil,
117  plateScale = cameraConfig.plateScale,
118  ))
119 
120  return Camera(cameraConfig.name, detectorList, transformMap)
An integer coordinate rectangle.
Definition: Box.h:53