Changeset 3f36e42 in flex_extract.git for source/python/classes/EcFlexpart.py
- Timestamp:
- Dec 4, 2018, 9:46:22 PM (5 years ago)
- Branches:
- master, ctbto, dev
- Children:
- fdda1b9
- Parents:
- 97f4f4c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/python/classes/EcFlexpart.py
r2d56c04 r3f36e42 147 147 i = 0 148 148 if fluxes and c.maxstep <= 24: 149 # no forecast beyond one day is needed!150 # Thus, prepare flux data manually as usual151 # with only forecast fields with start times at 00/12152 # (but without 00/12 fields since these are153 # the initialisation times of the flux fields154 # and therefore are zero all the time)155 149 self.types[str(c.acctype)] = {'times': str(c.acctime), 156 150 'steps': '{}/to/{}/by/{}'.format( … … 523 517 retr_param_dict['gaussian'] = self.gaussian 524 518 525 if pk == 'OG__SL':526 pass527 519 if pk == 'OG_OROLSM__SL' and not oro: 528 520 oro = True … … 658 650 from genshi.template.text import NewTextTemplate 659 651 from genshi.template import TemplateLoader 660 661 loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False) 662 namelist_template = loader.load(_config.TEMPFILE_NAMELIST, 663 cls=NewTextTemplate) 664 665 self.inputdir = c.inputdir 666 area = np.asarray(self.area.split('/')).astype(float) 667 grid = np.asarray(self.grid.split('/')).astype(float) 668 669 if area[1] > area[3]: 670 area[1] -= 360 671 maxl = int((area[3] - area[1]) / grid[1]) + 1 672 maxb = int((area[0] - area[2]) / grid[0]) + 1 673 674 stream = namelist_template.generate( 675 maxl = str(maxl), 676 maxb = str(maxb), 677 mlevel = str(self.level), 678 mlevelist = str(self.levelist), 679 mnauf = str(self.resol), 680 metapar = '77', 681 rlo0 = str(area[1]), 682 rlo1 = str(area[3]), 683 rla0 = str(area[2]), 684 rla1 = str(area[0]), 685 momega = str(c.omega), 686 momegadiff = str(c.omegadiff), 687 mgauss = str(c.gauss), 688 msmooth = str(c.smooth), 689 meta = str(c.eta), 690 metadiff = str(c.etadiff), 691 mdpdeta = str(c.dpdeta) 692 ) 693 694 namelistfile = os.path.join(self.inputdir, _config.FILE_NAMELIST) 695 696 with open(namelistfile, 'w') as f: 697 f.write(stream.render('text')) 652 from genshi.template.eval import UndefinedError 653 654 try: 655 loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False) 656 namelist_template = loader.load(_config.TEMPFILE_NAMELIST, 657 cls=NewTextTemplate) 658 659 self.inputdir = c.inputdir 660 area = np.asarray(self.area.split('/')).astype(float) 661 grid = np.asarray(self.grid.split('/')).astype(float) 662 663 if area[1] > area[3]: 664 area[1] -= 360 665 maxl = int((area[3] - area[1]) / grid[1]) + 1 666 maxb = int((area[0] - area[2]) / grid[0]) + 1 667 668 stream = namelist_template.generate( 669 maxl = str(maxl), 670 maxb = str(maxb), 671 mlevel = str(self.level), 672 mlevelist = str(self.levelist), 673 mnauf = str(self.resol), 674 metapar = '77', 675 rlo0 = str(area[1]), 676 rlo1 = str(area[3]), 677 rla0 = str(area[2]), 678 rla1 = str(area[0]), 679 momega = str(c.omega), 680 momegadiff = str(c.omegadiff), 681 mgauss = str(c.gauss), 682 msmooth = str(c.smooth), 683 meta = str(c.eta), 684 metadiff = str(c.etadiff), 685 mdpdeta = str(c.dpdeta) 686 ) 687 except UndefinedError as e: 688 print('... ERROR ' + str(e)) 689 690 sys.exit('\n... error occured while trying to generate namelist ' + 691 _config.TEMPFILE_NAMELIST) 692 except OSError as e: 693 print('... ERROR CODE: ' + str(e.errno)) 694 print('... ERROR MESSAGE:\n \t ' + str(e.strerror)) 695 696 sys.exit('\n... error occured while trying to generate template ' + 697 _config.TEMPFILE_NAMELIST) 698 699 try: 700 namelistfile = os.path.join(self.inputdir, _config.FILE_NAMELIST) 701 702 with open(namelistfile, 'w') as f: 703 f.write(stream.render('text')) 704 except OSError as e: 705 print('... ERROR CODE: ' + str(e.errno)) 706 print('... ERROR MESSAGE:\n \t ' + str(e.strerror)) 707 708 sys.exit('\n... error occured while trying to write ' + 709 namelistfile) 698 710 699 711 return … … 701 713 702 714 def deacc_fluxes(self, inputfiles, c): 703 '''Goes through all flux fields in ordered time and de-accumulate 715 '''De-accumulate and disaggregate flux data. 716 717 Goes through all flux fields in ordered time and de-accumulate 704 718 the fields. Afterwards the fields are disaggregated in time. 705 719 Different versions of disaggregation is provided for rainfall … … 988 1002 if not gid: 989 1003 continue 990 1004 #============================================================================================ 991 1005 # remove old fort.* files and open new ones 992 1006 # they are just valid for a single product … … 995 1009 silent_remove(fortfile) 996 1010 fdict[k] = open(fortfile, 'w') 997 1011 #============================================================================================ 998 1012 # create correct timestamp from the three time informations 999 1013 cdate = str(codes_get(gid, 'date')) … … 1019 1033 'WRF' + cdate + '.' + ctime + '.000.grb2'), 'w') 1020 1034 olddate = cdate[:] 1021 1035 #============================================================================================ 1022 1036 # savedfields remembers which fields were already used. 1023 1037 savedfields = [] … … 1083 1097 codes_release(gid) 1084 1098 gid = codes_new_from_index(iid) 1085 1099 #============================================================================================ 1086 1100 for f in fdict.values(): 1087 1101 f.close() 1088 1102 #============================================================================================ 1089 1103 # call for Fortran program to convert e.g. reduced_gg grids to 1090 1104 # regular_ll and calculate detadot/dp … … 1097 1111 my_error(c.mailfail, 'fort.21 is empty while parameter eta \ 1098 1112 is set to 1 in CONTROL file') 1099 1113 #============================================================================================ 1100 1114 # write out all output to log file before starting fortran programm 1101 1115 sys.stdout.flush() … … 1105 1119 c.exedir, _config.FORTRAN_EXECUTABLE)], shell=True) 1106 1120 os.chdir(pwd) 1107 1121 #============================================================================================ 1108 1122 # create name of final output file, e.g. EN13040500 (ENYYMMDDHH) 1109 1123 if c.maxstep > 12: … … 1115 1129 # collect for final processing 1116 1130 self.outputfilelist.append(os.path.basename(fnout)) 1117 1131 #============================================================================================ 1118 1132 # create outputfile and copy all data from intermediate files 1119 1133 # to the outputfile (final GRIB input files for FLEXPART) … … 1135 1149 shutil.copyfileobj(open(os.path.join(c.inputdir, 'fort.25'), 1136 1150 'rb'), fout) 1137 1151 #============================================================================================ 1138 1152 if c.wrf: 1139 1153 fwrf.close() … … 1145 1159 1146 1160 def process_output(self, c): 1147 '''The grib files are postprocessed depending on the selection in 1161 '''Postprocessing of FLEXPART input files. 1162 1163 The grib files are postprocessed depending on the selection in 1148 1164 CONTROL file. The resulting files are moved to the output 1149 1165 directory if its not equal to the input directory. … … 1180 1196 1181 1197 if c.format.lower() == 'grib2': 1182 p = subprocess.check_call([' codes_set', '-s', 'edition=2,',1198 p = subprocess.check_call(['grib_set', '-s', 'edition=2,', 1183 1199 'productDefinitionTemplateNumber=8', 1184 1200 ofile, ofile + '_2'])
Note: See TracChangeset
for help on using the changeset viewer.