LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
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  raw_header_wcs=None
53  ):
54  """
55  Set up the necessary variables for butlerGet tests.
56 
57  All "exposure name" entries below should correspond to an entry in
58  self.dataIds.
59 
60  Parameters
61  ----------
62 
63  ccdExposureId_bits : `int`
64  expected value of ccdExposureId_bits
65  exposureIds : `dict`
66  dict of exposure name : ccdExposureId (the number as returned by the butler)
67  filters : `dict`
68  dict of exposure name : filter name
69  exptimes : `dict`
70  dict of exposure name : exposure time
71  detector_names : `dict`
72  dict of exposure name : detector name
73  detectorIds : `dict`
74  dict of exposure name : detectorId
75  detector_serials : `dict`
76  dict of exposure name : detector serial
77  dimensions : `dict`
78  dict of exposure name : dimensions (as a geom.Extent2I)
79  sky_origin : `tuple` of `float`
80  Longitude, Latitude of 'raw' exposure
81  raw_subsets : `tuple` of (kwargs, `int`)
82  keyword args and expected number of subsets for butler.subset('raw', **kwargs)
83  good_detectorIds : `list` of `int`
84  list of valid ccd numbers
85  bad_detectorIds : `list` of `int`
86  list of invalid ccd numbers
87  linearizer_type : `dict`
88  dict of detectorId (usually `int`): LinearizerType
89  (e.g. lsst.ip.isr.LinearizeLookupTable.LinearityType),
90  or unittest.SkipTest to skip all linearizer tests.
91  raw_header_wcs : `lsst.afw.geom.SkyWcs`
92  The SkyWcs object that should be returned by:
93  `butler.get("raw_header_wcs", dataId=self.dataIds["raw"])`
94  """
95 
96  fields = ['ccdExposureId_bits',
97  'exposureIds',
98  'filters',
99  'exptimes',
100  'detector_names',
101  'detectorIds',
102  'detector_serials',
103  'dimensions',
104  'sky_origin',
105  'raw_subsets',
106  'good_detectorIds',
107  'bad_detectorIds',
108  'linearizer_type',
109  'raw_header_wcs'
110  ]
111  ButlerGet = collections.namedtuple("ButlerGetData", fields)
112 
113  self.butler_get_data = ButlerGet(ccdExposureId_bits=ccdExposureId_bits,
114  exposureIds=exposureIds,
115  filters=filters,
116  exptimes=exptimes,
117  detectorIds=detectorIds,
118  detector_names=detector_names,
119  detector_serials=detector_serials,
120  dimensions=dimensions,
121  sky_origin=sky_origin,
122  raw_subsets=raw_subsets,
123  good_detectorIds=good_detectorIds,
124  bad_detectorIds=bad_detectorIds,
125  linearizer_type=linearizer_type,
126  raw_header_wcs=raw_header_wcs
127  )
128 
130  bits = self.butler.get('ccdExposureId_bits')
131  self.assertEqual(bits, self.butler_get_data.ccdExposureId_bits)
132 
133  def _test_exposure(self, name):
134  if self.dataIds[name] is unittest.SkipTest:
135  self.skipTest('Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
136  exp = self.butler.get(name, self.dataIds[name])
137 
138  exp_md = self.butler.get(name + "_md", self.dataIds[name])
139  self.assertEqual(type(exp_md), type(exp.getMetadata()))
140 
141  self.assertEqual(exp.getDimensions(), self.butler_get_data.dimensions[name])
142  self.assertEqual(exp.getDetector().getId(), self.butler_get_data.detectorIds[name])
143  self.assertEqual(exp.getDetector().getName(), self.butler_get_data.detector_names[name])
144  self.assertEqual(exp.getDetector().getSerial(), self.butler_get_data.detector_serials[name])
145  self.assertEqual(exp.getFilter().getName(), self.butler_get_data.filters[name])
146  exposureId = self.butler.get('ccdExposureId', dataId=self.dataIds[name])
147  self.assertEqual(exposureId, self.butler_get_data.exposureIds[name])
148  self.assertEqual(exp.getInfo().getVisitInfo().getExposureTime(), self.butler_get_data.exptimes[name])
149  return exp
150 
151  def test_raw(self):
152  exp = self._test_exposure('raw')
153  # We only test the existence of WCS in the raw files, since it's only well-defined
154  # for raw, and other exposure types could have or not have a WCS depending
155  # on various implementation details.
156  # Even for raw, there are data that do not have a WCS, e.g. teststand data
157  if self.butler_get_data.sky_origin is not unittest.SkipTest:
158  self.assertEqual(exp.hasWcs(), True)
159  origin = exp.getWcs().getSkyOrigin()
160  self.assertAlmostEqual(origin.getLongitude().asDegrees(), self.butler_get_data.sky_origin[0])
161  self.assertAlmostEqual(origin.getLatitude().asDegrees(), self.butler_get_data.sky_origin[1])
162 
163  def test_bias(self):
164  self._test_exposure('bias')
165 
166  def test_dark(self):
167  self._test_exposure('dark')
168 
169  def test_flat(self):
170  self._test_exposure('flat')
171 
173  """Test that `raw_header_wcs` returns the unmodified raw image header.
174  """
175  if self.butler_get_data.raw_header_wcs is not None:
176  wcs = self.butler.get('raw_header_wcs', self.dataIds['raw'])
177  self.assertEqual(wcs, self.butler_get_data.raw_header_wcs)
178 
179  @unittest.skip('Cannot test this, as there is a bug in the butler! DM-8097')
180  def test_raw_sub_bbox(self):
181  exp = self.butler.get('raw', self.dataIds['raw'], immediate=True)
182  bbox = exp.getBBox()
183  bbox.grow(-1)
184  sub = self.butler.get("raw_sub", self.dataIds['raw'], bbox=bbox, immediate=True)
185  self.assertEqual(sub.getImage().getBBox(), bbox)
186  self.assertImagesEqual(sub, exp.Factory(exp, bbox))
187 
188  def test_subset_raw(self):
189  for kwargs, expect in self.butler_get_data.raw_subsets:
190  subset = self.butler.subset("raw", **kwargs)
191  self.assertEqual(len(subset), expect, msg="Failed for kwargs: {}".format(kwargs))
192 
194  """Test that we can get a linearizer for good detectorIds."""
195  if self.butler_get_data.linearizer_type is unittest.SkipTest:
196  self.skipTest('Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
197 
198  camera = self.butler.get("camera")
199  for detectorId in self.butler_get_data.good_detectorIds:
200  detector = camera[detectorId]
201  linearizer = self.butler.get("linearizer", dataId=dict(ccd=detectorId), immediate=True)
202  self.assertEqual(linearizer.LinearityType, self.butler_get_data.linearizer_type[detectorId])
203  linearizer.checkDetector(detector)
204 
206  """Do bad detectorIds raise?"""
207  if self.butler_get_data.linearizer_type is unittest.SkipTest:
208  self.skipTest('Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
209 
210  for badccd in self.butler_get_data.bad_detectorIds:
211  with self.assertRaises(RuntimeError):
212  self.butler.get("linearizer", dataId=dict(ccd=badccd), immediate=True)
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
table::Key< int > type
Definition: Detector.cc:163
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, raw_header_wcs=None)
Definition: butler_tests.py:53