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 

26 

27import lsst.geom 

28import lsst.pex.config 

29import lsst.utils 

30import lsst.pex.exceptions 

31 

32import jointcalTestBase 

33 

34 

35# for MemoryTestCase 

36def setup_module(module): 

37 lsst.utils.tests.init() 

38 

39 

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

41 

42 @classmethod 

43 def setUpClass(cls): 

44 try: 

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

46 except lsst.pex.exceptions.NotFoundError: 

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

48 

49 def setUp(self): 

50 # See Readme for an explanation of this empirical value. 

51 self.dist_rms_absolute = 53e-3*u.arcsecond 

52 

53 do_plot = False 

54 

55 # center of the hsc validation_data catalog 

56 center = lsst.geom.SpherePoint(320.367492, 0.3131554, lsst.geom.degrees) 

57 radius = 5*lsst.geom.degrees 

58 

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

60 all_visits = [903334, 903336, 903338, 903342, 903344, 903346, 903986, 903988, 903990, 904010, 904014] 

61 

62 self.setUp_base(center, radius, 

63 input_dir=input_dir, 

64 all_visits=all_visits, 

65 do_plot=do_plot) 

66 

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

68 self.configfiles.append(test_config) 

69 

70 def test_jointcalTask_2_visits_simple(self): 

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

72 self.config.astrometryModel = "simple" 

73 self.config.photometryModel = "simpleFlux" 

74 

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

76 dist_rms_relative = 17e-3*u.arcsecond 

77 pa1 = 0.024 

78 metrics = {'collected_astrometry_refStars': 2948, 

79 'collected_photometry_refStars': 2948, 

80 'selected_astrometry_refStars': 657, 

81 'selected_photometry_refStars': 657, 

82 'associated_astrometry_fittedStars': 1151, 

83 'associated_photometry_fittedStars': 1151, 

84 'selected_astrometry_fittedStars': 851, 

85 'selected_photometry_fittedStars': 851, 

86 'selected_astrometry_ccdImages': 6, 

87 'selected_photometry_ccdImages': 6, 

88 'astrometry_final_chi2': 819.07, 

89 'astrometry_final_ndof': 2134, 

90 'photometry_final_chi2': 1811.45, 

91 'photometry_final_ndof': 1072 

92 } 

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

94 

95 def test_jointcalTask_11_visits_simple_astrometry_no_photometry(self): 

96 """Test 11 visits with different filters. 

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

98 """ 

99 

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

101 self.config.astrometryModel = "simple" 

102 self.config.doPhotometry = False 

103 self.jointcalStatistics.do_photometry = False 

104 

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

106 dist_rms_relative = 17e-3*u.arcsecond 

107 pa1 = None # pa1 = 0.134 

108 metrics = {'collected_astrometry_refStars': 4926, 

109 'selected_astrometry_refStars': 1346, 

110 'associated_astrometry_fittedStars': 2908, 

111 'selected_astrometry_fittedStars': 2276, 

112 'selected_astrometry_ccdImages': 33, 

113 'astrometry_final_chi2': 8207.62, 

114 'astrometry_final_ndof': 14856, 

115 } 

116 self._testJointcalTask(11, dist_rms_relative, self.dist_rms_absolute, pa1, metrics=metrics) 

117 

118 def setup_jointcalTask_2_visits_simplePhotometry(self): 

119 """Set default values for the constrainedAstrometry tests, and make 

120 the differences between each test and the defaults more obvious. 

121 """ 

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

123 self.config.photometryModel = "simpleFlux" 

124 self.config.doAstrometry = False 

125 self.jointcalStatistics.do_astrometry = False 

126 

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

128 pa1 = 0.024 

129 metrics = {'collected_photometry_refStars': 2948, 

130 'selected_photometry_refStars': 657, 

131 'associated_photometry_fittedStars': 1151, 

132 'selected_photometry_fittedStars': 851, 

133 'selected_photometry_ccdImages': 6, 

134 'photometry_final_chi2': 1811.45, 

135 'photometry_final_ndof': 1072 

136 } 

137 return pa1, metrics 

138 

139 def test_jointcalTask_2_visits_simpleFlux(self): 

140 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

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

142 

143 def test_jointcalTask_2_visits_simpleMagnitude(self): 

144 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

145 self.config.photometryModel = "simpleMagnitude" 

146 metrics['photometry_final_chi2'] = 1845.67 

147 metrics['photometry_final_ndof'] = 1074 

148 

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

150 

151 def test_jointcalTask_2_visits_simpleMagnitude_colorterms(self): 

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

153 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

154 self.config.photometryModel = "simpleMagnitude" 

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

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

157 self.configfiles.append(test_config) 

158 

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

160 # to expect it to be larger or smaller. 

161 metrics['photometry_final_chi2'] = 1966.67 

162 

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

164 

165 def test_jointcalTask_2_visits_simpleMagnitude_colorterms_no_library(self): 

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

167 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

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

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

170 self.configfiles.append(test_config) 

171 

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

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

174 

175 def testJointcalTask_2_visits_simple_astrometry_no_photometry(self): 

