New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
griddata with multiple data values #13306
Comments
Have you looked at Matplotlib's triangular grid functionality (https://matplotlib.org/3.3.3/api/tri_api.html)? You can create a single
The Delaunay triangulation is calculated once (when creating the |
You can already do it by using LinearNDInterpolator /
NearestNDInterpolator / CloughTocher2DInterpolator (for which griddata
is a convenience wrapper) with a pre-constructed triangulation.
https://docs.scipy.org/doc/scipy-1.5.4/reference/generated/scipy.interpolate.CloughTocher2DInterpolator.html#scipy.interpolate.CloughTocher2DInterpolator
|
Thanks for the input. I do know that it is possible to achieve this with various methods - preferably using the scipy „backend“. |
Yes, it's true griddata should accept a triangulation as "points". It should also be handle multiple datapoints if they are stacked to an array of size |
I’ll give it a closer look. Guess the tag should be scipy.interpolate? |
If you are aiming to use griddata(points,values, method=linear') for interpolating different values from same points to same grid, and want to # here points is original x,y; z1,z2 are z1 = f1(x,y); z2 = f2(x,y)
# and we want to interpolate z1_new, z2_new on grid (lons, lats)
# first stack two types of data, z1, z2, both 2-D array
stack_array = np.vstack((z1.flatten(),z2.flatten())).T
ip = LinearNDInterpolator(points, stack_array)
valuesi = ip((lons, lats))
z1_new=valuesi[...,0]
z2_new=valuesi[...,1] why we can do this, let's look at the source code in interpnd.pyx class LinearNDInterpolator(NDInterpolatorBase):
...
def _do_evaluate(self, const double[:,::1] xi, double_or_complex dummy):
...
# here nvalues is stack_array.shape[1], just means two different values
# to calculate z1_new and z2_new, the isimplex and c(the weights of Linear barycentric interpolation) only once for every grid point.
for j in range(ndim+1):
for k in range(nvalues):
m = simplices[isimplex,j]
out[i,k] = out[i,k] + c[j] * values[m,k]
return out |
I am aiming to use PS: I have tried updating the values of an existing instance of |
This seems to work for
Updating the values sounds similar to what was done for the RGI: #17230 |
Thanks! |
I have created a PR which solves my problem, which includes some basic tests and doesn't break the existing API. |
The refactor of gh-18376 makes it easier to deal with changing |
Hi,
Especially in engineering, griddata is very helpful to move data from one spatial representation to another. Often, this is done with large datasets and thus is time consuming. Also often, the spatial information is the same for many datasets. Thus, a great speedup would be easily achieved when allowing griddata to accept multiple datas at once.
As far as I understand, the heavy lifting is the complex hull and weights calculation, which could be reused easily. An example I found is doing that by unrolling griddata, loosing some performance and a lot of convenience (https://stackoverflow.com/questions/20915502/speedup-scipy-griddata-for-multiple-interpolations-between-two-irregular-grids)
Any plans in this direction?
best
The text was updated successfully, but these errors were encountered: