Coverage for tests/test_equatSkyMap.py: 13%

119 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-23 08:20 +0000

1# 

2# LSST Data Management System 

3# Copyright 2008, 2009, 2010 LSST Corporation. 

4# 

5# This product includes software developed by the 

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

7# 

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

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

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

11# (at your option) any later version. 

12# 

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

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

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

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

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

21# 

22"""Test EquatSkyMap class 

23""" 

24import unittest 

25 

26import numpy 

27 

28import lsst.geom as geom 

29import lsst.utils.tests 

30 

31from lsst.skymap import EquatSkyMap 

32from helper import skyMapTestCase 

33 

34 

35class EquatSkyMapTestCase(skyMapTestCase.SkyMapTestCase): 

36 def setUp(self): 

37 self.setAttributes( 

38 SkyMapClass=EquatSkyMap, 

39 name="equat", 

40 numTracts=4, 

41 neighborAngularSeparation=90*geom.degrees, 

42 numNeighbors=2, 

43 ) 

44 

45 def getNeighborTracts(self, skyMap, tractId): 

46 """Return previous and next tractInfo 

47 """ 

48 if not 0 <= tractId < len(skyMap): 

49 raise RuntimeError("Invalid tractId=%s" % (tractId,)) 

50 if tractId > 0: 

51 prevTract = skyMap[tractId - 1] 

52 else: 

53 prevTract = skyMap[-1] 

54 if tractId + 1 < len(skyMap): 

55 nextTract = skyMap[tractId + 1] 

56 else: 

57 nextTract = skyMap[0] 

58 return (prevTract, nextTract) 

59 

60 def testDefaults(self): 

61 """Test important default values 

62 """ 

63 config = EquatSkyMap.ConfigClass() 

64 skyMap = EquatSkyMap(config) 

65 self.assertEqual(skyMap.config.projection, "CEA") 

66 

67 def test_gettingPatchInfo(self): 

68 skyMap = EquatSkyMap(EquatSkyMap.ConfigClass()) 

69 tract = skyMap[0] 

70 # Look up patchInfo with a coordinate pair 

71 patchIndex = (3, 5) 

72 pairPatchInfo = tract.getPatchInfo(patchIndex) 

73 # Fetch the sequential index 

74 sequentialPatchIndex = tract.getSequentialPatchIndex(pairPatchInfo) 

75 # Turn the sequential index back into a pair 

76 returnedPatchIndex = tract.getPatchIndexPair(sequentialPatchIndex) 

77 # Test that the different indexes match 

78 self.assertEqual(patchIndex, returnedPatchIndex) 

79 # verify patch info can be retrieved with both indexes 

80 sequentialPatchInfo = tract.getPatchInfo(sequentialPatchIndex) 

81 self.assertEqual(pairPatchInfo, sequentialPatchInfo) 

82 

83 def testSymmetry(self): 

84 """Verify that the projection is symmetrical about the equator 

85 """ 

86 for minDec in (-5.0, -1.0, 0.5): 

87 maxDec = minDec + 2.0 

88 config = EquatSkyMap.ConfigClass() 

89 config.decRange = minDec, maxDec 

90 skyMap = EquatSkyMap(config) 

91 for tractInfo in skyMap[0:1]: 

92 numPatches = tractInfo.getNumPatches() 

93 midXIndex = numPatches[0]//2 

94 minPixelPosList = [] 

95 maxPixelPosList = [] 

96 maxYInd = numPatches[1] - 1 

97 for xInd in (0, midXIndex, numPatches[0] - 1): 

98 minDecPatchInfo = tractInfo.getPatchInfo((xInd, 0)) 

99 minDecPosBox = geom.Box2D(minDecPatchInfo.getOuterBBox()) 

100 minPixelPosList += [ 

101 minDecPosBox.getMin(), 

102 geom.Point2D(minDecPosBox.getMaxX(), minDecPosBox.getMinY()), 

103 ] 

104 

105 maxDecPatchInfo = tractInfo.getPatchInfo((xInd, maxYInd)) 

106 maxDecPosBox = geom.Box2D(maxDecPatchInfo.getOuterBBox()) 

107 maxPixelPosList += [ 

108 maxDecPosBox.getMax(), 

109 geom.Point2D(maxDecPosBox.getMinX(), maxDecPosBox.getMaxY()), 

110 ] 

111 wcs = tractInfo.getWcs() 

112 minDecList = [wcs.pixelToSky(pos).getPosition(geom.degrees)[1] for pos in minPixelPosList] 

113 maxDecList = [wcs.pixelToSky(pos).getPosition(geom.degrees)[1] for pos in maxPixelPosList] 

