问题描述
我正在尝试使用 healpy 在healpix地图上产生光束.对于初学者来说,我希望能够以mollweide投影方式产生2D高斯,但我真的不知道从哪里开始.
I am attempting to produce a beam on a healpix map, using healpy. For starters, I would like to be able to produce a 2D gaussian in a mollweide projection, but I really don't know where to begin.
我可以定义2D高斯:
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))
这样我就可以建立3D X,Y,Z空间,例如:
such that I can build up a 3D X, Y, Z space like:
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)
但是从这里我很迷路,无法找到关于如何投影和/或投影什么的很多有用的文档.任何有关攻击方向的建议将不胜感激!
but from here I'm pretty lost, and can't track down much useful documentation concerning how and/or what to project. Any suggestions for a direction of attack would be much appreciated!
推荐答案
这是我的操作方式:
使用一个小技巧.我在所需的高斯中心点上插入一个点,然后使用涂抹"来创建具有某些sigma的高斯.
using a small trick. I insert a point at the desired Gaussian centrer and then I use "smearing" to create a Gaussian with some sigma.
以下是一些示例:
#!/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()
现在,如果您想手动执行此操作,则可以使用高斯函数
now if you want to do that by hand, you would use a function for a gaussian
1)您输入一些坐标
2)使用以下方法检索与该坐标对应的索引:
2) you retrieve the index corresponding to that coordinate using:
indx=hp.pixelfunc.ang2pix(NSIDE,theta,phi)
3)将该点的值设置为高斯函数的值.即:
3) you set the value for that point to the value from your gaussian function. i.e.:
my_healpy_map[indx]=my_gauss(theta, phy, mean_theta, mean_phy, sigma_theta, sigma_phy)
这篇关于在healpy中绘制一个numpy数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!