Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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 

25from astropy import units as u 

26import numpy as np 

27 

28from lsst.daf.butler import Butler 

29import lsst.geom 

30import lsst.pex.config 

31import lsst.utils 

32import lsst.pex.exceptions 

33 

34import jointcalTestBase 

35 

36 

37# for MemoryTestCase 

38def setup_module(module): 

39 lsst.utils.tests.init() 

40 

41 

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

43 

44 @classmethod 

45 def setUpClass(cls): 

46 try: 

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

48 except LookupError: 

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

50 try: 

51 lsst.utils.getPackageDir('obs_subaru') 

52 except LookupError: 

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

54 

55 def setUp(self): 

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

57 self.dist_rms_absolute = 21e-3*u.arcsecond 

58 self.dist_rms_relative = 7e-3*u.arcsecond 

59 

60 do_plot = False 

61 

62 # center of the hsc validation_data catalog 

63 center = lsst.geom.SpherePoint(337.710899, +0.807006, lsst.geom.degrees) 

64 radius = 0.5*lsst.geom.degrees 

65 

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

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

68 

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

70 

71 self.setUp_base(center, radius, 

72 input_dir=input_dir, 

73 all_visits=all_visits, 

74 do_plot=do_plot, 

75 where=where) 

76 

77 test_config = os.path.join(lsst.utils.getPackageDir('jointcal'), 'tests/config/hsc-config.py') 

78 self.configfiles.append(test_config) 

79 

80 def test_jointcalTask_2_visits_simple(self): 

81 self.config = lsst.jointcal.jointcal.JointcalConfig() 

82 self.config.astrometryModel = "simple" 

83 self.config.photometryModel = "simpleFlux" 

84 

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

86 pa1 = 0.016 

87 metrics = {'astrometry_collected_refStars': 568, 

88 'photometry_collected_refStars': 6485, 

89 'astrometry_prepared_refStars': 137, 

90 'photometry_prepared_refStars': 1609, 

91 'astrometry_matched_fittedStars': 2070, 

92 'photometry_matched_fittedStars': 2070, 

93 'astrometry_prepared_fittedStars': 989, 

94 'photometry_prepared_fittedStars': 1731, 

95 'astrometry_prepared_ccdImages': 6, 

96 'photometry_prepared_ccdImages': 6, 

97 'astrometry_final_chi2': 835.473, 

98 'astrometry_final_ndof': 1918, 

99 'photometry_final_chi2': 4997.62, 

100 'photometry_final_ndof': 2188 

101 } 

102 self._testJointcalTask(2, self.dist_rms_relative, self.dist_rms_absolute, pa1, metrics=metrics) 

103 

104 def test_jointcalTask_2_visits_simple_gen3(self): 

105 """Test gen3 butler jointcal.""" 

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

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

108 

109 metrics = {'astrometry_collected_refStars': 568, 

110 'photometry_collected_refStars': 6485, 

111 'astrometry_prepared_refStars': 137, 

112 'photometry_prepared_refStars': 1609, 

113 'astrometry_matched_fittedStars': 2070, 

114 'photometry_matched_fittedStars': 2070, 

115 'astrometry_prepared_fittedStars': 989, 

116 'photometry_prepared_fittedStars': 1731, 

117 'astrometry_prepared_ccdImages': 6, 

118 'photometry_prepared_ccdImages': 6, 

119 'astrometry_final_chi2': 835.473, 

120 'astrometry_final_ndof': 1918, 

121 'photometry_final_chi2': 4997.62, 

122 'photometry_final_ndof': 2188 

123 } 

124 self._runGen3Jointcal("lsst.obs.subaru.HyperSuprimeCam", "HSC", whereSuffix=where, 

125 configOptions=configOptions, metrics=metrics) 

126 # TODO DM-28863: this does not currently test anything other than the code 

127 # running without raising and that it writes non-empty output. 

128 butler = Butler(self.repo, collections=['HSC/testdata/jointcal']) 

129 

130 def check_output(visit, detectors): 

131 """Check that there is something for each detector, and only 

132 entries for the correct detectors.""" 

133 dataId = {'visit': visit, 'instrument': 'HSC', 'tract': 9697} 

