-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
ENH: Efficient interpolation on regular grids in arbitrary dimensions #3323
Conversation
Yes, this is a very commonly needed feature, and currently missing. What is needed is an interpolation method that does not make a copy of the data or do any expensive preprocessing, and this seems to fit the bill. However, I suggest at the same time also adding a convenience function The point of The interface probably should mimic |
Which other interpolation methods do you have in mind? Otherwise, |
Changes Unknown when pulling e23aa50 on andreas-h:regulargrid into * on scipy:master*. |
Changes Unknown when pulling e23aa50 on andreas-h:regulargrid into * on scipy:master*. |
@andreas-h: RectBivariateSpline, and any other methods that may be eventually added |
|
||
References | ||
---------- | ||
- Python package *regulargrid* by Johannes Buchner, see https://pypi.python.org/pypi/regulargrid/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RST reference format
.. [1] Python package ...
.. [2] Foo bar. Lorem ipsum.
@pv: Doesn't |RectBivariateSpline| only support the 2d case? All the optional parameters to |RectBivariateSpline| should then be I should be able to do that this weekend. Do you think there's any chance this will make it into 0.14? |
Yes, it's 2D only (as I noted above). It needs to be documented and an error raised for other dimensions. The optional parameters shouldn't be available in |
We can try to get this (and |
Currently in the nearest neighbor implementation, I'm using |
Changes Unknown when pulling a68a922 on andreas-h:regulargrid into * on scipy:master*. |
Changes Unknown when pulling 8fbf99b on andreas-h:regulargrid into * on scipy:master*. |
@pv Do you think it's a good idea to add |
if method not in ["linear", "nearest", "splinef2d"]: | ||
raise ValueError("interpn only understands the methods 'linear', " | ||
"'nearest', and 'splinef2d'. You provided " | ||
"{}".format(method)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not valid in Python 2.6 which we still support. Better use the %
string formatting.
Not sure about bounds_error and fill_value. |
The only problem would be extrapolation, which wouldn't be supported for |
I don't see problems with that. |
Changes Unknown when pulling e5918ef on andreas-h:regulargrid into * on scipy:master*. |
Re nearest neighbor implementation ( |
I think we want here nearest-neighbor semantics, ie. voronoi cells. I.e. 0.5 seems fine to me. |
one further question is about the kwarg What do you think? |
I'd go with |
grid = tuple([np.asarray(p) for p in points]) | ||
|
||
# sanity check requested xi | ||
xi = np.atleast_2d(xi) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not fully understand your point """griddata
expects xi
to be of shape (M, D)
. My intention was to allow 1D xi
of shape (D, )
as well""". You mean you want to evaluate at a single point?
However, I think uniform interface with griddata is of high priority here. The xi
parameter has exactly the same meaning, so it should behave the same way.
The problem with atleast_2d is that it does not broadcast. If you want to evaluate it on a grid, you need to do a meshgrid+ravel dance on the user side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other option is to add an "expected dimension" argument to _ndim_coords_from_arrays
, and transpose 1D the array if >1D is expected.
Can be done if it doesn't cause some inputs to be ambiguous. (It probably doesn't cause ambiguity.)
I think this is almost ready now, and should make it to 0.14.0. |
Some missing stuff is added in: pv/scipy-work@andreas-h:regulargrid...pr-3323
|
Looks great! I wanted to add the lower-dim Do I need to do anything with this PR or do you do the necessary git magic before merging? |
I hope I can still write an example for |
@andreas-h: comments? I'd be ready to merge to 0.14.0 with those changes. |
Ok, I'll merge this and any remaining enhancements can then be made later. |
ENH: interpolate: add interpn and RegularGridInterpolator Implemented a new class RegularGridInterpolator for efficient linear and nearest-neighbour interpolation on regular (possibly unevenly spaced) grids in arbitrary dimensions. The existing ND-interpolators perform a triangulation of the input points with becomes unfeasible with medium (~8) dimensions. There, by taking advantage of the regular grid structure, the interpolation can be sped up quite a bit. Another advantage of this class is that it accepts anthing that can be appropriately indexed as values parameter, meaning that it is possible to use this interpolation object for interpolation of disk-based data sets (netCDF, pytables, ...). This PR also adds a simpler function `interpn` for regular grid data interpolation.
Thanks, merged in a90dc28 |
Based on Johannes Buchner's regulargrid package (see https://github.com/JohannesBuchner/regulargrid), I implemented a new class
RegularGridInterpolator
for efficient linear and nearest-neighbour interpolation on regular (possibly unevenly spaced) grids in arbitrary dimensions.I believe this is a significant addition to the
scipy.interpolate
package because the existing ND-interpolators perform a triangulation of the input points with becomes unfeasible with medium (~8) dimensions. There, by taking advantage of the regular grid structure, the interpolation can be sped up quite a bit.Another advantage of this class is that it accepts anthing that can be appropriately indexed as values parameter, meaning that it is possible to use this interpolation object for interpolation of disk-based data sets (netCDF, pytables, ...).
I asked for permission about inclusion in Scipy; the (positive) answer is here: JohannesBuchner/regulargrid#2.