Changeset f20af73 in flex_extract.git for source/python/classes/MarsRetrieval.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/classes/MarsRetrieval.py
r6f951ca rf20af73 35 35 import sys 36 36 import subprocess 37 import traceback 37 38 38 39 # software specific classes and modules from flex_extract 39 40 sys.path.append('../') 40 41 import _config 42 try: 43 ec_api = True 44 import ecmwfapi 45 except ImportError: 46 ec_api = False 47 48 try: 49 cds_api = True 50 import cdsapi 51 except ImportError: 52 cds_api = False 41 53 # ------------------------------------------------------------------------------ 42 54 # CLASS … … 130 142 ''' 131 143 132 def __init__(self, server, public, marsclass=" ei", dataset="", type="",144 def __init__(self, server, public, marsclass="EA", dataset="", type="", 133 145 levtype="", levelist="", repres="", date="", resol="", 134 146 stream="", area="", time="", step="", expver="1", … … 158 170 marsclass : str, optional 159 171 Characterisation of dataset. E.g. EI (ERA-Interim), 160 E4 (ERA40), OD (Operational archive), ea(ERA5).161 Default is the ERA -Interim dataset "ei".172 E4 (ERA40), OD (Operational archive), EA (ERA5). 173 Default is the ERA5 dataset "EA". 162 174 163 175 dataset : str, optional … … 429 441 def data_retrieve(self): 430 442 '''Submits a MARS retrieval. Depending on the existence of 431 ECMWF Web-API it is submitted via Python or a443 ECMWF Web-API or CDS API it is submitted via Python or a 432 444 subprocess in the Shell. The parameter for the mars retrieval 433 445 are taken from the defined class attributes. … … 452 464 attrs['class'] = mclass 453 465 454 # prepare target variable as needed for the Web API mode466 # prepare target variable as needed for the Web API or CDS API mode 455 467 # within the dictionary for full access 456 468 # as a single variable for public access … … 475 487 if self.server: 476 488 try: 477 if self.public: 478 print('RETRIEVE PUBLIC DATA!') 489 if cds_api and isinstance(self.server, cdsapi.Client): 490 print('RETRIEVE ERA5 WITH CDS API!') 491 self.server.retrieve(_config.CDS_DATASET, 492 attrs, target) 493 elif ec_api and isinstance(self.server, ecmwfapi.ECMWFDataServer): 494 print('RETRIEVE PUBLIC DATA (NOT ERA5)!') 479 495 self.server.retrieve(attrs) 496 elif ec_api and isinstance(self.server, ecmwfapi.ECMWFService): 497 print('EXECUTE NON-PUBLIC RETRIEVAL (NOT ERA5)!') 498 self.server.execute(attrs, target) 480 499 else: 481 print('EXECUTE NON-PUBLIC RETRIEVAL!') 482 self.server.execute(attrs, target) 483 except: 484 e = sys.exc_info()[0] 485 print("ERROR: ", e) 486 print('MARS Request failed!') 487 if not self.public and os.stat(target).st_size == 0: 488 print('MARS Request returned no data - ' 489 'please check request') 500 print('ERROR:') 501 print('No match for Web API instance!') 490 502 raise IOError 491 elif self.public and os.stat(target).st_size == 0: 492 print('Public MARS Request returned no data - ' 493 'please check request') 494 raise IOError 495 else: 496 raise IOError 497 # MARS request via extra process in shell 503 except Exception as e: 504 print('\n\nMARS Request failed!') 505 print(e) 506 tb = sys.exc_info()[2] 507 print(traceback.format_exc()) 508 sys.exit() 509 510 # MARS request via call in shell 498 511 else: 499 512 request_str = 'ret' … … 501 514 request_str = request_str + ',' + key + '=' + str(value) 502 515 request_str += ',target="' + target + '"' 503 p = subprocess.Popen(['mars' ],516 p = subprocess.Popen(['mars', '-p'], 504 517 stdin=subprocess.PIPE, 505 518 stdout=subprocess.PIPE,
Note: See TracChangeset
for help on using the changeset viewer.