Changeset f20af73 in flex_extract.git for source/python/mods/get_mars_data.py


Ignore:
Timestamp:
Mar 8, 2019, 10:05:20 AM (5 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
82c2959
Parents:
b4a4777
Message:

added CDS API support for ERA5 instead of ECMWFAPI / refactored setup of CONTROL parameter because for local version it wanted to use not installed ECMWF_ENV file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/python/mods/get_mars_data.py

    r45b99e6 rf20af73  
    6767    inspect.getfile(inspect.currentframe()))) + '/../')
    6868import _config
    69 from tools import (my_error, normal_exit, get_cmdline_args,
     69from .tools import (setup_controldata, my_error, normal_exit, get_cmdline_args,
    7070                   read_ecenv, make_dir)
    7171from classes.EcFlexpart import EcFlexpart
     
    7474
    7575try:
    76     ecapi = True
     76    ec_api = True
    7777    import ecmwfapi
    7878except ImportError:
    79     ecapi = False
     79    ec_api = False
     80
     81try:
     82    cds_api = True
     83    import cdsapi
     84except ImportError:
     85    cds_api = False
    8086# ------------------------------------------------------------------------------
    8187# FUNCTION
     
    95101    '''
    96102
    97     args = get_cmdline_args()
    98     c = ControlFile(args.controlfile)
    99 
    100     env_parameter = read_ecenv(_config.PATH_ECMWF_ENV)
    101     c.assign_args_to_control(args)
    102     c.assign_envs_to_control(env_parameter)
    103     c.check_conditions(args.queue)
    104 
     103    c, _, _, _ = setup_controldata()
    105104    get_mars_data(c)
    106     normal_exit(c.mailops, c.queue, 'Done!')
     105    normal_exit('Retrieving MARS data: Done!')
    107106
    108107    return
     
    125124
    126125    '''
    127     c.ecapi = ecapi
     126    c.ec_api = ec_api
     127    c.cds_api = cds_api
    128128
    129129    if not os.path.exists(c.inputdir):
     
    182182
    183183def mk_server(c):
    184     '''Creates server connection if ECMWF WebAPI is available.
     184    '''Creates a server connection with available python API.
     185
     186    Which API is used depends on availability and the dataset to be retrieved.
     187    The CDS API is used for ERA5 dataset no matter if the user is a member or
     188    a public user. ECMWF WebAPI is used for all other available datasets.
    185189
    186190    Parameters
     
    192196    Return
    193197    ------
    194     server : ECMWFDataServer or ECMWFService
    195         Connection to ECMWF server via python interface ECMWF WebAPI.
    196 
    197     '''
    198     if c.ecapi:
     198    server : ECMWFDataServer, ECMWFService or Client
     199        Connection to ECMWF server via python interface ECMWF WebAPI or CDS API.
     200
     201    '''
     202    if cds_api and (c.marsclass.upper() == 'EA'):
     203        server = cdsapi.Client()
     204        c.ec_api = False
     205    elif c.ec_api:
    199206        if c.public:
    200207            server = ecmwfapi.ECMWFDataServer()
    201208        else:
    202209            server = ecmwfapi.ECMWFService("mars")
     210        c.cds_api = False
    203211    else:
    204212        server = False
    205213
    206     print('Using ECMWF WebAPI: ' + str(c.ecapi))
     214    print('Using ECMWF WebAPI: ' + str(c.ec_api))
     215    print('Using CDS API: ' + str(c.cds_api))
    207216
    208217    return server
     
    353362            flexpart.retrieve(server, dates, c.public, c.request, c.inputdir)
    354363        except IOError:
    355             my_error(c.mailfail, 'MARS request failed')
     364            my_error('MARS request failed')
    356365
    357366        day += delta_t
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG