Coverage for tests / test_diaSourceTableTractMetrics.py: 34%
30 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-28 09:21 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-28 09:21 +0000
1#
2# Developed for the LSST Data Management System.
3# This product includes software developed by the LSST Project
4# (https://www.lsst.org).
5# See the COPYRIGHT file at the top-level directory of this distribution
6# for details of code ownership.
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program. If not, see <https://www.gnu.org/licenses/>.
21import unittest
23import matplotlib.pyplot as plt
24from astropy.table import Table
26import lsst.utils.tests
27from lsst.analysis.tools.atools import diaSourceTableTractMetrics as diaAtool
30class DiaSourceTableTractTest(lsst.utils.tests.TestCase):
31 """Test to see if DiaSources are counted as expected
32 and a plot is generated without falling over."""
34 def setUp(self):
35 testFile = "tests/data/diaSourceTable_tract_test.ecsv"
36 self.data = Table.read(testFile)
38 def test_metrics(self):
39 """Test that metrics have the expected values from the test data."""
40 NumDiaSources = diaAtool.NumDiaSourcesMetric()
41 NumDiaSources.finalize()
42 goodDiaSourceCount = NumDiaSources(self.data)
43 self.assertEqual(goodDiaSourceCount["numDiaSources"].quantity.value, 2938)
45 NumStreakDiaSources = diaAtool.NumStreakDiaSourcesMetric()
46 NumStreakDiaSources.finalize()
47 streakDiaSourceCount = NumStreakDiaSources(self.data)
48 self.assertEqual(streakDiaSourceCount["numStreakDiaSources"].quantity.value, 8)
50 NumStreakCenterDiaSources = diaAtool.NumStreakCenterDiaSourcesMetric()
51 NumStreakCenterDiaSources.finalize()
52 streakCenterDiaSourceCount = NumStreakCenterDiaSources(self.data)
53 self.assertEqual(streakCenterDiaSourceCount["numStreakCenterDiaSources"].quantity.value, 7)
55 def test_plot(self):
56 """Test that a plot is created from the test data."""
57 plot = diaAtool.PlotStreakDiaSources()
58 plot.finalize()
59 result = plot(self.data)
60 self.assertTrue(isinstance(result["DiaSkyPlot"], plt.Figure))
63if __name__ == "__main__": 63 ↛ 64line 63 didn't jump to line 64 because the condition on line 63 was never true
64 lsst.utils.tests.init()
65 unittest.main()