Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit d88a54c3 authored by Olga Stamati's avatar Olga Stamati
Browse files

test for rankPoints()

parent 0bcb2e05
Pipeline #64599 passed with stages
in 12 minutes and 47 seconds
......@@ -1220,7 +1220,7 @@ def tetVolumes(points, connectivity):
#
# return
def rankPoints(points, neighbourRadius=20):
def rankPoints(points, neighbourRadius=20, verbose=True):
'''
This function ranks an array of points around the top point
......@@ -1246,7 +1246,7 @@ def rankPoints(points, neighbourRadius=20):
-----
Based on https://gricad-gitlab.univ-grenoble-alpes.fr/DVC/pt4d
'''
from scipy.spatial import KDTree
import scipy.spatial
import progressbar
rowNumbers = numpy.zeros((points.shape[0]), dtype=int)
......@@ -1264,13 +1264,14 @@ def rankPoints(points, neighbourRadius=20):
# Create progressbar
numberOfPoints = pointsRanked.shape[0]
widgets = [progressbar.FormatLabel(''), ' ', progressbar.Bar(), ' ', progressbar.AdaptiveETA()]
pbar = progressbar.ProgressBar(widgets=widgets, maxval=numberOfPoints)
pbar.start()
if verbose:
widgets = [progressbar.FormatLabel(''), ' ', progressbar.Bar(), ' ', progressbar.AdaptiveETA()]
pbar = progressbar.ProgressBar(widgets=widgets, maxval=numberOfPoints)
pbar.start()
while points.shape[0] >= 1:
# Try to see how many points can be found around the current point based on the given radius
treeCoord = KDTree(points[:, 0:3])
treeCoord = scipy.spatial.KDTree(points[:, 0:3])
indRadius = numpy.array(treeCoord.query_ball_point(pointsRanked[pR, 0:3], neighbourRadius))
indRadius = indRadius[numpy.argsort(indRadius)]
......@@ -1290,8 +1291,9 @@ def rankPoints(points, neighbourRadius=20):
p += len(indRadius)
pR += 1
widgets[0] = progressbar.FormatLabel("{:.1f}%%".format((p/numberOfPoints)*100))
pbar.update(pR)
if verbose:
widgets[0] = progressbar.FormatLabel("{:.1f}%%".format((p/numberOfPoints)*100))
pbar.update(pR)
return pointsRanked[:,0:3], rowNumbers
......
......@@ -237,5 +237,12 @@ class testAll(unittest.TestCase):
#self.assertTrue(numpy.allclose(vZmean[numpy.isfinite(vZmean)], zPos[numpy.isfinite(vZmean)]*0.1, atol=0.1))
self.assertTrue(numpy.allclose(displ, gridded['displacementField'], atol=0.001))
def test_rankPoints(self):
points, _ = spam.DIC.grid.makeGrid([1, 15, 15], 2)
points = numpy.vstack(([0, 0, 0], points))
rankedPoints, rowNumbers = spam.mesh.rankPoints(points, verbose=True)
self.assertTrue(numpy.allclose(rowNumbers, numpy.arange(points.shape[0])))
self.assertTrue(numpy.allclose(points, rankedPoints))
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment