lsst.obs.base  15.0-9-ge25808d+2
camera_tests.py
Go to the documentation of this file.
1 from __future__ import absolute_import, division, print_function
2 from future.utils import with_metaclass
3 #
4 # LSST Data Management System
5 # Copyright 2016 LSST Corporation.
6 #
7 # This product includes software developed by the
8 # LSST Project (http://www.lsst.org/).
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the LSST License Statement and
21 # the GNU General Public License along with this program. If not,
22 # see <http://www.lsstcorp.org/LegalNotices/>.
23 #
24 import abc
25 import collections
26 import math
27 
28 import lsst.afw.geom
29 from lsst.afw.cameraGeom import FOCAL_PLANE, FIELD_ANGLE
30 
31 __all__ = ["CameraTests"]
32 
33 
34 class CameraTests(with_metaclass(abc.ABCMeta)):
35  """
36  Tests that the butler returns a useable Camera.
37 
38  In the subclasses's setUp():
39  * Call setUp_camera() to fill in required parameters.
40  """
41 
42  def setUp_camera(self,
43  camera_name=None,
44  n_detectors=None,
45  first_detector_name=None,
46  plate_scale=None,
47  ):
48  """
49  Set up the necessary variables for camera tests.
50 
51  Parameters
52  ----------
53 
54  camera_name : `str`
55  name of this camera
56  n_detectors : `int`
57  number of detectors in this camera
58  first_detector_name : `str`
59  name of the first detector in this camera
60  plate_scale : `lsst.afw.geom.Angle`
61  plate scale at center of focal plane, as angle-on-sky/mm
62  """
63  fields = ['camera_name',
64  'n_detectors',
65  'first_detector_name',
66  'plate_scale',
67  ]
68  CameraData = collections.namedtuple("CameraData", fields)
69  self.camera_data = CameraData(camera_name=camera_name,
70  n_detectors=n_detectors,
71  first_detector_name=first_detector_name,
72  plate_scale=plate_scale,
73  )
74 
75  def test_iterable(self):
76  """Simplest camera test: can we get a Camera instance, and does iterating return Detectors?"""
77  camera = self.butler.get('camera', immediate=True)
78  self.assertIsInstance(camera, lsst.afw.cameraGeom.Camera)
79  for detector in camera:
80  msg = "Failed for detector={}".format(detector)
81  self.assertIsInstance(detector, lsst.afw.cameraGeom.Detector, msg=msg)
82 
83  def test_camera_butler(self):
84  """Check that the butler returns the right type of camera."""
85  camera = self.butler.get('camera', immediate=True)
86  self.assertEqual(camera.getName(), self.camera_data.camera_name)
87  self.assertEqual(len(camera), self.camera_data.n_detectors)
88  self.assertEqual(next(iter(camera)).getName(), self.camera_data.first_detector_name)
89 
90  def test_plate_scale(self):
91  """Check the plate scale at center of focal plane
92 
93  Check plate_scale using the FOCAL_PLANE to FIELD_ANGLE transform
94  from the camera.
95  """
96  plate_scale = self.camera_data.plate_scale
97  self.assertIsNotNone(plate_scale)
98  camera = self.butler.get('camera', immediate=True)
99  focalPlaneToFieldAngle = camera.getTransformMap().getTransform(FOCAL_PLANE, FIELD_ANGLE)
100  focalPlaneRadiusMm = 0.001 # an offset small enough to be in the linear regime
101  for offsetAngleRad in (0.0, 0.65, 1.3): # direction of offset; a few arbitrary angles
102  cosAng = math.cos(offsetAngleRad)
103  sinAng = math.sin(offsetAngleRad)
104  fieldAngleRadians = focalPlaneToFieldAngle.applyForward(
105  lsst.afw.geom.Point2D(cosAng * focalPlaneRadiusMm, sinAng * focalPlaneRadiusMm))
106  fieldAngleRadius = math.hypot(*fieldAngleRadians) * lsst.afw.geom.radians
107  measuredScale1 = fieldAngleRadius / focalPlaneRadiusMm
108  self.assertAnglesAlmostEqual(measuredScale1, plate_scale)
109 
110  focalPlanePos = focalPlaneToFieldAngle.applyInverse(
111  lsst.afw.geom.Point2D(fieldAngleRadius.asRadians() * cosAng,
112  fieldAngleRadius.asRadians() * sinAng))
113  focalPlaneRadiusMm2 = math.hypot(*focalPlanePos)
114  measureScale2 = fieldAngleRadius / focalPlaneRadiusMm2
115  self.assertAnglesAlmostEqual(measureScale2, plate_scale)
def setUp_camera(self, camera_name=None, n_detectors=None, first_detector_name=None, plate_scale=None)
Definition: camera_tests.py:47