114 self.assertTrue(numpy.allclose(minDecList, minDecList[0])) 

115 self.assertTrue(numpy.allclose(maxDecList, maxDecList[0])) 

116 self.assertTrue(minDecList[0] <= minDec) 

117 self.assertTrue(maxDecList[0] >= maxDec) 

118 

119 def testMoreBasicAttributes(self): 

120 """Confirm that constructor attributes are available. 

121 """ 

122 defaultSkyMap = self.getSkyMap() 

123 for numTracts in (1, 2, 4, 25): 

124 config = EquatSkyMap.ConfigClass() 

125 config.numTracts = numTracts 

126 skyMap = EquatSkyMap(config) 

127 self.assertEqual(len(skyMap), numTracts) 

128 if numTracts == defaultSkyMap.config.numTracts: 

129 self.assertEqual(skyMap, defaultSkyMap) 

130 else: 

131 self.assertNotEqual(skyMap, defaultSkyMap) 

132 

133 for decRange in ([-1.3, 0.5], [6.1, 6.8]): 

134 config = EquatSkyMap.ConfigClass() 

135 config.decRange = decRange 

136 skyMap = EquatSkyMap(config) 

137 self.assertNotEqual(skyMap, defaultSkyMap) 

138 

139 def testFindTract(self): 

140 """Test the SkyMap.findTract method 

141 """ 

142 for numTracts in (2, 4): 

143 config = EquatSkyMap.ConfigClass() 

144 config.numTracts = numTracts 

145 skyMap = EquatSkyMap(config) 

146 decRange = skyMap.config.decRange 

147 decList = ( 

148 (decRange[0] * 0.999) + (decRange[1] * 0.901), 

149 (decRange[0] * 0.500) + (decRange[1] * 0.500), 

150 (decRange[0] * 0.091) + (decRange[1] * 0.999), 

151 ) 

152 for tractInfo0 in skyMap: 

153 tractId0 = tractInfo0.getId() 

154 ctrCoord0 = tractInfo0.getCtrCoord() 

155 

156 for tractInfo1 in self.getNeighborTracts(skyMap, tractId0): 

157 

158 tractId1 = tractInfo1.getId() 

159 ctrCoord1 = tractInfo1.getCtrCoord() 

160 

161 for deltaFrac in (-0.001, 0.001): 

162 v0 = ctrCoord0.getVector() * (0.5 + deltaFrac) 

163 v1 = ctrCoord1.getVector() * (0.5 - deltaFrac) 

164 testVec = v0 + v1 

165 testRa = geom.SpherePoint(testVec).getRa() 

166 

167 if deltaFrac > 0.0: 

168 expectedTractId = tractId0 

169 else: 

170 expectedTractId = tractId1 

171 

172 for testDecDeg in decList: 

173 testDec = geom.Angle(testDecDeg, geom.degrees) 

174 testCoord = geom.SpherePoint(testRa, testDec) 

175 

176 nearestTractInfo = skyMap.findTract(testCoord) 

177 nearestTractId = nearestTractInfo.getId() 

178 

179 self.assertEqual(nearestTractId, expectedTractId) 

180 

181 patchInfo = nearestTractInfo.findPatch(testCoord) 

182 pixelInd = geom.Point2I(nearestTractInfo.getWcs().skyToPixel(testCoord)) 

183 self.assertTrue(patchInfo.getInnerBBox().contains(pixelInd)) 

184 

185 # find a point outside the tract and make sure it fails 

186 tractInfo = tractInfo0 

187 wcs = tractInfo.getWcs() 

188 bbox = geom.Box2D(tractInfo.getBBox()) 

189 outerPixPosList = [ 

190 bbox.getMin() - geom.Extent2D(1, 1), 

191 geom.Point2D(bbox.getMaxX(), bbox.getMinY()) - geom.Extent2D(1, 1), 

192 bbox.getMax() + geom.Extent2D(1, 1), 

193 geom.Point2D(bbox.getMinX(), bbox.getMaxY()) + geom.Extent2D(1, 1), 

194 ] 

195 for outerPixPos in outerPixPosList: 

196 testCoord = wcs.pixelToSky(outerPixPos) 

197 self.assertRaises(LookupError, tractInfo.findPatch, testCoord) 

198 

199 

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

201 pass 

202 

203 

204def setup_module(module): 

205 lsst.utils.tests.init() 

206 

207 

208if __name__ == "__main__": 208 ↛ 209line 208 didn't jump to line 209, because the condition on line 208 was never true

209 lsst.utils.tests.init() 

210 unittest.main()