I am trying to interpolate a 2D array that contents masked data. I have used some of the SciPy module\'s methods available, including interp2d
, bisplrep/b
i typically follow the approach described by @mseifert, but add the following refinement if i am weary of the interpolation error through the masked areas. that seems to be one of your concerns, @hurrdrought? the idea is to propagate the mask to the interpolated result. a simple example for 1D data is:
def ma_interp(newx,x,y,mask,propagate_mask=True):
newy = np.interp(newx,x[~mask],y[~mask]) # interpolate data
if propagate_mask: # interpolate mask & apply to interpolated data
newmask = mask[:]
newmask[mask] = 1; newmask[~mask] = 0
newmask = np.interp(newx,x,newmask)
newy = np.ma.masked_array(newy, newmask>0.5)
return newy