问题描述
我有的目录,我想在我的 MCMC code。什么是关键的是执行的速度,以避免拖慢我马尔可夫链蒙特卡罗抽样。
问题:
在目录中,我在第一和第二列两个参数名为 RA
和十二月
这是的天空坐标的:
I have a catalogue of data and I want to use it in my MCMC code. What is crucial is the speed of implementation, in order to avoid slowing down my Markov chain monte carlo sampling.The problem:In the catalogue, I have in the first and second column two parameters called ra
and dec
which are sky coordinates:
data=np.loadtxt('Final.Cluster.Shear.NegligibleShotNoise.Redshift.cat')
ra=data[:,0]
dec=data[:,1]
然后在七,八列 X
和是
位置,即网格坐标,它们在点网格空间
then in the seven and eight columns X
and Y
positions, i.e. the grid coordinates, they are points in a grid space
Xpos=data[:,6]
Ypos=data[:,7]
在我写了,它是需要被称为像一百万时间的功能,
我举一个 X中心值
和 Ycenter
位置(例如X中心值= 200.6,Ycenter = 310.9)作为函数的输入我想找到在 RA
和月
列中的对应点。然而,它可能发生的输入没有在 RA
和月
任何真正的信件。所以,我想要做的插值万一有用于 X没有类似条目和是
和 RA
和月
目录中的数据,并获得基于真实插值坐标 RA
和月
条目在目录中。
In the function that I have written and it is needed to be called like a million time,I will give one Xcenter
and Ycenter
positions (for example Xcenter=200.6, Ycenter=310.9) as inputs to the function and I want to find the correspondence points in the ra
and dec
columns. However it might happen that the inputs do not have any real correspondence in the ra
and dec
. So I want to do an interpolation in case there is no similar entries for X
and Y
and ra
and dec
data in the catalogue and obtain the interpolated coordinates based on real ra
and dec
entries in the catalogue.
推荐答案
这是一个完美的情况下 scipy.spatial.cKDTree()
类可用于查询各点一次:
This is a perfect case where the scipy.spatial.cKDTree()
class can be used to query all the points at once:
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
给出三个最近点的指数。您可以使用这些指标让你的 RA
和月
值非常有效地使用 np.take ()
:
where [ 2662, 22789, 5932]
are the indices corresponding to the three closest points given in xyCenters
. You can use these indices to get your ra
and dec
values very efficiently using np.take()
:
dists, indices = k.query(xyCenters)
myra = np.take(ra, indices)
mydec = np.take(dec, indices)
这篇关于查找数据的对应从一个数据组中的其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!