22 """Unit test base class for the gen2 to gen3 converter.
35 import lsst.daf.butler
43 """Test the `butler convert` command.
45 Subclass this, and then `lsst.utils.tests.TestCase` and set the below
46 attributes. Uses the `butler convert` command line command to do the
51 """Root path to the gen2 repo to be converted."""
54 """Path to the gen2 calib repo to be converted."""
59 """Full path to the `Instrument` class of the data to be converted,
60 e.g. ``lsst.obs.decam.DarkEnergyCamera``.
65 The fully qualified instrument class name.
71 """The instrument class."""
76 """Name of the instrument for the gen3 registry, e.g. "DECam".
81 The name of the instrument.
86 """Full path to a config override for ConvertRepoTask, to be applied after
87 the Instrument overrides when running the conversion function."""
90 """List dataIds to use to load gen3 biases to test that they exist."""
93 """Name of the dataset that the biases are loaded into."""
96 """List dataIds to use to load gen3 flats to test that they exist."""
99 """Name of the dataset that the flats are loaded into."""
102 """List dataIds to use to load gen3 darks to test that they exist."""
105 """Name of the dataset that the darks are loaded into."""
108 """Other keyword arguments to pass directly to the converter function,
112 """Names of the reference catalogs to query for the existence of in the
113 converted gen3 repo."""
116 """Additional collections that should appear in the gen3 repo.
118 This will automatically be populated by the base `setUp` to include
119 ``"raw/{instrumentName}"``, ``"refcats"`` (if the ``refcats``
120 class attribute is non-empty), and ``"skymaps"`` (if ``skymapName`` is
125 """Key to use in a gen2 dataId to refer to a detector."""
127 exposureKey =
"visit"
128 """Key to use in a gen2 dataId to refer to a visit or exposure."""
130 calibFilterType =
"physical_filter"
131 """Gen3 dimension that corresponds to Gen2 ``filter``. Should be
132 physical_filter or abstract_filter."""
135 """Name of the Gen3 skymap."""
138 """Path to skymap config file defining the new gen3 skymap."""
151 shutil.rmtree(self.
gen3root, ignore_errors=
True)
153 def _run_convert(self):
154 """Convert a gen2 repo to gen3 for testing.
159 log.setLevel(log.INFO)
173 """Check that a raw was converted correctly.
177 gen3Butler : `lsst.daf.butler.Butler`
178 The Butler to be tested.
180 The exposure/vist identifier ``get`` from both butlers.
182 The detector identifier to ``get`` from both butlers.
186 gen2Exposure = self.
gen2Butler.get(
"raw", dataId=dataIdGen2)
190 dataIdGen3 = dict(detector=detector, exposure=exposure, instrument=self.
instrumentName)
191 gen3Exposure = gen3Butler.get(
"raw", dataId=dataIdGen3)
195 self.assertEqual(gen3Exposure.getInfo().getDetector().getId(), detector)
196 self.assertMaskedImagesEqual(gen2Exposure.maskedImage, gen3Exposure.maskedImage)
199 """Test that we can get converted bias/dark/flat from the gen3 repo.
201 Note: because there is no clear way to get calibrations from a gen2
202 repo, we just test that the thing we got is an ExposureF here, and
203 assume that formatter testing is handled properly elsewhere.
208 The name of the calibration to attempt to get ("bias", "flat").
209 calibIds : `list` of `dict`
210 The list of calibration dataIds to get.
211 gen3Butler : `lsst.daf.butler.Butler`
212 The Butler to use to get the data.
214 for dataId
in calibIds:
215 with self.subTest(dtype=calibName, dataId=dataId):
216 datasets =
list(gen3Butler.registry.queryDatasets(calibName, collections=..., dataId=dataId))
217 gen3Exposure = gen3Butler.getDirect(datasets[0])
218 self.assertIsInstance(gen3Exposure, lsst.afw.image.ExposureF)
221 """Test that we can get converted defects from the gen3 repo.
225 gen3Butler : `lsst.daf.butler.Butler`
226 The Butler to be tested.
227 detectors : `list` of `int`
228 The detector identifiers to ``get`` from the gen3 butler.
230 for detector
in detectors:
235 with self.subTest(dtype=
"defects", dataId=dataId):
236 datasets =
list(gen3Butler.registry.queryDatasets(
"defects", collections=..., dataId=dataId))
238 gen3Defects = gen3Butler.getDirect(datasets[0])
242 """Test that each expected refcat is in the gen3 repo.
246 gen3Butler : `lsst.daf.butler.Butler`
247 The Butler to be tested.
251 query = gen3Butler.registry.queryDatasets(refcat, collections=[
"refcats"])
252 self.assertGreater(len(
list(query)), 0,
253 msg=f
"refcat={refcat} has no entries in collection 'refcats'.")
256 """Test that the correct set of collections is in the gen3 repo.
260 gen3Butler : `lsst.daf.butler.Butler`
261 The Butler to be tested.
263 self.assertEqual(
set(gen3Butler.registry.queryCollections()), self.
collections,
264 f
"Compare with expected collections ({self.collections})")
267 """Test that all data are converted correctly.
270 gen3Butler = lsst.daf.butler.Butler(self.
gen3root, collections=f
"raw/{self.instrumentName}")
276 for exposure, detector
in itertools.product(exposures, detectors):
277 with self.subTest(mode=
"raw", exposure=exposure, detector=detector):
278 self.
check_raw(gen3Butler, exposure, detector)
291 if __name__ ==
"__main__":