将拟合文件转换为healpix贴图

时间:2019-12-26 18:40:04

标签: python healpy

我创建了一个拟合文件。它只是一个2D数组,我可以使用plt.imshow(fits.getdata(my_file))对其进行可视化。有没有办法将其转变为healpix地图?如果是,请提供详细答案。如果否,请解释原因。任何帮助表示赞赏!

我知道healpy.fitsfunc.write_map(filename, m),但是我在使用它时遇到了麻烦(无法设置m参数),并且不知道此功能是否对我的任务有帮助

2 个答案:

答案 0 :(得分:0)

hp.write_map函数仅用于将内存中预先存在的healpix映射写入fits文件。

根据您的问题,目前尚不清楚您拥有哪种数据。但是,假设您使用imshow后就拥有二维数据网格。使用hp.write_map之前,需要将其转换为healpix映射。

根据您的坐标系,您需要了解每个网格点的坐标,才能将网格转换为healpix贴图。

要在找到坐标后将某些数据(标量)转换为healpix映射,可以编写一个像这样的函数,该函数获取坐标并为您创建healpix映射。

def make_map_vec(theta, phi, data):
    assert len(theta) == len(phi) == len(data)
    e1map = np.full(hp.nside2npix(NSIDE), hp.UNSEEN, dtype=np.float)
    index = hp.ang2pix(NSIDE, theta, phi)
    values = np.fromiter((np.sum(data[index==i]) for i in np.unique(index)), float, count=len(np.unique(index)))
    e1map[np.unique(index)] = values
    return e1map

This链接为您提供了healpix使用的坐标系。

答案 1 :(得分:0)

我有同样的问题,我想在mollweide投影中绘制一个2d数组。 我的2d数组是180 * 360数组,使用matplotlib.pyplot。 imshow轴不遵循投影: enter image description here

所以要解决此问题,我想使用healpy的mollview,但是我不知道将我的2d数组Data(180 * 360)转换为mollview可以绘制的对象。

在上一个答案中,您假设数据是一维数组,其长度与theta和phi相同。我试图这样做:

test = np.ones((180,360))
data = test.reshape(180*360)
theta = []
phi = []
for i in range (360):
    for j in range (180):
        theta.append((j)*np.pi/180)
        phi.append((i)*np.pi/180)

theta = np.asarray(theta)
phphi = np.asarray(y)

def make_map_vec(theta, phi, data):
    assert len(theta) == len(phi) == len(data)
    e1map = np.full(hp.nside2npix(NSIDE), hp.UNSEEN, dtype=np.float)
    index = hp.ang2pix(NSIDE, theta, phi)
    values = np.fromiter((np.sum(data[index==i]) for i in np.unique(index)), float, count=len(np.unique(index)))
    e1map[np.unique(index)] = values
    return e1map

map_test = make_map_vec(theta,phi,data)
hp.mollview(map_test,title="Mollview image RING")

我得到了:

enter image description here

这是不正确的。

您知道是否还有其他方法可以从2D数组中获取地图吗?