Coverage for tests/test_ics.py: 54%
57 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-09 13:02 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-09 13:02 +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 os
24import tempfile
25import unittest
27import matplotlib.pyplot as plt
28from utils import getVcr
30import lsst.utils.tests
31from lsst.summit.utils.efdUtils import makeEfdClient
32from lsst.summit.utils.m1m3.inertia_compensation_system import evaluate_m1m3_ics_single_slew
33from lsst.summit.utils.m1m3.plots.inertia_compensation_system import (
34 FIGURE_HEIGHT,
35 FIGURE_WIDTH,
36 plot_hp_measured_data,
37)
38from lsst.summit.utils.tmaUtils import TMAEventMaker
40vcr = getVcr()
43@vcr.use_cassette()
44class M1M3ICSTestCase(lsst.utils.tests.TestCase):
45 @classmethod
46 @vcr.use_cassette()
47 def setUp(cls):
48 try:
49 cls.client = makeEfdClient(testing=True)
50 except RuntimeError:
51 raise unittest.SkipTest("Could not instantiate an EFD client")
53 cls.dayObs = 20230728 # need a day with M1M3 data
54 cls.seqNumToPlot = 38
56 cls.tmaEventMaker = TMAEventMaker(cls.client)
57 cls.events = cls.tmaEventMaker.getEvents(cls.dayObs) # does the fetch
58 cls.sampleData = cls.tmaEventMaker._data[cls.dayObs] # pull the data from the object and test length
59 cls.outputDir = tempfile.mkdtemp()
61 @vcr.use_cassette()
62 def tearDown(self):
63 loop = asyncio.get_event_loop()
64 loop.run_until_complete(self.client.influx_client.close())
66 @vcr.use_cassette()
67 def test_analysis(self):
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) > 1_000_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()