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

Tickets/dm 10091 Patch up DM-9952 #210

Merged
merged 3 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion python/lsst/afw/math/backgroundList.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ def readFits(fileName, hdu=0, flags=0):

self = BackgroundList()

hdu -= 1 # we want to start at 0 (post RFC-304), but are about to increment
INT_MIN = -(1 << 31)
if hdu == INT_MIN:
hdu = -1
else:
hdu -= 1 # we want to start at 0 (post RFC-304), but are about to increment

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look fine although I don't understand the commit message and its relationship with pipe_tasks's testProcessCcd.py

while True:
hdu += 1

Expand Down
11 changes: 2 additions & 9 deletions src/formatters/PropertyListFormatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,12 @@ void PropertyListFormatter::write(
}

namespace {
// I'd use a unique_ptr, except that PropertyList won't allow me to merge non-shared_ptrs
std::unique_ptr<daf::base::PropertyList>
readMetadataAsUniquePtr(std::string const & fileName, int hdu, bool strip)
{
auto metadata = std::unique_ptr<daf::base::PropertyList>(new lsst::daf::base::PropertyList);
//
// We need a shared_ptr to be able to call PropertyList.combine()
//
auto inheritedMetadata = std::shared_ptr<daf::base::PropertyList>(new daf::base::PropertyList);

fits::Fits fitsfile(fileName, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
fitsfile.setHdu(hdu);
fitsfile.readMetadata(*inheritedMetadata, strip);

auto inheritedMetadata = fits::readMetadata(fileName, hdu, strip);
metadata->combine(inheritedMetadata);

return metadata;
Expand Down
2 changes: 1 addition & 1 deletion src/formatters/TanWcsFormatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ dafBase::Persistable* afwForm::TanWcsFormatter::read(
else if (typeid(*storage) == typeid(dafPersist::FitsStorage)) {
LOGL_DEBUG(_log, "TanWcsFormatter read FitsStorage");
dafPersist::FitsStorage* fits = dynamic_cast<dafPersist::FitsStorage*>(storage.get());
int hdu = additionalData->get<int>("hdu", 0);
int hdu = additionalData->get<int>("hdu", INT_MIN);
dafBase::PropertySet::Ptr md =
afw::fits::readMetadata(fits->getPath(), hdu);
afwImg::TanWcs* ip = new afwImg::TanWcs(md);
Expand Down
2 changes: 1 addition & 1 deletion src/formatters/WcsFormatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ dafBase::Persistable* afwForm::WcsFormatter::read(
else if (typeid(*storage) == typeid(dafPersist::FitsStorage)) {
LOGL_DEBUG(_log, "WcsFormatter read FitsStorage");
dafPersist::FitsStorage* fits = dynamic_cast<dafPersist::FitsStorage*>(storage.get());
int hdu = additionalData->get<int>("hdu", 0);
int hdu = additionalData->get<int>("hdu", INT_MIN);
dafBase::PropertySet::Ptr md =
afw::fits::readMetadata(fits->getPath(), hdu);
afwImg::Wcs* ip = new afwImg::Wcs(md);
Expand Down
4 changes: 2 additions & 2 deletions tests/ramFitsIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void test6()

//Read FITS file from disk into an Image
PTR(dafBase::PropertySet) miMetadata(new dafBase::PropertySet);
PTR(ImageF) image(new ImageF(gFilename, 0, miMetadata));
PTR(ImageF) image(new ImageF(gFilename, INT_MIN, miMetadata));

//Write the Image to a RAM FITS file
image->writeFits(string(gFilenameStripped + "_imageOut.fit").c_str());
Expand All @@ -133,7 +133,7 @@ void test7()

//Read FITS file from disk into an Exposure
dafBase::PropertySet::Ptr miMetadata(new dafBase::PropertySet);
ImageF::Ptr image = ImageF::Ptr(new ImageF(gFilename, 0, miMetadata));
ImageF::Ptr image = ImageF::Ptr(new ImageF(gFilename, INT_MIN, miMetadata));
MaskedImageF maskedImage(image);
afwImage::Wcs::Ptr wcsFromFITS = afwImage::makeWcs(miMetadata);
ExposureF exposure(maskedImage, wcsFromFITS);
Expand Down
6 changes: 3 additions & 3 deletions tests/testImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,9 @@ def testReadFits(self):
"""Test reading FITS files"""

hdus = {}
hdus["img"] = 2 # an S16 fits HDU
hdus["msk"] = 3 # an U8 fits HDU
hdus["var"] = 4 # an F32 fits HDU
hdus["img"] = 1 # an S16 fits HDU
hdus["msk"] = 2 # an U8 fits HDU
hdus["var"] = 3 # an F32 fits HDU

imgU = afwImage.DecoratedImageU(self.fileForMetadata, hdus["img"]) # read as unsigned short
imgF = afwImage.DecoratedImageF(self.fileForMetadata, hdus["img"]) # read as float
Expand Down
6 changes: 3 additions & 3 deletions tests/testImageIo1.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ def testS16(self):
@unittest.skipIf(dataDir is None, "afwdata not setup")
def testF32(self):
"""Test reading F32 image"""
im = afwImage.ImageD(os.path.join(dataDir, "871034p_1_MI.fits"), 4)
im = afwImage.ImageD(os.path.join(dataDir, "871034p_1_MI.fits"), 3)

col, row, val = 32, 1, 39.11672
self.assertAlmostEqual(im.get(col, row), val, 5)
self.assertAlmostEqual(im.get(col, row), val, 4)

@unittest.skipIf(dataDir is None, "afwdata not setup")
def testF64(self):
Expand All @@ -103,7 +103,7 @@ def testWriteReadF64(self):
@unittest.skipIf(dataDir is None, "afwdata not setup")
def testSubimage(self):
"""Test reading a subimage image"""
fileName, hdu = os.path.join(dataDir, "871034p_1_MI.fits"), 4
fileName, hdu = os.path.join(dataDir, "871034p_1_MI.fits"), 3
im = afwImage.ImageF(fileName, hdu)

bbox = afwGeom.Box2I(afwGeom.Point2I(110, 120), afwGeom.Extent2I(20, 15))
Expand Down
6 changes: 3 additions & 3 deletions tests/testMask.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,21 @@ def testSubmasks(self):
@unittest.skipIf(afwdataDir is None, "afwdata not setup")
def testReadFits(self):
nMaskPlanes0 = self.Mask.getNumPlanesUsed()
mask = self.Mask(self.maskFile, 3) # will shift any unrecognised mask planes into unused slots
mask = self.Mask(self.maskFile, hdu=2) # will shift any unrecognised mask planes into unused slots

self.assertMasksEqual(mask, self.expect << nMaskPlanes0)

@unittest.skipIf(afwdataDir is None, "afwdata not setup")
def testReadFitsConform(self):
hdu = 3
hdu = 2
mask = afwImage.MaskU(self.maskFile, hdu, None, afwGeom.Box2I(), afwImage.LOCAL, True)

self.assertMasksEqual(mask, self.expect)

@unittest.skipIf(afwdataDir is None, "afwdata not setup")
def testWriteFits(self):
nMaskPlanes0 = self.Mask.getNumPlanesUsed()
mask = self.Mask(self.maskFile, 3)
mask = self.Mask(self.maskFile, hdu=2)

self.assertMasksEqual(mask, self.expect << nMaskPlanes0)

Expand Down
4 changes: 2 additions & 2 deletions tests/testMaskedImageIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def testFitsReadConform(self):
def testFitsReadNoConform2(self):
"""Check that reading a mask doesn't invalidate the plane dictionary"""

testMask = afwImage.MaskU(self.fileName, 3)
testMask = afwImage.MaskU(self.fileName, hdu=2)

mask = self.mi.getMask()
mask |= testMask
Expand All @@ -152,7 +152,7 @@ def testFitsReadNoConform2(self):
def testFitsReadConform2(self):
"""Check that conforming a mask invalidates the plane dictionary"""

hdu, metadata, bbox, conformMasks = 3, None, afwGeom.Box2I(), True
hdu, metadata, bbox, conformMasks = 2, None, afwGeom.Box2I(), True
testMask = afwImage.MaskU(self.fileName,
hdu, metadata, bbox, afwImage.LOCAL, conformMasks)

Expand Down