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