Plotting a numpy array in healpy

孤街醉人 提交于 2019-12-11 12:11:48

问题


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.

I can define a 2D gaussian:

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))

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!


回答1:


here is how I do this:

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.

Here is some example:

#!/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) you feed it some coordinates

2) you retrieve the index corresponding to that coordinate using:

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

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)


来源:https://stackoverflow.com/questions/25539428/plotting-a-numpy-array-in-healpy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!