Changeset 1186 in lmdz_wrf


Ignore:
Timestamp:
Oct 14, 2016, 5:12:55 PM (8 years ago)
Author:
lfita
Message:

Introducing projection without CDO

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/model_graphics.py

    r1168 r1186  
    36753675    return
    36763676
    3677 def reproject_modexp(mod,exp,config,CDOops,fscr,fadd,debug):
     3677def reproject_modexp(mod,exp,config,REPRJops,fscr,fadd,debug):
    36783678    """ Function to re-project and re-compute files from a given model/experiment
    36793679      mod= model
    36803680      exp= experiment
    36813681      config= configuration
    3682       CDOops= dictionary with the CDO operators to use for reproject and for which variable
     3682      REPRJops= dictionary with the reprojection operators to use for reproject and for which variable
     3683        #    remapbil   CDO: Bilinear interpolation
     3684        #    remapbic   CDO: Bicubic interpolation
     3685        #    remapdis   CDO: Distance-weighted average remapping
     3686        #    remapnn    CDO: Nearest neighbor remapping
     3687        # Operators only available if projections have the corners of the grid points.
     3688        #    remapcon   CDO: First order conservative remapping
     3689        #    remapcon2  CDO: Second order conservative remapping
     3690        #    remaplaf   CDO: Largest area fraction remapping
     3691        ####### ####### ####### or additionally ####### ####### #######
     3692        # python remapping
     3693        #    dis        python: Distance-weighted average remapping
     3694        #    pnn        python: Nearest neighbor remapping
     3695
    36833696      fscr= re-projected files to compute from the scratch
    36843697      fadd= re-projected files to be added
     
    37063719    if fadd:
    37073720        sub.call('rm ' + varcompf +' >& /dev/null', shell=True)
     3721
     3722    # CF dims-vardims pairs:
     3723    CFvardims = ['long@lon', 'lat@lat', 'pres@pres', 'time@time']
     3724
     3725    # Dictionary with the operations with surnames for the operated variable
     3726    opersurnames = {}
     3727    opsur = gen.get_specdictionary_HMT(config, H='opsur_',M='',T='')
     3728    for opsr in opsur.keys():
     3729        opn = opsr.split('_')[1]
     3730        vls = opsur[opsr].split(':')
     3731        opersurnames[opn] = vls
    37083732
    37093733    if not os.path.isfile(varcompf):
     
    37833807        op = vnop.split('_')[1]
    37843808        values = allcompvar[vnop]
     3809        VnOpS = varnoper(vn, op, opsurnames)
    37853810
    37863811        # Only are reprojected that files which do contain 'lon' and 'lat',
     
    37883813        inNO, iopNO, iop = gen.list_coincidences(opNOreproj,op.split('+'))
    37893814
    3790         cdoop = gen.dictionary_key_list(CDOops,vn).split('_')[1]
    3791         if cdoop is None:
     3815        reprjop = gen.dictionary_key_list(REPRJops,vn).split('_')[1]
     3816        if reprjop is None:
    37923817            print errmsg
    3793             print '  ' + fname + ": no reprojecting CDO operator found for " +       \
     3818            print '  ' + fname + ": no reprojecting operator found for " +           \
    37943819              " variable '" + vn + "' !!"
    37953820            print '    available values _______'
    3796             gen.printing_dictionary(CDOops)
     3821            gen.printing_dictionary(REPRJops)
    37973822            quit(-1)
    37983823       
     
    38473872                      ofile + "'"
    38483873
    3849                 ins = config['cdoHOME'] + '/cdo remap' + cdoop + ',' +               \
    3850                   config['RefProjfile'] + ' ' + ifile + ' ' + ofile
    3851                 try:
    3852                     with gen.Capturing() as output:
    3853                         sout = sub.call(ins, shell=True)
    3854                 except:
    3855                     print errmsg
    3856                     print '  ' + fname + ': $ ' + ins
    3857                     for s1out in output: print s1out
    3858                     print sout
    3859                     quit(-1)
    3860                 if sout != 0:
    3861                     print errmsg
    3862                     print '  ' + fname + ': $ ' + ins
    3863                     sub.call(ins, shell=True)
    3864                     quit(-1)
     3874                # Reprojecting...
     3875                if reprjop[0:6] == 'remap':
     3876                    ins = config['cdoHOME'] + '/cdo ' + reprjop + ',' +              \
     3877                      config['RefProjfile'] + ' ' + ifile + ' ' + ofile
     3878                    try:
     3879                        with gen.Capturing() as output:
     3880                            sout = sub.call(ins, shell=True)
     3881                    except:
     3882                        print errmsg
     3883                        print '  ' + fname + ': $ ' + ins
     3884                        for s1out in output: print s1out
     3885                        print sout
     3886                        quit(-1)
     3887                    if sout != 0:
     3888                        print errmsg
     3889                        print '  ' + fname + ': $ ' + ins
     3890                        sub.call(ins, shell=True)
     3891                        quit(-1)
     3892                else:
     3893                    values = 'lon,lat,' + config['RefProjfile'] + ':'.join(CFvardims)
     3894                    try:
     3895                        with gen.Capturing() as output:
     3896                            sout=ncvar.reproject(values, ifile, VnOpS)
     3897                            ins = 'ncvar.reproject(' + values + ', ' + ifile + ', '+ \
     3898                              VnOpS + ')'
     3899                    except:
     3900                        print errmsg
     3901                        print '  ' + fname + ': ' + ins
     3902                        for s1out in output: print s1out
     3903                        quit(-1)
    38653904
    38663905                if debug:
     
    38773916                trckobjf.write(ins + '\n')
    38783917
    3879                 # CFing the reprojected file
    3880                 try:
    3881                     with gen.Capturing() as output:
    3882                         ncvar.CDO_toCF(ofile)
    3883                 except:
    3884                     print errmsg
    3885                     print 'ncvar.CDO_toCF(' + ofile + ')'
    3886                     for s1out in output: print s1out
    3887                     quit(-1)
    3888 
    3889                 if debug:
    3890                     for s1out in output: print s1out
     3918                if reprjop[0:6] == 'remap':
     3919                    # CFing the reprojected file
     3920                    try:
     3921                        with gen.Capturing() as output:
     3922                            ncvar.CDO_toCF(ofile)
     3923                    except:
     3924                        print errmsg
     3925                        print 'ncvar.CDO_toCF(' + ofile + ')'
     3926                        for s1out in output: print s1out
     3927                        quit(-1)
     3928
     3929                    if debug:
     3930                        for s1out in output: print s1out
    38913931               
    38923932    trckobjf.close()
     
    45864626    print 'Models to use as reference for the projection:', ModComProj
    45874627
    4588 # CDO operators to use for the remapping of each variable
    4589 CDOremapvar0 = gen.get_specdictionary_HMT(cnf, H='CDOremapvar_')
    4590 CDOremapvar = {}
    4591 for Skey in CDOremapvar0.keys():
    4592     CDOremapvar[Skey] = gen.str_list(CDOremapvar0[Skey],':')
     4628# Operators to use for the reprojection of each variable
     4629REPRJvar0 = gen.get_specdictionary_HMT(cnf, H='reprojectvar_')
     4630REPRJvar = {}
     4631for Skey in REPRJvar0.keys():
     4632    REPRJvar[Skey] = gen.str_list(REPRJvar0[Skey],':')
    45934633
    45944634if dbg:
    45954635    print 'Remaping operators to use _______'
    4596     gen.printing_dictionary(CDOremapvar)
    4597 
    4598 # Getting common base wights for grid point remapping with CDO
     4636    gen.printing_dictionary(REPRJvar)
     4637
     4638# Getting common base weights for grid point remapping with CDO
    45994639frefgridn = 'RefProj.nc'
    46004640for mod in mods:
     
    46074647        exps = modexps[mod]
    46084648        exp = exps[0]
    4609         cdofdir = cnf['ofold'] + '/' + mod + '/' + exp
    4610         cdofile = None
    4611         for cdoop in CDOremapvar.keys():
    4612             cdovars = CDOremapvar[cdoop]
    4613             for cdovar in cdovars:
    4614                 cdofs= gen.files_folder_HMT(folder=cdofdir,head=cdovar+'_',tail='.nc')
    4615                 for cdof in cdofs:
     4649        reprjfdir = cnf['ofold'] + '/' + mod + '/' + exp
     4650        reprjfile = None
     4651        for reprjop in REPRJvar.keys():
     4652            reprjvars = REPRJvar[cdoop]
     4653            for reprjvar in reprjvars:
     4654                reprjfs= gen.files_folder_HMT(folder=reprjfdir,head=reprjvar+'_',tail='.nc')
     4655                for reprjf in reprjfs:
    46164656                    # Getting direct files as [var]_[fhead].nc
    4617                     if len(cdof.split('_')) == 2:
    4618                         cdofile = cdofdir + '/' + cdof
    4619                         cdovn = cdovar
     4657                    if len(reprjf.split('_')) == 2:
     4658                        reprjfile = reprjfdir + '/' + reprjf
     4659                        reprjvn = reprjvar
    46204660                        break
    4621         if cdofile is None:
     4661        if reprjfile is None:
    46224662            print errmsg
    46234663            print '  ' + main + ": no proper file to get projection information " +  \
    4624               "from '" + cdofdir + "' has been found !!"
     4664              "from '" + reprjfdir + "' has been found !!"
    46254665            quit(-1)
    46264666
    46274667        print "  Creation of reference projection information file from '" + mod+ "'"
    46284668        if dbg:
    4629             print "    using file: '" + cdofile
     4669            print "    using file: '" + reprjfile
    46304670
    46314671        # Getting only 1 time-step for disk space issues
    46324672        try:
    46334673             with gen.Capturing() as output:
    4634                  ncvar.DataSetSection('time,0,1,1', cdofile)
     4674                 ncvar.DataSetSection('time,0,1,1', reprjfile)
    46354675        except:
    46364676            print errmsg
    4637             print 'ncvar.DataSetSection(time,0,1,1, ' + cdofile + ')'
     4677            print 'ncvar.DataSetSection(time,0,1,1, ' + reprjfile + ')'
    46384678            for s1out in output: print s1out
    46394679            quit(-1)
    46404680
    4641         of = cdofile.split('.')[0] + '_time_B0-E1-I1.nc'
     4681        of = reprjfile.split('.')[0] + '_time_B0-E1-I1.nc'
    46424682
    46434683        # Cleaning variables
    46444684        try:
    46454685             with gen.Capturing() as output:
    4646                  ncvar.selvar('lon@lon,lat@lat,time@time', of, cdovn)
     4686                 ncvar.selvar('lon@lon,lat@lat,time@time', of, reprjvn)
    46474687        except:
    46484688            print errmsg
    4649             print 'ncvar.selvar(lon@lon,lat@lat, ' + of + ', ' + cdovn + ')'
     4689            print 'ncvar.selvar(lon@lon,lat@lat, ' + of + ', ' + reprjvn + ')'
    46504690            for s1out in output: print s1out
    46514691            quit(-1)
     
    47054745                        print  "  Projecting files of model '" + mod + "' exp: '" +  \
    47064746                          exp + "' with file '" + cnf['RefProjfile'] + "'"
    4707                         reproject_modexp(mod, exp, cnf, CDOremapvar, moddiffscratch, \
     4747                        reproject_modexp(mod, exp, cnf, REPRJvar, moddiffscratch,    \
    47084748                          addmoddiffs, dbg)
    47094749                        difreproj[imod] = True
  • trunk/tools/model_graphics_template.dat

    r1148 r1186  
    185185plevels = 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.
    186186
     187# Variables reprojection to compute differences among models (which might use different projections)
    187188# ':' separated list of models to use as reference for the common projection
    188189RefProj = WRF:WRF_LMDZ
    189190
     191# Reprojection methodologies using `RefProj' as common projection
     192#
    190193# CDO remapping option to be used for each variable
    191194#  ':' separated list for each of CDO's operators (version depending) to use for each variable
     
    209212#    remaplaf   Largest area fraction remapping
    210213#               Performs a largest area fraction remapping on all input fields.
    211 CDOremapvar_dis = uas:vas:wss
    212 CDOremapvar_nn = hfls:hfss:hus:hurs
    213 CDOremapvar_bic = tas:ta
     214####### ####### ####### or additionally ####### ####### #######
     215# python remapping
     216#   remapping using functions created on purpose
     217#    dis        Distance-weighted average remapping
     218#               Performs a distance-weighted average remapping of the four nearest neighbor
     219#               values on all input fields.
     220#    pnn        Nearest neighbor remapping
     221#               Performs a nearest neighbor remapping on all input fields.
     222reprojectvar_dis = uas:vas:wss
     223reprojectvar_pnn = hfls:hfss:hus:hurs
     224reprojectvar_remapbic = tas:ta
    214225
    215226# Differences to compute
Note: See TracChangeset for help on using the changeset viewer.