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

import numpy as np 

 

import unittest 

import lsst.utils.tests 

import lsst.jointcal.testUtils 

 

import lsst.afw.cameraGeom 

import lsst.afw.geom 

import lsst.afw.table 

import lsst.afw.image 

import lsst.afw.image.utils 

import lsst.daf.persistence 

import lsst.jointcal.ccdImage 

import lsst.jointcal.photometryModels 

import lsst.jointcal.star 

 

 

def getNParametersPolynomial(order): 

"""Number of parameters in a photometry polynomial model is (d+1)(d+2)/2.""" 

return (order + 1)*(order + 2)/2 

 

 

class PhotometryModelTestBase: 

@classmethod 

def setUpClass(cls): 

try: 

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

except lsst.pex.exceptions.NotFoundError: 

raise unittest.SkipTest("testdata_jointcal not setup") 

 

def setUp(self): 

# Ensure that the filter list is reset for each test so that we avoid 

# confusion or contamination each time we create a cfht camera below. 

lsst.afw.image.utils.resetFilters() 

 

struct = lsst.jointcal.testUtils.createTwoFakeCcdImages(100, 100) 

self.ccdImageList = struct.ccdImageList 

self.camera = struct.camera 

catalogs = struct.catalogs 

pixToFocal = self.ccdImageList[0].getDetector().getTransform(lsst.afw.cameraGeom.PIXELS, 

lsst.afw.cameraGeom.FOCAL_PLANE) 

self.stars = lsst.jointcal.testUtils.getMeasuredStarsFromCatalog(catalogs[0], pixToFocal) 

 

self.star0 = self.stars[0] 

self.star1 = self.stars[1] 

 

self.instFlux = 5.0 

self.instFluxErr = 2.0 

 

self.firstIndex = 0 # for assignIndices 

 

def _toPhotoCalib(self, ccdImage): 

"""Test converting this object to a PhotoCalib.""" 

photoCalib = self.model.toPhotoCalib(ccdImage) 

for star in self.stars: 

expect = self.model.transform(ccdImage, star, star.getInstFlux()) 

point = lsst.afw.geom.Point2D(star.x, star.y) 

result = photoCalib.instFluxToMaggies(star.getInstFlux(), point) 

self.assertFloatsAlmostEqual(result, expect, rtol=1e-13) 

 

def test_freezeErrorTransform(self): 

"""After calling freezeErrorTransform(), the error transform is unchanged 

by offsetParams(). 

""" 

self.model.offsetParams(self.delta) 

ccdImage = self.ccdImageList[0] 

t1 = self.model.transform(ccdImage, self.star0, self.instFlux) 

t1Err = self.model.transformError(ccdImage, self.star0, self.instFluxErr) 

self.model.freezeErrorTransform() 

self.model.offsetParams(self.delta) 

t2 = self.model.transform(ccdImage, self.star0, self.instFlux) 

t2Err = self.model.transformError(ccdImage, self.star0, self.instFluxErr) 

 

self.assertFloatsNotEqual(t1, t2) 

self.assertFloatsEqual(t1Err, t2Err) 

 

 

class SimplePhotometryModelTestCase(PhotometryModelTestBase, lsst.utils.tests.TestCase): 

def setUp(self): 

super(SimplePhotometryModelTestCase, self).setUp() 

self.model = lsst.jointcal.photometryModels.SimplePhotometryModel(self.ccdImageList) 

self.model.assignIndices("", self.firstIndex) # have to call this once to let offsetParams work. 

self.delta = np.arange(len(self.ccdImageList), dtype=float)*-0.2 + 1 

 

def test_getNpar(self): 

result = self.model.getNpar(self.ccdImageList[0]) 

self.assertEqual(result, 1) 

result = self.model.getNpar(self.ccdImageList[1]) 

self.assertEqual(result, 1) 

 

def testGetTotalParameters(self): 

result = self.model.getTotalParameters() 

self.assertEqual(result, 2) 

 

def test_toPhotoCalib(self): 

self._toPhotoCalib(self.ccdImageList[0]) 

self._toPhotoCalib(self.ccdImageList[1]) 

 

 

class ConstrainedPhotometryModelTestCase(PhotometryModelTestBase, lsst.utils.tests.TestCase): 

def setUp(self): 

super(ConstrainedPhotometryModelTestCase, self).setUp() 

self.visitOrder = 3 

self.focalPlaneBBox = self.camera.getFpBBox() 

self.model = lsst.jointcal.photometryModels.ConstrainedPhotometryModel(self.ccdImageList, 

self.focalPlaneBBox, 

self.visitOrder) 

# have to call this once to let offsetParams work. 

self.model.assignIndices("", self.firstIndex) 

# tweak to get more than just a constant field for the second ccdImage 

self.delta = np.arange(20, dtype=float)*-0.2 + 1 

# but keep the first ccdImage constant, to help distinguish test failures. 

self.delta[:10] = 0.0 

self.delta[0] = -5.0 

self.model.offsetParams(self.delta) 

 

def test_getNpar(self): 

""" 

Order 3 => (3+1)*(3+2))/2 = 10 parameters, 

and the chip map is fixed (only one ccd), so does not contribute. 

""" 

expect = getNParametersPolynomial(self.visitOrder) 

result = self.model.getNpar(self.ccdImageList[0]) 

self.assertEqual(result, expect) 

result = self.model.getNpar(self.ccdImageList[1]) 

self.assertEqual(result, expect) 

 

def testGetTotalParameters(self): 

"""Two visits, one (fixed) ccd.""" 

expect = getNParametersPolynomial(self.visitOrder) * 2 

result = self.model.getTotalParameters() 

self.assertEqual(result, expect) 

 

def test_toPhotoCalib(self): 

self._toPhotoCalib(self.ccdImageList[0]) 

self._toPhotoCalib(self.ccdImageList[1]) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()