Coverage for tests/test_jointcal_hsc.py: 25%

114 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-02-05 03:23 -0800

1# This file is part of jointcal. 

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 

23import os 

24 

25import lsst.geom 

26import lsst.pex.config 

27import lsst.utils 

28import lsst.pex.exceptions 

29 

30import jointcalTestBase 

31 

32 

33# for MemoryTestCase 

34def setup_module(module): 

35 lsst.utils.tests.init() 

36 

37 

38class JointcalTestHSC(jointcalTestBase.JointcalTestBase, lsst.utils.tests.TestCase): 

39 

40 @classmethod 

41 def setUpClass(cls): 

42 try: 

43 cls.data_dir = lsst.utils.getPackageDir('testdata_jointcal') 

44 except LookupError: 

45 raise unittest.SkipTest("testdata_jointcal not setup") 

46 try: 

47 lsst.utils.getPackageDir('obs_subaru') 

48 except LookupError: 

49 raise unittest.SkipTest("obs_subaru not setup") 

50 

51 def setUp(self): 

52 input_dir = os.path.join(self.data_dir, 'hsc') 

53 all_visits = [34648, 34690, 34714, 34674, 34670, 36140, 35892, 36192, 36260, 36236] 

54 

55 where = "instrument='HSC' and tract=9697 and skymap='hsc_rings_v1'" 

56 inputCollections = ["refcats/gen2", 

57 "HSC/testdata", 

58 "HSC/calib/unbounded"] 

59 outputDataId = {'instrument': 'HSC', 'tract': 9697, 'skymap': 'hsc_rings_v1'} 

60 

61 self.setUp_base("lsst.obs.subaru.HyperSuprimeCam", "HSC", 

62 input_dir=input_dir, 

63 all_visits=all_visits, 

64 where=where, 

65 inputCollections=inputCollections, 

66 outputDataId=outputDataId) 

67 

68 self.configfiles.append(os.path.join(self.path, 'config/hsc-config.py')) 

69 

70 def test_jointcalTask_2_visits_simple(self): 

71 configOptions = {"astrometryModel": "simple", "photometryModel": "simpleFlux"} 

72 where = f" and visit in ({self.all_visits[0]},{self.all_visits[1]})" 

73 # test colorterm loading in gen3 (see DM-29884) 

74 configFiles = [os.path.join(self.path, 'config/hsc-colorterms-config.py')] 

75 

76 # See Readme for an explanation of these empirical values. 

77 metrics = {'astrometry_collected_refStars': 568, 

78 'photometry_collected_refStars': 6478, 

79 'astrometry_prepared_refStars': 137, 

80 'photometry_prepared_refStars': 1609, 

81 'astrometry_matched_fittedStars': 2070, 

82 'photometry_matched_fittedStars': 2070, 

83 'astrometry_prepared_fittedStars': 989, 

84 'photometry_prepared_fittedStars': 1731, 

85 'astrometry_prepared_ccdImages': 6, 

86 'photometry_prepared_ccdImages': 6, 

87 'astrometry_final_chi2': 835.473, 

88 'astrometry_final_ndof': 1918, 

89 'photometry_final_chi2': 4977.2, 

90 'photometry_final_ndof': 2188 

91 } 

92 outputVisits = {34648: [51, 59, 67], 34690: [48, 56, 64]} 

93 self._runJointcalTest(whereSuffix=where, 

94 configOptions=configOptions, configFiles=configFiles, metrics=metrics, 

95 astrometryOutputs=outputVisits, photometryOutputs=outputVisits) 

96 

97 def test_jointcalTask_ri_visits_2_bands_simple_dm32207(self): 

98 """Test gen3 butler jointcal putting 2 bands in same repo. 

99 Not testing metric values here; the goal of this test is to check that 

100 the metrics Connections are defined correctly so that the QauntumGraph 

101 generation doesn't fail. 

102 """ 

103 configOptions = {"astrometryModel": "simple", "photometryModel": "simpleFlux"} 

104 where = (f" and visit in ({self.all_visits[0]},{self.all_visits[1]}," 

105 f"{self.all_visits[5]},{self.all_visits[6]})") 

106 configFiles = [] 

107 

108 outputVisits = {34648: [51, 59, 67], 34690: [48, 56, 64], 

109 36140: [51, 59, 67], 35892: [23, 31, 39]} 

110 self._runJointcalTest(whereSuffix=where, 

111 configOptions=configOptions, configFiles=configFiles, metrics=None, nJobs=2, 

112 astrometryOutputs=outputVisits, photometryOutputs=outputVisits) 

113 

114 def test_jointcalTask_10_visits_simple_astrometry_no_photometry(self): 

115 """Test all 10 visits with different filters. 

116 Testing photometry doesn't make sense for this currently. 

117 """ 

