On 7/23/11 9:32 AM, Yoshi Rokuko wrote: > +----------------------------------------- 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 ?
Yoshi: Islands would be a problem. I was assuming you had one polygon. Can you get rid of the islands so you just have one closed polygon to use for a mask? -Jeff ------------------------------------------------------------------------------ Storage Efficiency Calculator This modeling tool is based on patent-pending intellectual property that has been used successfully in hundreds of IBM storage optimization engage- ments, worldwide. Store less, Store more with what you own, Move data to the right place. Try It Now! http://www.accelacomm.com/jaw/sfnl/114/51427378/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users