Coverage for tests/test_ics.py: 54%
57 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-18 12:42 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-18 12:42 +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 unittest
23import lsst.utils.tests
24import os
25import tempfile
27import asyncio
28import matplotlib.pyplot as plt
30from lsst.summit.utils.efdUtils import makeEfdClient
31from lsst.summit.utils.tmaUtils import TMAEventMaker
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 plot_hp_measured_data,
35 FIGURE_WIDTH,
36 FIGURE_HEIGHT,
37)
39from utils import getVcr
41vcr = getVcr()
44@vcr.use_cassette()
45class M1M3ICSTestCase(lsst.utils.tests.TestCase):
47 @classmethod
48 @vcr.use_cassette()
49 def setUp(cls):
50 try:
51 cls.client = makeEfdClient(testing=True)
52 except RuntimeError:
53 raise unittest.SkipTest("Could not instantiate an EFD client")
55 cls.dayObs = 20230728 # need a day with M1M3 data
56 cls.seqNumToPlot = 38
58 cls.tmaEventMaker = TMAEventMaker(cls.client)
59 cls.events = cls.tmaEventMaker.getEvents(cls.dayObs) # does the fetch
60 cls.sampleData = cls.tmaEventMaker._data[cls.dayObs] # pull the data from the object and test length
61 cls.outputDir = tempfile.mkdtemp()
63 @vcr.use_cassette()
64 def tearDown(self):
65 loop = asyncio.get_event_loop()
66 loop.run_until_complete(self.client.influx_client.close())
68 @vcr.use_cassette()
69 def test_analysis(self):
70 plotFilename = os.path.join(self.outputDir, 'testPlotting_exp.jpg')
71 statFilename = os.path.join(self.outputDir, 'm1m3_ics_stats.csv')
72 dataFilename = os.path.join(self.outputDir, 'm1m3_ics_df.csv')
74 event = self.events[self.seqNumToPlot]
76 results = evaluate_m1m3_ics_single_slew(event, self.client)
77 results.stats.to_csv(statFilename)
78 results.df.to_csv(dataFilename)
80 self.assertTrue(os.path.isfile(dataFilename))
81 # data is big, about 2.5MB at time of writing
82 self.assertTrue(os.path.getsize(dataFilename) > 1_000_000)
83 # stats are small, about 1.8kB at time of writing
84 self.assertTrue(os.path.isfile(statFilename))
85 self.assertTrue(os.path.getsize(statFilename) > 1000)
87 dpi = 300
88 fig = plt.figure(figsize=(FIGURE_WIDTH, FIGURE_HEIGHT), dpi=dpi)
89 fig = plot_hp_measured_data(results, fig)
90 fig.savefig(plotFilename)
91 self.assertTrue(os.path.isfile(plotFilename))
92 self.assertTrue(os.path.getsize(plotFilename) > 200_000) # plot is about 400kB at 300 dpi
95class TestMemory(lsst.utils.tests.MemoryTestCase):
96 pass
99def setup_module(module):
100 lsst.utils.tests.init()
103if __name__ == "__main__": 103 ↛ 104line 103 didn't jump to line 104, because the condition on line 103 was never true
104 lsst.utils.tests.init()
105 unittest.main()