Web-API examples

 UERRA SMHI pressure level request

  • The objective of this example is to demonstrate how to iterate efficiently over some years, for a particular HARMONIE/V1 pressure level request.
  • At this point you may wish to have a look on the  UERRA SMHI availability
  • The request below can be used as a starting point, however you need to keep in mind that you have to adapt it to your needs e.g. to set the keyword, values according to your requirements (e.g. add or remove 'param', 'levtype', 'step' etc).
  • In this way you can extend this example to download a longer period or even the whole UERRA dataset.

(smile) You can use the variable 'target' to organise the requested data in separate files if you wish.

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

def retrieve_uerra_eswi():
    """      
       A function to demonstrate how to iterate efficiently over several years and months etc    
       for a particular UERRA request for origin SMHI.     
       Change the variables below to adapt the iteration to your needs.
       You can use the variable 'target' to organise the requested data in files as you wish.
       In the example below the data are organised in files per month. (eg "uerra_eswi_daily_201510.grb")
    """
    yearStart = 2008
    yearEnd = 2009
    monthStart = 1
    monthEnd = 12
    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)
            target = "uerra_eswi_daily_%04d%02d.grb" % (year, month)
            requestDates = (startDate + "/TO/" + lastDate)
            uerra_eswi_request(requestDates, target)

def uerra_eswi_request(requestDates, target):
    """      
        A UERRA request for origin SMHI, for analysis pressure level data.
        Change the keywords below to adapt it to your needs.
        (eg to add or to remove  levels, parameters, times etc)
        Request cost per day is XXXX fields, XXXX Mbytes
    """
    server.retrieve({
        "class": "ur",
        "stream": "oper",
        "type": "an",
        "dataset": "uerra",
        "origin" : "eswi",
        "date": requestDates,
        "expver": "prod",
        "levtype": "pl",
        "levelist": "1000",
        "param": "130.128",
        "target": target,
        "time": "00/06/12/18"
    })

if __name__ == '__main__':
    retrieve_uerra_eswi()