Отличный вопрос!Я написал короткую функцию для преобразования каталога в карту HEALPix с числом чисел:
from astropy.coordinates import SkyCoord
import healpy as hp
import numpy as np
def cat2hpx(lon, lat, nside, radec=True):
"""
Convert a catalogue to a HEALPix map of number counts per resolution
element.
Parameters
----------
lon, lat : (ndarray, ndarray)
Coordinates of the sources in degree. If radec=True, assume input is in the icrs
coordinate system. Otherwise assume input is glon, glat
nside : int
HEALPix nside of the target map
radec : bool
Switch between R.A./Dec and glon/glat as input coordinate system.
Return
------
hpx_map : ndarray
HEALPix map of the catalogue number counts in Galactic coordinates
"""
npix = hp.nside2npix(nside)
if radec:
eq = SkyCoord(lon, lat, 'icrs', unit='deg')
l, b = eq.galactic.l.value, eq.galactic.b.value
else:
l, b = lon, lat
# conver to theta, phi
theta = np.radians(90. - b)
phi = np.radians(l)
# convert to HEALPix indices
indices = hp.ang2pix(nside, theta, phi)
idx, counts = np.unique(indices, return_counts=True)
# fill the fullsky map
hpx_map = np.zeros(npix, dtype=int)
hpx_map[idx] = counts
return hpx_map
Затем вы можете использовать ее для заполнения карты HEALPix:
l = np.random.uniform(-180, 180, 20000)
b = np.random.uniform(-90, 90, 20000)
hpx_map = hpx.cat2hpx(l, b, nside=32, radec=False)
Здесь,nside
определяет, насколько точной или грубой является ваша пиксельная сетка.
hp.mollview(np.log10(hpx_map+1))
Также обратите внимание, что при равномерной выборке в галактической широте вы 'Я предпочитаю точки данных на галактических полюсах.Если вы хотите избежать этого, вы можете уменьшить его с помощью косинуса.
hp.orthview(np.log10(hpx_map+1), rot=[0, 90])
hp.graticule(color='white')