Changeset 1011 in lmdz_wrf


Ignore:
Timestamp:
Aug 11, 2016, 6:50:20 PM (9 years ago)
Author:
lfita
Message:

Working version of some diagnostics. NOT working for 2D in `pinterp'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/model_graphics.py

    r1001 r1011  
    3232        filescr = True
    3333        figscr = True
    34 #        tim.sleep(10)
     34        tim.sleep(10)
    3535    else:
    3636        scr = False
     
    140140#        quit(-1)
    141141
    142     # Getting only the first possibility of diagnostic
     142    # Getting only the first possibility of model and diagnostic
     143    if vmod is not None:
     144        modV = vmod[0]
     145    else:
     146        modV = None
    143147    if vdiag is not None:
    144         varcomp = VariableInf(var, headerf, vmod, vdiag[0])
     148        diagV = vdiag[0]
    145149    else:
    146         varcomp = VariableInf(var, headerf, vmod, vdiag)
     150        diagV = None
     151
     152    varcomp = VariableInf(var, headerf, modV, diagV)
    147153
    148154    # a ';' list 'varcompute' it is created for each variable giving:
     
    250256           providing a consecutive number of calculations separated by '+'
    251257             VAR_[calc1]+[calc2] = tas:wss
    252            will compute first [calc1] and ten [calc2] for 'tas' and 'wss'
     258           will compute first [calc1] and then [calc2] for 'tas' and 'wss'
    253259      minf= class with information about the model
    254260      Files= dictionary of files for heach header
     
    269275    strfiles = gen.dictKeysVals_stringList(Files)
    270276    strtestfiles = gen.dictKeysVals_stringList(TestFiles)
     277
     278    print 'Lluis' + fname + ': strtestfile:', strtestfiles
    271279
    272280    Svarcompute = ''
     
    357365    return Files, TestFiles, allvarcomp, ivop
    358366
    359 def function compute_variable(minf, idir, usefiles, odir, cvar, gP, db):
     367def compute_variable(minf, idir, usefiles, odir, cvar, gP, scr, pyH, Tref, Tunits, db):
    360368    """ Function to compute a variable
    361369      minf= class with the information of the model
     
    363371      usefiles= dictionary of files as dict([headerf]) = [file1], ..., [fileN]
    364372      odir= directory to write the output files
    365       cvar= class with the 'name', 'fheader', 'varmod', 'vardiag'
     373      cvar= class with the information of the variable: 'name', 'fheader', 'varmod', 'vardiag'
    366374      gP= kind of vertical interpolation ('global', 'local', 'none')
     375      scr= should it be done from the scratch?
     376      pyH= location of the python HOME
     377      Tref= CF time reference
     378      Tunits= CF time units
    367379    """
    368380    fname='compute_variable'
     
    384396    # Computing separately and then joinging for all files
    385397    Ntotfiles = len(cfiles)
     398    Nzeros = len(str(Ntotfiles))
     399    NStot = str(Ntotfiles).zfill(Nzeros)
     400
     401    # For that variables which require vertical interpolation 'p' suffix to the
     402    #   file header is added
     403    if gP != 'none':
     404        SgP = 'p'
     405    else:
     406        SgP = ''
     407
     408    # Getting in working dir
     409    os.chdir(odir)
     410
     411    # File to keep track of all operations
     412    otrackf = open( odir + '/all_computevars.inf', 'a')
     413
     414    # Computing variable
    386415    ifile=1
    387 
    388416    for cf in cfiles:
    389         ifS = str(ifile)
    390 
    391 # Computing variable
    392     # Changing file head when it is a pressure-interpolated variable
    393     if test ${vark} == 'pinterp'; then
    394       fhead=${headerf}p
    395     else
    396       fhead=${headerf}
    397     fi
    398 
    399     filen=${odir}/${CFvarn}_${fhead}_${ifile}-${Ntotfiles}.nc
    400     if ${scratch}; then
    401       rm ${filen} >& /dev/null
    402       rm ${odir}/${CFvarn}_${fhead}.nc >& /dev/null
    403     fi
    404 
    405     if test ! -f ${filen} && test ! -f ${odir}/${CFvarn}_${fhead}.nc; then
    406 # Since model direct values are retrieved from `variables_valules.dat' which was initially coincived
    407 #   as a way to only give variable attributes, range and color bars, if a variable has a diagnostic
    408 #   way to be computed, the later one will be preferred
    409 
    410       if test ! ${modvar} = 'None' && test ${diagvar} = 'None'; then
    411         # model variable
    412         values=${modvar}',0,-1,-1'
    413         vs=${modvar},${vdnx},${vdny},${vdnz},${vdnt}
    414         pyout=`${pyHOME}/nc_var.py -f ${cf} -o DataSetSection_multivars -v ${vs}     \
    415           -S ${values} | grep succesfull | awk '{print $6}' | tr '"' ' '`
    416         pyn=$?
    417         Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
    418         ferrmsg ${pyn} ${fname} "python!'DataSetSection_multivars'!failed"${Spyout}
    419         mv ${pyout} ${filen}
    420 
    421         # Keeping the operations
    422         pyins=${pyHOME}"/nc_var.py -f "${cf}" -o DataSetSection_multivars -v "${vs}
    423         pyins=${pyins}" -S "${values}
    424         echo " " >> ${odir}/all_computevars.inf
    425         echo "# ${CFvarn}" "${modvar}" >> ${odir}/all_computevars.inf
    426         echo ${pyins} >> ${odir}/all_computevars.inf
    427 
    428         pyout=`${pyHOME}/nc_var.py -f ${filen} -o chvarname -v ${modvar} -S ${CFvarn}`
    429         pyn=$?
    430         Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
    431         ferrmsgF ${pyn} ${fname} "python!'chvarname'!failed"${Spyout} ${filen}
    432       else
    433         # diagnostic variable
    434         dims=${dnt}@${vdnt},${dnz}@${vdnz},${dny}@${vdny},${dnx}@${vdnx}
    435         diagn=`echo ${diagvar} | tr ':' '\n' | head -n 1`
    436         Ndiagvars=`echo ${diagvar} | tr ':' ' ' | wc -w | awk '{print $1}'`
    437         idiagv=2
    438         diagc=''
    439         while test ${idiagv} -le ${Ndiagvars}; do
    440           diag1=`echo ${diagvar} | tr ':' '\n' | head -n ${idiagv} | tail -n 1`
    441           if test ${idiagv} -eq 2; then
    442             diagc=${diag1}
    443           else
    444             diagc=${diagc}'@'${diag1}
    445           fi
    446           idiagv=`expr ${idiagv} + 1`
    447         done
    448         pyout=`python ${pyHOME}/diagnostics.py -f ${cf} -d ${dims} -v ${diagn}'|'${diagc}`
    449         pyn=$?
    450         Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
    451         ferrmsg ${pyn} ${fname} "python!'diagnostics'!failed#"${Spyout}
    452         mv diagnostics.nc ${filen}
    453 
    454         # Keeping the operations
    455         pyins=${pyHOME}"/diagnostics.py -f "${cf}" -d "${dims}" -v '"${diagn}"|"
    456         pyins=${pyins}${diagc}"'"
    457         echo " " >> ${odir}/all_computevars.inf
    458         echo "# ${CFvarn}" "${diagvar}" >> ${odir}/all_computevars.inf
    459         echo ${pyins} >> ${odir}/all_computevars.inf
    460       fi
    461 
    462       # adding CF lon,lat,time in WRF files
    463       if test ${headerf:0:3} = 'wrf'; then
    464         WRF_toCF ${filen} ${vdnx} ${vdny}
    465       fi
    466       # Attaching necessary variables for the pressure interpolation
    467       if test ${vark} == 'pinterp'; then
    468         requiredinterpvars='P:PB:PSFC:PH:PHB:HGT:T:QVAPOR:'
    469         rqvs=`echo ${requiredinterpvars} | tr ':' ' '`
    470         echo "  "${fname}": adding variables: "${rqvs}" to allow pressure interpolation"
    471         for rqv in ${rqvs}; do
    472           pyout=`${pyHOME}/nc_var.py -o fvaradd -S ${cf},${rqv} -f ${filen}`
    473           pyn=$?
    474           Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
    475           ferrmsgF ${pyn} ${fname} "python!'fvaradd'!failed#"${Spyout} ${filen}
    476         done
    477       fi
    478     fi
    479 
    480     ifile=`expr ${ifile} + 1`
    481 # End of files
    482   done
    483 
    484   # Joining variable files
    485   filen=${odir}/${CFvarn}_${fhead}.nc
    486   if ${scratch}; then rm ${filen} >& /dev/null; fi
    487 
    488   if test ! -f ${filen}; then
    489     pyout=`python ${pyHOME}/nc_var.py -f ${CFvarn}'_'${fhead}'_,-,.nc'               \
    490       -o netcdf_fold_concatenation_HMT -S ./,time -v all`
    491     pyn=$?
    492     Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
    493     ferrmsg ${pyn} ${fname} "python!'netcdf_fold_concatenation_HMT'!failed#"${Spyout}
    494     mv netcdf_fold_concatenated_HMT.nc ${filen}
    495     if test -f ${filen}; then
    496       rm ${CFvarn}_${fhead}_*-*.nc
    497     fi
    498   fi
    499 }
    500 
    501 
    502 def compute_vars(config, Files, allvarcomp, debug):
     417        ifS = str(ifile).zfill(Nzeros)
     418        ifilen = odir + '/' + CFvarn + '_' + headerf + SgP + '_' + ifS + '-' +       \
     419          NStot + '.nc'
     420        fileon = odir + '/' + CFvarn + '_' + headerf + SgP + '.nc'
     421
     422        if db:
     423            print '  ' + fname + ": creation of variable file '" + ifilen + "' ..."
     424
     425        if scr:
     426            sout = sub.call('rm ' + ifilen + ' >& /dev/null', shell=True)
     427            sout = sub.call('rm ' + fileon + ' >& /dev/null', shell=True)
     428
     429        if not os.path.isfile(ifilen) and not os.path.isfile(fileon):
     430# Since model direct values are retrieved from `variables_valules.dat' which was
     431#   initially coincived as a way to only give variable attributes, range and color
     432#   bars, if a variable has a diagnostic way to be computed, the later one will be
     433#   preferred
     434
     435            if modvar is not None and diagvar is None:
     436                # model variable
     437                values = modvar + ',0,-1,-1'
     438                vs = modvar + ',' + vdnx + ',' + vdny + ',' + vdnz + ',' + vdnt
     439                with gen.Capturing() as output:
     440                    ncvar.DataSetSection_multivars(values, cf, vs)
     441               
     442                newfile, loc = gen.search_sec_list(output,'succesfull')
     443                print fname, 'Lluis newfile', newfile
     444                ofile = newfile[0].split(' ')[7]
     445                sub.call('mv ' + ofile + ' ' + ifilen, shell=True)
     446
     447                # Keeping track of the operations
     448                pyins = pyH + "/nc_var.py -f "+cf+" -o DataSetSection_multivars -v "+\
     449                  vs + " -S '" + values + "'"
     450                otrackf.write('\n')
     451                otrackf.write('# ' + CFvarn + " " + modvar + '\n')
     452                otrackf.write(pyins + '\n')
     453
     454                # CF renaming of variable
     455                ncvar.chvarname(CFvarn,ifilen,modvar)
     456            else:
     457                # diagnostic variable
     458                dims = dnt+'@'+vdnt+','+dnz+'@'+vdnz+','+dny+'@'+vdny+','+dnx+'@'+vdnx
     459                diagn = diagvar[0]
     460                Ndiagvars = len(diagvar)
     461                diagc = '@'.join(diagvar[1:])
     462           
     463                values = '-f ' + cf + ' -d ' + dims + " -v '" + diagn + '|' +diagc+"'"
     464                sout = sub.call('python ' + pyH + '/diagnostics.py ' + values,       \
     465                  shell=True)
     466                sout = sub.call(' mv diagnostics.nc ' + ifilen, shell=True)
     467
     468                # Keeping track of the operations
     469                pyins = 'python ' + pyH + '/diagnostics.py ' + values
     470                otrackf.write('\n')
     471                otrackf.write('# ' + CFvarn + " " + diagn + '\n')
     472                otrackf.write(pyins + '\n')
     473
     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)
     486
     487        ifile = ifile + 1
     488
     489    otrackf.close()
     490
     491    # Joining variable files
     492    if not os.path.isfile(fileon):
     493        if db:
     494            print '  ' + fname + ": concatenating all variable files to create '" +  \
     495              fileon + "..."
     496        ncvar.netcdf_fold_concatenation_HMT('./,time', CFvarn+'_'+headerf+SgP+       \
     497          '_,-,.nc', 'all')
     498        sout = sub.call('mv netcdf_fold_concatenated_HMT.nc ' + fileon, shell=True)
     499        if os.path.isfile(fileon):
     500            sout = sub.call('rm ' + CFvarn + '_' + headerf + '_*-*.nc', shell=True)
     501
     502    return
     503
     504def compute_statistics(minf, idir, usefiles, odir, cvar, plevels, gP, Opers, scr,    \
     505  pyH, db):
     506    """ Function to compute different statistics it will take previous steps if they
     507        are availale
     508      minf= class with the information of the model
     509      idir= directory with the input files
     510      usefiles= ',' list of files to use [file1],...,[fileN]
     511      odir= directory to write the output files
     512      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
     514      gP= kind of vertical interpolation ('global', 'local', 'none')
     515      Opers= kind of operation: (as possible multiple consecutive combination of operations separated by '+'
     516        [calc1]+[calc2] will compute first [calc1] and then [calc2]
     517        acc: temporal accumulated values
     518        diff: differences between models
     519        direct: no statistics
     520        last: last temporal value
     521        Lmean: latitudinal mean values
     522        Lsec: latitudinal section (latitudinal value must be given, [var]@[lat])
     523        lmean: longitudinal mean values
     524        lsec: longitudinal section (longitudinal value must be given, [var]@[lat])
     525        pinterp: pressure interpolation (to the given $plevels)
     526        tmean: temporal mean values
     527        turb: Taylor's turbulence decomposition value
     528        xmean: x-axis mean values
     529        ymean: y-axis mean values
     530        zsum: vertical aggregated values
     531      scr= should it be done from the scratch?
     532      pyH= location of the python HOME
     533    """
     534    fname='compute_statistics'
     535
     536    # Getting a previous file name to continue with(for combinations)
     537    CFvarn=cvar.name
     538    headerf = cvar.fheader
     539    modvar = cvar.model
     540    diagvar = cvar.diag
     541
     542    cfiles = usefiles[headerf]
     543
     544    # dimensions
     545    dnx = minf.dimxn
     546    dny = minf.dimyn
     547    # var-dimensions
     548    vdnx = minf.vardxn
     549    vdny = minf.vardyn
     550
     551    # For that variables which require vertical interpolation 'p' suffix to the
     552    #   file header is added
     553    if gP != 'none':
     554        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
     559    else:
     560        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')
     568
     569    # Input file
     570    ifilen = odir + '/' + CFvarn + '_' + headerf + SgP + '.nc'
     571
     572    # Computing variable statisitcs
     573    istats=0
     574
     575    # List of not computed statistics
     576    wrongstats = []
     577
     578    # Variables to be kept in the final file
     579    varkeep = []
     580
     581    # Mandatory CF variables to be in all files
     582    varnCFs = ['lon', 'lat', 'pres', 'time']
     583
     584    opers = Opers.split('+')
     585    Fopers = ''
     586    if db: print '    computing statistics of variable:', CFvarn, ' ...'
     587    for op in opers:
     588        if op == opers[0]:
     589            Fopers = op
     590            prevfile = ifilen
     591        else:
     592            Fopers = Fopers + '_' + op
     593            prevfile = fileon
     594        fileon = odir + '/' + CFvarn + '_' + headerf + SgP + '_' + Fopers + '.nc'
     595
     596        if scr:
     597            sout = sub.call('rm ' + fileon + ' >& /dev/null', shell=True)
     598
     599        hprevfile = prevfile[0:len(prevfile)-3]
     600        if not os.path.isfile(fileon):
     601            if db: print '      ', op, "using '" + prevfile + "' "
     602       
     603            if op == 'acc':
     604                # temporal accumulated values
     605                print "  " + fname + ": kind '" + op + "' not ready !!"
     606                wrongstats.appen(CFvarn + '_' + opers)
     607                break
     608            elif op == 'direct':
     609                # no statistics
     610                sout = sub.call('mv ' + prevfile + ' ' + fileon, shell=True)
     611            elif op == 'last':
     612                # last temporal value
     613                vals='time,-9,0,0'
     614                with gen.Capturing() as output:
     615                    ncvar.DataSetSection(vals,prevfile)
     616               
     617                sout = sub.call('mv ' + hprevfile + '_time_B-9-E0-I0.nc ' + fileon, \
     618                  shell=True)
     619
     620                # Keeping the operations
     621                pyins=pyH + "/nc_var.py -o DataSetSection -S '" + vals + "' -f " +  \
     622                  prevfile
     623                otrackf.write("\n")
     624                otrackf.write("# " + CFvarn + " " + Fopers + "\n")
     625                otrackf.write(pyins + "\n")
     626            elif op =='Lmean':
     627                # latitudinal mean values
     628                print "  " + fname + ": kind '" + op + "' not ready !!"
     629                wrongstats.appen(CFvarn + '_' + opers)
     630                break
     631            elif op =='Lsec':
     632                # latitudinal section (latitudinal value must be given, [var]@[lat])
     633                print "  " + fname + ": kind '" + op + "' not ready !!"
     634                wrongstats.appen(CFvarn + '_' + opers)
     635                break
     636            elif op =='lmean':
     637                # longitudinal mean values
     638                print "  " + fname + ": kind '" + op + "' not ready !!"
     639                wrongstats.appen(CFvarn + '_' + opers)
     640                break
     641            elif op =='lsec':
     642                # longitudinal section (longitudinal value must be given, [var]@[lon])
     643                print "  " + fname + ": kind '" + op + "' not ready !!"
     644                wrongstats.appen(CFvarn + '_' + opers)
     645                break
     646            elif op == 'pinterp':
     647                # pinterp: pressure interpolation (to the given $plevels)
     648                vals=plevels + ',1,1'
     649                ncvar.pinterp(vals,prevfile,CFvarnp)
     650                sout = sub.vall('mv pinterp.nc ' + fileon, shell=True)
     651
     652                # Keeping the operations
     653                pyins=pyH + "/nc_var.py -o pinterp -S '" + vals + "' -f " +          \
     654                  prevfile + "-v " + CFvarnp
     655                otrackf.write("\n")
     656                otrackf.write("# " + CFvarn + " " + Fopers + "\n")
     657                otrackf.write(pyins + "\n")
     658
     659                # adding CF lon,lat,time in WRF files
     660                if minf.name == 'WRF':
     661                    values = vdnx + ':' + vdny + ':'+ Tref + ':' + Tunits
     662                    ncvar.WRF_toCF(values, fileon)
     663
     664                # vertical interpolation variables are no more needed
     665                CFvarnp = CFvarn
     666
     667            elif op == 'tmean':
     668                # temporal mean values
     669                vals='time|-1,time,mean,lon:lat:' + vdnz + ':time:pres'
     670                dims='time@time,' + dnz + '@' + vdnz + ',lat@lat,lon@lon'
     671                ncvar.file_oper_alongdims(vals,prevfile,CFvarnp)
     672                sout = sub.call('mv file_oper_alongdims_mean.nc '+fileon, shell=True)
     673
     674                # Keeping the operations
     675                pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals +        \
     676                  "' -f " + prevfile + " -v " + CFvarnp
     677                otrackf.write("\n")
     678                otrackf.write("# " + CFvarn + " " + Fopers + "\n")
     679                otrackf.write(pyins + "\n")
     680
     681                varkeep.append(CFvarn + 'mean')
     682                varkeep.append('timestats')
     683
     684#            elif op == 'turb':
     685#                # turbulence values
     686#                vals='turbulence|'${CFvarn}
     687#                dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon,pres@pres'
     688#                pyout=`python ${pyHOME}/diagnostics.py -d ${dims} -v ${vals} -f ${cfiles}`
     689
     690#                # Keeping the operations
     691#                pyins="python "${pyHOME}"/diagnostics.py -d "${dims}" -v '"${vals}
     692#                pyins=${pyins}"' -f ${cfiles}"
     693#                echo " " >> ${odir}/all_statsvars.inf
     694#                echo "# ${CFvarn}" "${vark}" >> ${odir}/all_statsvars.inf
     695#                echo ${pyins} >> ${odir}/all_statsvars.inf
     696
     697#                varkeep=':'${CFvarn}'turb'
     698
     699            elif op == 'xmean':
     700                # x-axis mean values
     701                vals='lon|-1,lon,mean,lon:lat:' + vdnz + ':time:pres'
     702                dims='time@time,' + dnz + '@' + vdnz + ',lat@lat,lon@lon'
     703                ncvar.file_oper_alongdims(vals,prevfile,CFvarnp)
     704                sout = sub.call('mv file_oper_alongdims_mean.nc '+fileon, shell=True)
     705
     706                # Keeping the operations
     707                pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals +        \
     708                  "' -f " + prevfile + " -v " + CFvarnp
     709                otrackf.write("\n")
     710                otrackf.write("# " + CFvarn + " " + Fopers + "\n")
     711                otrackf.write(pyins + "\n")
     712
     713                varkeep.append(CFvarn + 'mean')
     714                varkeep.append('lonstats')
     715
     716            elif op == 'ymean':
     717                # y-axis mean values
     718                vals='lat|-1,lat,mean,lon:lat:' + vdnz + ':time:pres'
     719                dims='time@time,' + dnz + '@' + vdnz + ',lat@lat,lon@lon'
     720                ncvar.file_oper_alongdims(vals,prevfile,CFvarnp)
     721                sout = sub.call('mv file_oper_alongdims_mean.nc '+fileon, shell=True)
     722
     723                # Keeping the operations
     724                pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals +        \
     725                  "' -f " + prevfile + " -v " + CFvarnp
     726                otrackf.write("\n")
     727                otrackf.write("# " + CFvarn + " " + Fopers + "\n")
     728                otrackf.write(pyins + "\n")
     729
     730                varkeep.append(CFvarn + 'mean')
     731                varkeep.append('latstats')
     732            elif op == 'zsum':
     733                # vertical aggregated values
     734                print "  " + fname + ": kind '" + op + "' not ready !!"
     735                wrongstats.appen(CFvarn + '_' + opers)
     736                break
     737            else:
     738                print errmsg
     739                print '  ' + fname + ": operation '" + op + "' not ready !!"
     740                quit(-1)
     741
     742            # End of kind of operation
     743            if len(varkeep) > 0:
     744                varkeepS = ',' + ','.join(varkeep)
     745            else:
     746                varkeepS = ''
     747
     748            totalvarkeeps = CFvarnp + ',' + ','.join(varnCFs) + varkeepS
     749            oclean = ncvar.cleaning_varsfile(totalvarkeeps,fileon)
     750
     751    # End of operations
     752    if len(wrongstats) > 1:
     753        print warnmsg
     754        print '  ' + fname + ": statisitcs not possible to compute:", wrongstats
     755
     756    return
     757
     758def compute_vars(config, modinf, idir, odir, Files, allvarcomp, fscr, debug):
    503759    """ Function to compute the variables
    504760      config= Configuration of the experiment
     761      modinf= class with information about the model
     762      idir= input experiment folder
     763      odir= output experiment folder
    505764      Files= dictionary with the header and the files' correspondence
    506765      allvarcomp= dictionary with all the variables to compute and their information
     766      fscr= whether files should be done from the scratch or not
    507767    """
    508768    fname = 'compute_vars'
     
    522782
    523783        # Computing CF variable
    524         if model is not None and diag is not None:
     784        if model is not None or diag is not None:
    525785            vinf = VariableInf(vn,fheader,model,diag)
    526             compute_variable ${Iwdir} ${Files} ${Owdir} ${cvar} ${Moddims} ${Modvdims} ${Filescratch}
     786            # Comppute variable
     787            compute_variable(modinf, idir, Files, odir, vinf, globalP, fscr,         \
     788              config['pyHOME'], config['CFreftime'], config['CFunitstime'], debug)
     789
     790            # Compute variable statistics
     791            compute_statistics(modinf, iwdir, Files, owdir, vinf, config['plevels'], \
     792              globalP, op, fscr, config['pyHOME'], debug)
     793
    527794        else:
    528795            print errmsg
     
    532799
    533800    return
    534 
    535 
    536801
    537802# Files with information about the configuration of the script
     
    559824
    560825    # Characteristics of the model
    561     modinf = ncvar.model_characteristics(mod,'None','False')
    562     dnx = modinf.dimxn
    563     dny = modinf.dimyn
    564     dnz = modinf.dimzn
    565     dnt = modinf.dimtn
    566     vdnx = modinf.vardxn
    567     vdny = modinf.vardyn
    568     vdnz = modinf.vardzn
    569     vdnt = modinf.vardtn
     826    Modinf = ncvar.model_characteristics(mod,'None','False')
     827    dnx = Modinf.dimxn
     828    dny = Modinf.dimyn
     829    dnz = Modinf.dimzn
     830    dnt = Modinf.dimtn
     831    vdnx = Modinf.vardxn
     832    vdny = Modinf.vardyn
     833    vdnz = Modinf.vardzn
     834    vdnt = Modinf.vardtn
    570835
    571836    if dbg:
     
    640905                gen.printing_dictionary(testfiles)
    641906         
    642             allcompvar, Nvar = compvars_listconstruct(cnf, modinf, files, testfiles, \
     907            allcompvar, Nvar = compvars_listconstruct(cnf, Modinf, files, testfiles, \
    643908              iwdir, owdir, dbg)
    644909        else:
     
    647912            files, testfiles, allcompvar, Nvar = read_varcomp_file(owdir +           \
    648913              '/varcompute.inf')         
     914        # End of avoiding to repeat all the experiment search
    649915
    650916        print "  For experiment '"+exp+"' is required to compute:", Nvar, "variables"
     
    654920###
    655921        print "    Computing variables ..."
    656         compute_vars(conf, files, allcompvar, dbg)
    657 
    658 # End of avoiding to repeat all the experiment search
    659     fi
    660 
     922        compute_vars(cnf, Modinf, iwdir, owdir, files, allcompvar, filescratch, dbg)
     923
     924        quit()
    661925
    662926    # end of experiments loop
  • trunk/tools/model_graphics_template.dat

    r1007 r1011  
    8989# Variables to compute (as possible multiple consecutive combination of operations must start by 'VAR_' separated by '+'
    9090#   VAR_[calc1]+[calc2] = tas:wss
    91 #     will compute first [calc1] and ten [calc2] for 'tas' and 'wss'
     91#     will compute first [calc1] and then [calc2] for 'tas' and 'wss'
    9292VAR_last = tas:uas:vas:hfss:hfls:wss
    9393VAR_mean = tas:uas:vas:hfss:hfls:wss
     
    108108
    109109# Pressure levels
    110 #   Common vertical pressure levels to compute vertical differences
     110#   Common vertical pressure levels (in Pa) to vertically interpolate
    111111#39Lowp#plevels = 100500.:100000.:98500.:97500.:95000.:92500.:90000.:87500.:85000.:80000.:75000.:70000.:65000.:60000.:55000.:50000.:45000.:40000.:35000.:30000.:25000.:20000.:15000.:10000.:900.:800.:700.:600.:500.:400.:300.:200.::1000.:85.:50.:40.:30.:20.:10.
    112112#26#plevels = 100000.:97500.:95000.:92500.:90000.:85000.:80000.:75000.:70000.:65000.:60000.:55000.:50000.:45000.:40000.:35000.:30000.:25000.:20000.:15000.:10000.:5000.:2500.:1000.:500.:250.
Note: See TracChangeset for help on using the changeset viewer.