Changeset 1329 in lmdz_wrf


Ignore:
Timestamp:
Nov 15, 2016, 4:37:20 PM (8 years ago)
Author:
lfita
Message:

Adding `figinf_figname': Function to retrieve figure information from its name
Propoer loop for grouping figures by variable
Propoer caption (two variables by figure!) for the grouping figures by variable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/model_graphics.py

    r1327 r1329  
    43784378    return
    43794379
     4380def figinf_figname(figname,config):
     4381    """ Function to retrieve figure information from its name
     4382      figname= name of the figure
     4383      config= configuration of `model_graphics.py'
     4384    >>> figinf_figname('2linesTime_wss_wrfout_xvar-ymean-tas_wrfout_xvar-ymean.pdf', cnf)
     4385    (2, '2linesTime', 'wss-tas', 'xvar-ymean@xvar-ymean')
     4386    >>> figinf_figname('Nlines_tas_wrfout_tturb-xmean-tmean.pdf', cnf)
     4387    (1, 'Nlines', 'tas', 'tturb-xmean-tmean')
     4388    >>> figinf_figname('2lines_wss_diffvar_WRF-micro1_WRF-current_tturb-xmean-last-tas_tturb-xmean-last.pdf',cnf)
     4389    (2, '2lines', 'wss-tas', 'tturb-xmean-last@tturb-xmean-last')
     4390    """
     4391    fname = 'figinf_figname'
     4392    plotsecs = figname.split('_')
     4393    plotk = plotsecs[0]
     4394
     4395    if gen.searchInlist(config['pairfigures'].split(':'), plotk):
     4396        Nvars = 2
     4397        varn1 = plotsecs[1]
     4398        if plotsecs[2] == 'diffvar' or plotsecs[2] == 'diffop':
     4399            statn1varn2 = plotsecs[5].split('-')
     4400            statn2 = plotsecs[6].split('.')[0]
     4401            Lstatn1varn2 = len(statn1varn2)
     4402            statn1 = '-'.join(statn1varn2[0:Lstatn1varn2-1])
     4403            varn2 = statn1varn2[Lstatn1varn2-1]
     4404        else:
     4405            statn1varn2 = plotsecs[3].split('-')
     4406            statn2 = plotsecs[5].split('.')[0]
     4407            Lstatn1varn2 = len(statn1varn2)
     4408            statn1 = '-'.join(statn1varn2[0:Lstatn1varn2-1])
     4409            varn2 = statn1varn2[Lstatn1varn2-1]
     4410        return Nvars, plotk, varn1+'-'+varn2, statn1+'@'+statn2
     4411    elif gen.searchInlist(config['Nsourcesfigures'].split(':'), plotk):
     4412        Nvars = 1
     4413        varn = plotsecs[1]
     4414        statn = plotsecs[3].split('.')[0]
     4415        return Nvars, plotk, varn, statn
     4416    else:
     4417        print errmsg
     4418        print '  ' + fname + ": kind of figure '" + plotk + "' not ready !!"
     4419        print '    ready ones _______'
     4420        print "    'pair_figures': figures of pair of variables: ",                  \
     4421          config['pairfigures'].split(':')
     4422        print "    'N-sources_figures': figures of pair of variables: ",                  \
     4423          config['Nsourcesfigures'].split(':')
     4424        quit(-1)
     4425   
    43804426# Files with information about the configuration of the script
    43814427inffiles = ['varcompute.inf', 'all_computevars.inf', 'all_statsvars.inf']
     
    53425388lvars = []
    53435389for plot in modexpimg:
    5344     plotk = plot.split('_')[0]
    5345     varn = plot.split('_')[1]
    5346     statn = plot.split('_')[3].split('.')[0]
     5390    Nvars, plotk, varn, statn = figinf_figname(plot,cnf)
    53475391    if not gen.searchInlist(lplots,plotk):
    53485392        lplots.append(plotk)
     
    53665410print '      variables:', lvars
    53675411
    5368 for var in lvars:
     5412for dplot in dplots.keys():
     5413    plot = dplot.split('_')[0]
     5414    var = dplot.split('_')[1]
    53695415    otexf.write('% ' + var + '\n')
    53705416    otexf.write('\\modexp{' + gen.latex_text(var) + '}\n')
    5371     for plot in lplots:
    5372         if dplots.has_key(plot+'_'+varn):
    5373             for stn in dplots[plot+'_'+varn]:
    5374                 plotvarfigs = []
    5375                 caption = varn + ' ' + plot + ' ' + stn + ' '
    5376                 flab = 'fig:' + varn + '_' + plot + '_' + stn + '_allmodexp'
    5377                 for me in lmodexps:
    5378                     modexpn = expGC[me].label
    5379                     modn = me.split('/')[0]
    5380                     imgns = gen.files_folder_HMT(owdir+'/'+me, head=plot+'_'+varn,   \
    5381                       middle=stn, tail=cnf['kindfig'])
    5382                     caption = caption + ', ' + modexpn
    5383                     imgn = owdir+'/'+me+'/'+imgns[0]
    5384                     if os.path.isfile(imgn):
    5385                         plotvarfigs.append(imgn)
    5386                 if dbg:
    5387                     print '      Grouping figures:', plotvarfigs
    5388                 try:
    5389                     with gen.Capturing() as output:
    5390                         gen.latex_fig_array(plotvarfigs, otexf,                      \
    5391                           gen.latex_text(caption), flab, refsize=0.5, dist='sqr',    \
    5392                           dorest='center')
    5393                 except:
    5394                     print errmsg
    5395                     print 'gen.latex_fig_array(',plotvarfigs,', '+otexf+', '+        \
    5396                           'gen.latex_text(' + caption + '), ' + flab +               \
    5397                           ", refsize=0.5, dist='sqr', dorest='center')"
    5398                     for s1out in output: print s1out
    5399                     quit(-1)
     5417    varn1 = var.split('-')[0]
     5418    varn2 = var.split('-')[1]
     5419    varn = varn1+'-'+varn2
     5420    for stn12 in dplots[dplot]:
     5421        stn1 = stn12.split('@')[0]
     5422        stn2 = stn12.split('@')[1]
     5423        stn = gen.lstring_values(stn12, '@',' & ')
     5424        plotvarfigs = []
     5425        caption = varn.replace('-',' & ') + ' ' + plot + ' ' + stn
     5426        flab = 'fig:' + varn + '_' + plot + '_' + stn12 + '_allmodexp'
     5427        for me in lmodexps:
     5428            modexpn = expGC[me].label
     5429            modn = me.split('/')[0]
     5430            imgns = gen.files_folder_HMT(owdir+'/'+me, head=plot+'_'+varn1,          \
     5431              middle=stn1+'-'+varn2, tail=stn2+'.'+cnf['kindfig'])
     5432            caption = caption + ', ' + modexpn
     5433            imgn = owdir+'/'+me+'/'+imgns[0]
     5434            if os.path.isfile(imgn):
     5435                plotvarfigs.append(imgn)
     5436        if dbg:
     5437            print '      Grouping figures:', plotvarfigs
     5438        try:
     5439            with gen.Capturing() as output:
     5440                gen.latex_fig_array(plotvarfigs, otexf, gen.latex_text(caption),     \
     5441                  flab, refsize=0.5, dist='sqr', dorest='center')
     5442        except:
     5443            print errmsg
     5444            print 'gen.latex_fig_array(',plotvarfigs,', '+otexf+', gen.latex_text(' +\
     5445               caption + '), ' + flab + ", refsize=0.5, dist='sqr', dorest='center')"
     5446            for s1out in output: print s1out
     5447            quit(-1)
    54005448
    54015449Nmods = len(mods)
     
    54145462lvars = []
    54155463for plot in modexpimg:
    5416     plotk = plot.split('_')[0]
    5417     varn = plot.split('_')[1]
    5418     statn = plot.split('_')[5].split('.')[0]
     5464    Nvars, plotk, varn, statn = figinf_figname(plot,cnf)
    54195465    if not gen.searchInlist(lplots,plotk):
    54205466        lplots.append(plotk)
     
    54375483print '      plots:', lplots
    54385484print '      variables:', lvars
    5439 
    5440 for var in lvars:
     5485print '      dplots:', dplots
     5486
     5487for dplot in dplots.keys():
     5488    plot = dplot.split('_')[0]
     5489    var = dplot.split('_')[1]
    54415490    otexf.write('% ' + var + '\n')
    54425491    otexf.write('\\modexp{diff ' + gen.latex_text(var) + '}\n')
    5443     for plot in lplots:
    5444         if dplots.has_key(plot+'_'+varn):
    5445             for stn in dplots[plot+'_'+varn]:
    5446                 plotvarfigs = []
    5447                 caption = varn + ' ' + plot + ' ' + stn + ' '
    5448                 flab = 'fig:' + varn + '_' + plot + '_' + stn + '_alldiffmodexp'
    5449                 for me in ldiffmodexps:
    5450                     mods = me.split('/')[0]
    5451                     exps = me.split('/')[1]
    5452                     if exps.find('-') != -1:
    5453                         expn1 = exps.split('-')[0]
    5454                         expn2 = exps.split('-')[1]
    5455                     else:
    5456                         expn1 = exps
    5457                         expn2 = exps
    5458 
    5459                     if mods.find('-') != -1:
    5460                         modn1 = mods.split('-')[0]
    5461                         modn2 = mods.split('-')[1]
    5462                     else:
    5463                         modn1 = mods
    5464                         modn2 = mods
    5465                     modexpn1 = expGC[modn1 + '/' + expn1].label
    5466                     modexpn2 = expGC[modn2 + '/' + expn2].label
    5467                     modexpn = modexpn1 + '-' + modexpn2
    5468 
    5469                     modn = me.split('/')[0]
    5470                     imgns = gen.files_folder_HMT(owdir+'/'+me, head=plot+'_'+varn,   \
    5471                       middle=stn, tail=cnf['kindfig'])
    5472                     caption = caption + ', ' + modexpn
    5473                     imgn = owdir+'/'+me+'/'+imgns[0]
    5474                     if os.path.isfile(imgn):
    5475                         plotvarfigs.append(imgn)
    5476                 if dbg:
    5477                     print '      Grouping figures:', plotvarfigs
    5478                 try:
    5479                     with gen.Capturing() as output:
    5480                         gen.latex_fig_array(plotvarfigs, otexf,                      \
    5481                           gen.latex_text(caption), flab, refsize=0.5, dist='sqr',    \
    5482                           dorest='center')
    5483                 except:
    5484                     print errmsg
    5485                     print 'gen.latex_fig_array(',plotvarfigs,', '+otexf+', '+        \
    5486                           'gen.latex_text(' + caption + '), ' + flab +               \
    5487                           ", refsize=0.5, dist='sqr', dorest='center')"
    5488                     for s1out in output: print s1out
    5489                     quit(-1)
     5492    varn1 = var.split('-')[0]
     5493    varn2 = var.split('-')[1]
     5494    varn = varn1+'-'+varn2
     5495    for stn12 in dplots[dplot]:
     5496        stn1 = stn12.split('@')[0]
     5497        stn2 = stn12.split('@')[1]
     5498        stn = gen.lstring_values(stn12, '@',' & ')
     5499        plotvarfigs = []
     5500        caption = varn.replace('-',' & ') + ' ' + plot + ' ' + stn
     5501        flab = 'fig:' + varn + '_' + plot + '_' + stn12 + '_alldiffmodexp'
     5502        for me in ldiffmodexps:
     5503            mods = me.split('/')[0]
     5504            exps = me.split('/')[1]
     5505            if exps.find('-') != -1:
     5506                expn1 = exps.split('-')[0]
     5507                expn2 = exps.split('-')[1]
     5508            else:
     5509                expn1 = exps
     5510                expn2 = exps
     5511
     5512            if mods.find('-') != -1:
     5513                modn1 = mods.split('-')[0]
     5514                modn2 = mods.split('-')[1]
     5515            else:
     5516                modn1 = mods
     5517                modn2 = mods
     5518            modexpn1 = expGC[modn1 + '/' + expn1].label
     5519            modexpn2 = expGC[modn2 + '/' + expn2].label
     5520            modexpn = modexpn1 + '-' + modexpn2
     5521
     5522            modn = me.split('/')[0]
     5523            imgns = gen.files_folder_HMT(owdir+'/'+me, head=plot+'_'+varn1,          \
     5524              middle=stn1+'-'+varn2, tail=stn2+'.'+cnf['kindfig'])
     5525            caption = caption + ', ' + modexpn
     5526            imgn = owdir+'/'+me+'/'+imgns[0]
     5527            if os.path.isfile(imgn):
     5528                plotvarfigs.append(imgn)
     5529        if dbg:
     5530            print '      Grouping figures:', plotvarfigs
     5531        try:
     5532            with gen.Capturing() as output:
     5533                gen.latex_fig_array(plotvarfigs, otexf, gen.latex_text(caption),     \
     5534                  flab, refsize=0.5, dist='sqr', dorest='center')
     5535        except:
     5536            print errmsg
     5537            print 'gen.latex_fig_array(',plotvarfigs,', '+otexf+', gen.latex_text('+ \
     5538              caption + '), ' + flab + ", refsize=0.5, dist='sqr', dorest='center')"
     5539            for s1out in output: print s1out
     5540            quit(-1)
    54905541
    54915542otexf.write('\\end{document}\n')
Note: See TracChangeset for help on using the changeset viewer.