Coverage for tests/test_minimize.py: 30%

33 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-03-29 02:27 -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# 

22 

23import unittest 

24 

25import numpy as np 

26 

27import lsst.utils.tests 

28import lsst.afw.math as afwMath 

29 

30 

31class MinimizeTestCase(lsst.utils.tests.TestCase): 

32 

33 def testMinimize2(self): 

34 

35 variances = np.array([0.01, 0.01, 0.01, 0.01]) 

36 xPositions = np.array([0.0, 1.0, 0.0, 1.0]) 

37 yPositions = np.array([0.0, 0.0, 1.0, 1.0]) 

38 

39 polyOrder = 1 

40 polyFunc = afwMath.PolynomialFunction2D(polyOrder) 

41 

42 modelParams = [0.1, 0.2, 0.3] 

43 polyFunc.setParameters(modelParams) 

44 measurements = [] 

45 for x, y in zip(xPositions, yPositions): 

46 measurements.append(polyFunc(x, y)) 

47 print("measurements=", measurements) 

48 

49 # Set up initial guesses 

50 nParameters = polyFunc.getNParameters() 

51 initialParameters = np.zeros(nParameters, float) 

52 stepsize = np.ones(nParameters, float) 

53 stepsize *= 0.1 

54 

55 # Minimize! 

56 fitResults = afwMath.minimize( 

57 polyFunc, 

58 initialParameters, 

59 stepsize, 

60 measurements, 

61 variances, 

62 xPositions, 

63 yPositions, 

64 0.1, 

65 ) 

66 

67 print("modelParams=", modelParams) 

68 print("fitParams =", fitResults.parameterList) 

69 self.assertTrue(fitResults.isValid, "fit failed") 

70 self.assertFloatsAlmostEqual( 

71 np.array(modelParams), np.array(fitResults.parameterList), 1e-11) 

72 

73 

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

75 pass 

76 

77 

78def setup_module(module): 

79 lsst.utils.tests.init() 

80 

81 

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

83 lsst.utils.tests.init() 

84 unittest.main()