Coverage for tests/test_plotUtils.py: 36%

23 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-10 11:26 +0000

1import unittest 

2import numpy as np 

3 

4from lsst.analysis.drp.plotUtils import stellarLocusFit, perpDistance 

5import lsst.utils.tests 

6 

7 

8class FitTest(lsst.utils.tests.TestCase): 

9 """Test to see if the fitting and distance calculations are working""" 

10 

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.""" 

14 

15 xs = np.arange(1, 10) 

16 ys = np.arange(1, 10) 

17 

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) 

21 

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["bODR"], 0.0) 

28 self.assertFloatsAlmostEqual(paramsOut["bPerpMin"], 0.0) 

29 self.assertFloatsAlmostEqual(paramsOut["bPerpMax"], 22.0) 

30 

31 def testPerpDistance(self): 

32 """Test the calculation of the perpendicular distance""" 

33 

34 p1 = np.array([1, 1]) 

35 p2 = np.array([2, 2]) 

36 testPoints = np.array([[1, 2], [1.5, 1.5], [2, 1]]) 

37 # perpDistance uses two points, p1 and p2, to define a line 

38 # then calculates the perpendicular distance of the testPoints 

39 # to this line 

40 dists = perpDistance(p1, p2, testPoints) 

41 self.assertFloatsAlmostEqual(np.array([1.0/np.sqrt(2), 0.0, -1.0/np.sqrt(2)]), np.array(dists)) 

42 

43 

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

45 lsst.utils.tests.init() 

46 unittest.main()