27 __all__ = [
"ButlerGetTests"]
32 Tests of obs_* Butler get() functionality.
34 In the subclasses's setUp():
35 * Call setUp_butler_get() to fill in required parameters.
39 ccdExposureId_bits=None,
45 detector_serials=None,
49 good_detectorIds=None,
55 Set up the necessary variables for butlerGet tests.
57 All "exposure name" entries below should correspond to an entry in
63 ccdExposureId_bits : `int`
64 expected value of ccdExposureId_bits
66 dict of exposure name : ccdExposureId (the number as returned by the butler)
68 dict of exposure name : filter name
70 dict of exposure name : exposure time
71 detector_names : `dict`
72 dict of exposure name : detector name
74 dict of exposure name : detectorId
75 detector_serials : `dict`
76 dict of exposure name : detector serial
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"])`
96 fields = [
'ccdExposureId_bits',
111 ButlerGet = collections.namedtuple(
"ButlerGetData", fields)
113 self.
butler_get_data = ButlerGet(ccdExposureId_bits=ccdExposureId_bits,
114 exposureIds=exposureIds,
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
130 bits = self.butler.get(
'ccdExposureId_bits')
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])
138 exp_md = self.butler.get(name +
"_md", self.dataIds[name])
139 self.assertEqual(
type(exp_md),
type(exp.getMetadata()))
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])
148 self.assertEqual(exp.getInfo().getVisitInfo().getExposureTime(), self.
butler_get_data.exptimes[name])
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])
173 """Test that `raw_header_wcs` returns the unmodified raw image header.
176 wcs = self.butler.get(
'raw_header_wcs', self.dataIds[
'raw'])
179 @unittest.skip(
'Cannot test this, as there is a bug in the butler! DM-8097')
181 exp = self.butler.get(
'raw', self.dataIds[
'raw'], immediate=
True)
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))
190 subset = self.butler.subset(
"raw", **kwargs)
191 self.assertEqual(len(subset), expect, msg=
"Failed for kwargs: {}".
format(kwargs))
194 """Test that we can get a linearizer for good detectorIds."""
196 self.skipTest(
'Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
198 camera = self.butler.get(
"camera")
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)
206 """Do bad detectorIds raise?"""
208 self.skipTest(
'Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
211 with self.assertRaises(RuntimeError):
212 self.butler.get(
"linearizer", dataId=dict(ccd=badccd), immediate=
True)