176 """Test turning off fitting photometry.""" 

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

178 dist_rms_relative = 17e-3*u.arcsecond 

179 metrics = {'collected_astrometry_refStars': 2948, 

180 'selected_astrometry_refStars': 657, 

181 'associated_astrometry_fittedStars': 1151, 

182 'selected_astrometry_fittedStars': 851, 

183 'selected_astrometry_ccdImages': 6, 

184 'astrometry_final_chi2': 819.07, 

185 'astrometry_final_ndof': 2134, 

186 } 

187 

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

189 self.config.astrometryModel = "simple" 

190 self.config.doPhotometry = False 

191 self.jointcalStatistics.do_photometry = False 

192 

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

194 None, metrics=metrics) 

195 

196 for data_ref in data_refs: 

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

198 data_ref.get('jointcal_photoCalib') 

199 

200 def test_jointcalTask_2_visits_simple_astrometry_gaia_refcat(self): 

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

202 self.config.astrometryModel = "simple" 

203 self.config.photometryModel = "simpleFlux" 

204 # use the a.net refcat for photometry, gaia for astrometry 

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

206 self.configfiles.append(test_config) 

207 dist_rms_relative = 17e-3*u.arcsecond 

208 

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

210 # NOTE: PA1 is slightly different here, because the number of SDSS 

211 # cross-matches within 0.1" goes down after we apply the GAIA-fit WCS. 

212 pa1 = 0.02405 

213 metrics = {'collected_astrometry_refStars': 1425, 

214 'collected_photometry_refStars': 2948, 

215 'selected_astrometry_refStars': 271, 

216 'selected_photometry_refStars': 657, 

217 'associated_astrometry_fittedStars': 1151, 

218 'associated_photometry_fittedStars': 1151, 

219 'selected_astrometry_fittedStars': 645, 

220 'selected_photometry_fittedStars': 851, 

221 'selected_astrometry_ccdImages': 6, 

222 'selected_photometry_ccdImages': 6, 

223 'astrometry_final_chi2': 435.01995, 

224 'astrometry_final_ndof': 1412, 

225 'photometry_final_chi2': 1811.45, 

226 'photometry_final_ndof': 1072 

227 } 

228 # NOTE: The astrometry/photometry tests are computed using the a.net SDSS refcat, 

229 # so the absolute astrometry RMS will be larger (because GAIA is better, so 

230 # comparing against SDSS will look "worse"). 

231 dist_rms_absolute = 56e-3*u.arcsecond 

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

233 

234 def test_jointcalTask_2_visits_simple_astrometry_no_photometry_match_cut_10(self): 

235 """A larger matching radius will result in more associated fittedStars. 

236 """ 

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

238 self.config.astrometryModel = "simple" 

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

240 self.config.doPhotometry = False 

241 self.jointcalStatistics.do_photometry = False 

242 

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

244 dist_rms_relative = 17e-3*u.arcsecond 

245 metrics = {'collected_astrometry_refStars': 2948, 

246 'selected_astrometry_refStars': 693, 

247 'associated_astrometry_fittedStars': 1151, 

248 'selected_astrometry_fittedStars': 876, 

249 'selected_astrometry_ccdImages': 6, 

250 'astrometry_final_chi2': 818.46, 

251 'astrometry_final_ndof': 2132, 

252 } 

253 pa1 = None 

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

255 

256 def test_jointcalTask_3_visits_simple_astrometry_no_photometry(self): 

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

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

259 self.config.astrometryModel = "simple" 

260 self.config.minMeasurements = 2 

261 self.config.doPhotometry = False 

262 self.jointcalStatistics.do_photometry = False 

263 

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

265 dist_rms_relative = 17e-3*u.arcsecond 

266 metrics = {'collected_astrometry_refStars': 2948, 

267 'selected_astrometry_refStars': 695, 

268 'associated_astrometry_fittedStars': 1270, 

269 'selected_astrometry_fittedStars': 1011, 

270 'selected_astrometry_ccdImages': 8, 

271 'astrometry_final_chi2': 1357.59, 

272 'astrometry_final_ndof': 3302, 

273 } 

274 pa1 = None 

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

276 

277 def test_jointcalTask_3_visits_simple_astrometry_no_photometry_min_measurements_3(self): 

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

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

280 other values.""" 

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

282 self.config.minMeasurements = 3 

283 self.config.astrometryModel = "simple" 

284 self.config.doPhotometry = False 

285 self.jointcalStatistics.do_photometry = False 

286 

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

288 dist_rms_relative = 17e-3*u.arcsecond 

289 metrics = {'collected_astrometry_refStars': 2948, 

290 'selected_astrometry_refStars': 695, 

291 'associated_astrometry_fittedStars': 1270, 

292 'selected_astrometry_fittedStars': 808, 

293 'selected_astrometry_ccdImages': 8, 

294 'astrometry_final_chi2': 1210.05, 

295 'astrometry_final_ndof': 2906, 

296 } 

297 pa1 = None 

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

299 

300 

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

302 pass 

303 

304 

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

306 lsst.utils.tests.init() 

307 unittest.main()