134 

135 catalog = butler.get('jointcalPhotoCalibCatalog', dataId) 

136 for record in catalog: 

137 self.assertIsInstance(record.getPhotoCalib(), lsst.afw.image.PhotoCalib, 

138 msg=f"visit {visit}: {record}") 

139 np.testing.assert_array_equal(catalog['id'], detectors) 

140 

141 catalog = butler.get('jointcalSkyWcsCatalog', dataId) 

142 for record in catalog: 

143 self.assertIsInstance(record.getWcs(), lsst.afw.geom.SkyWcs, 

144 msg=f"visit {visit}: {record}") 

145 np.testing.assert_array_equal(catalog['id'], detectors) 

146 

147 check_output(34648, [51, 59, 67]) 

148 check_output(34690, [48, 56, 64]) 

149 

150 def test_jointcalTask_2_visits_simple_astrometry_no_photometry_gen3(self): 

151 """Test gen3 butler jointcal, no photometry.""" 

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

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

154 

155 metrics = {'astrometry_collected_refStars': 568, 

156 'astrometry_prepared_refStars': 137, 

157 'astrometry_matched_fittedStars': 2070, 

158 'astrometry_prepared_fittedStars': 989, 

159 'astrometry_prepared_ccdImages': 6, 

160 'astrometry_final_chi2': 835.473, 

161 'astrometry_final_ndof': 1918, 

162 } 

163 self._runGen3Jointcal("lsst.obs.subaru.HyperSuprimeCam", "HSC", whereSuffix=where, 

164 configOptions=configOptions, metrics=metrics) 

165 # TODO DM-28863: this does not currently test anything other than the code 

166 # running without raising and that it writes non-empty output. 

167 butler = Butler(self.repo, collections=['HSC/testdata/jointcal']) 

168 

169 def check_output(visit, detectors): 

170 """Check that there is something for each detector, and only 

171 entries for the correct detectors.""" 

172 dataId = {'visit': visit, 'instrument': 'HSC', 'tract': 9697} 

173 

174 catalog = butler.get('jointcalSkyWcsCatalog', dataId) 

175 for record in catalog: 

176 self.assertIsInstance(record.getWcs(), lsst.afw.geom.SkyWcs, 

177 msg=f"visit {visit}: {record}") 

178 np.testing.assert_array_equal(catalog['id'], detectors) 

179 

180 check_output(34648, [51, 59, 67]) 

181 check_output(34690, [48, 56, 64]) 

182 

183 def test_jointcalTask_2_visits_simple_photometry_no_astrometry_gen3(self): 

184 """Test gen3 butler jointcal, no astrometry.""" 

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

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

187 

188 metrics = {'photometry_collected_refStars': 6485, 

189 'photometry_prepared_refStars': 1609, 

190 'photometry_matched_fittedStars': 2070, 

191 'photometry_prepared_fittedStars': 1731, 

192 'photometry_prepared_ccdImages': 6, 

193 'photometry_final_chi2': 4997.62, 

194 'photometry_final_ndof': 2188 

195 } 

196 self._runGen3Jointcal("lsst.obs.subaru.HyperSuprimeCam", "HSC", whereSuffix=where, 

197 configOptions=configOptions, metrics=metrics) 

198 # TODO DM-28863: this does not currently test anything other than the code 

199 # running without raising and that it writes non-empty output. 

200 butler = Butler(self.repo, collections=['HSC/testdata/jointcal']) 

201 

202 def check_output(visit, detectors): 

203 """Check that there is something for each detector, and only 

204 entries for the correct detectors.""" 

205 dataId = {'visit': visit, 'instrument': 'HSC', 'tract': 9697} 

206 

207 catalog = butler.get('jointcalPhotoCalibCatalog', dataId) 

208 for record in catalog: 

209 self.assertIsInstance(record.getPhotoCalib(), lsst.afw.image.PhotoCalib, 

210 msg=f"visit {visit}: {record}") 

211 np.testing.assert_array_equal(catalog['id'], detectors) 

212 

213 check_output(34648, [51, 59, 67]) 

214 check_output(34690, [48, 56, 64]) 

