LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
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, CameraSys, 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] detectorList: a sequence of detectors in index order
34  @param[in] transformMap: a CameraTransformMap whose native system is FOCAL_PLANE
35  and that at least supports PUPIL coordinates
36  """
37  self._name = name
38  self._transformMap = transformMap
39  self._nativeCameraSys = self._transformMap.getNativeCoordSys()
40  super(Camera, self).__init__(detectorList)
41 
42  def getName(self):
43  return self._name
44 
45  def _tranformFromNativeSys(self, nativePoint, toSys):
46  """ Transform a point in the native coordinate system to another point in an
47  arbitrary coordinate system.
48  @param[in] nativePoint: CameraPoint in the native system for the camera
49  @param[in] toSys: destination CameraSys
50  @return CameraPoint in the destination CameraSys
51  """
52  if isinstance(toSys, CameraSysPrefix):
53  # Must be in a detector. Find the detector and transform it.
54  detList = self.findDetectors(nativePoint)
55  if len(detList) == 0:
56  raise RuntimeError("No detectors found")
57  elif len(detList) > 1:
58  raise RuntimeError("More than one detector found")
59  else:
60  det = detList[0]
61  return det.transform(nativePoint, toSys)
62  else:
63  return self._transformSingleSys(nativePoint, toSys)
64 
65  def _transformSingleSys(self, cameraPoint, toSys):
66  """Transform a CameraPoint with a CameraSys to another CameraSys.
67  This method only handles a single jump, not a transform linked by a common native
68  sys.
69  @param[in] cameraPoint: CameraPoint to transform
70  @param[in] toSys: Destination coordinate system
71  """
72  fromSys = cameraPoint.getCameraSys()
73  if fromSys.hasDetectorName():
74  # use from detector to transform
75  det = self[fromSys.getDetectorName()]
76  return det.transform(cameraPoint, toSys)
77  elif toSys.hasDetectorName():
78  # use the to detector to transform
79  det = self[toSys.getDetectorName()]
80  return det.transform(cameraPoint, toSys)
81  elif toSys in self._transformMap:
82  # use camera transform map
83  outPoint = self._transformMap.transform(cameraPoint.getPoint(), cameraPoint.getCameraSys(), toSys)
84  return CameraPoint(outPoint, toSys)
85  raise RuntimeError("Could not find mapping from %s to %s"%(cameraPoint.getCameraSys(), toSys))
86 
87  def findDetectors(self, cameraPoint):
88  """Find the detectors that cover a given cameraPoint, or empty list
89 
90  @param[in] cameraPoint: position to use in lookup
91  @return a list of zero or more Detectors that overlap the specified point
92  """
93 
94  # first convert to focalPlane since the point may be in another overlapping detector
95  nativePoint = self._transformSingleSys(cameraPoint, self._nativeCameraSys)
96 
97  detectorList = []
98  for detector in self:
99  cameraSys = detector.makeCameraSys(PIXELS)
100  detPoint = detector.transform(nativePoint, cameraSys)
101  #This is safe because CameraPoint is not templated and getPoint() returns a Point2D.
102  if afwGeom.Box2D(detector.getBBox()).contains(detPoint.getPoint()):
103  detectorList.append(detector)
104  return detectorList
105 
106  def getTransformMap(self):
107  """Obtain a pointer to the transform registry.
108 
109  @return a TransformMap
110 
111  @note: TransformRegistries are immutable, so this should be safe.
112  """
113  return self._transformMap
114 
115  def transform(self, cameraPoint, toSys):
116  """Transform a CameraPoint to a different CameraSys
117  @param[in] cameraPoint: CameraPoint to transform
118  @param[in] toSys: Transform to this CameraSys
119  @return a CameraPoint in the new CameraSys
120  """
121  # All transform maps should know about the native coordinate system
122  nativePoint = self._transformSingleSys(cameraPoint, self._nativeCameraSys)
123  return self._tranformFromNativeSys(nativePoint, toSys)
124 
125 
126  def makeCameraPoint(self, point, cameraSys):
127  """Make a CameraPoint from a Point2D and a CameraSys
128 
129  @param[in] point: an lsst.afw.geom.Point2D
130  @param[in] cameraSys: a CameraSys
131  @return cameraPoint: a CameraPoint
132  """
133  if isinstance(cameraSys, CameraSysPrefix):
134  raise TypeError("Use the detector method to make a camera point from a CameraSysPrefix.")
135  if cameraSys in self._transformMap:
136  return CameraPoint(point, cameraSys)
137  if cameraSys.hasDetectorName():
138  if cameraSys in self[cameraSys.getDetectorName()].getTransformMap():
139  return CameraPoint(point, cameraSys)
140  raise RuntimeError("Could not find %s in any transformMap"%(cameraSys))
A floating-point coordinate rectangle geometry.
Definition: Box.h:271