LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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 instance from a detector config and amp info catalog
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 Orientation instance from a detector config
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: lsst.afw.geom.XYTransform from a config dict.
68 
69  @param transformConfigDict an lsst.pex.config.ConfigDictField from an lsst.afw.geom.XYTransform
70  registry; keys are camera system names.
71  @return a dict of CameraSys or CameraSysPrefix: lsst.afw.geom.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  """!Make a Camera instance from a directory of ampInfo files
82 
83  The directory must contain one ampInfo fits file for each detector in cameraConfig.detectorList.
84  The name of each ampInfo file must be shortNameFunc(fullDetectorName) + ".fits".
85 
86  @param[in] cameraConfig an instance of CameraConfig
87  @param[in] ampInfoPath path to ampInfo data files
88  @param[in] shortNameFunc a function that converts a long detector name to a short one
89  @return camera (an lsst.afw.cameraGeom.Camera)
90  """
91  ampInfoCatDict = dict()
92  for detectorConfig in cameraConfig.detectorList.itervalues():
93  shortName = shortNameFunc(detectorConfig.name)
94  ampCatPath = os.path.join(ampInfoPath, shortName + ".fits")
95  ampInfoCatalog = AmpInfoCatalog.readFits(ampCatPath)
96  ampInfoCatDict[detectorConfig.name] = ampInfoCatalog
97 
98  return makeCameraFromCatalogs(cameraConfig, ampInfoCatDict)
99 
100 def makeCameraFromCatalogs(cameraConfig, ampInfoCatDict):
101  """!Construct a Camera instance from a dictionary of detector name: AmpInfoCatalog
102 
103  @param[in] cameraConfig an instance of CameraConfig
104  @param[in] ampInfoCatDict a dictionary of detector name: AmpInfoCatalog
105  @return camera (an lsst.afw.cameraGeom.Camera)
106  """
107  nativeSys = cameraSysMap[cameraConfig.transformDict.nativeSys]
108  transformDict = makeTransformDict(cameraConfig.transformDict.transforms)
109  focalPlaneToPupil = transformDict[PUPIL]
110  transformMap = CameraTransformMap(nativeSys, transformDict)
111 
112  detectorList = []
113  for detectorConfig in cameraConfig.detectorList.itervalues():
114  ampInfoCatalog = ampInfoCatDict[detectorConfig.name]
115 
116  detectorList.append(makeDetector(
117  detectorConfig = detectorConfig,
118  ampInfoCatalog = ampInfoCatalog,
119  focalPlaneToPupil = focalPlaneToPupil,
120  plateScale = cameraConfig.plateScale,
121  ))
122 
123  return Camera(cameraConfig.name, detectorList, transformMap)
def makeTransformDict
Make a dictionary of CameraSys: lsst.afw.geom.XYTransform from a config dict.
An integer coordinate rectangle.
Definition: Box.h:53
def makeOrientation
Make an Orientation instance from a detector config.
def makeCameraFromPath
Make a Camera instance from a directory of ampInfo files.
def makePixelToTanPixel
Make an XYTransform whose forward direction converts PIXEL to TAN_PIXEL for one detector.
def makeDetector
Make a Detector instance from a detector config and amp info catalog.
def makeCameraFromCatalogs
Construct a Camera instance from a dictionary of detector name: AmpInfoCatalog.