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

# 

# 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/>. 

# 

 

from lsst.sphgeom import ConvexPolygon 

from lsst.afw.geom import Box2D 

 

__all__ = ["PatchInfo", "makeSkyPolygonFromBBox"] 

 

 

def makeSkyPolygonFromBBox(bbox, wcs): 

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

 

Parameters 

---------- 

bbox : `lsst.afw.geom.Box2I` or `lsst.afw.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. 

""" 

 

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

"""Construct a PatchInfo 

 

@param[in] index: x,y index of patch (a pair of ints) 

@param[in] innerBBox: inner bounding box (an afwGeom.Box2I) 

@param[in] outerBBox: inner bounding box (an afwGeom.Box2I) 

""" 

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) 

""" 

return self._index 

 

def getInnerBBox(self): 

"""Get inner bounding box 

""" 

return self._innerBBox 

 

def getOuterBBox(self): 

"""Get outer bounding box 

""" 

return self._outerBBox 

 

def getInnerSkyPolygon(self, tractWcs): 

"""Get the inner on-sky region as an sphgeom.ConvexPolygon. 

""" 

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

 

def getOuterSkyPolygon(self, tractWcs): 

"""Get the outer on-sky region as a sphgeom.ConvexPolygon. 

""" 

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

 

def __eq__(self, rhs): 

"""Support == 

""" 

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

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

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

 

def __ne__(self, rhs): 

"""Support != 

""" 

return not self.__eq__(rhs) 

 

def __str__(self): 

"""Return a brief string representation 

""" 

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

 

def __repr__(self): 

"""Return a detailed string representation 

""" 

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

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