LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
butler_tests.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2016 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 abc
23 import inspect
24 import unittest
25 import collections
26 
27 __all__ = ["ButlerGetTests"]
28 
29 
30 class ButlerGetTests(metaclass=abc.ABCMeta):
31  """
32  Tests of obs_* Butler get() functionality.
33 
34  In the subclasses's setUp():
35  * Call setUp_butler_get() to fill in required parameters.
36  """
37 
38  def setUp_butler_get(self,
39  ccdExposureId_bits=None,
40  exposureIds=None,
41  filters=None,
42  exptimes=None,
43  detectorIds=None,
44  detector_names=None,
45  detector_serials=None,
46  dimensions=None,
47  sky_origin=None,
48  raw_subsets=None,
49  good_detectorIds=None,
50  bad_detectorIds=None,
51  linearizer_type=None
52  ):
53  """
54  Set up the necessary variables for butlerGet tests.
55 
56  All "exposure name" entries below should correspond to an entry in
57  self.dataIds.
58 
59  Parameters
60  ----------
61 
62  ccdExposureId_bits : `int`
63  expected value of ccdExposureId_bits
64  exposureIds : `dict`
65  dict of exposure name : ccdExposureId (the number as returned by the butler)
66  filters : `dict`
67  dict of exposure name : filter name
68  exptimes : `dict`
69  dict of exposure name : exposure time
70  detector_names : `dict`
71  dict of exposure name : detector name
72  detectorIds : `dict`
73  dict of exposure name : detectorId
74  detector_serials : `dict`
75  dict of exposure name : detector serial
76  dimensions : `dict`
77  dict of exposure name : dimensions (as a geom.Extent2I)
78  sky_origin : `tuple` of `float`
79  Longitude, Latitude of 'raw' exposure
80  raw_subsets : `tuple` of (kwargs, `int`)
81  keyword args and expected number of subsets for butler.subset('raw', **kwargs)
82  good_detectorIds : `list` of `int`
83  list of valid ccd numbers
84  bad_detectorIds : `list` of `int`
85  list of invalid ccd numbers
86  linearizer_type : `dict`
87  dict of detectorId (usually `int`): LinearizerType
88  (e.g. lsst.ip.isr.LinearizeLookupTable.LinearityType),
89  or unittest.SkipTest to skip all linearizer tests.
90  """
91 
92  fields = ['ccdExposureId_bits',
93  'exposureIds',
94  'filters',
95  'exptimes',
96  'detector_names',
97  'detectorIds',
98  'detector_serials',
99  'dimensions',
100  'sky_origin',
101  'raw_subsets',
102  'good_detectorIds',
103  'bad_detectorIds',
104  'linearizer_type'
105  ]
106  ButlerGet = collections.namedtuple("ButlerGetData", fields)
107 
108  self.butler_get_data = ButlerGet(ccdExposureId_bits=ccdExposureId_bits,
109  exposureIds=exposureIds,
110  filters=filters,
111  exptimes=exptimes,
112  detectorIds=detectorIds,
113  detector_names=detector_names,
114  detector_serials=detector_serials,
115  dimensions=dimensions,
116  sky_origin=sky_origin,
117  raw_subsets=raw_subsets,
118  good_detectorIds=good_detectorIds,
119  bad_detectorIds=bad_detectorIds,
120  linearizer_type=linearizer_type
121  )
122 
124  bits = self.butler.get('ccdExposureId_bits')
125  self.assertEqual(bits, self.butler_get_data.ccdExposureId_bits)
126 
127  def _test_exposure(self, name):
128  if self.dataIds[name] is unittest.SkipTest:
129  self.skipTest('Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
130  exp = self.butler.get(name, self.dataIds[name])
131 
132  exp_md = self.butler.get(name + "_md", self.dataIds[name])
133  self.assertEqual(type(exp_md), type(exp.getMetadata()))
134 
135  self.assertEqual(exp.getDimensions(), self.butler_get_data.dimensions[name])
136  self.assertEqual(exp.getDetector().getId(), self.butler_get_data.detectorIds[name])
137  self.assertEqual(exp.getDetector().getName(), self.butler_get_data.detector_names[name])
138  self.assertEqual(exp.getDetector().getSerial(), self.butler_get_data.detector_serials[name])
139  self.assertEqual(exp.getFilter().getName(), self.butler_get_data.filters[name])
140  exposureId = self.butler.get('ccdExposureId', dataId=self.dataIds[name])
141  self.assertEqual(exposureId, self.butler_get_data.exposureIds[name])
142  self.assertEqual(exp.getInfo().getVisitInfo().getExposureTime(), self.butler_get_data.exptimes[name])
143  return exp
144 
145  def test_raw(self):
146  exp = self._test_exposure('raw')
147  # We only test the existence of WCS in the raw files, since it's only well-defined
148  # for raw, and other exposure types could have or not have a WCS depending
149  # on various implementation details.
150  # Even for raw, there are data that do not have a WCS, e.g. teststand data
151  if self.butler_get_data.sky_origin is not unittest.SkipTest:
152  self.assertEqual(exp.hasWcs(), True)
153  origin = exp.getWcs().getSkyOrigin()
154  self.assertAlmostEqual(origin.getLongitude().asDegrees(), self.butler_get_data.sky_origin[0])
155  self.assertAlmostEqual(origin.getLatitude().asDegrees(), self.butler_get_data.sky_origin[1])
156 
157  def test_bias(self):
158  self._test_exposure('bias')
159 
160  def test_dark(self):
161  self._test_exposure('dark')
162 
163  def test_flat(self):
164  self._test_exposure('flat')
165 
166  @unittest.skip('Cannot test this, as there is a bug in the butler! DM-8097')
167  def test_raw_sub_bbox(self):
168  exp = self.butler.get('raw', self.dataIds['raw'], immediate=True)
169  bbox = exp.getBBox()
170  bbox.grow(-1)
171  sub = self.butler.get("raw_sub", self.dataIds['raw'], bbox=bbox, immediate=True)
172  self.assertEqual(sub.getImage().getBBox(), bbox)
173  self.assertImagesEqual(sub, exp.Factory(exp, bbox))
174 
175  def test_subset_raw(self):
176  for kwargs, expect in self.butler_get_data.raw_subsets:
177  subset = self.butler.subset("raw", **kwargs)
178  self.assertEqual(len(subset), expect, msg="Failed for kwargs: {}".format(kwargs))
179 
181  """Test that we can get a linearizer for good detectorIds."""
182  if self.butler_get_data.linearizer_type is unittest.SkipTest:
183  self.skipTest('Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
184 
185  camera = self.butler.get("camera")
186  for detectorId in self.butler_get_data.good_detectorIds:
187  detector = camera[detectorId]
188  linearizer = self.butler.get("linearizer", dataId=dict(ccd=detectorId), immediate=True)
189  self.assertEqual(linearizer.LinearityType, self.butler_get_data.linearizer_type[detectorId])
190  linearizer.checkDetector(detector)
191 
193  """Do bad detectorIds raise?"""
194  if self.butler_get_data.linearizer_type is unittest.SkipTest:
195  self.skipTest('Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
196 
197  for badccd in self.butler_get_data.bad_detectorIds:
198  with self.assertRaises(RuntimeError):
199  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:52
table::Key< int > type
Definition: Detector.cc:164
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:168