From 9403ed500a8d69142688f39c1fe70518c31bbc86 Mon Sep 17 00:00:00 2001 From: Jim Bosch Date: Tue, 3 Dec 2024 15:52:07 -0500 Subject: [PATCH] Drop unnecessary and broken handling of dotted FITS keys in WCS reads. Writing keys with '.' in them isn't advisable, but HEIRARCH permits it and we definitely don't want it to cause reading everything else to fail. --- src/geom/detail/frameSetUtils.cc | 6 ++---- tests/test_exposure.py | 9 +++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/geom/detail/frameSetUtils.cc b/src/geom/detail/frameSetUtils.cc index 57d8892d5..2e4b3d822 100644 --- a/src/geom/detail/frameSetUtils.cc +++ b/src/geom/detail/frameSetUtils.cc @@ -375,10 +375,8 @@ ast::FitsChan getFitsChanFromPropertyList(daf::base::PropertySet& metadata, } // Loop over the names and add them to the FitsChan if not excluded - for (auto const &fullName : allParamNames) { - if (excludeNames.count(fullName) == 0) { - std::size_t lastPeriod = fullName.rfind(char('.')); - auto name = (lastPeriod == std::string::npos) ? fullName : fullName.substr(lastPeriod + 1); + for (auto const &name : allParamNames) { + if (excludeNames.count(name) == 0) { std::type_info const &type = metadata.typeOf(name); if (name.size() > 8) { diff --git a/tests/test_exposure.py b/tests/test_exposure.py index 3bef204f3..1171551c4 100644 --- a/tests/test_exposure.py +++ b/tests/test_exposure.py @@ -1150,6 +1150,15 @@ def testReadVersion2(self): self.assertEqual(reader.readExposureInfo().getPhotoCalib(), self.v1PhotoCalib) self.assertEqual(reader.readPhotoCalib(), self.v1PhotoCalib) + def testReadDottedHeaderKey(self): + """Test that we can read a file with a dot-delimited header key.""" + original = afwImage.ExposureF.readFits(os.path.join(self.dataDir, "exposure-version-2.fits")) + original.metadata["x.y.z"] = "three" + with lsst.utils.tests.getTempFilePath(".fits") as tmpFile: + original.writeFits(tmpFile) + roundtripped = afwImage.ExposureF(tmpFile) + self.assertMaskedImagesEqual(original.maskedImage, roundtripped.maskedImage) + def testExposureSummaryExtraComponents(self): """Test that we can read an exposure summary with extra components. """