Skip to content

Commit 2f7c921

Browse files
authored
Use KDTree instead of cKDTree (#339)
Require scipy>= 1.6.0
1 parent c9dcf59 commit 2f7c921

6 files changed

Lines changed: 12 additions & 13 deletions

File tree

pyntcloud/filters/kdtree.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self, *, pyntcloud, kdtree_id, k, r):
5757
self.r = r
5858

5959
def compute(self):
60-
distances = self.kdtree.query(self.points, k=self.k, n_jobs=-1)[0]
60+
distances = self.kdtree.query(self.points, k=self.k, workers=-1)[0]
6161
ror_filter = np.all(distances < self.r, axis=1)
6262

6363
return ror_filter
@@ -96,7 +96,7 @@ def __init__(self, *, pyntcloud, kdtree_id, k, z_max):
9696
self.z_max = z_max
9797

9898
def compute(self):
99-
distances = self.kdtree.query(self.points, k=self.k, n_jobs=-1)[0]
99+
distances = self.kdtree.query(self.points, k=self.k, workers=-1)[0]
100100
z_distances = zscore(np.mean(distances, axis=1), ddof=1)
101101
sor_filter = abs(z_distances) < self.z_max
102102

pyntcloud/neighbors/k_neighbors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ def k_neighbors(kdtree, k):
1717
"""
1818
# [1] to select indices and ignore distances
1919
# [:,1:] to discard self-neighbor
20-
return kdtree.query(kdtree.data, k=k + 1, n_jobs=-1)[1][:, 1:]
20+
return kdtree.query(kdtree.data, k=k + 1, workers=-1)[1][:, 1:]

pyntcloud/structures/kdtree.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from scipy.spatial import cKDTree
1+
from scipy.spatial import KDTree as sKDTree
22

33
from .base import Structure
44

55

6-
class KDTree(cKDTree, Structure):
6+
class KDTree(sKDTree, Structure):
77

88
def __init__(self, *, points, leafsize=16, compact_nodes=False, balanced_tree=False):
99
Structure.__init__(self, points=points)
@@ -13,8 +13,7 @@ def __init__(self, *, points, leafsize=16, compact_nodes=False, balanced_tree=Fa
1313

1414
def compute(self):
1515
self.id = "K({},{},{})".format(self._leafsize, self._compact_nodes, self._balanced_tree)
16-
cKDTree.__init__(
17-
self,
16+
super(sKDTree, self).__init__(
1817
self._points,
1918
leafsize=self._leafsize,
2019
compact_nodes=self._compact_nodes,

pyntcloud/structures/voxelgrid.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22

3-
from scipy.spatial import cKDTree
3+
from scipy.spatial import KDTree
44

55
from .base import Structure
66
from ..plot.voxelgrid import plot_voxelgrid
@@ -202,8 +202,8 @@ def get_feature_vector(self, mode="binary"):
202202

203203
elif mode == "TDF":
204204
# truncation = np.linalg.norm(self.shape)
205-
kdt = cKDTree(self._points)
206-
vector, i = kdt.query(self.voxel_centers, n_jobs=-1)
205+
kdt = KDTree(self._points)
206+
vector, i = kdt.query(self.voxel_centers, workers=-1)
207207

208208
elif mode.endswith("_max"):
209209
if not is_numba_avaliable:

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
numpy
2-
scipy
2+
scipy>=1.6.0
33
pandas
44
laspy
55
lazrs

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
python_requires='>3.7',
2121
install_requires=[
2222
"numpy",
23-
"scipy",
23+
"scipy>=1.6.0",
2424
"pandas",
2525
],
2626
extras_require={
27-
'LAS': ["laspy", "lazrs"],
27+
'LAS': ["laspy", "lazrs"],
2828
'PLOT': ["ipython", "matplotlib", "pyvista>=0.32.0"],
2929
'NUMBA': ["numba"]
3030
},

0 commit comments

Comments
 (0)