Coverage for tests/test_utils.py: 35%
37 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-16 02:46 -0700
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-16 02:46 -0700
1# This file is part of lsst.scarlet.lite.
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 numpy as np
23from lsst.scarlet.lite.utils import (
24 continue_class,
25 get_circle_mask,
26 integrated_circular_gaussian,
27 integrated_gaussian_value,
28)
29from numpy.testing import assert_array_almost_equal, assert_array_equal
30from utils import ScarletTestCase
33class DummyClass:
34 """A class to test the continue_class decorator"""
36 def __init__(self, x):
37 self.x = x
40@continue_class
41class DummyClass: # noqa: F811
42 """Update to the DummyClass"""
44 def square(self):
45 return self.x**2
48class TestUtils(ScarletTestCase):
49 def test_integrated_gaussians(self):
50 result = integrated_circular_gaussian()
51 self.assertTupleEqual(result.shape, (15, 15))
53 x = np.arange(-5, 6)
54 y = np.arange(-3, 4)
55 result = integrated_circular_gaussian(x, y, sigma=1.2)
56 x_psf = integrated_gaussian_value(x, sigma=1.2)
57 y_psf = integrated_gaussian_value(y, sigma=1.2)
58 truth = x_psf[None, :] * y_psf[:, None]
59 truth /= np.sum(truth)
60 assert_array_almost_equal(result, truth)
62 with self.assertRaises(ValueError):
63 integrated_circular_gaussian(x)
65 with self.assertRaises(ValueError):
66 integrated_circular_gaussian(y=y)
68 def test_circle_mask(self):
69 truth = [
70 [0, 0, 0, 1, 0, 0, 0],
71 [0, 1, 1, 1, 1, 1, 0],
72 [0, 1, 1, 1, 1, 1, 0],
73 [1, 1, 1, 1, 1, 1, 1],
74 [0, 1, 1, 1, 1, 1, 0],
75 [0, 1, 1, 1, 1, 1, 0],
76 [0, 0, 0, 1, 0, 0, 0],
77 ]
78 x = get_circle_mask(7, dtype=int)
79 assert_array_equal(x, truth)
81 truth = [
82 [0, 1, 1, 1, 1, 0],
83 [1, 1, 1, 1, 1, 1],
84 [1, 1, 1, 1, 1, 1],
85 [1, 1, 1, 1, 1, 1],
86 [1, 1, 1, 1, 1, 1],
87 [0, 1, 1, 1, 1, 0],
88 ]
89 x = get_circle_mask(6, dtype=int)
90 assert_array_equal(x, truth)
92 def test_continue_class(self):
93 test = DummyClass(5)
94 self.assertEqual(test.square(), 25)