astropy-healpix icon indicating copy to clipboard operation
astropy-healpix copied to clipboard

Support arrays for nside

Open cdeil opened this issue 6 years ago • 5 comments

One of the issues trying to switch Gammapy over to using astropy-healpix is that we call ang2pix with an array of nside values: https://gist.github.com/cdeil/754b76dc7f22511a5504fbbe74dccd62#file-gistfile1-txt-L989

Minimum test case that works with healpy

>>> import healpy as hp
>>> hp.ang2pix(nside=[2, 4], theta=[0, 0], phi=[0, 0])
array([0, 0])

but doesn't work with astropy_healpix.healpy (casting to numpy arrays is missing):

>>> from astropy_healpix import healpy as hp
>>> hp.ang2pix(nside=[2, 4], theta=[0, 0], phi=[0, 0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/deil/code/astropy-healpix/astropy_healpix/healpy.py", line 105, in ang2pix
    return lonlat_to_healpix(lon, lat, nside, order='nested' if nest else 'ring')
  File "/Users/deil/code/astropy-healpix/astropy_healpix/core.py", line 341, in lonlat_to_healpix
    nside = int(nside)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

and also support for array-valued nside is missing:

>>> hp.ang2pix(nside=np.array([2, 4]), theta=np.array([0, 0]), phi=np.array([0, 0]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/deil/code/astropy-healpix/astropy_healpix/healpy.py", line 105, in ang2pix
    return lonlat_to_healpix(lon, lat, nside, order='nested' if nest else 'ring')
  File "/Users/deil/code/astropy-healpix/astropy_healpix/core.py", line 341, in lonlat_to_healpix
    nside = int(nside)
TypeError: only length-1 arrays can be converted to Python scalars

I didn't look yet how much work it would be to make this work for ang2pix or possibly also similar other functions, I'm just going through and see what's missing for Gammapy today.

cdeil avatar Oct 17 '17 07:10 cdeil