- Timestamp:
- Nov 7, 2016, 8:06:40 PM (8 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r1263 r1274 27 27 ## e.g. # python ../drawing.py -f ~/etudes/domains/SIRTA/geo_em.d01.nc,/home/lluis/etudes/domains/SIRTA/geo_em.d02.nc -o draw_topo_geogrid_boxes -S '0.,1500.:None:WRF!domain!centered!at!SIRTA:png:cyl,i:d01$_{15k}$,d02$_{3k}$:0|10:True' 28 28 ## e.g. # drawing.py -f ~/etudes/domains/MEDCORDEX/geo_em.d01.nc -o draw_2D_shad_cont -S 'height,landmask:Time|0:Time|0:XLONG_M:XLAT_M:terrain:fixc,k:None:0.,3000.:0,1,10:MEDCORDEX height & landmask:pdf:False:lcc,i' -v HGT_M,LANDMASK 29 ## e.g. # drawing.py -o draw_2D_shad_line -f 'mean_dtcon-pluc-pres_lat.nc,mean_dtcon-pluc-pres_lat.nc' -S 'dtcon,prc:bottom_top|-1,south_north|-1:latmean:presmean:seismic,k:-5.,5.:monthly|dtcon|&|prc:pdf:flip@y:None:True' -v 'dtconmean,prcmean' 30 ## e.g. # drawing.py -f 'geo_em.d02.nc' -o draw_topo_geogrid -S '0.,3000.:None:FF_3dom d02:png:cyl,i' 31 ## e.g. # drawing.py -o draw_topo_geogrid_boxes -S '0.,3000.:None:FF domains:pdf:lcc,i:d01,d02,d03:0' -f geo_em.d01.nc,geo_em.d02.nc,geo_em.d03.nc 29 ## e.g. # $ drawing.py -f WRF/current/hurs_wrfout_tturb_xmean_last.nc,WRF/micro1/hurs_wrfout_tturb_xmean_last.nc,WRF/micro2/hurs_wrfout_tturb_xmean_last.nc,WRF_LMDZ/AR40/hurs_wrfout_tturb_xmean_last.nc,WRF_LMDZ/NPv31/hurs_wrfout_tturb_xmean_last.nc,LMDZ/AR40/hurs_reproj-histins_tturb_xmean_last.nc,LMDZ/NPv31/hurs_reproj-histins_tturb_xmean_last.nc -o draw_lines -S 'lat:x:lat ($degrees\ North$):auto:wcurr,wmp1,wmp2,wlmdza,wlmdzb,lmdza,lmdzb:hurs:all model-experiments meridional hurs$_{[tturb\ xmean\ last]}$:0|auto:None:-:,:2.:2.:all:Nlines_hurs_wrfout_tturb-xmean-last:png:True' -v hursturbmean 30 ## e.g. # drawing.py -o draw_lines_time -f wrfout_d01_2001-11-11_00:00:00_west_east_B20-E20-I1_south_north_B20-E20-I1.nc,wrfout_d01_2001-11-11_00:00:00_west_east_B25-E25-I1_south_north_B25-E25-I1.nc,wrfout_d01_2001-11-11_00:00:00_west_east_B35-E35-I1_south_north_B35-E35-I1.nc -S 'WRFtime;y;time ([DD]${[HH]}$);auto;we=20$\times$sn=20,we=25$\times$sn=25,we=35$\times$sn=35;tas;tas|evolution|at|3|different|grid|points;None;time|hours!since!1949-12-01_00:00:00|exct,3,h|%d$^{%H}$;0|12;pdf;-;r,g,b;.;2.;2.;all;-1;True' -v T2 31 32 32 33 ## e.g. # drawing.py -o draw_trajectories -f 'WRF/control/trajectory.dat@-1@/home/lluis/etudes/domains/WL_HyMeX_HighRes_C/geo_em.d03.nc#XLONG_M#XLAT_M,WRF_LMDZ/wlmdza/trajectory.dat@-1@/home/lluis/etudes/domains/WL_HyMeX_C/geo_em.d01.nc#XLONG_M#XLAT_M,WRF_LMDZ/wlmdzb/trajectory.dat@-1@/home/lluis/etudes/domains/WL_HyMeX_C/geo_em.d01.nc#XLONG_M#XLAT_M,WRF_LMDZ/wlmdzb_ii/trajectory.dat@-1@/home/lluis/etudes/domains/WL_HyMeX_C/geo_em.d01.nc#XLONG_M#XLAT_M' -S '$WRF_{CRM}$,$LMDZ_{AR4.0}$,$LMDZ_{NPv3.1}$,$LMDZ_{NPv3.1b}$|None|medicane trajectories|pdf|cyl,i' -v obs/trajectory.dat,satellite,-1 33 34 ## e.g. # drawing.py -o draw_vals_trajectories -f WRF_LMDZ/wlmdza/tevolboxtraj_T2.nc,WRF_LMDZ/wlmdzb/tevolboxtraj_T2.nc,WRF/control/tevolboxtraj_T2.nc -S 'mean:-1:$WRF_{CRM}$,$LMDZ_{AR4.0}$,$LMDZ_{NPv3.1}$@4:tas:time|($[DD]^[HH]$):exct,6,h:$%d^{%H}$:trajectory|following|mean:pdf' -v T2 … … 2275 2276 return 2276 2277 2277 def draw_lines_time(ncfilens, values, varname 0):2278 def draw_lines_time(ncfilens, values, varnames): 2278 2279 """ Function to draw different lines at the same time from different files with times 2279 2280 draw_lines_time(ncfilens, values, varname): 2280 2281 ncfilens= [filen] ',' separated list of netCDF files 2281 values= [dimvname];[valuesaxis];[dimtit];[ leglabels];[vtit];[title];[rangevals];[timevals];2282 values= [dimvname];[valuesaxis];[dimtit];[dimxyfmt];[leglabels];[vtit];[title];[rangevals];[timevals]; 2282 2283 [legvals];[graphk];[collines];[points];[linewidths];[pointsizes];[pointfreq];[period];[close] 2283 [dimvname]: ',' list of names of the variables with he values of the common dimension 2284 [dimvname]: ',' list of names of the variables with he values of the common dimension ('WRFtime' for WRF Times variable) 2284 2285 [valuesaxis]: which axis will be used for the values ('x', or 'y') 2285 2286 [dimtit]: title for the common dimension ('|' for spaces) 2287 [dimxyfmt]=[dxs],[dxf],[Ndx],[ordx],[dys],[dyf],[Ndy],[ordx]: format of the values at each axis (or 'auto') 2288 [dxs]: style of x-axis ('auto' for 'pretty') 2289 'Nfix', values computed at even 'Ndx' 2290 'Vfix', values computed at even 'Ndx' increments 2291 'pretty', values computed following aprox. 'Ndx' at 'pretty' intervals (2.,2.5,4,5,10) 2292 [dxf]: format of the labels at the x-axis ('auto' for '%5g') 2293 [Ndx]: Number of ticks at the x-axis ('auto' for 5) 2294 [ordx]: angle of orientation of ticks at the x-axis ('auto' for horizontal) 2295 [dys]: style of y-axis ('auto' for 'pretty') 2296 [dyf]: format of the labels at the y-axis ('auto' for '%5g') 2297 [Ndy]: Number of ticks at the y-axis ('auto' for 5) 2298 [ordy]: angle of orientation of ticks at the y-axis ('auto' for horizontal) 2286 2299 [leglabels]: ',' separated list of names for the legend ('None', no legend '!' for spaces) 2287 2300 [vartit]: name of the variable in the graph … … 2322 2335 [beg],[end]: beginning and end of the period in reference time-units of first file 2323 2336 [close]: Whether figure should be finished or not 2324 varname 0= ',' list of variable names to plot (assuming only 1 variable per file)2337 varnames= ',' list of variable names to plot (assuming only 1 variable per file) 2325 2338 values= 'time;y;time ([DD]${[HH]}$);32x32;$wss^{*}$;wss Taylor's turbulence term;time|hours!since!1949-12-01_00:00:00;exct,12,h|%d$^{%H}$;2;pdf' 2326 2339 """ … … 2333 2346 quit() 2334 2347 2335 expectargs = '[dimvname];[valuesaxis];[dimtit];[leglabels];[vtit];[title];' 2336 expectargs = expectargs + '[rangevals];[timevals];[legvals];[graphk];[lines];' 2337 expectargs = expectargs + '[collines];[points];[linewidths];[pointsizes];' 2338 expectargs = expectargs + '[pointfreq];[period];[close]' 2348 expectargs = '[dimvname];[valuesaxis];[dimtit];[dimxyfmt];[leglabels];[vtit];' + \ 2349 '[title];[rangevals];[timevals];[legvals];[graphk];[lines];[collines];' + \ 2350 '[points];[linewidths];[pointsizes];[pointfreq];[period];[close]' 2339 2351 drw.check_arguments(fname,values,expectargs,';') 2340 2352 … … 2343 2355 valuesaxis = values.split(';')[1] 2344 2356 dimtit = values.split(';')[2].replace('|',' ') 2345 leglabels = gen.latex_text(values.split(';')[3]).replace('!',' ') 2346 vartit = values.split(';')[4] 2347 title = values.split(';')[5].replace('|',' ') 2348 rangevals = values.split(';')[6] 2349 timevals = values.split(';')[7] 2350 legvals = values.split(';')[8] 2351 graphk = values.split(';')[9] 2352 lines0 = values.split(';')[10] 2353 collines0 = values.split(';')[11] 2354 points0 = values.split(';')[12] 2355 linewidths0 = values.split(';')[13] 2356 pointsizes0 = values.split(';')[14] 2357 pointfreq0 = values.split(';')[15] 2358 period = values.split(';')[16] 2359 close = gen.Str_Bool(values.split(':')[17]) 2357 dimxyfmt = values.split(';')[3] 2358 leglabels = gen.latex_text(values.split(';')[4]).replace('!',' ') 2359 vartit = values.split(';')[5] 2360 title = values.split(';')[6].replace('|',' ') 2361 rangevals = values.split(';')[7] 2362 timevals = values.split(';')[8] 2363 legvals = values.split(';')[9] 2364 graphk = values.split(';')[10] 2365 lines0 = values.split(';')[11] 2366 collines0 = values.split(';')[12] 2367 points0 = values.split(';')[13] 2368 linewidths0 = values.split(';')[14] 2369 pointsizes0 = values.split(';')[15] 2370 pointfreq0 = values.split(';')[16] 2371 period = values.split(';')[17] 2372 close = gen.Str_Bool(values.split(';')[18]) 2360 2373 2361 2374 Nfiles = len(ncfiles) … … 2473 2486 founddvar = False 2474 2487 for dvar in dimvname: 2475 if objfile.variables.has_key(dvar):2488 if dvar != 'WRFtime' and objfile.variables.has_key(dvar): 2476 2489 founddvar = True 2477 2490 vdobj = objfile.variables[dvar] 2491 uvd = str(vdobj.units) 2478 2492 if len(vdobj.shape) != 1: 2479 2493 print errormsg … … 2481 2495 "variable '" + dvar + "' !!" 2482 2496 quit(-1) 2497 vdvals = vdobj[:] 2483 2498 break 2499 elif dvar == 'WRFtime' and objfile.variables.has_key('Times'): 2500 founddvar = True 2501 uvd = timeunit 2502 tunitsec = timeunit.split(' ') 2503 if len(tunitsec) == 4: 2504 refdate = tunitsec[2][0:4]+tunitsec[2][5:7]+tunitsec[2][8:10] + \ 2505 tunitsec[3][0:2] + tunitsec[3][3:5] + tunitsec[3][6:8] 2506 else: 2507 refdate = tunitsec[2][0:4]+tunitsec[2][5:7]+tunitsec[2][8:10] + \ 2508 '000000' 2509 tunitsval = tunitsec[0] 2510 2511 timewrfv = objfile.variables['Times'] 2512 dt = timewrfv.shape[0] 2513 vdvals = np.zeros((dt), dtype=np.float) 2514 2515 for it in range(dt): 2516 wrfdates = gen.datetimeStr_conversion(timewrfv[it,:], \ 2517 'WRFdatetime', 'matYmdHMS') 2518 vdvals[it] = gen.realdatetime1_CFcompilant(wrfdates, refdate, \ 2519 tunitsval) 2520 2484 2521 if not founddvar: 2485 2522 print errormsg … … 2505 2542 "' has any variable '", varname, "' !!" 2506 2543 quit(-1) 2507 if vdobj.units.find('month') != -1:2544 if uvd.find('month') != -1: 2508 2545 print warnmsg 2509 2546 print ' ' + fname + ": transforming time units from 'months' to 'days'!!" 2510 timevals0, tunits0 = gen.CFmonthU_daysU(vd obj[:], vdobj.units)2547 timevals0, tunits0 = gen.CFmonthU_daysU(vdvals[:], vdobj.units) 2511 2548 else: 2512 timevals0 = vd obj[:]2513 tunits0 = str(vdobj.units)2549 timevals0 = vdvals[:] 2550 tunits0 = uvd 2514 2551 2515 2552 # Getting period … … 2520 2557 reftvals = timevals0 2521 2558 2522 dimt = len(vd obj[:])2559 dimt = len(vdvals[:]) 2523 2560 2524 2561 if period == '-1': … … 2612 2649 pointfreq = int(pointfreq0) 2613 2650 2614 drw.plot_lines_time(dimvalues, varvalues, valuesaxis, dimtit, legvals, vartit, \ 2615 varunits, timepos, timelabels, title, locleg, legfontsize, graphk, valmin, \ 2616 valmax, lines, collines, points, linewidths, pointsizes, pointfreq, close) 2651 # axis 2652 xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimxyfmt,',') 2653 xaxis = [xstyl, xaxf, Nxax, xaxor] 2654 yaxis = [ystyl, yaxf, Nyax, yaxor] 2655 2656 drw.plot_lines_time(dimvalues, varvalues, valuesaxis, xaxis, yaxis, dimtit, \ 2657 legvals, vartit, varunits, timepos, timelabels, title, locleg, legfontsize, \ 2658 graphk, valmin, valmax, lines, collines, points, linewidths, pointsizes, \ 2659 pointfreq, close) 2617 2660 2618 2661 return -
trunk/tools/drawing_tools.py
r1263 r1274 6062 6062 return lkinds, pkinds 6063 6063 6064 def plot_lines_time(vardv, varvv, vaxis, dtit, linesn0, vtit, vunit, tpos, tlabs, \ 6065 gtit, gloc, gsize, kfig, vmin, vmax, lsl, coll, ptl, lwidth, psize, ptf, ifclose): 6064 def plot_lines_time(vardv, varvv, vaxis, xaxv, yaxv, dtit, linesn0, vtit, vunit, \ 6065 tpos, tlabs, gtit, gloc, gsize, kfig, vmin, vmax, lsl, coll, ptl, lwidth, psize, \ 6066 ptf, ifclose): 6066 6067 """ Function to plot a collection of lines with a time axis 6067 6068 vardv= list of set of dimension values 6068 6069 varvv= list of set of values 6069 6070 vaxis= which axis will be used for the time values ('x', or 'y') 6071 xaxv= list with the x-axis paramteres [style, format, number and orientation] 6072 yaxv= list with the y-axis paramteres [style, format, number and orientation] 6070 6073 dtit= title for the common dimension 6071 6074 linesn= names for the legend (None, no legend) … … 6108 6111 Ntraj, coll, lsl, ptl, lwidth, psize, ptf) 6109 6112 6113 # Axis ticks 6114 # Usually axis > x must be the time one, thus... 6115 dxn = np.min(vardv) 6116 dxx = np.max(vardv) 6117 dyn = np.min(varvv) 6118 dyx = np.max(varvv) 6119 6120 dimxt0 = tpos 6121 if yaxv[0] == 'pretty': 6122 dimyt0 = np.array(gen.pretty_int(dyn,dyx,yaxv[2])) 6123 elif yaxv[0] == 'Nfix': 6124 dimyt0 = np.arange(dyn,dyx,(dyx-dyn)/(1.*yaxv[2])) 6125 elif yaxv[0] == 'Vfix': 6126 dimyt0 = np.arange(0,dyx,yaxv[2]) 6127 6128 dimxv0 = dimxt0 6129 dimyv0 = dimyt0 6130 6131 dimxl0 = tlabs 6132 dimyl0 = [] 6133 for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i], style=yaxv[1])) 6134 6135 dimxT0 = gen.latex_text(dtit) 6136 dimyT0 = gen.latex_text(vtit) + ' (' + units_lunits(vaxis) + ')' 6137 6138 pixkind = 'fixpixel' 6139 6140 if vaxis == 'y': 6141 reva = None 6142 else: 6143 reva = 'transpose' 6144 6145 if reva is not None: 6146 varsv = np.zeros((len(dimxt0), len(dimyt0)), dtype=np.float) 6147 varsv, dimxv, dimyv, dimxt, dimyt, dimxl, dimyl, dimxT, dimyT = \ 6148 transform(varsv, reva, dxv=dimxv0, dyv=dimyv0, dxt=dimxt0, dyt=dimyt0, \ 6149 dxl=dimxl0, dyl=dimyl0, dxtit=dimxT0, dytit=dimyT0) 6150 else: 6151 dimxv = dimxv0 6152 dimyv = dimyv0 6153 dimxt = dimxt0 6154 dimyt = dimyt0 6155 dimxl = dimxl0 6156 dimyl = dimyl0 6157 dimxT = dimxT0 6158 dimyT = dimyT0 6159 6110 6160 plt.rc('text', usetex=True) 6111 6161 xtrmvv = [fillValueF,-fillValueF] … … 6126 6176 label=linesn[il], color=colvalues[il], linewidth=lwidths[il], \ 6127 6177 markersize=psizes[il], markevery=ptf) 6128 6129 # Old way6130 # if ptf is None:6131 # plt.plot(varvv[il], vardv[il], linekinds[il], label= linesn[il], \6132 # color=colvalues[il], linewidth=lwidths[il], markersize=psizes[il])6133 # else:6134 # plt.plot(varvv[il], vardv[il], linekinds[il], color=colvalues[il], \6135 # linewidth=lwidths[il])6136 # plt.plot(varvv[il][::ptf], vardv[il][::ptf], pointkinds[il], \6137 # label= linesn[il], color=colvalues[il], linewidth=lwidths[il], \6138 # markersize=psizes[il])6139 6178 6140 6179 minvv = np.min(varvv[il]) … … 6173 6212 markersize=psizes[il], markevery=ptf) 6174 6213 6175 # Old way6176 # if ptf is None:6177 # plt.plot(vardv[il], varvv[il], linekinds[il], label= linesn[il], \6178 # color=colvalues[il], linewidth=lwidths[il], markersize=psizes[il], markevery=ptf)6179 # else:6180 # plt.plot(vardv[il], varvv[il], linekinds[il], color=coll[il], \6181 # linewidth=lwidths[il])6182 # plt.plot(vardv[il][::ptf], varvv[il][::ptf], pointkinds[il], \6183 # label= linesn[il], color=colvalues[il], linewidth=lwidths[il], \6184 # markersize=psizes[il])6185 6186 6214 minvv = np.min(varvv[il]) 6187 6215 maxvv = np.max(varvv[il]) … … 6214 6242 6215 6243 figname = 'lines_time' 6216 graphtit = g tit.replace('_','\_').replace('&','\&')6244 graphtit = gen.latex_text(gtit) 6217 6245 6218 6246 plt.title(graphtit) 6219 6247 if linesn0 is not None: 6220 if Ntraj < 10: 6221 plt.legend(loc=gloc, prop={'size':gsize}) 6222 elif 10 < Ntraj < 20: 6223 plt.legend(loc=gloc, prop={'size':int(gsize*0.8)}) 6224 else: 6225 plt.legend(loc=gloc, prop={'size':int(gsize*0.6)}) 6226 6227 print plt.xlim(),':', plt.ylim() 6228 6248 plt.legend(loc=gloc, prop={'size':gsize}) 6249 6229 6250 output_kind(kfig, figname, ifclose) 6230 6251
Note: See TracChangeset
for help on using the changeset viewer.