# [SciPy-User] masked griddata() from Cookbook example

denis denis-bz-gg@t-online...
Fri Aug 6 11:07:52 CDT 2010

```While the doc for matplotlib.mlab.griddata clearly says

A masked array is returned if any grid points are outside convex
hull
defined by input data (no extrapolation is done).

it may not be obvious to someone running the example in
http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data
how easily "outside convex hull" can happen.
I'd suggest growing the example a bit along the lines

<code><pre>
nrand = 10
ngrid = 21
hull = 0
exec "\n".join( sys.argv[1:] )  # run this.py nrand= ...
...
x = np.random.uniform(-2, 2, nrand)
y = np.random.uniform(-2, 2, nrand)
if hull:
x = np.r_[ -2, 2, 2, -2, x]  # add 4 corners to griddata all, not
just the convex hull
y = np.r_[ -2, -2, 2, 2, y]
z = f(x,y)
xi = np.linspace(-2,2,ngrid)
yi = np.linspace(-2,2,ngrid)

#...............................................................................
zi = griddata(x,y,z,xi,yi)  # 1d x y z -> 2d zi on meshgrid(xi,yi)

nmask = np.ma.count_masked(zi)
if nmask > 0:
print >>sys.stderr, "warning: griddata: %d masked points in
output" % nmask
np.savetxt( sys.stderr, zi.mask.astype(int), "%d", "" )
...
</pre></code>

Would anyone care to talk this over, before editing the Cookbook
example ?
(Actually I think griddata() should add the 4 corners by itself, but.)

cheers
-- denis
```

More information about the SciPy-User mailing list