[SciPy-User] 3D spline interpolation very, very slow - UPDATE -

Uwe Fechner u.fechner at tudelft.nl
Tue Sep 9 16:00:33 EDT 2014


Thank you very much for your detailed response.

Your suggestion is working fine.

My application is a real-time kite simulator, and I need every 50 ms a new wind vector,
depending on the current kite position.

When I launch the simulator I can run the spline_filter, and than do the lookup of the
wind vector fast when the simulator is running.

Only the documentation should be improved.

Best regards:

Uwe Fechner

Am 09.09.2014 um 15:53 schrieb Joe Kington:
> The reason is because `ndimage.map_coordinates` pre-calculates a series of weights on the entire
> input grid to reduce a higher-order interpolation problem to linear interpolation.    This is why
> linear 3D interpolation (`order=1`) takes a fraction of a millisecond while your second-order spline
> interpolation on the same dataset takes several seconds.
>
> It's an optimization for the situation where you're interpolating many (e.g. thousands) of points
> instead of a single point, as your example.  In a nutshell, `map_coordinates` isn't optimized for
> the use-case of interpolating a small number of points.
>
> If you were to compare an interpolation with several thousand points, the timing should be similar.
>
> However, the cost is a one-time cost.  One way to get around it is to pre-calculate the weights
> before-hand using `ndimage.spline_filter` and then pass them in and specify `prefilter=False` to
> `map_coordinates.  Here's a quick modification of your original example:
> https://gist.github.com/joferkington/cc2f4d9a3eb96d837ef1
>
> At any rate, this is something that could certainly be more optimized for a small number of points.
> It currently assumes you're interested in interpolating over most of the input array and does a lot
> of (sometimes unnecessary) legwork to optimize for that use-case.  I'm not going to volunteer, at
> the moment, though :)
>
> (Also, on a side note, it's best to use odd-ordered splines.  Otherwise you won't have a "smooth"
> interpolation.  I'd be willing to bet that your julia example is effectively using `order=3`.
> Regardless, that doesn't have anything to do with speed.)
>
> Hope that helps,
> -Joe
>
> On Tue, Sep 9, 2014 at 5:06 AM, Uwe Fechner <u.fechner at tudelft.nl <mailto:u.fechner at tudelft.nl>> wrote:
>
>     Hello,
>
>     I am trying to do a spline interpolation of a 3D wind field.
>
>     For this I am using the function ndimage.map_coordinates.
>
>     For some reasons this works well if I interpolate in one dimension,
>     but it gets terrible slow if I do this in three dimensions.
>
>     An example program can be found at:
>     https://gist.github.com/anonymous/32c8599466dad30cd551
>
>     Am I doing something wrong?
>
>     I wrote a similar program, using the Julia programming language,
>     at the speed is about 10000 times higher.
>
>     This Julia program can be found at:
>     https://gist.github.com/anonymous/70af96a6916b4906f2b0
>
>     Any ideas how to improve the speed of the Python code are welcome.
>
>     Best regards:
>
>     Uwe Fechner
>
>        ---------------------------------------------
>     Uwe Fechner, M.Sc.
>     Delft University of Technology
>     Faculty of Aerospace Engineering/ Wind Energy
>     Kluyverweg 1,
>     2629 HS Delft, The Netherlands
>     Phone: +31-15-27-88902 <tel:%2B31-15-27-88902>
>
>     _______________________________________________
>     SciPy-User mailing list
>     SciPy-User at scipy.org <mailto:SciPy-User at scipy.org>
>     http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>


-- 
---------------------------------------------
Uwe Fechner, M.Sc.
Delft University of Technology
Faculty of Aerospace Engineering/ Wind Energy
Kluyverweg 1,
2629 HS Delft, The Netherlands
Phone: +31-15-27-88902



More information about the SciPy-User mailing list