2014-08-28 70 views
1

我有a catalogue of data,我想在我的MCMC代碼中使用它。關鍵是實施的速度,以避免減慢我的馬爾可夫鏈蒙特卡洛採樣。 問題: 在目錄中,我已經在第一和第二列的兩個參數稱爲radec其是天空座標查找另一個數據集中數據的對應關係

data=np.loadtxt('Final.Cluster.Shear.NegligibleShotNoise.Redshift.cat') 
ra=data[:,0] 
dec=data[:,1] 
在七分八列 XY位置

然後,即網格座標,它們是網格空間中的點

Xpos=data[:,6] 
Ypos=data[:,7] 

在函數中我寫了n和它需要被稱爲像百萬時間, 我會給一個XcenterYcenter職位(例如Xcenter = 200.6,Ycenter = 310.9)作爲函數的輸入,我想找到對應點在radec列。但是可能會發生輸入在radec中沒有任何真實對應關係。因此,如果目錄中的XYra和數據沒有類似的條目,並且基於目錄中的實際radec條目獲得插值座標,我想要進行插值。

回答

1

這就是scipy.spatial.cKDTree()類可用於在一次查詢各點一個完美的案例:

from scipy.spatial import cKDTree 

k = cKDTree(data[:, 6:8]) # creating the KDtree using the Xpos and Ypos 

xyCenters = np.array([[200.6, 310.9], 
         [300, 300], 
         [400, 400]]) 
print(k.query(xyCenters)) 
# (array([ 1.59740195, 1.56033234, 0.56352196]), 
# array([ 2662, 22789, 5932])) 

其中[ 2662, 22789, 5932]是對應於xyCenters給出三個最近點的指數。您可以使用這些指標非常有效地得到您的radec值使用np.take()

dists, indices = k.query(xyCenters) 
myra = np.take(ra, indices) 
mydec = np.take(dec, indices) 
+1

完美!它工作得很好! – Dalek 2014-08-28 14:29:59

相關問題