Coverage for tests/test_stamps.py : 30%

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 meas_algorithms.
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
23import numpy as np
24import tempfile
26from lsst.meas.algorithms import stamps
27from lsst.afw import image as afwImage
28from lsst.daf.base import PropertyList
29import lsst.geom as geom
30import lsst.utils.tests
32np.random.seed(90210)
35def make_stamps():
36 stampSize = 25
37 # create dummy stamp stamps
38 stampImages = [afwImage.maskedImage.MaskedImageF(stampSize, stampSize)
39 for _ in range(3)]
40 for stampIm in stampImages:
41 stampImArray = stampIm.image.array
42 stampImArray += np.random.rand(stampSize, stampSize)
43 ras = np.random.rand(3)*360.
44 decs = np.random.rand(3)*180 - 90
45 stamp_list = [stamps.Stamp(stamp_im=stampIm,
46 position=geom.SpherePoint(geom.Angle(ra, geom.degrees),
47 geom.Angle(dec, geom.degrees)))
48 for stampIm, ra, dec in zip(stampImages, ras, decs)]
49 metadata = PropertyList()
50 metadata['RA_DEG'] = ras
51 metadata['DEC_DEG'] = decs
53 return stamps.Stamps(stamp_list, metadata=metadata)
56class StampsTestCase(lsst.utils.tests.TestCase):
57 """Test Stamps.
58 """
59 def testAppend(self):
60 """Test ability to append to a Stamps object
61 """
62 ss = make_stamps()
63 s = ss[-1]
64 ss.append(s)
65 self.roundtrip(ss)
66 # check if appending something other than a Stamp raises
67 with self.assertRaises(ValueError):
68 ss.append('hello world')
70 def testExtend(self):
71 ss = make_stamps()
72 ss2 = make_stamps()
73 ss.extend([s for s in ss2])
74 # check if extending with something other than a Stamps
75 # object raises
76 with self.assertRaises(ValueError):
77 ss.extend(['hello', 'world'])
79 def testIO(self):
80 """Test the class' write and readFits methods.
81 """
82 self.roundtrip(make_stamps())
84 def roundtrip(self, ss):
85 """Round trip a Stamps object to disk and check values
86 """
87 with tempfile.NamedTemporaryFile() as f:
88 ss.writeFits(f.name)
89 options = PropertyList()
90 ss2 = stamps.Stamps.readFitsWithOptions(f.name, options)
91 self.assertEqual(len(ss), len(ss2))
92 for s1, s2 in zip(ss, ss2):
93 self.assertMaskedImagesAlmostEqual(s1.stamp_im, s2.stamp_im)
94 self.assertAlmostEqual(s1.position.getRa().asDegrees(),
95 s2.position.getRa().asDegrees())
96 self.assertAlmostEqual(s1.position.getDec().asDegrees(),
97 s2.position.getDec().asDegrees())
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()