【问题标题】:Make a 2D histogram with HEALPix pixellization using healpy使用 healpy 使用 HEALPix 像素化制作 2D 直方图
【发布时间】:2018-11-02 03:25:31
【问题描述】:

数据是天空中物体的坐标,例如:

import pylab as plt
import numpy as np
l = np.random.uniform(-180, 180, 2000)
b = np.random.uniform(-90, 90, 2000)

我想做一个 2D 直方图,以便在 Mollweide 投影上使用 HEALPIx 像素化绘制天空中具有 (l, b) 坐标的某个点的密度图。我怎样才能使用 healpy 做到这一点?

教程:

http://healpy.readthedocs.io/en/v1.9.0/tutorial.html

说如何绘制一维数组或拟合文件,但我不知道如何使用这种像素化来绘制二维直方图。

我也找到了这个功能,但它不起作用,所以我卡住了。

hp.projaxes.MollweideAxes.hist2d(l, b, bins=10)

我可以通过这种方式在 Mollweide 投影中绘制这些点:

l_axis_name ='Latitude l (deg)'
b_axis_name = 'Longitude b (deg)'

fig = plt.figure(figsize=(12,9))
ax = fig.add_subplot(111, projection="mollweide")
ax.grid(True)

ax.scatter(np.array(l)*np.pi/180., np.array(b)*np.pi/180.)

plt.show()

非常感谢您的帮助。

【问题讨论】:

    标签: python plot astronomy healpy histogram2d


    【解决方案1】:

    好问题!我编写了一个简短的函数来将目录转换为数字计数的 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')
    

    【讨论】:

    • 非常有用,仅供参考 mollview 接受 norm='log' 关键字(尽管您仍然可能在使用 log(0) 时遇到问题,因此您的 hpx_map+1...
    • 很好的答案!类似的东西对地球观测有用吗?我想将来自 MODIS 的卫星数据映射到一个球体上,我认为 Healpix 可能是正确的方法。但是我怎么能从观察中创建一个 healpix 地图呢?
    猜你喜欢
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    • 2021-07-08
    • 2015-10-12
    • 1970-01-01
    • 1970-01-01
    • 2014-08-29
    • 1970-01-01
    相关资源
    最近更新 更多