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 def test_jointcalTask_10_visits_simple_astrometry_no_photometry(self): 

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

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

102 """ 

103 

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

105 self.config.astrometryModel = "simple" 

106 self.config.doPhotometry = False 

107 self.jointcalStatistics.do_photometry = False 

108 

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

110 dist_rms_absolute = 22e-3*u.arcsecond 

111 dist_rms_relative = 13e-3*u.arcsecond 

112 pa1 = None 

113 metrics = {'collected_astrometry_refStars': 1316, 

114 'selected_astrometry_refStars': 318, 

115 'associated_astrometry_fittedStars': 5860, 

116 'selected_astrometry_fittedStars': 3568, 

117 'selected_astrometry_ccdImages': 30, 

118 'astrometry_final_chi2': 9621.29, 

119 'astrometry_final_ndof': 18562, 

120 } 

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

122 

123 def setup_jointcalTask_2_visits_simplePhotometry(self): 

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

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

126 """ 

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

128 self.config.photometryModel = "simpleFlux" 

129 self.config.doAstrometry = False 

130 self.jointcalStatistics.do_astrometry = False 

131 

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

133 pa1 = 0.016 

134 metrics = {'collected_photometry_refStars': 6485, 

135 'selected_photometry_refStars': 1609, 

136 'associated_photometry_fittedStars': 2070, 

137 'selected_photometry_fittedStars': 1731, 

138 'selected_photometry_ccdImages': 6, 

139 'photometry_final_chi2': 4997.62, 

140 'photometry_final_ndof': 2188 

141 } 

142 return pa1, metrics 

143 

144 def test_jointcalTask_2_visits_simpleFlux(self): 

145 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

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

147 

148 def test_jointcalTask_2_visits_simpleMagnitude(self): 

149 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

150 self.config.photometryModel = "simpleMagnitude" 

151 metrics['photometry_final_chi2'] = 5236.91 

152 metrics['photometry_final_ndof'] = 2200 

153 

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

155 

156 def test_jointcalTask_2_visits_simpleMagnitude_colorterms(self): 

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

158 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

159 self.config.photometryModel = "simpleMagnitude" 

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

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

162 self.configfiles.append(test_config) 

163 

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

165 metrics['collected_photometry_refStars'] = 6478 

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

167 # to expect it to be larger or smaller. 

168 metrics['photometry_final_chi2'] = 5181.25 

169 metrics['photometry_final_ndof'] = 2197 

170 

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

172 

173 def test_jointcalTask_2_visits_simpleMagnitude_colorterms_no_library(self): 

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

175 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

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

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

178 self.configfiles.append(test_config) 

179 

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

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

182 

183 def testJointcalTask_2_visits_simple_astrometry_no_photometry(self): 

184 """Test turning off fitting photometry.""" 

185 metrics = {'collected_astrometry_refStars': 568, 

186 'selected_astrometry_refStars': 137, 

187 'associated_astrometry_fittedStars': 2070, 

188 'selected_astrometry_fittedStars': 989, 

189 'selected_astrometry_ccdImages': 6, 

190 'astrometry_final_chi2': 683.783, 

191 'astrometry_final_ndof': 1916, 

192 } 

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

194 self.config.astrometryModel = "simple" 

195 self.config.doPhotometry = False 

196 self.jointcalStatistics.do_photometry = False 

197 

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

199 None, metrics=metrics) 

200 

201 for data_ref in data_refs: 

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

203 data_ref.get('jointcal_photoCalib') 

204 

205 def test_jointcalTask_2_visits_simple_astrometry_no_photometry_match_cut_10(self): 

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

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

208 associated, were. 

209 """ 

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

211 self.config.astrometryModel = "simple" 

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

213 self.config.doPhotometry = False 

214 self.jointcalStatistics.do_photometry = False 

215 

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

217 dist_rms_absolute = 23e-3*u.arcsecond 

218 metrics = {'collected_astrometry_refStars': 568, 

219 'selected_astrometry_refStars': 211, 

220 'associated_astrometry_fittedStars': 2070, 

221 'selected_astrometry_fittedStars': 1042, 

222 'selected_astrometry_ccdImages': 6, 

223 'astrometry_final_chi2': 683.369, 

224 'astrometry_final_ndof': 1910, 

225 } 

226 pa1 = None 

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

228 

229 def test_jointcalTask_3_visits_simple_astrometry_no_photometry(self): 

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

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

232 self.config.astrometryModel = "simple" 

233 self.config.minMeasurements = 2 

234 self.config.doPhotometry = False 

235 self.jointcalStatistics.do_photometry = False 

236 

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

238 dist_rms_relative = 8.2e-3*u.arcsecond 

239 dist_rms_absolute = 24e-3*u.arcsecond 

240 metrics = {'collected_astrometry_refStars': 1038, 

241 'selected_astrometry_refStars': 209, 

242 'associated_astrometry_fittedStars': 3199, 

243 'selected_astrometry_fittedStars': 1282, 

244 'selected_astrometry_ccdImages': 9, 

245 'astrometry_final_chi2': 1013.22, 

246 'astrometry_final_ndof': 2900, 

247 } 

248 pa1 = None 

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

250 

251 def test_jointcalTask_3_visits_simple_astrometry_no_photometry_min_measurements_3(self): 

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

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

254 other values.""" 

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

256 self.config.minMeasurements = 3 

257 self.config.astrometryModel = "simple" 

258 self.config.doPhotometry = False 

259 self.jointcalStatistics.do_photometry = False 

260 

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

262 dist_rms_relative = 11e-3*u.arcsecond 

263 dist_rms_absolute = 24e-3*u.arcsecond 

264 metrics = {'collected_astrometry_refStars': 1038, 

265 'selected_astrometry_refStars': 209, 

266 'associated_astrometry_fittedStars': 3199, 

267 'selected_astrometry_fittedStars': 432, 

268 'selected_astrometry_ccdImages': 9, 

269 'astrometry_final_chi2': 360.891, 

270 'astrometry_final_ndof': 1294, 

271 } 

272 pa1 = None 

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

274 

275 

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

277 pass 

278 

279 

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

281 lsst.utils.tests.init() 

282 unittest.main()