22 from __future__
import absolute_import, division
23 from builtins
import range
24 from .cameraGeomLib
import CameraPoint, CameraSysPrefix, PIXELS
25 from .detectorCollection
import DetectorCollection
29 """!A collection of Detectors that also supports coordinate transformation
31 def __init__(self, name, detectorList, transformMap):
32 """!Construct a Camera
34 @param[in] name name of camera
35 @param[in] detectorList a sequence of detectors in index order
36 @param[in] transformMap a CameraTransformMap whose native system is FOCAL_PLANE
37 and that at least supports PUPIL coordinates
42 super(Camera, self).
__init__(detectorList)
45 """!Return the camera name
50 """!Transform a point in the native coordinate system to another coordinate system.
52 @param[in] nativePoint CameraPoint in the native system for the camera
53 @param[in] toSys destination CameraSys
54 @return CameraPoint in the destination CameraSys
56 if isinstance(toSys, CameraSysPrefix):
60 raise RuntimeError(
"No detectors found")
61 elif len(detList) > 1:
62 raise RuntimeError(
"More than one detector found")
65 return det.transform(nativePoint, toSys)
70 """!Transform an array of points from once CameraSys to another CameraSys
71 @warning This method only handles a single jump, not a transform linked by a common native sys.
73 @param[in] positionList List of Point2D objects, one per position
74 @param[in] fromSys Initial camera coordinate system
75 @param[in] toSys Destination camera coordinate system
77 @returns an array of Point2D objects containing the transformed coordinates in the destination system.
79 if fromSys.hasDetectorName():
80 det = self[fromSys.getDetectorname()]
81 detTrans = det.getTransfromMap()
82 return detTrans.transform(positionList, fromSys, toSys)
83 elif toSys.hasDetectorName():
84 det = self[toSys.getDetectorName()]
85 detTrans = det.getTransformMap()
86 return detTrans.transform(positionList, fromSys, toSys)
89 return self._transformMap.transform(positionList, fromSys, toSys)
90 raise RuntimeError(
"Could not find mapping from %s to %s"%(fromSys, toSys))
93 """!Transform a CameraPoint with a CameraSys to another CameraSys.
95 @warning This method only handles a single jump, not a transform linked by a common native sys.
97 @param[in] cameraPoint CameraPoint to transform
98 @param[in] toSys Destination coordinate system
100 fromSys = cameraPoint.getCameraSys()
101 if fromSys.hasDetectorName():
103 det = self[fromSys.getDetectorName()]
104 return det.transform(cameraPoint, toSys)
105 elif toSys.hasDetectorName():
107 det = self[toSys.getDetectorName()]
108 return det.transform(cameraPoint, toSys)
111 outPoint = self._transformMap.transform(cameraPoint.getPoint(), cameraPoint.getCameraSys(), toSys)
112 return CameraPoint(outPoint, toSys)
113 raise RuntimeError(
"Could not find mapping from %s to %s"%(cameraPoint.getCameraSys(), toSys))
116 """!Find the detectors that cover a given cameraPoint, or empty list
118 @param[in] cameraPoint position to use in lookup
119 @return a list of zero or more Detectors that overlap the specified point
125 for detector
in self:
126 cameraSys = detector.makeCameraSys(PIXELS)
127 detPoint = detector.transform(nativePoint, cameraSys)
129 if afwGeom.Box2D(detector.getBBox()).contains(detPoint.getPoint()):
130 detectorList.append(detector)
134 """!Find the detectors that cover a list of points specified by x and y coordinates in any system
136 @param[in] cameraPointList a list of cameraPoints
137 @param[in] coordSys the camera coordinate system in which cameraPointList is defined
138 @return a list of lists; each list contains the names of all detectors which contain the
146 for i
in range(len(cameraPointList)):
147 detectorList.append([])
149 for detector
in self:
150 coordMap = detector.getTransformMap()
151 cameraSys = detector.makeCameraSys(PIXELS)
152 detectorPointList = coordMap.transform(nativePointList, self.
_nativeCameraSys, cameraSys)
154 for i, pt
in enumerate(detectorPointList):
156 detectorList[i].append(detector)
161 """!Obtain the transform registry.
163 @return a TransformMap
165 @note: TransformRegistries are immutable, so this should be safe.
170 """!Transform a CameraPoint to a different CameraSys
172 @param[in] cameraPoint CameraPoint to transform
173 @param[in] toSys Transform to this CameraSys
174 @return a CameraPoint in the the specified CameraSys
181 """!Make a CameraPoint from a Point2D and a CameraSys
183 @param[in] point an lsst.afw.geom.Point2D
184 @param[in] cameraSys a CameraSys
185 @return the CameraPoint
187 if isinstance(cameraSys, CameraSysPrefix):
188 raise TypeError(
"Use the detector method to make a camera point from a CameraSysPrefix.")
190 return CameraPoint(point, cameraSys)
191 if cameraSys.hasDetectorName():
193 return CameraPoint(point, cameraSys)
194 raise RuntimeError(
"Could not find %s in any transformMap"%(cameraSys))
def makeCameraPoint
Make a CameraPoint from a Point2D and a CameraSys.
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.