Coverage for tests/test_tasks.py: 27%

71 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-02 00:13 -0700

1# This file is part of faro. 

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

21 

22import os 

23import unittest 

24import astropy.units as u 

25 

26from lsst.afw.table import SimpleCatalog 

27 

28from lsst.faro.base import CatalogMeasurementBaseConfig, CatalogMeasurementBaseTask, NumSourcesMergeTask 

29from lsst.faro.measurement import (VisitTableMeasurementConfig, VisitTableMeasurementTask, 

30 DetectorTableMeasurementConfig, DetectorTableMeasurementTask, 

31 VisitMeasurementConfig, VisitMeasurementTask, 

32 DetectorMeasurementConfig, DetectorMeasurementTask, 

33 TractMeasurementConfig, TractMeasurementTask, 

34 TractTableValueMeasurementConfig, TractTableValueMeasurementTask, 

35 ) 

36 

37TESTDIR = os.path.abspath(os.path.dirname(__file__)) 

38DATADIR = os.path.join(TESTDIR, 'data') 

39 

40 

41class TaskTest(unittest.TestCase): 

42 

43 def load_data(self, key): 

44 cat_file = self.file_map[key] 

45 catalog = SimpleCatalog.readFits(os.path.join(DATADIR, cat_file)) 

46 return catalog 

47 

48 def setUp(self): 

49 """This is called immediately before calling each test method.""" 

50 self.file_map = {'CatalogMeasurementBaseTask': 

51 'src_HSC_i_HSC-I_903986_0_31_HSC_runs_ci_hsc_20210407T021858Z.fits'} 

52 

53 def testCatalogMeasurementBaseTask(self): 

54 """Test run method of CatalogMeasurementBaseTask.""" 

55 catalog = self.load_data('CatalogMeasurementBaseTask') 

56 config = CatalogMeasurementBaseConfig() 

57 t = CatalogMeasurementBaseTask(config) 

58 outputs = t.run(catalog=catalog) 

59 expected = 771 * u.count 

60 self.assertEqual(outputs.measurement.quantity, expected) 

61 

62 def testVisitTableMeasurementTask(self): 

63 """Test run method of VisitTableMeasurementTask.""" 

64 catalog = self.load_data('CatalogMeasurementBaseTask') 

65 config = VisitTableMeasurementConfig() 

66 t = VisitTableMeasurementTask(config) 

67 outputs = t.run(catalog=catalog) 

68 expected = 771 * u.count 

69 self.assertEqual(outputs.measurement.quantity, expected) 

70 

71 def testDetectorTableMeasurementTask(self): 

72 """Test run method of VisitTableMeasurementTask.""" 

73 catalog = self.load_data('CatalogMeasurementBaseTask') 

74 config = DetectorTableMeasurementConfig() 

75 t = DetectorTableMeasurementTask(config) 

76 outputs = t.run(catalog=catalog) 

77 expected = 771 * u.count 

78 self.assertEqual(outputs.measurement.quantity, expected) 

79 

80 def testTractMeasurementTask(self): 

81 """Test run method of TractMeasurementTask.""" 

82 catalog = self.load_data('CatalogMeasurementBaseTask') 

83 config = TractMeasurementConfig() 

84 config.measure.retarget(NumSourcesMergeTask) 

85 t = TractMeasurementTask(config) 

86 outputs = t.run( 

87 catalogs=[catalog, ], 

88 photoCalibs=[None, ], 

89 astromCalibs=[None, ], 

90 dataIds=[{'band': 'r'}, ], 

91 ) 

92 expected = 771 * u.count 

93 self.assertEqual(outputs.measurement.quantity, expected) 

94 

95 def testTractTableValueMeasurementTask(self): 

96 table = self.load_data('CatalogMeasurementBaseTask').asAstropy().to_pandas() 

97 config = TractTableValueMeasurementConfig( 

98 band_order=[''], 

99 format_column='{band}{column}', 

100 prefixes_column=[''], 

101 row=0, 

102 ) 

103 config.action.column = 'parent' 

104 t = TractTableValueMeasurementTask() 

105 t.config = config 

106 outputs = t.run(table=table, bands=[''], name_metric='parent') 

107 expected = 0 * u.Unit('') 

108 self.assertEqual(outputs.measurement[0].quantity, expected) 

109 

110 def testVisitMeasurementTask(self): 

111 """Test run method of VisitMeasurementTask.""" 

112 catalog = self.load_data('CatalogMeasurementBaseTask') 

113 config = VisitMeasurementConfig() 

114 config.measure.retarget(NumSourcesMergeTask) 

115 t = VisitMeasurementTask(config) 

116 outputs = t.run( 

117 catalogs=[catalog, ], 

118 photoCalibs=[None, ], 

119 astromCalibs=[None, ], 

120 dataIds=[{'band': 'r'}, ], 

121 ) 

122 print(outputs) 

123 expected = 771 * u.count 

124 self.assertEqual(outputs.measurement.quantity, expected) 

125 

126 def testDetectorMeasurementTask(self): 

127 """Test run method of DetectorMeasurementTask.""" 

128 catalog = self.load_data('CatalogMeasurementBaseTask') 

129 config = DetectorMeasurementConfig() 

130 t = DetectorMeasurementTask(config) 

131 outputs = t.run(catalog=catalog) 

132 expected = 771 * u.count 

133 self.assertEqual(outputs.measurement.quantity, expected) 

134 

135 

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

137 unittest.main()