Changeset 0a75335 in flex_extract.git


Ignore:
Timestamp:
Jul 10, 2020, 8:20:31 AM (4 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
8028176
Parents:
bbbe1e1
Message:

changed cds api retrieval for single levels to retrieve from CS3 disks instead of MARS - severe performance boost

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • Source/Python/Classes/ControlFile.py

    r5f67883 r0a75335  
    616616                      os.path.join(self.inputdir, _config.FILE_MARS_REQUESTS))
    617617
    618         check_public(self.public, self.dataset)
     618        check_public(self.public, self.dataset, self.marsclass)
    619619
    620620        self.type = check_type(self.type, self.step)
  • Source/Python/Classes/MarsRetrieval.py

    r026b359 r0a75335  
    446446
    447447        return
     448   
     449    def _convert_to_cdsera5_sfc_request(self, attrs):
     450        '''
     451        The keywords and values for the single level download
     452        with CDS API is different from MARS. This function
     453        converts the old request keywords to the new ones.
     454       
     455        Example request for single level downloads in CDS API
     456       
     457        retrieve(
     458            'reanalysis-era5-single-levels',
     459            {
     460                'product_type': 'reanalysis',
     461                'variable': 'total_precipitation',
     462                'year': '2019',
     463                'month': '01',
     464                'day': '01',
     465                'time': '00:00',
     466                'format': 'grib',
     467                'grid':[1.0, 1.0],
     468                'area': [
     469                    45, 0, 43,
     470                    12,
     471                ],
     472            },
     473            'download.grib')
     474           
     475        Parameters
     476        ----------
     477        attrs : dict
     478            Dictionary of the mars request parameters.
     479
     480        Return
     481        ------
     482
     483        '''
     484        from datetime import datetime, timedelta
     485        newattrs = {}
     486
     487        if '/' in attrs['date']:
     488            year = set()
     489            month = set()
     490            day = set()
     491            start,end = attrs['date'].split('/')[::2]
     492            sdate = datetime.strptime(start, '%Y%m%d')
     493            edate = datetime.strptime(end, '%Y%m%d')
     494            date = sdate
     495            while date <= edate:
     496                year.add(date.year)
     497                month.add(date.month)
     498                day.add(date.day)     
     499                date = date + timedelta(days=1)
     500            newattrs['year'] =list(year)
     501            newattrs['month'] = list(month)
     502            newattrs['day'] =  list(day)                       
     503        else:
     504            date = datetime.strptime(attrs['date'], '%Y%m%d')
     505            newattrs['year'] = date.year
     506            newattrs['month'] = date.month
     507            newattrs['day'] =  date.day                 
     508       
     509        newattrs['product_type'] = 'reanalysis'
     510        newattrs['area'] = attrs['area'].split('/')
     511        newattrs['grid'] = list(map(float,attrs['grid'].split('/')))
     512        newattrs['param'] = attrs['param'].split('/')       
     513        newattrs['time'] = list(map(str,range(0,24,3)))
     514        newattrs['format'] = 'grib'
     515               
     516        return newattrs
    448517
    449518    def data_retrieve(self):
     
    479548            del attrs['target']
    480549        print('target: ' + target)
    481 
     550       
    482551        # find all keys without a value and convert all other values to strings
    483552        empty_keys = []
     
    498567            try:
    499568                if cds_api and isinstance(self.server, cdsapi.Client):
     569                    # distinguish between model (ECMWF MARS access)
     570                    # and surface level (CS3 online access)
     571                    if attrs['levtype'].lower() == 'ml':
     572                        dataset = _config.CDS_DATASET_ML
     573                    else:
     574                        dataset = _config.CDS_DATASET_SFC
     575                        attrs = self._convert_to_cdsera5_sfc_request(attrs)
    500576                    print('RETRIEVE ERA5 WITH CDS API!')
    501                     self.server.retrieve(_config.CDS_DATASET,
     577                    self.server.retrieve(dataset,
    502578                                         attrs, target)
    503579                elif ec_api and isinstance(self.server, ecmwfapi.ECMWFDataServer):
  • Source/Python/Mods/checks.py

    rf61e1df r0a75335  
    651651    return
    652652
    653 def check_public(public, dataset):
     653def check_public(public, dataset, marsclass):
    654654    '''Check wether the dataset parameter is set to a
    655655    public data set.
     
    667667
    668668    '''
    669     if public and not dataset:
     669    if public and not dataset and not (marsclass.upper() == 'EA'):
    670670        raise ValueError('ERROR: If public MARS data are to be retrieved, '
    671671                         'the "dataset"-parameter has to be set, too!')
  • Source/Python/_config.py

    r98f09d2 r0a75335  
    4646INSTALL_TARGETS = ['local', 'ecgate', 'cca', 'ccb']
    4747
    48 CDS_DATASET = 'reanalysis-era5-complete'
     48CDS_DATASET_ML = 'reanalysis-era5-complete'
     49CDS_DATASET_SFC = 'reanalysis-era5-single-levels'
    4950
    5051# up-to-date available maximum level numbers at ECMWF, 05.10.2018
  • Testing/Installation/Api_testscripts/test_cdsapi_modellevel.py

    r5bf163a r0a75335  
    1313        'type'    : 'fc',
    1414        'step'    : '3/to/12/by/3',
    15         'param'   : '130.128',
     15        'param'   : 't',
    1616        'levtype' : 'ml',
    1717        'levelist': '135/to/137',
  • Testing/Installation/Api_testscripts/test_ecmwfapi_public.py

    r5bf163a r0a75335  
    1717        'type'      : "an",
    1818        'class'     : "ep",
     19    'number'    : "0",
    1920        'target'    : "download_cera20c_ecmwfapi.grib"
    2021})
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG