lsst.obs.base  14.0
 All Classes Namespaces Files Functions Variables
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 
27 import lsst.afw.geom
28 
29 
30 class CameraTests(with_metaclass(abc.ABCMeta)):
31  """
32  Tests that the butler returns a useable Camera.
33 
34  In the subclasses's setUp():
35  * Call setUp_camera() to fill in required parameters.
36  """
37 
38  def setUp_camera(self,
39  camera_name=None,
40  n_detectors=None,
41  first_detector_name=None
42  ):
43  """
44  Set up the necessary variables for camera tests.
45 
46  Parameters
47  ----------
48 
49  camera_name : `str`
50  name of this camera
51  n_detectors : `int`
52  number of detectors in this camera
53  first_detector_name : `str`
54  name of the first detector in this camera
55  """
56  fields = ['camera_name',
57  'n_detectors',
58  'first_detector_name'
59  ]
60  CameraData = collections.namedtuple("CameraData", fields)
61  self.camera_data = CameraData(camera_name=camera_name,
62  n_detectors=n_detectors,
63  first_detector_name=first_detector_name
64  )
65 
66  def test_iterable(self):
67  """Simplest camera test: can we get a Camera instance, and does iterating return Detectors?"""
68  camera = self.butler.get('camera', immediate=True)
69  self.assertIsInstance(camera, lsst.afw.cameraGeom.Camera)
70  for detector in camera:
71  msg = "Failed for detector={}".format(detector)
72  self.assertIsInstance(detector, lsst.afw.cameraGeom.Detector, msg=msg)
73 
74  def test_camera_butler(self):
75  """Check that the butler returns the right type of camera."""
76  camera = self.butler.get('camera', immediate=True)
77  self.assertEqual(camera.getName(), self.camera_data.camera_name)
78  self.assertEqual(len(camera), self.camera_data.n_detectors)
79  self.assertEqual(next(iter(camera)).getName(), self.camera_data.first_detector_name)