Coverage for tests/test_statClipException1045.py: 26%
70 statements
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-03 02:47 -0700
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-03 02:47 -0700
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#
23# -*- lsst-python -*-
24"""
25Tests for ticket 1043 - Photometry fails when no PSF is provided
26"""
28import math
29import unittest
31import numpy as np
33import lsst.afw.math as afwMath
34import lsst.utils.tests
35import lsst.pex.exceptions as pexExcept
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
44class Ticket1045TestCase(unittest.TestCase):
46 def setUp(self):
47 pass
49 def tearDown(self):
50 pass
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
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)
65 # this was reported to fail
66 # (problem was due to error in median)
67 knownMeanClip = 1.097431111111111
68 knownStdevClip = 0.012984991763998597
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)
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)
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)
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)
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)
104 # check the median with no values
105 vals = []
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)
113 def testUnexpectedNan1051(self):
115 values = [7824.0, 7803.0, 7871.0, 7567.0,
116 7813.0, 7809.0, 8011.0, 7807.0]
117 npValues = np.array(values)
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)
126class TestMemory(lsst.utils.tests.MemoryTestCase):
127 pass
130def setup_module(module):
131 lsst.utils.tests.init()
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()