2

Using RectBivariateSpline to interpolate over a 2D image (raw data illustrated below), if smoothing is 0, I get an interpolation, but if I set smoothing to a non-zero value, even 0.001, the result contains only nan values. My "image" is a 1000x800 grid of numbers from 0~14.

from scipy import interpolate
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

x=np.arange(img.shape[1])
y=np.arange(img.shape[0])
X, Y = np.meshgrid(x,y)
fig=plt.figure(1)
for smooth in [0,.001,.01,.1]:
    plt.clf()
    plt.cla()
    ax=fig.add_subplot(111,projection='3d')
    bvspl=interpolate.RectBivariateSpline(x,y,np.transpose(img),s=smooth)
    print(np.min(bvspl(x,y)),np.max(bvspl(x,y)))
    ax.plot_surface(X,Y,np.transpose(bvspl(x,y)))
    fig.savefig(path+str(smooth)+'_3d.png')

The result of the print statement is: -2.15105711021e-15 14.3944312333 nan nan nan nan nan nan

plot of surface

ali_m
  • 71,714
  • 23
  • 223
  • 298
user3450049
  • 825
  • 1
  • 10
  • 20
  • Similar to [Bivariate structured interpolation of large array with NaN values or mask](http://stackoverflow.com/questions/15485343/bivariate-structured-interpolation-of-large-array-with-nan-values-or-mask). – Mogsdad May 11 '16 at 18:11

1 Answers1

2

In my case, I simply set all the missing values to -9999 before interpolating. After interpolation, I set all the negative values to missing values again - yes I will lose the information on the boundary, but that's what I can do so far. I am looking for another fast and accurate solution as well.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275