Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Code Block
#!/usr/bin/env python
import calendar
from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer()

def retrieve_cera20c_enda():
       A function to demonstrate how to iterate efficiently over all months,
       for a list of years, for a CERA-20C daily data request. 
       You can extend the number of years to adapt the iteration to your needs.
       You can use the variable 'target' to organise the requested data in files as you wish."        
    yearStart = 2000
    yearEnd = 2002
    monthStart = 1
    monthEnd = 12

    # enda is arranged by months, so we iterate over the months
    for year in list(range(yearStart, yearEnd + 1)):
        for month in list(range(monthStart, monthEnd + 1)):
            startDate = '%04d%02d%02d' % (year, month, 1)
            numberOfDays = calendar.monthrange(year, month)[1]
            lastDate = '%04d%02d%02d' % (year, month, numberOfDays)
            # we submit a data request for the current month
            target = "cera20c_enda_ensemble_%04d%02d_pl.grb" % (year, month)
            requestDates = (startDate + "/TO/" + lastDate)
            era20c_enda_sfc_request(requestDates, target)

def era20c_enda_sfc_request(requestDates, target):
        A CERA-20C request for U and V component of wind, pressure levels, all 10 ensemble members.
        You can change the keywords below to adapt it to your needs.
        (eg add or remove  parameters, times etc)
        "class": "ep",
        "dataset": "cera20c",
        "stream": "enda",
        "expver": "1",
        "type": "an",
        "levtype": "pl",
        "levelist": "1/2/3/5/7/10/20/30/50/70/100/125/150/175/200/225/250/300/350/400/450/500/550/600/650/700/750/775/800/825/850/875/900/925/950/975/1000",
        "number": "0/1/2/3/4/5/6/7/8/9",   # ensemble members
        "date": requestDates,
        "time": "00/03/06/09/12/15/18/21",
 # ensemble members         "step": "0",
        "param": "131.128/132.128",   # Here: U and V components of wind. These parameters are not archived explicitly, but derived from vorticity and divergence on the fly.
        "target": target,

if __name__ == '__main__':