Problem statement:
I have 150k points in a 3D space with their coordinates stored in a matrix with dimension [150k, 3] in mm.
I want to find all the neighbors of a given point p
that are within a radius r
. And I want to do that in the most accurate way.
How should I choose my leafsize
parameter ?
from scipy.spatial import KDTree
import numpy as np
pts = np.random.rand(150000,3)
T1 = KDTree(pts, leafsize=20)
T2 = KDTree(pts, leafsize=1)
neighbors1= T1.query_ball_point((0.3,0.2,0.1), r=2.0)
neighbors2= T2.query_ball_point((0.3,0.2,0.1), r=2.0)
np.allclose(sorted(neighbors1), sorted(neighbors2))
True