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 LookupError: 

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

48 try: 

49 lsst.utils.getPackageDir('obs_subaru') 

50 except LookupError: 

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

52 

53 def setUp(self): 

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

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

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

57 

58 do_plot = False 

59 

60 # center of the hsc validation_data catalog 

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

62 radius = 0.5*lsst.geom.degrees 

63 

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

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

66 

67 self.setUp_base(center, radius, 

68 input_dir=input_dir, 

69 all_visits=all_visits, 

70 do_plot=do_plot) 

71 

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

73 self.configfiles.append(test_config) 

74 

75 def test_jointcalTask_2_visits_simple(self): 

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

77 self.config.astrometryModel = "simple" 

78 self.config.photometryModel = "simpleFlux" 

79 

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

81 pa1 = 0.016 

82 metrics = {'collected_astrometry_refStars': 568, 

83 'collected_photometry_refStars': 6485, 

84 'selected_astrometry_refStars': 137, 

85 'selected_photometry_refStars': 1609, 

86 'associated_astrometry_fittedStars': 2070, 

87 'associated_photometry_fittedStars': 2070, 

88 'selected_astrometry_fittedStars': 989, 

89 'selected_photometry_fittedStars': 1731, 

90 'selected_astrometry_ccdImages': 6, 

91 'selected_photometry_ccdImages': 6, 

92 'astrometry_final_chi2': 683.783, 

93 'astrometry_final_ndof': 1916, 

94 'photometry_final_chi2': 4997.62, 

95 'photometry_final_ndof': 2188 

96 } 

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

98 

99 @unittest.skip("This test cannot be run until gen3 jointcal is fully implemented.") 

100 def test_jointcalTask_2_visits_simple_gen3(self): 

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

102 self.config.astrometryModel = "simple" 

103 self.config.photometryModel = "simpleFlux" 

104 # TODO DM-27843: use PS1 until the gen3 refcats support `anyFilterMapsToThis` 

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

106 self.configfiles.append(test_config) 

107 

108 queryString = "instrument='HSC' and tract=9697 and skymap='deepCoadd_skyMap'" 

109 self._runGen3Jointcal("lsst.obs.subaru.HyperSuprimeCam", "HSC", queryString) 

110 

111 def test_jointcalTask_10_visits_simple_astrometry_no_photometry(self): 

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

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

114 """ 

115 

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

117 self.config.astrometryModel = "simple" 

118 self.config.doPhotometry = False 

119 self.jointcalStatistics.do_photometry = False 

120 

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

122 dist_rms_absolute = 23e-3*u.arcsecond 

123 dist_rms_relative = 13e-3*u.arcsecond 

124 pa1 = None 

125 metrics = {'collected_astrometry_refStars': 1316, 

126 'selected_astrometry_refStars': 318, 

127 'associated_astrometry_fittedStars': 5860, 

128 'selected_astrometry_fittedStars': 3568, 

129 'selected_astrometry_ccdImages': 30, 

130 'astrometry_final_chi2': 9621.29, 

131 'astrometry_final_ndof': 18562, 

132 } 

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

134 

135 def setup_jointcalTask_2_visits_simplePhotometry(self): 

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

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

138 """ 

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

140 self.config.photometryModel = "simpleFlux" 

141 self.config.doAstrometry = False 

142 self.jointcalStatistics.do_astrometry = False 

143 

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

145 pa1 = 0.016 

146 metrics = {'collected_photometry_refStars': 6485, 

147 'selected_photometry_refStars': 1609, 

148 'associated_photometry_fittedStars': 2070, 

149 'selected_photometry_fittedStars': 1731, 

150 'selected_photometry_ccdImages': 6, 

151 'photometry_final_chi2': 4997.62, 

152 'photometry_final_ndof': 2188 

153 } 

154 return pa1, metrics 

155 

156 def test_jointcalTask_2_visits_simpleFlux(self): 

157 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

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

159 

160 def test_jointcalTask_2_visits_simpleMagnitude(self): 

161 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

162 self.config.photometryModel = "simpleMagnitude" 

163 metrics['photometry_final_chi2'] = 5236.91 

164 metrics['photometry_final_ndof'] = 2200 

165 

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

167 

