- Timestamp:
- Nov 8, 2016, 12:15:59 AM (8 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r1274 r1277 29 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 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 ## e.g. # drawing.py -o draw_Neighbourghood_evol -S 'vas:Time|-1|WRFtime,south_north|44|XLAT,west_east|88|XLONG:south_north,west_east:5:auto:time|($[DD]^{[HH]}$),time|($[DD]^{[HH]}$):exct,1,h|exct,3,h:$%d^{%H}$,$%d^{%H}$:5|pts|neighbourghood|temporal|evolution|on|2001|Nov.|at|x=88,|y=44:0.0,20.:rainbow,auto,auto:auto:png:vas_Neigh_evol:True' -f ~/PY/wrfout_d01_2001-11-11_00:00:00 -v V10 31 32 32 33 … … 2666 2667 filen= netCDF file name 2667 2668 values= [gvarname]:[dimsval]:[neigdims]:[Nneig]:[Ncol]:[timetits]:[tkinds]: 2668 [timefmts]:[gtitle]:[shadxtrms]:[cbar]:[gkind]:[ofile] 2669 [timefmts]:[gtitle]:[shadxtrms]:[colobarvals]:[neighlinevals]:[gkind]:[ofile]:[close] 2670 [gvarname]: ':' list of names of the variables in the plot 2669 2671 [dimsval]: [dimn1]|[val1]|[dimv1],...,[dimnN]|[valN]|[dimvN] dimension names, values to get 2670 2672 (-1, for all; no name/value pair given full length) and variable with values of the dimension 2673 'WRFtime' for WRF times 2671 2674 NOTE: when dimsval[X,Y] == neigdims[X,Y], valX,valY --> valX,valY-Nneig/2, valX,valY+Nneig/2 2672 2675 [neigdims]: [dimnX],[dimnY] dimensions mnames along which the neigbourghood should be defined … … 2683 2686 [timefmts]: [tfmtX],[tfmtY] format of the time labels 2684 2687 [gtitle]: title of the graphic ('|' for spaces) 2685 [shadxtrms]: Extremes for the shading 2686 [cbar]: colorbar to use 2688 [shadxtrms]: minimum and maximum value for the shading or: 2689 'Srange': for full range 2690 'Saroundmean@val': for mean-xtrm,mean+xtrm where xtrm = np.min(mean-min@val,max@val-mean) 2691 'Saroundminmax@val': for min*val,max*val 2692 'Saroundpercentile@val': for median-xtrm,median+xtrm where xtrm = np.min(median-percentile_(val), 2693 percentile_(100-val)-median) 2694 'Smean@val': for -xtrm,xtrm where xtrm = np.min(mean-min*@val,max*@val-mean) 2695 'Smedian@val': for -xtrm,xtrm where xtrm = np.min(median-min@val,max@val-median) 2696 'Spercentile@val': for -xtrm,xtrm where xtrm = np.min(median-percentile_(val), 2697 percentile_(100-val)-median) 2698 [colorbarvals]=[colbarn],[fmtcolorbar],[orientation] characteristics of the colormap and colorbar 2699 [colorbarn]: name of the color bar 2700 [fmtcolorbar]: format of the numbers in the color bar 'C'-like ('auto' for %6g) 2701 [orientation]: orientation of the colorbar ('vertical' (default, by 'auto'), 'horizontal') 2702 [neighlinevals]=[linecol],[linestyle],[linewidth] characterisitcs of the lines to mark the limits of the neighborhood 2703 ('auto' for: ['#646464', '-', 2.]) 2704 [linecol]: color of the line 2705 [linestyle]: style of the line 2706 [linewidth]: width of the line 2687 2707 [gkind]: kind of graphical output 2688 2708 [ofile]: True/False whether the netcdf with data should be created or not 2709 [close]: Whether figure should be finished or not 2689 2710 variable= name of the variable 2690 2711 values = 'q:Time|-1|Times,bottom_top|6|ZNU,south_north|3|XLAT,west_east|26|XLONG:south_north,west_east:5:auto:time|($[DD]^{[HH]}$),time|($[DD]^{[HH]}$):exct,2,h|exct,1,d:$%d^{%H}$,$%d^{%H}$:5|pts|neighbourghood|temporal|evolution:0.0,0.004:BuPu:pdf:True' … … 2699 2720 2700 2721 expectargs = '[gvarname]:[dimsval]:[neigdims]:[Nneig]:[Ncol]:' + \ 2701 '[timetits]:[tkinds]:[timefmts]:[gtitle]:[shadxtrms]:[cbar]:[gkind]:[ofile]' 2722 '[timetits]:[tkinds]:[timefmts]:[gtitle]:[shadxtrms]:[colorbarvals]:' + \ 2723 '[neighlinevals]:[gkind]:[ofile]:[close]' 2702 2724 2703 2725 drw.check_arguments(fname,values,expectargs,':') … … 2713 2735 gtitle = values.split(':')[8].replace('|',' ') 2714 2736 shadxtrms = values.split(':')[9].split(',') 2715 cbar = values.split(':')[10] 2716 gkind = values.split(':')[11] 2717 ofile = values.split(':')[12] 2737 colorbarvals = values.split(':')[10] 2738 neighlinevals = values.split(':')[11] 2739 gkind = values.split(':')[12] 2740 ofile = values.split(':')[13] 2741 close = gen.Str_Bool(values.split(':')[14]) 2718 2742 2719 2743 if Ncol0 != 'auto': … … 2727 2751 if np.mod(Nneig,2) == 0: 2728 2752 print errormsg 2729 print ' ' + fname + ": an odd value for 'Nneig':", Nneig,'is required !!!'2753 print ' ' + fname + ": an odd value for 'Nneig':", Nneig, 'is required !!!' 2730 2754 quit(-1) 2731 2755 … … 2756 2780 slicevar.append(slice(0, dimsize+1)) 2757 2781 newdimn.append(dimn) 2758 newdimsvar[dimn] = dims eize2782 newdimsvar[dimn] = dimsize 2759 2783 2760 2784 for dimslicen in dimvslice.keys(): … … 2795 2819 dimtime = dim1 2796 2820 2821 # Number of columns and rows 2797 2822 if Ncol == 'auto': 2798 dimtsqx = int(np.sqrt(dimt)) + 1 2799 dimtsqy = int(np.sqrt(dimt)) + 1 2823 dimtsqx = int(np.sqrt(dimt)) 2800 2824 else: 2801 2825 dimtsqx = int(Ncol) 2802 dimtsqy = dimt/dimtsqx + 1 2826 2827 dimtsqy = dimt/dimtsqx + 1 2828 print ' ' + fname + '; plotting ', dimtsqx, 'x', dimtsqy, 'time-windows of:', \ 2829 Nneig, 'x', Nneig, 'grid-points' 2803 2830 2804 2831 neighbourghood = np.ones((dimtsqy*Nneig,dimtsqx*Nneig), dtype=np.float)*fillValue … … 2821 2848 2822 2849 # Time values at the X/Y axes 2823 if ncobj.variables[dimvvalues[dimtime]].dtype == '|S1':2824 print ' ' + fname + ': WRF time variable!'2850 if dimvvalues[dimtime] == 'WRFtime': 2851 print ' ' + fname + ": WRF time variable!: 'Times'" 2825 2852 refdate = '19491201000000' 2826 2853 tunitsval = 'hours' 2827 2854 dimtvalues = np.zeros((dimt), dtype=np.float) 2828 tvals = ncobj.variables[ dimvvalues[dimtime]]2855 tvals = ncobj.variables['Times'] 2829 2856 yrref=refdate[0:4] 2830 2857 monref=refdate[4:6] … … 2868 2895 newnc.close() 2869 2896 print fname + ": Successfull generation of file '" + ofilen + "' !!" 2897 # Colorbar values 2898 colbarn, fmtcolbar, colbaror = drw.colorbar_vals(colorbarvals,',') 2899 colormapv = [colbarn, fmtcolbar, colbaror] 2900 2901 # Neighborhood line values 2902 if neighlinevals == 'auto': 2903 neiglinev = ['#646464', '-', 2.] 2904 else: 2905 neiglinev = neighlinevals.split(',') 2870 2906 2871 2907 # Time ticks … … 2881 2917 2882 2918 drw.plot_Neighbourghood_evol(neighbourghood, dimxv, dimyv, gvarname, timetits, \ 2883 timepos, timelabels, cbar, Nneig, shadxtrms, vunits, gtitle, gkind, True) 2919 timepos, timelabels, colormapv, neiglinev, Nneig, shadxtrms, vunits, gtitle, \ 2920 gkind, close) 2884 2921 2885 2922 def draw_points(filen, values): … … 5053 5090 varn=opts.varname 5054 5091 oper=opts.operation 5092 5093 if opts.operation is None: 5094 print errormsg 5095 print ' No operation provided !!' 5096 print " an operation must be provided as '-o [operationname]' " 5097 quit(-1) 5055 5098 5056 5099 if opts.ncfile is not None and not os.path.isfile(opts.ncfile) and \ -
trunk/tools/drawing_tools.py
r1274 r1277 5560 5560 return 5561 5561 5562 def plot_Neighbourghood_evol(varsv, dxv, dyv, vnames, ttits, tpos, tlabels, c olorbar,\5563 Nng, vs, uts, gtit, kfig, ifclose):5562 def plot_Neighbourghood_evol(varsv, dxv, dyv, vnames, ttits, tpos, tlabels, cbarv, \ 5563 neighv, Nng, vs, uts, gtit, kfig, ifclose): 5564 5564 """ Plotting neighbourghood evolution 5565 5565 varsv= 2D values to plot with shading … … 5569 5569 tpos= positions of the time ticks 5570 5570 tlabels= labels of the time ticks 5571 colorbar= name of the color bar to use 5571 cbarv= list with the parameters of the color bar [colorbar, cbarfmt, cbaror] 5572 colorbar: name of the color bar to use 5573 cbarfmt: format of the numbers in the colorbar 5574 cbaror: orientation of the colorbar 5575 neighv = list with the parameters for the lines of the limits of the neighborhood [color, style, width] 5572 5576 Nng= Number of grid points of the full side of the box (odd value) 5573 5577 vs= minmum and maximum values to plot in shadow or: … … 5671 5675 5672 5676 # plt.pcolormesh(dxv, dyv, varsv, cmap=plt.get_cmap(colorbar), vmin=vsend[0], vmax=vsend[1]) 5673 plt.pcolormesh(varsvmask, cmap=plt.get_cmap(colorbar), vmin=vsend[0], vmax=vsend[1]) 5674 cbar = plt.colorbar() 5675 5676 newtposx = (tpos[0][:] - np.min(dxv)) * len(dxv) * Nng / (np.max(dxv) - np.min(dxv)) 5677 newtposy = (tpos[1][:] - np.min(dyv)) * len(dyv) * Nng / (np.max(dyv) - np.min(dyv)) 5678 5679 plt.xticks(newtposx, tlabels[0]) 5680 plt.yticks(newtposy, tlabels[1]) 5677 plt.pcolormesh(varsvmask, cmap=plt.get_cmap(cbarv[0]), vmin=vsend[0], vmax=vsend[1]) 5678 if cbarv[2] == 'horizontal': 5679 cbar = plt.colorbar(format=cbarv[1],orientation=cbarv[2]) 5680 # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib 5681 ticklabels= cbar.ax.get_xticklabels() 5682 Nticks = len(ticklabels) 5683 ticklabs = [] 5684 for itick in range(Nticks): ticklabs.append(ticklabels[itick].get_text()) 5685 cbar.ax.set_xticklabels(ticklabs,rotation=90) 5686 else: 5687 cbar = plt.colorbar(format=cbarv[1],orientation=cbarv[2]) 5688 5689 newtposx = (tpos[0][:] - np.min(dxv)) * (len(dxv)-1) * Nng / (np.max(dxv) - \ 5690 np.min(dxv)) 5691 newtposy = (tpos[1][:] - np.min(dyv)) * (len(dyv)-1) * Nng / (np.max(dyv) - \ 5692 np.min(dyv)) 5693 5694 plt.xlim(np.min(newtposx), np.max(newtposx)) 5695 plt.ylim(np.min(newtposy), np.max(newtposy)+Nng) 5696 5697 # Plotting neighborhood boundaries 5698 Nng2 = Nng/2. 5699 for iy in range(len(dyv)): 5700 plt.plot([np.min(newtposx),np.max(newtposx)], [newtposy[iy],newtposy[iy]], \ 5701 linestyle=neighv[1], color=neighv[0], linewidth=neighv[2]) 5702 for ix in range(len(dxv)): 5703 plt.plot([newtposx[ix],newtposx[ix]],[np.min(newtposy),np.max(newtposy)+Nng],\ 5704 linestyle=neighv[1], color=neighv[0], linewidth=neighv[2]) 5705 # Plotting center 5706 for iy in range(len(dyv)): 5707 for ix in range(len(dxv)): 5708 plt.plot([newtposx[ix]+Nng2,newtposx[ix]+Nng2], [newtposy[iy]+Nng2-0.125,\ 5709 newtposy[iy]+Nng2+0.125], linestyle=neighv[1], color=neighv[0], \ 5710 linewidth=neighv[2]) 5711 plt.plot([newtposx[ix]+Nng2-0.125,newtposx[ix]+Nng2+0.125], \ 5712 [newtposy[iy]+Nng2,newtposy[iy]+Nng2], linestyle=neighv[1], \ 5713 color=neighv[0], linewidth=neighv[2]) 5714 5715 plt.xticks(newtposx+Nng/2., tlabels[0]) 5716 plt.yticks(newtposy+Nng/2., tlabels[1]) 5681 5717 plt.xlabel(ttits[0]) 5682 5718 plt.ylabel(ttits[1]) … … 5688 5724 5689 5725 # units labels 5690 cbar.set_label( vnames.replace('_','\_') + ' (' + units_lunits(uts) + ')')5726 cbar.set_label(gen.latex_text(vnames) + ' (' + units_lunits(uts) + ')') 5691 5727 5692 5728 figname = 'Neighbourghood_evol' 5693 graphtit = g tit.replace('_','\_').replace('&','\&')5729 graphtit = gen.latex_text(gtit) 5694 5730 5695 5731 plt.title(graphtit, position=(0.5,1.05))
Note: See TracChangeset
for help on using the changeset viewer.