Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've had a similar problem using the scipy.interpolate.interp2d function. My understanding is that the issue arises because the interp1d/interp2d and related functions use an older wrapping of FITPACK for the underlying calculations. I was able to get a problem similar to yours to work using the spline functions, which rely on a newer wrapping of FITPACK. The spline functions can be identified because they seem to all have capital letters in their names here <a href="http://docs.scipy.org/doc/scipy/reference/interpolate.html" rel="nofollow">http://docs.scipy.org/doc/scipy/reference/interpolate.html</a>. Within the scipy installation, these newer functions appear to be located in scipy/interpolate/fitpack2.py, while the functions using the older wrappings are in fitpack.py. </p> <p>For your purposes, RectBivariateSpline is what I believe you want. Here is some sample code for implementing RectBivariateSpline:</p> <pre><code>import numpy as np from scipy import interpolate # Generate unevenly spaced x/y data for axes npoints = 25 maxaxis = 100 x = (np.random.rand(npoints)*maxaxis) - maxaxis/2. y = (np.random.rand(npoints)*maxaxis) - maxaxis/2. xsort = np.sort(x) ysort = np.sort(y) # Generate the z-data, which first requires converting # x/y data into grids xg, yg = np.meshgrid(xsort,ysort) z = xg**2 - yg**2 # Generate the interpolated, evenly spaced data # Note that the min/max of x/y isn't necessarily 0 and 100 since # randomly chosen points were used. If we want to avoid extrapolation, # the explicit min/max must be found interppoints = 100 xinterp = np.linspace(xsort[0],xsort[-1],interppoints) yinterp = np.linspace(ysort[0],ysort[-1],interppoints) # Generate the kernel that will be used for interpolation # Note that the default version uses three coefficients for # interpolation (i.e. parabolic, a*x**2 + b*x +c). Higher order # interpolation can be used by setting kx and ky to larger # integers, i.e. interpolate.RectBivariateSpline(xsort,ysort,z,kx=5,ky=5) kernel = interpolate.RectBivariateSpline(xsort,ysort,z) # Now calculate the linear, interpolated data zinterp = kernel(xinterp, yinterp) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload