Changeset 1468 in lmdz_wrf
- Timestamp:
- Mar 21, 2017, 10:34:04 PM (8 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r1466 r1468 1 # -*- coding: iso-8859-15 -*- 1 2 # Python to manage plot data in netCDF files. 2 3 # From L. Fita work in different places: LMD (France) … … 39 40 ## e.g. # drawing.py -o draw_ptZvals -f MountainPeaks.nc -S 'height:lon,lat:auto:x:5.:-180.,-90.,180.,90.:0,9000.:ptlabel,name,8,0,4:Mountain!peaks:rainbow,auto,auto:cyl,l:png:yes' -v height 40 41 ## e.g. # drawing.py -o draw_vectors -f wrfout_d01_1995-01-01_00:00:00 -S 'T|Time|Times|2,Y|south_north|XLAT|-1,X|west_east|XLONG|-1:auto:3@3,wind@rainbow@Srange|Srange,9:10m wind,ms-1:cyl,l:WRF!10!m!winds!on!Dec.!1st!1995!06!UTC:png:winds:yes' -v U10,V10 42 ## e.g.# drawing.py -o draw_vertical_levels -f wrfout_d01_1995-01-01_00:00:00 -S 'true,true:false,false:wrfout!vertical!levels!(LUPA):png:4|12:yes' -v WRFz 43 ## e.g. # drawing.py -o draw_subbasin -f Caceres_subbasin.nc -S 'Caceres:None:cyl,l:2:True:Parana!subbasins!from!Cáceres:png:0:Caceres_subbasin:True:True' 44 ## e.g. # drawing.py -o draw_basins -f routing.nc -S '-5,5,42.,52.:l:rainbow,auto,auto:1,1000:True:True:True:ORCDHIEE|river-basins:png:basins_named:True' -v nav_lon,nav_lat,trip,basins 45 ## e.g. # drawing.py -o draw_river_desc -f river_desc.nc -S 'Y|lat|lat|-1,X|lon|lon|-1:red,green:Blues:cyl,l:ORCDHIEE|rivers:png:0:or_rivers:True' -v Amazon,Parana 46 41 47 42 48 … … 4548 4554 return 4549 4555 4550 def draw_basins(ncfile, values , varns):4551 """ Function to plot river basins with their discharge vector and basins id (from 'routing.nc' )4552 values= [lonlatbox]:[mapres]:[c barname]:[xtrmbasin]:[mapdraw]:[veclength]:[freq]:4553 [ifreq]:[plotcountry]:[basinidn]:[gtit]:[kindfig]:[figuren]4556 def draw_basins(ncfile, values): 4557 """ Function to plot river basins with their discharge vector and basins id (from 'routing.nc' - ORCHIDEE routing output) 4558 values= [lonlatbox]:[mapres]:[colorbarvals]:[xtrmbasin]:[mapdraw]:[veclength]:[plotcountry]:[basinidn]: 4559 [gtit]:[kindfig]:[figuren] 4554 4560 [lonlatbox]= [lonSW],[lonNE],[latSW],[latNE] coordinates of the lon/lat box 4555 [mapres]= resolution of the mapping information 4556 [cbarname]= colorbar name for the colors 4557 [xtrmbasin]= [minbasin],[maxbasin] minimum and maximum basin numbers 4561 [mapres]= resolution of the mapping information to lon/lat 4562 * 'c': cure 4563 * 'l': low 4564 * 'i': intermediate 4565 * 'h': high 4566 * 'f': full 4567 [colorbarvals] = [cbarname],[fmtcolorbar],[orientation] 4568 [cbarname]: colorbar name for the colors 4569 [fmtcolorbar]: format of the numbers in the color bar 'C'-like ('auto' for %6g) 4570 [orientation]: orientation of the colorbar ('vertical' (default, by 'auto', 'horizontal') 4571 [xtrmbasin]= [minbasin],[maxbasin] minimum and maximum basin numbers to define color range 4558 4572 [mapdraw]= whether to draw the map (and project the data) or not ('True/False') 4559 [veclength]= length of the vectors of discharge at each grid cell4560 [freq]= frequency of values allong each axis (None, all grid points;4561 'auto', computed automatically to have 20 vectors along each axis)4562 4573 [plotcountry]= whether country lines should be plotted or not ('True/False') 4563 4574 [plotbasinid]= whether id of the basins should be plotted or not ('True/False') … … 4565 4576 [kindfig]= kind of figure 4566 4577 [figuren]= name of the figure 4578 [closefig]= whether figure should be closed or not 4567 4579 ncfile= file to use 4568 4580 """ … … 4575 4587 4576 4588 expectargs = '[lonlatbox]:[mapres]:[cbarname]:[xtrmbasin]:[mapdraw]:' + \ 4577 '[ veclength]:[freq]:[plotcountry]:[basinidn]:[gtit]:[kindfig]:[figuren]'4589 '[plotcountry]:[basinidn]:[gtit]:[kindfig]:[figuren]:[closefig]' 4578 4590 4579 4591 drw.check_arguments(fname,values,expectargs,':') … … 4592 4604 latlims.append(np.float(values.split(':')[0].split(',')[3])) 4593 4605 map_res = values.split(':')[1] 4594 c barname= values.split(':')[2]4606 colorbarvals = values.split(':')[2] 4595 4607 vtit = 'basins' 4596 4608 minbasin = np.int(values.split(':')[3].split(',')[0]) 4597 4609 maxbasin = np.int(values.split(':')[3].split(',')[1]) 4598 4610 mapdraw = gen.Str_Bool(values.split(':')[4]) 4599 veclength = np.float(values.split(':')[5]) 4600 freq0 = values.split(':')[6] 4601 plotcountry = gen.Str_Bool(values.split(':')[7]) 4602 plotbasinid = gen.Str_Bool(values.split(':')[8]) 4603 gtit = values.split(':')[9].replace('|',' ') 4604 kindfig = values.split(':')[10] 4605 figuren = values.split(':')[11] 4606 4607 if freq0 == 'None': freq = None 4611 plotcountry = gen.Str_Bool(values.split(':')[5]) 4612 plotbasinid = gen.Str_Bool(values.split(':')[6]) 4613 gtit = values.split(':')[7].replace('|',' ') 4614 kindfig = values.split(':')[8] 4615 figuren = values.split(':')[9] 4616 closefig = gen.Str_Bool(values.split(':')[10]) 4608 4617 4609 4618 ofile = NetCDFFile(ncfile, 'r') … … 4625 4634 4626 4635 imin, imax, jmin, jmax = gen.ijlonlat(lon, lat, nlon, xlon, nlat, xlat) 4636 4637 colbarn, fmtcolbar, colbaror = drw.colorbar_vals(colorbarvals,',') 4627 4638 4628 4639 drw.plot_basins(lon[jmin:jmax,imin:imax], lat[jmin:jmax,imin:imax], \ 4629 oflow[jmin:jmax,imin:imax], freq, cbarname+'@basin@-',\4630 obasins[jmin:jmax,imin:imax], veclength, minbasin, maxbasin, 'outflow', '-',\4631 'cyl,'+map_res, plotcountry, plotbasinid, gtit, kindfig, figuren )4640 oflow[jmin:jmax,imin:imax], colbarn+'@basin@-', fmtcolbar, colbaror, \ 4641 obasins[jmin:jmax,imin:imax], minbasin, maxbasin, 'outflow', '-', \ 4642 'cyl,'+map_res, plotcountry, plotbasinid, gtit, kindfig, figuren, closefig) 4632 4643 4633 4644 ofile.close() … … 4791 4802 4792 4803 def draw_river_desc(ncfile, values, riverns): 4793 """ Function to plot rivers' description from ORCHIDEE's routing scheme 4804 """ Function to plot rivers' description from ORCHIDEE's routing scheme file ('river_desc.nc') 4794 4805 values= [dimname]|[vardimname]|[value]:[basinvals]:[upstreamvals]:[mapvalues]: 4795 [gtit]:[kindfig]:[legvals]:[figuren] 4806 [gtit]:[kindfig]:[legvals]:[figuren]:[closefig] 4796 4807 'X/Y'|[dimname]|[vardimname]|[value]: ',', list for each basic dimension '|' separated of: 4797 [dimname] : name of the dimension in the file4808 [dimname]= name of the dimension in the file for 'X' and 'Y' axis 4798 4809 [vardimname]: name of the variable with the values for the dimension in the file 4799 4810 [value]: which value of the given dimension is required: … … 4804 4815 * NOTE, no dim name all the dimension size 4805 4816 No value takes all the range of the dimension 4806 [basinsvals]= [colorline] 4817 [basinsvals]= [colorline] colors for the border line of each basin 4807 4818 [basincolor]: ',' list of colors of the line to use to mark the basins contours (single value also possible) 4808 [upstreamvals]= [upstreamvarn],[colorbar] 4809 [upstreamcolor]: colorbar to use to plot the basins upstream values 4819 [upstreamvals]= [upstreamcolor]: colorbar to use to plot the basins upstream values 4810 4820 [mapvalues]= map characteristics: [proj],[res] 4811 4821 see full documentation: http://matplotlib.org/basemap/ … … 4819 4829 * 'h', high 4820 4830 * 'f', full 4821 gtit= title of the graph ('|', for spaces)4822 kindfig= kind of figure4831 [gtit]= title of the graph ('|', for spaces) 4832 [kindfig]= kind of figure (png, ps, pdf) 4823 4833 [legvals]=[locleg]|[fontsize]: 4824 4834 [locleg]: location of the legend (0, autmoatic) … … 4827 4837 9: 'upper center', 10: 'center' 4828 4838 [fontsize]: font size for the legend (auto for 12) 4829 figuren= name of the figure 4839 [figuren]= name of the figure 4840 [closefig]= whether figure should be closed or not 4830 4841 ncfile= file to use 4831 4842 riverns= ',' list of the name of the rivers to plot … … 4840 4851 4841 4852 expectargs = '[X/Y/Z/T]|[dimname]|[vardimname]|[value]:[basinvals]:' + \ 4842 '[upstreamvals]:[mapvalues]:[gtit]:[kindfig]:[legloc]:[figuren] '4853 '[upstreamvals]:[mapvalues]:[gtit]:[kindfig]:[legloc]:[figuren]:[closefig]' 4843 4854 4844 4855 drw.check_arguments(fname,values,expectargs,':') … … 4848 4859 upstreamvals = values.split(':')[2] 4849 4860 mapvals = values.split(':')[3] 4850 gtit = values.split(':')[4] 4861 gtit = values.split(':')[4].replace('|',' ') 4851 4862 kindfig = values.split(':')[5] 4852 4863 legloc = int(values.split(':')[6]) 4853 4864 figuren = values.split(':')[7] 4865 closefig = gen.Str_Bool(values.split(':')[8]) 4854 4866 4855 4867 basincol = basinvals … … 4970 4982 4971 4983 drw.plot_river_desc(malonvals, malatvals, rivers, riversubbasins, riversupstream, riversoutflow, \ 4972 basincolor, upstreamcolor, uunits, mapvalues, gtit, kindfig, legloc, figuren )4984 basincolor, upstreamcolor, uunits, mapvalues, gtit, kindfig, legloc, figuren, closefig) 4973 4985 4974 4986 of.close() 4975 4987 4976 4988 def draw_vertical_levels(ncfile, values, varn): 4977 """ plotting vertical levels distribution4989 """ plotting distribution of vertical levels 4978 4990 draw_vertical_levels(ncfile, values, varn) 4979 4991 ncfile= file to use 4980 values= [zlogs]:[plogs]:[title]:[graphic_kind]:[legvals] 4981 zlogs= zlog,dzlog4982 zlog: to use logarithmic scale on the height axis ('true/false')4983 dzlog: to use logarithmic scale on the difference of height between levels axis ('true/false')4984 plogs= plog,dplog4985 plog: to use logarithmic scale on the height axis ('true/false')4986 dplog: to use logarithmic scale on the difference of height between levels axis ('true/false')4987 title:title of the graph ('!' for spaces)4988 graphic_kind:kind of figure (jpg, pdf, png)4992 values= [zlogs]:[plogs]:[title]:[graphic_kind]:[legvals]:[closefig] 4993 [zlogs]= zlog,dzlog 4994 zlog: to use logarithmic scale on the height axis ('true/false') 4995 dzlog: to use logarithmic scale on the difference of height between levels axis ('true/false') 4996 [plogs]= plog,dplog 4997 plog: to use logarithmic scale on the height axis ('true/false') 4998 dplog: to use logarithmic scale on the difference of height between levels axis ('true/false') 4999 [title]= title of the graph ('!' for spaces) 5000 [graphic_kind]= kind of figure (jpg, pdf, png) 4989 5001 [legvals]=[locleg]|[fontsize] 4990 5002 [locleg]: location of the legend (0, autmoatic) … … 4993 5005 9: 'upper center', 10: 'center' 4994 5006 [fontsize]: font size for the legend (auto for 12) 5007 [closefig]= whether figures should be closed or not 4995 5008 varn= [varnheight],[varnpres] 4996 varnheight: name of the variable with the height of the vertical levels5009 [varnheight]: name of the variable with the height of the vertical levels 4997 5010 'WRFz': for WRF z-levels (computed as (PH + PHB)/g, from a PHB(0,i,j) = 0) 4998 varnpres: name of the variable with the pressure of the vertical levels ('None', for no pressure plot)5011 [varnpres]: name of the variable with the pressure of the vertical levels ('None', for no pressure plot) 4999 5012 'WRFp': for WRF p-levels (computed as P + PB, from a PHB(0,i,j) = 0) 5000 5013 """ … … 5006 5019 quit() 5007 5020 5008 expectargs = '[zlogs]:[plogs]:[title]:[graphic_kind]:[legloc] '5021 expectargs = '[zlogs]:[plogs]:[title]:[graphic_kind]:[legloc]:[closefig]' 5009 5022 5010 5023 drw.check_arguments(fname,values,expectargs,':') 5011 5024 5012 zlog = values.split(':')[0].split(',')[0]5013 dzlog = values.split(':')[0].split(',')[1]5014 plog = values.split(':')[1].split(',')[0]5015 dplog = values.split(':')[1].split(',')[1]5025 zlogv = gen.Str_Bool(values.split(':')[0].split(',')[0]) 5026 dzlogv = gen.Str_Bool(values.split(':')[0].split(',')[1]) 5027 plogv = gen.Str_Bool(values.split(':')[1].split(',')[0]) 5028 dplogv = gen.Str_Bool(values.split(':')[1].split(',')[1]) 5016 5029 title = values.split(':')[2].replace('!',' ') 5017 5030 kindfig = values.split(':')[3] 5018 5031 legvals = values.split(':')[4] 5032 closefig = gen.Str_Bool(values.split(':')[5]) 5019 5033 5020 5034 if varn.find(',') == -1: … … 5136 5150 pvals = objvar[:] 5137 5151 5138 # Logarithmic axes5139 if zlog == 'true':5140 zlogv = True5141 elif zlog == 'false':5142 zlogv = False5143 else:5144 print errormsg5145 print ' ' + fname + ": wrong value for zlog: '" + zlog + "' !!"5146 print " must be either: 'true' or 'false'"5147 quit(-1)5148 5149 if dzlog == 'true':5150 dzlogv = True5151 elif dzlog == 'false':5152 dzlogv = False5153 else:5154 print errormsg5155 print ' ' + fname + ": wrong value for dzlog: '" + dzlog + "' !!"5156 print " must be either: 'true' or 'false'"5157 quit(-1)5158 5159 if pvals is not None:5160 if plog == 'true':5161 plogv = True5162 elif plog == 'false':5163 plogv = False5164 else:5165 print errormsg5166 print ' ' + fname + ": wrong value for plog: '" + plog + "' !!"5167 print " must be either: 'true' or 'false'"5168 quit(-1)5169 if dplog == 'true':5170 dplogv = True5171 elif dplog == 'false':5172 dplogv = False5173 else:5174 print errormsg5175 print ' ' + fname + ": wrong value for dplog: '" + dplog + "' !!"5176 print " must be either: 'true' or 'false'"5177 quit(-1)5178 5152 5179 5153 # Legend values … … 5181 5155 5182 5156 drw.plot_vertical_lev(zvals, pvals, zlogv, dzlogv, plogv, dplogv, title, kindfig,\ 5183 legloc, legsize )5157 legloc, legsize, closefig) 5184 5158 5185 5159 objf.close() … … 5188 5162 5189 5163 def draw_subbasin(ncfile, values): 5190 """ Function to plot subbasin from 'routnig.nc' ORCDHIEE 5191 ncfile= file to use produced with nc_var.py#subbasin function 5192 values= [subasiname]:[rangecolors]:[mapv]:[basinlinewidth]:[drawsubid]:[gtit]:[figkind]:[legvals]:[figurename] 5164 """ Function to plot subbasin from a given point of its discharge from 'routing.nc' ORCDHIEE file 5165 Each river is composed of different subbasins. Grouped up-flow. This function use a different color 5166 for the first level of suubbasins, and a different degree of color for the sub-subbasins of the first level 5167 It takes output from `subbasin' function from 'nc_var.py' 5168 ncfile= file to use produced with nc_var.py#subbasin function 5169 values= [subasiname]:[rangecolors]:[mapv]:[basinlinewidth]:[drawsubid]:[gtit]:[figkind]:[legvals]:[figurename]: 5170 [drawrivers]:[closefig] 5193 5171 [subasiname]= name of the subbasin ('!' for spaces) 5194 5172 [rcolor]= '@', list of 'r|g|b' 1-based colors (as much as first level sub-flow). 'None' for automatic … … 5214 5192 [fontsize]: font size for the legend (auto for 12) 5215 5193 [figname]= name of the figure 5194 [drawrivers]= whether rivers from pythons' data-based have to be added or not 5195 [closefig]= whether figures should be closed or not 5216 5196 """ 5217 5197 fname = 'draw_subbasin' … … 5223 5203 5224 5204 expectargs = '[subasiname]:[rangecolors]:[mapv]:[basinlinewidth]:[drawsubid]:' + \ 5225 '[gtit]:[figkind]:[legloc]:[figurename] '5205 '[gtit]:[figkind]:[legloc]:[figurename]:[drawrivers]:[closefig]' 5226 5206 5227 5207 drw.check_arguments(fname,values,expectargs,':') … … 5236 5216 legloc = int(values.split(':')[7]) 5237 5217 figurename = values.split(':')[8] 5218 drawrivers = gen.Str_Bool(values.split(':')[9]) 5219 closefig = gen.Str_Bool(values.split(':')[10]) 5238 5220 5239 5221 if not os.path.isfile(ncfile): … … 5293 5275 5294 5276 drw.plot_subbasin(subbasiname, lon, lat, subnames, latlonsub, outflowsub, \ 5295 rangecols, mapv, basinlinewidth, drawsubid, gtit, figkind, legloc, figurename) 5277 rangecols, mapv, basinlinewidth, drawsubid, gtit, figkind, legloc, figurename, \ 5278 drawrivers, closefig) 5296 5279 5297 5280 objf.close() … … 6513 6496 draw_barbs(opts.ncfile, opts.values, opts.varname) 6514 6497 elif oper == 'draw_basins': 6515 draw_basins(opts.ncfile, opts.values , opts.varname)6498 draw_basins(opts.ncfile, opts.values) 6516 6499 elif oper == 'draw_Neighbourghood_evol': 6517 6500 draw_Neighbourghood_evol(opts.ncfile, opts.values, opts.varname) -
trunk/tools/drawing_tools.py
r1466 r1468 7110 7110 return 7111 7111 7112 def plot_basins(xvals, yvals,fvals,vecfreq,vecoln,veccolor,veclength,vcolmin,vcolmax,windn,wuts,\7113 mapv,drawcountry,basinid,graphtit,kfig,figname):7114 """ Function to plot vectors7112 def plot_basins(xvals, yvals, fvals, vecoln, fmtcol, orcol, veccolor, vcolmin, \ 7113 vcolmax, windn, wuts, mapv, drawcountry, basinid, graphtit, kfig, figname, fclose): 7114 """ Function to plot the rivers from the ORCHIDEE data file `routing.nc' with their upstream flow shaded 7115 7115 xvals= values for the x-axis 7116 7116 yvals= values for the y-axis 7117 7117 fvals= values for the flow (1-8: N, NE, E, ..., NW; 97: sub-basin; 98: small to sea; 99: large to sea) 7118 vecfreq= [xfreq],[yfreq] frequency of values allong each axis (None, all grid points; 7119 'auto', computed automatically to have 20 vectors along each axis) 7120 veccoln= name for the color of the vectors (as '3rdvar@[basinsvar]@[varn]@[units]' from plot_vector) 7121 veccolor= color of the vectors 7122 veclength= length of the wind vectors: 7123 'singlecol': 'auto', for 9 7124 'wind' and '3rdvar': 'auto' length as wind speed, otherwise fix length 7118 vecoln= name for the color of the vectors (as '3rdvar@[basinsvar]@[varn]@[units]' from plot_vector) 7119 fmtcol= format of the labels at the color bar 7120 orcol= orientation of the color bar 7121 veccolor= color of the vectors 7125 7122 windn= name of the wind variable in the graph 7126 7123 wuts= units of the wind variable in the graph … … 7141 7138 kfig= kind of figure 7142 7139 figname= name of the figure 7140 fclose= whether figures should be close or not 7143 7141 """ 7144 7142 fname = 'plot_basins' … … 7147 7145 dy=xvals.shape[0] 7148 7146 7149 # Frequency of vectors 7150 if vecfreq is None: 7151 xfreq = 1 7152 yfreq = 1 7153 elif vecfreq == 'auto': 7154 xfreq = dx/20 7155 yfreq = dy/20 7156 else: 7157 xfreq=int(vecfreq.split('@')[0]) 7158 yfreq=int(vecfreq.split('@')[1]) 7159 7160 # Vector length 7161 if veclength == 'auto': 7162 vlength = 9 7163 else: 7164 vlength = veclength 7147 vlength = 9. 7165 7148 7166 7149 # flow direction 7167 angle = (fvals[: :yfreq,::xfreq] - 1)*np.pi/47168 uvals = np.where(fvals[: :yfreq,::xfreq] < 9, np.float(veclength)*np.sin(angle), 0.)7169 vvals = np.where(fvals[: :yfreq,::xfreq] < 9, np.float(veclength)*np.cos(angle), 0.)7150 angle = (fvals[:] - 1)*np.pi/4 7151 uvals = np.where(fvals[:] < 9, np.float(vlength)*np.sin(angle), 0.) 7152 vvals = np.where(fvals[:] < 9, np.float(vlength)*np.cos(angle), 0.) 7170 7153 7171 7154 # Colors … … 7195 7178 flowvals = [] 7196 7179 7197 for j in range(0,dy ,yfreq):7198 for i in range(0,dx ,xfreq):7180 for j in range(0,dy): 7181 for i in range(0,dx): 7199 7182 if veccolor[j,i] != '--': 7200 7183 xlabpos.append(xvals[j,i]) … … 7211 7194 map_res=mapv.split(',')[1] 7212 7195 7213 nlon = np.min(xvals[: :yfreq,::xfreq])7214 xlon = np.max(xvals[: :yfreq,::xfreq])7215 nlat = np.min(yvals[: :yfreq,::xfreq])7216 xlat = np.max(yvals[: :yfreq,::xfreq])7196 nlon = np.min(xvals[:]) 7197 xlon = np.max(xvals[:]) 7198 nlat = np.min(yvals[:]) 7199 xlat = np.max(yvals[:]) 7217 7200 7218 7201 lon2 = xvals[dy/2,dx/2] … … 7247 7230 plt.ylabel('S-N') 7248 7231 7249 if veclength != 'auto': 7250 wind = np.sqrt(uvals**2 + vvals**2) 7251 uvals = np.where(wind == 0., 0., uvals) 7252 vvals = np.where(wind == 0., 0., vvals) 7253 uvals = np.float(veclength)*uvals/wind 7254 vvals = np.float(veclength)*vvals/wind 7255 7256 vecolorvals = veccolor[::yfreq,::xfreq] 7232 # if veclength != 'auto': 7233 # wind = np.sqrt(uvals**2 + vvals**2) 7234 # uvals = np.where(wind == 0., 0., uvals) 7235 # vvals = np.where(wind == 0., 0., vvals) 7236 # uvals = np.float(veclength)*uvals/wind 7237 # vvals = np.float(veclength)*vvals/wind 7238 wind = np.sqrt(uvals**2 + vvals**2) 7239 uvals = np.where(wind == 0., 0., uvals) 7240 vvals = np.where(wind == 0., 0., vvals) 7241 uvals = np.float(vlength)*uvals/wind 7242 vvals = np.float(vlength)*vvals/wind 7243 7244 vecolorvals = veccolor[:] 7257 7245 vecolorvals = np.where(vecolorvals < vcolmin, vcolmin - 1, vecolorvals) 7258 7246 vecolorvals = np.where(vecolorvals > vcolmax, vcolmax + 1, vecolorvals) 7259 7247 7260 # plt.quiver(xvals[::yfreq,::xfreq], yvals[::yfreq,::xfreq], \ 7261 # uvals[::yfreq,::xfreq], vvals[::yfreq,::xfreq], veccolor[::yfreq,::xfreq], \ 7262 # cmap=plt.get_cmap(vcolor), pivot='middle') 7263 plt.quiver(xvals[::yfreq,::xfreq], yvals[::yfreq,::xfreq], \ 7264 uvals[::yfreq,::xfreq], vvals[::yfreq,::xfreq], vecolorvals, \ 7248 plt.quiver(xvals[:], yvals[:], uvals[:], vvals[:], vecolorvals, \ 7265 7249 cmap=plt.get_cmap(vcolor), pivot='middle') 7266 cbar = plt.colorbar() 7250 if orcol == 'horizontal': 7251 cbar = plt.colorbar(format=fmtcol,orientation=orcol) 7252 # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tik-labels-in-matplotlib 7253 ticklabels= cbar.ax.get_xticklabels() 7254 Nticks = len(ticklabels) 7255 ticklabs = [] 7256 for itick in range(Nticks): ticklabs.append(ticklabels[itick].get_text()) 7257 cbar.ax.set_xticklabels(ticklabs,rotation=90) 7258 else: 7259 cbar = plt.colorbar(format=fmtcol,orientation=orcol) 7267 7260 7268 7261 vN = vecoln.split('@')[1] … … 7272 7265 if basinid: 7273 7266 for i in range(len(xlabpos)): 7274 plt.text(xlabpos[i]+0.5*ddx, ylabpos[i]+0.95*ddy, labels[i], \ 7275 color=labcol[i], fontdict=fontcharac) 7276 7267 plt.text(xlabpos[i]+0.5*ddx, ylabpos[i]+0.95*ddy, \ 7268 gen.latex_text(labels[i]), color=labcol[i], fontdict=fontcharac) 7277 7269 # Sea-flow 7278 7270 for i in range(len(xlabpos)): … … 7285 7277 7286 7278 plt.annotate(windn.replace('_','\_') +' (' + units_lunits(wuts) + ')', \ 7287 xy=(0.80,-0. 15), xycoords='axes fraction', color='black')7288 7289 plt.title(g raphtit.replace('|',' ').replace('&','\&'))7290 7291 output_kind(kfig, figname, True)7279 xy=(0.80,-0.08), xycoords='axes fraction', color='black') 7280 7281 plt.title(gen.latex_text(graphtit)) 7282 7283 output_kind(kfig, figname, fclose) 7292 7284 7293 7285 return … … 7533 7525 7534 7526 def plot_river_desc(lons, lats, rns, rss, rus, ros, bcolor, ucolor, uuts, mapv, \ 7535 graphtit, kfig, lloc, figname ):7527 graphtit, kfig, lloc, figname, closef): 7536 7528 """ Function to plot rivers from 'river_desc.nc' ORCDHIEE 7537 7529 lons= values for the x-axis … … 7561 7553 9: 'upper center', 10: 'center' kfig= kind of figure 7562 7554 figname= name of the figure 7555 closef= whether should be closed or not 7563 7556 """ 7564 7557 fname = 'plot_basins' … … 7679 7672 # xy=(0.80,-0.15), xycoords='axes fraction', color='black') 7680 7673 7681 plt.title(g raphtit.replace('|',' ').replace('&','\&'))7682 7683 output_kind(kfig, figname, True)7674 plt.title(gen.latex_text(graphtit)) 7675 7676 output_kind(kfig, figname, closef) 7684 7677 7685 7678 return 7686 7679 7687 7680 def plot_vertical_lev(vertz, vertp, zlog, dzlog, plog, dplog, gtit, kfig, lloc, \ 7688 lsize ):7681 lsize, fclose): 7689 7682 """ plotting vertical levels distribution 7690 7683 plot_vertical_lev(vertz, gtit, kfig, lloc) … … 7702 7695 9: 'upper center', 10: 'center' kfig= kind of figure 7703 7696 lsize: font-size of the labels in legend 7697 fclose: whether figures shoul be closed or not 7704 7698 """ 7705 7699 fname = 'plot_vertical_lev' … … 7728 7722 plt.xlim(0,Nlev) 7729 7723 7724 print 'vertz:', vertz 7725 7730 7726 l1 = ax1.plot(range(Nlev), vertz, 'r-x', label='height') 7731 7727 l2 = ax2.plot(range(1,Nlev), dvertz, 'b-x', label='dheight') 7732 7728 7733 7729 # ax1.set_xlabel('level (\#)') 7734 ax1.set_ylabel('height (m)', color='r') 7735 ax1.set_ylim(1,np.max(vertz)) 7730 ax1.set_ylabel('height ($m$)', color='r') 7731 print np.max([0.,np.min(vertz)]) 7732 ax1.set_ylim(np.min([1., np.max([0.,np.min(vertz)]) ]),np.max(vertz)) 7736 7733 ax1.grid() 7737 ax2.set_ylabel('difference between levels ( m)', color='b')7734 ax2.set_ylabel('difference between levels ($m$)', color='b') 7738 7735 #plt.legend(['height', 'dheight'], loc=lloc, prop={'size':lsize}) 7739 7736 … … 7756 7753 ax3.set_xlim(0, Nlev) 7757 7754 ax3.set_xlabel('level (\#)') 7758 ax3.set_ylabel('pressure ( Pa)', color='r')7755 ax3.set_ylabel('pressure ($Pa$)', color='r') 7759 7756 ax3.set_ylim(np.min(vertp), np.max(vertp)) 7760 7757 ax3.grid() 7761 ax4.set_ylabel('difference between levels ( Pa)', color='b')7758 ax4.set_ylabel('difference between levels ($Pa$)', color='b') 7762 7759 7763 7760 #plt.legend(['pressure','dpressure'], loc=lloc, prop={'size':lsize}) … … 7773 7770 7774 7771 7775 output_kind(kfig, figname, True)7772 output_kind(kfig, figname, fclose) 7776 7773 7777 7774 return 7778 7775 7779 7776 def plot_subbasin(subname, lons, lats, rsf, rLlf, rof, rcolors, mapv, basinwidth, \ 7780 drawsubid, graphtit, kfig, lloc, figname ):7781 """ Function to plot rivers from 'river_desc.nc' ORCDHIEE7782 subname= name of the subbasin7783 lons= values for the x-axis7784 lats= values for the y-axis7785 rsf= list of the name of the sub-flows to plot7786 rLlf= dictionary with the lat,lon of the subflows7787 rof= dictionary with the outflows of the subflows7788 rcolors= base of colors of the lines for the subflows (first level)7789 mapv= map characteristics: [proj],[res]7777 drawsubid, graphtit, kfig, lloc, figname, drivers, fclose): 7778 """ Function to plot a reiver basin from a given point of its discharge from 'river_desc.nc' ORCDHIEE after `subbasin' 7779 [subname]= name of the subbasin 7780 [lons]= values for the x-axis 7781 [lats]= values for the y-axis 7782 [rsf]= list of the name of the sub-flows to plot 7783 [rLlf]= dictionary with the lat,lon of the subflows 7784 [rof]= dictionary with the outflows of the subflows 7785 [rcolors]= base of colors of the lines for the subflows (first level) 7786 [mapv]= map characteristics: [proj],[res] 7790 7787 see full documentation: http://matplotlib.org/basemap/ 7791 7788 [proj]: projection … … 7798 7795 * 'h', high 7799 7796 * 'f', full 7800 basinwidth= with of the lines of the basin7801 drawsubid= wehther sub-flow ids should be plot or not7802 graphtit= title of the graph ('|', for spaces)7803 lloc= location of the legend (0, automatic)7797 [basinwidth]= with of the lines of the basin 7798 [drawsubid]= wehther sub-flow ids should be plot or not 7799 [graphtit]= title of the graph ('|', for spaces) 7800 [lloc]= location of the legend (0, automatic) 7804 7801 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 7805 7802 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', 7806 7803 9: 'upper center', 10: 'center' kfig= kind of figure 7807 figname= name of the figure 7804 [figname]= name of the figure 7805 [drivers]= whether river basins from python's data-base should be added or not 7806 [fclose]= whether figure should be closed or not 7808 7807 """ 7809 7808 fname = 'plot_subbasin' … … 7970 7969 plt.ylabel('S-N') 7971 7970 7971 if drivers: 7972 m.drawrivers(color='blue') 7973 7972 7974 j = 0 7973 7975 for i in range(len(xtrack)/3): … … 7989 7991 color=colorsub[rsf[i]], fontdict=fontcharac) 7990 7992 7991 plt.title(g raphtit)7992 output_kind(kfig, figname, True)7993 plt.title(gen.latex_text(graphtit)) 7994 output_kind(kfig, figname, fclose) 7993 7995 7994 7996 return
Note: See TracChangeset
for help on using the changeset viewer.