LSSTApplications  16.0-1-gce273f5+20,16.0-10-g1758552,16.0-10-gc1446dd+21,16.0-12-g569485f+3,16.0-13-g5f20d24+1,16.0-13-g80874fd+2,16.0-13-gb122224+12,16.0-14-g08f9460+4,16.0-14-g8a3b804,16.0-14-ga5060d2,16.0-15-g77ef378+7,16.0-18-gdf247dd+2,16.0-18-ge18fa5b,16.0-18-ge4151178,16.0-2-g0febb12+16,16.0-2-g9d5294e+46,16.0-2-gc6e0ed0+5,16.0-23-ge8a9b866+3,16.0-3-g404ea43+13,16.0-3-gbc759ec+19,16.0-3-gcfd6c53+44,16.0-3-ge00e371,16.0-4-g03cf288+35,16.0-4-g13a27c5+21,16.0-4-g5f3a788+15,16.0-4-ga3eb747+5,16.0-5-g1991253+21,16.0-5-g1e9226d+3,16.0-5-g6a53317,16.0-5-g865efd9+23,16.0-5-gb3f8a4b+53,16.0-5-gd0f1235+10,16.0-52-gad2f36c79,16.0-7-g6043bfc+9,16.0-7-gd2eeba5+3,16.0-7-gde5bd64+3,16.0-8-g0e813a6+1,16.0-9-g52c50f7,16.0-9-g73415e6,master-g5768c874b9+5,w.2018.41
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 lsst.pex.exceptions import InvalidParameterError
23 import lsst.geom
24 from .cameraGeomLib import FOCAL_PLANE, PIXELS
25 from .detectorCollection import DetectorCollection
26 from .pupil import PupilFactory
27 
28 
30  """!A collection of Detectors plus additional coordinate system support
31 
32  Camera.transform transforms points from one camera coordinate system to another.
33 
34  Camera.getTransform returns a transform between camera coordinate systems.
35 
36  Camera.findDetectors finds all detectors overlapping a specified point.
37  """
38 
39  def __init__(self, name, detectorList, transformMap, pupilFactoryClass=PupilFactory):
40  """!Construct a Camera
41 
42  @param[in] name name of camera
43  @param[in] detectorList a sequence of detectors in index order
44  @param[in] transformMap a TransformMap that at least supports
45  FOCAL_PLANE and FIELD_ANGLE coordinates
46  @param[in] pupilFactoryClass a PupilFactory class for this camera
47  [default: afw.cameraGeom.PupilFactory]
48  """
49  self._name = name
50  self._transformMap = transformMap
51  self._nativeCameraSys = FOCAL_PLANE
52  self._pupilFactoryClass = pupilFactoryClass
53  super(Camera, self).__init__(detectorList)
54 
55  def getName(self):
56  """!Return the camera name
57  """
58  return self._name
59 
60  def getPupilFactory(self, visitInfo, pupilSize, npix, **kwargs):
61  """!Construct a PupilFactory.
62 
63  @param[in] visitInfo VisitInfo object for a particular exposure.
64  @param[in] pupilSize Size in meters of constructed Pupil array.
65  Note that this may be larger than the actual
66  diameter of the illuminated pupil to
67  accommodate zero-padding.
68  @param[in] npix Constructed Pupils will be npix x npix.
69  @param[in] kwargs Other keyword arguments for the pupil factory
70  """
71  return self._pupilFactoryClass(visitInfo, pupilSize, npix, **kwargs)
72 
73  @property
74  def telescopeDiameter(self):
75  return self._pupilFactoryClass.telescopeDiameter
76 
77  def _getTransformFromOneTransformMap(self, fromSys, toSys):
78  """!Get a transform from one TransformMap
79 
80  `fromSys` and `toSys` must both be present in the same transform map,
81  but that transform map may be from any detector or this camera object.
82 
83  @param[in] fromSys Camera coordinate system of `position`
84  input points
85  @param[in] toSys Camera coordinate system of returned point(s)
86 
87  @return an lsst.afw.geom.TransformPoint2ToPoint2 that transforms from
88  `fromSys` to `toSys` in the forward direction
89 
90  @throws lsst.pex.exceptions.InvalidParameterError if no transform is
91  available. This includes the case that fromSys specifies a known
92  detector and toSys specifies any other detector (known or unknown)
93  @throws KeyError if an unknown detector is specified
94  """
95  if fromSys.hasDetectorName():
96  det = self[fromSys.getDetectorName()]
97  return det.getTransformMap().getTransform(fromSys, toSys)
98  elif toSys.hasDetectorName():
99  det = self[toSys.getDetectorName()]
100  return det.getTransformMap().getTransform(fromSys, toSys)
101  else:
102  return self.getTransformMap().getTransform(fromSys, toSys)
103 
104  def findDetectors(self, point, cameraSys):
105  """!Find the detectors that cover a point in any camera system
106 
107  @param[in] point position to use in lookup (lsst.geom.Point2D)
108  @param[in] cameraSys camera coordinate system of `point`
109  @return a list of zero or more Detectors that overlap the specified point
110  """
111  # convert `point` to the native coordinate system
112  transform = self._getTransformFromOneTransformMap(cameraSys, self._nativeCameraSys)
113  nativePoint = transform.applyForward(point)
114 
115  detectorList = []
116  for detector in self:
117  nativeToPixels = detector.getTransform(self._nativeCameraSys, PIXELS)
118  pointPixels = nativeToPixels.applyForward(nativePoint)
119  if lsst.geom.Box2D(detector.getBBox()).contains(pointPixels):
120  detectorList.append(detector)
121  return detectorList
122 
123  def findDetectorsList(self, pointList, cameraSys):
124  """!Find the detectors that cover a list of points in any camera system
125 
126  @param[in] pointList a list of points (lsst.geom.Point2D)
127  @param[in] cameraSys the camera coordinate system of the points in `pointList`
128  @return a list of lists; each list contains the names of all detectors
129  which contain the corresponding point
130  """
131 
132  # transform the points to the native coordinate system
133  transform = self._getTransformFromOneTransformMap(cameraSys, self._nativeCameraSys)
134  nativePointList = transform.applyForward(pointList)
135 
136  detectorList = []
137  for i in range(len(pointList)):
138  detectorList.append([])
139 
140  for detector in self:
141  pixelSys = detector.makeCameraSys(PIXELS)
142  transform = detector.getTransformMap().getTransform(self._nativeCameraSys, pixelSys)
143  detectorPointList = transform.applyForward(nativePointList)
144  box = lsst.geom.Box2D(detector.getBBox())
145  for i, pt in enumerate(detectorPointList):
146  if box.contains(pt):
147  detectorList[i].append(detector)
148 
149  return detectorList
150 
151  def getTransform(self, fromSys, toSys):
152  """!Get a transform from one CameraSys to another
153 
154  @param[in] fromSys From CameraSys
155  @param[in] toSys To CameraSys
156  @return an lsst.afw.geom.TransformPoint2ToPoint2 that transforms from
157  `fromSys` to `toSys` in the forward direction
158 
159  @throws lsst.pex.exceptions.InvalidParameterError if no transform is
160  available.
161  @throws KeyError if an unknown detector is specified
162  """
163  # Cameras built via makeCameraFromConfig or makeCameraFromPath
164  # should now have all coordinate systems available in their
165  # transformMap.
166  try:
167  return self.getTransformMap().getTransform(fromSys, toSys)
168  except InvalidParameterError:
169  pass
170  # Camera must have been constructed an in an unusual way (which we
171  # still support for backwards compatibility).
172  # All transform maps should know about the native coordinate system
173  fromSysToNative = self._getTransformFromOneTransformMap(fromSys, self._nativeCameraSys)
174  nativeToToSys = self._getTransformFromOneTransformMap(self._nativeCameraSys, toSys)
175  return fromSysToNative.then(nativeToToSys)
176 
177  def getTransformMap(self):
178  """!Obtain the transform registry.
179 
180  @return a TransformMap
181 
182  @note: TransformRegistries are immutable, so this should be safe.
183  """
184  return self._transformMap
185 
186  def transform(self, points, fromSys, toSys):
187  """!Transform a point or list of points from one camera coordinate system
188  to another
189 
190  @param[in] points an lsst.geom.Point2D or list of Point2D
191  @param[in] fromSys Transform from this CameraSys
192  @param[in] toSys Transform to this CameraSys
193  @return `points` transformed to `toSys` (an lsst.geom.Point2D
194  or list of Point2D)
195  """
196  transform = self.getTransform(fromSys, toSys)
197  return transform.applyForward(points)
def __init__(self, name, detectorList, transformMap, pupilFactoryClass=PupilFactory)
Construct a Camera.
Definition: camera.py:39
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
A floating-point coordinate rectangle geometry.
Definition: Box.h:291
def getTransformMap(self)
Obtain the transform registry.
Definition: camera.py:177
def getName(self)
Return the camera name.
Definition: camera.py:55
def getPupilFactory(self, visitInfo, pupilSize, npix, kwargs)
Construct a PupilFactory.
Definition: camera.py:60
def findDetectors(self, point, cameraSys)
Find the detectors that cover a point in any camera system.
Definition: camera.py:104
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33
def getTransform(self, fromSys, toSys)
Get a transform from one CameraSys to another.
Definition: camera.py:151
def _getTransformFromOneTransformMap(self, fromSys, toSys)
Get a transform from one TransformMap.
Definition: camera.py:77
def transform(self, points, fromSys, toSys)
Transform a point or list of points from one camera coordinate system to another. ...
Definition: camera.py:186
A collection of Detectors plus additional coordinate system support.
Definition: camera.py:29
def findDetectorsList(self, pointList, cameraSys)
Find the detectors that cover a list of points in any camera system.
Definition: camera.py:123
An immutable collection of Detectors that can be accessed by name or ID.