|
8 | 8 | # this script reads the file generated by grdlandmask, plots it,
|
9 | 9 | # and saves it in the format that Basemap._readlsmask expects.
|
10 | 10 |
|
11 |
| -# WARNING: This tends to use excessive amounts of RAM. Do not attempt to run |
12 |
| -# this unless you're on a machine with >=32GB of RAM (yes, 32 Gigabytes). |
| 11 | +UTILS_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 12 | +OUTPUT_DIR = os.path.join(UTILS_DIR, '..', 'lib', 'mpl_toolkits', |
| 13 | + 'basemap', 'data') |
13 | 14 |
|
14 | 15 | # run grdlandmask
|
15 | 16 | athresh={}
|
|
19 | 20 | athresh['h']=10
|
20 | 21 | athresh['f']=1
|
21 | 22 |
|
22 |
| -for resolution in ['c']:#,'l','i']: |
| 23 | +for resolution in ['c','l','i','f']: |
23 | 24 | for grid in [1.25,2.5,5,10]:
|
24 | 25 |
|
25 | 26 | filename = 'grdlandmask%smin_%s.nc' % (grid,resolution)
|
|
31 | 32 |
|
32 | 33 | # read in data.
|
33 | 34 | nc = Dataset(filename)
|
34 |
| - print nc.variables.keys() |
35 |
| - lons = nc.variables['lon'][:] |
36 |
| - nlons = len(lons) |
37 |
| - lats = nc.variables['lat'][:] |
38 |
| - nlats = len(lats) |
39 | 35 | lsmask = nc.variables['z'][:].astype(np.uint8)
|
40 | 36 |
|
41 |
| - # plot |
42 |
| - fig = plt.figure() |
43 |
| - m =\ |
44 |
| - Basemap(llcrnrlon=-180,llcrnrlat=-90,urcrnrlon=180,urcrnrlat=90,resolution=resolution,projection='mill') |
45 |
| - m.drawcoastlines() # coastlines should line up with land/sea mask. |
46 |
| - m.drawlsmask(land_color='coral',ocean_color='aqua',lsmask=lsmask,lsmask_lons=lons,lsmask_lats=lats,lakes=True) |
47 |
| - plt.title('%s by %s land-sea mask (resolution = %s) from grdlandmask' %\ |
48 |
| - (nlons,nlats,resolution)) |
49 |
| - |
50 | 37 | # write out.
|
51 |
| - f = gzip.open('lsmask_%smin_%s.bin' % (grid,resolution),'wb') |
52 |
| - print lsmask.dtype, lsmask.shape |
| 38 | + filename = os.path.join(OUTPUT_DIR, |
| 39 | + 'lsmask_%smin_%s.bin' % (grid, resolution)) |
| 40 | + f = gzip.open(filename, 'wb') |
53 | 41 | f.write(lsmask.tostring())
|
54 | 42 | f.close()
|
55 | 43 |
|
| 44 | +# Plot data for debugging purposes. |
| 45 | +for resolution in ['c','l','i','f']: |
| 46 | + grid = 10 |
| 47 | + filename = 'grdlandmask%smin_%s.nc' % (grid,resolution) |
| 48 | + |
| 49 | + nc = Dataset(filename) |
| 50 | + lsmask = nc.variables['z'][:].astype(np.uint8) |
| 51 | + lons = nc.variables['lon'][:] |
| 52 | + lats = nc.variables['lat'][:] |
| 53 | + |
| 54 | + fig = plt.figure() |
| 55 | + m = Basemap(llcrnrlon=-180, llcrnrlat=-90, |
| 56 | + urcrnrlon=180, urcrnrlat=90, |
| 57 | + resolution=resolution, projection='mill') |
| 58 | + |
| 59 | + m.drawcoastlines() # coastlines should line up with land/sea mask. |
| 60 | + m.drawlsmask(land_color='coral', ocean_color='aqua', |
| 61 | + lsmask=lsmask, lsmask_lons=lons, lsmask_lats=lats, |
| 62 | + lakes=True) |
| 63 | + plt.title('Land-sea mask (res = %s) from grdlandmask' % resolution) |
| 64 | + |
56 | 65 | plt.show()
|
0 commit comments