LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
butler_tests.py
Go to the documentation of this file.
1 # This file is part of obs_base.
2 #
3 # Developed for the LSST Data Management System.
4 # This product includes software developed by the LSST Project
5 # (https://www.lsst.org).
6 # See the COPYRIGHT file at the top-level directory of this distribution
7 # for details of code ownership.
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <https://www.gnu.org/licenses/>.
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