1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | ### A. Spiga LMD 29/05/2011 |
---|
4 | |
---|
5 | def usage(): |
---|
6 | print 'USAGE: winds.py nvert file (target)' |
---|
7 | print 'file : name of input netcdf file.' |
---|
8 | print 'nvert : vertical level.' |
---|
9 | print '(target) : a directory with write rights.' |
---|
10 | print 'Example: winds.py 0 /d5/aslmd/LMD_MM_MARS_SIMUS/OM/OM6_TI85/wrfout_d01_2024-06-43_06:00:00_zabg ~/' |
---|
11 | |
---|
12 | def winds (namefile,nvert,proj="cyl",back=None,target=None): |
---|
13 | from netCDF4 import Dataset |
---|
14 | from myplot import getcoord2d,define_proj,makeplotpng,simplinterv,vectorfield,ptitle |
---|
15 | from matplotlib.pyplot import contourf, subplot, figure |
---|
16 | nc = Dataset(namefile) |
---|
17 | [lon2d,lat2d] = getcoord2d(nc) |
---|
18 | [wlon,wlat] = simplinterv(lon2d,lat2d) |
---|
19 | [u,v] = getwinds(nc) |
---|
20 | nt = len(u[:,0,0,0]) |
---|
21 | fig = figure() |
---|
22 | fig.subplots_adjust(wspace = 0.0, hspace = 0.3) |
---|
23 | sub = 221 |
---|
24 | for i in range(0,nt-1,int(nt/4.)): |
---|
25 | subplot(sub) |
---|
26 | ptitle("Winds time"+str(i)+" level"+str(nvert)) |
---|
27 | m = define_proj(proj,wlon,wlat,back=back) |
---|
28 | x, y = m(lon2d, lat2d) |
---|
29 | contourf(x, y, nc.variables['HGT'][0,:,:] / 1000., 30) |
---|
30 | vectorfield(u[i,nvert,:,:], v[i,nvert,:,:],\ |
---|
31 | x, y, stride=5, csmooth=3,\ |
---|
32 | scale=20., factor=300., color='k') |
---|
33 | sub += 1 |
---|
34 | if not target: zeplot = namefile+".winds"+str(nvert) |
---|
35 | else: zeplot = target+"winds"+str(nvert) |
---|
36 | makeplotpng(zeplot,pad_inches_value=0.35) |
---|
37 | |
---|
38 | def getwinds (nc,charu='Um',charv='Vm'): |
---|
39 | u = nc.variables[charu] |
---|
40 | v = nc.variables[charv] |
---|
41 | return u,v |
---|
42 | |
---|
43 | if __name__ == "__main__": |
---|
44 | import sys |
---|
45 | if (len(sys.argv)) == 3: winds( str(sys.argv[2]) , int(sys.argv[1]) ) |
---|
46 | elif (len(sys.argv)) == 4: winds( str(sys.argv[2]) , int(sys.argv[1]) , target=str(sys.argv[3])) |
---|