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

# See COPYRIGHT file at the top of the source tree. 

import inspect 

import unittest 

import os 

 

from astropy import units as u 

 

import lsst.afw.geom 

import lsst.afw.image 

import lsst.utils 

import lsst.pex.exceptions 

from lsst.meas.extensions.astrometryNet import LoadAstrometryNetObjectsTask 

 

import jointcalTestBase 

import lsst.jointcal.jointcal 

 

 

# for MemoryTestCase 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

class JointcalTestLSSTSim(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, 'twinkles1_and_index') 

except lsst.pex.exceptions.NotFoundError: 

raise unittest.SkipTest("testdata_jointcal not setup") 

 

def setUp(self): 

# We don't want the absolute astrometry to become significantly worse 

# than the single-epoch astrometry (about 0.040"). 

# See Readme for an explanation of this empirical value. 

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

 

do_plot = False 

 

# position of the Twinkles run 1 catalog 

center = lsst.afw.geom.SpherePoint(53.00914, -27.43895, lsst.afw.geom.degrees) 

radius = 3*lsst.afw.geom.degrees 

 

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

all_visits = list(range(840, 850)) 

other_args = ['raft=2,2', 'sensor=1,1', 'filter=r'] 

 

self.setUp_base(center, radius, 

input_dir=input_dir, 

all_visits=all_visits, 

other_args=other_args, 

do_plot=do_plot) 

 

@unittest.skip('jointcal currently fails (may segfault) if only given one catalog!') 

def testJointcalTask_1_visits(self): 

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

self.config.photometryRefObjLoader.retarget(LoadAstrometryNetObjectsTask) 

self.config.astrometryRefObjLoader.retarget(LoadAstrometryNetObjectsTask) 

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

 

dist_rms_relative = 0*u.arcsecond # there is no such thing as a "relative" test for 1 catalog. 

pa1 = 2.64e-3 

self._testJointcalTask(1, dist_rms_relative, self.dist_rms_absolute, pa1) 

 

def testJointcalTask_2_visits(self): 

# NOTE: The relative RMS limits were empirically determined from the 

# first run of jointcal on this data. We should always do better than 

# this in the future! 

dist_rms_relative = 9.7e-3*u.arcsecond 

# TODO: reinstate photometry tests once DM-11397 is fixed. 

# NOTE: the measured values of the metrics may change with the new fitter. 

pa1 = None 

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

self.config.astrometryModel = "simple" 

self.config.astrometryRefObjLoader.retarget(LoadAstrometryNetObjectsTask) 

self.config.photometryRefObjLoader.retarget(LoadAstrometryNetObjectsTask) 

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

self.config.doPhotometry = False 

self.jointcalStatistics.do_photometry = False 

 

# See Readme for an explanation of these empirical values. 

# pa1 = 2.64e-3 

# 'collected_photometry_refStars': 1686, 

# 'selected_photometry_refStars': 1686, 

# 'associated_photometry_fittedStars': 1365, 

# 'selected_photometry_fittedStars': 789, 

# 'selected_photometry_ccdImages': 2, 

# 'photometry_final_chi2': 2310.628, 

# 'photometry_final_ndof': 727 

metrics = {'collected_astrometry_refStars': 1686, 

'selected_astrometry_refStars': 176, 

'associated_astrometry_fittedStars': 1365, 

'selected_astrometry_fittedStars': 789, 

'selected_astrometry_ccdImages': 2, 

'astrometry_final_chi2': 742.4992, 

'astrometry_final_ndof': 1698, 

} 

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

 

def testJointcalTask_10_visits(self): 

dist_rms_relative = 7.9e-3*u.arcsecond 

# TODO: reinstate photometry tests once DM-11397 is fixed. 

# NOTE: the measured values of the metrics may change with the new fitter. 

pa1 = None 

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

self.config.astrometryModel = "simple" 

self.config.astrometryRefObjLoader.retarget(LoadAstrometryNetObjectsTask) 

self.config.photometryRefObjLoader.retarget(LoadAstrometryNetObjectsTask) 

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. 

# pa1 = 2.64e-3 

# 'collected_photometry_refStars': 1686, 

# 'selected_photometry_refStars': 1686, 

# 'associated_photometry_fittedStars': 1823, 

# 'selected_photometry_fittedStars': 1506, 

# 'selected_photometry_ccdImages': 10, 

# 'photometry_final_chi2': 35321.947, 

# 'photometry_final_ndof': 9140 

metrics = {'collected_astrometry_refStars': 1686, 

'selected_astrometry_refStars': 203, 

'associated_astrometry_fittedStars': 1823, 

'selected_astrometry_fittedStars': 1506, 

'selected_astrometry_ccdImages': 10, 

'astrometry_final_chi2': 7262.2075, 

'astrometry_final_ndof': 18260, 

} 

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

 

@unittest.skip("A.net reference catalog missing flux errors. Unskip once DM-11397 is fixed.") 

def testJointcalTask_2_visits_no_astrometry(self): 

"""Test turning off fitting astrometry.""" 

# See Readme for an explanation of these empirical values. 

pa1 = 2.64e-3 

metrics = {'collected_photometry_refStars': 1686, 

'selected_photometry_refStars': 176, 

'associated_photometry_fittedStars': 1365, 

'selected_photometry_fittedStars': 789, 

'selected_photometry_ccdImages': 2, 

'photometry_final_chi2': 2310.6280, 

'photometry_final_ndof': 727 

} 

 

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

self.config.photometryRefObjLoader.retarget(LoadAstrometryNetObjectsTask) 

self.config.doAstrometry = False 

self.config.photometryModel = "simpleFlux" 

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

self.jointcalStatistics.do_astrometry = 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.assertIsNone(rms_result.dist_relative) 

self.assertIsNone(rms_result.dist_absolute) 

self.assertLess(rms_result.pa1, pa1) 

 

for data_ref in data_refs: 

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

data_ref.get('jointcal_wcs') 

 

def testJointcalTask_2_visits_no_photometry(self): 

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

# See Readme for an explanation of these empirical values. 

dist_rms_relative = 9.7e-3*u.arcsecond 

metrics = {'collected_astrometry_refStars': 1686, 

'selected_astrometry_refStars': 176, 

'associated_astrometry_fittedStars': 1365, 

'selected_astrometry_fittedStars': 789, 

'selected_astrometry_ccdImages': 2, 

'astrometry_final_chi2': 742.4992, 

'astrometry_final_ndof': 1698 

} 

 

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

self.config.astrometryRefObjLoader.retarget(LoadAstrometryNetObjectsTask) 

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') 

 

 

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

pass 

 

 

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

lsst.utils.tests.init() 

unittest.main()