+----------------------------------------- Jeff Whitaker -----------+

Here's the basic idea:

1) read the germany.dat file, use it to create a _geoslib Poly instance,

i.e.

from mpl_toolkits.basemap import _geoslib

b = np.asarray([lons,lats]).T # lons and lats are lists.

germanypoly = _geoslib.Polygon(b)

2) loop over all the points on the grid and do

inside = _geoslib.Point((lonpt,latpt)).within(germanypoly)

filling a boolean array with the values.

3) use this boolean array as a mask to create a masked array from your

data. Then, when you plot the masked array with contourf only the

points inside germany will be contoured.

Give this a try and let us know how it goes.

-Jeff

because of islands it doesn't work as expected i guess?

here is what i did:

bmap = Basemap(projection='aeqd', ...)

x, y = bmap(lons, lats)

npoints = 300

xi = np.linspace(np.amin(x), np.amax(x), npoints*.7178)

yi = np.linspace(np.amin(y), np.amax(y), npoints)

zi = griddata(x, y, var, xi, yi)

inside = np.zeros_like(zi)

lon, lat = np.loadtxt('germany-lon-lat-np.arr')

bx, by = bmap(lon, lat)

b = np.asarray([bx, by]).T

poly = _geoslib.Polygon(b)

i = 0

# i know this is slow, but ...

for y in yi:

for x in xi:

inside.flat[i] = _geoslib.Point((x,y)).within(poly)

i += 1

mzi = ma.masked_array(zi, mask=inside)

here is what it looks like:

http://rokuko.net/test.png

matlab includes NaNs right before and after islands in the lon

lat lists, is there something similar ?

thank you so far, best regards

PS

http://rokuko.net/germany-lon-lat-np.arr