I have my own triangulation algorithm that creates a triangulation based on both Delaunay's condition and the gradient such that the triangles align with the gradient.
The above description is not relevant to the question but is necessary for the context.
Now I want to use my triangulation with scipy.interpolate.LinearNDInterpolator
to do an interpolation.
With scipy's Delaunay I would do the following
import numpy as np
import scipy.interpolate
import scipy.spatial
points = np.random.rand(100, 2)
values = np.random.rand(100)
delaunay = scipy.spatial.Delaunay(points)
ip = scipy.interpolate.LinearNDInterpolator(delaunay, values)
This delaunay
object has delaunay.points
and delaunay.simplices
that form the triangulation. I have the exact same information with my own triangulation, but scipy.interpolate.LinearNDInterpolator
requires a scipy.spatial.Delaunay
object.
I think I would need to subclass scipy.spatial.Delaunay
and implement the relevant methods. However, I don't know which ones I need in order to get there.
I wanted to do this very same thing with the Delaunay triangulation offered by the
triangle
package. The triangle Delaunay code is about eight times faster than the SciPy one on large (~100_000) points. (I encourage other developers to try to beat that :) )Unfortunately, the
Scipy LinearNDInterpolator
function relies heavily on specific attributes present in the SciPy Delaunay triangulation object. These are created by the_get_delaunay_info()
CPython code, which is difficult to disassemble. Even knowing which attributes are needed (there seem to be many, including things likeparaboloid_scale
andparaboloid_shift
), I'm not sure how I would extract this from a different triangulation library.Instead, I tried @Patol75's approach (comment to the Question above), but using
LinearTriInterpolator
instead of the Cubic one. The code runs correctly, but is slower than doing the entire thing in SciPy. Interpolating 400_000 points from a cloud of 400_000 points takes about 3 times longer using the matplotlib code than scipy. The Matplotlib tri code is written in C++, so converting the code to i.e. CuPy is not straightforward. If we could mix the two approaches, we could reduce the total time from 3.65 sec / 10.2 sec to 1.1 seconds!