Changeset 1363 in lmdz_wrf


Ignore:
Timestamp:
Dec 4, 2016, 1:07:13 PM (8 years ago)
Author:
lfita
Message:
  • Adding `dimvarvalue': Slicing along the index at the nearest given value of a dimension-variable
  • Adding opexplained': Function to provide the final explanation for the title in the graph. Some operations have values separated by ~' which need to be processed
  • Removing double `!!' from 'create_figure_title'
  • Removing double `..' from figure's name
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/model_graphics.py

    r1345 r1363  
    11421142            wrongstats.append(CFvarn + '_' + opers)
    11431143            break
     1144
     1145        elif op[0:11] == 'dimvarvalue':
     1146            # Slicing along the index at the nearest given value of a dimension-variable
     1147            dimvarn = op.split('~')[1]
     1148            dimvalue = op.split('~')[2]
     1149            vals = dimvarn + ',' + dimvalue + ',' + dimvalue + ',0'
     1150            if dofile:
     1151                try:
     1152                    with gen.Capturing() as output:
     1153                        ncvar.DataSetSection_multivars(vals,prevfile,CFvarnp)
     1154                except:
     1155                    print errmsg
     1156                    print 'DataSetSection_multivars('+vals+',', prevfile, ',' +      \
     1157                      CFvarnp + ')'
     1158                    for s1out in output: print s1out
     1159                    quit(-1)
     1160
     1161                if db:
     1162                    for s1out in output: print s1out
     1163
     1164                sout = sub.call('mv DataSetSection_multivars.nc '+fileon, shell=True)
     1165
     1166                # Keeping the operations
     1167                pyins=pyH + "/nc_var.py -o DataSetSection_multivars -S '" + vals +   \
     1168                  "' -f " + prevfile + " -v " + CFvarnp
     1169                otrackf.write("\n")
     1170                otrackf.write("# " + CFvarnp + " " + Fopers + "\n")
     1171                otrackf.write(pyins + "\n")
     1172
     1173            # removing the given variable-dimension
     1174            varnCFs.remove(dimvarn)
     1175
    11441176        elif op == 'direct':
    11451177            # no statistics
     
    23342366    return
    23352367
     2368def opexplained(Opn,Exp):
     2369    """ Function to provide the final explanation for the title in the graph. Some operations have
     2370      values separated by `~' which need to be processed
     2371      Opn= full operation string
     2372      Exp= explanation from dictionary
     2373    >>> opexplained('dimvarvalue~pres~85000','@')
     2374    pres@85000
     2375    >>> opexplained('xmean','xmean')
     2376    xmean
     2377    """
     2378    fname = 'opexplained'
     2379
     2380    if Opn.find('~') == -1:
     2381        explanation = Exp
     2382    else:
     2383        Opnv = Opn.split('~')
     2384        if Opnv[0] == 'dimvarvalue':
     2385            explanation =  Opnv[1] + Exp + Opnv[2]
     2386        else:
     2387            print errormsg
     2388            print '  ' + fname + ": unknow '~' separated operation '" + Opnv[0] +    \
     2389              "' !!"
     2390            quit(-1)
     2391    return explanation
     2392
    23362393def optitle(op,opexp):
    23372394    """ Function to creat the operation section in the title of a figure ('!' for spaces)
     
    23402397    >>> optitle('pinterp+xmean+tmean',{'pinterp':'pinterp', 'xmean':'xmean', 'tmean':'tmean'})
    23412398    $_{[pinterp\!xmean\!tmean]}$
     2399    >>> optitle('pinterp+dimvarvalue~pres~85000+tmean',{'dimvarvalue':'@', 'pinterp':'pinterp', 'xmean':'xmean', 'tmean':'tmean'})
     2400    $_{[pinterp\!pres@85000\!tmean]}$
    23422401    """
    23432402    fname = 'optitle'
     
    23452404    opvals = op.split('+')
    23462405    for op1 in opvals:
    2347         if not opexp.has_key(op1):
     2406        op1n = op1.split('~')[0]
     2407        if not opexp.has_key(op1n):
    23482408            print errmsg
    2349             print '  '+fname+": no explanation for operation '"+op1+"' !!"
     2409            print '  ' + fname + ": no explanation for operation '" + op1n + "' !!"
    23502410            print '    provided:', opexp.keys()
    23512411            quit(-1)
    2352         if op1 == opvals[0]:
    2353             titop = '$_{[' + opexp[op1].replace(' ','!')
     2412        # Final explanation
     2413        op1en = opexplained(op1,opexp[op1n]).replace(' ','!')
     2414
     2415        if op1n == opvals[0].split('~')[0]:
     2416            titop = '$_{[' + op1en
    23542417            if len(opvals) == 1: titop = titop + ']}$'
    2355         elif op1 == opvals[len(opvals)-1]:
    2356             titop = titop + '\!' + opexp[op1].replace(' ','!') + ']}$'
     2418        elif op1n == opvals[len(opvals)-1].split('~')[0]:
     2419            titop = titop + '\!' + op1en + ']}$'
    23572420        else:
    2358             titop = titop + '\!' + opexp[op1].replace(' ','!')
     2421            titop = titop + '\!' + op1en
    23592422
    23602423    return titop
     
    23732436    >>> create_figure_title('WRF','current',['ua|pinterp+xmean+tmean', 'va|pinterp+xmean+last'], expops)
    23742437    WRF!current!ua$_{[pinterp\!xmean\!tmean]}$!&!va$_{[pinterp\!xmean\!last]}$
     2438    >>> create_figure_title('WRF','current',['uas|dimvarvalue~lon~23.23', 'vas|dimvarvalue~lon~23.23'], expops)
     2439    WRF!current!uas!&!vas$_{[lon@23.23]}$
     2440    >>> create_figure_title('WRF','current',['hus|pinterp+tmean+dimvarvalue~pres~85000.', 'ta|pinterp+tmean+dimvarvalue~pres~85000.'], expops)
     2441    WRF!current!hus!&!ta$_{[pinterp\!tmean\!pres@85000.]}$
    23752442    """
    23762443    fname = 'create_figure_title'
     
    24352502                    titfig = titfig + ',!' + vnop
    24362503
    2437     return titfig
     2504    return titfig.replace('!!','!')
     2505#expops = {'dimvarvalue':'@', 'last':'last', 'pinterp':'pinterp', 'xmean':'xmean', 'tmean':'tmean'}
    24382506
    24392507def draw_plots(config, plots, mod, exp, odir, allvarcomp, figscr, debug):
     
    26192687            # End of variable-operation
    26202688            figname = figname + '.' + kindfigure
     2689
     2690            # Removig double '..' (from `dimvarvalue')
     2691            figname = figname.replace('..', '.')
    26212692
    26222693            # Title of figure
     
    29783049        acc: temporal accumulated values
    29793050        diff: differences between models
     3051        dimvarvalue~[dimvarn]~[value]: Slicing along the index at the nearest given value of a dimension-variable
    29803052        direct: no statistics
    29813053        last: last temporal value
     
    30663138            wrongstats.append(varn + '_' + opers)
    30673139            break
     3140
     3141        elif op[0:11] == 'dimvarvalue':
     3142            # Slicing along the index at the nearest given value of a dimension-variable
     3143            dimvarn = op.split('~')[1]
     3144            dimvalue = op.split('~')[2]
     3145            vals = dimvarn + ',' + dimvalue + ',' + dimvalue + ',0'
     3146            if dofile:
     3147                try:
     3148                    with gen.Capturing() as output:
     3149                        ncvar.DataSetSection_multivars(vals,prevfile,CFvarnp)
     3150                except:
     3151                    print errmsg
     3152                    print 'DataSetSection_multivars('+vals+',', prevfile, ',' +      \
     3153                      CFvarnp + ')'
     3154                    for s1out in output: print s1out
     3155                    quit(-1)
     3156
     3157                if db:
     3158                    for s1out in output: print s1out
     3159
     3160                sout = sub.call('mv DataSetSection_multivars.nc '+fileon, shell=True)
     3161
     3162                # Keeping the operations
     3163                pyins=pyH + "/nc_var.py -o DataSetSection_multivars -S '" + vals +   \
     3164                  "' -f " + prevfile + " -v " + CFvarnp
     3165                otrackf.write("\n")
     3166                otrackf.write("# " + CFvarnp + " " + Fopers + "\n")
     3167                otrackf.write(pyins + "\n")
     3168
     3169            # removing the given variable-dimension
     3170            varnCFs.remove(dimvarn)
     3171
    30683172        elif op == 'direct':
    30693173            # no statistics
     
    46924796            # op and var differences
    46934797            diffvarcompf = owdir + '/' + difffiles[0]
    4694             print 'Lluis HERE !2!1!: diffvarcompf:', diffvarcompf
    46954798            if not os.path.isfile(diffvarcompf):
    46964799                alldiffop, alldiffvar,Nopdiffs,Nvardiffs=diffvarop_listconstruct(cnf,\
Note: See TracChangeset for help on using the changeset viewer.