215 

216 def test_jointcalTask_10_visits_simple_astrometry_no_photometry(self): 

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

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

219 """ 

220 

221 self.config = lsst.jointcal.jointcal.JointcalConfig() 

222 self.config.astrometryModel = "simple" 

223 self.config.doPhotometry = False 

224 self.jointcalStatistics.do_photometry = False 

225 

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

227 dist_rms_absolute = 23e-3*u.arcsecond 

228 dist_rms_relative = 13e-3*u.arcsecond 

229 pa1 = None 

230 metrics = {'astrometry_collected_refStars': 1316, 

231 'astrometry_prepared_refStars': 318, 

232 'astrometry_matched_fittedStars': 5860, 

233 'astrometry_prepared_fittedStars': 3568, 

234 'astrometry_prepared_ccdImages': 30, 

235 'astrometry_final_chi2': 10225.31, 

236 'astrometry_final_ndof': 18576, 

237 } 

238 self._testJointcalTask(10, dist_rms_relative, dist_rms_absolute, pa1, metrics=metrics) 

239 

240 def setup_jointcalTask_2_visits_simplePhotometry(self): 

241 """Set default values for the simplePhotometry tests, and make it so 

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

243 """ 

244 self.config = lsst.jointcal.jointcal.JointcalConfig() 

245 self.config.photometryModel = "simpleFlux" 

246 self.config.doAstrometry = False 

247 self.jointcalStatistics.do_astrometry = False 

248 

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

250 pa1 = 0.016 

251 metrics = {'photometry_collected_refStars': 6485, 

252 'photometry_prepared_refStars': 1609, 

253 'photometry_matched_fittedStars': 2070, 

254 'photometry_prepared_fittedStars': 1731, 

255 'photometry_prepared_ccdImages': 6, 

256 'photometry_final_chi2': 4997.62, 

257 'photometry_final_ndof': 2188 

258 } 

259 return pa1, metrics 

260 

261 def test_jointcalTask_2_visits_simpleFlux(self): 

262 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

263 self._testJointcalTask(2, None, None, pa1, metrics=metrics) 

264 

265 def test_jointcalTask_2_visits_simpleMagnitude(self): 

266 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

267 self.config.photometryModel = "simpleMagnitude" 

268 metrics['photometry_final_chi2'] = 5236.91 

269 metrics['photometry_final_ndof'] = 2200 

270 

271 self._testJointcalTask(2, None, None, pa1, metrics=metrics) 

272 

273 def test_jointcalTask_2_visits_simpleMagnitude_colorterms(self): 

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

275 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

276 self.config.photometryModel = "simpleMagnitude" 

277 test_config = os.path.join(lsst.utils.getPackageDir('jointcal'), 

278 'tests/config/hsc-colorterms-config.py') 

279 self.configfiles.append(test_config) 

280 

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

282 metrics['photometry_collected_refStars'] = 6478 

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

284 # to expect it to be larger or smaller. 

285 metrics['photometry_final_chi2'] = 5181.25 

286 metrics['photometry_final_ndof'] = 2197 

287 

288 self._testJointcalTask(2, None, None, pa1, metrics=metrics) 

289 

290 def test_jointcalTask_2_visits_simpleMagnitude_colorterms_no_library(self): 

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

292 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

293 test_config = os.path.join(lsst.utils.getPackageDir('jointcal'), 

294 'tests/config/hsc-colorterms_no_library-config.py') 

295 self.configfiles.append(test_config) 

296 

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

298 self._testJointcalTask(2, None, None, pa1) 

299 

300 def test_JointcalTask_2_visits_simple_astrometry_no_photometry(self): 

301 """Test turning off fitting photometry.""" 

302 metrics = {'astrometry_collected_refStars': 568, 

303 'astrometry_prepared_refStars': 137, 

304 'astrometry_matched_fittedStars': 2070, 

305 'astrometry_prepared_fittedStars': 989, 

306 'astrometry_prepared_ccdImages': 6, 

307 'astrometry_final_chi2': 835.473, 

308 'astrometry_final_ndof': 1918, 

309 } 

310 self.config = lsst.jointcal.jointcal.JointcalConfig() 

311 self.config.astrometryModel = "simple" 

312 self.config.doPhotometry = False 

313 self.jointcalStatistics.do_photometry = False 

314 

315 data_refs = self._testJointcalTask(2, self.dist_rms_relative, self.dist_rms_absolute, 

316 None, metrics=metrics) 

317 

318 for data_ref in data_refs: 

319 with self.assertRaises(lsst.daf.persistence.butlerExceptions.NoResults): 

320 data_ref.get('jointcal_photoCalib') 

321 

322 def test_jointcalTask_2_visits_simple_astrometry_no_photometry_match_cut_10(self): 

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

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

325 associated, were. 

326 """ 

