Changeset 531 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jun 25, 2015, 11:46:49 AM (10 years ago)
Author:
lfita
Message:

Adding in `drawing_lines_time', multiple dim-vars and vars
Adding in `drawing_lines_time', providing the name of the colors to use

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r489 r531  
    16401640    return
    16411641
    1642 def draw_lines_time(ncfilens, values, varname):
     1642def draw_lines_time(ncfilens, values, varname0):
    16431643    """ Function to draw different lines at the same time from different files with times
    16441644    draw_lines_time(ncfilens, values, varname):
    16451645      ncfilens= [filen] ',' separated list of netCDF files
    1646       values= [dimvname];[valuesaxis];[dimtit];[leglabels];[vtit];[title];[timevals];[locleg];[graphk]
    1647         [dimvname]: name of the variable with he values of the common dimension
     1646      values= [dimvname];[valuesaxis];[dimtit];[leglabels];[vtit];[title];[timevals];[locleg];
     1647        [graphk];[collines]
     1648        [dimvname]: ',' list of names of the variables with he values of the common dimension
    16481649        [valuesaxis]: which axis will be used for the values ('x', or 'y')
    16491650        [dimtit]: title for the common dimension
     
    16671668          9: 'upper center', 10: 'center'
    16681669        [graphk]: kind of the graphic
    1669       varname= variable to plot
     1670        [collines]: ',' list of colors for the lines or None for automatic
     1671      varname0= ',' list of variable names to plot (assuming only 1 variable per file)
    16701672      values= 'time;y;time ([DD]${[HH]}$);32x32;$wss^{*}$;wss Taylor's turbulence term;time|hours!since!1949-12-01_00:00:00;exct,12,h|%d$^{%H}$;2;pdf'
    16711673    """
     
    16791681
    16801682    expectargs = '[dimvname];[valuesaxis];[dimtit];[leglabels];[vtit];[title];'
    1681     expectargs = expectargs + '[timevals];[locleg];[graphk]'
     1683    expectargs = expectargs + '[timevals];[locleg];[graphk];[collines]'
    16821684    drw.check_arguments(fname,len(expectargs.split(';')),values,';',expectargs)
    16831685
    16841686    ncfiles = ncfilens.split(',')
    1685     dimvname = values.split(';')[0]
     1687    dimvname0 = values.split(';')[0]
    16861688    valuesaxis = values.split(';')[1]
    16871689    dimtit = values.split(';')[2]
     
    16921694    locleg = int(values.split(';')[7])
    16931695    graphk = values.split(';')[8]
     1696    collines0 = values.split(';')[9]
    16941697
    16951698    Nfiles = len(ncfiles)
     1699
     1700# Multiple variable-dimension names?
     1701    if dimvname0.find(',') != -1:
     1702        dimvname = dimvname0.split(',')
     1703    else:
     1704        dimvname = [dimvname0]
     1705
     1706# Multiple variables?
     1707    if varname0.find(',') != -1:
     1708        varname = varname0.split(',')
     1709    else:
     1710        varname = [varname0]
     1711
     1712# Multiple color names?
     1713    if collines0.find(',') != -1:
     1714        collines = collines0.split(',')
     1715    else:
     1716        collines = None
    16961717
    16971718# Getting values
     
    17191740        objfile = NetCDFFile(filen, 'r')
    17201741
    1721         if not objfile.variables.has_key(dimvname):
     1742        founddvar = False
     1743        for dvar in dimvname:
     1744            if objfile.variables.has_key(dvar):
     1745                founddvar = True
     1746                vdobj = objfile.variables[dvar]
     1747                if len(vdobj.shape) != 1:
     1748                    print errormsg
     1749                    print '  ' + fname + ': wrong shape:',vdobj.shape," of " +       \
     1750                      "variable '" + dvar +  "' !!"
     1751                    quit(-1)
     1752                break
     1753        if not founddvar:
    17221754            print errormsg
    17231755            print '  ' + fname + ": netCDF file '" + filen +                         \
    1724               "' does not have variable '" + dimvname + "' !!"
     1756            "' has any variable '", dimvname, "' !!"
    17251757            quit(-1)
    17261758
    1727         if not objfile.variables.has_key(varname):
     1759        foundvar = False
     1760        for var in varname:
     1761            if objfile.variables.has_key(var):
     1762                foundvar = True
     1763                vvobj = objfile.variables[var]
     1764                if len(vvobj.shape) != 1:
     1765                    print errormsg
     1766                    print '  ' + fname + ': wrong shape:',vvobj.shape," of " +       \
     1767                      "variable '" + var +  "' !!"
     1768                    quit(-1)
     1769
     1770                break
     1771        if not foundvar:
    17281772            print errormsg
    17291773            print '  ' + fname + ": netCDF file '" + filen +                         \
    1730               "' does not have variable '" + varname + "' !!"
    1731             quit(-1)
    1732 
    1733         vvobj = objfile.variables[varname]
    1734         if len(vvobj.shape) != 1:
    1735             print errormsg
    1736             print '  ' + fname + ': wrong shape:',vvobj.shape," of variable '" +     \
    1737               varname +  "' !!"
    1738             quit(-1)
    1739 
    1740         vdobj = objfile.variables[dimvname]
    1741         if len(vdobj.shape) != 1:
    1742             print errormsg
    1743             print '  ' + fname + ': wrong shape:',vdobj.shape," of variable '" +     \
    1744               dimvname +  "' !!"
     1774              "' has any variable '", varname, "' !!"
    17451775            quit(-1)
    17461776
     
    17731803
    17741804    drw.plot_lines_time(dimvalues, varvalues, valuesaxis, dimtit, leglabels.split(','),   \
    1775       vartit, varunits, timepos, timelabels, title, locleg, graphk)
     1805      vartit, varunits, timepos, timelabels, title, locleg, graphk, collines)
    17761806
    17771807    return
  • trunk/tools/drawing_tools.py

    r530 r531  
    14061406
    14071407# Units which does not change
    1408     same = ['1', 'category', 'day', 'degrees East', 'degrees Nord', 'degrees North', \
    1409       'g', 'gpm', 'hour', 'hPa', 'K', 'Km', 'kg', 'km', 'm', 'minute', 'mm', 'month', 'Pa', \
    1410       's', 'second', 'um', 'year', '-']
     1408    same = ['1', 'category', 'day', 'deg', 'degrees East', 'degrees Nord',          \
     1409      'degrees North', 'g', 'gpm', 'hour', 'hPa', 'K', 'Km', 'kg', 'km', 'm',        \
     1410      'minute', 'mm', 'month', 'Pa', 's', 'second', 'um', 'year', '-']
    14111411
    14121412    if searchInlist(same,u):
     
    50865086
    50875087def plot_lines_time(vardv, varvv, vaxis, dtit, linesn, vtit, vunit, tpos, tlabs,     \
    5088   gtit, gloc, kfig):
     5088  gtit, gloc, kfig, coll):
    50895089    """ Function to plot a collection of lines with a time axis
    50905090      vardv= list of set of dimension values
     
    51035103        9: 'upper center', 10: 'center'
    51045104      kfig= kind of figure
     5105      coll= ',' list of colors for the lines or None for automatic
    51055106      plot_lines([np.arange(10)], [np.sin(np.arange(10)*np.pi/2.5)], 'y', 'time (s)',      \
    51065107  ['2.5'], 'sin', '-', 'sinus frequency dependency', 'pdf')
     
    51265127    if vaxis == 'x':
    51275128        for il in range(Ntraj):
    5128             plt.plot(varvv[il], vardv[il], linekinds[N7lines], label= linesn[il])
     5129            if coll is None:
     5130                plt.plot(varvv[il], vardv[il], linekinds[N7lines], label= linesn[il])
     5131            else:
     5132                plt.plot(varvv[il], vardv[il], linekinds[N7lines], label= linesn[il],\
     5133                  color=coll[il])
     5134
    51295135            varTvv = varTvv + list(varvv[il])
    51305136            varTdv = varTdv + list(vardv[il])
     
    51385144    else:
    51395145        for il in range(Ntraj):
    5140             plt.plot(vardv[il], varvv[il], linekinds[N7lines], label= linesn[il])
     5146            if coll is None:
     5147                plt.plot(vardv[il], varvv[il], linekinds[N7lines], label= linesn[il])
     5148            else:
     5149                plt.plot(vardv[il], varvv[il], linekinds[N7lines], label= linesn[il],\
     5150                  color=coll[il])
     5151
    51415152            varTvv = varTvv + list(varvv[il])
    51425153            varTdv = varTdv + list(vardv[il])
Note: See TracChangeset for help on using the changeset viewer.