Changeset 1468 in lmdz_wrf


Ignore:
Timestamp:
Mar 21, 2017, 10:34:04 PM (8 years ago)
Author:
lfita
Message:

Improving: draw_vertical_levels', draw_subbasin', draw_basin'. draw_river_desc'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r1466 r1468  
     1# -*- coding: iso-8859-15 -*-
    12# Python to manage plot data in netCDF files.
    23# From L. Fita work in different places: LMD (France)
     
    3940## 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
    4041## 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
    4147
    4248
     
    45484554    return
    45494555
    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]:[cbarname]:[xtrmbasin]:[mapdraw]:[veclength]:[freq]:
    4553         [ifreq]:[plotcountry]:[basinidn]:[gtit]:[kindfig]:[figuren]
     4556def 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]
    45544560        [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
    45584572        [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 cell
    4560         [freq]= frequency of values allong each axis (None, all grid points;
    4561           'auto', computed automatically to have 20 vectors along each axis)
    45624573        [plotcountry]= whether country lines should be plotted or not ('True/False')
    45634574        [plotbasinid]= whether id of the basins should be plotted or not ('True/False')
     
    45654576        [kindfig]= kind of figure
    45664577        [figuren]= name of the figure
     4578        [closefig]= whether figure should be closed or not
    45674579      ncfile= file to use
    45684580    """
     
    45754587
    45764588    expectargs = '[lonlatbox]:[mapres]:[cbarname]:[xtrmbasin]:[mapdraw]:' +          \
    4577       '[veclength]:[freq]:[plotcountry]:[basinidn]:[gtit]:[kindfig]:[figuren]'
     4589      '[plotcountry]:[basinidn]:[gtit]:[kindfig]:[figuren]:[closefig]'
    45784590 
    45794591    drw.check_arguments(fname,values,expectargs,':')
     
    45924604    latlims.append(np.float(values.split(':')[0].split(',')[3]))
    45934605    map_res = values.split(':')[1]
    4594     cbarname = values.split(':')[2]
     4606    colorbarvals = values.split(':')[2]
    45954607    vtit = 'basins'
    45964608    minbasin = np.int(values.split(':')[3].split(',')[0])
    45974609    maxbasin = np.int(values.split(':')[3].split(',')[1])
    45984610    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])
    46084617
    46094618    ofile = NetCDFFile(ncfile, 'r')
     
    46254634
    46264635    imin, imax, jmin, jmax = gen.ijlonlat(lon, lat, nlon, xlon, nlat, xlat)
     4636   
     4637    colbarn, fmtcolbar, colbaror = drw.colorbar_vals(colorbarvals,',')
    46274638
    46284639    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)
    46324643
    46334644    ofile.close()
     
    47914802
    47924803def 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')
    47944805      values= [dimname]|[vardimname]|[value]:[basinvals]:[upstreamvals]:[mapvalues]:
    4795         [gtit]:[kindfig]:[legvals]:[figuren]
     4806        [gtit]:[kindfig]:[legvals]:[figuren]:[closefig]
    47964807        'X/Y'|[dimname]|[vardimname]|[value]: ',', list for each basic dimension '|' separated of:
    4797           [dimname]: name of the dimension in the file
     4808          [dimname]= name of the dimension in the file for 'X' and 'Y' axis
    47984809          [vardimname]: name of the variable with the values for the dimension in the file
    47994810          [value]: which value of the given dimension is required:
     
    48044815            * NOTE, no dim name all the dimension size
    48054816          No value takes all the range of the dimension
    4806         [basinsvals]= [colorline]
     4817        [basinsvals]= [colorline] colors for the border line of each basin
    48074818          [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
    48104820        [mapvalues]= map characteristics: [proj],[res]
    48114821          see full documentation: http://matplotlib.org/basemap/
     
    48194829            * 'h', high
    48204830            * 'f', full
    4821         gtit= title of the graph ('|', for spaces)
    4822         kindfig= kind of figure
     4831        [gtit]= title of the graph ('|', for spaces)
     4832        [kindfig]= kind of figure (png, ps, pdf)
    48234833        [legvals]=[locleg]|[fontsize]:
    48244834          [locleg]: location of the legend (0, autmoatic)
     
    48274837            9: 'upper center', 10: 'center'
    48284838          [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
    48304841      ncfile= file to use
    48314842      riverns= ',' list of the name of the rivers to plot
     
    48404851
    48414852    expectargs = '[X/Y/Z/T]|[dimname]|[vardimname]|[value]:[basinvals]:' +           \
    4842       '[upstreamvals]:[mapvalues]:[gtit]:[kindfig]:[legloc]:[figuren]'
     4853      '[upstreamvals]:[mapvalues]:[gtit]:[kindfig]:[legloc]:[figuren]:[closefig]'
    48434854 
    48444855    drw.check_arguments(fname,values,expectargs,':')
     
    48484859    upstreamvals = values.split(':')[2]
    48494860    mapvals = values.split(':')[3]
    4850     gtit = values.split(':')[4]
     4861    gtit = values.split(':')[4].replace('|',' ')
    48514862    kindfig = values.split(':')[5]
    48524863    legloc = int(values.split(':')[6])
    48534864    figuren = values.split(':')[7]
     4865    closefig = gen.Str_Bool(values.split(':')[8])
    48544866
    48554867    basincol = basinvals
     
    49704982
    49714983    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)
    49734985
    49744986    of.close()
    49754987
    49764988def draw_vertical_levels(ncfile, values, varn):
    4977     """ plotting vertical levels distribution
     4989    """ plotting distribution of vertical levels
    49784990    draw_vertical_levels(ncfile, values, varn)
    49794991      ncfile= file to use
    4980       values= [zlogs]:[plogs]:[title]:[graphic_kind]:[legvals]
    4981         zlogs= zlog,dzlog
    4982         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,dplog
    4985         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)
    49895001        [legvals]=[locleg]|[fontsize]
    49905002          [locleg]: location of the legend (0, autmoatic)
     
    49935005            9: 'upper center', 10: 'center'
    49945006          [fontsize]: font size for the legend (auto for 12)
     5007        [closefig]= whether figures should be closed or not
    49955008      varn= [varnheight],[varnpres]
    4996         varnheight: name of the variable with the height of the vertical levels
     5009        [varnheight]: name of the variable with the height of the vertical levels
    49975010          '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)
    49995012          'WRFp': for WRF p-levels (computed as P + PB, from a PHB(0,i,j) = 0)
    50005013    """
     
    50065019        quit()
    50075020
    5008     expectargs = '[zlogs]:[plogs]:[title]:[graphic_kind]:[legloc]'
     5021    expectargs = '[zlogs]:[plogs]:[title]:[graphic_kind]:[legloc]:[closefig]'
    50095022 
    50105023    drw.check_arguments(fname,values,expectargs,':')
    50115024
    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])
    50165029    title = values.split(':')[2].replace('!',' ')
    50175030    kindfig = values.split(':')[3]
    50185031    legvals = values.split(':')[4]
     5032    closefig = gen.Str_Bool(values.split(':')[5])
    50195033
    50205034    if varn.find(',') == -1:
     
    51365150                pvals = objvar[:]
    51375151
    5138 # Logarithmic axes
    5139     if zlog == 'true':
    5140         zlogv = True
    5141     elif zlog == 'false':
    5142         zlogv = False
    5143     else:
    5144         print errormsg
    5145         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 = True
    5151     elif dzlog == 'false':
    5152         dzlogv = False
    5153     else:
    5154         print errormsg
    5155         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 = True
    5162         elif plog == 'false':
    5163             plogv = False
    5164         else:
    5165             print errormsg
    5166             print '  ' + fname + ": wrong value for plog: '" + plog + "' !!"
    5167             print "    must be either: 'true' or 'false'"
    5168             quit(-1)
    5169         if dplog == 'true':
    5170             dplogv = True
    5171         elif dplog == 'false':
    5172             dplogv = False
    5173         else:
    5174             print errormsg
    5175             print '  ' + fname + ": wrong value for dplog: '" + dplog + "' !!"
    5176             print "    must be either: 'true' or 'false'"
    5177             quit(-1)
    51785152
    51795153    # Legend values
     
    51815155
    51825156    drw.plot_vertical_lev(zvals, pvals, zlogv, dzlogv, plogv, dplogv, title, kindfig,\
    5183       legloc, legsize)
     5157      legloc, legsize, closefig)
    51845158
    51855159    objf.close()
     
    51885162
    51895163def 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]
    51935171        [subasiname]= name of the subbasin ('!' for spaces)
    51945172        [rcolor]= '@', list of 'r|g|b' 1-based colors (as much as first level sub-flow). 'None' for automatic
     
    52145192          [fontsize]: font size for the legend (auto for 12)
    52155193        [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
    52165196    """
    52175197    fname = 'draw_subbasin'
     
    52235203
    52245204    expectargs = '[subasiname]:[rangecolors]:[mapv]:[basinlinewidth]:[drawsubid]:' + \
    5225       '[gtit]:[figkind]:[legloc]:[figurename]'
     5205      '[gtit]:[figkind]:[legloc]:[figurename]:[drawrivers]:[closefig]'
    52265206 
    52275207    drw.check_arguments(fname,values,expectargs,':')
     
    52365216    legloc = int(values.split(':')[7])
    52375217    figurename = values.split(':')[8]
     5218    drawrivers = gen.Str_Bool(values.split(':')[9])
     5219    closefig = gen.Str_Bool(values.split(':')[10])
    52385220
    52395221    if not os.path.isfile(ncfile):
     
    52935275
    52945276    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)
    52965279
    52975280    objf.close()
     
    65136496        draw_barbs(opts.ncfile, opts.values, opts.varname)
    65146497    elif oper == 'draw_basins':
    6515         draw_basins(opts.ncfile, opts.values, opts.varname)
     6498        draw_basins(opts.ncfile, opts.values)
    65166499    elif oper == 'draw_Neighbourghood_evol':
    65176500        draw_Neighbourghood_evol(opts.ncfile, opts.values, opts.varname)
  • trunk/tools/drawing_tools.py

    r1466 r1468  
    71107110    return
    71117111
    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 vectors
     7112def 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
    71157115      xvals= values for the x-axis
    71167116      yvals= values for the y-axis
    71177117      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
    71257122      windn= name of the wind variable in the graph
    71267123      wuts= units of the wind variable in the graph
     
    71417138      kfig= kind of figure
    71427139      figname= name of the figure
     7140      fclose= whether figures should be close or not
    71437141    """
    71447142    fname = 'plot_basins'
     
    71477145    dy=xvals.shape[0]
    71487146
    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.
    71657148
    71667149# flow direction
    7167     angle = (fvals[::yfreq,::xfreq] - 1)*np.pi/4
    7168     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.)
    71707153
    71717154# Colors
     
    71957178    flowvals = []
    71967179   
    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):
    71997182            if veccolor[j,i] != '--':
    72007183                xlabpos.append(xvals[j,i])
     
    72117194        map_res=mapv.split(',')[1]
    72127195
    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[:])
    72177200
    72187201        lon2 = xvals[dy/2,dx/2]
     
    72477230        plt.ylabel('S-N')
    72487231
    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[:]
    72577245    vecolorvals = np.where(vecolorvals < vcolmin, vcolmin - 1, vecolorvals)
    72587246    vecolorvals = np.where(vecolorvals > vcolmax, vcolmax + 1, vecolorvals)
    72597247
    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,                  \
    72657249       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)
    72677260
    72687261    vN = vecoln.split('@')[1]
     
    72727265    if basinid:
    72737266        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)
    72777269# Sea-flow
    72787270    for i in range(len(xlabpos)):
     
    72857277
    72867278    plt.annotate(windn.replace('_','\_') +' (' + units_lunits(wuts) + ')',           \
    7287       xy=(0.80,-0.15), xycoords='axes fraction', color='black')
    7288 
    7289     plt.title(graphtit.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)
    72927284
    72937285    return
     
    75337525
    75347526def plot_river_desc(lons, lats, rns, rss, rus, ros, bcolor, ucolor, uuts, mapv,      \
    7535   graphtit, kfig, lloc, figname):
     7527  graphtit, kfig, lloc, figname, closef):
    75367528    """ Function to plot rivers from 'river_desc.nc' ORCDHIEE
    75377529      lons= values for the x-axis
     
    75617553        9: 'upper center', 10: 'center'      kfig= kind of figure
    75627554      figname= name of the figure
     7555      closef= whether should be closed or not
    75637556    """
    75647557    fname = 'plot_basins'
     
    76797672#      xy=(0.80,-0.15), xycoords='axes fraction', color='black')
    76807673
    7681     plt.title(graphtit.replace('|',' ').replace('&','\&'))
    7682 
    7683     output_kind(kfig, figname, True)
     7674    plt.title(gen.latex_text(graphtit))
     7675
     7676    output_kind(kfig, figname, closef)
    76847677
    76857678    return
    76867679
    76877680def plot_vertical_lev(vertz, vertp, zlog, dzlog, plog, dplog, gtit, kfig, lloc,      \
    7688   lsize):
     7681  lsize, fclose):
    76897682    """ plotting vertical levels distribution
    76907683    plot_vertical_lev(vertz, gtit, kfig, lloc)
     
    77027695        9: 'upper center', 10: 'center'      kfig= kind of figure
    77037696      lsize: font-size of the labels in legend
     7697      fclose: whether figures shoul be closed or not
    77047698    """
    77057699    fname = 'plot_vertical_lev'
     
    77287722    plt.xlim(0,Nlev)
    77297723 
     7724    print 'vertz:', vertz
     7725
    77307726    l1 = ax1.plot(range(Nlev), vertz, 'r-x', label='height')
    77317727    l2 = ax2.plot(range(1,Nlev), dvertz, 'b-x', label='dheight')
    77327728
    77337729#    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))
    77367733    ax1.grid()
    7737     ax2.set_ylabel('difference between levels (m)', color='b')
     7734    ax2.set_ylabel('difference between levels ($m$)', color='b')
    77387735    #plt.legend(['height', 'dheight'], loc=lloc, prop={'size':lsize})
    77397736
     
    77567753        ax3.set_xlim(0, Nlev)
    77577754        ax3.set_xlabel('level (\#)')
    7758         ax3.set_ylabel('pressure (Pa)', color='r')
     7755        ax3.set_ylabel('pressure ($Pa$)', color='r')
    77597756        ax3.set_ylim(np.min(vertp), np.max(vertp))
    77607757        ax3.grid()
    7761         ax4.set_ylabel('difference between levels (Pa)', color='b')
     7758        ax4.set_ylabel('difference between levels ($Pa$)', color='b')
    77627759
    77637760        #plt.legend(['pressure','dpressure'], loc=lloc, prop={'size':lsize})
     
    77737770
    77747771
    7775     output_kind(kfig, figname, True)
     7772    output_kind(kfig, figname, fclose)
    77767773
    77777774    return
    77787775
    77797776def 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' ORCDHIEE
    7782       subname= name of the subbasin
    7783       lons= values for the x-axis
    7784       lats= values for the y-axis
    7785       rsf= list of the name of the sub-flows to plot
    7786       rLlf= dictionary with the lat,lon of the subflows
    7787       rof= dictionary with the outflows of the subflows
    7788       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]
    77907787        see full documentation: http://matplotlib.org/basemap/
    77917788        [proj]: projection
     
    77987795          * 'h', high
    77997796          * 'f', full
    7800       basinwidth = with of the lines of the basin
    7801       drawsubid= wehther sub-flow ids should be plot or not
    7802       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)
    78047801        1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    78057802        5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
    78067803        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
    78087807    """
    78097808    fname = 'plot_subbasin'
     
    79707969        plt.ylabel('S-N')
    79717970
     7971        if drivers:
     7972            m.drawrivers(color='blue')
     7973
    79727974    j = 0
    79737975    for i in range(len(xtrack)/3):
     
    79897991              color=colorsub[rsf[i]], fontdict=fontcharac)
    79907992
    7991     plt.title(graphtit)
    7992     output_kind(kfig, figname, True)
     7993    plt.title(gen.latex_text(graphtit))
     7994    output_kind(kfig, figname, fclose)
    79937995
    79947996    return
Note: See TracChangeset for help on using the changeset viewer.