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

# 

# LSST Data Management System 

# Copyright 2008, 2009, 2010 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/>. 

# 

 

__all__ = ["PatchInfo", "makeSkyPolygonFromBBox"] 

 

from lsst.sphgeom import ConvexPolygon 

from lsst.afw.geom import Box2D 

 

 

def makeSkyPolygonFromBBox(bbox, wcs): 

"""Make an on-sky polygon from a bbox and a SkyWcs 

 

Parameters 

---------- 

bbox : `lsst.geom.Box2I` or `lsst.geom.Box2D` 

Bounding box of region, in pixel coordinates 

wcs : `lsst.afw.geom.SkyWcs` 

Celestial WCS 

 

Returns 

------- 

polygon : `lsst.sphgeom.ConvexPolygon` 

On-sky region 

""" 

pixelPoints = Box2D(bbox).getCorners() 

skyPoints = wcs.pixelToSky(pixelPoints) 

return ConvexPolygon.convexHull([sp.getVector() for sp in skyPoints]) 

 

 

class PatchInfo: 

"""Information about a patch within a tract of a sky map. 

 

See `TractInfo` for more information. 

 

Parameters 

---------- 

index : `tuple` of `int` 

x,y index of patch (a pair of ints) 

innerBBox : `lsst.geom.Box2I` 

inner bounding box 

outerBBox : `lsst.geom.Box2I` 

inner bounding box 

""" 

 

def __init__(self, index, innerBBox, outerBBox): 

self._index = index 

self._innerBBox = innerBBox 

self._outerBBox = outerBBox 

if not outerBBox.contains(innerBBox): 

raise RuntimeError("outerBBox=%s does not contain innerBBox=%s" % (outerBBox, innerBBox)) 

 

def getIndex(self): 

"""Return patch index: a tuple of (x, y) 

 

Returns 

------- 

result : `tuple` of `int` 

Patch index (x, y). 

""" 

return self._index 

 

def getInnerBBox(self): 

"""Get inner bounding box. 

 

Returns 

------- 

bbox : `lsst.geom.Box2I` 

The inner bounding Box. 

""" 

return self._innerBBox 

 

def getOuterBBox(self): 

"""Get outer bounding box. 

 

Returns 

------- 

bbox : `lsst.geom.Box2I` 

The outer bounding Box. 

""" 

return self._outerBBox 

 

def getInnerSkyPolygon(self, tractWcs): 

"""Get the inner on-sky region. 

 

Returns 

------- 

result : `lsst.sphgeom.ConvexPolygon` 

The inner sky region. 

""" 

return makeSkyPolygonFromBBox(bbox=self.getInnerBBox(), wcs=tractWcs) 

 

def getOuterSkyPolygon(self, tractWcs): 

"""Get the outer on-sky region. 

 

Returns 

------- 

result : `lsst.sphgeom.ConvexPolygon` 

The outer sky region. 

""" 

return makeSkyPolygonFromBBox(bbox=self.getOuterBBox(), wcs=tractWcs) 

 

def __eq__(self, rhs): 

return (self.getIndex() == rhs.getIndex()) \ 

and (self.getInnerBBox() == rhs.getInnerBBox()) \ 

and (self.getOuterBBox() == rhs.getOuterBBox()) 

 

def __ne__(self, rhs): 

return not self.__eq__(rhs) 

 

def __str__(self): 

return "PatchInfo(index=%s)" % (self.getIndex(),) 

 

def __repr__(self): 

return "PatchInfo(index=%s, innerBBox=%s, outerBBox=%s)" % \ 

(self.getIndex(), self.getInnerBBox(), self.getOuterBBox())