Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capitalize on read and warn, warn when keywords are capitalized on write for fits files #522

Merged
merged 4 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/fits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern "C" {
#include "fitsio2.h"
}

#include "boost/algorithm/string.hpp"
#include "boost/regex.hpp"
#include "boost/filesystem.hpp"
#include "boost/preprocessor/seq/for_each.hpp"
Expand Down Expand Up @@ -789,7 +790,16 @@ void Fits::forEachKey(HeaderIterationFunctor &functor) {
int i = 1;
while (i <= nKeys) {
fits_read_keyn(reinterpret_cast<fitsfile *>(fptr), i, key, value, comment, &status);
keyStr = key;
// fits_read_keyn does not convert the key case on read, like other fits methods in cfitsio>=3.38
// We uppercase to try to be more consistent.
std::string upperKey(key);
boost::to_upper(upperKey);
if (upperKey.compare(key) != 0){
LOGLS_WARN("afw.fits",
boost::format("In %s, raising key case on read for key '%s' (for cfitsio>=3.38).") %
BOOST_CURRENT_FUNCTION % key);
brianv0 marked this conversation as resolved.
Show resolved Hide resolved
}
keyStr = upperKey;
valueStr = value;
commentStr = comment;
++i;
Expand Down Expand Up @@ -969,6 +979,13 @@ void MetadataIterationFunctor::operator()(std::string const &key, std::string co

void writeKeyFromProperty(Fits &fits, daf::base::PropertySet const &metadata, std::string const &key,
char const *comment = 0) {
std::string upperKey(key);
boost::to_upper(upperKey);
if (upperKey.compare(key) != 0){
LOGLS_WARN("afw.fits",
boost::format("In %s, cfitsio>=3.38 will raise key case on write ('%s' -> '%s').") %
BOOST_CURRENT_FUNCTION % key % upperKey);
brianv0 marked this conversation as resolved.
Show resolved Hide resolved
}
std::type_info const &valueType = metadata.typeOf(key);
if (valueType == typeid(bool)) {
if (metadata.isArray(key)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def setUp(self):
self.md = maskedImageMD
self.psf = DummyPsf(2.0)
self.detector = DetectorWrapper().detector
self.extras = {"misc": DummyPsf(3.5)}
self.extras = {"MISC": DummyPsf(3.5)}

self.exposureBlank = afwImage.ExposureF()
self.exposureMiOnly = afwImage.makeExposure(maskedImage)
Expand Down