I am trying to fit a spline surface to some 2D data using scipy interpolate
from scipy import interpolate
Using
# fit spline to surface
xnew, ynew = np.mgrid[x[0]:x[-1]:100j, y[0]:y[-1]:100j]
tck = interpolate.bisplrep(X, Z, array)
znew = interpolate.bisplev(xnew[:,0], ynew[0,:], tck)
But I'm getting the following warning messages:
C:\Users...\AppData\Local\Continuum\Anaconda3\lib\site-packages\scipy\interpolate_fitpack_impl.py:975: RuntimeWarning: A theoretically impossible result when finding a smoothing spline with fp = s. Probable causes: s too small or badly chosen eps. (abs(fp-s)/s>0.001) kx,ky=3,3 nx,ny=16,18 m=610 fp=18417275715.663498 s=575.071502 warnings.warn(RuntimeWarning(_iermess2[ierm][0] + _mess)) C:\Users...\AppData\Local\Continuum\Anaconda3\lib\site-packages\scipy\interpolate_fitpack_impl.py:975: RuntimeWarning: The required storage space exceeds the available storage space. Probable causes: nxest or nyest too small or s is too small. (fp>s) kx,ky=3,3 nx,ny=20,20 m=610 fp=661.198585 s=575.071502 warnings.warn(RuntimeWarning(_iermess2[ierm][0] + _mess)) C:\Users...\AppData\Local\Continuum\Anaconda3\lib\site-packages\scipy\interpolate_fitpack_impl.py:975: RuntimeWarning: The required storage space exceeds the available storage space. Probable causes: nxest or nyest too small or s is too small. (fp>s) kx,ky=3,3 nx,ny=20,20 m=610 fp=1013.605606 s=575.071502 warnings.warn(RuntimeWarning(_iermess2[ierm][0] + _mess))
And instead of getting something similar to my data:
I'm getting this:
I admit I don't know what the warning messages mean and haven't found anything on the internet.
Seems like your input data contains too few data points? Another issue might be that your x
and y
axes have very different order of magnitude. I don't know if that is a problem for bisplrep
, but other interpolation algorithms do not like that.
I had more success with scipy.interpolate.Rbf
, which also gives a very smooth result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With