Changeset 612
- Timestamp:
- Apr 4, 2012, 1:59:05 PM (13 years ago)
- Location:
- trunk/UTIL/PYTHON
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/myplot.py
r610 r612 105 105 106 106 ## Author: AC 107 # Compute the norm of the winds 108 # The corresponding variable to call is UV or uvmet (to use api) 107 109 def windamplitude (nc): 108 110 import numpy as np … … 123 125 zvint=zv 124 126 return np.sqrt(zuint**2 + zvint**2) 127 128 ## Author: AC 129 # Compute the norm of the slope angles 130 # The corresponding variable to call is SLOPEXY 131 def slopeamplitude (nc): 132 import numpy as np 133 varinfile = nc.variables.keys() 134 if "slopex" in varinfile: zu=getfield(nc,'slopex') 135 elif "SLOPEX" in varinfile: zu=getfield(nc,'SLOPEX') 136 if "slopey" in varinfile: zv=getfield(nc,'slopey') 137 elif "SLOPEY" in varinfile: zv=getfield(nc,'SLOPEY') 138 znt,zny,znx = np.array(zu).shape 139 zuint = np.zeros([znt,zny,znx]) 140 zvint = np.zeros([znt,zny,znx]) 141 zuint=zu 142 zvint=zv 143 return np.sqrt(zuint**2 + zvint**2) 144 145 ## Author: AC 146 # Compute the temperature difference between surface and first level. 147 # API is automatically called to get TSURF and TK. 148 # The corresponding variable to call is DELTAT 149 def deltat0t1 (nc): 150 import numpy as np 151 varinfile = nc.variables.keys() 152 if "tsurf" in varinfile: zu=getfield(nc,'tsurf') 153 elif "TSURF" in varinfile: zu=getfield(nc,'TSURF') 154 if "tk" in varinfile: zv=getfield(nc,'tk') 155 elif "TK" in varinfile: zv=getfield(nc,'TK') 156 znt,zny,znx = np.array(zu).shape 157 zuint = np.zeros([znt,zny,znx]) 158 zuint=zu - zv[:,0,:,:] 159 return zuint 125 160 126 161 ## Author: AS + TN + AC … … 814 849 "TPOT": "%.0f",\ 815 850 "TSURF": "%.0f",\ 851 "U_OUT1": "%.0f",\ 852 "T_OUT1": "%.0f",\ 816 853 "def": "%.1e",\ 817 854 "PTOT": "%.0f",\ … … 831 868 "UM": "%.0f",\ 832 869 "WIND": "%.0f",\ 870 "UVMET": "%.0f",\ 871 "UV": "%.0f",\ 833 872 "ALBBARE": "%.2f",\ 834 873 "TAU": "%.1f",\ -
trunk/UTIL/PYTHON/myscript.py
r610 r612 39 39 parser.add_option('--ylabel', action='store',dest='ylab', type="string", default=None, help='customize the y-axis label') 40 40 parser.add_option('--labels', action='store',dest='labels', type="string", default=None, help='customize 1D curve labels. Str comma-separated. [None]') 41 parser.add_option('--lstyle', action='store',dest='linestyle', type="string", default=None, help='customize 1D curve linestyles. String separated by commas. [None]') 41 42 42 43 ### SPECIFIC FOR MAPPING [MAPMODE 1] … … 48 49 parser.add_option('--blat', action='store',dest='blat', type="int", default=None, help='reference lat (or bounding lat for stere) [computed]') 49 50 parser.add_option('--blon', action='store',dest='blon', type="int", default=None, help='reference lon [computed]') 51 parser.add_option('--mark', action='append',dest='mark', type="string", default=None, help='superimpose a crossmark at given coords. lon,lat float separated by commas. [None]') 50 52 51 53 ### SPECIFIC FOR SLICING [MAPMODE 0] -
trunk/UTIL/PYTHON/planetoplot.py
r610 r612 64 64 xlab=None,\ 65 65 ylab=None,\ 66 lbls=None): 66 lbls=None,\ 67 lstyle=None,\ 68 cross=None): 67 69 68 70 #################################################################################################################### … … 75 77 fmtvar,definecolorvec,defcolorb,getprefix,putpoints,calculate_bounds,errormess,definesubplot,\ 76 78 zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth,nolow,\ 77 getname,localtime,check_localtime,polarinterv,getsindex,define_axis,determineplot,readslices,bidimfind,getlschar,hole_bounds,windamplitude 79 getname,localtime,check_localtime,polarinterv,getsindex,define_axis,determineplot,readslices,bidimfind,getlschar,hole_bounds,\ 80 windamplitude,slopeamplitude,deltat0t1 78 81 from mymath import deg,max,min,mean,get_tsat,writeascii,fig2data,fig2img 79 82 import matplotlib as mpl … … 148 151 ### we get the names of variables to be read. in case only one available, we choose this one. 149 152 varname=var[vvv] 150 if ((varname not in nc.variables) and not ((typefile in ['meso']) and (varname in ['UV','uv','uvmet' ]))):153 if ((varname not in nc.variables) and not ((typefile in ['meso']) and (varname in ['UV','uv','uvmet','slopexy','SLOPEXY','deltat','DELTAT']))): 151 154 if len(varinfile) == 1: varname = varinfile[0] 152 155 else: varname = False … … 205 208 ###### principle: calculate correct indices then repopulate slon and slat 206 209 if slon is not None or slat is not None: 207 if firstfile and save == 'png' and typefile == 'meso' and "HGT" in varinfile : iwantawhereplot = nc #show a topo map with a cross on the chosen point210 if firstfile and save == 'png' and typefile == 'meso' and "HGT" in varinfile and display: iwantawhereplot = nc #show a topo map with a cross on the chosen point 208 211 else: iwantawhereplot = None #do not show anything, just select indices 209 212 numlon = 1 ; numlat = 1 … … 278 281 all_namefile[k] = namefile 279 282 all_time[k] = time 280 if var2: all_var2[k] = getfield(nc,var2) 283 if var2: 284 if ((var2 in ['slopexy','SLOPEXY']) and (typefile in ['meso']) and (var2 not in nc.variables)): all_var2[k] = slopeamplitude(nc) 285 else: all_var2[k] = getfield(nc,var2) 281 286 if winds: all_windu[k] = getfield(nc,uchar) ; all_windv[k] = getfield(nc,vchar) 282 287 ##################### … … 293 298 elif ((varname in ['UV','uv','uvmet']) and (typefile in ['meso']) and (varname not in nc.variables)): 294 299 all_var[k]=windamplitude(nc) 300 elif ((varname in ['slopexy','SLOPEXY']) and (typefile in ['meso']) and (varname not in nc.variables)): 301 all_var[k]=slopeamplitude(nc) 302 elif ((varname in ['DELTAT','deltat']) and (typefile in ['meso']) and (varname not in nc.variables)): 303 all_var[k]=deltat0t1(nc) 295 304 else: 296 305 ##### GENERAL STUFF HERE … … 310 319 if ((all_varname[k-1] in ['UV','uv','uvmet']) and (typefile in ['meso']) and (all_varname[k-1] not in ncref.variables)): 311 320 all_var[k] = windamplitude(ncref) 321 elif ((all_varname[k-1] in ['slopexy','SLOPEXY']) and (typefile in ['meso']) and (all_varname[k-1] not in ncref.variables)): 322 all_var[k] = slopeamplitude(ncref) 323 elif ((all_varname[k-1] in ['DELTAT','deltat']) and (typefile in ['meso']) and (all_varname[k-1] not in ncref.variables)): 324 all_var[k]=deltat0t1(ncref) 312 325 else: 313 326 all_var[k] = getfield(ncref,all_varname[k-1]) 314 327 all_varname[k] = all_varname[k-1] ; all_time[k] = all_time[k-1] ; all_namefile[k] = all_namefile[k-1] ; all_var2[k] = all_var2[k-1] 328 if winds: all_windu[k] = getfield(ncref,uchar) ; all_windv[k] = getfield(ncref,vchar) 315 329 else: errormess("fileref is missing!") 316 330 if ope == "-": all_var[k+1]= all_var[k-1] - all_var[k] … … 321 335 all_var[k+1]= 100.*(all_var[k-1] - masked)/masked 322 336 all_varname[k+1] = all_varname[k] ; all_time[k+1] = all_time[k] ; all_namefile[k+1] = all_namefile[k] ; all_var2[k+1] = all_var2[k] ; numplot = numplot+2 337 if winds: all_windu[k+1] = all_windu[k-1]-all_windu[k] ; all_windv[k+1] = all_windv[k-1] - all_windv[k] 323 338 elif ope in ["cat"]: 324 339 tabtime = all_time[0];tab = all_var[0];k = 1 … … 349 364 ### Time loop for plotting device 350 365 nplot = 1 ; error = False 351 linecycler = cycle(["-","--","-.",":"]) 366 if lstyle is not None: linecycler = cycle(lstyle) 367 else: linecycler = cycle(["-","--","-.",":"]) 352 368 print "********************************************" 353 369 while error is False: … … 492 508 493 509 if which == "unidim": 494 lbl = "" 495 if indexlat is not None: lbl = lbl + " ix" + str(indexlat[0]) 496 if indexlon is not None: lbl = lbl + " iy" + str(indexlon[0]) 497 if indexvert is not None: lbl = lbl + " iz" + str(indexvert[0]) 498 if indextime is not None: lbl = lbl + " it" + str(indextime[0]) 499 if lbl == "": lbl = namefiles[index_f] 500 if lbls is not None: lbl=lbls[nplot-1] 510 if lbls is not None: lbl=lbls[index_f] 511 else: 512 lbl = "" 513 if indexlat is not None: lbl = lbl + " ix" + str(indexlat[0]) 514 if indexlon is not None: lbl = lbl + " iy" + str(indexlon[0]) 515 if indexvert is not None: lbl = lbl + " iz" + str(indexvert[0]) 516 if indextime is not None: lbl = lbl + " it" + str(indextime[0]) 517 if lbl == "": lbl = namefiles[index_f] 501 518 502 519 if mrate is not None: x = y ## because swapaxes... … … 523 540 if mapmode == 1: m.contourf( x, y, what_I_plot_frame, zelevels, cmap = palette, alpha=trans) 524 541 elif mapmode == 0: contourf( x, y, what_I_plot_frame, zelevels, cmap = palette, alpha=trans) 542 if cross is not None and mapmode == 1: 543 idx,idy=m(cross[0][0],cross[0][1]) 544 mpl.pyplot.plot([idx],[idy],'+k',mew=0.5,ms=18) 525 545 else: 526 546 if mapmode == 1: m.pcolor( x, y, what_I_plot_frame, cmap = palette, vmin=zevmin, vmax=zevmax, alpha=trans) … … 553 573 zevminc, zevmaxc = calculate_bounds(what_I_plot_frame, vmin=min(what_I_plot_frame), vmax=max(what_I_plot_frame)) 554 574 zelevels = np.linspace(zevminc,zevmaxc,ticks/2) #20) 555 if var2 == 'HGT': zelevels = np.arange(-10000.,30000., 2000.)575 if var2 == 'HGT': zelevels = np.arange(-10000.,30000.,1000.) 556 576 if mapmode == 0: 557 577 what_I_plot_frame, x, y = define_axis( lon,lat,vert,time,indexlon,indexlat,indexvert,\ 558 578 itime,what_I_plot_frame, len(all_var2[index_f].shape),vertmode ) 559 cs = contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 1 ) #0.33 colors='w' )# , alpha=0.5)#, linestyles='solid')560 elif mapmode == 1: cs = m.contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 1 ) #0.33 colors='w' )# , alpha=0.5)#, linestyles='solid')579 cs = contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 0.33, alpha=0.5, linestyles='solid') 580 elif mapmode == 1: cs = m.contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 0.33, alpha=0.5, linestyles='solid') 561 581 if which in ["regular","unidim"]: 562 582 … … 645 665 if zetitle[0] != "fill": zecb.ax.set_xlabel(zetitle[index_f]) ; zetitle[index_f]="" 646 666 647 667 648 668 ########################################################################## 649 669 ### Save the figure in a file in the data folder or an user-defined folder -
trunk/UTIL/PYTHON/pp.py
r610 r612 102 102 ### winds or no winds 103 103 if opt.winds : zefields = 'uvmet' 104 elif opt.var[j] in ['deltat','DELTAT'] : zefields = 'tk,TSURF' 104 105 else : zefields = '' 105 106 ### var or no var … … 170 171 blat=opt.blat,blon=opt.blon,tsat=opt.tsat,flagnolow=opt.nolow,\ 171 172 mrate=opt.rate,mquality=opt.quality,trans=opt.trans,zarea=opt.area,axtime=opt.axtime,\ 172 redope=opt.redope,seevar=opt.seevar,xlab=opt.xlab,ylab=opt.ylab,lbls=separatenames(opt.labels)) 173 redope=opt.redope,seevar=opt.seevar,xlab=opt.xlab,ylab=opt.ylab,lbls=separatenames(opt.labels),\ 174 lstyle=separatenames(opt.linestyle),cross=readslices(opt.mark)) 173 175 print 'DONE: '+name 174 176 system("rm -f to_be_erased")
Note: See TracChangeset
for help on using the changeset viewer.