Changeset 1015 in lmdz_wrf


Ignore:
Timestamp:
Aug 12, 2016, 6:55:25 PM (8 years ago)
Author:
lfita
Message:

Working on the changing name of variables and disappearing variables...

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/model_graphics.py

    r1011 r1015  
    342342    for line in objf:
    343343        vals = line.split(' ')
    344         if vals[0] == 'files':
    345             Files = stringList_dictKeysVals(vals[1])
    346         elif vals[0] == 'testfiles':
    347             TestFiles = stringList_dictKeysVals(vals[1])
    348         elif vals[0] == 'varcompute':
     344        if vals[0] == 'files:':
     345            Files = gen.stringList_dictKeysVals(vals[1])
     346        elif vals[0] == 'testfiles:':
     347            TestFiles = gen.stringList_dictKeysVals(vals[1])
     348        elif vals[0] == 'varcompute:':
    349349            Vvals = vals[1].split('|')
    350350            if Vvals[3] == 'None':
     
    358358
    359359            allvarcomp[Vvals[0]+'_'+Vvals[1]] = [Vvals[2], mod, diag, Vvals[5]]
    360         elif vals[0] == 'itotv':
     360        elif vals[0] == 'itotv:':
    361361            ivop = int(vals[1])
    362362
     
    420420        fileon = odir + '/' + CFvarn + '_' + headerf + SgP + '.nc'
    421421
    422         if db:
    423             print '  ' + fname + ": creation of variable file '" + ifilen + "' ..."
    424 
    425422        if scr:
    426423            sout = sub.call('rm ' + ifilen + ' >& /dev/null', shell=True)
     
    432429#   bars, if a variable has a diagnostic way to be computed, the later one will be
    433430#   preferred
     431            if db:
     432                print '  ' + fname + ": creation of variable file '" + CFvarn +      \
     433                  "' in file '" + ifilen + "' ..."
    434434
    435435            if modvar is not None and diagvar is None:
     
    441441               
    442442                newfile, loc = gen.search_sec_list(output,'succesfull')
    443                 print fname, 'Lluis newfile', newfile
    444443                ofile = newfile[0].split(' ')[7]
    445444                sub.call('mv ' + ofile + ' ' + ifilen, shell=True)
     
    461460                diagc = '@'.join(diagvar[1:])
    462461           
    463                 values = '-f ' + cf + ' -d ' + dims + " -v '" + diagn + '|' +diagc+"'"
     462                values = '-f ' + cf + " -d '" + dims + "' -v '" + diagn + '|' +      \
     463                  diagc + "'"
    464464                sout = sub.call('python ' + pyH + '/diagnostics.py ' + values,       \
    465465                  shell=True)
     
    472472                otrackf.write(pyins + '\n')
    473473
    474         # adding CF lon,lat,time in WRF files
    475         if minf.name == 'WRF':
    476             values = vdnx + ':' + vdny + ':'+ Tref + ':' + Tunits
    477             ncvar.WRF_toCF(values, ifilen)
    478 
    479         # Attaching necessary variables for the pressure interpolation
    480         if gP != 'none':
    481             requiredinterpvars = ['P', 'PB', 'PSFC', 'PH', 'PHB', 'HGT', 'T','QVAPOR']
    482             print "    " + ": adding variables:", requiredinterpvars, ' to allow ' + \
    483               'pressure interpolation'
    484             for rqv in requiredinterpvars:
    485                 ncvar.fvaradd(cf+','+rqv,ifilen)
     474            # Attaching necessary variables for the pressure interpolation
     475            if gP != 'none':
     476                requiredinterpvars = ['P', 'PB', 'PSFC', 'PH', 'PHB', 'HGT', 'T',    \
     477                  'QVAPOR', 'XLONG', 'XLAT', 'Times']
     478                print "   " + fname + ": adding variables:", requiredinterpvars,     \
     479                  ' to allow pressure interpolation'
     480                for rqv in requiredinterpvars:
     481                    ncvar.fvaradd(idir+'/'+cf+','+rqv,ifilen)
     482
     483            # adding CF lon,lat,time in WRF files
     484            if minf.name == 'WRF':
     485                values = vdnx + ':' + vdny + ':'+ Tref + ':' + Tunits
     486                ncvar.WRF_toCF(values, ifilen)
    486487
    487488        ifile = ifile + 1
     
    502503    return
    503504
    504 def compute_statistics(minf, idir, usefiles, odir, cvar, plevels, gP, Opers, scr,    \
    505   pyH, db):
     505def compute_statistics(minf, config, idir, usefiles, odir, cvar, gP, Opers, scr, db):
    506506    """ Function to compute different statistics it will take previous steps if they
    507507        are availale
    508508      minf= class with the information of the model
     509      config= dictionary with the configuration of the experiment
    509510      idir= directory with the input files
    510511      usefiles= ',' list of files to use [file1],...,[fileN]
    511512      odir= directory to write the output files
    512513      cvar= class with the information of the variable: 'name', 'fheader', 'varmod', 'vardiag'
    513       plevels= ':' separated list of pressures (in Pa) to use for the vertical interpolation
    514514      gP= kind of vertical interpolation ('global', 'local', 'none')
    515515      Opers= kind of operation: (as possible multiple consecutive combination of operations separated by '+'
     
    530530        zsum: vertical aggregated values
    531531      scr= should it be done from the scratch?
    532       pyH= location of the python HOME
    533532    """
    534533    fname='compute_statistics'
     
    549548    vdny = minf.vardyn
    550549
    551     # For that variables which require vertical interpolation 'p' suffix to the
    552     #   file header is added
     550    # Some experiment configuration values
     551    #  plevels= ':' separated list of pressures (in Pa) to use for the vertical interpolation
     552    plevels = config['plevels']
     553    #  pyH= location of the python HOME
     554    pyH = config['pyHOME']
     555    #  Tref= CF time reference
     556    Tref = config['CFreftime']
     557    #  Tunits= CF time units
     558    Tunits = config['CFunitstime']
     559    #  opsur = operation surnames
     560    opsur = gen.get_specdictionary_HMT(config, H='opsur_',M='',T='')
     561    Opsurs = {}
     562    for opk in opsur:
     563        opn = opk.split('_')[1]
     564        vals = opsur[opk]
     565        Opsurs[opn] = vals.split(':')
     566    if db:
     567        print '  ' + fname + ' operation surnames _______'
     568        gen.printing_dictionary(Opsurs)
     569
     570    # Getting in working dir
     571    os.chdir(odir)
     572
     573    # File to keep track of all operations
     574    otrackf = open( odir + '/all_statsvars.inf', 'a')
     575
     576    # For that variables which require vertical interpolation 'p' suffix to the file
     577    #   header is added
    553578    if gP != 'none':
    554579        SgP = 'p'
    555         if gP == 'local':
    556             CFvarnp = CFvarn + ',P,PB,PSFC,PH,PHB,HGT,T,QVAPOR,XLONG,XLAT,Times'
    557         else:
    558             CFvarnp = CFvarn
     580        varnCFs = ['lon', 'lat', 'pres', 'time']
    559581    else:
    560582        SgP = ''
    561         CFvarnp = CFvarn
    562 
    563     # Getting in working dir
    564     os.chdir(odir)
    565 
    566     # File to keep track of all operations
    567     otrackf = open( odir + '/all_statsvars.inf', 'a')
     583        varnCFs = ['lon', 'lat', 'time']
     584
     585    # Mandatory CF variables to be in all files
     586    SvarnCFs = ',' + ','.join(varnCFs)
    568587
    569588    # Input file
     
    578597    # Variables to be kept in the final file
    579598    varkeep = []
    580 
    581     # Mandatory CF variables to be in all files
    582     varnCFs = ['lon', 'lat', 'pres', 'time']
    583599
    584600    opers = Opers.split('+')
     
    586602    if db: print '    computing statistics of variable:', CFvarn, ' ...'
    587603    for op in opers:
     604
     605        # File name from previous operations
    588606        if op == opers[0]:
    589607            Fopers = op
    590608            prevfile = ifilen
     609            vninF = CFvarn
    591610        else:
    592611            Fopers = Fopers + '_' + op
    593612            prevfile = fileon
    594613        fileon = odir + '/' + CFvarn + '_' + headerf + SgP + '_' + Fopers + '.nc'
     614
     615        # Adding required variables for the vertical interpolation in all operations
     616        if gP != 'none':
     617            if gP == 'local':
     618                CFvarnp = vninF + ',P,PB,PSFC,PH,PHB,HGT,T,QVAPOR,XLONG,XLAT,Times' + SvarnCFs
     619            else:
     620                CFvarnp = vninF + SvarnCFs
     621        else:
     622            CFvarnp = vninF + SvarnCFs
    595623
    596624        if scr:
     
    647675                # pinterp: pressure interpolation (to the given $plevels)
    648676                vals=plevels + ',1,1'
    649                 ncvar.pinterp(vals,prevfile,CFvarnp)
    650                 sout = sub.vall('mv pinterp.nc ' + fileon, shell=True)
     677                ncvar.pinterp(vals,prevfile,vninF)
     678                sout = sub.call('mv pinterp.nc ' + fileon, shell=True)
    651679
    652680                # Keeping the operations
    653681                pyins=pyH + "/nc_var.py -o pinterp -S '" + vals + "' -f " +          \
    654                   prevfile + "-v " + CFvarnp
     682                  prevfile + "-v " + vninF
    655683                otrackf.write("\n")
    656684                otrackf.write("# " + CFvarn + " " + Fopers + "\n")
     
    663691
    664692                # vertical interpolation variables are no more needed
    665                 CFvarnp = CFvarn
     693                CFvarnp = vninF
     694                gP = 'none'
    666695
    667696            elif op == 'tmean':
     
    679708                otrackf.write(pyins + "\n")
    680709
    681                 varkeep.append(CFvarn + 'mean')
     710                # lon, lat CF-variables do not have time, thus they are not kept in
     711                #   output
     712                for rqv in varnCFs:
     713                    if rqv != 'time':
     714                        ncvar.fvaradd(prevfile+','+rqv,fileon)
    682715                varkeep.append('timestats')
    683716
     
    711744                otrackf.write(pyins + "\n")
    712745
    713                 varkeep.append(CFvarn + 'mean')
     746                # time CF-variable do not have 'x', thus they are not kept in
     747                #   output
     748                rqv = 'time'
     749                ncvar.fvaradd(prevfile+','+rqv,fileon)
    714750                varkeep.append('lonstats')
    715751
     
    728764                otrackf.write(pyins + "\n")
    729765
    730                 varkeep.append(CFvarn + 'mean')
     766                # time CF-variable do not have 'y', thus they are not kept in
     767                #   output
     768                rqv = 'time'
     769                ncvar.fvaradd(prevfile+','+rqv,fileon)
    731770                varkeep.append('latstats')
    732771            elif op == 'zsum':
    733772                # vertical aggregated values
    734773                print "  " + fname + ": kind '" + op + "' not ready !!"
    735                 wrongstats.appen(CFvarn + '_' + opers)
     774                wrongstats.append(CFvarn + '_' + opers)
    736775                break
    737776            else:
     
    741780
    742781            # End of kind of operation
     782
     783            # Variable name in file (vninF) changed due to operation
     784            #   but only if previous operation does not the same 'statistic'
     785            chvn = gen.dictionary_key_list(Opsurs, op)
     786            if chvn is not None:
     787                oldvninF = vninF
     788                if vninF.find(chvn) != -1:
     789                    Lchvn = len(chvn)
     790                    LvninF = len(vninF)
     791                    if vninF[LvninF-Lchvn:LvninF-Lchvn+1] != chvn:
     792                        vninF = vninF + chvn
     793                else:
     794                    vninF = vninF + chvn
     795                CFvarnp = CFvarnp.replace(oldvninF,vninF)
     796               
    743797            if len(varkeep) > 0:
    744798                varkeepS = ',' + ','.join(varkeep)
     
    789843
    790844            # Compute variable statistics
    791             compute_statistics(modinf, iwdir, Files, owdir, vinf, config['plevels'], \
    792               globalP, op, fscr, config['pyHOME'], debug)
     845            compute_statistics(modinf, cnf, iwdir, Files, owdir, vinf, globalP, op, \
     846              fscr, debug)
    793847
    794848        else:
     
    911965            print '  ' + main + ": getting variables to compute already from file !!"
    912966            files, testfiles, allcompvar, Nvar = read_varcomp_file(owdir +           \
    913               '/varcompute.inf')         
     967              '/varcompute.inf')
    914968        # End of avoiding to repeat all the experiment search
    915969
  • trunk/tools/model_graphics_template.dat

    r1011 r1015  
    2727
    2828# Scratch figures: should be any figures previous work removed and start from the scratch?
    29 figscratch = false
     29figscratch = true
    3030
    3131# Have new files been added and do they need to be processed?
     
    9191#     will compute first [calc1] and then [calc2] for 'tas' and 'wss'
    9292VAR_last = tas:uas:vas:hfss:hfls:wss
    93 VAR_mean = tas:uas:vas:hfss:hfls:wss
     93VAR_tmean = tas:uas:vas:hfss:hfls:wss
    9494VAR_xmean = tas:uas:vas:hfss:hfls:wss
    95 VAR_last+pinterp+xmean = ta:ua:va:hur:hus:turb
     95#VAR_last+pinterp+xmean = ta:ua:va:hur:hus:turb
    9696VAR_pinterp+tmean+xmean = ta:ua:va:hur:hus:turb
    9797
     
    104104vardiff = tas|last:tas|xmean:tas|tmean:wss|last:wss|xmean:wss|tmean:ua|pinterp@last@xmean:va|pinterp@last@xmean
    105105
    106 # Operations which attach 'mean' at the end of the variable name
    107 varmeanname=Lmean:lmean:tmean:xmean:ymean
     106# Operations which attach a 'surname' at the end of the variable name
     107#  Values are given as opsur_[surname] = [operation1]:[operation2][:...[operationN]]
     108#    opsur_mean = tmean:xmean
     109#      once 'tmean', or 'xmean' are computed, variable [varn] will become [varn]mean
     110#   NOTE: surnames are attaced only once
     111opsur_mean = Lmean:lmean:tmean:xmean:ymean
    108112
    109113# Pressure levels
Note: See TracChangeset for help on using the changeset viewer.