Changeset 1080 in lmdz_wrf for trunk


Ignore:
Timestamp:
Sep 1, 2016, 8:14:41 PM (9 years ago)
Author:
lfita
Message:

Adding:

  • `optitle': Function to creat the operation section in the title of a figure ('!' for spaces)
  • `create_figure_title': Function to create the title of a figure ('!' for spaces)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/model_graphics.py

    r1078 r1080  
    16251625              axisvals + ':' + ','.join(CFvplot) + ':' + Aline + ',' + Bline +       \
    16261626              ':2.,2.:' + Akind + ',' + Bkind + ':,:' + figtit + ':' + spacedim +    \
    1627               ':0:' +  finame + ':' + kfig
     1627              ':0:' +  finame.replace('.'+kfig, '') + ':' + kfig
    16281628
    16291629            fvarS = ','.join(vplot)
     
    16921692              timefmt + ':' + timeaxis + ':' + ','.join(CFvplot) + ':' + Aline + ',' \
    16931693              + Bline + ':2.,2.:' + Akind + ',' + Bkind + ':2.,2.:,:' + figtit + ':' \
    1694               + timelabel + ':0:' +  finame + ':' + kfig
     1694              + timelabel + ':0:' +  finame.replace('.'+kfig, '') + ':' + kfig
    16951695
    16961696            fvarS = ','.join(vplot)
     
    18851885    return
    18861886
     1887def optitle(op,opexp):
     1888    """ Function to creat the operation section in the title of a figure ('!' for spaces)
     1889      op= '+' separated list of operations
     1890      opexp= dictionary with the `explanation'(text in title) to appear for each operation
     1891    >>> optitle('pinterp+xmean+tmean',{'pinterp':'pinterp', 'xmean':'xmean', 'tmean':'tmean'})
     1892    $_{[pinterp\!xmean\!tmean]}$
     1893    """
     1894    fname = 'optitle'
     1895
     1896    opvals = op.split('+')
     1897    for op1 in opvals:
     1898        if not opexp.has_key(op1):
     1899            print errmsg
     1900            print '  '+fname+": no explanation for operation '"+op1+"' !!"
     1901            print '    provided:', opexp.keys()
     1902            quit(-1)
     1903        if op1 == opvals[0]:
     1904            titop = '$_{[' + opexp[op1].replace(' ','!')
     1905            if len(opvals) == 1: titop = titop + ']}$'
     1906        elif op1 == opvals[len(opvals)-1]:
     1907            titop = titop + '\!' + opexp[op1].replace(' ','!') + ']}$'
     1908        else:
     1909            titop = titop + '\!' + opexp[op1].replace(' ','!')
     1910
     1911    return titop
     1912
     1913def create_figure_title(mod,exp,varops,explop):
     1914    """ Function to create the title of a figure ('!' for spaces)
     1915      mod: model name
     1916      exp: experiment name
     1917      varops: list with [var]|[op] values from wich create the title
     1918      explop: dictionary with the `explanation'(text in title) to appear for each operation
     1919    >>> expops = {'pinterp':'pinterp', 'xmean':'xmean', 'tmean':'tmean', 'last':'last'}
     1920    >>> create_figure_title('WRF','current',['ua|pinterp+xmean+tmean', 'va|pinterp+xmean+tmean'], expops)
     1921    WRF!current!ua!&!va$_{[pinterp\!xmean\!tmean]}$
     1922    >>> create_figure_title('WRF','current',['ua|pinterp+xmean+tmean', 'ua|pinterp+xmean+last'], expops)
     1923    WRF!current!ua$_{[pinterp\!xmean\!tmean]}$!&!!$_{[pinterp\!xmean\!last]}$
     1924    >>> create_figure_title('WRF','current',['ua|pinterp+xmean+tmean', 'va|pinterp+xmean+last'], expops)
     1925    WRF!current!ua$_{[pinterp\!xmean\!tmean]}$!&!va$_{[pinterp\!xmean\!last]}$
     1926    """
     1927    fname = 'create_figure_title'
     1928
     1929    titfig = mod + '!' + exp + '!'
     1930
     1931    varns = []
     1932    opns = []
     1933    for varop in varops:
     1934        vn = varop.split('|')[0]
     1935        op = varop.split('|')[1]
     1936        varns.append(vn)
     1937        opns.append(op)
     1938        if varop == varops[0]:
     1939            allvarequal = True
     1940            allopequal = True
     1941            varinfig = vn
     1942            opinfig = op
     1943        else:
     1944            if vn != varinfig: allvarequal = False
     1945            if op != opinfig: allopequal = False
     1946
     1947    Nvars = len(varns)
     1948    Nops = len(opns)
     1949
     1950    if allvarequal:
     1951        titfig = titfig + '!' + varns[0]
     1952        if allopequal:
     1953            opS = optitle(op,explop)
     1954            titfig = titfig + opS
     1955        else:
     1956            for opn in opns:
     1957                opS = optitle(opn,explop)
     1958                if opn == opns[0]:
     1959                    titfig = titfig + opS
     1960                elif opn == opns[Nops-1]:
     1961                    titfig = titfig + '!&!' + opS
     1962                else:
     1963                    titfig = titfig + ',!' + opS
     1964    else:
     1965        if allopequal:
     1966            opS = optitle(op,explop)
     1967            for vn in varns:
     1968                if vn == varns[0]:
     1969                    titfig = titfig + '!' + vn
     1970                elif vn == varns[Nvars-1]:
     1971                    titfig = titfig + '!&!' + vn
     1972                else:
     1973                    titfig = titfig + ',!' + vn
     1974            titfig = titfig + opS
     1975        else:
     1976            for ivop in range(Nvars):
     1977                vn = varns[ivop]
     1978                op = opns[ivop]
     1979                vnop = vn + optitle(op,explop)
     1980               
     1981                if vn == varns[0]:
     1982                    titfig = titfig + '!' + vnop
     1983                elif vn == varns[Nvars-1]:
     1984                    titfig = titfig + '!&!' + vnop
     1985                else:
     1986                    titfig = titfig + ',!' + vnop
     1987
     1988    return titfig
     1989
    18871990def draw_plots(config, plots, mod, exp, odir, allvarcomp, figscr, debug):
    18881991    """ Function to draw all plots
     
    20572160                    figname = figname + '-'+vn+'_'+headf+'_'+op.replace('+','-')
    20582161
    2059                 # Title of the figure:
    2060                 if ivp == 0:
    2061                     titfigure = mod + '!' + exp + "!'" + vn + "'"
    2062                 else:
    2063                     titfigure = titfigure + "!&!'" + vn + "'"
    2064                 opvals = op.split('+')
    2065                 for op1 in opvals:
    2066                     if not opexplained.has_key(op1):
    2067                         print errmsg
    2068                         print '  '+fname+": no explanation for operation '"+op1+"' !!"
    2069                         print '    provided:', opexplained.keys()
    2070                         quit(-1)
    2071                     if op1 == opvals[0]:
    2072                         titfigure = titfigure + '$_{[' + opexplained[op1]
    2073                         if len(opvals) == 1: titfigure = titfigure + ']}$'
    2074                     elif op1 == opvals[len(opvals)-1]:
    2075                         titfigure = titfigure + '\!' + opexplained[op1] + ']}$'
    2076                     else:
    2077                         titfigure = titfigure + '\!' + opexplained[op1]
    2078 
    20792162                ivp = ivp + 1
    20802163            # End of variable-operation
    20812164            figname = figname + '.' + kindfigure
     2165
     2166            # Title of figure
     2167            titfigure = create_figure_title(mod, exp, varops, opexplained)
    20822168
    20832169            draw_plot(kplot, CFvarsplot, filesplot, varsplot, dimsplot, pictplot,    \
     
    26932779        elif op == 'xvar':
    26942780            # x-axis variance values
    2695             vals='lon|-1,lon,var,' + ':'.join(varnCFs) + ':' + vdnz
    2696             dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') + dnz+'@'+vdnz
     2781            vals='lon|-1,lon,var,' + ':'.join(varnCFs)
     2782            dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@')
    26972783            if dofile:
    26982784                try:
     
    27142800                  "' -f " + prevfile + " -v " + CFvarnp
    27152801                otrackf.write("\n")
    2716                 otrackf.write("# " + CFvarn + " " + Fopers + "\n")
     2802                otrackf.write("# " + varn + " " + Fopers + "\n")
    27172803                otrackf.write(pyins + "\n")
    27182804
     
    30843170                headf = vopvals[4]
    30853171
    3086                 modexpdiff = mod2 + '/' + exp2 + ' - ' + mod1 + '/' + exp1
     3172                modexpdiff = mod2 + '/' + exp2 + '-' + mod1 + '/' + exp1
    30873173                modexpdiffS = mod2 + '-' + exp2 + '_' + mod1 + '-' + exp1
    30883174
     
    31373223                    modexptit = modexpdiff
    31383224
    3139                 if ivp == 0:
    3140                     titfigure = modexptit + "!" + kdiff + "!'" + vn + "'"
    3141                     vnS = vn
    3142                 else:
    3143                     titfigure = titfigure + "!&!'" + vn + "'"
    3144                     vnS = vnS + '!&!' + vn
    3145 
    3146                 opvals = op.split('+')
    3147                 for op1 in opvals:
    3148                     if not opexplained.has_key(op1):
    3149                         print errormsg
    3150                         print '  '+fname+": no explanation for operation '"+op1+"' !!"
    3151                         print '    provided:', opexplained.keys()
    3152                         quit(-1)
    3153                     if op1 == opvals[0]:
    3154                         titfigure = titfigure + '$_{[' + opexplained[op1]
    3155                         if len(opvals) == 1: titfigure = titfigure + ']}$'
    3156                     elif op1 == opvals[len(opvals)-1]:
    3157                         titfigure = titfigure + '\!' + opexplained[op1] + ']}$'
    3158                     else:
    3159                         titfigure = titfigure + '\!' + opexplained[op1]
    3160 
    31613225                ivp = ivp + 1
    31623226            # End of variable-operation
    31633227            figname = figname + '.' + kindfigure
     3228
     3229            # Title of figure
     3230            titfigure = create_figure_title(modexptit, kdiff, varops, opexplained)
    31643231
    31653232            if len(titfigure) > 80:
Note: See TracChangeset for help on using the changeset viewer.