LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+f5613e8b4f,g1470d8bcf6+190ad2ba91,g14a832a312+311607e4ab,g2079a07aa2+86d27d4dc4,g2305ad1205+a8e3196225,g295015adf3+b67ee847e5,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+a761f810f3,g487adcacf7+17c8fdbcbd,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+65b5bd823e,g5a732f18d5+53520f316c,g64a986408d+f5613e8b4f,g6c1bc301e9+51106c2951,g858d7b2824+f5613e8b4f,g8a8a8dda67+585e252eca,g99cad8db69+6729933424,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+ef4e3a5875,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e9bba80f27,gc120e1dc64+eee469a5e5,gc28159a63d+0e5473021a,gcf0d15dbbd+a761f810f3,gdaeeff99f8+f9a426f77a,ge6526c86ff+d4c1d4bfef,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf1cff7945b+f5613e8b4f,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Properties | List of all members
lsst.sphgeom._healpixPixelization.HealpixPixelization Class Reference
Inheritance diagram for lsst.sphgeom._healpixPixelization.HealpixPixelization:
lsst.sphgeom.pixelization_abc.PixelizationABC

Public Member Functions

 __init__ (self, int level)
 
 nside (self)
 
 getLevel (self)
 
RangeSet universe (self)
 
Region pixel (self, i)
 
int index (self, UnitVector3d v)
 
str toString (self, int i)
 
 envelope (self, Region region, int maxRanges=0)
 
 interior (self, Region region, int maxRanges=0)
 
 __eq__ (self, other)
 
 __repr__ (self)
 
 __reduce__ (self)
 

Static Public Attributes

int MAX_LEVEL = 17
 

Protected Member Functions

 _interior_pixels_from_region (self, int nside, Region region)
 

Protected Attributes

 _level
 
 _nside
 
 _npix
 
 _bit_shift
 
 _nside_highres
 

Properties

 level = property(getLevel)
 

Detailed Description

HEALPix pixelization class.

Parameters
----------
level : `int`
    Pixelization level.  HEALPix nside = 2**level

Definition at line 36 of file _healpixPixelization.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.sphgeom._healpixPixelization.HealpixPixelization.__init__ ( self,
int level )

Definition at line 47 of file _healpixPixelization.py.

