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

# 

# LSST Data Management System 

# Copyright 2008-2014 LSST Corporation. 

# 

# This product includes software developed by the 

# LSST Project (http://www.lsst.org/). 

# 

# 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 LSST License Statement and 

# the GNU General Public License along with this program. If not, 

# see <http://www.lsstcorp.org/LegalNotices/>. 

# 

 

""" 

Tests for image.ApCorrMap 

 

Run with: 

python test_apCorrMap.py 

or 

pytest test_apCorrMap.py 

""" 

import collections 

import os 

import unittest 

 

import numpy as np 

 

import lsst.utils.tests 

import lsst.pex.exceptions 

import lsst.geom 

import lsst.afw.math 

import lsst.afw.image 

 

 

class ApCorrMapTestCase(lsst.utils.tests.TestCase): 

 

def setUp(self): 

np.random.seed(100) 

self.bbox = lsst.geom.Box2I( 

lsst.geom.Point2I(-5, -5), lsst.geom.Point2I(5, 5)) 

self.map = lsst.afw.image.ApCorrMap() 

for name in ("a", "b", "c"): 

self.map.set(name, lsst.afw.math.ChebyshevBoundedField( 

self.bbox, np.random.randn(3, 3))) 

 

def tearDown(self): 

del self.map 

del self.bbox 

 

def compare(self, a, b): 

"""Compare two ApCorrMaps for equality, without assuming that their BoundedFields have the 

same addresses (i.e. so we can compare after serialization). 

""" 

self.assertEqual(len(a), len(b)) 

for name, value in list(a.items()): 

value2 = b.get(name) 

self.assertIsNotNone(value2) 

self.assertEqual(value.getBBox(), value2.getBBox()) 

self.assertFloatsAlmostEqual( 

value.getCoefficients(), value2.getCoefficients(), rtol=0.0) 

 

def testAccessors(self): 

"""Test the accessors and other custom Swig code we've added to make ApCorrMap behave like a Python 

mapping. 

""" 

self.assertEqual(len(self.map), 3) 

self.assertEqual(collections.OrderedDict(self.map), 

{name: value for (name, value) in list(self.map.items())}) 

self.assertEqual(list(collections.OrderedDict(self.map).keys()), 

list(self.map.keys())) 

self.assertEqual(list(collections.OrderedDict(self.map).values()), 

list(self.map.values())) 

self.assertEqual(list(collections.OrderedDict(self.map).items()), 

list(self.map.items())) 

self.assertEqual(list(collections.OrderedDict(self.map).keys()), 

list(self.map)) 

self.assertIn("b", self.map) 

self.assertNotIn("d", self.map) 

self.map["d"] = lsst.afw.math.ChebyshevBoundedField( 

self.bbox, np.random.randn(2, 2)) 

self.assertIn("d", self.map) 

self.assertIsNone(self.map.get("e")) 

with self.assertRaises(lsst.pex.exceptions.NotFoundError): 

self.map["e"] 

self.assertEqual(self.map.get("d"), self.map["d"]) 

 

def testPersistence(self): 

"""Test that we can round-trip an ApCorrMap through FITS persistence. 

""" 

with lsst.utils.tests.getTempFilePath(".fits") as filename: 

self.map.writeFits(filename) 

map2 = lsst.afw.image.ApCorrMap.readFits(filename) 

self.compare(self.map, map2) 

 

def testExposurePersistence(self): 

"""Test that the ApCorrMap is saved with an Exposure. 

""" 

with lsst.utils.tests.getTempFilePath(".fits") as filename: 

exposure1 = lsst.afw.image.ExposureF(self.bbox) 

exposure1.getInfo().setApCorrMap(self.map) 

exposure1.writeFits(filename) 

exposure2 = lsst.afw.image.ExposureF(filename) 

map2 = exposure2.getInfo().getApCorrMap() 

self.compare(self.map, map2) 

 

def testExposureRecordPersistence(self): 

"""Test that the ApCorrMap is saved with an ExposureRecord. 

""" 

with lsst.utils.tests.getTempFilePath(".fits") as filename: 

cat1 = lsst.afw.table.ExposureCatalog( 

lsst.afw.table.ExposureTable.makeMinimalSchema()) 

record1 = cat1.addNew() 

record1.setApCorrMap(self.map) 

cat1.writeFits(filename) 

cat2 = lsst.afw.table.ExposureCatalog.readFits(filename) 

record2 = cat2[0] 

map2 = record2.getApCorrMap() 

self.compare(self.map, map2) 

 

def testExposureCatalogBackwardsCompatibility(self): 

"""Test that we can read an ExposureCatalog written with an old version of the code. 

""" 

testPath = os.path.abspath(os.path.dirname(__file__)) 

filename = os.path.join(testPath, "data", "version-0-ExposureCatalog.fits") 

cat = lsst.afw.table.ExposureCatalog.readFits(filename) 

record = cat[0] 

self.assertIsNone(record.getApCorrMap()) 

 

def testScale(self): 

"""Test that we can scale an ApCorrMap. 

""" 

scale = 12.345 

new = lsst.afw.image.ApCorrMap() 

for name, value in self.map.items(): 

new.set(name, value*scale) 

new /= scale 

self.compare(self.map, new) 

# And back the other way 

new = lsst.afw.image.ApCorrMap() 

for name, value in self.map.items(): 

new.set(name, value/scale) 

new *= scale 

self.compare(self.map, new) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()