327 self.config = lsst.jointcal.jointcal.JointcalConfig() 

328 self.config.astrometryModel = "simple" 

329 self.config.matchCut = 10.0 # TODO: once DM-6885 is fixed, we need to put `*lsst.geom.arcseconds` 

330 self.config.doPhotometry = False 

331 self.jointcalStatistics.do_photometry = False 

332 

333 # Slightly larger absolute astrometry RMS because of the larger matching radius 

334 dist_rms_absolute = 23e-3*u.arcsecond 

335 metrics = {'astrometry_collected_refStars': 568, 

336 'astrometry_prepared_refStars': 211, 

337 'astrometry_matched_fittedStars': 2070, 

338 'astrometry_prepared_fittedStars': 1042, 

339 'astrometry_prepared_ccdImages': 6, 

340 'astrometry_final_chi2': 819.608, 

341 'astrometry_final_ndof': 1872, 

342 } 

343 pa1 = None 

344 self._testJointcalTask(2, self.dist_rms_relative, dist_rms_absolute, pa1, metrics=metrics) 

345 

346 def test_jointcalTask_3_visits_simple_astrometry_no_photometry(self): 

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

348 self.config = lsst.jointcal.jointcal.JointcalConfig() 

349 self.config.astrometryModel = "simple" 

350 self.config.minMeasurements = 2 

351 self.config.doPhotometry = False 

352 self.jointcalStatistics.do_photometry = False 

353 

354 # More visits and slightly worse relative and absolute rms. 

355 dist_rms_relative = 8.3e-3*u.arcsecond 

356 dist_rms_absolute = 24e-3*u.arcsecond 

357 metrics = {'astrometry_collected_refStars': 1038, 

358 'astrometry_prepared_refStars': 209, 

359 'astrometry_matched_fittedStars': 3199, 

360 'astrometry_prepared_fittedStars': 1282, 

361 'astrometry_prepared_ccdImages': 9, 

362 'astrometry_final_chi2': 1221.63, 

363 'astrometry_final_ndof': 2892, 

364 } 

365 pa1 = None 

366 self._testJointcalTask(3, dist_rms_relative, dist_rms_absolute, pa1, metrics=metrics) 

367 

368 def test_jointcalTask_3_visits_simple_astrometry_no_photometry_min_measurements_3(self): 

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

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

371 other values.""" 

372 self.config = lsst.jointcal.jointcal.JointcalConfig() 

373 self.config.minMeasurements = 3 

374 self.config.astrometryModel = "simple" 

375 self.config.doPhotometry = False 

376 self.jointcalStatistics.do_photometry = False 

377 

378 # More visits and slightly worse relative and absolute rms. 

379 dist_rms_relative = 11e-3*u.arcsecond 

380 dist_rms_absolute = 24e-3*u.arcsecond 

381 metrics = {'astrometry_collected_refStars': 1038, 

382 'astrometry_prepared_refStars': 209, 

383 'astrometry_matched_fittedStars': 3199, 

384 'astrometry_prepared_fittedStars': 432, 

385 'astrometry_prepared_ccdImages': 9, 

386 'astrometry_final_chi2': 567.433, 

387 'astrometry_final_ndof': 1286, 

388 } 

389 pa1 = None 

390 self._testJointcalTask(3, dist_rms_relative, dist_rms_absolute, pa1, metrics=metrics) 

391 

392 

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

394 pass 

395 

396 

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

398 lsst.utils.tests.init() 

399 unittest.main()