A KDTree is a tree indexed by N-D position in space. If I have an item with coordinate [1,2,3] and another item with coordinate [1.0001,2,3], then a KDTree would return this nearest neighbor in a single O(logN) operation. I have an algorithmic approach where I would like to sort the whole set of items in ..
For example, suppose I have created a kdtree from the points in a 2-d array. Then I run a nearest neighbor query on some point (represented as a pair of x-y coordinates) asking for the 8 nearest neighbors to that point. This returns two lists: (1) a list of 8 distances to neighbors of the ..
I am using scipy.cKDTree.query(data, n_jobs=2) in conjunction with export OMP_NUM_THREADS=2, on a machine with 2 threads per core. I would have expected there to be 200% CPU usage when the script is running, however, only 100% seems to be running. I wondered what could be the cause? This is the simple shell script (script.sh): #!/bin/sh ..
I would like to implement a restricted nearest neighbor search for each point in a data matrix X. Specifically, I would like to find the nearest neighbor of X[i,:] among the rows of X[mask_i,:], where mask_i is a logical mask depending on X[i,:]. Below is a brute force way of accomplishing this task, using the ..
I’m trying to measure the shortest euclidean distance of each point to the nearest group of points. Using below, I have 6 unique points displayed in x,y at two separate time points. I have a separate xy point recorded in x_ref, y_ref, which I pass a radius around. So for each point outside this radius, ..
I have got a list of nodes which are the collection of 3D coorinates. I’m using the following code to find the nearest coordinates based on a specific distance. nodes = translations.tolist() for i in range(len(nodes)): node = nodes[i] ix_list = kdtree.query_ball_point(node, DISTANCE) The above code results in duplication of the indices because ix_list also ..
I am trying to create a kd-tree through scipy’s KD_tree class built by objects rather than pure coordinates. The objects has a (x,y) tuple, and the tree is based upon this, but i would like to include the object itself as the node/in the node. Is there some "easy" approach to this? Had a look ..
I have a pandas dataframe of the form: benchmark_x benchmark_y ref_point_x ref_point_y 0 525039.140 175445.518 525039.145 175445.539 1 525039.022 175445.542 525039.032 175445.568 2 525038.944 175445.558 525038.954 175445.588 3 525038.855 175445.576 525038.859 175445.576 4 525038.797 175445.587 525038.794 175445.559 5 525038.689 175445.609 525038.679 175445.551 6 525038.551 175445.637 525038.544 175445.577 7 525038.473 175445.653 525038.459 175445.594 8 525038.385 175445.670 ..
I’m currently using Python’s scipy.spatial.kdtree to perform nearest neighbor lookups between two large sets of earth science data. One is a collection of storm reports that have a specific lat/lon attached; the other is 1×1 km gridded data containing land use data for half of the United States. I’ve performed kd-tree operations on similar datasets ..
I’m trying to find a closest triangle plane to a point using cKDTree query. I already know to find a closest neighbor to the point. Example: from scipy.spatial import cKDTree import numpy as np p1 = np.array([0, 0, 0]) p2 = np.array([[100, 100, 100], [670, 500, 890], [666, 456, 765]]) tuple_dist_neighbor = cKDTree(p2).query(p1) print(tuple_dist_neighbor) # ..