Finding the correspondence of data from one data set in the other

后端 未结 1 1332
滥情空心
滥情空心 2020-12-10 22:51

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 ch

相关标签:
1条回答
  • 2020-12-10 23:18

    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]))
    

    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)
    
    0 讨论(0)
提交回复
热议问题