You can use griddata , the only problem is that it does not handle edges well. This can be caused, for example, by reflection, depending on how your data is ... Here is an example:
from __future__ import division import numpy import pylab from scipy import interpolate # The signal and lots of noise M, N = 20, 30 # The shape of the data array y, x = numpy.mgrid[0:M+1, 0:N+1] signal = -10 * numpy.cos(x / 50 + y / 10) / (y + 1) noise = numpy.random.normal(size=(M+1, N+1)) z = signal + noise # Some holes in my dataset z[1:2, 0:2] = numpy.nan z[1:2, 9:11] = numpy.nan z[0:1, :12] = numpy.nan z[10:12, 17:19] = numpy.nan zi = numpy.vstack((z[::-1,:],z)) zi = numpy.hstack((zi[:,::-1], zi)) y, x = numpy.mgrid[0:2*(M+1), 0:2*(N+1)] y *= 5 # anisotropic interpolation if needed. zi = interpolate.griddata((y[~numpy.isnan(zi)], x[~numpy.isnan(zi)]), zi[~numpy.isnan(zi)], (y, x), method='cubic') zi = zi[:(M+1),:(N+1)][::-1,::-1] pylab.subplot(1,2,1) pylab.imshow(z, origin='lower') pylab.subplot(1,2,2) pylab.imshow(zi, origin='lower') pylab.show()
If you run out of memory, you can split your data into lines:
def large_griddata(data_x, vals, grid, method='nearest'): x, y = data_x X, Y = grid try: return interpolate.griddata((x,y),vals,(X,Y),method=method) except MemoryError: pass N = (np.min(X)+np.max(X))/2. M = (np.min(Y)+np.max(Y))/2. masks = [(x<N) & (y<M), (x<N) & (y>=M), (x>=N) & (y<M), (x>=N) & (y>=M)] grid_mask = [(X<N) & (Y<M), (X<N) & (Y>=M), (X>=N) & (Y<M), (X>=N) & (Y>=M)] Z = np.zeros_like(X) for i in range(4): Z[grid_mask[i]] = large_griddata((x[masks[i]], y[masks[i]]), vals[masks[i]], (X[grid_mask[i]], Y[grid_mask[i]]), method=method) return Z