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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

# This file is part of jointcal. 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

# (https://www.lsst.org). 

# See the COPYRIGHT file at the top-level directory of this distribution 

# for details of code ownership. 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with this program. If not, see <https://www.gnu.org/licenses/>. 

 

import inspect 

import unittest 

import os 

 

from astropy import units as u 

 

import lsst.afw.geom 

import lsst.utils 

import lsst.pex.exceptions 

 

import jointcalTestBase 

 

 

# for MemoryTestCase 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

 

@classmethod 

def setUpClass(cls): 

try: 

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

os.environ['ASTROMETRY_NET_DATA_DIR'] = os.path.join(cls.data_dir, 'hsc_and_index') 

except lsst.pex.exceptions.NotFoundError: 

raise unittest.SkipTest("testdata_jointcal not setup") 

 

def setUp(self): 

# See Readme for an explanation of this empirical value. 

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

 

do_plot = False 

 

# center of the hsc validation_data catalog 

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

radius = 5*lsst.afw.geom.degrees 

 

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

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

 

self.setUp_base(center, radius, 

input_dir=input_dir, 

all_visits=all_visits, 

do_plot=do_plot) 

 

def test_jointcalTask_2_visits(self): 

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

self.config.astrometryModel = "simple" 

self.config.photometryModel = "simpleFlux" 

self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated") 

 

# See Readme for an explanation of these empirical values. 

dist_rms_relative = 17e-3*u.arcsecond 

pa1 = 0.024 

metrics = {'collected_astrometry_refStars': 2187, 

'collected_photometry_refStars': 2187, 

'selected_astrometry_refStars': 515, 

'selected_photometry_refStars': 515, 

'associated_astrometry_fittedStars': 1151, 

'associated_photometry_fittedStars': 1151, 

'selected_astrometry_fittedStars': 770, 

'selected_photometry_fittedStars': 770, 

'selected_astrometry_ccdImages': 6, 

'selected_photometry_ccdImages': 6, 

'astrometry_final_chi2': 691.12, 

'astrometry_final_ndof': 1858, 

'photometry_final_chi2': 1557.27, 

'photometry_final_ndof': 968 

} 

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

 

def test_jointcalTask_11_visits_no_photometry(self): 

"""Test 11 visits with different filters. 

Testing photometry doesn't make sense for this currently. 

""" 

 

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

self.config.astrometryModel = "simple" 

self.config.doPhotometry = False 

self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated") 

self.jointcalStatistics.do_photometry = False 

 

# See Readme for an explanation of these empirical values. 

dist_rms_relative = 17e-3*u.arcsecond 

pa1 = None # pa1 = 0.134 

metrics = {'collected_astrometry_refStars': 3649, 

'selected_astrometry_refStars': 1038, 

'associated_astrometry_fittedStars': 2908, 

'selected_astrometry_fittedStars': 2203, 

'selected_astrometry_ccdImages': 33, 

'astrometry_final_chi2': 7929.656, 

'astrometry_final_ndof': 14262, 

} 

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

 

def setup_jointcalTask_2_visits_simplePhotometry(self): 

"""Help keep the simplePhotometry tests consistent and make 

the differences between them more obvious. 

""" 

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

self.config.photometryModel = "simpleFlux" 

self.config.doAstrometry = False 

self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated") 

self.jointcalStatistics.do_astrometry = False 

 

# See Readme for an explanation of these empirical values. 

pa1 = 0.024 

metrics = {'collected_photometry_refStars': 2187, 

'selected_photometry_refStars': 515, 

'associated_photometry_fittedStars': 1151, 

'selected_photometry_fittedStars': 770, 

'selected_photometry_ccdImages': 6, 

'photometry_final_chi2': 1557.27, 

'photometry_final_ndof': 968 

} 

return pa1, metrics 

 

def test_jointcalTask_2_visits_simpleFlux(self): 

pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

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

 

def test_jointcalTask_2_visits_simpleMagnitude(self): 

pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry() 

self.config.photometryModel = "simpleMagnitude" 

metrics['photometry_final_chi2'] = 1550.47 

metrics['photometry_final_ndof'] = 967 

 

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

 

def testJointcalTask_2_visits_no_photometry(self): 

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

# See Readme for an explanation of these empirical values. 

dist_rms_relative = 17e-3*u.arcsecond 

metrics = {'collected_astrometry_refStars': 2187, 

'selected_astrometry_refStars': 515, 

'associated_astrometry_fittedStars': 1151, 

'selected_astrometry_fittedStars': 770, 

'selected_astrometry_ccdImages': 6, 

'astrometry_final_chi2': 691.1210, 

'astrometry_final_ndof': 1858, 

} 

 

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