168 def test_jointcalTask_2_visits_simpleMagnitude_colorterms(self): 

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

170 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

171 self.config.photometryModel = "simpleMagnitude" 

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

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

174 self.configfiles.append(test_config) 

175 

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

177 metrics['collected_photometry_refStars'] = 6478 

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

179 # to expect it to be larger or smaller. 

180 metrics['photometry_final_chi2'] = 5181.25 

181 metrics['photometry_final_ndof'] = 2197 

182 

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

184 

185 def test_jointcalTask_2_visits_simpleMagnitude_colorterms_no_library(self): 

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

187 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

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

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

190 self.configfiles.append(test_config) 

191 

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

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

194 

195 def test_JointcalTask_2_visits_simple_astrometry_no_photometry(self): 

196 """Test turning off fitting photometry.""" 

197 metrics = {'collected_astrometry_refStars': 568, 

198 'selected_astrometry_refStars': 137, 

199 'associated_astrometry_fittedStars': 2070, 

200 'selected_astrometry_fittedStars': 989, 

201 'selected_astrometry_ccdImages': 6, 

202 'astrometry_final_chi2': 683.783, 

203 'astrometry_final_ndof': 1916, 

204 } 

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

206 self.config.astrometryModel = "simple" 

207 self.config.doPhotometry = False 

208 self.jointcalStatistics.do_photometry = False 

209 

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

211 None, metrics=metrics) 

212 

213 for data_ref in data_refs: 

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

215 data_ref.get('jointcal_photoCalib') 

216 

217 def test_jointcalTask_2_visits_simple_astrometry_no_photometry_match_cut_10(self): 

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

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

220 associated, were. 

221 """ 

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

223 self.config.astrometryModel = "simple" 

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

225 self.config.doPhotometry = False 

226 self.jointcalStatistics.do_photometry = False 

227 

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

229 dist_rms_absolute = 23e-3*u.arcsecond 

230 metrics = {'collected_astrometry_refStars': 568, 

231 'selected_astrometry_refStars': 211, 

232 'associated_astrometry_fittedStars': 2070, 

233 'selected_astrometry_fittedStars': 1042, 

234 'selected_astrometry_ccdImages': 6, 

235 'astrometry_final_chi2': 683.369, 

236 'astrometry_final_ndof': 1910, 

237 } 

238 pa1 = None 

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

240 

241 def test_jointcalTask_3_visits_simple_astrometry_no_photometry(self): 

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

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

244 self.config.astrometryModel = "simple" 

245 self.config.minMeasurements = 2 

246 self.config.doPhotometry = False 

247 self.jointcalStatistics.do_photometry = False 

248 

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

250 dist_rms_relative = 8.2e-3*u.arcsecond 

251 dist_rms_absolute = 24e-3*u.arcsecond 

252 metrics = {'collected_astrometry_refStars': 1038, 

253 'selected_astrometry_refStars': 209, 

254 'associated_astrometry_fittedStars': 3199, 

255 'selected_astrometry_fittedStars': 1282, 

256 'selected_astrometry_ccdImages': 9, 

257 'astrometry_final_chi2': 1013.20, 

258 'astrometry_final_ndof': 2900, 

259 } 

260 pa1 = None 

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

262 

263 def test_jointcalTask_3_visits_simple_astrometry_no_photometry_min_measurements_3(self): 

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

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

266 other values.""" 

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

268 self.config.minMeasurements = 3 

269 self.config.astrometryModel = "simple" 

270 self.config.doPhotometry = False 

271 self.jointcalStatistics.do_photometry = False 

272 

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

274 dist_rms_relative = 11e-3*u.arcsecond 

275 dist_rms_absolute = 24e-3*u.arcsecond 

276 metrics = {'collected_astrometry_refStars': 1038, 

277 'selected_astrometry_refStars': 209, 

278 'associated_astrometry_fittedStars': 3199, 

279 'selected_astrometry_fittedStars': 432, 

280 'selected_astrometry_ccdImages': 9, 

281 'astrometry_final_chi2': 360.884, 

282 'astrometry_final_ndof': 1294, 

283 } 

284 pa1 = None 

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

286 

287 

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

289 pass 

290 

291 

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

293 lsst.utils.tests.init() 

294 unittest.main()