Coverage for tests/test_statClipException1045.py: 26%

70 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-01-10 02:46 -0800

1# 

2# LSST Data Management System 

3# Copyright 2008, 2009, 2010 LSST Corporation. 

4# 

5# This product includes software developed by the 

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

7# 

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

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

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

11# (at your option) any later version. 

12# 

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

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

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

16# GNU General Public License for more details. 

17# 

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

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

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

21# 

22 

23# -*- lsst-python -*- 

24""" 

25Tests for ticket 1043 - Photometry fails when no PSF is provided 

26""" 

27 

28import math 

29import unittest 

30 

31import numpy as np 

32 

33import lsst.afw.math as afwMath 

34import lsst.utils.tests 

35import lsst.pex.exceptions as pexExcept 

36 

37# math.isnan() available in 2.6, but not 2.5.2 

38try: 

39 math.isnan(1) 

40except AttributeError: 

41 math.isnan = lambda x: x != x 

42 

43 

44class Ticket1045TestCase(unittest.TestCase): 

45 

46 def setUp(self): 

47 pass 

48 

49 def tearDown(self): 

50 pass 

51 

52 def testTicket1045(self): 

53 values = [1.08192, 1.08792, 1.08774, 1.09953, 1.1122, 

54 1.09408, 0.879792, 1.12235, 1.10115, 1.08999] 

55 knownMean, knownStdev = np.mean(values), 0.069903889977279199 

56 

57 # this was reported to work 

58 dmean1 = afwMath.makeStatistics( 

59 values, afwMath.NPOINT | afwMath.MEAN | afwMath.STDEV) 

60 mean1 = dmean1.getValue(afwMath.MEAN) 

61 stdev1 = dmean1.getValue(afwMath.STDEV) 

62 self.assertAlmostEqual(mean1, knownMean, 8) 

63 self.assertAlmostEqual(stdev1, knownStdev, places=16) 

64 

65 # this was reported to fail 

66 # (problem was due to error in median) 

67 knownMeanClip = 1.097431111111111 

68 knownStdevClip = 0.012984991763998597 

69 

70 dmean2 = afwMath.makeStatistics( 

71 values, afwMath.NPOINT | afwMath.MEANCLIP | afwMath.STDEVCLIP) 

72 mean2 = dmean2.getValue(afwMath.MEANCLIP) 

73 stdev2 = dmean2.getValue(afwMath.STDEVCLIP) 

74 self.assertEqual(mean2, knownMeanClip) 

75 self.assertEqual(stdev2, knownStdevClip) 

76 

77 # check the median, just for giggles 

78 knownMedian = np.median(values) 

79 stat = afwMath.makeStatistics(values, afwMath.MEDIAN) 

80 median = stat.getValue(afwMath.MEDIAN) 

81 self.assertEqual(median, knownMedian) 

82 

83 # check the median with an odd number of values 

84 vals = values[1:] 

85 knownMedian = np.median(vals) 

86 stat = afwMath.makeStatistics(vals, afwMath.MEDIAN) 

87 median = stat.getValue(afwMath.MEDIAN) 

88 self.assertEqual(median, knownMedian) 

89 

90 # check the median with only two values 

91 vals = values[0:2] 

92 knownMedian = np.median(vals) 

93 stat = afwMath.makeStatistics(vals, afwMath.MEDIAN) 

94 median = stat.getValue(afwMath.MEDIAN) 

95 self.assertEqual(median, knownMedian) 

96 

97 # check the median with only 1 value 

98 vals = values[0:1] 

99 knownMedian = np.median(vals) 

100 stat = afwMath.makeStatistics(vals, afwMath.MEDIAN) 

101 median = stat.getValue(afwMath.MEDIAN) 

102 self.assertEqual(median, knownMedian) 

103 

104 # check the median with no values 

105 vals = [] 

106 

107 def tst(): 

108 stat = afwMath.makeStatistics(vals, afwMath.MEDIAN) 

109 median = stat.getValue(afwMath.MEDIAN) 

110 return median 

111 self.assertRaises(pexExcept.InvalidParameterError, tst) 

112 

113 def testUnexpectedNan1051(self): 

114 

115 values = [7824.0, 7803.0, 7871.0, 7567.0, 

116 7813.0, 7809.0, 8011.0, 7807.0] 

117 npValues = np.array(values) 

118 

119 meanClip = afwMath.makeStatistics(values, afwMath.MEANCLIP).getValue() 

120 # note ... it will clip indices 3 and 6 

121 iKept = np.array([0, 1, 2, 4, 5, 7]) 

122 knownMeanClip = np.mean(npValues[iKept]) 

123 self.assertEqual(meanClip, knownMeanClip) 

124 

125 

126class TestMemory(lsst.utils.tests.MemoryTestCase): 

127 pass 

128 

129 

130def setup_module(module): 

131 lsst.utils.tests.init() 

132 

133 

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

135 lsst.utils.tests.init() 

136 unittest.main()