lsst.obs.base  15.0-12-g3681e7a+15
butler_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 inspect
26 import unittest
27 import collections
28 
29 __all__ = ["ButlerGetTests"]
30 
31 
32 class ButlerGetTests(with_metaclass(abc.ABCMeta)):
33  """
34  Tests of obs_* Butler get() functionality.
35 
36  In the subclasses's setUp():
37  * Call setUp_butler_get() to fill in required parameters.
38  """
39 
40  def setUp_butler_get(self,
41  ccdExposureId_bits=None,
42  exposureIds=None,
43  filters=None,
44  exptimes=None,
45  detectorIds=None,
46  detector_names=None,
47  detector_serials=None,
48  dimensions=None,
49  sky_origin=None,
50  raw_subsets=None,
51  good_detectorIds=None,
52  bad_detectorIds=None,
53  linearizer_type=None
54  ):
55  """
56  Set up the necessary variables for butlerGet tests.
57 
58  All "exposure name" entries below should correspond to an entry in
59  self.dataIds.
60 
61  Parameters
62  ----------
63 
64  ccdExposureId_bits : `int`
65  expected value of ccdExposureId_bits
66  exposureIds : `dict`
67  dict of exposure name : ccdExposureId (the number as returned by the butler)
68  filters : `dict`
69  dict of exposure name : filter name
70  exptimes : `dict`
71  dict of exposure name : exposure time
72  detector_names : `dict`
73  dict of exposure name : detector name
74  detectorIds : `dict`
75  dict of exposure name : detectorId
76  detector_serials : `dict`
77  dict of exposure name : detector serial
78  dimensions : `dict`
79  dict of exposure name : dimensions (as a geom.Extent2I)
80  sky_origin : `tuple` of `float`
81  Longitude, Latitude of 'raw' exposure
82  raw_subsets : `tuple` of (kwargs, `int`)
83  keyword args and expected number of subsets for butler.subset('raw', **kwargs)
84  good_detectorIds : `list` of `int`
85  list of valid ccd numbers
86  bad_detectorIds : `list` of `int`
87  list of invalid ccd numbers
88  linearizer_type : `dict`
89  dict of detectorId (usually `int`): LinearizerType
90  (e.g. lsst.ip.isr.LinearizeLookupTable.LinearityType),
91  or unittest.SkipTest to skip all linearizer tests.
92  """
93 
94  fields = ['ccdExposureId_bits',
95  'exposureIds',
96  'filters',
97  'exptimes',
98  'detector_names',
99  'detectorIds',
100  'detector_serials',
101  'dimensions',
102  'sky_origin',
103  'raw_subsets',
104  'good_detectorIds',
105  'bad_detectorIds',
106  'linearizer_type'
107  ]
108  ButlerGet = collections.namedtuple("ButlerGetData", fields)
109 
110  self.butler_get_data = ButlerGet(ccdExposureId_bits=ccdExposureId_bits,
111  exposureIds=exposureIds,
112  filters=filters,
113  exptimes=exptimes,
114  detectorIds=detectorIds,
115  detector_names=detector_names,
116  detector_serials=detector_serials,
117  dimensions=dimensions,
118  sky_origin=sky_origin,
119  raw_subsets=raw_subsets,
120  good_detectorIds=good_detectorIds,
121  bad_detectorIds=bad_detectorIds,
122  linearizer_type=linearizer_type
123  )
124 
126  bits = self.butler.get('ccdExposureId_bits')
127  self.assertEqual(bits, self.butler_get_data.ccdExposureId_bits)
128 
129  def _test_exposure(self, name):
130  if self.dataIds[name] is unittest.SkipTest:
131  self.skipTest('Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
132 
133  exp = self.butler.get(name, self.dataIds[name])
134  self.assertEqual(exp.getDimensions(), self.butler_get_data.dimensions[name])
135  self.assertEqual(exp.getDetector().getId(), self.butler_get_data.detectorIds[name])
136  self.assertEqual(exp.getDetector().getName(), self.butler_get_data.detector_names[name])
137  self.assertEqual(exp.getDetector().getSerial(), self.butler_get_data.detector_serials[name])
138  self.assertEqual(exp.getFilter().getName(), self.butler_get_data.filters[name])
139  exposureId = self.butler.get('ccdExposureId', dataId=self.dataIds[name])
140  self.assertEqual(exposureId, self.butler_get_data.exposureIds[name])
141  self.assertEqual(exp.getInfo().getVisitInfo().getExposureTime(), self.butler_get_data.exptimes[name])
142  return exp
143 
144  def test_raw(self):
145  exp = self._test_exposure('raw')
146  # We only test the existence of WCS in the raw files, since it's only well-defined
147  # for raw, and other exposure types could have or not have a WCS depending
148  # on various implementation details.
149  self.assertEqual(exp.hasWcs(), True)
150  origin = exp.getWcs().getSkyOrigin()
151  self.assertAlmostEqual(origin.getLongitude().asDegrees(), self.butler_get_data.sky_origin[0])
152  self.assertAlmostEqual(origin.getLatitude().asDegrees(), self.butler_get_data.sky_origin[1])
153 
154  def test_bias(self):
155  self._test_exposure('bias')
156 
157  def test_dark(self):
158  self._test_exposure('dark')
159 
160  def test_flat(self):
161  self._test_exposure('flat')
162 
163  @unittest.skip('Cannot test this, as there is a bug in the butler! DM-8097')
164  def test_raw_sub_bbox(self):
165  exp = self.butler.get('raw', self.dataIds['raw'], immediate=True)
166  bbox = exp.getBBox()
167  bbox.grow(-1)
168  sub = self.butler.get("raw_sub", self.dataIds['raw'], bbox=bbox, immediate=True)
169  self.assertEqual(sub.getImage().getBBox(), bbox)
170  self.assertImagesEqual(sub, exp.Factory(exp, bbox))
171 
172  def test_subset_raw(self):
173  for kwargs, expect in self.butler_get_data.raw_subsets:
174  subset = self.butler.subset("raw", **kwargs)
175  self.assertEqual(len(subset), expect, msg="Failed for kwargs: {}".format(kwargs))
176 
178  """Test that we can get a linearizer for good detectorIds."""
179  if self.butler_get_data.linearizer_type is unittest.SkipTest:
180  self.skipTest('Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
181 
182  camera = self.butler.get("camera")
183  for detectorId in self.butler_get_data.good_detectorIds:
184  detector = camera[detectorId]
185  linearizer = self.butler.get("linearizer", dataId=dict(ccd=detectorId), immediate=True)
186  self.assertEqual(linearizer.LinearityType, self.butler_get_data.linearizer_type[detectorId])
187  linearizer.checkDetector(detector)
188 
190  """Do bad detectorIds raise?"""
191  if self.butler_get_data.linearizer_type is unittest.SkipTest:
192  self.skipTest('Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
193 
194  for badccd in self.butler_get_data.bad_detectorIds:
195  with self.assertRaises(RuntimeError):
196  self.butler.get("linearizer", dataId=dict(ccd=badccd), immediate=True)
def setUp_butler_get(self, ccdExposureId_bits=None, exposureIds=None, filters=None, exptimes=None, detectorIds=None, detector_names=None, detector_serials=None, dimensions=None, sky_origin=None, raw_subsets=None, good_detectorIds=None, bad_detectorIds=None, linearizer_type=None)
Definition: butler_tests.py:54