Changeset 1022 in lmdz_wrf


Ignore:
Timestamp:
Aug 15, 2016, 2:38:53 PM (9 years ago)
Author:
lfita
Message:

Working copy up to statistics without 'turb' and redudec space computation of 'pinterp' (for 1D, 2D variables)

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/model_graphics.py

    r1015 r1022  
    275275    strfiles = gen.dictKeysVals_stringList(Files)
    276276    strtestfiles = gen.dictKeysVals_stringList(TestFiles)
    277 
    278     print 'Lluis' + fname + ': strtestfile:', strtestfiles
    279277
    280278    Svarcompute = ''
     
    347345            TestFiles = gen.stringList_dictKeysVals(vals[1])
    348346        elif vals[0] == 'varcompute:':
    349             Vvals = vals[1].split('|')
    350             if Vvals[3] == 'None':
    351                 mod = None
    352             else:
    353                 mod = Vvals[3].split(':')
    354             if Vvals[4] == 'None':
    355                 diag = None
    356             else:
    357                 diag = Vvals[4].split(':')
    358 
    359             allvarcomp[Vvals[0]+'_'+Vvals[1]] = [Vvals[2], mod, diag, Vvals[5]]
     347            for VvalsS in vals[1].split(','):
     348               
     349                Vvals = VvalsS.split('|')
     350                if Vvals[3] == 'None':
     351                    mod = None
     352                else:
     353                    mod = Vvals[3].split(':')
     354                if Vvals[4] == 'None':
     355                    diag = None
     356                else:
     357                    diag = Vvals[4].split(':')
     358
     359                allvarcomp[Vvals[0]+'_'+Vvals[1]] = [Vvals[2], mod, diag, Vvals[5]]
    360360        elif vals[0] == 'itotv:':
    361361            ivop = int(vals[1])
     
    462462                values = '-f ' + cf + " -d '" + dims + "' -v '" + diagn + '|' +      \
    463463                  diagc + "'"
    464                 sout = sub.call('python ' + pyH + '/diagnostics.py ' + values,       \
    465                   shell=True)
     464                try:
     465                    with gen.Capturing() as output:
     466                        sout = sub.call('python ' +pyH+ '/diagnostics.py ' + values, \
     467                          shell=True)
     468                except:
     469                    print 'python ' + pyH + '/diagnostics.py ' + values
     470                    for sout in output: print sout
     471                    quit(-1)
     472                if db:
     473                    for sout in output: print sout
     474
    466475                sout = sub.call(' mv diagnostics.nc ' + ifilen, shell=True)
    467476
     
    479488                  ' to allow pressure interpolation'
    480489                for rqv in requiredinterpvars:
    481                     ncvar.fvaradd(idir+'/'+cf+','+rqv,ifilen)
     490                    try:
     491                        with gen.Capturing() as output:
     492                            ncvar.fvaradd(idir+'/'+cf+','+rqv,ifilen)
     493                    except:
     494                        print 'fvaradd('+idir+'/'+cf+','+rqv+','+ifilen+')'
     495                        for sout in output: print sout
     496                        quit(-1)
     497                    if db:
     498                        for sout in output: print sout
    482499
    483500            # adding CF lon,lat,time in WRF files
     
    495512            print '  ' + fname + ": concatenating all variable files to create '" +  \
    496513              fileon + "..."
    497         ncvar.netcdf_fold_concatenation_HMT('./,time', CFvarn+'_'+headerf+SgP+       \
    498           '_,-,.nc', 'all')
     514        try:
     515            with gen.Capturing() as output:
     516                ncvar.netcdf_fold_concatenation_HMT('./,time', CFvarn+'_'+headerf+   \
     517                  SgP+'_,-,.nc', 'all')
     518        except:
     519            print 'netcdf_fold_concatenation_HMT(./time, '+CFvarn+'_'+headerf+SgP+   \
     520              '_,-,.nc, all)'
     521            for sout in output: print sout
     522            quit(-1)
     523        if db:
     524            for sout in output: print sout
     525
    499526        sout = sub.call('mv netcdf_fold_concatenated_HMT.nc ' + fileon, shell=True)
    500527        if os.path.isfile(fileon):
     
    547574    vdnx = minf.vardxn
    548575    vdny = minf.vardyn
     576    # Model dimension-variable dictionary
     577    Modeldimvardict = {dnx: vdnx, dny: vdny, dnz: vdnz, dnt: vdnt}
    549578
    550579    # Some experiment configuration values
     
    575604
    576605    # For that variables which require vertical interpolation 'p' suffix to the file
    577     #   header is added
     606    #   header is added.
     607    # After some operations some CF dimension-variables might not be kept
     608
    578609    if gP != 'none':
    579610        SgP = 'p'
     
    583614        varnCFs = ['lon', 'lat', 'time']
    584615
    585     # Mandatory CF variables to be in all files
    586     SvarnCFs = ',' + ','.join(varnCFs)
     616    # CF dimension-variable dictionary
     617    CFdimvardict = {'lon': 'lon', 'lat': 'lat', 'pres': 'pres', 'time': 'time'}
    587618
    588619    # Input file
     
    595626    wrongstats = []
    596627
    597     # Variables to be kept in the final file
    598     varkeep = []
    599 
    600628    opers = Opers.split('+')
    601629    Fopers = ''
    602     if db: print '    computing statistics of variable:', CFvarn, ' ...'
     630    if db: print "    computing statistics of variable:'", CFvarn, "' operation '" + \
     631      Opers + "'...'"
    603632    for op in opers:
    604633
    605         # File name from previous operations
     634        # File name from previous operations, and name of the variable within the
     635        #   file (some operations change the name of the variable)
    606636        if op == opers[0]:
    607637            Fopers = op
     
    614644
    615645        # Adding required variables for the vertical interpolation in all operations
     646        SvarnCFs = ',' + ','.join(varnCFs)
     647
    616648        if gP != 'none':
    617649            if gP == 'local':
    618                 CFvarnp = vninF + ',P,PB,PSFC,PH,PHB,HGT,T,QVAPOR,XLONG,XLAT,Times' + SvarnCFs
     650                CFvarnp = vninF + ',P,PB,PSFC,PH,PHB,HGT,T,QVAPOR,XLONG,XLAT,Times'+ \
     651                  SvarnCFs
    619652            else:
    620653                CFvarnp = vninF + SvarnCFs
     
    626659
    627660        hprevfile = prevfile[0:len(prevfile)-3]
     661
     662        if db: print '      ', op, "using '" + prevfile + "' "
     663        # Just produce file in case output file does not exist
    628664        if not os.path.isfile(fileon):
    629             if db: print '      ', op, "using '" + prevfile + "' "
     665            if db:
     666                print '  ' + fname + ": creation of file '" + fileon + "' ..."
     667            dofile = True
     668        else:
     669            dofile = False
    630670       
    631             if op == 'acc':
    632                 # temporal accumulated values
    633                 print "  " + fname + ": kind '" + op + "' not ready !!"
    634                 wrongstats.appen(CFvarn + '_' + opers)
    635                 break
    636             elif op == 'direct':
    637                 # no statistics
     671        # Variables to be kept in the final file
     672        varkeep = []
     673
     674        if op == 'acc':
     675            # temporal accumulated values
     676            print "  " + fname + ": kind '" + op + "' not ready !!"
     677            wrongstats.appen(CFvarn + '_' + opers)
     678            break
     679        elif op == 'direct':
     680            # no statistics
     681            if dofile:
    638682                sout = sub.call('mv ' + prevfile + ' ' + fileon, shell=True)
    639             elif op == 'last':
    640                 # last temporal value
    641                 vals='time,-9,0,0'
    642                 with gen.Capturing() as output:
    643                     ncvar.DataSetSection(vals,prevfile)
     683        elif op == 'last':
     684            # last temporal value
     685            vals='time,-9,0,0'
     686            if dofile:
     687                try:
     688                    with gen.Capturing() as output:
     689                        ncvar.DataSetSection(vals,prevfile)
     690                except:
     691                    print 'DataSetSection('+vals+',', prevfile, ')'
     692                    for sout in output: print sout
     693                    quit(-1)
     694
     695                if db:
     696                    for sout in output: print sout
    644697               
    645698                sout = sub.call('mv ' + hprevfile + '_time_B-9-E0-I0.nc ' + fileon, \
     
    652705                otrackf.write("# " + CFvarn + " " + Fopers + "\n")
    653706                otrackf.write(pyins + "\n")
    654             elif op =='Lmean':
    655                 # latitudinal mean values
    656                 print "  " + fname + ": kind '" + op + "' not ready !!"
    657                 wrongstats.appen(CFvarn + '_' + opers)
    658                 break
    659             elif op =='Lsec':
    660                 # latitudinal section (latitudinal value must be given, [var]@[lat])
    661                 print "  " + fname + ": kind '" + op + "' not ready !!"
    662                 wrongstats.appen(CFvarn + '_' + opers)
    663                 break
    664             elif op =='lmean':
    665                 # longitudinal mean values
    666                 print "  " + fname + ": kind '" + op + "' not ready !!"
    667                 wrongstats.appen(CFvarn + '_' + opers)
    668                 break
    669             elif op =='lsec':
    670                 # longitudinal section (longitudinal value must be given, [var]@[lon])
    671                 print "  " + fname + ": kind '" + op + "' not ready !!"
    672                 wrongstats.appen(CFvarn + '_' + opers)
    673                 break
    674             elif op == 'pinterp':
    675                 # pinterp: pressure interpolation (to the given $plevels)
    676                 vals=plevels + ',1,1'
    677                 ncvar.pinterp(vals,prevfile,vninF)
     707
     708        elif op =='Lmean':
     709            # latitudinal mean values
     710            print "  " + fname + ": kind '" + op + "' not ready !!"
     711            wrongstats.appen(CFvarn + '_' + opers)
     712            break
     713        elif op =='Lsec':
     714            # latitudinal section (latitudinal value must be given, [var]@[lat])
     715            print "  " + fname + ": kind '" + op + "' not ready !!"
     716            wrongstats.appen(CFvarn + '_' + opers)
     717            break
     718        elif op =='lmean':
     719            # longitudinal mean values
     720            print "  " + fname + ": kind '" + op + "' not ready !!"
     721            wrongstats.appen(CFvarn + '_' + opers)
     722            break
     723        elif op =='lsec':
     724            # longitudinal section (longitudinal value must be given, [var]@[lon])
     725            print "  " + fname + ": kind '" + op + "' not ready !!"
     726            wrongstats.appen(CFvarn + '_' + opers)
     727            break
     728        elif op == 'pinterp':
     729            # pinterp: pressure interpolation (to the given $plevels)
     730            vals=plevels + ',1,1'
     731            if dofile:
     732                try:
     733                    with gen.Capturing() as output:
     734                        ncvar.pinterp(vals,prevfile,vninF)
     735                except:
     736                    print 'pinterp('+vals+',', prevfile, ','+vninF+')'
     737                    for sout in output: print sout
     738                    quit(-1)
     739
     740                if db:
     741                    for sout in output: print sout
     742
    678743                sout = sub.call('mv pinterp.nc ' + fileon, shell=True)
    679744
     
    690755                    ncvar.WRF_toCF(values, fileon)
    691756
    692                 # vertical interpolation variables are no more needed
    693                 CFvarnp = vninF
    694                 gP = 'none'
    695 
    696             elif op == 'tmean':
    697                 # temporal mean values
    698                 vals='time|-1,time,mean,lon:lat:' + vdnz + ':time:pres'
    699                 dims='time@time,' + dnz + '@' + vdnz + ',lat@lat,lon@lon'
    700                 ncvar.file_oper_alongdims(vals,prevfile,CFvarnp)
     757            # vertical interpolation variables are no more needed
     758            CFvarnp = vninF
     759            gP = 'none'
     760
     761        elif op == 'tmean':
     762            # temporal mean values
     763            vals='time|-1,time,mean,' + ':'.join(varnCFs) + ':' + vdnz
     764            dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') + dnz+'@'+vdnz
     765            if dofile:
     766                try:
     767                    with gen.Capturing() as output:
     768                        ncvar.file_oper_alongdims(vals,prevfile,CFvarnp)
     769                except:
     770                    print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')'
     771                    for sout in output: print sout
     772                    quit(-1)
     773
     774                if db:
     775                    for sout in output: print sout
     776
    701777                sout = sub.call('mv file_oper_alongdims_mean.nc '+fileon, shell=True)
    702778
     
    708784                otrackf.write(pyins + "\n")
    709785
    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)
    715                 varkeep.append('timestats')
    716 
    717 #            elif op == 'turb':
    718 #                # turbulence values
    719 #                vals='turbulence|'${CFvarn}
    720 #                dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon,pres@pres'
    721 #                pyout=`python ${pyHOME}/diagnostics.py -d ${dims} -v ${vals} -f ${cfiles}`
    722 
    723 #                # Keeping the operations
    724 #                pyins="python "${pyHOME}"/diagnostics.py -d "${dims}" -v '"${vals}
    725 #                pyins=${pyins}"' -f ${cfiles}"
    726 #                echo " " >> ${odir}/all_statsvars.inf
    727 #                echo "# ${CFvarn}" "${vark}" >> ${odir}/all_statsvars.inf
    728 #                echo ${pyins} >> ${odir}/all_statsvars.inf
    729 
    730 #                varkeep=':'${CFvarn}'turb'
    731 
    732             elif op == 'xmean':
    733                 # x-axis mean values
    734                 vals='lon|-1,lon,mean,lon:lat:' + vdnz + ':time:pres'
    735                 dims='time@time,' + dnz + '@' + vdnz + ',lat@lat,lon@lon'
    736                 ncvar.file_oper_alongdims(vals,prevfile,CFvarnp)
     786            # removing dimension variable-dimension 'time'
     787            varnCFs.remove('time')
     788
     789            varkeep.append('timestats')
     790
     791#        elif op == 'turb':
     792#            # turbulence values
     793#            vals='turbulence|'${CFvarn}
     794#            dims='time@time,'${dnz}'@'${vdnz}',lat@lat,lon@lon,pres@pres'
     795#            pyout=`python ${pyHOME}/diagnostics.py -d ${dims} -v ${vals} -f ${cfiles}`
     796
     797#            # Keeping the operations
     798#            pyins="python "${pyHOME}"/diagnostics.py -d "${dims}" -v '"${vals}
     799#            pyins=${pyins}"' -f ${cfiles}"
     800#            echo " " >> ${odir}/all_statsvars.inf
     801#            echo "# ${CFvarn}" "${vark}" >> ${odir}/all_statsvars.inf
     802#            echo ${pyins} >> ${odir}/all_statsvars.inf
     803
     804#            varkeep=':'${CFvarn}'turb'
     805
     806        elif op == 'xmean':
     807            # x-axis mean values
     808            vals='lon|-1,lon,mean,' + ':'.join(varnCFs) + ':' + vdnz
     809            dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') + dnz+'@'+vdnz
     810            if dofile:
     811                try:
     812                    with gen.Capturing() as output:
     813                        ncvar.file_oper_alongdims(vals,prevfile,CFvarnp)
     814                except:
     815                    print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')'
     816                    for sout in output: print sout
     817                    quit(-1)
     818
     819                if db:
     820                    for sout in output: print sout
     821
    737822                sout = sub.call('mv file_oper_alongdims_mean.nc '+fileon, shell=True)
    738823
     
    744829                otrackf.write(pyins + "\n")
    745830
    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)
    750                 varkeep.append('lonstats')
    751 
    752             elif op == 'ymean':
    753                 # y-axis mean values
    754                 vals='lat|-1,lat,mean,lon:lat:' + vdnz + ':time:pres'
    755                 dims='time@time,' + dnz + '@' + vdnz + ',lat@lat,lon@lon'
    756                 ncvar.file_oper_alongdims(vals,prevfile,CFvarnp)
     831            varkeep.append('lonstats')
     832
     833        elif op == 'ymean':
     834            # y-axis mean values
     835            vals='lat|-1,lat,mean,' + ':'.join(varnCFs) + ':' + vdnz
     836            dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') + dnz+'@'+vdnz
     837            if dofile:
     838                try:
     839                    with gen.Capturing() as output:
     840                        ncvar.file_oper_alongdims(vals,prevfile,CFvarnp)
     841                except:
     842                    print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')'
     843                    for sout in output: print sout
     844                    quit(-1)
     845
     846                if db:
     847                    for sout in output: print sout
     848
    757849                sout = sub.call('mv file_oper_alongdims_mean.nc '+fileon, shell=True)
    758850
     
    764856                otrackf.write(pyins + "\n")
    765857
    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)
    770                 varkeep.append('latstats')
    771             elif op == 'zsum':
    772                 # vertical aggregated values
    773                 print "  " + fname + ": kind '" + op + "' not ready !!"
    774                 wrongstats.append(CFvarn + '_' + opers)
    775                 break
    776             else:
    777                 print errmsg
    778                 print '  ' + fname + ": operation '" + op + "' not ready !!"
    779                 quit(-1)
    780 
    781             # 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)
     858            varkeep.append('latstats')
     859
     860        elif op == 'zsum':
     861            # vertical aggregated values
     862            print "  " + fname + ": kind '" + op + "' not ready !!"
     863            wrongstats.append(CFvarn + '_' + opers)
     864            break
     865        else:
     866            print errmsg
     867            print '  ' + fname + ": operation '" + op + "' not ready !!"
     868            quit(-1)
     869
     870        # End of kind of operation
     871
     872        # Variable name in file (vninF) changed due to operation
     873        #   but only if previous operation does not the same 'statistic'
     874        chvn = gen.dictionary_key_list(Opsurs, op)
     875        if chvn is not None:
     876            oldvninF = vninF
     877            vninF = vninF + chvn
     878            CFvarnp = CFvarnp.replace(oldvninF,vninF)
    796879               
     880        if dofile:
    797881            if len(varkeep) > 0:
    798882                varkeepS = ',' + ','.join(varkeep)
     
    800884                varkeepS = ''
    801885
     886            # Adding such CF dimension variables which might not be in the
     887            #   post-operation file
     888            try:
     889                with gen.Capturing() as output: 
     890                    varinfile = ncvar.ivars(fileon)
     891            except:
     892                print 'ivars('+fileon+')'
     893                for sout in output: print sout
     894                quit(-1)
     895
     896            for CFvn in varnCFs:
     897                if not gen.searchInlist(varinfile, CFvn):
     898                    if db:
     899                        print '  ' + fname + ": recupering CF variable '" + CFvn + "'"
     900                    try:
     901                        with gen.Capturing() as output:
     902                            ncvar.fvaradd(prevfile+','+CFvn, fileon)
     903                    except:
     904                        print 'fvaradd(', prevfile, ','+CFvn+','+fileon+')'
     905                        for sout in output: print sout
     906                        quit(-1)
     907
     908                    if db:
     909                        for sout in output: print sout
     910
    802911            totalvarkeeps = CFvarnp + ',' + ','.join(varnCFs) + varkeepS
    803             oclean = ncvar.cleaning_varsfile(totalvarkeeps,fileon)
     912            try:
     913                with gen.Capturing() as output:
     914                    oclean = ncvar.cleaning_varsfile(totalvarkeeps,fileon)
     915            except:
     916                print 'cleaning_varsfile('+totalvarkeeps+','+fileon+')'
     917                for sout in output: print sout
     918                quit(-1)
     919
     920            if db:
     921                for sout in output: print sout
    804922
    805923    # End of operations
     924    if db:
     925        print fname + ": successful calculation of '" + vninF + "' from '" +        \
     926          CFvarn + "' '" + Opers + "' !!"
     927
    806928    if len(wrongstats) > 1:
    807929        print warnmsg
     
    9661088            files, testfiles, allcompvar, Nvar = read_varcomp_file(owdir +           \
    9671089              '/varcompute.inf')
     1090
    9681091        # End of avoiding to repeat all the experiment search
    9691092
    9701093        print "  For experiment '"+exp+"' is required to compute:", Nvar, "variables"
     1094
     1095        if dbg:
     1096            print 'Variables to compute _______', type(allcompvar)
     1097            gen.printing_dictionary(allcompvar)
    9711098
    9721099###
  • trunk/tools/model_graphics_template.dat

    r1015 r1022  
    2424
    2525# Scratch files: should be any files previous work removed and start from the scratch?
    26 filescratch = true
     26filescratch = false
    2727
    2828# Scratch figures: should be any figures previous work removed and start from the scratch?
     
    3030
    3131# Have new files been added and do they need to be processed?
    32 addfiles = false
     32addfiles = true
    3333
    3434# Have new figures been added and do they need to be drawn?
     
    9494VAR_xmean = tas:uas:vas:hfss:hfls:wss
    9595#VAR_last+pinterp+xmean = ta:ua:va:hur:hus:turb
    96 VAR_pinterp+tmean+xmean = ta:ua:va:hur:hus:turb
     96VAR_pinterp+tmean+xmean = ta:ua:va:hur:hus
    9797
    9898#varlast = tas:uas:vas:ps:pr:pracc:rsds:prw:evspsbl:hfss:hfls:hurs:huss:zmla:hufs:wakes:lwakeh:stherm:zmaxth:clt:cll:clm:clh:prc:prls:bils:wss
Note: See TracChangeset for help on using the changeset viewer.