Coverage for tests / test_focusAnalysis.py: 29%

60 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-01 09:04 +0000

1# This file is part of summit_extras. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

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

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

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

12# (at your option) any later version. 

13# 

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

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

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

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <https://www.gnu.org/licenses/>. 

21 

22import unittest 

23from typing import Iterable 

24 

25import matplotlib as mpl 

26 

27import lsst.utils.tests 

28 

29mpl.use("Agg") 

30 

31 

32import lsst.summit.utils.butlerUtils as butlerUtils # noqa: E402 

33from lsst.summit.extras import NonSpectralFocusAnalyzer, SpectralFocusAnalyzer # noqa: E402 

34from lsst.summit.utils.utils import getSite # noqa: E402 

35 

36 

37class FocusAnalysisTestCase(lsst.utils.tests.TestCase): 

38 @classmethod 

39 def setUpClass(cls): 

40 try: 

41 if getSite() == "jenkins": 

42 raise unittest.SkipTest("Skip running butler-driven tests in Jenkins.") 

43 cls.butler = butlerUtils.makeDefaultLatissButler() 

44 except FileNotFoundError: 

45 raise unittest.SkipTest("Skipping tests that require the LATISS butler repo.") 

46 

47 # dataIds have been chosen match those of a spectral focus sweep which 

48 # is in the LATISS-test-data collection at the summit, TTS and USDF 

49 cls.dayObs = 20220628 

50 cls.seqNums = range(280, 288 + 1) 

51 cls.focusAnalyzer = SpectralFocusAnalyzer() 

52 

53 # default is 3 boxes, so setting four tests the generality of the code. 

54 # The values have been picked to land on the pretty small spectrum we 

55 # have in the test data. 

56 cls.focusAnalyzer.setSpectrumBoxOffsets([1600, 1700, 1800, 1900]) 

57 

58 def test_run(self): 

59 # we don't check the plots, but set doDisplay to True to check the 

60 # plots are generated without error 

61 

62 self.focusAnalyzer.getFocusData(self.dayObs, self.seqNums, doDisplay=True) 

63 result = self.focusAnalyzer.fitDataAndPlot() 

64 self.assertIsInstance(result, Iterable) 

65 self.assertEqual(len(result), len(self.focusAnalyzer.getSpectrumBoxOffsets())) 

66 

67 for number in result: 

68 # check they're all numbers, non-nan, and vaguely sensible. These 

69 # are values in mm of the hexapod offset from nominal focus and are 

70 # usually very small (around 0.01mm) so this is just testing that 

71 # something hasn't gone wildly wrong with the fit 

72 self.assertGreater(number, -2.0) 

73 self.assertLess(number, 2.0) 

74 

75 

76class NonSpectralFocusAnalysisTestCase(lsst.utils.tests.TestCase): 

77 @classmethod 

78 def setUpClass(cls): 

79 try: 

80 if getSite() == "jenkins": 

81 raise unittest.SkipTest("Skip running butler-driven tests in Jenkins.") 

82 cls.butler = butlerUtils.makeDefaultLatissButler() 

83 except FileNotFoundError: 

84 raise unittest.SkipTest("Skipping tests that require the LATISS butler repo.") 

85 

86 # dataIds have been chosen match those of a non-spectral focus sweep 

87 # which is in the LATISS-test-data collection at the summit, TTS and 

88 # USDF 

89 cls.dayObs = 20220405 

90 cls.seqNums = range(523, 531 + 1) 

91 cls.focusAnalyzer = NonSpectralFocusAnalyzer() 

92 

93 def test_run(self): 

94 # we don't check the plots, but set doDisplay to True to check the 

95 # plots are generated without error 

96 self.focusAnalyzer.getFocusData(self.dayObs, self.seqNums, doDisplay=True) 

97 result = self.focusAnalyzer.fitDataAndPlot() 

98 self.assertIsInstance(result, dict) 

99 

100 # result is a dict which looks like this: 

101 # {'fwhmFitMin': 0.029221417454391708, 

102 # 'ee90FitMin': 0.0754762884665358, 

103 # 'ee80FitMin': 0.07188778363981346, 

104 # 'ee50FitMin': 0.13998855716378267} 

105 self.assertEqual(len(result), 4) 

106 

107 for k, v in result.items(): 

108 # check they're all numbers, non-nan, and vaguely sensible. The 

109 # values are the position of the fwhm which should be close to zero 

110 # on the x-axis assuming we were roughly symmetric around focus 

111 # (which is the case for the current test dataset) and encircled 

112 # energy radii, which also should be small as the data in question 

113 # was roughly in focus. This is really just to check that the code 

114 # isn't horribly broken, so not much attention should be paid 

115 # to these numerical values. 

116 self.assertIsInstance(k, str) 

117 self.assertIsInstance(v, float) 

118 

119 if k == "fwhmFitMin": 

120 # everything else is strictly positive but the fwhm position 

121 # can be negative. 

122 v = abs(v) 

123 

124 self.assertGreater(v, 0.0) 

125 self.assertLess(v, 1.0) 

126 

127 

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

129 pass 

130 

131 

132def setup_module(module): 

133 lsst.utils.tests.init() 

134 

135 

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

137 lsst.utils.tests.init() 

138 unittest.main()