查找数据的对应从一个数据组中的其他 [英] Finding the correspondence of data from one data set in the other

查看:243
本文介绍了查找数据的对应从一个数据组中的其他的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数据的目录,我想在我的 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)

这篇关于查找数据的对应从一个数据组中的其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