在healpy中绘制numpy数组

1 投票
1 回答
1161 浏览
提问于 2025-04-18 18:47

我正在尝试在一个healpix地图上生成一个光束,使用的是healpy这个库。首先,我想在一个莫尔维德投影中生成一个二维高斯分布,但我真的不知道从哪里开始。

我可以定义一个二维高斯分布:

import numpy as np
def gaussian_2D(x,y,mu_x=0.,mu_y=0.,sig_x=1.,sig_y=1.):
    return np.exp(-0.5*(((x-mu_x) / sig_x)**2 + ((y-mu_y) / sig_y)**2))

这样我就可以构建一个三维的X、Y、Z空间,比如:

delta = 0.025
x = np.arange(-4, 4, delta)
y = np.arange(-4, 4, delta)
X, Y = np.meshgrid(x,y)
Z = gaussian_2D(X,Y)

但是从这里开始我就有点迷茫了,找不到很多有用的文档来指导我该如何或者应该投影什么。任何建议都会非常感谢!

1 个回答

0

这是我怎么做的:

我用一个小技巧。在想要的高斯中心位置插入一个点,然后用“涂抹”来创建一个带有一定标准差的高斯分布。

这里有个例子:

#!/usr/bin/env python
import numpy as np
import healpy as hp
import pylab as pl

NSIDE=512 #the map garannularity

m_sm=np.arange(hp.nside2npix(NSIDE)) # creates the map
m_sm=m_sm*0. # sets all values to zero

theta=np.radians(80.) # coordinates for the gaussian
phi=np.radians(20.)

indx=hp.pixelfunc.ang2pix(NSIDE,theta,phi) # getting the index of the point corresponding to the coordinates
m_sm[indx]=1. # setting that point value to 1.

gmap=hp.smoothing(m_sm, sigma=np.radians(20.),verbose=False,lmax=1024) # creating a new map, smmeared version of m_sm

hp.mollview(gmap, title="Gaussian Map") #draw it
pl.show()

现在如果你想手动做这个,你需要使用一个高斯函数。

1) 你需要给它一些坐标。

2) 然后你可以用以下方法找到对应那个坐标的索引:

indx=hp.pixelfunc.ang2pix(NSIDE,theta,phi)

3) 最后,你把那个点的值设置为你高斯函数计算出来的值,也就是:

my_healpy_map[indx]=my_gauss(theta, phy, mean_theta, mean_phy, sigma_theta, sigma_phy)

撰写回答