Coverage for tests / test_ics.py: 42%
61 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-25 09:03 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-25 09:03 +0000
1# This file is part of summit_utils.
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 asyncio
23import logging
24import os
25import tempfile
26import unittest
28import matplotlib.pyplot as plt
29from utils import getVcr
31import lsst.utils.tests
32from lsst.summit.utils.efdUtils import makeEfdClient
33from lsst.summit.utils.m1m3.inertia_compensation_system import evaluate_m1m3_ics_single_slew
34from lsst.summit.utils.m1m3.plots.plot_ics import FIGURE_HEIGHT, FIGURE_WIDTH, plot_hp_measured_data
35from lsst.summit.utils.tmaUtils import TMAEventMaker
37vcr = getVcr()
40@vcr.use_cassette()
41class M1M3ICSTestCase(lsst.utils.tests.TestCase):
42 @classmethod
43 @vcr.use_cassette()
44 def setUp(cls):
45 try:
46 cls.client = makeEfdClient(testing=True)
47 except RuntimeError:
48 raise unittest.SkipTest("Could not instantiate an EFD client")
50 cls.dayObs = 20230728 # need a day with M1M3 data
51 cls.seqNumToPlot = 38
53 cls.tmaEventMaker = TMAEventMaker(cls.client)
54 cls.events = cls.tmaEventMaker.getEvents(cls.dayObs) # does the fetch
55 cls.sampleData = cls.tmaEventMaker._data[cls.dayObs] # pull the data from the object and test length
56 cls.outputDir = tempfile.mkdtemp()
57 cls.log = logging.getLogger(__name__)
59 @vcr.use_cassette()
60 def tearDown(self):
61 loop = asyncio.get_event_loop()
62 if self.client.influx_client is not None:
63 loop.run_until_complete(self.client.influx_client.close())
65 @vcr.use_cassette()
66 def test_analysis(self):
67 self.log.info(f"Writing temp output files to {self.outputDir}")
68 plotFilename = os.path.join(self.outputDir, "testPlotting_exp.jpg")
69 statFilename = os.path.join(self.outputDir, "m1m3_ics_stats.csv")
70 dataFilename = os.path.join(self.outputDir, "m1m3_ics_df.csv")
72 event = self.events[self.seqNumToPlot]
74 results = evaluate_m1m3_ics_single_slew(event, self.client)
75 results.stats.to_csv(statFilename)
76 results.df.to_csv(dataFilename)
78 self.assertTrue(os.path.isfile(dataFilename))
79 # data is big, about 2.5MB at time of writing
80 self.assertTrue(os.path.getsize(dataFilename) > 400_000)
81 # stats are small, about 1.8kB at time of writing
82 self.assertTrue(os.path.isfile(statFilename))
83 self.assertTrue(os.path.getsize(statFilename) > 1000)
85 dpi = 300
86 fig = plt.figure(figsize=(FIGURE_WIDTH, FIGURE_HEIGHT), dpi=dpi)
87 fig = plot_hp_measured_data(results, fig)
88 fig.savefig(plotFilename)
89 self.assertTrue(os.path.isfile(plotFilename))
90 self.assertTrue(os.path.getsize(plotFilename) > 200_000) # plot is about 400kB at 300 dpi
93class TestMemory(lsst.utils.tests.MemoryTestCase):
94 pass
97def setup_module(module):
98 lsst.utils.tests.init()
101if __name__ == "__main__": 101 ↛ 102line 101 didn't jump to line 102 because the condition on line 101 was never true
102 lsst.utils.tests.init()
103 unittest.main()