Dear Devs,
I have a particular issue with scipy.interpolate for which I would like
to know:
- Is there already a better way to do it which I miss?
- Is there interest to add this functionality to SciPy? or
- Is there interest to extend the functionality of the existing fct?
- None of the above or other ideas/comments?
My example deals with scipy.interpolate.RegularGridInterpolator;
however, it probably is the same for many of the interpolators.
The usage of it in, e.g., 2D is
func = RegularGridInterpolator((x, y), data)
func(pts)
where `x` and `y` define the regular grid on which `data` is defined,
and we interpolate it at `pts`-coordinates. This is ideal if you want to
interpolate the same data for different points again and again.
However, there are other use cases. Imagine you have a coarse grid,
defined by `x`, `y`, and a fine grid, defined by the `pts`-coordinates.
Both grids are regular grids, but not equidistant. Now we want to
interpolate a changing `data` from the coarse grid to the fine grid. The
current implementation is not good for that, as you have to create a new
RegularGridInterpolator-instance for each new data-set, which involves
the calculation of the indices and weights every time, even though they
remain the same. So in this case, the implementation should instead look
like:
func = RegularGridInterpolator((x, y), pts)
func(data)
hence, `pts` and `data` interchanged. In this way, the required indices
and weights can all be calculated during the initiation, which will
significantly speed-up the interpolation. And `func` can subsequently be
called relatively cheaply in, for instance, a loop which changes the
data every time, but not the coordinates.
This behaviour can be obtained by simply moving things between the
`__init__` and `__call__` functions in `RegularGridInterpolator`, which
could probably be done as a switch triggered by a new parameter.
Any thoughts?
Dieter