Coverage for tests/test_util.py: 29%

Shortcuts 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

45 statements  

1# LSST Data Management System 

2# Copyright 2017 LSST Corporation. 

3# 

4# This product includes software developed by the 

5# LSST Project (http://www.lsst.org/). 

6# 

7# This program is free software: you can redistribute it and/or modify 

8# it under the terms of the GNU General Public License as published by 

9# the Free Software Foundation, either version 3 of the License, or 

10# (at your option) any later version. 

11# 

12# This program is distributed in the hope that it will be useful, 

13# but WITHOUT ANY WARRANTY; without even the implied warranty of 

14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

15# GNU General Public License for more details. 

16# 

17# You should have received a copy of the LSST License Statement and 

18# the GNU General Public License along with this program. If not, 

19# see <http://www.lsstcorp.org/LegalNotices/>. 

20# 

21 

22 

23import unittest 

24 

25import lsst.utils 

26 

27from lsst.validate.drp import util 

28 

29 

30class UtilCalculations(lsst.utils.tests.TestCase): 

31 """Test utility functions.""" 

32 

33 def testEllipticityHorizonalLine(self): 

34 """Is util.ellipticity correct for a horizontal line.""" 

35 

36 ixx, ixy, iyy = 1, 0, 0 

37 exp_e, exp_e1, exp_e2 = 1+0j, 1, 0 

38 

39 obs_e, obs_e1, obs_e2 = util.ellipticity(ixx, ixy, iyy) 

40 self.assertFloatsAlmostEqual(exp_e, obs_e) 

41 self.assertFloatsAlmostEqual(exp_e1, obs_e1) 

42 self.assertFloatsAlmostEqual(exp_e2, obs_e2) 

43 

44 def testEllipticityVerticalLine(self): 

45 """Is util.ellipticity correct for a vertical line.""" 

46 

47 ixx, ixy, iyy = 0, 0, 1 

48 exp_e, exp_e1, exp_e2 = -1+0j, -1, 0 

49 

50 obs_e, obs_e1, obs_e2 = util.ellipticity(ixx, ixy, iyy) 

51 self.assertFloatsAlmostEqual(exp_e, obs_e) 

52 self.assertFloatsAlmostEqual(exp_e1, obs_e1) 

53 self.assertFloatsAlmostEqual(exp_e2, obs_e2) 

54 

55 def testEllipticityDiagonalLine(self): 

56 """Is util.ellipticity correct for a diagonal line.""" 

57 

58 ixx, ixy, iyy = 1, 1, 1 

59 exp_e, exp_e1, exp_e2 = 0+1j, 0, 1 

60 

61 obs_e, obs_e1, obs_e2 = util.ellipticity(ixx, ixy, iyy) 

62 print(obs_e, obs_e1, obs_e2) 

63 self.assertFloatsAlmostEqual(exp_e, obs_e) 

64 self.assertFloatsAlmostEqual(exp_e1, obs_e1) 

65 self.assertFloatsAlmostEqual(exp_e2, obs_e2) 

66 

67 def testEllipticityCircle(self): 

68 """Is util.ellipticity correct for a circle.""" 

69 

70 ixx, ixy, iyy = 1, 0, 1 

71 exp_e, exp_e1, exp_e2 = 0+0j, 0, 0 

72 

73 obs_e, obs_e1, obs_e2 = util.ellipticity(ixx, ixy, iyy) 

74 self.assertFloatsAlmostEqual(exp_e, obs_e) 

75 self.assertFloatsAlmostEqual(exp_e1, obs_e1) 

76 self.assertFloatsAlmostEqual(exp_e2, obs_e2) 

77 

78 def testEllipticityEllipse(self): 

79 """Is util.ellipticity correct for an ellipse.""" 

80 

81 ixx, ixy, iyy = 4, 0, 1 

82 exp_e, exp_e1, exp_e2 = 0.6+0j, 0.6, 0 

83 

84 obs_e, obs_e1, obs_e2 = util.ellipticity(ixx, ixy, iyy) 

85 self.assertFloatsAlmostEqual(exp_e, obs_e) 

86 self.assertFloatsAlmostEqual(exp_e1, obs_e1) 

87 self.assertFloatsAlmostEqual(exp_e2, obs_e2) 

88 

89 

90def setup_module(module): 

91 lsst.utils.tests.init() 

92 

93 

94if __name__ == "__main__": 94 ↛ 95line 94 didn't jump to line 95, because the condition on line 94 was never true

95 lsst.utils.tests.init() 

96 unittest.main()