lsst.afw  14.0-40-g0271be365
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, FIELD_ANGLE, PIXELS, TAN_PIXELS, ACTUAL_PIXELS, CameraSys, \
7  Detector, DetectorType, Orientation, TransformMap
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 = [FIELD_ANGLE, FOCAL_PLANE, PIXELS, TAN_PIXELS, ACTUAL_PIXELS]
16 cameraSysMap = dict((sys.getSysName(), sys) for sys in cameraSysList)
17 
18 
19 def makeDetector(detectorConfig, ampInfoCatalog, focalPlaneToField):
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 focalPlaneToField FOCAL_PLANE to FIELD_ANGLE Transform
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  focalPlaneToField = focalPlaneToField,
42  pixelSizeMm = pixelSizeMm,
43  )
44 
45  args = [
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  crosstalk = detectorConfig.getCrosstalk(len(ampInfoCatalog))
57  if crosstalk:
58  args.append(crosstalk)
59  return Detector(*args)
60 
61 
62 def copyDetector(detector, ampInfoCatalog=None):
63  """!Return a copy of a Detector
64 
65  @param detector The Detector to clone
66  @param ampInfoCatalog The ampInfoCatalog to use; default use original
67 
68  N.b. No deep copies are made; the input transformDict is used unmodified
69  """
70  if ampInfoCatalog is None:
71  ampInfoCatalog = detector.getAmpInfoCatalog()
72 
73  tm = detector.getTransformMap()
74  native = detector.getNativeCoordSys()
75  transformDict = dict()
76  for cs in tm:
77  if cs != native:
78  transformDict[cs] = tm.getTransform(native, cs)
79 
80  return Detector(detector.getName(), detector.getId(), detector.getType(),
81  detector.getSerial(), detector.getBBox(),
82  ampInfoCatalog, detector.getOrientation(), detector.getPixelSize(),
83  transformDict, detector.getCrosstalk())
84 
85 
86 def makeOrientation(detectorConfig):
87  """!Make an Orientation instance from a detector config
88 
89  @param detectorConfig config for this detector (an lsst.pex.config.Config)
90  @return orientation (an lsst.afw.cameraGeom.Orientation)
91  """
92  offset = afwGeom.Point2D(detectorConfig.offset_x, detectorConfig.offset_y)
93  refPos = afwGeom.Point2D(detectorConfig.refpos_x, detectorConfig.refpos_y)
94  yaw = afwGeom.Angle(detectorConfig.yawDeg, afwGeom.degrees)
95  pitch = afwGeom.Angle(detectorConfig.pitchDeg, afwGeom.degrees)
96  roll = afwGeom.Angle(detectorConfig.rollDeg, afwGeom.degrees)
97  return Orientation(offset, refPos, yaw, pitch, roll)
98 
99 
100 def makeTransformDict(transformConfigDict):
101  """!Make a dictionary of CameraSys: lsst.afw.geom.Transform from a config dict.
102 
103  @param transformConfigDict an lsst.pex.config.ConfigDictField from an lsst.afw.geom.Transform
104  registry; keys are camera system names.
105  @return a dict of CameraSys or CameraSysPrefix: lsst.afw.geom.Transform
106  """
107  resMap = dict()
108  if transformConfigDict is not None:
109  for key in transformConfigDict:
110  transform = transformConfigDict[key].transform.apply()
111  resMap[CameraSys(key)] = transform
112  return resMap
113 
114 
115 def makeCameraFromPath(cameraConfig, ampInfoPath, shortNameFunc,
116  pupilFactoryClass=PupilFactory):
117  """!Make a Camera instance from a directory of ampInfo files
118 
119  The directory must contain one ampInfo fits file for each detector in cameraConfig.detectorList.
120  The name of each ampInfo file must be shortNameFunc(fullDetectorName) + ".fits".
121 
122  @param[in] cameraConfig an instance of CameraConfig
123  @param[in] ampInfoPath path to ampInfo data files
124  @param[in] shortNameFunc a function that converts a long detector name to a short one
125  @param[in] pupilFactoryClass class to attach to camera; default afw.cameraGeom.PupilFactory
126  @return camera (an lsst.afw.cameraGeom.Camera)
127  """
128  ampInfoCatDict = dict()
129  for detectorConfig in cameraConfig.detectorList.values():
130  shortName = shortNameFunc(detectorConfig.name)
131  ampCatPath = os.path.join(ampInfoPath, shortName + ".fits")
132  ampInfoCatalog = AmpInfoCatalog.readFits(ampCatPath)
133  ampInfoCatDict[detectorConfig.name] = ampInfoCatalog
134 
135  return makeCameraFromCatalogs(cameraConfig, ampInfoCatDict, pupilFactoryClass)
136 
137 
138 def makeCameraFromCatalogs(cameraConfig, ampInfoCatDict,
139  pupilFactoryClass=PupilFactory):
140  """!Construct a Camera instance from a dictionary of detector name: AmpInfoCatalog
141 
142  @param[in] cameraConfig an instance of CameraConfig
143  @param[in] ampInfoCatDict a dictionary of detector name: AmpInfoCatalog
144  @param[in] pupilFactoryClass class to attach to camera; default afw.cameraGeom.PupilFactory
145  @return camera (an lsst.afw.cameraGeom.Camera)
146  """
147  nativeSys = cameraSysMap[cameraConfig.transformDict.nativeSys]
148  transformDict = makeTransformDict(cameraConfig.transformDict.transforms)
149  focalPlaneToField = transformDict[FIELD_ANGLE]
150  transformMap = TransformMap(nativeSys, transformDict)
151 
152  detectorList = []
153  for detectorConfig in cameraConfig.detectorList.values():
154  ampInfoCatalog = ampInfoCatDict[detectorConfig.name]
155 
156  detectorList.append(makeDetector(
157  detectorConfig = detectorConfig,
158  ampInfoCatalog = ampInfoCatalog,
159  focalPlaneToField = focalPlaneToField,
160  ))
161 
162  return Camera(cameraConfig.name, detectorList, transformMap, pupilFactoryClass)
def copyDetector(detector, ampInfoCatalog=None)
Return a copy of a Detector.
A registry of 2-dimensional coordinate transforms for a specific camera.
Definition: TransformMap.h:57
def makeCameraFromCatalogs(cameraConfig, ampInfoCatDict, pupilFactoryClass=PupilFactory)
Construct a Camera instance from a dictionary of detector name: AmpInfoCatalog.
An integer coordinate rectangle.
Definition: Box.h:55
Describe a detector's orientation in the focal plane.
Definition: Orientation.h:51
def makeOrientation(detectorConfig)
Make an Orientation instance from a detector config.
A class representing an angle.
Definition: Angle.h:102
def makeCameraFromPath(cameraConfig, ampInfoPath, shortNameFunc, pupilFactoryClass=PupilFactory)
Make a Camera instance from a directory of ampInfo files.
Information about a CCD or other imaging detector.
Definition: Detector.h:64
def makePixelToTanPixel(bbox, orientation, focalPlaneToField, pixelSizeMm)
Make a Transform whose forward direction converts PIXELS to TAN_PIXELS for one detector.
A collection of Detectors that also supports coordinate transformation.
Definition: camera.py:30
def makeTransformDict(transformConfigDict)
Make a dictionary of CameraSys: lsst.afw.geom.Transform from a config dict.
def makeDetector(detectorConfig, ampInfoCatalog, focalPlaneToField)
Make a Detector instance from a detector config and amp info catalog.