Coverage for tests/test_jointcal_hsc.py: 28%

115 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-27 12:17 +0000

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 self.configfiles.append(os.path.join(self.path, 'config/config-gen3-hsc.py')) 

70 

71 def test_jointcalTask_2_visits_simple(self): 

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

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

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

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

76 

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

78 metrics = {'astrometry_collected_refStars': 568, 

79 'photometry_collected_refStars': 6478, 

80 'astrometry_prepared_refStars': 137, 

81 'photometry_prepared_refStars': 1609, 

82 'astrometry_matched_fittedStars': 2070, 

83 'photometry_matched_fittedStars': 2070, 

84 'astrometry_prepared_fittedStars': 989, 

85 'photometry_prepared_fittedStars': 1731, 

86 'astrometry_prepared_ccdImages': 6, 

87 'photometry_prepared_ccdImages': 6, 

88 'astrometry_final_chi2': 835.473, 

89 'astrometry_final_ndof': 1918, 

90 'photometry_final_chi2': 4977.2, 

91 'photometry_final_ndof': 2188 

92 } 

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

94 self._runJointcalTest(whereSuffix=where, 

95 configOptions=configOptions, configFiles=configFiles, metrics=metrics, 

96 astrometryOutputs=outputVisits, photometryOutputs=outputVisits) 

97 

98 def test_jointcalTask_ri_visits_2_bands_simple_dm32207(self): 

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

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

101 the metrics Connections are defined correctly so that the QauntumGraph 

102 generation doesn't fail. 

103 """ 

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

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

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

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

108 

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

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

111 self._runJointcalTest(whereSuffix=where, 

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

113 astrometryOutputs=outputVisits, photometryOutputs=outputVisits) 

114 

115 def test_jointcalTask_10_visits_simple_astrometry_no_photometry(self): 

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

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

118 """ 

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

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

121 

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

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

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

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

126 metrics = {'astrometry_collected_refStars': 897, 

127 'astrometry_prepared_refStars': 192, 

128 'astrometry_matched_fittedStars': 4238, 

129 'astrometry_prepared_fittedStars': 2194, 

130 'astrometry_prepared_ccdImages': 15, 

131 'astrometry_final_chi2': 3557.92, 

132 'astrometry_final_ndof': 7610, 

133 } 

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

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

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

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

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

139 self._runJointcalTest(whereSuffix=where, 

140 configOptions=configOptions, metrics=metrics, nJobs=2, 

141 astrometryOutputs=outputVisits) 

142 

143 def setup_jointcalTask_2_visits_simple_photometry(self): 

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

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

146 """ 

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

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

149 metrics = {'photometry_collected_refStars': 6485, 

150 'photometry_prepared_refStars': 1609, 

151 'photometry_matched_fittedStars': 2070, 

152 'photometry_prepared_fittedStars': 1731, 

153 'photometry_prepared_ccdImages': 6, 

154 'photometry_final_chi2': 4997.62, 

155 'photometry_final_ndof': 2188 

156 } 

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

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

159 return configOptions, metrics, where, outputVisits 

160 

161 def test_jointcalTask_2_visits_simpleFlux(self): 

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

163 self._runJointcalTest(whereSuffix=where, 

164 configOptions=configOptions, metrics=metrics, 

165 photometryOutputs=outputVisits) 

166 

167 def test_jointcalTask_2_visits_simpleMagnitude(self): 

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

169 configOptions['photometryModel'] = "simpleMagnitude" 

170 metrics['photometry_final_chi2'] = 5236.91 

171 metrics['photometry_final_ndof'] = 2200 

172 self._runJointcalTest(whereSuffix=where, 

173 configOptions=configOptions, metrics=metrics, 

174 photometryOutputs=outputVisits) 

175 

176 def test_jointcalTask_2_visits_simpleMagnitude_colorterms(self): 

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

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

179 configOptions['photometryModel'] = "simpleMagnitude" 

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

181 

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

183 metrics['photometry_collected_refStars'] = 6478 

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

185 # to expect it to be larger or smaller. 

186 metrics['photometry_final_chi2'] = 5181.25 

187 metrics['photometry_final_ndof'] = 2197 

188 self._runJointcalTest(whereSuffix=where, 

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

190 photometryOutputs=outputVisits) 

191 

192 def test_jointcalTask_2_visits_simpleMagnitude_colorterms_no_library(self): 

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

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

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

196 self.configfiles.append(test_config) 

197 

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

199 self._runJointcalTest(whereSuffix=where, 

200 configOptions=configOptions, configFiles=[test_config]) 

201 

202 def setup_jointcalTask_2_visits_simple_astrometry(self): 

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

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

205 """ 

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

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

208 metrics = {'astrometry_collected_refStars': 568, 

209 'astrometry_prepared_refStars': 137, 

210 'astrometry_matched_fittedStars': 2070, 

211 'astrometry_prepared_fittedStars': 989, 

212 'astrometry_prepared_ccdImages': 6, 

213 'astrometry_final_chi2': 835.473, 

214 'astrometry_final_ndof': 1918, 

215 } 

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

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

218 return configOptions, metrics, where, outputVisits 

219 

220 def test_JointcalTask_2_visits_simple_astrometry_no_photometry(self): 

221 """Test turning off fitting photometry.""" 

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

223 self._runJointcalTest(whereSuffix=where, 

224 configOptions=configOptions, metrics=metrics, 

225 astrometryOutputs=outputVisits) 

226 

227 def test_jointcalTask_2_visits_simple_astrometry_no_photometry_match_cut_10(self): 

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

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

230 associated, were. 

231 """ 

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

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

234 configOptions['matchCut'] = 10.0 

235 

236 metrics['astrometry_prepared_refStars'] = 211 

237 metrics['astrometry_prepared_fittedStars'] = 1042 

238 metrics['astrometry_final_chi2'] = 819.608 

239 metrics['astrometry_final_ndof'] = 1872 

240 self._runJointcalTest(whereSuffix=where, 

241 configOptions=configOptions, metrics=metrics, 

242 astrometryOutputs=outputVisits) 

243 

244 def setup_jointcalTask_3_visits_simple_astrometry(self): 

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

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

247 """ 

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

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

250 metrics = {'astrometry_collected_refStars': 1038, 

251 'astrometry_prepared_refStars': 209, 

252 'astrometry_matched_fittedStars': 3199, 

253 'astrometry_prepared_fittedStars': 1282, 

254 'astrometry_prepared_ccdImages': 9, 

255 'astrometry_final_chi2': 1221.63, 

256 'astrometry_final_ndof': 2892, 

257 } 

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

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

260 return configOptions, metrics, where, outputVisits 

261 

262 def test_jointcalTask_3_visits_simple_astrometry_no_photometry(self): 

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

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

265 self._runJointcalTest(whereSuffix=where, 

266 configOptions=configOptions, metrics=metrics, 

267 astrometryOutputs=outputVisits) 

268 

269 def test_jointcalTask_3_visits_simple_astrometry_no_photometry_min_measurements_3(self): 

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

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

272 other values.""" 

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

274 configOptions['minMeasurements'] = 3 

275 metrics['astrometry_prepared_fittedStars'] = 432 

276 metrics['astrometry_final_chi2'] = 567.433 

277 metrics['astrometry_final_ndof'] = 1286 

278 self._runJointcalTest(whereSuffix=where, 

279 configOptions=configOptions, metrics=metrics, 

280 astrometryOutputs=outputVisits) 

281 

282 

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

284 pass 

285 

286 

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

288 lsst.utils.tests.init() 

289 unittest.main()