Changeset f20af73 in flex_extract.git for source/python/mods/tools.py
- Timestamp:
- Mar 8, 2019, 10:05:20 AM (5 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 82c2959
- Parents:
- b4a4777
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/python/mods/tools.py
r8778c5a rf20af73 65 65 import subprocess 66 66 import traceback 67 import exceptions 67 try: 68 import exceptions 69 except ImportError: 70 import builtins as exceptions 68 71 from datetime import datetime 69 72 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter 73 74 70 75 71 76 # ------------------------------------------------------------------------------ 72 77 # METHODS 73 78 # ------------------------------------------------------------------------------ 79 80 def setup_controldata(): 81 '''Collects, stores and checks controlling arguments from command line, 82 CONTROL file and ECMWF_ENV file. 83 84 Parameters 85 ---------- 86 87 Return 88 ------ 89 c : ControlFile 90 Contains all the parameters of CONTROL file and 91 command line. 92 93 ppid : str 94 Parent process id. 95 96 queue : str 97 Name of queue for submission to ECMWF (e.g. ecgate or cca ) 98 99 job_template : str 100 Name of the job template file for submission to ECMWF server. 101 ''' 102 import _config 103 from classes.ControlFile import ControlFile 104 105 args = get_cmdline_args() 106 c = ControlFile(args.controlfile) 107 c.assign_args_to_control(args) 108 if os.path.isfile(_config.PATH_ECMWF_ENV): 109 env_parameter = read_ecenv(_config.PATH_ECMWF_ENV) 110 c.assign_envs_to_control(env_parameter) 111 c.check_conditions(args.queue) 112 113 return c, args.ppid, args.queue, args.job_template 74 114 75 115 def none_or_str(value): … … 259 299 print("... clean inputdir!") 260 300 261 cleanlist = glob.glob(os.path.join(c.inputdir, "*")) 301 cleanlist = [file for file in glob.glob(os.path.join(c.inputdir, "*")) 302 if not os.path.basename(file).startswith(c.prefix)] 262 303 263 304 if cleanlist: 264 305 for element in cleanlist: 265 if c.prefix not in element: 266 silent_remove(element) 267 if c.ecapi is False and (c.ectrans == 1 or c.ecstorage == 1): 268 silent_remove(element) 306 silent_remove(element) 269 307 print("... done!") 270 308 else: … … 274 312 275 313 276 def my_error( users,message='ERROR'):314 def my_error(message='ERROR'): 277 315 '''Prints a specified error message which can be passed to the function 278 316 before exiting the program. … … 280 318 Parameters 281 319 ---------- 282 user : list of str283 Contains all email addresses which should be notified.284 It might also contain just the ecmwf user name which wil trigger285 mailing to the associated email address for this user.286 287 320 message : str, optional 288 321 Error message. Default value is "ERROR". … … 464 497 else: 465 498 for data in fdata: 466 if data [0] != '!':467 table128[data[0:3]] = data[59:6 4].strip()499 if data != '' and data[0] != '!': 500 table128[data[0:3]] = data[59:65].strip() 468 501 469 502 return table128 … … 508 541 509 542 return ipar 543 544 def to_param_id_with_tablenumber(pars, table): 545 '''Transform parameter names to parameter ids and add table id. 546 547 Conversion with ECMWF grib table 128. 548 549 Parameters 550 ---------- 551 pars : str 552 Addpar argument from CONTROL file in the format of 553 parameter names instead of ids. The parameter short 554 names are sepearted with "/" and they are passed as 555 one single string. 556 557 table : dict 558 Contains the ECMWF grib table 128 information. 559 The key is the parameter number and the value is the 560 short name of the parameter. 561 562 Return 563 ------ 564 spar : str 565 List of addpar parameters from CONTROL file transformed to 566 parameter ids in the format of integer. 567 ''' 568 if not pars: 569 return [] 570 if not isinstance(pars, str): 571 pars=str(pars) 572 573 cpar = pars.upper().split('/') 574 spar = [] 575 for par in cpar: 576 for k, v in table.iteritems(): 577 if par == k or par == v: 578 spar.append(k + '.128') 579 break 580 else: 581 print('\n\n\t\tWarning: par ' + par + ' not found in table 128\n\n') 582 583 return '/'.join(spar) 510 584 511 585 def get_list_as_string(list_obj, concatenate_sign=', '):
Note: See TracChangeset
for help on using the changeset viewer.