I have a set of non-gridded points and a grid with holes in it - represented by an array with NaN's in it (a masked array?). I am trying to "map" the non-gridded points onto this grid and then interpolate across the grid, with the NaN areas serving as boundaries.
griddata interpolates this data okay, but ignores the NaN values, and values on one side of a NaN "wall" affect values on the other side. (I hope this makes sense).
Does anyone know if there is any way to force griddata to take NaN's as boundaries and not allow points on one side of an NaN area from affecting the other?
So far I can get this:
Left plot is griddata carried out on a nonmasked array, the right plot is griddata carried out on a masked array. I was hoping to not see the interpolation carry across the masked areas.
This is a simplified example, and my masked array is in fact a bit more complicated (there is a set of blank islands or "holes" in the mesh/array), so cannot really treat sections in isolation (as would be a solution in this example).
This is what I have so far:
X = np.asarray(cfdx[1:])
Y = np.asarray(cfdy[1:])
Z = np.asarray(errors)
xi = np.linspace(X.min(),X.max(),100)
yi = np.linspace(Y.min(),Y.max(),100)
xii = xi
yii = yi
zii = griddata((X, Y), Z, (xii[None,:], yii[:,None]), method='cubic')
fig = plt.figure(figsize=plt.figaspect(0.5))
ax = fig.add_subplot(121)
CS = plt.contourf(xii,yii,zii,15)
xi[45:50] = np.NaN
yi[45:50] = np.NaN
zi = griddata((X, Y), Z, (xi[None,:], yi[:,None]), method='cubic')
ax2 = fig.add_subplot(122)
CS2 = plt.contourf(xi,yi,zi,15)
plt.show()
Any help would be greatly appreciated!
FP