Coverage for tests / test_diaSourceTableTractMetrics.py: 34%

30 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-15 00:23 +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/>. 

20 

21import unittest 

22 

23import lsst.utils.tests 

24import matplotlib.pyplot as plt 

25from astropy.table import Table 

26from lsst.analysis.tools.atools import diaSourceTableTractMetrics as diaAtool 

27 

28 

29class DiaSourceTableTractTest(lsst.utils.tests.TestCase): 

30 """Test to see if DiaSources are counted as expected 

31 and a plot is generated without falling over.""" 

32 

33 def setUp(self): 

34 testFile = "tests/data/diaSourceTable_tract_test.ecsv" 

35 self.data = Table.read(testFile) 

36 

37 def test_metrics(self): 

38 """Test that metrics have the expected values from the test data.""" 

39 NumDiaSources = diaAtool.NumDiaSourcesMetric() 

40 NumDiaSources.finalize() 

41 goodDiaSourceCount = NumDiaSources(self.data) 

42 self.assertEqual(goodDiaSourceCount["numDiaSources"].quantity.value, 2938) 

43 

44 NumStreakDiaSources = diaAtool.NumStreakDiaSourcesMetric() 

45 NumStreakDiaSources.finalize() 

46 streakDiaSourceCount = NumStreakDiaSources(self.data) 

47 self.assertEqual(streakDiaSourceCount["numStreakDiaSources"].quantity.value, 8) 

48 

49 NumStreakCenterDiaSources = diaAtool.NumStreakCenterDiaSourcesMetric() 

50 NumStreakCenterDiaSources.finalize() 

51 streakCenterDiaSourceCount = NumStreakCenterDiaSources(self.data) 

52 self.assertEqual(streakCenterDiaSourceCount["numStreakCenterDiaSources"].quantity.value, 7) 

53 

54 def test_plot(self): 

55 """Test that a plot is created from the test data.""" 

56 plot = diaAtool.PlotStreakDiaSources() 

57 plot.finalize() 

58 result = plot(self.data) 

59 self.assertTrue(isinstance(result["DiaSkyPlot"], plt.Figure)) 

60 

61 

62if __name__ == "__main__": 62 ↛ 63line 62 didn't jump to line 63 because the condition on line 62 was never true

63 lsst.utils.tests.init() 

64 unittest.main()