47 def __init__(self, level: int):
48 if level < 0:
49 raise ValueError("HealPix level must be >= 0.")
50
51 self._level = level
52 self._nside = 2**level
53
54 self._npix = hpg.nside_to_npixel(self._nside)
55
56 # Values used to do pixel/region intersections
57 self._bit_shift = 8
58 self._nside_highres = self._nside * (2 ** (self._bit_shift // 2))
59

Member Function Documentation

◆ __eq__()

lsst.sphgeom._healpixPixelization.HealpixPixelization.__eq__ ( self,
other )

Definition at line 171 of file _healpixPixelization.py.

171 def __eq__(self, other):
172 if isinstance(other, HealpixPixelization):
173 return self._level == other._level
174

◆ __reduce__()

lsst.sphgeom._healpixPixelization.HealpixPixelization.__reduce__ ( self)

Definition at line 178 of file _healpixPixelization.py.

178 def __reduce__(self):
179 return (self.__class__, (self._level,))

◆ __repr__()

lsst.sphgeom._healpixPixelization.HealpixPixelization.__repr__ ( self)

Definition at line 175 of file _healpixPixelization.py.

175 def __repr__(self):
176 return f"HealpixPixelization({self._level})"
177

◆ _interior_pixels_from_region()

lsst.sphgeom._healpixPixelization.HealpixPixelization._interior_pixels_from_region ( self,
int nside,
Region region )
protected
Get interior pixels from a region.

Parameters
----------
nside : `int`
    Healpix nside to retrieve interior pixels.
region : `lsst.sphgeom.Region`
    Sphgeom region to find interior pixels.

Returns
-------
pixels : `np.ndarray`
    Array of pixels at resolution nside, nest ordering.

Definition at line 116 of file _healpixPixelization.py.

116 def _interior_pixels_from_region(self, nside: int, region: Region):
117 """Get interior pixels from a region.
118
119 Parameters
120 ----------
121 nside : `int`
122 Healpix nside to retrieve interior pixels.
123 region : `lsst.sphgeom.Region`
124 Sphgeom region to find interior pixels.
125
126 Returns
127 -------
128 pixels : `np.ndarray`
129 Array of pixels at resolution nside, nest ordering.
130 """
131 if isinstance(region, Circle):
132 center = LonLat(region.getCenter())
133 pixels = hpg.query_circle(
134 nside,
135 center.getLon().asRadians(),
136 center.getLat().asRadians(),
137 region.getOpeningAngle().asRadians(),
138 degrees=False,
139 )
140 elif isinstance(region, ConvexPolygon):
141 vertices = np.array([[v.x(), v.y(), v.z()] for v in region.getVertices()])
142 pixels = hpg.query_polygon_vec(nside, vertices)
143 elif isinstance(region, Box):
144 pixels = hpg.query_box(
145 nside,
146 region.getLon().getA().asRadians(),
147 region.getLon().getB().asRadians(),
148 region.getLat().getA().asRadians(),
149 region.getLat().getB().asRadians(),
150 degrees=False,
151 )
152 elif isinstance(region, Ellipse):
153 # hpgeom supports query_ellipse given center, alpha, beta,
154 # and orientation. However, until we figure out how to get
155 # the orientation out of the Ellipse region, we will use the
156 # bounding circle as was done with healpy.
157 _circle = region.getBoundingCircle()
158 center = LonLat(_circle.getCenter())
159 pixels = hpg.query_circle(
160 nside,
161 center.getLon().asRadians(),
162 center.getLat().asRadians(),
163 _circle.getOpeningAngle().asRadians(),
164 degrees=False,
165 )
166 else:
167 raise ValueError("Invalid region.")
168
169 return pixels
170

◆ envelope()

lsst.sphgeom._healpixPixelization.HealpixPixelization.envelope ( self,
Region region,
int maxRanges = 0 )
Return the indexes of the pixels intersecting the spherical region.

The ``maxRanges`` parameter can be used to limit both these costs -
setting it to a non-zero value sets a cap on the number of ranges
returned by this method. To meet this constraint, implementations are
allowed to return pixels that do not intersect the region along with
those, that do.
This allows two ranges [a, b) and [c, d), a < b < c < d, to be
merged into one range [a, d) (by adding in the pixels [b, c)). Since
simplification proceeds by adding pixels, the return value will always
be a superset of the intersecting pixels.

Parameters
----------
region : `lsst.sphgeom.Region`
maxRanges : `int`

Returns
-------
rangeSet : `lsst.sphgeom.RangeSet`

Reimplemented from lsst.sphgeom.pixelization_abc.PixelizationABC.

Definition at line 84 of file _healpixPixelization.py.

84 def envelope(self, region: Region, maxRanges: int = 0):
85 if maxRanges > 0:
86 # If this is important, the rangeset can be consolidated.
87 raise NotImplementedError("HealpixPixelization: maxRanges not implemented")
88 pixels_highres = self._interior_pixels_from_region(self._nside_highres, region)
89
90 # Dilate the high resolution pixels by one to ensure that the full
91 # region is completely covered at high resolution.
92 neighbors = hpg.neighbors(self._nside_highres, pixels_highres)
93 # Shift back to the original resolution and uniquify
94 pixels = np.unique(np.right_shift(neighbors.ravel(), self._bit_shift))
95
96 return RangeSet(pixels)
97

◆ getLevel()

lsst.sphgeom._healpixPixelization.HealpixPixelization.getLevel ( self)

Definition at line 64 of file _healpixPixelization.py.

64 def getLevel(self):
65 return self._level
66

◆ index()

int lsst.sphgeom._healpixPixelization.HealpixPixelization.index ( self,
UnitVector3d v )
Compute the index of the pixel.

Parameters
----------
v : `lsst.sphgeom.UnitVector3d`

Returns
-------
i : `int`
    The index of the pixel.

Reimplemented from lsst.sphgeom.pixelization_abc.PixelizationABC.

Definition at line 78 of file _healpixPixelization.py.

78 def index(self, v: UnitVector3d) -> int:
79 return hpg.vector_to_pixel(self._nside, v.x(), v.y(), v.z())
80

◆ interior()

lsst.sphgeom._healpixPixelization.HealpixPixelization.interior ( self,
Region region,
int maxRanges = 0 )
Return the indexes of the pixels within the spherical region.

The ``maxRanges`` argument is analogous to the identically named
envelope() argument. The only difference is that implementations must
remove interior pixels to keep the number of ranges at or below the
maximum. The return value is therefore always a subset of the interior
pixels.

Parameters
----------
region : `lsst.sphgeom.Region`
maxRanges : `int`

Returns
-------
rangeSet : `lsst.sphgeom.RangeSet`

Reimplemented from lsst.sphgeom.pixelization_abc.PixelizationABC.

Definition at line 98 of file _healpixPixelization.py.

98 def interior(self, region: Region, maxRanges: int = 0):
99 if maxRanges > 0:
100 # If this is important, the rangeset can be consolidated.
101 raise NotImplementedError("HealpixPixelization: maxRanges not implemented")
102 pixels = self._interior_pixels_from_region(self._nside, region)
103
104 # Check that the corners of the pixels are entirely enclosed in
105 # the region
106
107 # Returns arrays [npixels, ncorners], where ncorners is 4.
108 corners_lon, corners_lat = hpg.boundaries(self._nside, pixels, step=1, degrees=False)
109
110 corners_int = region.contains(corners_lon.ravel(), corners_lat.ravel()).reshape((len(pixels), 4))
111 interior = np.sum(corners_int, axis=1) == 4
112 pixels = pixels[interior]
113
114 return RangeSet(pixels)
115

◆ nside()

lsst.sphgeom._healpixPixelization.HealpixPixelization.nside ( self)

Definition at line 61 of file _healpixPixelization.py.

61 def nside(self):
62 return self._nside
63

◆ pixel()

Region lsst.sphgeom._healpixPixelization.HealpixPixelization.pixel ( self,
i )
Return the spherical region corresponding to the pixel index ``i``.

This region will contain all unit vectors v with ``index(v) == i``.
But it may also contain points with index not equal to ``i``.
To see why, consider a point that lies on the edge of a polygonal
pixel - it is inside the polygons for both pixels sharing the edge,
but must be assigned to exactly one pixel by the pixelization.

Parameters
----------
i : `int`
    Pixel index.

Returns
-------
region : `lsst.sphgeom.Region`
    The spherical region corresponding to the pixel with index ``i``

Raises
------
`InvalidArgumentException`
    Raised if ``i`` is not a valid pixel index.

Reimplemented from lsst.sphgeom.pixelization_abc.PixelizationABC.

Definition at line 72 of file _healpixPixelization.py.

72 def pixel(self, i) -> Region:
73 # This is arbitrarily returning 4 points on a side
74 # to approximate the pixel shape.
75 varr = hpg.angle_to_vector(*hpg.boundaries(self._nside, i, step=4))
76 return ConvexPolygon([UnitVector3d(*c) for c in varr])
77
table::PointKey< int > pixel

◆ toString()

str lsst.sphgeom._healpixPixelization.HealpixPixelization.toString ( self,
int i )
Convert the given pixel index to a human-readable string.

Parameters
----------
i : `int`

Returns
-------
s : `str`

Reimplemented from lsst.sphgeom.pixelization_abc.PixelizationABC.

Definition at line 81 of file _healpixPixelization.py.

81 def toString(self, i: int) -> str:
82 return str(i)
83

◆ universe()

RangeSet lsst.sphgeom._healpixPixelization.HealpixPixelization.universe ( self)
Return the set of all pixel indexes for this pixelization.

Returns
-------
rangeSet : `lsst.sphgeom.RangeSet`

Reimplemented from lsst.sphgeom.pixelization_abc.PixelizationABC.

Definition at line 69 of file _healpixPixelization.py.

69 def universe(self) -> RangeSet:
70 return RangeSet(0, self._npix)
71

Member Data Documentation

◆ _bit_shift

lsst.sphgeom._healpixPixelization.HealpixPixelization._bit_shift
protected

Definition at line 57 of file _healpixPixelization.py.

◆ _level

lsst.sphgeom._healpixPixelization.HealpixPixelization._level
protected

Definition at line 51 of file _healpixPixelization.py.

◆ _npix

lsst.sphgeom._healpixPixelization.HealpixPixelization._npix
protected

Definition at line 54 of file _healpixPixelization.py.

◆ _nside

lsst.sphgeom._healpixPixelization.HealpixPixelization._nside
protected

Definition at line 52 of file _healpixPixelization.py.

◆ _nside_highres

lsst.sphgeom._healpixPixelization.HealpixPixelization._nside_highres
protected

Definition at line 58 of file _healpixPixelization.py.

◆ MAX_LEVEL

int lsst.sphgeom._healpixPixelization.HealpixPixelization.MAX_LEVEL = 17
static

Definition at line 45 of file _healpixPixelization.py.

Property Documentation

◆ level

lsst.sphgeom._healpixPixelization.HealpixPixelization.level = property(getLevel)
static

Definition at line 67 of file _healpixPixelization.py.


The documentation for this class was generated from the following file: