4 import matplotlib.pyplot
as plt
5 from mpl_toolkits.basemap
import Basemap
9 print "GET ARGS: ", locals()
13 if tmp[i]
is not None and i !=
'fn':
16 alist[i] = int(tmp[i])
19 print "ALIST : ", alist
21 plt.figure(figsize=(15,12))
24 grbu=grbs.select(typeOfLevel=
'isobaricInhPa', shortName=
'u', level=lev)[0] 25 grbv=grbs.select(typeOfLevel='isobaricInhPa', shortName=
'v', level=lev)[0]
26 clevs=np.arange(30,120,5)
28 grbu=grbs.select(typeOfLevel=
'heightAboveGround', shortName=
'10u', level=lev)[0]
29 grbv=grbs.select(typeOfLevel=
'heightAboveGround', shortName=
'10v', level=lev)[0]
30 clevs=np.arange(5,35,1)
34 atime=grbu.analDate.strftime(
'Analysis: %Y%m%d %H UTC')
35 altime=grbu.analDate.strftime(
'%Y%m%d%H')
36 vtime=grbu.validDate.strftime(
'Valid: %Y%m%d %H UTC')
37 date=os.getenv(
'START_TIME')
40 lat,lon = grbu.latlons()
41 data=np.sqrt(datau**2+datav**2)
43 if grid ==
'glob' or grid ==
'G3':
44 m =Basemap(projection=
'cyl',lat_ts=10,llcrnrlon=lon.min(), \
45 urcrnrlon=lon.max(),llcrnrlat=lat.min(),urcrnrlat=lat.max(), \
47 elif grid ==
'nh_mill':
48 m =Basemap(projection=
'mill',lat_ts=10,llcrnrlon=lon.min(), \
49 urcrnrlon=lon.max(),llcrnrlat=0,urcrnrlat=90, \
51 elif grid ==
'sh_mill':
52 m =Basemap(projection=
'mill',lat_ts=10,llcrnrlon=lon.min(), \
53 urcrnrlon=lon.max(),llcrnrlat=-90,urcrnrlat=0, \
55 elif grid ==
'trop_mill':
56 m =Basemap(projection=
'mill',lat_ts=10,llcrnrlon=lon.min(), \
57 urcrnrlon=lon.max(),llcrnrlat=-23,urcrnrlat=23, \
60 m =Basemap(projection=
'npstere',boundinglat=-0.268, \
61 lon_0=-105,resolution=
'c')
63 m =Basemap(projection=
'npstere',boundinglat=-60, \
64 lon_0=105,resolution=
'c')
66 m=Basemap(projection=
'lcc',lat_ts=10,llcrnrlon=226.514, \
67 urcrnrlon=-49.420,llcrnrlat=12.190,urcrnrlat=57.328, \
68 resolution=
'c',lat_1=25,lat_2=25,lon_0=265,rsphere=6371200)
70 lon_w,lon_e,lat_s,lat_n =[-147, -64, 10.8, 89.9]
71 lon_0 = lon_w + (lon_e - lon_w) / 2.
72 ref = lat_s
if abs(lat_s) > abs(lat_n)
else lat_n
73 lat_0 = math.copysign(90., ref)
74 proj =
'npstere' if lat_0 > 0
else 'spstere' 75 prj = Basemap(projection=proj, lon_0=lon_0, lat_0=lat_0,
76 boundinglat=0, resolution=
'c')
77 lons = [lon_w, lon_e, lon_w, lon_e, lon_0, lon_0]
78 lats = [lat_s, lat_s, lat_n, lat_n, lat_s, lat_n]
79 x, y = prj(lons, lats)
80 ll_lon, ll_lat = prj(min(x), min(y), inverse=
True)
81 ur_lon, ur_lat = prj(max(x), max(y), inverse=
True)
82 m=Basemap(projection=
'stere', lat_0=lat_0, lon_0=lon_0,
83 llcrnrlon=ll_lon, llcrnrlat=ll_lat,
84 urcrnrlon=ur_lon, urcrnrlat=ur_lat, resolution=
'c')
94 m.drawlsmask(ocean_color=
'white',land_color=
'white')
97 parallels = np.arange(-90.,90,10.)
98 m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10)
99 meridians = np.arange(0.,360.,20.)
100 m.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10)
103 cs = m.contourf(x,y,data,clevs,cmap=plt.cm.rainbow)
107 if typeOfLevel ==
'isobaricInhPa':
109 elif typeOfLevel ==
'hybrid':
111 elif typeOfLevel ==
'heightAboveGround':
118 maskarray = np.ones(datau.shape)
120 maskarray[1::7,1::14] = 0
122 maskarray[1::3,1::6] = 0
124 maskarray[1::20,1::40] = 0
126 mu = np.ma.masked_array(datau, mask=maskarray)
127 mv = np.ma.masked_array(datav, mask=maskarray)
129 barb_control = dict(height=0.6, width=0.3, emptybarb=0.07)
130 m.barbs(x, y, mu, mv, barbcolor=
'k',pivot=
'middle',sizes=barb_control, linewidth=0.4, length=5)
135 plt.colorbar(cs,orientation=
'horizontal',shrink=0.8)
136 plt.title(
'%s \nFcst Hr: %s' % (atime, fhr) , loc=
'left')
138 plt.title(
'wind magnitude (m s**-1,shaded)', loc =
'right')
139 plt.title(
'%s %s' % (lvl,vert_unit))
140 plt.xlabel(
'%s' % (vtime), fontsize=18, labelpad=40)
143 filename=
''.join([
'wind',
'%s' % (lvl),vert_unit,
'_',grid,
'_',altime,
'_f',fhr,
'.png'])
147 if not os.path.exists(outdir):
150 plt.savefig(
'/'.join([outdir, filename]))
def get_spd_field(fn, lvl, typeOfLevel, outdir, outmap, fhr, var)