lsst.afw  15.0-21-g91b8abf62
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, print_function
23 from builtins import range
24 from .cameraGeomLib import FOCAL_PLANE, PIXELS
25 from .detectorCollection import DetectorCollection
26 from .pupil import PupilFactory
27 import lsst.afw.geom as afwGeom
28 
29 
31  """!A collection of Detectors plus additional coordinate system support
32 
33  Camera.transform transforms points from one camera coordinate system to another.
34 
35  Camera.getTransform returns a transform between camera coordinate systems.
36 
37  Camera.findDetectors finds all detectors overlapping a specified point.
38  """
39 
40  def __init__(self, name, detectorList, transformMap, pupilFactoryClass=PupilFactory):
41  """!Construct a Camera
42 
43  @param[in] name name of camera
44  @param[in] detectorList a sequence of detectors in index order
45  @param[in] transformMap a TransformMap that at least supports
46  FOCAL_PLANE and FIELD_ANGLE coordinates
47  @param[in] pupilFactoryClass a PupilFactory class for this camera
48  [default: afw.cameraGeom.PupilFactory]
49  """
50  self._name = name
51  self._transformMap = transformMap
52  self._nativeCameraSys = FOCAL_PLANE
53  self._pupilFactoryClass = pupilFactoryClass
54  super(Camera, self).__init__(detectorList)
55 
56  def getName(self):
57  """!Return the camera name
58  """
59  return self._name
60 
61  def getPupilFactory(self, visitInfo, pupilSize, npix, **kwargs):
62  """!Construct a PupilFactory.
63 
64  @param[in] visitInfo VisitInfo object for a particular exposure.
65  @param[in] pupilSize Size in meters of constructed Pupil array.
66  Note that this may be larger than the actual
67  diameter of the illuminated pupil to
68  accommodate zero-padding.
69  @param[in] npix Constructed Pupils will be npix x npix.
70  @param[in] kwargs Other keyword arguments for the pupil factory
71  """
72  return self._pupilFactoryClass(visitInfo, pupilSize, npix, **kwargs)
73 
74  @property
75  def telescopeDiameter(self):
76  return self._pupilFactoryClass.telescopeDiameter
77 
78  def _getTransformFromOneTransformMap(self, fromSys, toSys):
79  """!Get a transform from one TransformMap
80 
81  `fromSys` and `toSys` must both be present in the same transform map,
82  but that transform map may be from any detector or this camera object.
83 
84  @param[in] fromSys Camera coordinate system of `position`
85  input points
86  @param[in] toSys Camera coordinate system of returned point(s)
87 
88  @return an lsst.afw.geom.TransformPoint2ToPoint2 that transforms from
89  `fromSys` to `toSys` in the forward direction
90 
91  @throws lsst.pex.exceptions.InvalidParameter if no transform is
92  available. This includes the case that fromSys specifies a known
93  detector and toSys specifies any other detector (known or unknown)
94  @throws KeyError if an unknown detector is specified
95  """
96  if fromSys.hasDetectorName():
97  det = self[fromSys.getDetectorName()]
98  return det.getTransformMap().getTransform(fromSys, toSys)
99  elif toSys.hasDetectorName():
100  det = self[toSys.getDetectorName()]
101  return det.getTransformMap().getTransform(fromSys, toSys)
102  else:
103  return self.getTransformMap().getTransform(fromSys, toSys)
104 
105  def findDetectors(self, point, cameraSys):
106  """!Find the detectors that cover a point in any camera system
107 
108  @param[in] point position to use in lookup (lsst.afw.geom.Point2D)
109  @param[in] cameraSys camera coordinate system of `point`
110  @return a list of zero or more Detectors that overlap the specified point
111  """
112  # convert `point` to the native coordinate system
113  transform = self._getTransformFromOneTransformMap(cameraSys, self._nativeCameraSys)
114  nativePoint = transform.applyForward(point)
115 
116  detectorList = []
117  for detector in self:
118  nativeToPixels = detector.getTransform(self._nativeCameraSys, PIXELS)
119  pointPixels = nativeToPixels.applyForward(nativePoint)
120  if afwGeom.Box2D(detector.getBBox()).contains(pointPixels):
121  detectorList.append(detector)
122  return detectorList
123 
124  def findDetectorsList(self, pointList, cameraSys):
125  """!Find the detectors that cover a list of points in any camera system
126 
127  @param[in] pointList a list of points (lsst.afw.geom.Point2D)
128  @param[in] cameraSys the camera coordinate system of the points in `pointList`
129  @return a list of lists; each list contains the names of all detectors
130  which contain the corresponding point
131  """
132 
133  # transform the points to the native coordinate system
134  transform = self._getTransformFromOneTransformMap(cameraSys, self._nativeCameraSys)
135  nativePointList = transform.applyForward(pointList)
136 
137  detectorList = []
138  for i in range(len(pointList)):
139  detectorList.append([])
140 
141  for detector in self:
142  pixelSys = detector.makeCameraSys(PIXELS)
143  transform = detector.getTransformMap().getTransform(self._nativeCameraSys, pixelSys)
144  detectorPointList = transform.applyForward(nativePointList)
145  box = afwGeom.Box2D(detector.getBBox())
146  for i, pt in enumerate(detectorPointList):
147  if box.contains(pt):
148  detectorList[i].append(detector)
149 
150  return detectorList
151 
152  def getTransform(self, fromSys, toSys):
153  """!Get a transform from one CameraSys to another
154 
155  @param[in] fromSys From CameraSys
156  @param[in] toSys To CameraSys
157  @return an lsst.afw.geom.TransformPoint2ToPoint2 that transforms from
158  `fromSys` to `toSys` in the forward direction
159 
160  @throws lsst.pex.exceptions.InvalidParameter if no transform is
161  available.
162  @throws KeyError if an unknown detector is specified
163  """
164  # All transform maps should know about the native coordinate system
165  fromSysToNative = self._getTransformFromOneTransformMap(fromSys, self._nativeCameraSys)
166  nativeToToSys = self._getTransformFromOneTransformMap(self._nativeCameraSys, toSys)
167  return fromSysToNative.then(nativeToToSys)
168 
169  def getTransformMap(self):
170  """!Obtain the transform registry.
171 
172  @return a TransformMap
173 
174  @note: TransformRegistries are immutable, so this should be safe.
175  """
176  return self._transformMap
177 
178  def transform(self, points, fromSys, toSys):
179  """!Transform a point or list of points from one camera coordinate system
180  to another
181 
182  @param[in] points an lsst.afw.geom.Point2D or list of Point2D
183  @param[in] fromSys Transform from this CameraSys
184  @param[in] toSys Transform to this CameraSys
185  @return `points` transformed to `toSys` (an lsst.afw.geom.Point2D
186  or list of Point2D)
187  """
188  transform = self.getTransform(fromSys, toSys)
189  return transform.applyForward(points)
def __init__(self, name, detectorList, transformMap, pupilFactoryClass=PupilFactory)
Construct a Camera.
Definition: camera.py:40
def getTransformMap(self)
Obtain the transform registry.
Definition: camera.py:169
def getName(self)
Return the camera name.
Definition: camera.py:56
def getPupilFactory(self, visitInfo, pupilSize, npix, kwargs)
Construct a PupilFactory.
Definition: camera.py:61
def findDetectors(self, point, cameraSys)
Find the detectors that cover a point in any camera system.
Definition: camera.py:105
def getTransform(self, fromSys, toSys)
Get a transform from one CameraSys to another.
Definition: camera.py:152
def _getTransformFromOneTransformMap(self, fromSys, toSys)
Get a transform from one TransformMap.
Definition: camera.py:78
def transform(self, points, fromSys, toSys)
Transform a point or list of points from one camera coordinate system to another. ...
Definition: camera.py:178
A collection of Detectors plus additional coordinate system support.
Definition: camera.py:30
A floating-point coordinate rectangle geometry.
Definition: Box.h:266
def findDetectorsList(self, pointList, cameraSys)
Find the detectors that cover a list of points in any camera system.
Definition: camera.py:124
An immutable collection of Detectors that can be accessed by name or ID.