Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_KDTreeFilter_raises_KeyError_if_id_is_not_valid(pyntcloud_with_kdtree_and_kdtree_id, kdtree_id):
cloud, true_id = pyntcloud_with_kdtree_and_kdtree_id
filter = KDTreeFilter(pyntcloud=cloud, kdtree_id=kdtree_id)
with pytest.raises(KeyError):
filter.extract_info()
"""
def __init__(self, *, pyntcloud, kdtree_id, k, r):
super().__init__(pyntcloud=pyntcloud, kdtree_id=kdtree_id)
self.k = k
self.r = r
def compute(self):
distances = self.kdtree.query(self.points, k=self.k, n_jobs=-1)[0]
print(distances)
ror_filter = np.all(distances < self.r, axis=1)
return ror_filter
class StatisticalOutlierRemovalFilter(KDTreeFilter):
"""Compute a Statistical Outlier Removal filter using the given KDTree.
Parameters
----------
kdtree_id: pyntcloud.structures.KDTree.id
k : int
Number of neighbors that will be used to compute the filter.
z_max: float
The maximum Z score which determines if the point is an outlier.
Notes
-----
> For each point, the mean of the distances between it and its 'k' nearest
neighbors is computed.
> The Z score of those means is computed.
kdtree_id: pyntcloud.structures.KDTree.id
Usually returned from PyntCloud.add_structure("kdtree"):
kdtree_id = my_cloud.add_structure("kdtree")
"""
super().__init__(pyntcloud=pyntcloud)
self.kdtree_id = kdtree_id
def extract_info(self):
self.points = self.pyntcloud.xyz
self.kdtree = self.pyntcloud.structures[self.kdtree_id]
def compute(self):
pass
class RadiusOutlierRemovalFilter(KDTreeFilter):
"""Compute a Radius Outlier Removal filter using the given KDTree.
Parameters
----------
kdtree_id: pyntcloud.structures.KDTree.id
k : int
Number of neighbors that will be used to compute the filter.
r : float
The radius of the sphere with center on each point. The filter
will look for the required number of neighboors inside that sphere.
Notes
-----
> The distances between each point and its 'k' nearest neighbors that
exceed the given 'r' are marked as False.