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

# 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/>. 

 

"""Test with a minimal catalog extracted from cfht.""" 

import inspect 

import unittest 

import os 

 

import lsst.afw.geom 

import lsst.utils 

import lsst.pex.exceptions 

 

import jointcalTestBase 

from lsst.jointcal import jointcal 

 

 

# for MemoryTestCase 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

@classmethod 

def setUpClass(cls): 

cls.data_dir = os.path.join(lsst.utils.getPackageDir('jointcal'), 'tests/data') 

 

def setUp(self): 

do_plot = False 

 

# center of the cfht validation_data catalog 

center = lsst.afw.geom.SpherePoint(214.884832, 52.6622199, lsst.afw.geom.degrees) 

radius = 3*lsst.afw.geom.degrees 

 

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

all_visits = [849375, 850587] 

other_args = ['ccd=12'] 

 

self.setUp_base(center, radius, 

input_dir=input_dir, 

all_visits=all_visits, 

other_args=other_args, 

do_plot=do_plot, log_level="debug") 

 

def test_jointcalTask_2_visits_photometry(self): 

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

self.config.photometryModel = "simpleFlux" 

self.config.doAstrometry = False 

self.config.writeInitMatrix = True # write Hessian/gradient files 

self.jointcalStatistics.do_astrometry = False 

 

# NOTE: ndof==1 from 4 fit parameters (2 model, 2 fittedStar), and 

# 5 degrees-of-freedom (3 star measurements, with 2 reference stars). 

metrics = {'collected_photometry_refStars': 346, 

'selected_photometry_refStars': 2, 

'associated_photometry_fittedStars': 2, 

'selected_photometry_fittedStars': 2, 

'selected_photometry_ccdImages': 2, 

'photometry_final_chi2': 2.336915, 

'photometry_final_ndof': 1 

} 

 

# The output repo is named after this method. 

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

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

 

# Check that the Hessian/gradient files were written. 

self.assertTrue(os.path.exists("photometry_preinit-mat.txt")) 

os.remove("photometry_preinit-mat.txt") 

self.assertTrue(os.path.exists("photometry_preinit-grad.txt")) 

os.remove("photometry_preinit-grad.txt") 

self.assertTrue(os.path.exists("photometry_postinit-mat.txt")) 

os.remove("photometry_postinit-mat.txt") 

self.assertTrue(os.path.exists("photometry_postinit-grad.txt")) 

os.remove("photometry_postinit-grad.txt") 

 

def test_jointcalTask_2_visits_photometry_magnitude(self): 

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

self.config.photometryModel = "simpleMagnitude" 

self.config.doAstrometry = False 

self.jointcalStatistics.do_astrometry = False 

 

# NOTE: ndof==1 from 4 fit parameters (2 model, 2 fittedStar), and 

# 5 degrees-of-freedom (3 star measurements, with 2 reference stars). 

metrics = {'collected_photometry_refStars': 346, 

'selected_photometry_refStars': 2, 

'associated_photometry_fittedStars': 2, 

'selected_photometry_fittedStars': 2, 

'selected_photometry_ccdImages': 2, 

'photometry_final_chi2': 2.23008, 

'photometry_final_ndof': 1 

} 

 

# The output repo is named after this method. 

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

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

 

def test_jointcalTask_fails_raise(self): 

"""Raise an exception if there is no data to process.""" 

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

self.config.setDefaults() 

self.config.photometryModel = "simpleFlux" 

self.config.sourceSelector['astrometry'].minSnr = 10000 

self.config.doAstrometry = False 

 

# The output repo is named after this method. 

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

nCatalogs = 2 

visits = '^'.join(str(v) for v in self.all_visits[:nCatalogs]) 

output_dir = os.path.join('.test', self.__class__.__name__, caller) 

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

self.configfiles = [test_config] + self.configfiles 

args = [self.input_dir, '--output', output_dir, 

'--clobber-versions', '--clobber-config', '--configfile', *self.configfiles, 

'--doraise', 

'--id', 'visit=%s'%visits] 

args.extend(self.other_args) 

with self.assertRaises(RuntimeError): 

jointcal.JointcalTask.parseAndRun(args=args, doReturnResults=True, config=self.config) 

 

def test_jointcalTask_fails_no_raise(self): 

"""exitStatus=1 if there is no data to process.""" 

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

self.config.setDefaults() 

self.config.photometryModel = "simpleFlux" 

self.config.sourceSelector['astrometry'].minSnr = 10000 

self.config.doAstrometry = False 

 

# The output repo is named after this method. 

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

nCatalogs = 2 

visits = '^'.join(str(v) for v in self.all_visits[:nCatalogs]) 

output_dir = os.path.join('.test', self.__class__.__name__, caller) 

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

self.configfiles = [test_config] + self.configfiles 

args = [self.input_dir, '--output', output_dir, 

'--clobber-versions', '--clobber-config', '--configfile', *self.configfiles, 

'--noExit', # have to specify noExit, otherwise the test quits 

'--id', 'visit=%s'%visits] 

args.extend(self.other_args) 

result = jointcal.JointcalTask.parseAndRun(args=args, doReturnResults=True, config=self.config) 

self.assertEqual(result.resultList[0].exitStatus, 1) 

 

def test_jointcalTask_fails_no_raise_no_return_results(self): 

"""exitStatus=1 if there is no data to process.""" 

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

self.config.setDefaults() 

self.config.photometryModel = "simpleFlux" 

self.config.sourceSelector['astrometry'].minSnr = 10000 

self.config.doAstrometry = False 

 

# The output repo is named after this method. 

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

nCatalogs = 2 

visits = '^'.join(str(v) for v in self.all_visits[:nCatalogs]) 

output_dir = os.path.join('.test', self.__class__.__name__, caller) 

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

self.configfiles = [test_config] + self.configfiles 

args = [self.input_dir, '--output', output_dir, 

'--clobber-versions', '--clobber-config', '--configfile', *self.configfiles, 

'--noExit', # have to specify noExit, otherwise the test quits 

'--id', 'visit=%s'%visits] 

args.extend(self.other_args) 

result = jointcal.JointcalTask.parseAndRun(args=args, config=self.config) 

self.assertEqual(result.resultList[0].exitStatus, 1) 

 

 

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

pass 

 

 

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

lsst.utils.tests.init() 

unittest.main()