Coverage for tests/test_focusAnalysis.py: 36%
55 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-07 04:45 -0700
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-07 04:45 -0700
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/>.
22import unittest
23from typing import Iterable
25import matplotlib as mpl
27import lsst.utils.tests
29mpl.use("Agg")
31import lsst.summit.utils.butlerUtils as butlerUtils # noqa: E402
32from lsst.summit.extras import NonSpectralFocusAnalyzer, SpectralFocusAnalyzer # noqa: E402
35class FocusAnalysisTestCase(lsst.utils.tests.TestCase):
36 @classmethod
37 def setUpClass(cls):
38 try:
39 cls.butler = butlerUtils.makeDefaultLatissButler()
40 except FileNotFoundError:
41 raise unittest.SkipTest("Skipping tests that require the LATISS butler repo.")
43 # dataIds have been chosen match those of a spectral focus sweep which
44 # is in the LATISS-test-data collection at the summit, TTS and USDF
45 cls.dayObs = 20220628
46 cls.seqNums = range(280, 288 + 1)
47 cls.focusAnalyzer = SpectralFocusAnalyzer()
49 # default is 3 boxes, so setting four tests the generality of the code.
50 # The values have been picked to land on the pretty small spectrum we
51 # have in the test data.
52 cls.focusAnalyzer.setSpectrumBoxOffsets([1600, 1700, 1800, 1900])
54 def test_run(self):
55 # we don't check the plots, but set doDisplay to True to check the
56 # plots are generated without error
57 self.focusAnalyzer.getFocusData(self.dayObs, self.seqNums, doDisplay=True)
58 result = self.focusAnalyzer.fitDataAndPlot()
59 self.assertIsInstance(result, Iterable)
60 self.assertEqual(len(result), len(self.focusAnalyzer.getSpectrumBoxOffsets()))
62 for number in result:
63 # check they're all numbers, non-nan, and vaguely sensible. These
64 # are values in mm of the hexapod offset from nominal focus and are
65 # usually very small (around 0.01mm) so this is just testing that
66 # something hasn't gone wildly wrong with the fit
67 self.assertGreater(number, -2.0)
68 self.assertLess(number, 2.0)
71class NonSpectralFocusAnalysisTestCase(lsst.utils.tests.TestCase):
72 @classmethod
73 def setUpClass(cls):
74 try:
75 cls.butler = butlerUtils.makeDefaultLatissButler()
76 except FileNotFoundError:
77 raise unittest.SkipTest("Skipping tests that require the LATISS butler repo.")
79 # dataIds have been chosen match those of a non-spectral focus sweep
80 # which is in the LATISS-test-data collection at the summit, TTS and
81 # USDF
82 cls.dayObs = 20220405
83 cls.seqNums = range(523, 531 + 1)
84 cls.focusAnalyzer = NonSpectralFocusAnalyzer()
86 def test_run(self):
87 # we don't check the plots, but set doDisplay to True to check the
88 # plots are generated without error
89 self.focusAnalyzer.getFocusData(self.dayObs, self.seqNums, doDisplay=True)
90 result = self.focusAnalyzer.fitDataAndPlot()
91 self.assertIsInstance(result, dict)
93 # result is a dict which looks like this:
94 # {'fwhmFitMin': 0.029221417454391708,
95 # 'ee90FitMin': 0.0754762884665358,
96 # 'ee80FitMin': 0.07188778363981346,
97 # 'ee50FitMin': 0.13998855716378267}
98 self.assertEqual(len(result), 4)
100 for k, v in result.items():
101 # check they're all numbers, non-nan, and vaguely sensible. The
102 # values are the position of the fwhm which should be close to zero
103 # on the x-axis assuming we were roughly symmetric around focus
104 # (which is the case for the current test dataset) and encircled
105 # energy radii, which also should be small as the data in question
106 # was roughly in focus. This is really just to check that the code
107 # isn't horribly broken, so not much attention should be paid
108 # to these numerical values.
109 self.assertIsInstance(k, str)
110 self.assertIsInstance(v, float)
112 if k == "fwhmFitMin":
113 # everything else is strictly positive but the fwhm position
114 # can be negative.
115 v = abs(v)
117 self.assertGreater(v, 0.0)
118 self.assertLess(v, 1.0)
121class TestMemory(lsst.utils.tests.MemoryTestCase):
122 pass
125def setup_module(module):
126 lsst.utils.tests.init()
129if __name__ == "__main__": 129 ↛ 130line 129 didn't jump to line 130, because the condition on line 129 was never true
130 lsst.utils.tests.init()
131 unittest.main()