Coverage for tests/test_utils.py: 35%

37 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-03-20 03:40 -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/>. 

21 

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 

31 

32 

33class DummyClass: 

34 """A class to test the continue_class decorator""" 

35 

36 def __init__(self, x): 

37 self.x = x 

38 

39 

40@continue_class 

41class DummyClass: # noqa: F811 

42 """Update to the DummyClass""" 

43 

44 def square(self): 

45 return self.x**2 

46 

47 

48class TestUtils(ScarletTestCase): 

49 def test_integrated_gaussians(self): 

50 result = integrated_circular_gaussian() 

51 self.assertTupleEqual(result.shape, (15, 15)) 

52 

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) 

61 

62 with self.assertRaises(ValueError): 

63 integrated_circular_gaussian(x) 

64 

65 with self.assertRaises(ValueError): 

66 integrated_circular_gaussian(y=y) 

67 

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) 

80 

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) 

91 

92 def test_continue_class(self): 

93 test = DummyClass(5) 

94 self.assertEqual(test.square(), 25)