Changeset 241 for trunk/MESOSCALE_DEV/PLOT/PYTHON/scripts/winds.py
- Timestamp:
- Jul 23, 2011, 1:38:02 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MESOSCALE_DEV/PLOT/PYTHON/scripts/winds.py
r240 r241 16 16 numplot=2,\ 17 17 var=None,\ 18 colorb= True,\18 colorb="def",\ 19 19 winds=True,\ 20 20 addchar=None,\ … … 28 28 hole=False,\ 29 29 save="gui",\ 30 anomaly=False): 30 anomaly=False,\ 31 var2=None): 31 32 32 33 #################################################################################################################### … … 38 39 from myplot import getcoord2d,define_proj,makeplotres,simplinterv,vectorfield,ptitle,latinterv,getproj,wrfinterv,dumpbdy,\ 39 40 fmtvar,definecolorvec,defcolorb,getprefix,putpoints,calculate_bounds,errormess,definesubplot,\ 40 zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth 41 zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth,nolow 41 42 from mymath import deg,max,min,mean 42 43 from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show … … 45 46 from numpy.core.defchararray import find 46 47 47 # rcParams['backend'] = 'PS'48 #if save == 'eps': rcParams['backend'] = 'PS' 48 49 49 50 ###################### … … 64 65 ### Define plot boundaries 65 66 if proj == "npstere": [wlon,wlat] = latinterv("North_Pole") 66 elif proj == "spstere": [wlon,wlat] = latinterv(" South_Pole")67 elif proj == "spstere": [wlon,wlat] = latinterv("Far_South_Pole") 67 68 elif proj in ["lcc","laea"]: [wlon,wlat] = wrfinterv(lon2d,lat2d) 68 69 else: [wlon,wlat] = simplinterv(lon2d,lat2d) … … 77 78 print nc.variables 78 79 errormess("please set at least winds or var") 80 if anomaly: basename = 'd' + basename 79 81 basename = basename + getstralt(nc,nvert) ## can be moved elsewhere for a more generic routine 80 82 … … 90 92 nplot = 1 91 93 error = False 92 if itstep is None: itstep = int(24./numplot) 94 if itstep is None and numplot > 0: itstep = int(24./numplot) 95 else: itstep = 1 93 96 while error is False: 94 97 … … 109 112 ### If only one local time is requested (numplot < 0) 110 113 elif numplot <= 0: 111 if int(ltst) + numplot != 0: 114 if int(ltst) + numplot != 0: 112 115 itime += 1 113 116 if found_lct is True: break ## because it means LT was found at previous iteration … … 121 124 122 125 #### Contour plot 126 if var2: 127 what_I_contour, error = reducefield( getfield(nc,var2), d4=itime, d3=nvert ) 128 if not error: 129 if typefile in ['mesoapi','meso']: what_I_contour = dumpbdy(what_I_contour,6) 130 zevmin, zevmax = calculate_bounds(what_I_contour) 131 zelevels = np.linspace(zevmin,zevmax,num=20) 132 if var2 == 'HGT': zelevels = np.arange(-10000.,30000.,2000.) 133 contour( x, y, what_I_contour, zelevels, colors='k', linewidths = 0.33 ) #colors='w' )# , alpha=0.5) 134 135 #### Shaded plot 123 136 if var: 124 137 what_I_plot, error = reducefield( getfield(nc,var), d4=itime, d3=nvert ) … … 132 145 if typefile in ['mesoapi','meso']: what_I_plot = dumpbdy(what_I_plot,6) 133 146 zevmin, zevmax = calculate_bounds(what_I_plot,vmin=vmin,vmax=vmax) 134 if colorb i s True: colorb = defcolorb(fvar)135 palette = get_cmap(name=colorb)147 if colorb in ["def","nobar"]: palette = get_cmap(name=defcolorb(fvar)) 148 else: palette = get_cmap(name=colorb) 136 149 if not tile: 137 150 if not hole: what_I_plot = bounds(what_I_plot,zevmin,zevmax) 138 zelevels = np.linspace(zevmin,zevmax) 151 zelevels = np.linspace(zevmin,zevmax) #,num=20) 139 152 contourf( x, y, what_I_plot, zelevels, cmap = palette ) 140 else: 141 pcolor( x, y, what_I_plot, cmap = palette, vmin=zevmin, vmax=zevmax )142 #putpoints(m,fig)143 if var in ['HGT']: pass144 elif colorb:153 else: 154 if hole: what_I_plot = nolow(what_I_plot) 155 pcolor( x, y, what_I_plot, cmap = palette, \ 156 vmin=zevmin, vmax=zevmax ) 157 if colorb != 'nobar' or var == 'HGT': 145 158 ndiv = 10 146 159 colorbar(fraction=0.05,pad=0.1,format=fmtvar(fvar),\ … … 148 161 extend='neither',spacing='proportional') 149 162 # both min max neither 150 163 151 164 ### Vector plot 152 165 if winds: … … 192 205 pad_inches_value = 0.35 193 206 if save == 'png': 194 makeplotres(zeplot,res=100.,pad_inches_value=pad_inches_value ,erase=True) ## a miniature207 makeplotres(zeplot,res=100.,pad_inches_value=pad_inches_value) #,erase=True) ## a miniature 195 208 makeplotres(zeplot,res=200.,pad_inches_value=pad_inches_value,disp=False) 196 209 elif save in ['eps','svg','pdf']: … … 214 227 outtab = ones(zelen) * -999999 215 228 else: 216 print zelen, len(tab)217 229 if zelen != len(tab): 218 230 print "not enough or too much values... setting same values all variables" … … 242 254 parser.add_option('-t', action='store',dest='target', type="string", default=None, help='destination folder') 243 255 parser.add_option('-s', action='store',dest='stride', type="int", default=3, help='stride vectors (def=3)') 244 parser.add_option('-v', action='append',dest='var', type="string", default=None, help='variable co ntoured (append)')256 parser.add_option('-v', action='append',dest='var', type="string", default=None, help='variable color-shaded (append)') 245 257 parser.add_option('-n', action='store',dest='numplot', type="int", default=2, help='number of plots (def=1)(<0: 1 plot of LT -*numplot*)') 246 258 parser.add_option('-i', action='store',dest='interp', type="int", default=None, help='interpolation method (2: press, 3: z-amr, 4:z-als)') 247 parser.add_option('-c', action='store',dest='colorb', type="string", default= True, help='change colormap')259 parser.add_option('-c', action='store',dest='colorb', type="string", default="def", help='change colormap (nobar: no colorbar)') 248 260 parser.add_option('-x', action='store_false',dest='winds', default=True, help='no wind vectors') 249 261 parser.add_option('-m', action='append',dest='vmin', type="float", default=None, help='bounding minimum value (append)') … … 257 269 parser.add_option('-S', action='store',dest='save', type="string", default="gui", help='save mode (png,eps,svg,pdf or gui)(def=gui)') 258 270 parser.add_option('-a', action='store_true',dest='anomaly', default=False, help='compute and plot relative anomaly in %') 271 parser.add_option('-w', action='store',dest='var2', type="string", default=None, help='variable contoured') 259 272 #parser.add_option('-V', action='store', dest='comb', type="float", default=None, help='a defined combination of variables') 260 273 (opt,args) = parser.parse_args() … … 262 275 print "I want to eat one file at least ! Use winds.py -f name_of_my_file. Or type winds.py -h" 263 276 exit() 277 if opt.var is None and opt.anomaly is True: 278 print "Cannot ask to compute anomaly if no variable is set" 279 exit() 264 280 print "Options:", opt 265 281 … … 296 312 if zefields == '' : zefields = listvar 297 313 else : zefields = zefields + "," + listvar 314 if opt.var2 is not None : zefields = zefields + "," + opt.var2 298 315 print zefields 299 316 zefile = api_onelevel ( path_to_input = '', \ … … 327 344 tile=opt.tile,zoom=opt.zoom,display=opt.display,\ 328 345 itstep=opt.itstep,hole=opt.hole,save=opt.save,\ 329 anomaly=opt.anomaly )346 anomaly=opt.anomaly,var2=opt.var2) 330 347 print 'Done: '+name 331 348 system("rm -f to_be_erased")
Note: See TracChangeset
for help on using the changeset viewer.