I am testing out scipy.interpolate.RectBivariateSpline for a project where I want to upscale some data to achieve better resolution. My attempt at using both scipy.interpolate.RectBivariateSpline and scipy.interpolate.interp2d results in no interpolation actually happening to the data; I just end up with a bigger matrix filled with more zeros. I have looked at some examples as well, but I am unable to see what I have done differently from them. And i would also expect my orgianal data to be centerd. Any help is appreciated
code
n = 10
smile = np.zeros((n,n))
a = 0.5
smile[2,2] = a
smile[3,2] = a
smile[2,7] = a
smile[3,7] = a
smile[6,2] = a
smile[6,7] = a
smile[7,3:7] = a
plt.imshow(smile)
plt.show()
#RECTBIVARIATESPLINE
#making interpolation function
x = np.arange(n)
y = x
z = smile
interpolation_funk = scipy.interpolate.RectBivariateSpline(x,y,z)
#using interpolation
x_new = np.arange(2*n)
y_new = x_new
Z_new = interpolation_funk(x_new,y_new)
#plotting new funtion
plt.imshow(Z_new)
Note x_new = np.arange(2*n)
: you are evaluating the interpolant outside of the original data range ([0, 9] x [0, 9]
) and you get all zeros for the extrapolation.
Use x_new = np.arange(2*n) / 2
or some such to actually interpolate between the data points.