Changeset 3f36e42 in flex_extract.git for source/python/classes
- Timestamp:
- Dec 4, 2018, 9:46:22 PM (5 years ago)
- Branches:
- master, ctbto, dev
- Children:
- fdda1b9
- Parents:
- 97f4f4c
- Location:
- source/python/classes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
source/python/classes/ControlFile.py
r97f4f4c r3f36e42 61 61 import _config 62 62 from mods.tools import my_error, silent_remove 63 from mods.checks import check_grid _area63 from mods.checks import check_grid, check_area, check_levels 64 64 65 65 # ------------------------------------------------------------------------------ … … 345 345 sys.exit(1) 346 346 347 # assure consistency of levelist and level 348 if not self.levelist and not self.level: 349 print('Warning: neither levelist nor level \ 350 specified in CONTROL file') 351 sys.exit(1) 352 elif not self.levelist and self.level: 353 self.levelist = '1/to/' + self.level 354 elif (self.levelist and not self.level) or \ 355 (self.levelist[-1] != self.level[-1]): 356 self.level = self.levelist.split('/')[-1] 357 else: 358 pass 359 360 # check if max level is a valid level 361 if int(self.level) not in _config.MAX_LEVEL_LIST: 362 print('ERROR: ') 363 print('LEVEL must be the maximum level of a specified ' 364 'level list from ECMWF, e.g.') 365 print(_config.MAX_LEVEL_LIST) 366 print('Check parameter "LEVEL" or the max level of "LEVELIST"!') 367 sys.exit(1) 347 self.levelist, self.level = check_levels(self.levelist, self.level) 348 349 # # assure consistency of levelist and level 350 # if not self.levelist and not self.level: 351 # print('Warning: neither levelist nor level \ 352 # specified in CONTROL file') 353 # sys.exit(1) 354 # elif not self.levelist and self.level: 355 # self.levelist = '1/to/' + self.level 356 # elif (self.levelist and not self.level) or \ 357 # (self.levelist[-1] != self.level[-1]): 358 # self.level = self.levelist.split('/')[-1] 359 # else: 360 # pass 361 362 # # check if max level is a valid level 363 # if int(self.level) not in _config.MAX_LEVEL_LIST: 364 # print('ERROR: ') 365 # print('LEVEL must be the maximum level of a specified ' 366 # 'level list from ECMWF, e.g.') 367 # print(_config.MAX_LEVEL_LIST) 368 # print('Check parameter "LEVEL" or the max level of "LEVELIST"!') 369 # sys.exit(1) 368 370 369 371 # prepare step list if "/" signs are found … … 477 479 478 480 479 self.grid, self.area = check_grid_area(self.grid, self.area, 480 self.upper, self.lower, 481 self.left, self.right) 482 483 484 485 # convert grid and area components to correct format and input 486 #if 'N' in self.grid: # Gaussian output grid 487 # self.area = 'G' 488 # else: 489 # if '/' in self.grid: 490 # gridx, gridy = self.grid.split('/') 491 # if gridx == gridy: 492 # self.grid = gridx 493 494 495 # # check on grid format 496 # if float(self.grid) / 100. >= 0.5: 497 # # grid is defined in 1/1000 degrees; old format 498 # self.grid = '{}/{}'.format(float(self.grid) / 1000., 499 # float(self.grid) / 1000.) 500 # self.area = '{}/{}/{}/{}'.format(float(self.upper) / 1000., 501 # float(self.left) / 1000., 502 # float(self.lower) / 1000., 503 # float(self.right) / 1000.) 504 # elif float(self.grid) / 100. < 0.5: 505 # # grid is defined in normal degree; new format 506 # self.grid = '{}/{}'.format(float(self.grid), float(self.grid)) 507 # self.area = '{}/{}/{}/{}'.format(float(self.upper), 508 # float(self.left), 509 # float(self.lower), 510 # float(self.right)) 481 self.grid = check_grid(self.grid) 482 483 self.area = check_area(self.grid, self.area, self.upper, self.lower, 484 self.left, self.right) 485 511 486 512 487 return … … 555 530 return sorted(l) 556 531 557 def check_ppid(self, ppid):558 '''Sets the current PPID.559 560 Parameters561 ----------562 ppid : :obj:`int` or :obj:`None`563 Contains the ppid number provided by the command line parameter564 of is None otherwise.565 566 Return567 ------568 569 '''570 571 if not ppid:572 self.ppid = str(os.getppid())573 else:574 self.ppid = ppid575 576 return -
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.