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