self.config.astrometryModel = "simple" 

self.config.doPhotometry = False 

self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated") 

self.jointcalStatistics.do_photometry = False 

 

caller = inspect.stack()[0].function 

result = self._runJointcalTask(2, caller, metrics=metrics) 

data_refs = result.resultList[0].result.dataRefs 

oldWcsList = result.resultList[0].result.oldWcsList 

rms_result = self.jointcalStatistics.compute_rms(data_refs, self.reference) 

 

if self.do_plot: 

self._plotJointcalTask(data_refs, oldWcsList, caller) 

 

self.assertLess(rms_result.dist_relative, dist_rms_relative) 

self.assertLess(rms_result.dist_absolute, self.dist_rms_absolute) 

self.assertIsNone(rms_result.pa1) 

 

for data_ref in data_refs: 

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

data_ref.get('jointcal_photoCalib') 

 

def test_jointcalTask_2_visits_gaia_refcat(self): 

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

self.config.astrometryModel = "simple" 

self.config.photometryModel = "simpleFlux" 

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

self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated") 

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

self.configfiles.extend([test_config]) 

dist_rms_relative = 17e-3*u.arcsecond 

 

# See Readme for an explanation of these empirical values. 

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

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

pa1 = 0.02405 

metrics = {'collected_astrometry_refStars': 1425, 

'collected_photometry_refStars': 2187, 

'selected_astrometry_refStars': 271, 

'selected_photometry_refStars': 515, 

'associated_astrometry_fittedStars': 1151, 

'associated_photometry_fittedStars': 1151, 

'selected_astrometry_fittedStars': 645, 

'selected_photometry_fittedStars': 770, 

'selected_astrometry_ccdImages': 6, 

'selected_photometry_ccdImages': 6, 

'astrometry_final_chi2': 435.01995, 

'astrometry_final_ndof': 1412, 

'photometry_final_chi2': 1557.27, 

'photometry_final_ndof': 968 

} 

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

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

# comparing against SDSS will look "worse"). 

dist_rms_absolute = 56e-3*u.arcsecond 

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

 

def test_jointcalTask_2_visits_no_photometry_match_cut_10(self): 

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

self.config.astrometryModel = "simple" 

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

self.config.doPhotometry = False 

self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated") 

self.jointcalStatistics.do_photometry = False 

 

# See Readme for an explanation of these empirical values. 

dist_rms_relative = 17e-3*u.arcsecond 

metrics = {'collected_astrometry_refStars': 2187, 

'selected_astrometry_refStars': 546, 

'associated_astrometry_fittedStars': 1151, 

'selected_astrometry_fittedStars': 790, 

'selected_astrometry_ccdImages': 6, 

'astrometry_final_chi2': 690.509, 

'astrometry_final_ndof': 1856, 

} 

pa1 = None 

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

 

def test_jointcalTask_3_visits_no_photometry(self): 

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

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

self.config.astrometryModel = "simple" 

self.config.minMeasurements = 2 

self.config.doPhotometry = False 

self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated") 

self.jointcalStatistics.do_photometry = False 

 

# See Readme for an explanation of these empirical values. 

dist_rms_relative = 17e-3*u.arcsecond 

metrics = {'collected_astrometry_refStars': 2187, 

'selected_astrometry_refStars': 541, 

'associated_astrometry_fittedStars': 1270, 

'selected_astrometry_fittedStars': 946, 

'selected_astrometry_ccdImages': 8, 

'astrometry_final_chi2': 1229.212, 

'astrometry_final_ndof': 3008, 

} 

pa1 = None 

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

 

def test_jointcalTask_3_visits_no_photometry_min_measurements_3(self): 

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

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

other values.""" 

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

self.config.minMeasurements = 3 

self.config.astrometryModel = "simple" 

self.config.doPhotometry = False 

self.config.sourceSelector['astrometry'].badFlags.append("base_PixelFlags_flag_interpolated") 

self.jointcalStatistics.do_photometry = False 

 

# See Readme for an explanation of these empirical values. 

dist_rms_relative = 17e-3*u.arcsecond 

metrics = {'collected_astrometry_refStars': 2187, 

'selected_astrometry_refStars': 541, 

'associated_astrometry_fittedStars': 1270, 

'selected_astrometry_fittedStars': 696, 

'selected_astrometry_ccdImages': 8, 

'astrometry_final_chi2': 1047.57, 

'astrometry_final_ndof': 2526, 

} 

pa1 = None 

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

 

 

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

pass 

 

 

295 ↛ 296line 295 didn't jump to line 296, because the condition on line 295 was never trueif __name__ == "__main__": 

lsst.utils.tests.init() 

unittest.main()