Changeset 1085 in lmdz_wrf


Ignore:
Timestamp:
Sep 5, 2016, 7:52:06 PM (9 years ago)
Author:
lfita
Message:

First working version with `Nlines'
Inclusion of computation of reprojected statistics from initial variable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/tools/model_graphics.py

    r1082 r1085  
    290290           self.model= model
    291291           self.diag= diag
     292
     293class ModelInf(object):
     294    """ Class which holds all information from a given model
     295      name= Acronym of the model
     296      model= Long description of the model
     297      dim[x/y/z/t/s]n= name of the dimensions of the model
     298      vdim[x/y/z/t/s]n= name of the variable-dimensions of the model
     299      dimensions= list of the dimensions
     300      vardimensions= list of the variable-dimensions
     301    """
     302    def __init__( self, name, model, dx, dy, dz, dt, ds, vdx, vdy, vdz, vdt, vds):
     303       self.name= None
     304       self.model= None
     305       self.dimxn= None
     306       self.dimyn= None
     307       self.dimzn= None
     308       self.dimtn= None
     309       self.dimsn= None
     310       self.vardxn= None
     311       self.vardyn= None
     312       self.vardzn= None
     313       self.vardtn= None
     314       self.vardsn= None
     315       if name is not None:
     316           self.name = name
     317           self.model= model
     318           self.dimxn= dx
     319           self.dimyn= dy
     320           self.dimzn= dz
     321           self.dimtn= dt
     322           self.dimsn= ds
     323           self.vardxn= vdx
     324           self.vardyn= vdy
     325           self.vardzn= vdz
     326           self.vardtn= vdt
     327           self.vardsn= vds
     328           self.dimensions = [dx, dy, dz, dt, ds]
     329           self.vardimensions = [vdx, vdy, vdz, vdt, vds]
    292330
    293331def variable_compute(idir,var,ftests,db):
     
    15751613        if db:
    15761614            print "    drawing '" + finame + "' ..."
     1615            print '      plot kind:', kplot
    15771616            print '      CFvars:', CFvplot
    15781617            print '      files:', fplot
     
    16071646            lineA = pplot[0]
    16081647            Arange = str(lineA[0]) + ',' + str(lineA[1])
    1609             Akind = lineA[4]
    1610             Aline = lineA[5]
     1648            # Values are changed from specific values in `model_graphics.dat'
     1649            if lineA[3].find('%') == -1:
     1650                Aline = lineA[2]
     1651                Akind = lineA[3]
     1652                Amark = lineA[4]
     1653                Asize = lineA[5]
     1654            else:
     1655                Aline = 'red'
     1656                Akind = '-'
     1657                Amark = ','
     1658                Asize = 2.
    16111659
    16121660            lineB = pplot[0]
    16131661            Brange = str(lineB[0]) + ',' + str(lineB[1])
    1614             Bkind = lineB[4]
    1615             Bline = lineB[5]
     1662            # Values are changed from specific values in `model_graphics.dat'
     1663            if lineB[3].find('%') == -1:
     1664                Bline = lineB[2]
     1665                Bkind = lineB[3]
     1666                Bmark = lineB[4]
     1667                Bsize = lineB[5]
     1668            else:
     1669                Bline = 'blue'
     1670                Bkind = '-'
     1671                Bmark = ','
     1672                Bsize = '2.'
    16161673
    16171674            # It is assumed that if the space variable is 'lon': is desired a
    16181675            #   (lon, vals) plot if it is 'lat': then (vals, lat) plot
    1619             if gen.searchInlist(dplot,'lon'):
     1676            if gen.searchInlist(dplot[0],'lon'):
    16201677                spacedim ='lon'
    16211678                axisvals = 'y'
    16221679                figmid = 'longitudinal'
    1623             elif gen.searchInlist(dplot,'lat'):
     1680            elif gen.searchInlist(dplot[0],'lat'):
    16241681                spacedim = 'lat'
    16251682                axisvals = 'x'
    16261683                figmid = 'meridional'
    1627             elif gen.searchInlist(dplot,'pres'):
     1684            elif gen.searchInlist(dplot[0],'pres'):
    16281685                spacedim = 'pres'
    16291686                axisvals = 'x'
     
    16331690                print '  ' + fname + ": in '2lines' only ready for: 'lon', 'lat'," + \
    16341691                 " 'pres' as common dimension !!"
    1635                 print '  dimensions in plot:', dplot
     1692                print '  dimensions in plot:', dplot[0]
    16361693                quit(-1)
    16371694
     
    16411698            graphvals = spacedim + ':' + Arange + ':' + Brange + ':Extrs:' +         \
    16421699              axisvals + ':' + ','.join(CFvplot) + ':' + Aline + ',' + Bline +       \
    1643               ':2.,2.:' + Akind + ',' + Bkind + ':,:' + figtit + ':' + spacedim +    \
    1644               ':0:' +  finame.replace('.'+kfig, '') + ':' + kfig
     1700              ':2.,2.:' + Akind + ',' + Bkind + ':2.,2.:,:' + figtit + ':' +         \
     1701              spacedim + ':0:' +  finame.replace('.'+kfig, '') + ':' + kfig
    16451702
    16461703            fvarS = ','.join(vplot)
     
    16841741                Akind = '-'
    16851742                Amark = ','
    1686                 Asize = 2.
     1743                Asize = '2.'
    16871744
    16881745            lineB = pplot[1]
     
    16951752                Bsize = lineB[5]
    16961753            else:
    1697                 Bline = 'red'
     1754                Bline = 'blue'
    16981755                Bkind = '-'
    16991756                Bmark = ','
    1700                 Bsize = 2.
     1757                Bsize = '2.'
    17011758
    17021759            timeaxis = 'x'
     
    17141771
    17151772            drwins = 'draw_2lines_time'
     1773            plotins = 'python ' + pyH + '/drawing.py -f ' + figfs +' -o ' + drwins + \
     1774              " -S '" + graphvals + "' -v " + fvarS
     1775
     1776            try:
     1777                with gen.Capturing() as output:
     1778                    sout = sub.call(plotins, shell=True)
     1779            except:
     1780                print errmsg
     1781                print drwins + '(' + graphvals + ',' + figfs + ',' + fvarS + ')'
     1782                print sout
     1783                for s1out in output: print s1out
     1784                quit(-1)
     1785
     1786            # keeping all figures
     1787            trkobjf.write('\n')
     1788            trkobjf.write("#" + tfig.replace('!',' ') + '\n')
     1789            trkobjf.write(plotins + '\n')
     1790
     1791        elif kplot == 'Nlines':
     1792            figtit = tfig.replace('!','|')
     1793
     1794            linestdn = CFvplot[0]
     1795            figfs = ','.join(fplot)
     1796
     1797            Nlines = len(fplot)
     1798
     1799            lablines = []
     1800            for il in range(Nlines):
     1801                linev = pplot[il]
     1802                # Values are changed from specific values in `model_graphics.dat'
     1803                if linev[3].find('%') == -1:
     1804                    line = linev[2]
     1805                    kind = linev[3]
     1806                    mark = linev[4]
     1807                    size = linev[5]
     1808                    if il == 0:
     1809                        vrange = str(linev[0]) + ',' + str(linev[1])
     1810                        kinds = kind
     1811                        lines = line
     1812                        marks = mark
     1813                        sizes = str(size)
     1814                    else:
     1815                        kinds = kinds + ',' + kind
     1816                        lines = lines + ',' + line
     1817                        marks = marks + ',' + mark
     1818                        sizes = sizes + ',' + str(size)
     1819                else:
     1820                    lines = 'None'
     1821                    kinds = '-'
     1822                    marks = ','
     1823                    sizes = '2.'
     1824
     1825
     1826                secsf = fplot[il].split('/')
     1827                Nsecsf = len(secsf)
     1828                lablines.append(secsf[Nsecsf-3] + '/' + secsf[Nsecsf-2])
     1829
     1830            # It is assumed that if the space variable is 'lon': is desired a
     1831            #   (lon, vals) plot if it is 'lat': then (vals, lat) plot
     1832            if gen.searchInlist(dplot[0],'lon'):
     1833                spacedim ='lon'
     1834                axisvals = 'y'
     1835                figmid = 'longitudinal'
     1836            elif gen.searchInlist(dplot[0],'lat'):
     1837                spacedim = 'lat'
     1838                axisvals = 'x'
     1839                figmid = 'meridional'
     1840            elif gen.searchInlist(dplot[0],'pres'):
     1841                spacedim = 'pres'
     1842                axisvals = 'x'
     1843                figmid = 'vertical'
     1844            else:
     1845                print errmsg
     1846                print '  ' + fname + ": in 'Nlines' only ready for: 'lon', 'lat'," + \
     1847                 " 'pres' as common dimension !!"
     1848                print '  dimensions in plot:', dplot[0]
     1849                quit(-1)
     1850
     1851            figtit = '|'.join(tfig.split('!')[0:2]) + '|' + figmid + '|' +           \
     1852              '|'.join(tfig.split('!')[2:])
     1853            leglabels = ','.join(lablines)
     1854
     1855            graphvals = spacedim + ':' + axisvals + ':' + spacedim + ':' +           \
     1856              leglabels + ':' + CFvplot[0] + ':' + figtit + ':0:' + lines + ':' +    \
     1857              kinds + ':' + marks +':'+ sizes +':'+ sizes + ':all:' +                \
     1858              finame.replace('.'+kfig, '') + ':' + kfig
     1859
     1860            fvarS = vplot[0]
     1861
     1862            drwins = 'draw_lines'
    17161863            plotins = 'python ' + pyH + '/drawing.py -f ' + figfs +' -o ' + drwins + \
    17171864              " -S '" + graphvals + "' -v " + fvarS
     
    18341981            trkobjf.write(plotins + '\n')
    18351982
    1836         elif 'shadcont2Dzsec':
     1983        elif kplot == 'shadcont2Dzsec':
    18371984            figtit = tfig.replace('!','|')
    18381985            shdstdn = CFvplot[0]
     
    24032550            values = line.replace('\n','').split(' ')
    24042551            if values[0] == 'differences:':
    2405                 diffs = gen.stringList_dictKeysVals(values[1])
     2552                if values[1] != 'none':
     2553                    diffs = gen.stringList_dictKeysVals(values[1])
     2554                else:
     2555                    diffs = {}
    24062556            elif values[0] == 'Ndiff:':
    24072557                Ndiffs = int(values[1])
     
    24762626        if not os.path.isfile(difffilen):
    24772627            if debug:
    2478                 print "  Computing operation difference '" + op + "' of '" + vn +    \
     2628                print "    Computing operation difference '" + op + "' of '" + vn +  \
    24792629                  "' for: '" + modexpdiff
    24802630                print "    var in file: '" + vninF + "'"
     
    30113161        if not os.path.isfile(difffinalfilen):
    30123162            if debug:
    3013                 print "  Computing variable difference of '" + vn + "' for: '" +     \
     3163                print "    Computing variable difference of '" + vn + "' for: '" +   \
    30143164                  modexpdiff + "' and performing operation '" + Sdoops + "'"
    30153165                print "    var in file: '" + vninF + "'"
     
    34223572                  " values from each model"
    34233573
     3574                # Building up resources to compute re-projected statistics
     3575                print '  ' + fname + ': computing from the original reprojected file'
     3576                ModI = ModelInf(mod, mod, 'lon', 'lat', 'pres', 'time', 'depth',     \
     3577                  'lon', 'lat', 'pres', 'time', 'depth')
     3578                VarI = VariableInf(vn, values[0], values[2], values[3])
     3579                usefs = {values[0]: ofileorig}
     3580
     3581                compute_statistics(ModI, config, config['ifold'], usefs,             \
     3582                  config['ofold']+'/'+mod+'/'+exp,VarI,pinterp_var(op), op, fscr, dbg)
     3583
    34243584            if not os.path.isfile(ofile) and doreproj:
    34253585                if debug and ofile == ofiles[0]:
     
    35603720    return allplts, Nallmodexp
    35613721
    3562 def read_allmodexp_file(filen):
     3722def allmodexps_read(filen):
    35633723    """ Function to read the file with the information about the all model-experiment plots
    35643724      filen= file with the information
    35653725    """
    3566     fname = 'read_allmodexp_file'
     3726    fname = 'allmodexps_read'
    35673727
    35683728    if not os.path.isfile(filen):
     
    36073767
    36083768    os.chdir(odir)
     3769
     3770    # Folder with the processed files
     3771    infold = config['ofold']
    36093772
    36103773    # Dictionary with the operations with surnames for the operated variable
     
    36993862                CFvarsplot.append(vn)
    37003863 
    3701                 vnopS = vn + '_' + op
     3864                if op.find('pinterp') != -1: gP = 'p'
     3865                else: gP = ''
     3866
     3867                vnopS = vn + '_' + op                   
    37023868                if not allvarcomp.has_key(vnopS):
    37033869                    print errmsg
    3704                     print '  ' + fname + ": no file for variable-operation '" +     \
     3870                    print '  ' + fname + ": no file for variable-operation '" +      \
    37053871                      vnopS + "' !!"
    3706                 vopvals = allvarcomp[vnopS]
    3707                 headf = vopvals[0]
    3708                 globalP = vopvals[3]
    3709                 gP = pinterpS(globalP)
    3710 
    3711                 filen = vn + '_' + headf + gP + '_' + op.replace('+','_') + '.nc'
    3712                 filesplot.append(filen)
    3713                 # Do we have processed the given variable?
    3714                 if not os.path.isfile(filen):
    3715                     print warnmsg
    3716                     print "  " + fname + ": there is no file for variable '" + varop \
    3717                       + "' skiping it !!"
    3718                     break
    3719 
    3720                 # Name of the variable inside the file
    3721                 vnsur = varnoper(vn, op, opersurnames)
    3722                 varsplot.append(vnsur)
    3723 
    3724                 # Dimensions in file
    3725                 try:
    3726                     with gen.Capturing() as output:
    3727                         dims = ncvar.idims(filen)
    3728                 except:
    3729                     print errmsg
    3730                     print 'ncvar.idims('+filen+')'
    3731                     for s1out in output: print s1out
    3732                     quit(-1)
    3733 
    3734                 dimsplot.append(dims)
    3735 
    3736                 # pictoric values for the figure
    3737                 Sfivaop = kplot + '_' + vn + '_' + op
    3738                 if plotspecifics.has_key(Sfivaop):
    3739                     pictvals = plotspecifics[Sfivaop]
    3740                 else:
    3741                     Vvals = gen.variables_values(vn)
    3742                     pictvals = [Vvals[2], Vvals[3], Vvals[6], '%g', 'fixc', 'black']
    3743 
    3744                 pictplot.append(pictvals)
    3745 
    3746                 # Header of the name of the figure
    3747                 if ivp == 0:
    3748                     figname = kplot +'_'+ vn + '_' + headf + '_' + op.replace('+','-')
    3749                 else:
    3750                     figname = figname + '-'+vn+'_'+headf+'_'+op.replace('+','-')
     3872                modexpvals = allvarcomp[vnopS]
     3873                Nmodexps = len(modexpvals)
     3874
     3875                for imodexp in range(0,Nmodexps,2):
     3876                    modexp = modexpvals[imodexp]
     3877                    headf = modexpvals[imodexp+1]
     3878                    if debug:
     3879                        print '  ' + fname + "    model/experiment: '" +  modexp + "'"
     3880
     3881                    filen = infold + '/' + modexp + '/' + vn +'_'+ headf+gP + '_' +  \
     3882                      op.replace('+','_') + '.nc'
     3883
     3884                    filesplot.append(filen)
     3885                    # Do we have processed the given variable?
     3886                    if not os.path.isfile(filen):
     3887                        print warnmsg
     3888                        print "  " + fname + ": there is no file for variable '" +   \
     3889                          varop + "' skiping it !!"
     3890                        break
     3891
     3892                    if imodexp == 0:
     3893                        # Name of the variable inside the file
     3894                        vnsur = varnoper(vn, op, opersurnames)
     3895                        varsplot.append(vnsur)
     3896
     3897                    # Dimensions in file
     3898                    try:
     3899                        with gen.Capturing() as output:
     3900                            dims = ncvar.idims(filen)
     3901                    except:
     3902                        print errmsg
     3903                        print 'ncvar.idims('+filen+')'
     3904                        for s1out in output: print s1out
     3905                        quit(-1)
     3906
     3907                    if imodexp == 0:
     3908                        # Dimensions in plot
     3909                        dimsplot.append(dims)
     3910
     3911                        # Header of the name of the figure
     3912                        if ivp == 0:
     3913                            figname = kplot+'_'+vn+'_'+headf+'_'+ op.replace('+','-')
     3914                        else:
     3915                            figname = figname+'-'+vn+'_'+headf+'_'+op.replace('+','-')
     3916
     3917                    # pictoric values for the figure
     3918                    Sfivaop = kplot + '_' + vn + '_' + op
     3919                    if plotspecifics.has_key(Sfivaop):
     3920                        pictvals = plotspecifics[Sfivaop]
     3921                    else:
     3922                        Vvals = gen.variables_values(vn)
     3923                        pictvals = [Vvals[2],Vvals[3],Vvals[6], '%g', 'fixc', 'black']
     3924
     3925                    pictplot.append(pictvals)
    37513926
    37523927                ivp = ivp + 1
     
    37553930
    37563931            # Title of figure
    3757             titfigure = create_figure_title(mod, exp, varops, opexplained)
     3932            titfigure = 'all model-experiments ' + vn + optitle(op,opexplained)
    37583933
    37593934            draw_plot(kplot, CFvarsplot, filesplot, varsplot, dimsplot, pictplot,    \
     
    38484023        # Does input folder exist?
    38494024        if not os.path.isdir(iwdir):
    3850             print errmsg
    3851             print "  " + main + ": folder '" + iwdir + "' does not exist !!"
    3852             quit(-1)
     4025            if filescratch*addfiles:
     4026                print errmsg
     4027                print "  " + main + ": folder '" + iwdir + "' does not exist !!"
     4028                quit(-1)
     4029            else:
     4030                print warnmsg
     4031                print "  " + main + ": folder '" + iwdir + "' does not exist !!"
     4032                print "    but start of files from scratch 'filescratch':",          \
     4033                  filescratch, "and there is not the add of any file 'addfiles':",   \
     4034                  addfiles
     4035                print '    so, keep moving'
    38534036
    38544037        owdir = cnf['ofold'] + '/' + mod + '/' + exp
     
    42744457
    42754458                if dbg:
    4276                     print 'Differences to compute _______'
     4459                    print '    op differences to compute _______'
    42774460                    gen.printing_dictionary(alldiffop)
     4461                    print '    var differences to compute _______'
    42784462                    gen.printing_dictionary(alldiffvar)
    42794463
     
    44144598    allmodexpvar, Nallmodexpvar = allmodexps_read(allf)
    44154599
    4416 #draw_allmodexp_plots(cnf, listplots, owdir, allmodexpvar, 'diffvar', figallmodexpscratch, dbg)
    4417 
     4600draw_allmodexp_plots(cnf, allmodexpvar, listplots, modexps, owdir, figallmodexpscratch, dbg)
     4601
     4602print main + ': all files and figures have been properly done !!'
Note: See TracChangeset for help on using the changeset viewer.