LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
camera.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2014 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 from __future__ import absolute_import, division
23 from .cameraGeomLib import CameraPoint, CameraSysPrefix, PIXELS
24 from .detectorCollection import DetectorCollection
25 import lsst.afw.geom as afwGeom
26 
27 class Camera(DetectorCollection):
28  """!A collection of Detectors that also supports coordinate transformation
29  """
30  def __init__(self, name, detectorList, transformMap):
31  """!Construct a Camera
32 
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
37  """
38  self._name = name
39  self._transformMap = transformMap
40  self._nativeCameraSys = self._transformMap.getNativeCoordSys()
41  super(Camera, self).__init__(detectorList)
42 
43  def getName(self):
44  """!Return the camera name
45  """
46  return self._name
47 
48  def _tranformFromNativeSys(self, nativePoint, toSys):
49  """!Transform a point in the native coordinate system to another coordinate system.
50 
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
54  """
55  if isinstance(toSys, CameraSysPrefix):
56  # Must be in a detector. Find the detector and transform it.
57  detList = self.findDetectors(nativePoint)
58  if len(detList) == 0:
59  raise RuntimeError("No detectors found")
60  elif len(detList) > 1:
61  raise RuntimeError("More than one detector found")
62  else:
63  det = detList[0]
64  return det.transform(nativePoint, toSys)
65  else:
66  return self._transformSingleSys(nativePoint, toSys)
67 
68  def _transformSingleSys(self, cameraPoint, toSys):
69  """!Transform a CameraPoint with a CameraSys to another CameraSys.
70 
71  @warning This method only handles a single jump, not a transform linked by a common native sys.
72 
73  @param[in] cameraPoint CameraPoint to transform
74  @param[in] toSys Destination coordinate system
75  """
76  fromSys = cameraPoint.getCameraSys()
77  if fromSys.hasDetectorName():
78  # use from detector to transform
79  det = self[fromSys.getDetectorName()]
80  return det.transform(cameraPoint, toSys)
81  elif toSys.hasDetectorName():
82  # use the to detector to transform
83  det = self[toSys.getDetectorName()]
84  return det.transform(cameraPoint, toSys)
85  elif toSys in self._transformMap:
86  # use camera transform map
87  outPoint = self._transformMap.transform(cameraPoint.getPoint(), cameraPoint.getCameraSys(), toSys)
88  return CameraPoint(outPoint, toSys)
89  raise RuntimeError("Could not find mapping from %s to %s"%(cameraPoint.getCameraSys(), toSys))
90 
91  def findDetectors(self, cameraPoint):
92  """!Find the detectors that cover a given cameraPoint, or empty list
93 
94  @param[in] cameraPoint position to use in lookup
95  @return a list of zero or more Detectors that overlap the specified point
96  """
97  # first convert to focalPlane since the point may be in another overlapping detector
98  nativePoint = self._transformSingleSys(cameraPoint, self._nativeCameraSys)
99 
100  detectorList = []
101  for detector in self:
102  cameraSys = detector.makeCameraSys(PIXELS)
103  detPoint = detector.transform(nativePoint, cameraSys)
104  #This is safe because CameraPoint is not templated and getPoint() returns a Point2D.
105  if afwGeom.Box2D(detector.getBBox()).contains(detPoint.getPoint()):
106  detectorList.append(detector)
107  return detectorList
108 
109  def getTransformMap(self):
110  """!Obtain a pointer to the transform registry.
111 
112  @return a TransformMap
113 
114  @note: TransformRegistries are immutable, so this should be safe.
115  """
116  return self._transformMap
117 
118  def transform(self, cameraPoint, toSys):
119  """!Transform a CameraPoint to a different CameraSys
120 
121  @param[in] cameraPoint CameraPoint to transform
122  @param[in] toSys Transform to this CameraSys
123  @return a CameraPoint in the the specified CameraSys
124  """
125  # All transform maps should know about the native coordinate system
126  nativePoint = self._transformSingleSys(cameraPoint, self._nativeCameraSys)
127  return self._tranformFromNativeSys(nativePoint, toSys)
128 
129  def makeCameraPoint(self, point, cameraSys):
130  """!Make a CameraPoint from a Point2D and a CameraSys
131 
132  @param[in] point an lsst.afw.geom.Point2D
133  @param[in] cameraSys a CameraSys
134  @return the CameraPoint
135  """
136  if isinstance(cameraSys, CameraSysPrefix):
137  raise TypeError("Use the detector method to make a camera point from a CameraSysPrefix.")
138  if cameraSys in self._transformMap:
139  return CameraPoint(point, cameraSys)
140  if cameraSys.hasDetectorName():
141  if cameraSys in self[cameraSys.getDetectorName()].getTransformMap():
142  return CameraPoint(point, cameraSys)
143  raise RuntimeError("Could not find %s in any transformMap"%(cameraSys))
def makeCameraPoint
Make a CameraPoint from a Point2D and a CameraSys.
Definition: camera.py:129
def getTransformMap
Obtain a pointer to the transform registry.
Definition: camera.py:109
def _tranformFromNativeSys
Transform a point in the native coordinate system to another coordinate system.
Definition: camera.py:48
def transform
Transform a CameraPoint to a different CameraSys.
Definition: camera.py:118
def __init__
Construct a Camera.
Definition: camera.py:30
A collection of Detectors that also supports coordinate transformation.
Definition: camera.py:27
def findDetectors
Find the detectors that cover a given cameraPoint, or empty list.
Definition: camera.py:91
def getName
Return the camera name.
Definition: camera.py:43
A floating-point coordinate rectangle geometry.
Definition: Box.h:271
def _transformSingleSys
Transform a CameraPoint with a CameraSys to another CameraSys.
Definition: camera.py:68