Changeset 1186 in lmdz_wrf
- Timestamp:
- Oct 14, 2016, 5:12:55 PM (8 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/model_graphics.py
r1168 r1186 3675 3675 return 3676 3676 3677 def reproject_modexp(mod,exp,config, CDOops,fscr,fadd,debug):3677 def reproject_modexp(mod,exp,config,REPRJops,fscr,fadd,debug): 3678 3678 """ Function to re-project and re-compute files from a given model/experiment 3679 3679 mod= model 3680 3680 exp= experiment 3681 3681 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 3683 3696 fscr= re-projected files to compute from the scratch 3684 3697 fadd= re-projected files to be added … … 3706 3719 if fadd: 3707 3720 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 3708 3732 3709 3733 if not os.path.isfile(varcompf): … … 3783 3807 op = vnop.split('_')[1] 3784 3808 values = allcompvar[vnop] 3809 VnOpS = varnoper(vn, op, opsurnames) 3785 3810 3786 3811 # Only are reprojected that files which do contain 'lon' and 'lat', … … 3788 3813 inNO, iopNO, iop = gen.list_coincidences(opNOreproj,op.split('+')) 3789 3814 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: 3792 3817 print errmsg 3793 print ' ' + fname + ": no reprojecting CDO operator found for " +\3818 print ' ' + fname + ": no reprojecting operator found for " + \ 3794 3819 " variable '" + vn + "' !!" 3795 3820 print ' available values _______' 3796 gen.printing_dictionary( CDOops)3821 gen.printing_dictionary(REPRJops) 3797 3822 quit(-1) 3798 3823 … … 3847 3872 ofile + "'" 3848 3873 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) 3865 3904 3866 3905 if debug: … … 3877 3916 trckobjf.write(ins + '\n') 3878 3917 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 3891 3931 3892 3932 trckobjf.close() … … 4586 4626 print 'Models to use as reference for the projection:', ModComProj 4587 4627 4588 # CDO operators to use for the remappingof each variable4589 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 4629 REPRJvar0 = gen.get_specdictionary_HMT(cnf, H='reprojectvar_') 4630 REPRJvar = {} 4631 for Skey in REPRJvar0.keys(): 4632 REPRJvar[Skey] = gen.str_list(REPRJvar0[Skey],':') 4593 4633 4594 4634 if dbg: 4595 4635 print 'Remaping operators to use _______' 4596 gen.printing_dictionary( CDOremapvar)4597 4598 # Getting common base w ights for grid point remapping with CDO4636 gen.printing_dictionary(REPRJvar) 4637 4638 # Getting common base weights for grid point remapping with CDO 4599 4639 frefgridn = 'RefProj.nc' 4600 4640 for mod in mods: … … 4607 4647 exps = modexps[mod] 4608 4648 exp = exps[0] 4609 cdofdir = cnf['ofold'] + '/' + mod + '/' + exp4610 cdofile = None4611 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: 4616 4656 # Getting direct files as [var]_[fhead].nc 4617 if len( cdof.split('_')) == 2:4618 cdofile = cdofdir + '/' + cdof4619 cdovn = cdovar4657 if len(reprjf.split('_')) == 2: 4658 reprjfile = reprjfdir + '/' + reprjf 4659 reprjvn = reprjvar 4620 4660 break 4621 if cdofile is None:4661 if reprjfile is None: 4622 4662 print errmsg 4623 4663 print ' ' + main + ": no proper file to get projection information " + \ 4624 "from '" + cdofdir + "' has been found !!"4664 "from '" + reprjfdir + "' has been found !!" 4625 4665 quit(-1) 4626 4666 4627 4667 print " Creation of reference projection information file from '" + mod+ "'" 4628 4668 if dbg: 4629 print " using file: '" + cdofile4669 print " using file: '" + reprjfile 4630 4670 4631 4671 # Getting only 1 time-step for disk space issues 4632 4672 try: 4633 4673 with gen.Capturing() as output: 4634 ncvar.DataSetSection('time,0,1,1', cdofile)4674 ncvar.DataSetSection('time,0,1,1', reprjfile) 4635 4675 except: 4636 4676 print errmsg 4637 print 'ncvar.DataSetSection(time,0,1,1, ' + cdofile + ')'4677 print 'ncvar.DataSetSection(time,0,1,1, ' + reprjfile + ')' 4638 4678 for s1out in output: print s1out 4639 4679 quit(-1) 4640 4680 4641 of = cdofile.split('.')[0] + '_time_B0-E1-I1.nc'4681 of = reprjfile.split('.')[0] + '_time_B0-E1-I1.nc' 4642 4682 4643 4683 # Cleaning variables 4644 4684 try: 4645 4685 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) 4647 4687 except: 4648 4688 print errmsg 4649 print 'ncvar.selvar(lon@lon,lat@lat, ' + of + ', ' + cdovn + ')'4689 print 'ncvar.selvar(lon@lon,lat@lat, ' + of + ', ' + reprjvn + ')' 4650 4690 for s1out in output: print s1out 4651 4691 quit(-1) … … 4705 4745 print " Projecting files of model '" + mod + "' exp: '" + \ 4706 4746 exp + "' with file '" + cnf['RefProjfile'] + "'" 4707 reproject_modexp(mod, exp, cnf, CDOremapvar, moddiffscratch,\4747 reproject_modexp(mod, exp, cnf, REPRJvar, moddiffscratch, \ 4708 4748 addmoddiffs, dbg) 4709 4749 difreproj[imod] = True -
trunk/tools/model_graphics_template.dat
r1148 r1186 185 185 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. 186 186 187 # Variables reprojection to compute differences among models (which might use different projections) 187 188 # ':' separated list of models to use as reference for the common projection 188 189 RefProj = WRF:WRF_LMDZ 189 190 191 # Reprojection methodologies using `RefProj' as common projection 192 # 190 193 # CDO remapping option to be used for each variable 191 194 # ':' separated list for each of CDO's operators (version depending) to use for each variable … … 209 212 # remaplaf Largest area fraction remapping 210 213 # 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. 222 reprojectvar_dis = uas:vas:wss 223 reprojectvar_pnn = hfls:hfss:hus:hurs 224 reprojectvar_remapbic = tas:ta 214 225 215 226 # Differences to compute
Note: See TracChangeset
for help on using the changeset viewer.