Coverage for tests / test_fit_coadd_multiband.py: 35%

50 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-26 09:21 +0000

1# This file is part of pipe_tasks. 

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 unittest 

23 

24import lsst.utils.tests 

25from lsst.daf.butler import DataCoordinate, DatasetRef, DatasetType, DimensionUniverse 

26from lsst.pipe.base import NoWorkFound 

27from lsst.pipe.tasks.fit_coadd_multiband import ( 

28 CoaddMultibandFitConfig, CoaddMultibandFitConnections, 

29 CoaddMultibandFitSubConfig, CoaddMultibandFitSubTask, 

30) 

31 

32 

33class CoaddMultibandFitDummySubTask(CoaddMultibandFitSubTask): 

34 ConfigClass = CoaddMultibandFitSubConfig 

35 _DefaultName = "test" 

36 

37 def run(self, catexps, cat_ref): 

38 return None 

39 

40 

41class CoaddMultibandFitTestCase(lsst.utils.tests.TestCase): 

42 """Tests adjustQuantum for now. Could run the task with mock data.""" 

43 def setUp(self): 

44 self.config = CoaddMultibandFitConfig() 

45 self.config.fit_coadd_multiband.retarget(CoaddMultibandFitDummySubTask) 

46 self.config.fit_coadd_multiband.bands_fit = ("g", "r") 

47 self.connections = CoaddMultibandFitConnections(config=self.config) 

48 self.config.freeze() 

49 

50 self.universe = DimensionUniverse() 

51 self.datasetType_coadd, self.datasetType_cat_meas = ( 

52 DatasetType( 

53 name=connection.name, 

54 dimensions=connection.dimensions, 

55 storageClass=connection.storageClass, 

56 universe=self.universe, 

57 ) 

58 for connection in (self.connections.coadds, self.connections.cats_meas) 

59 ) 

60 self.skymap = "test" 

61 self.tract = 0 

62 self.patch = 0 

63 self.run = "test" 

64 kwargs_patch = {"skymap": self.skymap, "tract": self.tract, "patch": self.patch} 

65 

66 self.inputs = { 

67 "coadds": ( 

68 self.connections.coadds, 

69 tuple( 

70 DatasetRef( 

71 self.datasetType_coadd, 

72 DataCoordinate.standardize(universe=self.universe, band=band, **kwargs_patch), 

73 self.run, 

74 ) 

75 for band in ("g", "r") 

76 ), 

77 ), 

78 "cats_meas": ( 

79 self.connections.cats_meas, 

80 tuple( 

81 DatasetRef( 

82 self.datasetType_cat_meas, 

83 DataCoordinate.standardize(universe=self.universe, band=band, **kwargs_patch), 

84 self.run, 

85 ) 

86 for band in ("r",) 

87 ), 

88 ) 

89 } 

90 self.universe = DimensionUniverse() 

91 self.dataId = DataCoordinate.standardize(universe=self.universe, **kwargs_patch) 

92 

93 def testAdjustQuantum(self): 

94 inputs, outputs = self.connections.adjustQuantum( 

95 self.inputs, outputs={}, label="test", data_id=self.dataId, 

96 ) 

97 self.assertEqual(len(outputs), 0) 

98 

99 for name, (connection, refs) in inputs.items(): 

100 self.assertEqual(len(refs), 1) 

101 self.assertEqual(refs[0].dataId["band"], "r") 

102 

103 def testAdjustQuantumMissingAll(self): 

104 inputs = { 

105 "coadds": self.inputs["coadds"], 

106 "cats_meas": (self.connections.cats_meas, tuple()), 

107 } 

108 with self.assertRaises(NoWorkFound): 

109 self.connections.adjustQuantum(inputs, outputs={}, label="test", data_id=self.dataId) 

110 

111 def testAdjustQuantumStrict(self): 

112 config = self.config.copy() 

113 config.allow_missing_bands = False 

114 connections = CoaddMultibandFitConnections(config=config) 

115 

116 with self.assertRaises(NoWorkFound): 

117 connections.adjustQuantum(self.inputs, outputs={}, label="test", data_id=self.dataId) 

118 

119 

120class MemoryTester(lsst.utils.tests.MemoryTestCase): 

121 pass 

122 

123 

124def setup_module(module): 

125 lsst.utils.tests.init() 

126 

127 

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

129 lsst.utils.tests.init() 

130 unittest.main()