Coverage for tests/test_diaSourceTableTractMetrics.py: 32%

35 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-15 02:38 -0700

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 

27from lsst.analysis.tools.contexts import DrpContext 

28 

29 

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.""" 

33 

34 def setUp(self): 

35 testFile = "tests/diaSourceTable_tract_test.ecsv" 

36 self.data = Table.read(testFile) 

37 

38 def test_metrics(self): 

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

40 NumDiaSources = diaAtool.NumDiaSourcesMetric() 

41 NumDiaSources.applyContext(DrpContext) 

42 NumDiaSources.finalize() 

43 goodDiaSourceCount = NumDiaSources(self.data) 

44 self.assertEqual(goodDiaSourceCount["numDiaSources"].quantity.value, 341) 

45 

46 NumStreakDiaSources = diaAtool.NumStreakDiaSourcesMetric() 

47 NumStreakDiaSources.applyContext(DrpContext) 

48 NumStreakDiaSources.finalize() 

49 streakDiaSourceCount = NumStreakDiaSources(self.data) 

50 self.assertEqual(streakDiaSourceCount["numStreakDiaSources"].quantity.value, 3) 

51 

52 NumStreakCenterDiaSources = diaAtool.NumStreakCenterDiaSourcesMetric() 

53 NumStreakCenterDiaSources.applyContext(DrpContext) 

54 NumStreakCenterDiaSources.finalize() 

55 streakCenterDiaSourceCount = NumStreakCenterDiaSources(self.data) 

56 self.assertEqual(streakCenterDiaSourceCount["numStreakCenterDiaSources"].quantity.value, 1) 

57 

58 def test_plot(self): 

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

60 plot = diaAtool.PlotStreakDiaSources() 

61 plot.applyContext(DrpContext) 

62 plot.finalize() 

63 result = plot(self.data) 

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

65 

66 

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

68 lsst.utils.tests.init() 

69 unittest.main()