27 __all__ = [
"ButlerGetTests"]
31 """Tests of obs_* Butler get() functionality.
33 In the subclasses's setUp():
34 * Call setUp_butler_get() to fill in required parameters.
38 ccdExposureId_bits=None,
44 detector_serials=None,
48 good_detectorIds=None,
54 Set up the necessary variables for butlerGet tests.
56 All "exposure name" entries below should correspond to an entry in
62 ccdExposureId_bits : `int`
63 expected value of ccdExposureId_bits
65 dict of exposure name : ccdExposureId (the number as returned by
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
83 ``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 raw_header_wcs : `lsst.afw.geom.SkyWcs`
93 The SkyWcs object that should be returned by
94 ``butler.get("raw_header_wcs", dataId=self.dataIds["raw"])``
97 fields = [
'ccdExposureId_bits',
112 ButlerGet = collections.namedtuple(
"ButlerGetData", fields)
114 self.
butler_get_databutler_get_data = ButlerGet(ccdExposureId_bits=ccdExposureId_bits,
115 exposureIds=exposureIds,
118 detectorIds=detectorIds,
119 detector_names=detector_names,
120 detector_serials=detector_serials,
121 dimensions=dimensions,
122 sky_origin=sky_origin,
123 raw_subsets=raw_subsets,
124 good_detectorIds=good_detectorIds,
125 bad_detectorIds=bad_detectorIds,
126 linearizer_type=linearizer_type,
127 raw_header_wcs=raw_header_wcs
131 bits = self.butler.get(
'ccdExposureId_bits')
132 self.assertEqual(bits, self.
butler_get_databutler_get_data.ccdExposureId_bits)
134 def _test_exposure(self, name):
135 if self.dataIds[name]
is unittest.SkipTest:
136 self.skipTest(
'Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
137 exp = self.butler.get(name, self.dataIds[name])
139 exp_md = self.butler.get(name +
"_md", self.dataIds[name])
140 self.assertEqual(
type(exp_md),
type(exp.getMetadata()))
142 self.assertEqual(exp.getDimensions(), self.
butler_get_databutler_get_data.dimensions[name])
143 self.assertEqual(exp.getDetector().getId(), self.
butler_get_databutler_get_data.detectorIds[name])
145 self.assertEqual(exp.getDetector().getSerial(), self.
butler_get_databutler_get_data.detector_serials[name])
147 exposureFilter = exp.getFilterLabel()
149 if exposureFilter.hasPhysicalLabel():
150 filterName = exposureFilter.physicalLabel
152 filterName = exposureFilter.bandLabel
154 filterName =
"_unknown_"
155 self.assertEqual(filterName, self.
butler_get_databutler_get_data.filters[name])
156 exposureId = self.butler.get(
'ccdExposureId', dataId=self.dataIds[name])
157 self.assertEqual(exposureId, self.
butler_get_databutler_get_data.exposureIds[name])
158 self.assertEqual(exp.getInfo().getVisitInfo().getExposureTime(), self.
butler_get_databutler_get_data.exptimes[name])
168 if self.
butler_get_databutler_get_data.sky_origin
is not unittest.SkipTest:
169 self.assertEqual(exp.hasWcs(),
True)
170 origin = exp.getWcs().getSkyOrigin()
171 self.assertAlmostEqual(origin.getLongitude().asDegrees(), self.
butler_get_databutler_get_data.sky_origin[0])
172 self.assertAlmostEqual(origin.getLatitude().asDegrees(), self.
butler_get_databutler_get_data.sky_origin[1])
184 """Test that `raw_header_wcs` returns the unmodified raw image header.
187 wcs = self.butler.get(
'raw_header_wcs', self.dataIds[
'raw'])
188 self.assertEqual(wcs, self.
butler_get_databutler_get_data.raw_header_wcs)
190 @unittest.skip('Cannot test this, as there is a bug in the butler! DM-8097')
192 exp = self.butler.get(
'raw', self.dataIds[
'raw'], immediate=
True)
195 sub = self.butler.get(
"raw_sub", self.dataIds[
'raw'], bbox=bbox, immediate=
True)
196 self.assertEqual(sub.getImage().getBBox(), bbox)
197 self.assertImagesEqual(sub, exp.Factory(exp, bbox))
201 subset = self.butler.subset(
"raw", **kwargs)
202 self.assertEqual(len(subset), expect, msg=
"Failed for kwargs: {}".
format(kwargs))
205 """Test that we can get a linearizer for good detectorIds."""
206 if self.
butler_get_databutler_get_data.linearizer_type
is unittest.SkipTest:
207 self.skipTest(
'Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
209 camera = self.butler.get(
"camera")
210 for detectorId
in self.
butler_get_databutler_get_data.good_detectorIds:
211 detector = camera[detectorId]
212 linearizer = self.butler.get(
"linearizer", dataId=dict(ccd=detectorId), immediate=
True)
213 self.assertEqual(linearizer.LinearityType, self.
butler_get_databutler_get_data.linearizer_type[detectorId])
214 linearizer.checkDetector(detector)
217 """Do bad detectorIds raise?"""
218 if self.
butler_get_databutler_get_data.linearizer_type
is unittest.SkipTest:
219 self.skipTest(
'Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
222 with self.assertRaises(RuntimeError):
223 self.butler.get(
"linearizer", dataId=dict(ccd=badccd), immediate=
True)
def test_exposureId_bits(self)
def test_subset_raw(self)
def test_raw_sub_bbox(self)
def test_get_linearizer_bad_detectorIds(self)
def _test_exposure(self, name)
def test_get_linearizer(self)
def test_raw_header_wcs(self)
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)
std::string const & getName() const noexcept
Return a filter's name.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)