Changeset 1549 in lmdz_wrf
- Timestamp:
- Apr 28, 2017, 9:36:52 PM (8 years ago)
- Location:
- trunk/tools
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/documentation/plotting/gallery.html
r1545 r1549 20 20 <A HREF="draw_bar.html"><IMG SRC="figs/bar_rain_CRU-NCEP_norm.png" ALT="bar char plot" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> 21 21 <A HREF="bar_line.html"><IMG SRC="figs/bar-line_rain_CRU-NCEP_norm.png" ALT="bar char and lines plot" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> 22 <A HREF="bar_line_time.html"><IMG SRC="figs/bar_time_rain_CRU-NCEP_DJFmean_norm.png" ALT="bar char and lines plot with time" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> 22 23 <A HREF="bar_time.html"><IMG SRC="figs/bar_time_rain_CRU-NCEP_DJFmean_norm.png" ALT="bar char plot time" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> 23 24 <A HREF="barbs.html"><IMG SRC="figs/wind_barbs_2001111003_wss.png" ALT="wind-barbs" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> -
trunk/tools/documentation/plotting/plotting.html
r1545 r1549 16 16 <A CLASS="lc" HREF="draw_bar.html" TARGET="value">bar</A><BR> 17 17 <A CLASS="lc" HREF="bar_line.html" TARGET="value">bar & line</A><BR> 18 <A CLASS="lc" HREF="bar_time.html" TARGET="value">bar_time</A><BR> 18 <A CLASS="lc" HREF="bar_line_time.html" TARGET="value">bar & line with time</A><BR> 19 <A CLASS="lc" HREF="bar_time.html" TARGET="value">bar with time</A><BR> 19 20 <A CLASS="lc" HREF="barbs.html" TARGET="value">barbs</A><BR> 20 21 <A CLASS="lc" HREF="basins.html" TARGET="value">ORCHIDEE's basins</A><BR> -
trunk/tools/drawing.py
r1545 r1549 48 48 ## e.g. # drawing.py -o draw_bar_time -f 'Forcing_rainstats_OKstomate_CRUNCEP_spinup_SESA_DJFmean_norm_meanstd_stat2.nc;time_centered,-1;time_centered;rainnorm:Forcing_rainstats_OKstomate_CRUNCEP_spinup_SACZ_DJFmean_norm_meanstd_stat2.nc;time_centered,-1;time_centered;rainnorm' -S 'auto;pr;1;y;None;year|seconds!since!1958-01-01!00:00:00|exct,5,y|%Y;SESA,SACZ;#AA0000,#0000AA;10000000.;normalized!evolution!of!DJFmean!of!precipitaion!with!CRU-NCEP!forcing;0|10;png;bar_time_rain_CRU-NCEP_DJFmean_norm;yes' 49 49 ## e.g. # drawing.py -o draw_bar_line -f 'Forcing_rainstats_OKstomate_CRUNCEP_spinup_SESA_norm_meanstd_stat2.nc;time_counter,0@12@1;time_counter;rainnorm;bar:Forcing_rainstats_OKstomate_CRUNCEP_spinup_SESA_norm_meanstd_stat2.nc;time_counter,12@24@1;time_counter;rainnorm;bar:Forcing_rainstats_OKstomate_CRUNCEP_spinup_SACZ_norm_meanstd_stat2.nc;time_counter,0@12@1;time_counter;rainnorm;line:Forcing_rainstats_OKstomate_CRUNCEP_spinup_SACZ_norm_meanstd_stat2.nc;time_counter,12@24@1;time_counter;rainnorm;line' -S 'Stringlist,%s,January@Feburary@March@April@May@June@July@August@September@October@November@December@Jan@Feb@Mar@Apr@May@Jun@Jul@Aug@Sept@Oct@Nov@Dec,25,pretty,auto,auto,auto:time!since!1958-01-01:pr:x:-4.,4.:seconds:1:$SESA_{1958}$,$SESA_{1959}$,$SACZ_{1958}$,$SACZ_{1959}$:#AA0000,#0000AA:1000000.:#00AA00,#AAAA00:-.:,:2.:2.:all:normalized!evolution!of!precipitation!with!CRU-NCEP!forcing:0|10:png:bar-line_rain_CRU-NCEP_norm:yes' 50 51 52 ## 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 53 ## 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 54 ## e.g. # drawing.py -o draw_2D_shad_time -f 'netcdf_concatenated.nc' -S 'dtcon:Time|-1,bottom_top|-1:presmean:time:seismic:-3.e-6,3.e-6:monthly|dtcon:pdf:transpose:time|hours!since!1949-12-01|exct,2,d|%d|date!([DD])|x:True' -v 'dtconmean' 55 ## e.g. # drawing.py -o variable_values -S PSFC 56 ## e.g. # drawing.py -o draw_timeSeries -f wrfout_d01_1979-12-01_00:00:00_bottom_top_B6-E6-I1_south_north_B3-E3-I1_west_east_B26-E26-I1.nc -S 'dt_con:time|($[DD]^{[HH]}$):exct,12,h:$%d^{%H}$:time|evolution|at|-1|6|3|26:1:pdf' -v 'LDQCON,time' 57 ## e.g. # drawing.py -f wrfout_d01_1979-12-01_00:00:00 -o draw_Neighbourghood_evol -S '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' -v QVAPOR 58 ## e.g. # drawing.py -o draw_lines_time -f wrfout_d01_1980-03-01_00:00:00_Time_B0-E48-I1_south_north_B15-E15-I1_west_east_B15-E15-I1.nc -S 'time;y;time ([DD]${[HH]}$);file1;tas;evolution;time|hours!since!1949-12-01_00:00:00|exct,12,h|%d$^{%H}$;pdf' -v T2 59 ## e.g. # drawing.py -o draw_barbs -f ERAI_pl199501_131-132.nc -S 'X|lon|lon|-1,Y|lat|lat|-1,Z|lev|lev|4,T|time|time|0:auto,auto,auto:wind,ms-1:cyl,c:ERA-Interim|winds|at|1000|hPa|on|1996|January|1st|at|00|UTC:pdf:ERAI_pl199501_131-132' -v var131,var132 60 ## e.g. # ~/etudes/WRF_LMDZ/svn/LMDZ_WRF/tools/drawing.py -o draw_points -S 'tslist.dat,#,3,2,1:SuperStorm|sfc|stations:cyl,i:legend:auto:None:0:png:stations_loc' -f $HOME'/etudes/domains/WRFdynamicoSENS_SuperStorm/geo_em.d02.nc,XLONG_M,XLAT_M,HGT_M,Time|0,height,0.,3000.,terrain,m' 61 ## e.g. # drawing.py -o draw_points -S 'tslist.dat,#,3,2,1:SuperStorm|sfc|stations:cyl,i:labelled,8,black:auto:None:0:png:stations_loc' -f $HOME'/etudes/domains/WRFdynamicoSENS_SuperStorm/geo_em_west_east_B25-E180-I1_south_north_B160-E262-I1.nc,XLONG_M,XLAT_M,HGT_M,Time|0,height,0.,1500.,terrain,m' 62 ## e.g. # drawing.py -o draw_ptZvals -f geo_v2_2012102123_RR1.nc -S 'pracc:lon,lat:o:80:2,42,7,47,:values!of!values:Blues:cyl,l:pdf' -v pr 63 ## e.g. # drawing.py -f carteveg5km.nc -o draw_points_lonlat -S 'longitude:latitude:pdf:points!veget|type:green:.:0.5:None:0:legend' 64 ## e.g. # drawing.py -o draw_vectors -f wrfout_d01_2001-11-11_00:00:00 -S 'T|Time|Times|2,Y|south_north|XLAT|-1,X|west_east|XLONG|-1:3@3,wind@rainbow,9:10m wind,ms-1:cyl,l:WRF 10 m winds:pdf:winds' -v U10,V10 65 ## e.g. # drawing.py -o draw_basins -f routing.py -S 'Y|y|nav_lat|-1,X|x|nav_lon|-1:1@1,rainbow,9:basins,-:cyl,l:ORCDHIEE river-basins:pdf:basins_named' -v nav_lon,nav_lat,trip,basins 66 ## e.g. # drawing.py -o draw_river_desc -f diver_desc.nc -S 'Y|lat|lat|-1,X|lon|lon|-1:red,green:Blues:cyl,l:ORCDHIEE rivers:pdf:0:or_rivers -v Amazon 67 ## e.g. # drawing.py -o draw_vertical_levels -f wrfout_d01_2001-11-11_00:00:00 -S 'true:false:wrfout!vertical!levels!(standard!40):png:4' -v WRFz 68 ## e.g. # drawing.py -o draw_subbasin -f Caceres_subbasin.nc -S 'Caceres:None:cyl,l:2,True:Caceres:pdf:0:Caceres_subbasin' 69 ## e.g. # drawing.py -o draw_2lines -f /home/lluis/etudes/WRF_LMDZ/WaquaL_highres/tests/model_graphics/WRF/current/wss_wrfout_tvar_xmean.nc,/home/lluis/etudes/WRF_LMDZ/WaquaL_highres/tests/model_graphics/WRF/current/tas_wrfout_tvar_xmean.nc -v wssvarmean,tasvarmean -S 'lat:0.,20.:0.,4.:-90.,90.:y:wss,tas:red,blue:2.,2.:-:2.,2.:,:wss!tas!mean!meridional!tvar:lon:0:wss_tas_wrfout_tvar_xmean:pdf' 70 ## e.g. # drawing.py -o draw_2lines_time -f /home/lluis/etudes/WRF_LMDZ/WaquaL_highres/tests/model_graphics/WRF/current/wss_wrfout_xvar_ymean.nc,/home/lluis/etudes/WRF_LMDZ/WaquaL_highres/tests/model_graphics/WRF/current/tas_wrfout_xvar_ymean.nc -v wssvarmean,tasvarmean -S 'time:0.,20.:0.,4.:exct,1,d;%d:x:wss,tas:red,blue:2.,2.:-:2.,2.:,:wss!tas!mean!longitudinal!xvar:time!($[DD]$):0:wss_tas_wrfout_xvar_ymean:pdf' 71 50 ## e.g. # drawing.py -o draw_bar_line_time -f 'Forcing_rainstats_OKstomate_SESA_DJFmean_norm_meanstd_stat2.nc;time_centered,-1;time_centered;rainnorm;bar:Forcing_rainstats_OKstomate_SACZ_DJFmean_norm_meanstd_stat2.nc;time_centered,-1;time_centered;rainnorm;bar:DiPolo_evapstats_OKstomate_SESA_DJFmean_stat2.nc;time_centered,-1;time_centered;evap_stats;line:DiPolo_evapnustats_OKstomate_SESA_DJFmean_stat2.nc;time_centered,-1;time_centered;evapnu_stats;line:DiPolo_evspsblvegstats_OKstomate_SESA_DJFmean_stat2.nc;time_centered,-1;time_centered;evspsblveg_stats;line:DiPolo_transpirstats_OKstomate_SESA_DJFmean_stat2.nc;time_centered,-1;time_centered;transpir_stats;line:DiPolo_evapstats_OKstomate_SACZ_DJFmean_stat2.nc;time_centered,-1;time_centered;evap_stats;line:DiPolo_evapnustats_OKstomate_SACZ_DJFmean_stat2.nc;time_centered,-1;time_centered;evapnu_stats;line:DiPolo_evspsblvegstats_OKstomate_SACZ_DJFmean_stat2.nc;time_centered,-1;time_centered;evspsblveg_stats;line:DiPolo_transpirstats_OKstomate_SACZ_DJFmean_stat2.nc;time_centered,-1;time_centered;transpir_stats;line' -S 'auto;pr;y;None;1;year|seconds!since!1958-01-01!00:00:00|exct,5,y|%Y;SESA,SACZ,SESA!evap,evapnu,evspblveg,transpir,SACZ!evap,None,None,None;#AA0000,#0000AA;10000000.;#AAAA00,#00AAAA,#AA00AA,#AAAAAA,#AAAA00,#00AAAA,#AA00AA,#AAAAAA;-,-,-,-,--,--,--,--;,;2.;2.;all;normalized!evolution!of!DJFmean!with!WFD3!forcing;0|10;png;bar_time_rain_CRU-NCEP_DJFmean_norm;yes' 72 51 ####### 73 52 # create_movie: Function to create a movie assuming ImageMagick installed! … … 85 64 # draw_bar_line: Function to plot a bar char and line figure with multiple sources 86 65 # draw_bar_time: Function to plot a bar char figure with multiple sources and time axis 66 # draw_bar_line_time: Function to plot a bar char and line figure with multiple sources with a time-axis 87 67 # draw_barbs: Function to plot wind barbs 88 68 # draw_basins: Function to plot river basins with their discharge vector and basins id (from 'routing.nc') … … 116 96 'draw_2D_shad_cont', 'draw_2D_shad_2cont', 'draw_2D_shad_cont_time', \ 117 97 'draw_2D_shad_line', \ 118 'draw_2D_shad_line_time', 'draw_bar', 'draw_bar_line', 'draw_bar_ time',\119 'draw_bar bs', 'draw_basins',\98 'draw_2D_shad_line_time', 'draw_bar', 'draw_bar_line', 'draw_bar_line_time', \ 99 'draw_bar_time', 'draw_barbs', 'draw_basins', \ 120 100 'draw_2lines', 'draw_2lines_time', 'draw_lines', 'draw_lines_time', \ 121 101 'draw_Neighbourghood_evol', \ … … 6752 6732 dti = mintval 6753 6733 dte = maxtval 6754 tvalsticks = np.arange(dti, dte , dtvals)6734 tvalsticks = np.arange(dti, dte+dtvals, dtvals) 6755 6735 6756 6736 dtiS = drw.datetimeStr_conversion(str(dti) + ',' + timeunit, 'cfTime', \ … … 6764 6744 6765 6745 # ranges 6746 valmin = np.min(yvals) 6747 valmax = np.max(yvals) 6766 6748 if rangevals == 'None': 6767 6749 valmin = np.min(yvals) 6768 6750 valmax = np.max(yvals) 6769 6751 else: 6770 valmin = np.float(rangevals.split(',')[0])6771 valmax = np.float(rangevals.split(',')[1])6772 if valmin == 'auto': valmin = np.min(yvals)6773 if valmax == 'auto': valmax = np.max(yvals)6752 if rangevals.split(',')[0] != 'auto': 6753 valmin = np.float(rangevals.split(',')[0]) 6754 if rangevals.split(',')[1] != 'auto': 6755 valmax = np.float(rangevals.split(',')[1]) 6774 6756 yrange = [valmin, valmax] 6775 6757 … … 6973 6955 valmax = yvsx 6974 6956 else: 6975 valmin = np.float(rangevals.split(',')[0])6976 valmax = np.float(rangevals.split(',')[1])6977 if valmin == 'auto': valmin = yvsn6978 if valmax == 'auto': valmax = yvsx6957 if rangevals.split(',')[0] != 'auto': 6958 valmin = np.float(rangevals.split(',')[0]) 6959 if rangevals.split(',')[1] != 'auto': 6960 valmax = np.float(rangevals.split(',')[1]) 6979 6961 yrange = [valmin, valmax] 6980 6962 … … 7003 6985 7004 6986 return 6987 6988 def draw_bar_line_time(ncfile, values): 6989 """ Function to plot a bar char and lines plot figure with multiple sources and time-axis 6990 ncfile = ':' list of [filen];[dimslice];[xvarn];[yvarn];[kind] 6991 [filen]: name of the file 6992 [dimslice]: '|' list of [dimn],[dimrange] 6993 [dimn]: name of the dimension 6994 [dimrange]: range for the slice 6995 * [integer]: which value of the dimension 6996 * -1: all along the dimension 6997 * -9: last value of the dimension 6998 * [beg]@[end]@[inc] slice from [beg] to [end] every [inc] 6999 * NOTE, no dim name all the dimension size 7000 [tvarn]: name of the variable time 7001 [yvarn]: name of the variable to use for the values 7002 [kind]: Kind of plotting 7003 'bar': for bar-plot 7004 'line': for line-plot 7005 values = [dimxyfmt];[yaxislab];[yunits];[aval];[rangevals];[timevals];[labels]; 7006 [colors];[wdth];[colns];[lines];[points];[lwdths];[psizes];[freqv];[graphtit];[legvalues]; 7007 [kindfig];[fign];[close] 7008 [dimxyfmt]=[dxs],[dxf],[Ndx],[ordx],[dys],[dyf],[Ndy],[ordy]: format of the values at each 7009 axis (or single 'auto' for 'auto','auto') 7010 [dxs]: style of x-axis ('auto' for 'pretty') 7011 'Nfix', values computed at even 'Ndx' 7012 'Stringlist', a given list of strings 7013 'Vfix', values computed at even 'Ndx' increments 7014 'pretty', values computed following aprox. 'Ndx' at 'pretty' intervals (2.,2.5,4,5,10) 7015 [dxf]: format of the labels at the x-axis 7016 [Ndx]: Number of ticks at the x-axis (for 'Stringlist', '@' list of labels) 7017 [ordx]: angle of orientation of ticks at the x-axis ('auto' for horizontal) 7018 [dys]: style of y-axis ('auto' for 'pretty') 7019 [dyf]: format of the labels at the y-axis 7020 [Ndy]: Number of ticks at the y-axis 7021 [ordy]: angle of orientation of ticks at the y-axis ('auto' for horizontal) 7022 [yaxislab]: Label for the y-axis ('!' for spaces) 7023 [yunits]: units of the y-label 7024 [aval]: which acis should be used for the values ('x' or 'y') 7025 [rangevals]: Range of the axis with the values (singel 'None' for 'auto','auto') 7026 [vmin],[vmax]: minimum and maximum values 7027 'auto': the computed minimumm or maximum of the values 7028 [timevals]: [timen]|[units]|[kind]|[tfmt] time labels characteristics 7029 [timen]; name of the time variable 7030 [units]; units string according to CF conventions ([tunits] since 7031 [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces) 7032 [kind]; kind of output 7033 'Nval': according to a given number of values as 'Nval',[Nval] 7034 'exct': according to an exact time unit as 'exct',[tunit]; 7035 tunit= [Nunits],[tu]; [tu]= 'c': centuries, 'y': year, 'm': month, 7036 'w': week, 'd': day, 'h': hour, 'i': minute, 's': second, 7037 'l': milisecond 7038 [tfmt]; desired format 7039 [labels]: ',' list of labels for the legend ('None' for no-labels, '!' for spaces) 7040 [colors]: ',' list of colors (single value same color, 'auto' automatic) 7041 [wdth]: width of the bars 7042 [colns]= ',' list of color names ('None' for automatic, single value for all the same) 7043 [lines]= ',' list of style of lines ('None' for automatic, single value for all the same) 7044 [points]= '@' list of style of points ('None' for automatic, single value for all the same) 7045 [lwdths]= ',' list of withs of lines ('None' for automatic, single value for all the same) 7046 [psizes]= ',' list of size of points ('None' for automatic, single value for all the same) 7047 [freqv]= frequency of values ('all' for all values) 7048 [graphtit]: title of the figure '!' for spaces 7049 [legvalues]=[locleg]|[fontsize]: 7050 [locleg]: location of the legend (0, autmoatic) 7051 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 7052 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', 7053 9: 'upper center', 10: 'center' 7054 [fontsize]: font size for the legend (auto for 12) 7055 [kindfig]: kind of output figure (png, pdf, ps) 7056 [fign]: name of the figure (without extension) 7057 [close]: whether figure should be close or not 7058 """ 7059 fname = 'draw_bar_line_time' 7060 7061 if values == 'h': 7062 print fname + '____________________________________________________________' 7063 print draw_bar_line_time.__doc__ 7064 quit() 7065 7066 expectargs = '[dimxyfmt];[yaxislab];[aval];[rangevals];[yunits];' + \ 7067 '[timevals];[labels];[colors];[wdth];[colns];[lines];[points];' + \ 7068 '[lwdths];[psizes];[freqv];[graphtit];[legvalues];[kindfig];' + \ 7069 '[fign];[close]' 7070 drw.check_arguments(fname,values,expectargs,';') 7071 7072 dimxyfmt = values.split(';')[0] 7073 yaxislab = values.split(';')[1].replace('!',' ') 7074 aval = values.split(';')[2] 7075 rangevals = values.split(';')[3] 7076 yunits = values.split(';')[4] 7077 timevals = values.split(';')[5] 7078 labels = gen.str_list(values.split(';')[6].replace('!', ' '), ',') 7079 colors = gen.str_list(values.split(';')[7], ',') 7080 wdth = np.float(values.split(';')[8]) 7081 colns = gen.str_list(values.split(';')[9], ',') 7082 lines = gen.str_list(values.split(';')[10], ',') 7083 points = gen.str_list(values.split(';')[11], '@') 7084 lwdths = gen.str_list_k(values.split(';')[12], ',', 'R') 7085 psizes = gen.str_list_k(values.split(';')[13], ',', 'R') 7086 freqv0 = values.split(';')[14] 7087 graphtit = values.split(';')[15].replace('!',' ') 7088 legvalues = values.split(';')[16] 7089 kindfig = values.split(';')[17] 7090 fign = values.split(';')[18] 7091 close = gen.Str_Bool(values.split(';')[19]) 7092 7093 # files and values 7094 filedvs = ncfile.split(':') 7095 bartvals = [] 7096 baryvals = [] 7097 linetvals = [] 7098 lineyvals = [] 7099 namebars = [] 7100 namelines = [] 7101 7102 # time-values 7103 expectargs = '[timen]|[units]|[kind]|[tfmt]' 7104 drw.check_arguments('timevals: '+fname,timevals,expectargs,'|') 7105 7106 timen = timevals.split('|')[0].replace('!',' ') 7107 timeunit = timevals.split('|')[1].replace('!',' ') 7108 timekind = timevals.split('|')[2] 7109 timefmt = timevals.split('|')[3] 7110 7111 valmin = gen.fillValueF 7112 valmax = -gen.fillValueF 7113 print ' ' + fname + 'plotting _______' 7114 il = 0 7115 for fdv in filedvs: 7116 filen = fdv.split(';')[0] 7117 dimrange = fdv.split(';')[1] 7118 tvarn = fdv.split(';')[2] 7119 yvarn = fdv.split(';')[3] 7120 plotk = fdv.split(';')[4] 7121 print ' ', filen, 'with', plotk 7122 7123 if not os.path.isfile(filen): 7124 print errormsg 7125 print ' ' + fname + ': file "' + filen + '" does not exist !!' 7126 quit(-1) 7127 7128 onc = NetCDFFile(filen, 'r') 7129 if not onc.variables.has_key(tvarn): 7130 print errormsg 7131 print ' ' + fname + ': file "' + filen + "' does not have variable '" + \ 7132 xvarn + "' for the time-values !!" 7133 print ' available ones:', onc.variables.keys() 7134 onc.close() 7135 quit(-1) 7136 if not onc.variables.has_key(yvarn): 7137 print errormsg 7138 print ' ' + fname + ': file "' + filen + "' does not have variable '" + \ 7139 yvarn + "' for the y-values !!" 7140 print ' available ones:', onc.variables.keys() 7141 onc.close() 7142 quit(-1) 7143 7144 otvar = onc.variables[tvarn] 7145 oyvar = onc.variables[yvarn] 7146 tvs, tdims = ncvar.slice_variable(otvar, dimrange.replace(',',':')) 7147 yvs, ydims = ncvar.slice_variable(oyvar, dimrange.replace(',',':')) 7148 tunitsvar = otvar.units 7149 7150 if len(tvs.shape) != 1: 7151 print errormsg 7152 print ' ' + fname + ': provided slice:', dimrange, "for variable '" + \ 7153 tvarn + "' does not provide a rank-1 value !!" 7154 print ' resultant shape:', tvs.shape, 'dimensions:', tdims, 'fix it!!' 7155 quit(-1) 7156 if len(yvs.shape) != 1: 7157 print errormsg 7158 print ' ' + fname + ': provided slice:', dimrange, "for variable '" + \ 7159 yvarn + "' does not provide a rank-1 value !!" 7160 print ' resultant shape:', yvs.shape, 'dimensions:', ydims, 'fix it!!' 7161 quit(-1) 7162 7163 # time-values 7164 uvd = timeunit 7165 tunitsec = timeunit.split(' ') 7166 if len(tunitsec) == 4: 7167 refdate = tunitsec[2][0:4]+tunitsec[2][5:7]+tunitsec[2][8:10] + \ 7168 tunitsec[3][0:2] + tunitsec[3][3:5] + tunitsec[3][6:8] 7169 else: 7170 refdate = tunitsec[2][0:4]+tunitsec[2][5:7]+tunitsec[2][8:10] + \ 7171 '000000' 7172 tunitsval = tunitsec[0] 7173 # Referring all times to the same reference time! 7174 reftvals = gen.coincident_CFtimes(tvs, timeunit, tunitsvar) 7175 7176 # Location of each kind 7177 if plotk == 'bar': 7178 bartvals.append(list(reftvals)) 7179 baryvals.append(list(yvs)) 7180 if labels is not None: namebars.append(labels[il]) 7181 elif plotk == 'line': 7182 linetvals.append(list(reftvals)) 7183 lineyvals.append(list(yvs)) 7184 if labels is not None: namelines.append(labels[il]) 7185 else: 7186 print errormsg 7187 print ' ' + fname + ": kind of input '" + plotk + "' not ready!!" 7188 print ' available ones:', ['bar', 'line'] 7189 quit(-1) 7190 7191 yvsn = np.min(yvs) 7192 yvsx = np.max(yvs) 7193 if yvsn < valmin: valmin = yvsn 7194 if yvsx > valmax: valmax = yvsx 7195 7196 onc.close() 7197 il = il + 1 7198 7199 # Times 7200 mintval = np.min(bartvals + linetvals) 7201 maxtval = np.max(bartvals + linetvals) 7202 7203 dtvals = (maxtval - mintval)/10. 7204 dti = mintval 7205 dte = maxtval 7206 tvalsticks = np.arange(dti, dte+dtvals, dtvals) 7207 7208 dtiS = drw.datetimeStr_conversion(str(dti) + ',' + timeunit, 'cfTime', \ 7209 'Y/m/d H-M-S') 7210 dteS = drw.datetimeStr_conversion(str(dte) + ',' + timeunit, 'cfTime', \ 7211 'Y/m/d H-M-S') 7212 7213 print ' ' + fname + ': plotting from: ' + dtiS + ' to ' + dteS 7214 7215 timepos, timelabels = drw.CFtimes_plot(tvalsticks, timeunit, timekind, timefmt) 7216 7217 # ranges 7218 if rangevals == 'None': 7219 valmin = valmin 7220 valmax = valmax 7221 else: 7222 if rangevals.split(',')[0] != 'auto': 7223 valmin = np.float(rangevals.split(',')[0]) 7224 if rangevals.split(',')[1] != 'auto': 7225 valmax = np.float(rangevals.split(',')[1]) 7226 yrange = [valmin, valmax] 7227 7228 xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimxyfmt,',') 7229 xaxis = [xstyl, xaxf, Nxax, xaxor] 7230 yaxis = [ystyl, yaxf, Nyax, yaxor] 7231 7232 # Frequqnecy for lines 7233 if freqv0 == 'all': 7234 freqv = None 7235 else: 7236 freqv = int(freqv0) 7237 7238 # Legend 7239 legloc, legsiz = drw.legend_values(legvalues,'|') 7240 7241 # units 7242 dyu = yunits 7243 7244 drw.plot_bars_line_time(bartvals, baryvals, linetvals, lineyvals, timepos, \ 7245 timelabels, yaxis, dyu, aval, yrange, timen, yaxislab, namebars, namelines, \ 7246 colors, wdth, colns, lines, points, lwdths, psizes, freqv, graphtit, legloc, \ 7247 legsiz, kindfig, fign, close) 7248 7249 return 7250 7005 7251 7006 7252 #quit() … … 7026 7272 'draw_2D_shad_cont_time', \ 7027 7273 'draw_2D_shad_line', 'draw_2D_shad_line_time', 'draw_2lines', 'draw_2lines_time', \ 7028 'draw_bar', 'draw_bar_line', 'draw_bar_ time', 'draw_lines',\7274 'draw_bar', 'draw_bar_line', 'draw_bar_line_time', 'draw_bar_time', 'draw_lines', \ 7029 7275 'draw_lines_time', 'draw_points', 'draw_Taylor', 'draw_topo_geogrid_boxes', \ 7030 7276 'draw_trajectories', 'draw_vals_trajectories', 'variable_values'] … … 7086 7332 elif oper == 'draw_bar_line': 7087 7333 draw_bar_line(opts.ncfile, opts.values) 7334 elif oper == 'draw_bar_line_time': 7335 draw_bar_line_time(opts.ncfile, opts.values) 7088 7336 elif oper == 'draw_bar_time': 7089 7337 draw_bar_time(opts.ncfile, opts.values) -
trunk/tools/drawing_tools.py
r1545 r1549 87 87 # plot_bars_line: Function to plot a bar and lines plot with multiple columns 88 88 # plot_bars_time: Function to plot a bar plot with multiple columns with time axis 89 # plot_bars_line: Function to plot a bar and lines plot with multiple columns with a time-axis 89 90 # plot_lines: Function to plot a collection of lines 90 91 # plot_Taylor: Function to draw a Taylor diagram (Taylor 2001) … … 9428 9429 return 9429 9430 9430 9431 9431 def plot_bars_line(bxvalues, byvalues, lxvalues, lyvalues, xaxv, yaxv, dimxu, dimyu, \ 9432 9432 valaxis, valrange, xlabel, ylabel, blabels, llabels, bcols, width, coll, typl, ptl,\ … … 9613 9613 else: 9614 9614 if llabels is not None: 9615 print fname + ': Lluis label:', llabels[iv] 9615 9616 plt.plot(lxvalues[iv], lyvalues[iv], lins[iv], marker=pts[iv], \ 9616 color=cols[iv], label=gen.latex_text( vlabels[iv]), \9617 color=cols[iv], label=gen.latex_text(llabels[iv]), \ 9617 9618 linewidth=lws[iv], markersize=pss[iv], markevery=ptf) 9618 9619 else: … … 9649 9650 return 9650 9651 9651 9652 def plot_bars_line_time(bxvalues, byvalues, lxvalues, lyvalues, tpos, tlabs, yaxv, dimyu, \ 9653 valaxis, valrange, xlabel, ylabel, blabels, llabels, bcols, width, coll, typl, ptl,\ 9654 wdtl, ptz, ptf, gtit, lloc, lsiz, kfig, figname, ifclose): 9655 """ Function to plot a bar and lines plot with multiple columns with a time-axis 9656 bxvalues= list with the values along the x-ais for bar plot 9657 byvalues= list with the values along the y-ais for bar plot 9658 lxvalues= list with the values along the x-ais for lines plot 9659 lyvalues= list with the values along the y-ais for lines plot 9660 tpos= position of the time-ticks 9661 tlabs= labels of the time-ticks 9662 yaxv= values at the axes of y 9663 dimyu= units at the axes of y 9664 valaxis= which axis holds the values 'x' or 'y' 9665 valrange= range of values along the values axis 9666 xlabel= label at the x-axis 9667 ylabel= label at the y-axis 9668 blabels= list of labels for legend (None for no legend) for bars 9669 llabels= list of labels for legend (None for no legend) for lines 9670 bcols= list of colors for the bars (single value for the same, 'auto' for automatic) 9671 width= size of the column 9672 coll= ',' list of colors for the lines, 'None' for automatic, single 9673 value all the same 9674 typl= ',' list of type for the lines, 'None' for automatic, single 9675 value all the same 9676 ptl= ',' list of type of points for the lines, 'None' for automatic, single 9677 value all the same 9678 wdtl= ',' list of width for the lines, 'None' for automatic, single 9679 value all the same 9680 ptz= ',' list of size of points for the lines, 'None' for automatic, single 9681 value all the same 9682 ptf= frequency of point plotting, 'all' for all time steps 9683 gtit= title of the figure 9684 lloc= location of the legend (0, autmoatic) 9685 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 9686 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', 9687 9: 'upper center', 10: 'center' 9688 lsiz= font size of the legend 9689 kfig= kind of output: pdf, png, ps 9690 figname= name of the figure 9691 ifclose= whether figure should be closed 9692 """ 9693 fname = 'plot_bars_line_time' 9694 9695 bNvalues = len(bxvalues) 9696 lNvalues = len(lxvalues) 9697 9698 if lNvalues > 0: 9699 # Lines' characteristics 9700 cols, lins, pts, lws, pss = ColorsLinesPointsStyles(lNvalues, coll, typl, \ 9701 ptl, wdtl, ptz, ptf) 9702 9703 # Maximum number of values: 9704 Lmaxvals = -10 9705 if bNvalues > 0: 9706 xticks = bxvalues[0] 9707 for iv in range(bNvalues): 9708 if len(bxvalues[iv]) > Lmaxvals: Lmaxvals = len(bxvalues[iv]) 9709 NOTcoinc = list(set(bxvalues[iv]).difference(set(xticks))) 9710 if len(NOTcoinc) != 0: 9711 xticks = xticks + NOTcoinc 9712 xticks.sort() 9713 if lNvalues > 0: 9714 if bNvalues == 0: xticks = lxvalues[0] 9715 for iv in range(lNvalues): 9716 if len(lxvalues[iv]) > Lmaxvals: Lmaxvals = len(lxvalues[iv]) 9717 NOTcoinc = list(set(lxvalues[iv]).difference(set(xticks))) 9718 if len(NOTcoinc) != 0: 9719 xticks = xticks + NOTcoinc 9720 xticks.sort() 9721 9722 dxn = np.min([bxvalues, lxvalues]) 9723 dxx = np.max([bxvalues, lxvalues]) 9724 dyn = valrange[0] 9725 dyx = valrange[1] 9726 9727 if yaxv[0] == 'pretty': 9728 dimyt = np.array(gen.pretty_int(dyn,dyx,yaxv[2])) 9729 dimyl = np.array(dimyt, dtype=str) 9730 elif yaxv[0] == 'Nfix': 9731 dimyt = np.arange(0.,1.,1./(yaxv[2]+1)) 9732 dimyl = np.arange(0.,1.,1./varsv.shape[0]) 9733 axytype='fixpixel' 9734 elif yaxv[0] == 'Vfix': 9735 dynvfix = int(dyn/yaxv[2]) 9736 dimyt = np.arange(dynvfix*xaxv[2],dyx,yaxv[2]) 9737 axytype='data' 9738 else: 9739 print errormsg 9740 print ' ' + fname + ": x-xais style '" + xaxv[0] + "' not ready !!" 9741 print ' available ones: ', axstyles 9742 quit(-1) 9743 9744 if valaxis == 'x': 9745 orient = 'horizontal' 9746 else: 9747 orient = 'vertical' 9748 9749 bcolvs = [] 9750 if len(bcols) == 1: 9751 if cols[0] == 'auto': 9752 bcolvs = colorsauto[0:bNvalues+1] 9753 else: 9754 for ic in range(bNvalues): bcolvs.append(bcols[0]) 9755 else: 9756 bcolvs = bcols 9757 9758 if bNvalues > 0: 9759 for iv in range(bNvalues): 9760 xvls = bxvalues[iv] 9761 Lvalues = len(xvls) 9762 dxmean = np.mean(np.array(xvls[1:Lvalues])-np.array(xvls[0:Lvalues-1])) 9763 if dxmean < width*bNvalues: 9764 print warnmsg 9765 print ' ' + fname + ': mean distance among x-values:', dxmean, \ 9766 'is smaller than the total number of bars with the given witdh (', \ 9767 width, '):', width*bNvalues 9768 print ' reduce widht of the column, should not be larger than:', \ 9769 dxmean/bNvalues 9770 if width*bNvalues < 0.01*dxmean: 9771 print warnmsg 9772 print ' ' + fname + ': mean distance among x-values:', dxmean, \ 9773 'is 100-times larger than the total number of bars with the given'+\ 9774 ' witdh (', width, '):', width*bNvalues 9775 print ' increase widht of the column, should not be smaller ' + \ 9776 'than:', 0.01*dxmean 9777 9778 # Relative position of the column respect the xtick 9779 if np.mod(bNvalues,2) == 0: 9780 xrel = width*(iv - bNvalues/2.) 9781 else: 9782 xrel = width*(iv - (bNvalues-1)/2.) 9783 9784 xrels = xrel*np.ones((Lvalues),dtype=np.float) 9785 9786 if valaxis == 'x': 9787 if blabels is not None and blabels[iv] != 'None': 9788 plt.barh(xvls+xrels, byvalues[iv], height=width,color=bcolvs[iv],\ 9789 label=gen.latex_text(blabels[iv])) 9790 else: 9791 plt.barh(xvls+xrels, byvalues[iv], height=width, color=bcolvs[iv]) 9792 else: 9793 if blabels is not None and blabels[iv] != 'None': 9794 plt.bar(xvls+xrels, byvalues[iv], width=width, color=bcolvs[iv], \ 9795 label=gen.latex_text(blabels[iv])) 9796 else: 9797 plt.bar(xvls+xrels, byvalues[iv], width=width, color=bcolvs[iv]) 9798 9799 if lNvalues > 0: 9800 for iv in range(lNvalues): 9801 if valaxis == 'x': 9802 if llabels is not None and llabels[iv] != 'None': 9803 plt.plot(lyvalues[iv], lxvalues[iv], lins[iv], marker=pts[iv], \ 9804 color=cols[iv], label=gen.latex_text(llabels[iv]), \ 9805 linewidth=lws[iv], markersize=pss[iv], markevery=ptf) 9806 else: 9807 plt.plot(lyvalues[iv], lxvalues[iv], lins[iv], marker=pts[iv], \ 9808 color=cols[iv],linewidth=lws[iv], markersize=pss[iv], \ 9809 markevery=ptf) 9810 else: 9811 if llabels is not None and llabels[iv] != 'None': 9812 plt.plot(lxvalues[iv], lyvalues[iv], lins[iv], marker=pts[iv], \ 9813 color=cols[iv], label=gen.latex_text(llabels[iv]), \ 9814 linewidth=lws[iv], markersize=pss[iv], markevery=ptf) 9815 else: 9816 plt.plot(lxvalues[iv], lyvalues[iv], lins[iv], marker=pts[iv], \ 9817 color=cols[iv],linewidth=lws[iv], markersize=pss[iv], \ 9818 markevery=ptf) 9819 9820 if valaxis == 'x': 9821 plt.xticks(dimyt, dimyl, rotation=yaxv[3]) 9822 plt.yticks(tpos, tlabs, rotation=0) 9823 plt.xlabel(gen.latex_text(ylabel) + ' (' + units_lunits(dimyu) + ')') 9824 plt.ylabel(gen.latex_text(xlabel)) 9825 plt.xlim(dyn, dyx) 9826 else: 9827 plt.xticks(tpos, tlabs, rotation=0) 9828 plt.yticks(dimyt, list(dimyl), rotation=yaxv[3]) 9829 plt.xlabel(gen.latex_text(xlabel)) 9830 plt.ylabel(ylabel + ' (' + units_lunits(dimyu) + ')') 9831 plt.ylim(dyn, dyx) 9832 9833 if blabels is not None or llabels is not None: 9834 plt.legend(loc=lloc, prop={'size':lsiz}) 9835 9836 plt.title(gen.latex_text(gtit)) 9837 9838 output_kind(kfig, figname, ifclose) 9839 9840 return 9841 9842
Note: See TracChangeset
for help on using the changeset viewer.