Skip to content

Commit

Permalink
Update utils.healpix module
Browse files Browse the repository at this point in the history
  • Loading branch information
adl1995 committed Jun 6, 2017
1 parent e4c00b9 commit bbb48be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Reference/API
=============

.. automodapi:: hips
.. automodapi:: hips.utils
19 changes: 8 additions & 11 deletions hips/utils/healpix.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
]

import healpy
import numpy as np


def boundaries(nside, pix, step=1, nest=False):
"""Returns an array containing the longitude and latitude.
def boundaries(nside: int, pix: int, nest: bool=False) -> tuple:
"""Returns an array containing the angle (theta and phi) in radians.
This method calls :py:meth:`.healpy.boundaries` and :py:meth:`.healpy.vec2ang`
Parameters
----------
nside : int
Expand All @@ -25,20 +26,16 @@ def boundaries(nside, pix, step=1, nest=False):
Pixel identifier
step : int, optional
Number of elements for each side of the pixel
nest : bool, optional
If True, assume NESTED pixel ordering, otherwise, RING pixel ordering
Returns
-------
longitude, latitude : float, array
Longitude and latitude positions
theta, phi : float, array
Returns the angle (theta and phi) in radians
"""

boundary_coords = healpy.boundaries(nside, pix, nest=nest)
lon, lat = healpy.vec2ang(boundary_coords, lonlat=True)
return [lon, lat]
theta, phi = healpy.vec2ang(np.transpose(boundary_coords))
return theta, phi
9 changes: 5 additions & 4 deletions hips/utils/tests/test_healpix.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
def test_boundaries():
nside = 8
pix = 450
lon = boundaries(nside, pix, nest=True)
lonlat_precomp = [[242.19350089, 270., 226.97382512, 229.39870535],
[-22.6263803, -43.1943471, -19.37793463, -33.05573115]]
theta, phi = boundaries(nside, pix, nest=True)

np.testing.assert_array_almost_equal(lon, lonlat_precomp, decimal=8)
thetaphi_precomp = ([[2.00057176, 2.0943951, 2.19362291, 2.0943951],
[4.61421421, 4.51603944, 4.61421421, 4.71238898]])

np.testing.assert_allclose([theta, phi], thetaphi_precomp)

0 comments on commit bbb48be

Please sign in to comment.