22 from __future__
import absolute_import, division, print_function
23 from builtins
import range
24 from .cameraGeomLib
import CameraPoint, CameraSysPrefix, FOCAL_PLANE, PIXELS
25 from .detectorCollection
import DetectorCollection
26 from .pupil
import PupilFactory
31 """!A collection of Detectors that also supports coordinate transformation
34 def __init__(self, name, detectorList, transformMap, pupilFactoryClass=PupilFactory):
35 """!Construct a Camera
37 @param[in] name name of camera
38 @param[in] detectorList a sequence of detectors in index order
39 @param[in] transformMap a TransformMap that at least supports
40 FOCAL_PLANE and FIELD_ANGLE coordinates
41 @param[in] pupilFactoryClass a PupilFactory class for this camera
42 [default: afw.cameraGeom.PupilFactory]
48 super(Camera, self).
__init__(detectorList)
51 """!Return the camera name
56 """!Construct a PupilFactory.
58 @param[in] visitInfo VisitInfo object for a particular exposure.
59 @param[in] pupilSize Size in meters of constructed Pupil array.
60 Note that this may be larger than the actual
61 diameter of the illuminated pupil to
62 accommodate zero-padding.
63 @param[in] npix Constructed Pupils will be npix x npix.
69 return self._pupilFactoryClass.telescopeDiameter
71 def _transformFromNativeSys(self, nativePoint, toSys):
72 """!Transform a point in the native coordinate system to another coordinate system.
74 @param[in] nativePoint CameraPoint in the native system for the camera
75 @param[in] toSys destination CameraSys
76 @return CameraPoint in the destination CameraSys
78 if isinstance(toSys, CameraSysPrefix):
82 raise RuntimeError(
"No detectors found")
83 elif len(detList) > 1:
84 raise RuntimeError(
"More than one detector found")
87 return det.transform(nativePoint, toSys)
91 def _transformSingleSysArray(self, positionList, fromSys, toSys):
92 """!Transform an array of points from once CameraSys to another CameraSys
93 @warning This method only handles a single jump, not a transform linked by a common native sys.
95 @param[in] positionList List of Point2D objects, one per position
96 @param[in] fromSys Initial camera coordinate system
97 @param[in] toSys Destination camera coordinate system
99 @returns an array of Point2D objects containing the transformed coordinates in the destination system.
101 if fromSys.hasDetectorName():
102 det = self[fromSys.getDetectorname()]
103 detTrans = det.getTransfromMap()
104 return detTrans.transform(positionList, fromSys, toSys)
105 elif toSys.hasDetectorName():
106 det = self[toSys.getDetectorName()]
107 detTrans = det.getTransformMap()
108 return detTrans.transform(positionList, fromSys, toSys)
111 return self._transformMap.transform(positionList, fromSys, toSys)
113 "Could not find mapping from %s to %s"%(fromSys, toSys))
115 def _transformSingleSys(self, cameraPoint, toSys):
116 """!Transform a CameraPoint with a CameraSys to another CameraSys.
118 @warning This method only handles a single jump, not a transform linked by a common native sys.
120 @param[in] cameraPoint CameraPoint to transform
121 @param[in] toSys Destination coordinate system
123 fromSys = cameraPoint.getCameraSys()
124 if fromSys.hasDetectorName():
126 det = self[fromSys.getDetectorName()]
127 return det.transform(cameraPoint, toSys)
128 elif toSys.hasDetectorName():
130 det = self[toSys.getDetectorName()]
131 return det.transform(cameraPoint, toSys)
134 outPoint = self._transformMap.transform(
135 cameraPoint.getPoint(), cameraPoint.getCameraSys(), toSys)
136 return CameraPoint(outPoint, toSys)
137 raise RuntimeError(
"Could not find mapping from %s to %s" %
138 (cameraPoint.getCameraSys(), toSys))
141 """!Find the detectors that cover a given cameraPoint, or empty list
143 @param[in] cameraPoint position to use in lookup
144 @return a list of zero or more Detectors that overlap the specified point
152 for detector
in self:
153 cameraSys = detector.makeCameraSys(PIXELS)
154 detPoint = detector.transform(nativePoint, cameraSys)
157 if afwGeom.Box2D(detector.getBBox()).contains(detPoint.getPoint()):
158 detectorList.append(detector)
162 """!Find the detectors that cover a list of points specified by x and y coordinates in any system
164 @param[in] cameraPointList a list of cameraPoints
165 @param[in] coordSys the camera coordinate system in which cameraPointList is defined
166 @return a list of lists; each list contains the names of all detectors which contain the
175 for i
in range(len(cameraPointList)):
176 detectorList.append([])
178 for detector
in self:
179 coordMap = detector.getTransformMap()
180 cameraSys = detector.makeCameraSys(PIXELS)
181 detectorPointList = coordMap.transform(
184 for i, pt
in enumerate(detectorPointList):
186 detectorList[i].append(detector)
191 """!Obtain the transform registry.
193 @return a TransformMap
195 @note: TransformRegistries are immutable, so this should be safe.
200 """!Transform a CameraPoint to a different CameraSys
202 @param[in] cameraPoint CameraPoint to transform
203 @param[in] toSys Transform to this CameraSys
204 @return a CameraPoint in the the specified CameraSys
212 """!Make a CameraPoint from a Point2D and a CameraSys
214 @param[in] point an lsst.afw.geom.Point2D
215 @param[in] cameraSys a CameraSys
216 @return the CameraPoint
218 if isinstance(cameraSys, CameraSysPrefix):
220 "Use the detector method to make a camera point from a CameraSysPrefix.")
222 return CameraPoint(point, cameraSys)
223 if cameraSys.hasDetectorName():
225 return CameraPoint(point, cameraSys)
226 raise RuntimeError(
"Could not find %s in any transformMap"%(cameraSys))
def makeCameraPoint
Make a CameraPoint from a Point2D and a CameraSys.
def getPupilFactory
Construct a PupilFactory.
def getTransformMap
Obtain the transform registry.
def _transformSingleSysArray
Transform an array of points from once CameraSys to another CameraSys.
def findDetectorsList
Find the detectors that cover a list of points specified by x and y coordinates in any system...
def transform
Transform a CameraPoint to a different CameraSys.
def __init__
Construct a Camera.
A collection of Detectors that also supports coordinate transformation.
def findDetectors
Find the detectors that cover a given cameraPoint, or empty list.
def getName
Return the camera name.
A floating-point coordinate rectangle geometry.
def _transformSingleSys
Transform a CameraPoint with a CameraSys to another CameraSys.
def _transformFromNativeSys
Transform a point in the native coordinate system to another coordinate system.