2011-09-17 18:23:21 -07:00
|
|
|
import scipy.spatial
|
2011-03-21 15:55:45 -07:00
|
|
|
|
2011-09-17 18:23:21 -07:00
|
|
|
from interp.grid import grid as basegrid
|
2011-03-22 13:20:25 -07:00
|
|
|
|
2011-03-21 15:55:45 -07:00
|
|
|
|
2011-09-17 18:23:21 -07:00
|
|
|
def get_simplex_extra_points(X, points, triangulation, kdtree, extra_points=8):
|
|
|
|
simplex_id = triangulation.find_simplex(X)
|
|
|
|
simplex_verts_ids = set(triangulation.vertices[simplex_id])
|
2011-03-21 15:55:45 -07:00
|
|
|
|
2011-09-17 18:23:21 -07:00
|
|
|
distances, kdt_ids = kdtree.query(X, extra_points + len(simplex_verts_ids))
|
|
|
|
kdt_ids = set(kdt_ids)
|
2011-03-21 15:55:45 -07:00
|
|
|
|
2011-09-17 18:23:21 -07:00
|
|
|
simplex_ids = list(simplex_verts_ids)
|
|
|
|
extra_points_ids = list(kdt_ids - simplex_verts_ids)
|
2011-03-21 15:55:45 -07:00
|
|
|
|
2011-09-17 18:23:21 -07:00
|
|
|
return simplex_ids, extra_points_ids
|
2011-03-21 15:55:45 -07:00
|
|
|
|
2011-03-23 10:14:50 -07:00
|
|
|
class dgrid(basegrid):
|
2011-09-17 18:23:21 -07:00
|
|
|
def __init__(self, points, values):
|
|
|
|
self.points = points
|
|
|
|
self.values = values
|
|
|
|
self.triangulation = scipy.spatial.Delaunay(points)
|
|
|
|
self.kdtree = scipy.spatial.KDTree(points)
|
|
|
|
|
|
|
|
def get_simplex_extra_points(self, X, extra_points=8):
|
|
|
|
return get_simplex_extra_points(X, self.points, self.triangulation,
|
|
|
|
self.kdtree, extra_points=extra_points)
|