Skip to content

Commit

Permalink
Add a unittest for MaskedImageFitsReader
Browse files Browse the repository at this point in the history
  • Loading branch information
arunkannawadi committed Dec 6, 2023
1 parent b2a3387 commit cc6bab3
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from lsst.geom import Box2I, Point2I, Extent2I, Point2D, Box2D, SpherePoint, degrees
from lsst.afw.geom import makeSkyWcs, Polygon
from lsst.afw.table import ExposureTable
from lsst.afw.image import (Image, Mask, Exposure, LOCAL, PARENT, MaskPixel, VariancePixel,
from lsst.afw.image import (Image, Mask, MaskedImage, Exposure, LOCAL, PARENT, MaskPixel, VariancePixel,
ImageFitsReader, MaskFitsReader, MaskedImageFitsReader, ExposureFitsReader,
FilterLabel, PhotoCalib, ApCorrMap, VisitInfo, TransmissionCurve,
CoaddInputs, ExposureInfo, ExposureF)
Expand Down Expand Up @@ -103,6 +103,29 @@ def testMaskFitsReader(self):
self.assertEqual(subIn.getXY0(), reader.readXY0(*args))
self.assertImagesEqual(subIn, mask)

def testMaskedImageFitsReader(self):
for n, dtypeIn in enumerate(self.dtypes):
with self.subTest(dtypeIn=dtypeIn):
maskedImageIn = MaskedImage(self.bbox, dtype=dtypeIn)
maskedImageIn.image.array[:, :] = np.random.randint(low=1, high=5,
size=maskedImageIn.image.array.shape
)
maskedImageIn.mask.array[:, :] = np.random.randint(low=1, high=5,
size=maskedImageIn.mask.array.shape
)
maskedImageIn.variance.array[:, :] = np.random.randint(low=1, high=5,
size=maskedImageIn.variance.array.shape
)
with lsst.utils.tests.getTempFilePath(".fits") as fileName:
maskedImageIn.writeFits(fileName)
reader = MaskedImageFitsReader(fileName)
self.assertEqual(reader.readBBox(), self.bbox)
self.assertEqual(reader.readImageDType(), dtypeIn)
self.assertEqual(reader.fileName, fileName)
self.checkMultiPlaneReader(reader, maskedImageIn, fileName, self.dtypes[n:],
compare=self.assertMaskedImagesEqual)
self.checkMaskedImageFitsReader(maskedImageIn, fileName, self.dtypes[n:])

def checkMultiPlaneReader(self, reader, objectIn, fileName, dtypesOut, compare):
"""Test operations common to MaskedImageFitsReader and ExposureFitsReader.
Expand Down

0 comments on commit cc6bab3

Please sign in to comment.