Changeset 182
- Timestamp:
- Jun 30, 2011, 12:47:42 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MESOSCALE/PLOT/PYTHON/scripts/winds.py
r181 r182 1 1 #!/usr/bin/env python 2 2 3 ### A. Spiga LMD 29/05/20113 ### A. Spiga and A. Colaitis -- LMD -- 30/05/2011 4 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): 5 def winds (namefile,\ 6 nvert,\ 7 proj="cyl",\ 8 back=None,\ 9 target=None, 10 stride=5,\ 11 var='HGT'): 13 12 from netCDF4 import Dataset 14 13 from myplot import getcoord2d,define_proj,makeplotpng,simplinterv,vectorfield,ptitle 15 14 from matplotlib.pyplot import contourf, subplot, figure 15 import numpy as np 16 16 nc = Dataset(namefile) 17 17 [lon2d,lat2d] = getcoord2d(nc) … … 19 19 [u,v] = getwinds(nc) 20 20 nt = len(u[:,0,0,0]) 21 if var not in nc.variables: 22 print "not found in file:",var 23 exit() 24 else: 25 dimension = np.array(nc.variables[var]).ndim 26 if dimension == 3: what_I_plot = nc.variables[var][:,:,:] 27 elif dimension == 4: what_I_plot = nc.variables[var][:,nvert,:,:] 21 28 fig = figure() 22 29 fig.subplots_adjust(wspace = 0.0, hspace = 0.3) … … 27 34 m = define_proj(proj,wlon,wlat,back=back) 28 35 x, y = m(lon2d, lat2d) 29 contourf(x, y, nc.variables['HGT'][0,:,:] / 1000., 30)36 contourf(x, y, what_I_plot[i,:,:], 30) 30 37 vectorfield(u[i,nvert,:,:], v[i,nvert,:,:],\ 31 x, y, stride= 5, csmooth=3,\38 x, y, stride=stride, csmooth=2,\ 32 39 scale=20., factor=300., color='k') 33 40 sub += 1 34 if not target: zeplot = namefile+".winds"+ str(nvert)35 else: zeplot = target+" winds"+str(nvert)41 if not target: zeplot = namefile+".winds"+var+str(nvert) 42 else: zeplot = target+"/winds"+var+str(nvert) 36 43 makeplotpng(zeplot,pad_inches_value=0.35) 37 44 38 def getwinds (nc,charu='Um',charv='Vm'): 45 def getwinds (nc,charu='U',charv='V'): 46 import numpy as np 39 47 u = nc.variables[charu] 40 48 v = nc.variables[charv] 49 if charu == 'U': u = u[:, :, :, 0:len(u[0,0,0,:])-1] 50 if charv == 'V': v = v[:, :, 0:len(v[0,0,:,0])-1, :] 51 #print np.array(u).shape, np.array(v).shape 41 52 return u,v 42 53 43 54 if __name__ == "__main__": 44 55 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])) 56 ### to be replaced by argparse 57 from optparse import OptionParser 58 parser = OptionParser() 59 parser.add_option('-f', action='store', dest='namefile', type="string", default=None, help='name of WRF file [NEEDED]') 60 parser.add_option('-l', action='store', dest='nvert', type="int", default=0, help='subscript for vertical level') 61 parser.add_option('-p', action='store', dest='proj', type="string", default='cyl', help='projection') 62 parser.add_option('-b', action='store', dest='back', type="string", default=None, help='background') 63 parser.add_option('-t', action='store', dest='target', type="string", default=None, help='destination folder') 64 parser.add_option('-s', action='store', dest='stride', type="int", default=5, help='stride vectors') 65 parser.add_option('-v', action='store', dest='var', type="string", default='HGT', help='variable contoured') 66 (opt,args) = parser.parse_args() 67 if opt.namefile is None: 68 print "I want to eat one file at least ! Use winds.py -f name_of_my_file. Or type winds.py -h" 69 exit() 70 print "Options:", opt 71 winds (opt.namefile,opt.nvert,proj=opt.proj,back=opt.back,target=opt.target,stride=opt.stride,var=opt.var)
Note: See TracChangeset
for help on using the changeset viewer.