118 configOptions = {"astrometryModel": "simple", "doPhotometry": False} 

119 where = f" and visit in {tuple(self.all_visits)}" 

120 

121 # See Readme for an explanation of these empirical values. 

122 # Gen3 jointcal splits the input by filter, so we get 15 ccdImages for 

123 # each of the r/i datasets (5 visits each). The metrics test only 

124 # checks the first Job (after sorting on the job keys), which is HSC-I. 

125 metrics = {'astrometry_collected_refStars': 897, 

126 'astrometry_prepared_refStars': 192, 

127 'astrometry_matched_fittedStars': 4238, 

128 'astrometry_prepared_fittedStars': 2194, 

129 'astrometry_prepared_ccdImages': 15, 

130 'astrometry_final_chi2': 3557.92, 

131 'astrometry_final_ndof': 7610, 

132 } 

133 outputVisits = {34648: [51, 59, 67], 34690: [48, 56, 64], 

134 34714: [13, 18, 19], 34674: [15, 21, 28], 

135 34670: [92, 93, 97], 36140: [51, 59, 67], 

136 35892: [23, 31, 39], 36192: [8, 14, 20], 

137 36260: [2, 7, 13], 36236: [87, 93, 98]} 

138 self._runJointcalTest(whereSuffix=where, 

139 configOptions=configOptions, metrics=metrics, nJobs=2, 

140 astrometryOutputs=outputVisits) 

141 

142 def setup_jointcalTask_2_visits_simple_photometry(self): 

143 """Set default values for the simple_photometry tests, and make it so 

144 the differences between each test and the defaults are more obvious. 

145 """ 

146 configOptions = {"photometryModel": "simpleFlux", "doAstrometry": False} 

147 # See Readme for an explanation of these empirical values. 

148 metrics = {'photometry_collected_refStars': 6485, 

149 'photometry_prepared_refStars': 1609, 

150 'photometry_matched_fittedStars': 2070, 

151 'photometry_prepared_fittedStars': 1731, 

152 'photometry_prepared_ccdImages': 6, 

153 'photometry_final_chi2': 4997.62, 

154 'photometry_final_ndof': 2188 

155 } 

156 where = f" and visit in ({self.all_visits[0]},{self.all_visits[1]})" 

157 outputVisits = {34648: [51, 59, 67], 34690: [48, 56, 64]} 

158 return configOptions, metrics, where, outputVisits 

159 

160 def test_jointcalTask_2_visits_simpleFlux(self): 

161 configOptions, metrics, where, outputVisits = self.setup_jointcalTask_2_visits_simple_photometry() 

162 self._runJointcalTest(whereSuffix=where, 

163 configOptions=configOptions, metrics=metrics, 

164 photometryOutputs=outputVisits) 

165 

166 def test_jointcalTask_2_visits_simpleMagnitude(self): 

167 configOptions, metrics, where, outputVisits = self.setup_jointcalTask_2_visits_simple_photometry() 

168 configOptions['photometryModel'] = "simpleMagnitude" 

169 metrics['photometry_final_chi2'] = 5236.91 

170 metrics['photometry_final_ndof'] = 2200 

171 self._runJointcalTest(whereSuffix=where, 

172 configOptions=configOptions, metrics=metrics, 

173 photometryOutputs=outputVisits) 

174 

175 def test_jointcalTask_2_visits_simpleMagnitude_colorterms(self): 

176 """Test that colorterms are applied and change the fit.""" 

177 configOptions, metrics, where, outputVisits = self.setup_jointcalTask_2_visits_simple_photometry() 

178 configOptions['photometryModel'] = "simpleMagnitude" 

179 test_config = os.path.join(self.path, 'config/hsc-colorterms-config.py') 

180 

181 # slightly fewer refstars because they each need the specific filters required by the colorterms 

182 metrics['photometry_collected_refStars'] = 6478 

183 # Final chi2 should be different, but I don't have an a-priori reason 

184 # to expect it to be larger or smaller. 

185 metrics['photometry_final_chi2'] = 5181.25 

186 metrics['photometry_final_ndof'] = 2197 

187 self._runJointcalTest(whereSuffix=where, 

188 configOptions=configOptions, configFiles=[test_config], metrics=metrics, 

189 photometryOutputs=outputVisits) 

190 

191 def test_jointcalTask_2_visits_simpleMagnitude_colorterms_no_library(self): 

192 """Fail Config validation if the color term library isn't defined.""" 

193 configOptions, metrics, where, outputVisits = self.setup_jointcalTask_2_visits_simple_photometry() 

194 test_config = os.path.join(self.path, 'config/hsc-colorterms_no_library-config.py') 

195 self.configfiles.append(test_config) 

196 

197 with self.assertRaises(lsst.pex.config.FieldValidationError): 

198 self._runJointcalTest(whereSuffix=where, 

199 configOptions=configOptions, configFiles=[test_config]) 

