Skip to content

Commit

Permalink
Use astropy_healpix.level_to_nside instead of (1 << level)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Feb 25, 2019
1 parent 5d3b455 commit 67b1578
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions regions/shapes/moc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ def from_skycoord(cls, skycoord, max_depth, meta=None, visual=None):
The MOC instance.
"""
nside = level_to_nside(max_depth)
hp = HEALPix(nside=(1 << max_depth), order='nested')
hp = HEALPix(nside=nside, order='nested')
ipix = hp.lonlat_to_healpix(skycoord.icrs.ra, skycoord.icrs.dec)

shift = 2 * (MOCSkyRegion.HPY_MAX_DEPTH - max_depth)
Expand Down Expand Up @@ -1136,7 +1136,8 @@ def from_lonlat(cls, lon, lat, max_depth, meta=None, visual=None):
result : `regions.MOCSkyRegion`
The resulting MOC
"""
hp = HEALPix(nside=(1 << max_depth), order='nested')
nside = level_to_nside(max_depth)
hp = HEALPix(nside=nside, order='nested')
ipix = hp.lonlat_to_healpix(lon, lat)

shift = 2 * (MOCSkyRegion.HPY_MAX_DEPTH - max_depth)
Expand Down
5 changes: 4 additions & 1 deletion regions/shapes/moc/plot/culling_backfacing_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from astropy.coordinates import ICRS
from astropy.wcs.utils import skycoord_to_pixel

from astropy_healpix import level_to_nside

def backface_culling(xp, yp):
# Remove cells crossing the MOC after projection
# The remaining HEALPix cells are used for computing the patch of the MOC
Expand Down Expand Up @@ -58,7 +60,8 @@ def from_moc(depth_ipix_d, wcs):

ipix_d = {}
for depth in range(min_depth, max_split_depth + 1):
hp = HEALPix(nside=(1 << depth), order='nested', frame=ICRS())
nside = level_to_nside(depth)
hp = HEALPix(nside=nside, order='nested', frame=ICRS())

ipix_boundaries = hp.boundaries_skycoord(ipixels, step=1)
# Projection on the given WCS
Expand Down
11 changes: 7 additions & 4 deletions regions/shapes/moc/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from astropy.coordinates import ICRS, Galactic
from astropy.coordinates import SkyCoord

from astropy_healpix import HEALPix
from astropy_healpix import HEALPix, \
level_to_nside
from astropy_healpix.core import boundaries_lonlat

try:
Expand Down Expand Up @@ -69,7 +70,7 @@ def to_xyz(lon, lat):
return np.array([x, y, z], dtype=np.float64)

def max_distance_center_to_vertex(depth):
nside = 1 << depth
nside = level_to_nside(depth)

lat1 = np.arcsin(2 / 3.0)
lat2 = np.arcsin(1 - ((1 - 1.0/nside)**2 / 3.0))
Expand Down Expand Up @@ -117,7 +118,8 @@ def max_distance_center_to_vertex(depth):

# Get the ipixels from astropy_healpix covering the cone of (center, radius) = (center, max_d)
lon_center, lat_center = vector.vector_to_lonlat(x=center[0], y=center[1], z=center[2], degrees=False)
hp = HEALPix(nside=(1 << depth), order='nested', frame=ICRS())
nside = level_to_nside(depth)
hp = HEALPix(nside=nside, order='nested', frame=ICRS())
starting_iter_ipix = hp.cone_search_lonlat(lon=lon_center * u.rad, lat=lat_center * u.rad, radius=max_d * u.rad)

return depth, starting_iter_ipix
Expand Down Expand Up @@ -167,7 +169,8 @@ def __init__(self, ra, dec, inside=None, max_depth=10):
## Iterative version of the algorithm: seems a bit faster than the recursive one
for depth in range(start_depth, end_depth + 1):
# Define a HEALPix at the current depth
hp = HEALPix(nside=(1 << depth), order='nested', frame=ICRS())
nside = level_to_nside(depth)
hp = HEALPix(nside=nside, order='nested', frame=ICRS())

# Get the lon and lat of the corners of the pixels
# intersecting the polygon
Expand Down

0 comments on commit 67b1578

Please sign in to comment.