22 from __future__
import absolute_import, division, print_function
23 from builtins
import range
24 from .cameraGeomLib
import CameraPoint, CameraSysPrefix, 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 CameraTransformMap whose native system is FOCAL_PLANE
40 and that at least supports PUPIL 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.
67 def _transformFromNativeSys(self, nativePoint, toSys):
68 """!Transform a point in the native coordinate system to another coordinate system.
70 @param[in] nativePoint CameraPoint in the native system for the camera
71 @param[in] toSys destination CameraSys
72 @return CameraPoint in the destination CameraSys
74 if isinstance(toSys, CameraSysPrefix):
78 raise RuntimeError(
"No detectors found")
79 elif len(detList) > 1:
80 raise RuntimeError(
"More than one detector found")
83 return det.transform(nativePoint, toSys)
87 def _transformSingleSysArray(self, positionList, fromSys, toSys):
88 """!Transform an array of points from once CameraSys to another CameraSys
89 @warning This method only handles a single jump, not a transform linked by a common native sys.
91 @param[in] positionList List of Point2D objects, one per position
92 @param[in] fromSys Initial camera coordinate system
93 @param[in] toSys Destination camera coordinate system
95 @returns an array of Point2D objects containing the transformed coordinates in the destination system.
97 if fromSys.hasDetectorName():
98 det = self[fromSys.getDetectorname()]
99 detTrans = det.getTransfromMap()
100 return detTrans.transform(positionList, fromSys, toSys)
101 elif toSys.hasDetectorName():
102 det = self[toSys.getDetectorName()]
103 detTrans = det.getTransformMap()
104 return detTrans.transform(positionList, fromSys, toSys)
107 return self._transformMap.transform(positionList, fromSys, toSys)
109 "Could not find mapping from %s to %s"%(fromSys, toSys))
111 def _transformSingleSys(self, cameraPoint, toSys):
112 """!Transform a CameraPoint with a CameraSys to another CameraSys.
114 @warning This method only handles a single jump, not a transform linked by a common native sys.
116 @param[in] cameraPoint CameraPoint to transform
117 @param[in] toSys Destination coordinate system
119 fromSys = cameraPoint.getCameraSys()
120 if fromSys.hasDetectorName():
122 det = self[fromSys.getDetectorName()]
123 return det.transform(cameraPoint, toSys)
124 elif toSys.hasDetectorName():
126 det = self[toSys.getDetectorName()]
127 return det.transform(cameraPoint, toSys)
130 outPoint = self._transformMap.transform(
131 cameraPoint.getPoint(), cameraPoint.getCameraSys(), toSys)
132 return CameraPoint(outPoint, toSys)
133 raise RuntimeError(
"Could not find mapping from %s to %s" %
134 (cameraPoint.getCameraSys(), toSys))
137 """!Find the detectors that cover a given cameraPoint, or empty list
139 @param[in] cameraPoint position to use in lookup
140 @return a list of zero or more Detectors that overlap the specified point
148 for detector
in self:
149 cameraSys = detector.makeCameraSys(PIXELS)
150 detPoint = detector.transform(nativePoint, cameraSys)
153 if afwGeom.Box2D(detector.getBBox()).contains(detPoint.getPoint()):
154 detectorList.append(detector)
158 """!Find the detectors that cover a list of points specified by x and y coordinates in any system
160 @param[in] cameraPointList a list of cameraPoints
161 @param[in] coordSys the camera coordinate system in which cameraPointList is defined
162 @return a list of lists; each list contains the names of all detectors which contain the
171 for i
in range(len(cameraPointList)):
172 detectorList.append([])
174 for detector
in self:
175 coordMap = detector.getTransformMap()
176 cameraSys = detector.makeCameraSys(PIXELS)
177 detectorPointList = coordMap.transform(
180 for i, pt
in enumerate(detectorPointList):
182 detectorList[i].append(detector)
187 """!Obtain the transform registry.
189 @return a TransformMap
191 @note: TransformRegistries are immutable, so this should be safe.
196 """!Transform a CameraPoint to a different CameraSys
198 @param[in] cameraPoint CameraPoint to transform
199 @param[in] toSys Transform to this CameraSys
200 @return a CameraPoint in the the specified CameraSys
208 """!Make a CameraPoint from a Point2D and a CameraSys
210 @param[in] point an lsst.afw.geom.Point2D
211 @param[in] cameraSys a CameraSys
212 @return the CameraPoint
214 if isinstance(cameraSys, CameraSysPrefix):
216 "Use the detector method to make a camera point from a CameraSysPrefix.")
218 return CameraPoint(point, cameraSys)
219 if cameraSys.hasDetectorName():
221 return CameraPoint(point, cameraSys)
222 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.