Changeset 1327 in lmdz_wrf for trunk


Ignore:
Timestamp:
Nov 14, 2016, 10:01:57 PM (8 years ago)
Author:
lfita
Message:

Adding grouping of figures by variable
Fixing wrong loop on modexp differences

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/model_graphics.py

    r1325 r1327  
    27142714    diffvar = gen.get_specdictionary_HMT(config, H='DIFFVAR_')
    27152715
     2716    print '  ' + fname + '; Lluis HERE !!!'
     2717
    27162718    if debug:
    27172719        if diffop is not None:
     
    46444646            # op and var differences
    46454647            diffvarcompf = owdir + '/' + difffiles[0]
     4648            print 'Lluis HERE !2!1!: diffvarcompf:', diffvarcompf
    46464649            if not os.path.isfile(diffvarcompf):
    46474650                alldiffop, alldiffvar,Nopdiffs,Nvardiffs=diffvarop_listconstruct(cnf,\
     
    46504653                if dbg:
    46514654                    print warnmsg
    4652                     print '  ' + main + ": getting 'op' and 'var'differences to " + \
     4655                    print '  ' + main + ": getting 'op' and 'var' differences to " + \
    46534656                      "compute already from file !!"
    46544657                alldiffop, Nopdiffops = read_diff_file(diffvarcompf)
    46554658                alldiffvar, Nopdiffvars = read_diff_file(owdir+'/'+difffiles[1])
    4656 
    4657         # End of avoiding to repeat all the experiment search
    4658 
    4659         print "    For experiments '"+exp2+"'-'"+exp1+"' is required to compute:",   \
    4660           Nvar, "differences"
    4661 
    4662         if dbg:
    4663             print 'Differences to compute _______'
    4664             gen.printing_dictionary(alldiffop)
    4665             gen.printing_dictionary(alldiffvar)
    4666 
    4667         # Computing differences
    4668         ##
    4669         print "    Computing operation differences ..."
    4670         compute_op_diffs(cnf, alldiffop, owdir, diffscratch, dbg)
    4671         print "    Computing variable differences ..."
    4672         compute_var_diffs(cnf, alldiffvar, owdir, diffscratch, dbg)
    4673 
    4674         # Plotting operation differences
    4675         ##
    4676         print "  " + main + ": Plotting operation differences' figures ..."
    4677         dirfigf = owdir + '/diffopplotsdraw.inf'
    4678         if figscratch:
    4679             sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True)
    4680 
    4681             objf = open(owdir+'/all_diffopfigures.inf','w')
    4682             objf.write("## Drawing of all operation difference figures \n")
    4683             objf.close()
    4684 
    4685         if adddifffigures:
     4659                print 'Nopdiffops:', Nopdiffops,'Nopdiffvars:', Nopdiffvars
     4660
     4661            # End of avoiding to repeat all the experiment search
     4662            print "    For experiments '"+exp2+"'-'"+exp1+"' is required to " +      \
     4663              "compute:", Nvar, "differences"
     4664
    46864665            if dbg:
    4687                 print '  ' + main + ": adding differences' figures removing file '" +\
    4688                   dirfigf + "' ..."
    4689 
    4690             sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True)
    4691 
    4692         if not os.path.isfile(dirfigf):
    4693             listplots, Nplt = plots_listconstruct(cnf, 'PLOTDIFFOP', dirfigf, owdir, \
    4694               dbg)
    4695         else:
     4666                print 'Differences to compute _______'
     4667                gen.printing_dictionary(alldiffop)
     4668                gen.printing_dictionary(alldiffvar)
     4669
     4670            # Computing differences
     4671            ##
     4672            print "    Computing operation differences ..."
     4673            compute_op_diffs(cnf, alldiffop, owdir, diffscratch, dbg)
     4674            print "    Computing variable differences ..."
     4675            compute_var_diffs(cnf, alldiffvar, owdir, diffscratch, dbg)
     4676
     4677            # Plotting operation differences
     4678            ##
     4679            print "  " + main + ": Plotting operation differences' figures ..."
     4680            dirfigf = owdir + '/diffopplotsdraw.inf'
     4681            if figscratch:
     4682                sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True)
     4683
     4684                objf = open(owdir+'/all_diffopfigures.inf','w')
     4685                objf.write("## Drawing of all operation difference figures \n")
     4686                objf.close()
     4687
     4688            if adddifffigures:
     4689                if dbg:
     4690                    print '  ' + main + ": adding differences' figures removing " +  \
     4691                      "file '" + dirfigf + "' ..."
     4692
     4693                sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True)
     4694
     4695            if not os.path.isfile(dirfigf):
     4696                listplots, Nplt = plots_listconstruct(cnf, 'PLOTDIFFOP', dirfigf,    \
     4697                  owdir, dbg)
     4698            else:
     4699                if dbg:
     4700                    print warnmsg
     4701                    print '  ' + main + ": getting plots to draw already from file !!"
     4702                listplots, Nplt = read_plot_file(dirfigf)
     4703
     4704            # End of avoiding to repeat all the plots search
     4705
     4706            print "  For experiment 'operation' differences '" + Sexps + "' is " +   \
     4707              "required to plot:" , Nplt, "plots"
     4708
    46964709            if dbg:
    4697                 print warnmsg
    4698                 print '  ' + main + ": getting plots to draw already from file !!"
    4699             listplots, Nplt = read_plot_file(dirfigf)
    4700 
    4701         # End of avoiding to repeat all the plots search
    4702 
    4703         print "  For experiment 'operation' differences '" + Sexps + "' is " +       \
    4704           "required to plot:" , Nplt, "plots"
    4705 
    4706         if dbg:
    4707             print '    Plots to draw _______'
    4708             gen.printing_dictionary(listplots)
    4709 
    4710         draw_diff_plots(cnf, listplots, owdir, alldiffop, 'diffop', figdiffscratch,  \
    4711           dbg)
    4712 
    4713         # Plotting variable differences
    4714         ##
    4715         print "  " + main + ": Plotting variable differences' figures ..."
    4716         dirfigf = owdir + '/diffvarplotsdraw.inf'
    4717         if figscratch:
    4718             sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True)
    4719 
    4720             objf = open(owdir+'/all_diffvarfigures.inf','w')
    4721             objf.write("## Drawing of all variables difference figures \n")
    4722             objf.close()
    4723 
    4724         if adddifffigures:
     4710                print '    Plots to draw _______'
     4711                gen.printing_dictionary(listplots)
     4712
     4713            draw_diff_plots(cnf, listplots, owdir, alldiffop, 'diffop',              \
     4714              figdiffscratch, dbg)
     4715
     4716            # Plotting variable differences
     4717            ##
     4718            print "  " + main + ": Plotting variable differences' figures ..."
     4719            dirfigf = owdir + '/diffvarplotsdraw.inf'
     4720            if figscratch:
     4721                sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True)
     4722
     4723                objf = open(owdir+'/all_diffvarfigures.inf','w')
     4724                objf.write("## Drawing of all variables difference figures \n")
     4725                objf.close()
     4726
     4727            if adddifffigures:
     4728                if dbg:
     4729                    print '  '+main+": adding differences' figures removing file '" +\
     4730                      dirfigf + "' ..."
     4731                sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True)
     4732
     4733            if not os.path.isfile(dirfigf):
     4734                listplots, Nplt = plots_listconstruct(cnf, 'PLOTDIFFVAR', dirfigf,   \
     4735                  owdir, dbg)
     4736            else:
     4737                if dbg:
     4738                    print warnmsg
     4739                    print '  ' + main + ": getting plots to draw already from file !!"
     4740                listplots, Nplt = read_plot_file(dirfigf)
     4741
     4742            # End of avoiding to repeat all the plots search
     4743
     4744            print "  For experiment 'variables' differences '" + Sexps + "' is " +   \
     4745              "required to plot:" , Nplt, "plots"
     4746 
    47254747            if dbg:
    4726                 print '  ' + main + ": adding differences' figures removing file '" +\
    4727                   dirfigf + "' ..."
    4728             sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True)
    4729 
    4730         if not os.path.isfile(dirfigf):
    4731             listplots, Nplt = plots_listconstruct(cnf, 'PLOTDIFFVAR', dirfigf, owdir,\
    4732               dbg)
    4733         else:
    4734             if dbg:
    4735                 print warnmsg
    4736                 print '  ' + main + ": getting plots to draw already from file !!"
    4737             listplots, Nplt = read_plot_file(dirfigf)
    4738 
    4739         # End of avoiding to repeat all the plots search
    4740 
    4741         print "  For experiment 'variables' differences '" + Sexps + "' is " +       \
    4742           "required to plot:" , Nplt, "plots"
    4743 
    4744         if dbg:
    4745             print '    Plots to draw _______'
    4746             gen.printing_dictionary(listplots)
    4747 
    4748         draw_diff_plots(cnf, listplots, owdir, alldiffvar, 'diffvar', figdiffscratch,\
    4749           dbg)
     4748                print '    Plots to draw _______'
     4749                gen.printing_dictionary(listplots)
     4750
     4751            draw_diff_plots(cnf, listplots, owdir, alldiffvar, 'diffvar',            \
     4752              figdiffscratch, dbg)
    47504753
    47514754# end of mods loop
     
    51345137
    51355138Nmods = len(mods)
     5139lmodexps = []
     5140ldiffmodexps = []
    51365141# Figures from mod/exp pairs
    51375142for mod in mods:
     
    51395144    for exp in exps:
    51405145        print '  direct plots:', mod, exp
     5146        lmodexps.append(mod+'/'+exp)
    51415147        owdirme = owdir + '/' + mod + '/' + exp
    51425148        otexf.write('% ' + mod + ' ' + exp + '\n')
     
    51665172                    except:
    51675173                        print errmsg
    5168                         print 'gen.latex_fig_array('+modexpimg+', '+otexf+', '+      \
     5174                        print 'gen.latex_fig_array(',modexpimg,', '+otexf+', '+      \
    51695175                              'gen.latex_text(' + caption + '), ' + flab +           \
    51705176                              ", refsize=0.5, dist='sqr', dorest='center')"
     
    51825188            owdirme = owdir + '/' + mod + '/' + Sexps
    51835189            print '    diffs:',  mod + '/' + Sexps + ' ...'
     5190            ldiffmodexps.append(mod + '/' + Sexps)
    51845191            for diffn in ['op', 'var']:
    51855192                fileplotinf = owdirme + '/diff' + diffn + 'plotsdraw.inf'
     
    52135220                                except:
    52145221                                    print errmsg
    5215                                     print 'gen.latex_fig_array('+modexpimg+', '+     \
     5222                                    print 'gen.latex_fig_array(',modexpimg,', '+     \
    52165223                                      otexf+', gen.latex_text(' + caption + '), ' +  \
    52175224                                      flab + ", refsize=0.5, dist='sqr', " +         \
     
    52385245                Sexps = exp2 + '-' + exp1
    52395246                print '      ' + Smods + ' ' + Sexps + ' ...'
     5247                ldiffmodexps.append(Smods + '/' + Sexps)
    52405248                owdirme = owdir + '/' + Smods + '/' + Sexps
    52415249                for diffn in ['op', 'var']:
     
    52715279                                        except:
    52725280                                            print errmsg
    5273                                             print 'gen.latex_fig_array('+modexpimg+  \
     5281                                            print 'gen.latex_fig_array(',modexpimg,  \
    52745282                                              ', '+otexf+', gen.latex_text(' +       \
    52755283                                              caption + '), '+flab+ ", refsize=0.5,"+\
     
    53095317                except:
    53105318                    print errmsg
    5311                     print 'gen.latex_fig_array('+modexpimg+', '+otexf+               \
     5319                    print 'gen.latex_fig_array(',modexpimg,', '+otexf+               \
    53125320                      ', gen.latex_text(' + caption + '), ' +flab+ ", refsize=0.5," +\
    53135321                      " dist='sqr', dorest='center')"
     
    53165324
    53175325                otexf.write('%\\clearpage\n')
     5326#
     5327# Grouping by type of figure
     5328#
     5329Nmods = len(mods)
     5330# Figures from mod/exp pairs
     5331owsearch = owdir + '/' + mods[0] + '/' + modexps[mods[0]][0]
     5332print "  Looking in '" + owsearch + "' for figures by kind and variable..."
     5333otexf.write('% figures by kind and variable from:' + owsearch + '\n')
     5334modexpimg = gen.files_folder_HMT(owsearch, tail=cnf['kindfig'])
     5335# dictionary with kind of plots
     5336dplots = {}
     5337# list with kind of plots
     5338lplots = []
     5339# dictionary with variable-statistics of each kind of plot
     5340dvarstats = {}
     5341# list with variables of each kind of plot
     5342lvars = []
     5343for plot in modexpimg:
     5344    plotk = plot.split('_')[0]
     5345    varn = plot.split('_')[1]
     5346    statn = plot.split('_')[3].split('.')[0]
     5347    if not gen.searchInlist(lplots,plotk):
     5348        lplots.append(plotk)
     5349        if not dplots.has_key(plotk+'_'+varn):
     5350            if not gen.searchInlist(lvars,varn): lvars.append(varn)
     5351            dplots[plotk+'_'+varn] = [statn]
     5352        else:
     5353            vals = dplots[plotk+'_'+varn]
     5354            dplots[plotk+'_'+varn] = vals + [statn]
     5355    else:
     5356        if not dplots.has_key(plotk+'_'+varn):
     5357            if not gen.searchInlist(lvars,varn): lvars.append(varn)
     5358            dplots[plotk+'_'+varn] = [statn]
     5359        else:
     5360            vals = dplots[plotk+'_'+varn]
     5361            dplots[plotk+'_'+varn] = vals + [statn]
     5362       
     5363# Figures found
     5364print '    direct figures to group:', modexpimg
     5365print '      plots:', lplots
     5366print '      variables:', lvars
     5367
     5368for var in lvars:
     5369    otexf.write('% ' + var + '\n')
     5370    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)
     5400
     5401Nmods = len(mods)
     5402# Figures from mod/exp differences
     5403owsearch = owdir + '/' + ldiffmodexps[0]
     5404print "  Looking in '" + owsearch + "' for difference figures by kind and variable..."
     5405otexf.write('% difference figures by kind and variable from:' + owsearch + '\n')
     5406modexpimg = gen.files_folder_HMT(owsearch, tail=cnf['kindfig'])
     5407# dictionary with kind of plots
     5408dplots = {}
     5409# list with kind of plots
     5410lplots = []
     5411# dictionary with variable-statistics of each kind of plot
     5412dvarstats = {}
     5413# list with variables of each kind of plot
     5414lvars = []
     5415for plot in modexpimg:
     5416    plotk = plot.split('_')[0]
     5417    varn = plot.split('_')[1]
     5418    statn = plot.split('_')[5].split('.')[0]
     5419    if not gen.searchInlist(lplots,plotk):
     5420        lplots.append(plotk)
     5421        if not dplots.has_key(plotk+'_'+varn):
     5422            if not gen.searchInlist(lvars,varn): lvars.append(varn)
     5423            dplots[plotk+'_'+varn] = [statn]
     5424        else:
     5425            vals = dplots[plotk+'_'+varn]
     5426            dplots[plotk+'_'+varn] = vals + [statn]
     5427    else:
     5428        if not dplots.has_key(plotk+'_'+varn):
     5429            if not gen.searchInlist(lvars,varn): lvars.append(varn)
     5430            dplots[plotk+'_'+varn] = [statn]
     5431        else:
     5432            vals = dplots[plotk+'_'+varn]
     5433            dplots[plotk+'_'+varn] = vals + [statn]
     5434       
     5435# Figures found
     5436print '    difference figures to group:', modexpimg
     5437print '      plots:', lplots
     5438print '      variables:', lvars
     5439
     5440for var in lvars:
     5441    otexf.write('% ' + var + '\n')
     5442    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)
    53185490
    53195491otexf.write('\\end{document}\n')
Note: See TracChangeset for help on using the changeset viewer.