Coverage for tests/test_plotUtils.py: 33%
25 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-08 11:40 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-08 11:40 +0000
1import unittest
2import numpy as np
4from lsst.analysis.drp.plotUtils import stellarLocusFit, perpDistance
5import lsst.utils.tests
8class FitTest(lsst.utils.tests.TestCase):
9 """Test to see if the fitting and distance calculations are working"""
11 def testFitLine(self):
12 """Make a known array of points for x and y and then test that
13 the derived fit parameters are as expected."""
15 xs = np.arange(1, 10)
16 ys = np.arange(1, 10)
18 # Define an initial fit box that encompasses the points
19 testParams = {"xMin": 0, "xMax": 11, "yMin": 0, "yMax": 11, "mHW": 1, "bHW": 0}
20 paramsOut = stellarLocusFit(xs, ys, testParams)
22 # stellarLocusFit performs two iterations of fitting and also
23 # calculates the perpendicular gradient to the fit line and
24 # the points of intersection between the box and the fit
25 # line. Test that these are returning what is expected.
26 self.assertFloatsAlmostEqual(paramsOut["mODR"], 1.0)
27 self.assertFloatsAlmostEqual(paramsOut["mODR2"], 1.0)
28 self.assertFloatsAlmostEqual(paramsOut["bODR"], 0.0)
29 self.assertFloatsAlmostEqual(paramsOut["bODR2"], 0.0)
30 self.assertFloatsAlmostEqual(paramsOut["bPerpMin"], 0.0)
31 self.assertFloatsAlmostEqual(paramsOut["bPerpMax"], 22.0)
33 def testPerpDistance(self):
34 """Test the calculation of the perpendicular distance"""
36 p1 = np.array([1, 1])
37 p2 = np.array([2, 2])
38 testPoints = np.array([[1, 2], [1.5, 1.5], [2, 1]])
39 # perpDistance uses two points, p1 and p2, to define a line
40 # then calculates the perpendicular distance of the testPoints
41 # to this line
42 dists = perpDistance(p1, p2, testPoints)
43 self.assertFloatsAlmostEqual(np.array([1.0/np.sqrt(2), 0.0, -1.0/np.sqrt(2)]), np.array(dists))
46if __name__ == "__main__": 46 ↛ 47line 46 didn't jump to line 47, because the condition on line 46 was never true
47 lsst.utils.tests.init()
48 unittest.main()