2016-12-07 45 views
1

假設我有三個數量:theta,phi和v(theta,phi)。我想使用角度分箱,以便我可以插入任何未來的theta & phi以獲得v。我對healpix完全陌生,不理解如何去做這件事。基本上我想要一個theta和phi的網格,然後想要使用scipy.griddata進行插值。謝謝。使用healpy進行角裝倉

+0

有你看了一下[numpy.histogram](https://docs.scipy.org/ doc/numpy/reference/generated/numpy.histogram.html) – DrBwts

回答

0

您可以只使用插值與scipy.interpolate.interp2d,請參閱https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.interp2d.html,甚至不使用healpy

但是,讓我示範如何使用healpy地圖來做到這一點。這個想法是,您爲地圖的每個像素預先計算v(theta,phi),然後在未來thetaphi中找到它們屬於哪個像素,然後使用healpy非常快速地獲得該像素處的地圖值。

見我的筆記本電腦在這裏:https://gist.github.com/zonca/e16fcf42e23e30fb2bc7301482f4683f

我複製下面的代碼以供參考:

import healpy as hp 
import numpy as np 

NSIDE = 64 

print("Angular resolution is {:.2f} arcmin".format(hp.nside2resol(NSIDE, arcmin=True))) 
NPIX = hp.nside2npix(NSIDE) 
print("Number of pixels", NPIX) 
pixel_indices = np.arange(NPIX) 
theta_pix, phi_pix = hp.pix2ang(NSIDE, pixel_indices) 
def v(theta, phi): 
    return theta ** 2 
v_map = v(theta_pix, phi_pix) 
new_theta, new_phi = np.radians(30), np.radians(0) 
new_pix = hp.ang2pix(NSIDE, new_theta, new_phi) 
print("New theta and phi are hitting pixel", new_pix) 
# We find what pixel the new coordinates are hitting and get the precomputed value of V at that pixel, to increase accuracy, you can increase NSIDE of the precomputed map. 
v_map[new_pix] 
v(new_theta, new_phi) 
+0

這非常有幫助,謝謝! – user6769140