Coverage for tests/test_imagePsf_trampoline.py : 43%

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
23from copy import deepcopy
25import numpy as np
27import lsst.utils.tests
28from lsst.afw.image import Image
29from lsst.geom import Box2I, Point2I, Extent2I
30from lsst.meas.algorithms import ImagePsf
33class DummyImagePsf(ImagePsf):
34 def __init__(self, image):
35 ImagePsf.__init__(self)
36 self.image = image
38 # "public" virtual overrides
39 def __deepcopy__(self, meta=None):
40 return DummyImagePsf(self.image)
42 def resized(self, width, height):
43 raise NotImplementedError("resized not implemented for DummyImagePsf")
45 # "private" virtual overrides are underscored
46 def _doComputeKernelImage(self, position=None, color=None):
47 return self.image
49 def _doComputeBBox(self, position=None, color=None):
50 return self.image.getBBox()
53class ImagePsfTrampolineTestSuite(lsst.utils.tests.TestCase):
54 def setUp(self):
55 dimensions = Extent2I(7, 7)
56 self.bbox = Box2I(Point2I(-dimensions/2), dimensions)
57 self.img = Image(self.bbox, dtype=np.float64)
58 x, y = np.ogrid[-3:4, -3:4]
59 rsqr = x**2 + y**2
60 # Some arbitrary circular double Gaussian
61 self.img.array[:] = np.exp(-0.5*rsqr**2) + np.exp(-0.5*rsqr**2/4)
62 self.img.array /= np.sum(self.img.array)
63 self.psf = DummyImagePsf(self.img)
65 def testImage(self):
66 self.assertImagesEqual(
67 self.img,
68 self.psf.computeImage()
69 )
70 self.assertImagesEqual(
71 self.img,
72 self.psf.computeKernelImage()
73 )
75 def testBBox(self):
76 self.assertEqual(
77 self.bbox,
78 self.psf.computeBBox()
79 )
81 def testResized(self):
82 with self.assertRaises(NotImplementedError):
83 self.psf.resized(9, 9)
85 def testClone(self):
86 clone1 = deepcopy(self.psf)
87 clone2 = self.psf.clone()
88 for clone in [clone1, clone2]:
89 self.assertIsNot(clone, self.psf)
90 self.assertImagesEqual(
91 clone.computeImage(),
92 self.psf.computeImage()
93 )
94 self.assertEqual(
95 clone.computeApertureFlux(0.5),
96 self.psf.computeApertureFlux(0.5)
97 )
98 self.assertEqual(
99 clone.computeShape(),
100 self.psf.computeShape()
101 )
104class MemoryTester(lsst.utils.tests.MemoryTestCase):
105 pass
108def setup_module(module):
109 lsst.utils.tests.init()
112if __name__ == "__main__": 112 ↛ 113line 112 didn't jump to line 113, because the condition on line 112 was never true
113 lsst.utils.tests.init()
114 unittest.main()