22 from __future__
import absolute_import, division
23 from .cameraGeomLib
import CameraPoint, CameraSysPrefix, PIXELS
24 from .detectorCollection
import DetectorCollection
28 """!A collection of Detectors that also supports coordinate transformation
30 def __init__(self, name, detectorList, transformMap):
31 """!Construct a Camera
33 @param[in] name name of camera
34 @param[in] detectorList a sequence of detectors in index order
35 @param[in] transformMap a CameraTransformMap whose native system is FOCAL_PLANE
36 and that at least supports PUPIL coordinates
41 super(Camera, self).
__init__(detectorList)
44 """!Return the camera name
49 """!Transform a point in the native coordinate system to another coordinate system.
51 @param[in] nativePoint CameraPoint in the native system for the camera
52 @param[in] toSys destination CameraSys
53 @return CameraPoint in the destination CameraSys
55 if isinstance(toSys, CameraSysPrefix):
59 raise RuntimeError(
"No detectors found")
60 elif len(detList) > 1:
61 raise RuntimeError(
"More than one detector found")
64 return det.transform(nativePoint, toSys)
69 """!Transform an array of points from once CameraSys to another CameraSys
70 @warning This method only handles a single jump, not a transform linked by a common native sys.
72 @param[in] positionList List of Point2D objects, one per position
73 @param[in] fromSys Initial camera coordinate system
74 @param[in] toSys Destination camera coordinate system
76 @returns an array of Point2D objects containing the transformed coordinates in the destination system.
78 if fromSys.hasDetectorName():
79 det = self[fromSys.getDetectorname()]
80 detTrans = det.getTransfromMap()
81 return detTrans.transform(positionList, fromSys, toSys)
82 elif toSys.hasDetectorName():
83 det = self[toSys.getDetectorName()]
84 detTrans = det.getTransformMap()
85 return detTrans.transform(positionList, fromSys, toSys)
88 return self._transformMap.transform(positionList, fromSys, toSys)
89 raise RuntimeError(
"Could not find mapping from %s to %s"%(fromSys, toSys))
92 """!Transform a CameraPoint with a CameraSys to another CameraSys.
94 @warning This method only handles a single jump, not a transform linked by a common native sys.
96 @param[in] cameraPoint CameraPoint to transform
97 @param[in] toSys Destination coordinate system
99 fromSys = cameraPoint.getCameraSys()
100 if fromSys.hasDetectorName():
102 det = self[fromSys.getDetectorName()]
103 return det.transform(cameraPoint, toSys)
104 elif toSys.hasDetectorName():
106 det = self[toSys.getDetectorName()]
107 return det.transform(cameraPoint, toSys)
110 outPoint = self._transformMap.transform(cameraPoint.getPoint(), cameraPoint.getCameraSys(), toSys)
111 return CameraPoint(outPoint, toSys)
112 raise RuntimeError(
"Could not find mapping from %s to %s"%(cameraPoint.getCameraSys(), toSys))
115 """!Find the detectors that cover a given cameraPoint, or empty list
117 @param[in] cameraPoint position to use in lookup
118 @return a list of zero or more Detectors that overlap the specified point
124 for detector
in self:
125 cameraSys = detector.makeCameraSys(PIXELS)
126 detPoint = detector.transform(nativePoint, cameraSys)
128 if afwGeom.Box2D(detector.getBBox()).contains(detPoint.getPoint()):
129 detectorList.append(detector)
133 """!Find the detectors that cover a list of points specified by x and y coordinates in any system
135 @param[in] cameraPointList a list of cameraPoints
136 @param[in] coordSys the camera coordinate system in which cameraPointList is defined
137 @return a list of lists; each list contains the names of all detectors which contain the
145 for i
in range(len(cameraPointList)):
146 detectorList.append([])
148 for detector
in self:
149 coordMap = detector.getTransformMap()
150 cameraSys = detector.makeCameraSys(PIXELS)
151 detectorPointList = coordMap.transform(nativePointList, self.
_nativeCameraSys, cameraSys)
153 for i, pt
in enumerate(detectorPointList):
155 detectorList[i].append(detector)
160 """!Obtain the transform registry.
162 @return a TransformMap
164 @note: TransformRegistries are immutable, so this should be safe.
169 """!Transform a CameraPoint to a different CameraSys
171 @param[in] cameraPoint CameraPoint to transform
172 @param[in] toSys Transform to this CameraSys
173 @return a CameraPoint in the the specified CameraSys
180 """!Make a CameraPoint from a Point2D and a CameraSys
182 @param[in] point an lsst.afw.geom.Point2D
183 @param[in] cameraSys a CameraSys
184 @return the CameraPoint
186 if isinstance(cameraSys, CameraSysPrefix):
187 raise TypeError(
"Use the detector method to make a camera point from a CameraSysPrefix.")
189 return CameraPoint(point, cameraSys)
190 if cameraSys.hasDetectorName():
192 return CameraPoint(point, cameraSys)
193 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.