Changeset 240 for trunk/MESOSCALE_DEV/PLOT/PYTHON/scripts/winds.py
- Timestamp:
- Jul 22, 2011, 9:46:21 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MESOSCALE_DEV/PLOT/PYTHON/scripts/winds.py
r238 r240 26 26 display=True,\ 27 27 itstep=None,\ 28 hole=False): 28 hole=False,\ 29 save="gui",\ 30 anomaly=False): 29 31 30 32 #################################################################################################################### … … 34 36 ### Load librairies and functions 35 37 from netCDF4 import Dataset 36 from myplot import getcoord2d,define_proj,makeplot png,makeplotpngres,simplinterv,vectorfield,ptitle,latinterv,getproj,wrfinterv,dumpbdy,\38 from myplot import getcoord2d,define_proj,makeplotres,simplinterv,vectorfield,ptitle,latinterv,getproj,wrfinterv,dumpbdy,\ 37 39 fmtvar,definecolorvec,defcolorb,getprefix,putpoints,calculate_bounds,errormess,definesubplot,\ 38 zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield 40 zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth 39 41 from mymath import deg,max,min,mean 40 from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor 42 from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show 41 43 from matplotlib.cm import get_cmap 42 44 import numpy as np 43 45 from numpy.core.defchararray import find 44 46 47 #rcParams['backend'] = 'PS' 48 45 49 ###################### 46 50 ### Load NETCDF object 47 nc = Dataset(namefile) 51 nc = Dataset(namefile) 48 52 49 53 ################################## … … 60 64 ### Define plot boundaries 61 65 if proj == "npstere": [wlon,wlat] = latinterv("North_Pole") 66 elif proj == "spstere": [wlon,wlat] = latinterv("South_Pole") 62 67 elif proj in ["lcc","laea"]: [wlon,wlat] = wrfinterv(lon2d,lat2d) 63 68 else: [wlon,wlat] = simplinterv(lon2d,lat2d) … … 119 124 what_I_plot, error = reducefield( getfield(nc,var), d4=itime, d3=nvert ) 120 125 if not error: 121 if typefile in ['mesoapi','meso']: what_I_plot = dumpbdy(what_I_plot) 126 fvar = var 127 ### 128 if anomaly: 129 what_I_plot = 100. * ((what_I_plot / smooth(what_I_plot,10)) - 1.) 130 fvar = 'anomaly' 131 ### 132 if typefile in ['mesoapi','meso']: what_I_plot = dumpbdy(what_I_plot,6) 122 133 zevmin, zevmax = calculate_bounds(what_I_plot,vmin=vmin,vmax=vmax) 123 if colorb is True: colorb = defcolorb( var)134 if colorb is True: colorb = defcolorb(fvar) 124 135 palette = get_cmap(name=colorb) 125 136 if not tile: … … 133 144 elif colorb: 134 145 ndiv = 10 135 colorbar(fraction=0.05,pad=0.1,format=fmtvar( var),\146 colorbar(fraction=0.05,pad=0.1,format=fmtvar(fvar),\ 136 147 ticks=np.linspace(zevmin,zevmax,ndiv+1),\ 137 extend=' max',spacing='proportional')138 # both min max neither 148 extend='neither',spacing='proportional') 149 # both min max neither 139 150 140 151 ### Vector plot … … 144 155 if not error: 145 156 if typefile in ['mesoapi','meso']: 146 [vecx,vecy] = [dumpbdy(vecx, stag=uchar), dumpbdy(vecy,stag=vchar)]157 [vecx,vecy] = [dumpbdy(vecx,6,stag=uchar), dumpbdy(vecy,6,stag=vchar)] 147 158 key = True 148 159 elif typefile in ['gcm']: … … 178 189 else: zeplot = target + "/" + zeplot 179 190 ### 180 if found_lct: makeplotpng(zeplot,pad_inches_value=0.35,disp=display) 181 #if found_lct: makeplotpngres(zeplot,200,disp=display) 191 if found_lct: 192 pad_inches_value = 0.35 193 if save == 'png': 194 makeplotres(zeplot,res=100.,pad_inches_value=pad_inches_value,erase=True) ## a miniature 195 makeplotres(zeplot,res=200.,pad_inches_value=pad_inches_value,disp=False) 196 elif save in ['eps','svg','pdf']: 197 makeplotres(zeplot, pad_inches_value=pad_inches_value,disp=False,ext=save) 198 elif save == 'gui': 199 show() 200 else: 201 print "save mode not supported. using gui instead." 202 show() 182 203 else: print "Local time not found" 183 204 … … 210 231 from netCDF4 import Dataset 211 232 from myplot import getlschar 233 from os import system 212 234 213 235 ############################# … … 233 255 parser.add_option('-e', action='store',dest='itstep', type="int", default=None, help='stride time (def=4)') 234 256 parser.add_option('-H', action='store_true',dest='hole', default=False, help='holes above max and below min') 257 parser.add_option('-S', action='store',dest='save', type="string", default="gui", help='save mode (png,eps,svg,pdf or gui)(def=gui)') 258 parser.add_option('-a', action='store_true',dest='anomaly', default=False, help='compute and plot relative anomaly in %') 235 259 #parser.add_option('-V', action='store', dest='comb', type="float", default=None, help='a defined combination of variables') 236 260 (opt,args) = parser.parse_args() … … 275 299 zefile = api_onelevel ( path_to_input = '', \ 276 300 input_name = zefile, \ 277 #path_to_output = opt.target, \278 301 fields = zefields, \ 279 302 interp_method = opt.interp, \ … … 303 326 addchar=lschar,interv=[zehour,zehourin],vmin=argvmin,vmax=argvmax,\ 304 327 tile=opt.tile,zoom=opt.zoom,display=opt.display,\ 305 itstep=opt.itstep,hole=opt.hole) 328 itstep=opt.itstep,hole=opt.hole,save=opt.save,\ 329 anomaly=opt.anomaly) 306 330 print 'Done: '+name 307 331 system("rm -f to_be_erased") 332 308 333 ######################################################### 309 334 ### Generate a .sh file with the used command saved in it
Note: See TracChangeset
for help on using the changeset viewer.