Coverage for tests/test_exposureFromImage.py: 29%
60 statements
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-12 01:53 -0800
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-12 01:53 -0800
1# This file is part of obs_base.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22import unittest
24import lsst.utils.tests
25from lsst.daf.base import PropertyList
26from lsst.obs.base import exposureFromImage
27import lsst.afw.image as afwImage
30class ExposureFromImageTestCase(lsst.utils.tests.TestCase):
31 """A test case for exposureFromImage."""
33 def setUp(self):
34 self.maskedImage = makeRampMaskedImage(10, 11)
36 def tearDown(self):
37 del self.maskedImage
39 def testDecoratedImage(self):
40 image = self.maskedImage.getImage()
41 decoImage = afwImage.DecoratedImageF(image)
42 metadata = PropertyList()
43 metadata.set("FOO", "BAR")
44 decoImage.setMetadata(metadata)
45 exposure = exposureFromImage(decoImage)
46 self.assertImagesEqual(exposure.getMaskedImage().getImage(), image)
47 md = exposure.getMetadata()
48 self.assertEqual(md.getScalar("FOO"), "BAR")
50 def testExposure(self):
51 inExposure = afwImage.ExposureF(self.maskedImage)
52 outExposure = exposureFromImage(inExposure)
53 self.assertIs(inExposure, outExposure)
55 def testImage(self):
56 image = self.maskedImage.getImage()
57 exposure = exposureFromImage(image)
58 self.assertImagesEqual(image, exposure.getMaskedImage().getImage())
60 def testMaskedImage(self):
61 exposure = exposureFromImage(self.maskedImage)
62 self.assertMaskedImagesEqual(self.maskedImage, exposure.getMaskedImage())
64 def testDecoratedImageBadWcs(self):
65 """Test that exposureFromImage() attaches a None wcs to the exposure
66 when the WCS cannot be constructed
67 """
68 image = self.maskedImage.getImage()
69 decoImage = afwImage.DecoratedImageF(image)
70 metadata = PropertyList()
71 metadata.set("CTYPE1", "RA---TPV")
72 metadata.set("CTYPE2", "DEC--TPV")
73 decoImage.setMetadata(metadata)
74 exposure = exposureFromImage(decoImage)
75 self.assertIs(exposure.getWcs(), None)
78def makeRampMaskedImage(width, height, imgClass=afwImage.MaskedImageF):
79 """Make a ramp image of the specified size and image class
81 Image values start from 0 at the lower left corner and increase by 1 along
82 rows. Variance values equal image values + 100.
83 Mask values equal image values modulo 8 bits (leaving plenty of unused
84 values).
85 """
86 mi = imgClass(width, height)
87 image = mi.getImage()
88 mask = mi.getMask()
89 variance = mi.getVariance()
90 val = 0
91 for yInd in range(height):
92 for xInd in range(width):
93 image[xInd, yInd, afwImage.LOCAL] = val
94 variance[xInd, yInd, afwImage.LOCAL] = val + 100
95 mask[xInd, yInd, afwImage.LOCAL] = val % 0x100
96 val += 1
97 return mi
100class MemoryTester(lsst.utils.tests.MemoryTestCase):
101 pass
104def setup_module(module):
105 lsst.utils.tests.init()
108if __name__ == "__main__": 108 ↛ 109line 108 didn't jump to line 109, because the condition on line 108 was never true
109 lsst.utils.tests.init()
110 unittest.main()