lsst.afw  13.0-91-g2a3e2ee
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
cameraFactory.py
Go to the documentation of this file.
1 from __future__ import absolute_import, division, print_function
2 
3 import os.path
4 import lsst.afw.geom as afwGeom
5 from lsst.afw.table import AmpInfoCatalog
6 from .cameraGeomLib import FOCAL_PLANE, PUPIL, PIXELS, TAN_PIXELS, ACTUAL_PIXELS, CameraSys, \
7  Detector, DetectorType, Orientation, CameraTransformMap
8 from .camera import Camera
9 from .makePixelToTanPixel import makePixelToTanPixel
10 from .pupil import PupilFactory
11 
12 __all__ = ["makeCameraFromPath", "makeCameraFromCatalogs",
13  "makeDetector", "copyDetector"]
14 
15 cameraSysList = [PUPIL, FOCAL_PLANE, PIXELS, TAN_PIXELS, ACTUAL_PIXELS]
16 cameraSysMap = dict((sys.getSysName(), sys) for sys in cameraSysList)
17 
18 
19 def makeDetector(detectorConfig, ampInfoCatalog, focalPlaneToPupil):
20  """!Make a Detector instance from a detector config and amp info catalog
21 
22  @param detectorConfig config for this detector (an lsst.pex.config.Config)
23  @param ampInfoCatalog amplifier information for this detector (an lsst.afw.table.AmpInfoCatalog)
24  @param focalPlaneToPupil FOCAL_PLANE to PUPIL XYTransform
25  @return detector (an lsst.afw.cameraGeom.Detector)
26  """
27  orientation = makeOrientation(detectorConfig)
28  pixelSizeMm = afwGeom.Extent2D(
29  detectorConfig.pixelSize_x, detectorConfig.pixelSize_y)
30  transforms = makeTransformDict(detectorConfig.transformDict.transforms)
31  transforms[FOCAL_PLANE] = orientation.makePixelFpTransform(pixelSizeMm)
32 
33  llPoint = afwGeom.Point2I(detectorConfig.bbox_x0, detectorConfig.bbox_y0)
34  urPoint = afwGeom.Point2I(detectorConfig.bbox_x1, detectorConfig.bbox_y1)
35  bbox = afwGeom.Box2I(llPoint, urPoint)
36 
37  tanPixSys = CameraSys(TAN_PIXELS, detectorConfig.name)
38  transforms[tanPixSys] = makePixelToTanPixel(
39  bbox = bbox,
40  orientation = orientation,
41  focalPlaneToPupil = focalPlaneToPupil,
42  pixelSizeMm = pixelSizeMm,
43  )
44 
45  return Detector(
46  detectorConfig.name,
47  detectorConfig.id,
48  DetectorType(detectorConfig.detectorType),
49  detectorConfig.serial,
50  bbox,
51  ampInfoCatalog,
52  orientation,
53  pixelSizeMm,
54  transforms,
55  )
56 
57 
58 def copyDetector(detector, ampInfoCatalog=None):
59  """!Return a copy of a Detector
60 
61  @param detector The Detector to clone
62  @param ampInfoCatalog The ampInfoCatalog to use; default use original
63 
64  N.b. No deep copies are made; the input transformDict is used unmodified
65  """
66  if ampInfoCatalog is None:
67  ampInfoCatalog = detector.getAmpInfoCatalog()
68 
69  tm = detector.getTransformMap()
70  transformDict = dict()
71  for cs in tm.getCoordSysList():
72  if cs != tm.getNativeCoordSys():
73  transformDict[cs] = tm.get(cs)
74 
75  return Detector(detector.getName(), detector.getId(), detector.getType(),
76  detector.getSerial(), detector.getBBox(),
77  ampInfoCatalog, detector.getOrientation(), detector.getPixelSize(),
78  transformDict)
79 
80 
81 def makeOrientation(detectorConfig):
82  """!Make an Orientation instance from a detector config
83 
84  @param detectorConfig config for this detector (an lsst.pex.config.Config)
85  @return orientation (an lsst.afw.cameraGeom.Orientation)
86  """
87  offset = afwGeom.Point2D(detectorConfig.offset_x, detectorConfig.offset_y)
88  refPos = afwGeom.Point2D(detectorConfig.refpos_x, detectorConfig.refpos_y)
89  yaw = afwGeom.Angle(detectorConfig.yawDeg, afwGeom.degrees)
90  pitch = afwGeom.Angle(detectorConfig.pitchDeg, afwGeom.degrees)
91  roll = afwGeom.Angle(detectorConfig.rollDeg, afwGeom.degrees)
92  return Orientation(offset, refPos, yaw, pitch, roll)
93 
94 
95 def makeTransformDict(transformConfigDict):
96  """!Make a dictionary of CameraSys: lsst.afw.geom.XYTransform from a config dict.
97 
98  @param transformConfigDict an lsst.pex.config.ConfigDictField from an lsst.afw.geom.XYTransform
99  registry; keys are camera system names.
100  @return a dict of CameraSys or CameraSysPrefix: lsst.afw.geom.XYTransform
101  """
102  resMap = dict()
103  if transformConfigDict is not None:
104  for key in transformConfigDict:
105  transform = transformConfigDict[key].transform.apply()
106  resMap[CameraSys(key)] = transform
107  return resMap
108 
109 
110 def makeCameraFromPath(cameraConfig, ampInfoPath, shortNameFunc,
111  pupilFactoryClass=PupilFactory):
112  """!Make a Camera instance from a directory of ampInfo files
113 
114  The directory must contain one ampInfo fits file for each detector in cameraConfig.detectorList.
115  The name of each ampInfo file must be shortNameFunc(fullDetectorName) + ".fits".
116 
117  @param[in] cameraConfig an instance of CameraConfig
118  @param[in] ampInfoPath path to ampInfo data files
119  @param[in] shortNameFunc a function that converts a long detector name to a short one
120  @param[in] pupilFactoryClass class to attach to camera; default afw.cameraGeom.PupilFactory
121  @return camera (an lsst.afw.cameraGeom.Camera)
122  """
123  ampInfoCatDict = dict()
124  for detectorConfig in cameraConfig.detectorList.values():
125  shortName = shortNameFunc(detectorConfig.name)
126  ampCatPath = os.path.join(ampInfoPath, shortName + ".fits")
127  ampInfoCatalog = AmpInfoCatalog.readFits(ampCatPath)
128  ampInfoCatDict[detectorConfig.name] = ampInfoCatalog
129 
130  return makeCameraFromCatalogs(cameraConfig, ampInfoCatDict, pupilFactoryClass)
131 
132 
133 def makeCameraFromCatalogs(cameraConfig, ampInfoCatDict,
134  pupilFactoryClass=PupilFactory):
135  """!Construct a Camera instance from a dictionary of detector name: AmpInfoCatalog
136 
137  @param[in] cameraConfig an instance of CameraConfig
138  @param[in] ampInfoCatDict a dictionary of detector name: AmpInfoCatalog
139  @param[in] pupilFactoryClass class to attach to camera; default afw.cameraGeom.PupilFactory
140  @return camera (an lsst.afw.cameraGeom.Camera)
141  """
142  nativeSys = cameraSysMap[cameraConfig.transformDict.nativeSys]
143  transformDict = makeTransformDict(cameraConfig.transformDict.transforms)
144  focalPlaneToPupil = transformDict[PUPIL]
145  transformMap = CameraTransformMap(nativeSys, transformDict)
146 
147  detectorList = []
148  for detectorConfig in cameraConfig.detectorList.values():
149  ampInfoCatalog = ampInfoCatDict[detectorConfig.name]
150 
151  detectorList.append(makeDetector(
152  detectorConfig = detectorConfig,
153  ampInfoCatalog = ampInfoCatalog,
154  focalPlaneToPupil = focalPlaneToPupil,
155  ))
156 
157  return Camera(cameraConfig.name, detectorList, transformMap, pupilFactoryClass)
Camera coordinate system; used as a key in in TransformMap.
Definition: CameraSys.h:74
def makeTransformDict
Make a dictionary of CameraSys: lsst.afw.geom.XYTransform from a config dict.
An integer coordinate rectangle.
Definition: Box.h:55
Describe a detector's orientation in the focal plane.
Definition: Orientation.h:51
def copyDetector
Return a copy of a Detector.
A class representing an angle.
Definition: Angle.h:102
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.
Information about a CCD or other imaging detector.
Definition: Detector.h:64
def makeCameraFromCatalogs
Construct a Camera instance from a dictionary of detector name: AmpInfoCatalog.