Coverage for tests/test_exposureFromImage.py : 29%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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 rows
82 Variance values equal image values + 100
83 Mask values equal image values modulo 8 bits (leaving plenty of unused values)
84 """
85 mi = imgClass(width, height)
86 image = mi.getImage()
87 mask = mi.getMask()
88 variance = mi.getVariance()
89 val = 0
90 for yInd in range(height):
91 for xInd in range(width):
92 image[xInd, yInd, afwImage.LOCAL] = val
93 variance[xInd, yInd, afwImage.LOCAL] = val + 100
94 mask[xInd, yInd, afwImage.LOCAL] = val % 0x100
95 val += 1
96 return mi
99class MemoryTester(lsst.utils.tests.MemoryTestCase):
100 pass
103def setup_module(module):
104 lsst.utils.tests.init()
107if __name__ == "__main__": 107 ↛ 108line 107 didn't jump to line 108, because the condition on line 107 was never true
108 lsst.utils.tests.init()
109 unittest.main()