200 

201 def setup_jointcalTask_2_visits_simple_astrometry(self): 

202 """Set default values for the 2 visit simple_astrometry tests, so that 

203 the differences between each test and the defaults are more obvious. 

204 """ 

205 configOptions = {"astrometryModel": "simple", "doPhotometry": False} 

206 # See Readme for an explanation of these empirical values. 

207 metrics = {'astrometry_collected_refStars': 568, 

208 'astrometry_prepared_refStars': 137, 

209 'astrometry_matched_fittedStars': 2070, 

210 'astrometry_prepared_fittedStars': 989, 

211 'astrometry_prepared_ccdImages': 6, 

212 'astrometry_final_chi2': 835.473, 

213 'astrometry_final_ndof': 1918, 

214 } 

215 where = f" and visit in ({self.all_visits[0]},{self.all_visits[1]})" 

216 outputVisits = {34648: [51, 59, 67], 34690: [48, 56, 64]} 

217 return configOptions, metrics, where, outputVisits 

218 

219 def test_JointcalTask_2_visits_simple_astrometry_no_photometry(self): 

220 """Test turning off fitting photometry.""" 

221 configOptions, metrics, where, outputVisits = self.setup_jointcalTask_2_visits_simple_astrometry() 

222 self._runJointcalTest(whereSuffix=where, 

223 configOptions=configOptions, metrics=metrics, 

224 astrometryOutputs=outputVisits) 

225 

226 def test_jointcalTask_2_visits_simple_astrometry_no_photometry_match_cut_10(self): 

227 """A larger matching radius will result in more associated fittedStars, 

228 and a somewhat worse final fit because stars that should not have been 

229 associated, were. 

230 """ 

231 configOptions, metrics, where, outputVisits = self.setup_jointcalTask_2_visits_simple_astrometry() 

232 # TODO: once DM-6885 is fixed, we need to put `*lsst.geom.arcseconds` 

233 configOptions['matchCut'] = 10.0 

234 

235 metrics['astrometry_prepared_refStars'] = 211 

236 metrics['astrometry_prepared_fittedStars'] = 1042 

237 metrics['astrometry_final_chi2'] = 819.608 

238 metrics['astrometry_final_ndof'] = 1872 

239 self._runJointcalTest(whereSuffix=where, 

240 configOptions=configOptions, metrics=metrics, 

241 astrometryOutputs=outputVisits) 

242 

243 def setup_jointcalTask_3_visits_simple_astrometry(self): 

244 """Set default values for the 3 visit simple_astrometry tests, so that 

245 the differences between each test and the defaults are more obvious. 

246 """ 

247 configOptions = {"astrometryModel": "simple", "doPhotometry": False} 

248 # See Readme for an explanation of these empirical values. 

249 metrics = {'astrometry_collected_refStars': 1038, 

250 'astrometry_prepared_refStars': 209, 

251 'astrometry_matched_fittedStars': 3199, 

252 'astrometry_prepared_fittedStars': 1282, 

253 'astrometry_prepared_ccdImages': 9, 

254 'astrometry_final_chi2': 1221.63, 

255 'astrometry_final_ndof': 2892, 

256 } 

257 where = f" and visit in {tuple(self.all_visits[:3])}" 

258 outputVisits = {34648: [51, 59, 67], 34690: [48, 56, 64], 34714: [13, 18, 19]} 

259 return configOptions, metrics, where, outputVisits 

260 

261 def test_jointcalTask_3_visits_simple_astrometry_no_photometry(self): 

262 """3 visit, default config to compare with min_measurements_3 test.""" 

263 configOptions, metrics, where, outputVisits = self.setup_jointcalTask_3_visits_simple_astrometry() 

264 self._runJointcalTest(whereSuffix=where, 

265 configOptions=configOptions, metrics=metrics, 

266 astrometryOutputs=outputVisits) 

267 

268 def test_jointcalTask_3_visits_simple_astrometry_no_photometry_min_measurements_3(self): 

269 """Raising min_measurements to 3 will reduce the number of selected 

270 fitted stars (and thus the chisq and Ndof), but should not change the 

271 other values.""" 

272 configOptions, metrics, where, outputVisits = self.setup_jointcalTask_3_visits_simple_astrometry() 

273 configOptions['minMeasurements'] = 3 

274 metrics['astrometry_prepared_fittedStars'] = 432 

275 metrics['astrometry_final_chi2'] = 567.433 

276 metrics['astrometry_final_ndof'] = 1286 

277 self._runJointcalTest(whereSuffix=where, 

278 configOptions=configOptions, metrics=metrics, 

279 astrometryOutputs=outputVisits) 

280 

281 

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

283 pass 

284 

285 

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

287 lsst.utils.tests.init() 

288 unittest.main()