Changeset 1147 in lmdz_wrf
- Timestamp:
- Oct 6, 2016, 3:04:05 PM (8 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r1137 r1147 10 10 ## e.g. # drawing.py -f /media/data2/etudes/WRF_LMDZ/WL_HyMeX/IIphase/medic950116/wlmdza/wrfout/wrfout_d01_1995-01-13_00:00:00 -o create_movie -S 'draw_2D_shad#Time@WRFTimes@10@95@191@1#tas:East_West|-1,North_South|-1,Time|2:longitude:latitude:Summer:270.,300.:tas|at|t=0:pdf:None:None' -v T2 11 11 ## e.g. # drawing.py -f wrfout_d01_1980-03-01_00\:00\:00_Time_B0-E48-I1.nc -o draw_2D_shad -S 'tas:East_West|-1,North_South|-1,Time|2:longitude:latitude:Summer:270.,300.:tas|at|t=0:pdf:None:cyl,i' -v T2 12 ## e.g. # drawing.py -f ~/etudes/domains/MEDCORDEX/geo_em.d01.nc -o draw_2D_shad_cont -S 'landmask,height:Time|0:Time|0:XLONG_M:XLAT_M: rainbow:fixc,k:%.2f:0,1:0.,3000.,10:landmask & height:pdf:False:lcc,i' -v LANDMASK,HGT_M12 ## e.g. # drawing.py -f ~/etudes/domains/MEDCORDEX/geo_em.d01.nc -o draw_2D_shad_cont -S 'landmask,height:Time|0:Time|0:XLONG_M:XLAT_M:auto:rainbow,auto,auto:fixc,k:%.2f:0.,1.:0.,3000.,10:landmask & height:pdf:None:lcc,i:True' -v LANDMASK,HGT_M 13 13 ## 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 14 14 ## 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' … … 407 407 draw_2D_shad_cont(ncfile, values, varn) 408 408 ncfile= [ncfilevars],[ncfilevarc] files to use (one value, same file) 409 values=[vnamefs]:[dimvals]:[dimvalc]:[dimxvn]:[dimyvn]:[ colorbar]:[ckind]:[clabfmt]:[sminv],[smaxv]:[sminc],[smaxv],[Nlev]:[figt]:[kindfig]:[reverse]:[mapv]409 values=[vnamefs]:[dimvals]:[dimvalc]:[dimxvn]:[dimyvn]:[dimxyfmt]:[colorbarvals]:[ckind]:[clabfmt]:[sminv],[smaxv]:[sminc],[smaxv],[Nlev]:[figt]:[kindfig]:[reverse]:[mapv]:[close] 410 410 [vnamefs],[vnamefc]: Name in the figure of the shaded and the contour variables 411 411 [dimvals/c]: list of [dimname]|[value] telling at which dimension of the 412 412 variable a given value is required (no dimension name, all the length) 413 413 [dimx/yvn]: names of the variables with the values of the dimensions for the plot 414 [colorbar]: name of the color bar 414 [dimxyfmt]=[dxf],[Ndx],[dyf],[Ndy]: format of the values at each axis 415 [dxs]: style of x-axis ('auto' for 'pretty') 416 'Nfix', values computed at even 'Ndx' 417 'Vfix', values computed at even 'Ndx' increments 418 'pretty', values computed following aprox. 'Ndx' at 'pretty' intervals (2.,2.5,4,5,10) 419 [dxf]: format of the labels at the x-axis 420 [Ndx]: Number of ticks at the x-axis 421 [ordx]: angle of orientation of ticks at the x-axis ('auto' for horizontal) 422 [dys]: style of y-axis ('auto' for 'pretty') 423 [dyf]: format of the labels at the y-axis 424 [Ndy]: Number of ticks at the y-axis 425 [ordy]: angle of orientation of ticks at the y-axis ('auto' for horizontal) 426 [colorbarvals]=[colbarn],[fmtcolorbar],[orientation] 427 [colorbarn]: name of the color bar 428 [fmtcolorbar]: format of the numbers in the color bar 'C'-like ('auto' for %6g) 429 [orientation]: orientation of the colorbar ('vertical' (default, by 'auto'), 'horizontal') 415 430 [ckind]: kind of contours 416 431 'cmap': as it gets from colorbar … … 418 433 'fixsigc,[colname]': fixed color [colname], >0 stright, <0 dashed line 419 434 [clabfmt]: format of the labels in the contour (None, also possible) 420 [smin/axv]: minimum and maximum value for the shading 435 [smin/axv]: minimum and maximum value for the shading or 436 'Srange': for full range 437 'Saroundmean@val': for mean-xtrm,mean+xtrm where xtrm = np.min(mean-min@val,max@val-mean) 438 'Saroundminmax@val': for min*val,max*val 439 'Saroundpercentile@val': for median-xtrm,median+xtrm where xtrm = np.min(median-percentile_(val), 440 percentile_(100-val)-median) 441 'Smean@val': for -xtrm,xtrm where xtrm = np.min(mean-min*@val,max*@val-mean) 442 'Smedian@val': for -xtrm,xtrm where xtrm = np.min(median-min@val,max@val-median) 443 'Spercentile@val': for -xtrm,xtrm where xtrm = np.min(median-percentile_(val), 444 percentile_(100-val)-median) 421 445 [sminc]:[smaxv]:[Nlev]: minimum, maximum and number of values for the contour 422 446 [figt]: title of the figure ('|' for spaces) … … 434 458 * 'h', high 435 459 * 'f', full 460 [close]: Whether figure should be finished or not 436 461 valules= 'rh,ta:z|-1,x|-1:z|-1,x|-1:lat:pressure:BuPu:fixsigc,black:%d:0.,100.:195.,305.,7:Meridonal|average|of|rh|&|ta:pdf:flip@y:None' 437 462 varn= [varsn],[varcn] name of the variable to plot with shading variable with contour … … 444 469 quit() 445 470 446 expectargs = '[vnamefs]:[dimvals]:[dimvalc]:[dimxvn]:[dimyvn]:[ colorbar]:'447 expectargs = expectargs + '[ckind]:[clabfmt]:[sminv],[smaxv]:[sminc],[smaxv],'448 expectargs = expectargs + '[Nlev]:[figt]:[kindfig]:[reverse]:[mapv]'471 expectargs = '[vnamefs]:[dimvals]:[dimvalc]:[dimxvn]:[dimyvn]:[dimxyf]:' + \ 472 '[colorbarvals]:[ckind]:[clabfmt]:[sminv],[smaxv]:[sminc],[smaxv],[Nlev]:' + \ 473 '[figt]:[kindfig]:[reverse]:[mapv]:[close]' 449 474 450 475 drw.check_arguments(fname,values,expectargs,':') … … 455 480 vdimxn = values.split(':')[3] 456 481 vdimyn = values.split(':')[4] 457 colbarn = values.split(':')[5] 458 countkind = values.split(':')[6] 459 countlabelfmt = values.split(':')[7] 460 shadminmax = values.split(':')[8] 461 contlevels = values.split(':')[9] 462 figtitle = values.split(':')[10].replace('|',' ') 463 figkind = values.split(':')[11] 464 revals = values.split(':')[12] 465 mapvalue = values.split(':')[13] 482 dimxyf = values.split(':')[5] 483 colorbarvals = values.split(':')[6] 484 countkind = values.split(':')[7] 485 countlabelfmt = values.split(':')[8] 486 shadminmax = values.split(':')[9].split(',') 487 contlevels = values.split(':')[10] 488 figtitle = values.split(':')[11].replace('|',' ') 489 figkind = values.split(':')[12] 490 revals = values.split(':')[13] 491 mapvalue = values.split(':')[14] 492 close = gen.Str_Bool(values.split(':')[15]) 466 493 467 494 if2filenames = ncfile.find(',') … … 603 630 countlfmt = countlabelfmt 604 631 605 shading_nx = np.zeros((2), dtype=np.float)606 shading_nx [0] = np.float(shadminmax.split(',')[0])607 shading_nx[1] = np.float(shadminmax.split(',')[1]) 608 632 # Shading limits 633 shading_nx = drw.graphic_range(shadminmax,valshad) 634 635 # Contour limits 609 636 clevmin = np.float(contlevels.split(',')[0]) 610 637 clevmax = np.float(contlevels.split(',')[1]) … … 622 649 623 650 if mapvalue == 'None': mapvalue = None 651 652 colbarn, fmtcolbar, colbaror = drw.colorbar_vals(colorbarvals,',') 653 654 xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimxyf,',') 655 xaxis = [xstyl, xaxf, Nxax, xaxor] 656 yaxis = [ystyl, yaxf, Nyax, yaxor] 657 624 658 if revals == 'None': revals = None 625 659 626 660 drw.plot_2D_shadow_contour(valshad, valcont, vnamesfig, odimxv, odimyv, odimxu, \ 627 odimyu, dimnamesv, colbarn, countkind, countlfmt, shading_nx, levels_cont, \ 628 varunits, figtitle, figkind, revals, mapvalue) 661 odimyu, xaxis, yaxis, dimnamesv, colbarn, fmtcolbar, colbaror, countkind, \ 662 countlfmt, shading_nx, levels_cont, varunits, figtitle, figkind, revals, \ 663 mapvalue, close) 629 664 630 665 return -
trunk/tools/drawing_tools.py
r1134 r1147 1850 1850 elif u == 'ms-2': lu='$ms^{-2}$' 1851 1851 elif u == 'minutes': lu='$minute$' 1852 elif u == 'meters MSL': lu='$m$' 1853 elif u == 'none': lu='-' 1852 1854 elif u == 'Pa/s': lu='$Pas^{-1}$' 1853 1855 elif u == 'Pas-1': lu='$Pas^{-1}$' … … 2709 2711 rangegrph = np.zeros((2), dtype=np.float) 2710 2712 # Changing limits of the colors 2711 if type(vrng[0]) != type(np.float(1.)) and type(vrng[0]) != type(np.float64(1.)):2713 if vrng[0][0:1] == 'S': 2712 2714 if vrng[0] == 'Srange': 2713 2715 rangegrph[0] = np.min(varsV) … … 2765 2767 print ' ' + fname + ': modified shadow min,max:',rangegrph 2766 2768 else: 2767 rangegrph[0] = vrng[0]2768 rangegrph[1] = vrng[1]2769 rangegrph[0] = np.float(vrng[0]) 2770 rangegrph[1] = np.float(vrng[1]) 2769 2771 2770 2772 return rangegrph … … 4443 4445 return 4444 4446 4445 def plot_2D_shadow_contour(varsv,varcv,vnames,dimxv,dimyv,dimxu,dimyu,dimn, \ 4446 colorbar,ckind,clabfmt,vs,vc,uts,vtit,kfig,reva,mapv): 4447 def plot_2D_shadow_contour(varsv, varcv, vnames, dimxv, dimyv, dimxu, dimyu, xaxv, \ 4448 yaxv, dimn, colorbar, cbarfmt, cbaror, ckind, clabfmt, vs, vc, uts, vtit, kfig, \ 4449 reva, mapv, ifclose): 4447 4450 """ Adding labels and other staff to the graph 4448 4451 varsv= 2D values to plot with shading … … 4451 4454 dim[x/y]v = values at the axes of x and y 4452 4455 dim[x/y]u = units at the axes of x and y 4456 xaxv= list with the x-axis paramteres [style, format, number and orientation] 4457 yaxv= list with the y-axis paramteres [style, format, number and orientation] 4453 4458 dimn= dimension names to plot 4454 4459 colorbar= name of the color bar to use 4460 cbarfmt= format of the numbers in the colorbar 4461 cbaror= orientation of the colorbar 4455 4462 ckind= contour kind 4456 4463 'cmap': as it gets from colorbar … … 4477 4484 * 'h', high 4478 4485 * 'f', full 4486 ifclose= boolean value whether figure should be close (finish) or not 4479 4487 """ 4480 4488 ## import matplotlib as mpl … … 4488 4496 quit() 4489 4497 4498 if len(varsv.shape) != 2: 4499 print errormsg 4500 print ' ' + fname + ': wrong variable shape:',varsv.shape,'is has to be 2D!!' 4501 quit(-1) 4502 if len(varcv.shape) != 2: 4503 print errormsg 4504 print ' ' + fname + ': wrong variable contour:',varcv.shape,'is has to be 2D!!' 4505 quit(-1) 4506 4507 # Axis ticks 4490 4508 # Usually axis > x must be the lon, thus... 4491 4509 dimxv0 = dimxv.copy() 4492 4510 dimyv0 = dimyv.copy() 4493 dimxt0 = np.array(pretty_int(dimxv.min(),dimxv.max(),10)) 4494 dimyt0 = np.array(pretty_int(dimyv.min(),dimyv.max(),10)) 4511 4512 dxn = dimxv.min() 4513 dxx = dimxv.max() 4514 dyn = dimyv.min() 4515 dyx = dimyv.max() 4516 4517 if xaxv[0] == 'pretty': 4518 dimxt0 = np.array(pretty_int(dxn,dxx,xaxv[2])) 4519 elif xaxv[0] == 'Nfix': 4520 dimxt0 = np.arange(dxn,dxx,(dxx-dxn)/(1.*xaxv[2])) 4521 elif xaxv[0] == 'Vfix': 4522 dimxt0 = np.arange(0,dxx,xaxv[2]) 4523 if yaxv[0] == 'pretty': 4524 dimyt0 = np.array(pretty_int(dyn,dyx,yaxv[2])) 4525 elif yaxv[0] == 'Nfix': 4526 dimyt0 = np.arange(dyn,dyx,(dyx-dyn)/(1.*yaxv[2])) 4527 elif yaxv[0] == 'Vfix': 4528 dimyt0 = np.arange(0,dyx,yaxv[2]) 4529 4495 4530 dimxl0 = [] 4496 for i in range(len(dimxt0)): dimxl0.append('{: .1f}'.format(dimxt0[i]))4531 for i in range(len(dimxt0)): dimxl0.append('{:{style}}'.format(dimxt0[i], style=xaxv[1])) 4497 4532 dimyl0 = [] 4498 for i in range(len(dimyt0)): dimyl0.append('{:.1f}'.format(dimyt0[i])) 4533 for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i], style=yaxv[1])) 4534 4499 4535 dimxT0 = variables_values(dimn[0])[0] + ' (' + units_lunits(dimxu) + ')' 4500 4536 dimyT0 = variables_values(dimn[1])[0] + ' (' + units_lunits(dimyu) + ')' … … 4592 4628 4593 4629 else: 4594 x,y = gen.lonlat2D(dimxv,dimyv) 4630 # No following data values 4631 #x = dimxv 4632 #y = dimyv 4633 x = (dimxv-np.min(dimxv))/(np.max(dimxv) - np.min(dimxv)) 4634 y = (dimyv-np.min(dimyv))/(np.max(dimyv) - np.min(dimyv)) 4595 4635 4596 4636 plt.rc('text', usetex=True) 4597 4637 4598 4638 plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(colorbar), vmin=vs[0], vmax=vs[1]) 4599 cbar = plt.colorbar() 4639 if cbaror == 'horizontal': 4640 cbar = plt.colorbar(format=cbarfmt,orientation=cbaror) 4641 # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib 4642 ticklabels= cbar.ax.get_xticklabels() 4643 Nticks = len(ticklabels) 4644 ticklabs = [] 4645 for itick in range(Nticks): ticklabs.append(ticklabels[itick].get_text()) 4646 cbar.ax.set_xticklabels(ticklabs,rotation=90) 4647 else: 4648 cbar = plt.colorbar(format=cbarfmt,orientation=cbaror) 4600 4649 4601 4650 # contour … … 4638 4687 plt.ylabel(dimyT) 4639 4688 4640 plt.xticks(dimxt, dimxl )4641 plt.yticks(dimyt, dimyl )4689 plt.xticks(dimxt, dimxl, rotation=xaxv[3]) 4690 plt.yticks(dimyt, dimyl, rotation=yaxv[3]) 4642 4691 4643 4692 # set the limits of the plot to the limits of the data … … 4646 4695 4647 4696 # units labels 4648 cbar.set_label( vnames[0].replace('_','\_') + ' (' + units_lunits(uts[0]) + ')')4649 plt.annotate( vnames[1].replace('_','\_') +' (' + units_lunits(uts[1]) + ') [' + \4697 cbar.set_label(gen.latex_text(vnames[0]) + ' (' + units_lunits(uts[0]) + ')') 4698 plt.annotate(gen.latex_text(vnames[1]) +' (' + units_lunits(uts[1]) + ') [' + \ 4650 4699 mincntS + ', ' + maxcntS + ']', xy=(0.55,0.04), xycoords='figure fraction', \ 4651 4700 color=coln) 4652 4701 4653 4702 figname = '2Dfields_shadow-contour' 4654 graphtit = vtit.replace('_','\_').replace('&','\&')4703 graphtit = gen.latex_text(vtit) 4655 4704 4656 4705 plt.title(graphtit) 4657 4706 4658 output_kind(kfig, figname, True)4707 output_kind(kfig, figname, ifclose) 4659 4708 4660 4709 return
Note: See TracChangeset
for help on using the changeset viewer.