WebAPI functionality

Koen Hufkens



Programmatic interface to the ‘ECMWF’ web API services. Allows for easy downloads of ECMWF public data.


Before starting save your provided ECMWF key to your local keychain. In this example I use my R development account with the key hidden using Xs. The package does not allow you to use your key inline in scripts to limit security issues when sharing scripts on github or otherwise.

Alternatively, you can call the wf_set_key() function with only the service argument. The function will then redirect you to the correct login page where you can find your login credentials, which can be copied and pasted into the command prompt.

Before you can download any data you have to make sure to accept the terms and conditions here: https://apps.ecmwf.int/datasets/licences/general/.

ECMWF Data Requests (Public Data Sets)

To download data use the wf_request() function, together with your email and a request string syntax as documented. Instead of json formatting the function uses a simple R list for all the arguments.

The conversion from a MARS or python based query to the list format can be automated if you use the RStudio based Addin. By selecting and using Addin -> Mars to list (or ‘Python to list’) you dynamically convert queries copied from either ECMWF or CDS based services.

The download operation might take a while. A progress indicator will keep you informed on the status of your request. The download will expire after a default time out of one hour. You will be informed of where to track your job request on the ECMWF website, and provided with a download url which can be used with the wt_transfer() funtion to download the data on a later moment. Keep in mind that you can only have 3 active downloads and 20 job items queued!

If the download is successful you can visualize one layer in the retrieved stack of temperatures at 2 meters using the plotting routine below.

ECMWF mars Requests

The ecmwfr package (wf_request()) also allows to submit mars requests. Note that this requires a member state login or a commercial user account!

The ecmwfr syntax for mars requests is identical to the ones to the public ECMWF API except that one has to specify dataset = "mars". The example below downloads the 2 meter temperature forecast (parameter 167) from the 00 UTC ECMWF HRES run January 22, 2019, only 12 ahead forecast (step). A NetCDF file with a regular 0.125 x 0.125 degree horizontal resolution for a custom area in northern Europe will be downloaded (area). Note that the grid specification is required if format = "netcdf" as grib to NetCDF conversion is only able for regular longitude-latitude grids.

Listing Ancillary data

You can list ancillary data such as user information, datasets and services using the following calls.