Coverage for tests/test_wcsSelectImages.py: 54%

Shortcuts 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

80 statements  

1# 

2# LSST Data Management System 

3# Copyright 2008-2013 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 

23import unittest 

24 

25import lsst.utils.tests 

26import lsst.geom as geom 

27import lsst.afw.geom as afwGeom 

28from lsst.pipe.tasks.selectImages import WcsSelectImagesTask, SelectStruct 

29from lsst.pipe.tasks.coaddBase import CoaddBaseTask 

30 

31 

32class KeyValue: 

33 

34 """Mixin to provide __getitem__ of key/value pair""" 

35 

36 def __init__(self, key, value): 

37 self._key = key 

38 self._value = value 

39 

40 def __getitem__(self, key): 

41 if key != self._key: 

42 raise KeyError("Unrecognised key in %s: %s vs %s" % (self.__class__.__name__, key, self._key)) 

43 return self._value 

44 

45 

46class DummyPatch: 

47 

48 """Quacks like a lsst.skymap.PatchInfo""" 

49 

50 def __init__(self, xy0, dims): 

51 self._outerBBox = geom.Box2I(xy0, dims) 

52 

53 def getOuterBBox(self): 

54 return self._outerBBox 

55 

56 

57class DummyTract(KeyValue): 

58 

59 """Quacks like a lsst.skymap.TractInfo""" 

60 

61 def __init__(self, patchId, patch, wcs): 

62 super(DummyTract, self).__init__(patchId, patch) 

63 self._wcs = wcs 

64 

65 def getPatchInfo(self, patchId): 

66 return self[patchId] 

67 

68 def getWcs(self): 

69 return self._wcs 

70 

71 

72class DummySkyMap(KeyValue): 

73 

74 """Quacks like a lsst.skymap.BaseSkyMap""" 

75 

76 def __init__(self, tractId, tract): 

77 super(DummySkyMap, self).__init__(tractId, tract) 

78 

79 

80class DummyDataRef: 

81 

82 """Quacks like a lsst.daf.persistence.ButlerDataRef""" 

83 

84 def __init__(self, dataId, **data): 

85 self.dataId = dataId 

86 self._data = data 

87 

88 def get(self, dataType): 

89 return self._data[dataType] 

90 

91 

92# Common defaults for createPatch and createImage 

93CENTER = geom.SpherePoint(0, 90, geom.degrees) 

94ROTATEAXIS = geom.SpherePoint(0, 0, geom.degrees) 

95DIMS = geom.Extent2I(3600, 3600) 

96SCALE = 0.5*geom.arcseconds 

97 

98 

99def createPatch( 

100 tractId=1, patchId=(2, 3), # Tract and patch identifier, for dataId 

101 dims=DIMS, # Patch dimensions (Extent2I) 

102 xy0=geom.Point2I(1234, 5678), # Patch xy0 (Point2I) 

103 center=CENTER, # ICRS sky position of center (lsst.afw.geom.SpherePoint) 

104 scale=SCALE # Pixel scale (Angle) 

105): 

106 crpix = geom.Point2D(xy0) + geom.Extent2D(dims)*0.5 

107 cdMatrix = afwGeom.makeCdMatrix(scale=scale) 

108 wcs = afwGeom.makeSkyWcs(crpix=crpix, crval=center, cdMatrix=cdMatrix) 

109 patch = DummyPatch(xy0, dims) 

110 tract = DummyTract(patchId, patch, wcs) 

111 skymap = DummySkyMap(tractId, tract) 

112 dataRef = DummyDataRef({'tract': tractId, 'patch': ",".join(map(str, patchId))}, deepCoadd_skyMap=skymap) 

113 return dataRef 

114 

115 

116def createImage( 

117 dataId={"name": "foobar"}, # Data identifier 

118 center=CENTER, # ICRS sky position of center (lsst.afw.geom.SpherePoint) 

119 rotateAxis=ROTATEAXIS, # Rotation axis (lsst.afw.geom.SpherePoint) 

120 rotateAngle=0*geom.degrees, # Rotation angle/distance to move (Angle) 

121 dims=DIMS, # Image dimensions (Extent2I) 

122 scale=SCALE # Pixel scale (Angle) 

123): 

124 crpix = geom.Point2D(geom.Extent2D(dims)*0.5) 

125 center = center.rotated(rotateAxis, rotateAngle) 

126 cdMatrix = afwGeom.makeCdMatrix(scale=scale) 

127 wcs = afwGeom.makeSkyWcs(crpix=crpix, crval=center, cdMatrix=cdMatrix) 

128 return SelectStruct(DummyDataRef(dataId), wcs, geom.Box2I(geom.Point2I(0, 0), 

129 geom.Extent2I(dims[0], dims[1]))) 

130 

131 

132class WcsSelectImagesTestCase(unittest.TestCase): 

133 

134 def check(self, patchRef, selectData, doesOverlap): 

135 config = CoaddBaseTask.ConfigClass() 

136 config.select.retarget(WcsSelectImagesTask) 

137 task = CoaddBaseTask(config=config, name="CoaddBase") 

138 dataRefList = task.selectExposures(patchRef, selectDataList=[selectData]) 

139 numExpected = 1 if doesOverlap else 0 

140 self.assertEqual(len(dataRefList), numExpected) 

141 

142 def testIdentical(self): 

143 self.check(createPatch(), createImage(), True) 

144 

145 def testImageContains(self): 

146 self.check(createPatch(), createImage(scale=2*SCALE), True) 

147 

148 def testImageContained(self): 

149 self.check(createPatch(), createImage(scale=0.5*SCALE), True) 

150 

151 def testDisjoint(self): 

152 self.check(createPatch(), 

153 createImage(center=geom.SpherePoint(0, -90, geom.degrees)), 

154 False) 

155 

156 def testIntersect(self): 

157 self.check(createPatch(), createImage(rotateAngle=0.5*geom.Extent2D(DIMS).computeNorm()*SCALE), 

158 True) 

159 

160 

161class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase): 

162 pass 

163 

164 

165def setup_module(module): 

166 lsst.utils.tests.init() 

167 

168 

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

170 lsst.utils.tests.init() 

171 unittest.main()