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

# 

# LSST Data Management System 

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

# 

 

import unittest 

 

import lsst.utils.tests 

import lsst.afw.geom as afwGeom 

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

from lsst.pipe.tasks.coaddBase import CoaddBaseTask 

 

 

class KeyValue: 

 

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

 

def __init__(self, key, value): 

self._key = key 

self._value = value 

 

def __getitem__(self, key): 

40 ↛ 41line 40 didn't jump to line 41, because the condition on line 40 was never true if key != self._key: 

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

return self._value 

 

 

class DummyPatch: 

 

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

 

def __init__(self, xy0, dims): 

self._outerBBox = afwGeom.Box2I(xy0, dims) 

 

def getOuterBBox(self): 

return self._outerBBox 

 

 

class DummyTract(KeyValue): 

 

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

 

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

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

self._wcs = wcs 

 

def getPatchInfo(self, patchId): 

return self[patchId] 

 

def getWcs(self): 

return self._wcs 

 

 

class DummySkyMap(KeyValue): 

 

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

 

def __init__(self, tractId, tract): 

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

 

 

class DummyDataRef: 

 

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

 

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

self.dataId = dataId 

self._data = data 

 

def get(self, dataType): 

return self._data[dataType] 

 

 

# Common defaults for createPatch and createImage 

CENTER = afwGeom.SpherePoint(0, 90, afwGeom.degrees) 

ROTATEAXIS = afwGeom.SpherePoint(0, 0, afwGeom.degrees) 

DIMS = afwGeom.Extent2I(3600, 3600) 

SCALE = 0.5*afwGeom.arcseconds 

 

 

def createPatch( 

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

dims=DIMS, # Patch dimensions (Extent2I) 

xy0=afwGeom.Point2I(1234, 5678), # Patch xy0 (Point2I) 

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

scale=SCALE # Pixel scale (Angle) 

): 

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

cdMatrix = afwGeom.makeCdMatrix(scale=scale) 

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

patch = DummyPatch(xy0, dims) 

tract = DummyTract(patchId, patch, wcs) 

skymap = DummySkyMap(tractId, tract) 

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

return dataRef 

 

 

def createImage( 

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

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

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

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

dims=DIMS, # Image dimensions (Extent2I) 

scale=SCALE # Pixel scale (Angle) 

): 

crpix = afwGeom.Point2D(afwGeom.Extent2D(dims)*0.5) 

center = center.rotated(rotateAxis, rotateAngle) 

cdMatrix = afwGeom.makeCdMatrix(scale=scale) 

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

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

afwGeom.Extent2I(dims[0], dims[1]))) 

 

 

class WcsSelectImagesTestCase(unittest.TestCase): 

 

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

config = CoaddBaseTask.ConfigClass() 

config.select.retarget(WcsSelectImagesTask) 

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

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

numExpected = 1 if doesOverlap else 0 

self.assertEqual(len(dataRefList), numExpected) 

 

def testIdentical(self): 

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

 

def testImageContains(self): 

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

 

def testImageContained(self): 

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

 

def testDisjoint(self): 

self.check(createPatch(), 

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

False) 

 

def testIntersect(self): 

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

True) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()