Skip to content
Interface to the public ECMWF API Web Services
Branch: master
Clone or download
Latest commit 6bc15de Apr 22, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R testing addin modules Apr 22, 2019
docs update docs Apr 22, 2019
inst
man adjusting vignettes and removing modify function Apr 19, 2019
tests testing addin modules Apr 22, 2019
vignettes rename request Apr 22, 2019
.Rbuildignore server check timeout fix Apr 21, 2019
.gitignore docs + unit checks for server uptime Feb 1, 2019
.travis.yml update key Apr 19, 2019
CONDUCT.md first commit Nov 6, 2018
DESCRIPTION server check timeout fix Apr 21, 2019
LICENSE
NAMESPACE adjusting vignettes and removing modify function Apr 19, 2019
NEWS.md
README.md update docs Apr 22, 2019
contact.md Devel Update Jan 20, 2019
cran-comments.md docs Apr 19, 2019
ecmwfr-logo.ai logo Mar 14, 2019
ecmwfr-logo.png
ecmwfr.Rproj first commit Nov 6, 2018

README.md

ecmwfr

Build Status codecov CRAN_Status_Badge DOI Buy Me A Coffee

Programmatic interface to the European Centre for Medium-Range Weather Forecasts 'ECMWF' web API services and Copernicus Climate Data Store or 'CDS'.

Installation

stable release

To install the current stable release use a CRAN repository:

install.packages("ecmwfr")
library("ecmwfr")

development release

To install the development releases of the package run the following commands:

if(!require(devtools)){install.packages("devtools")}
devtools::install_github("khufkens/ecmwfr")
library("ecmwfr")

Vignettes are not rendered by default, if you want to include additional documentation please use:

if(!require(devtools)){install.packages("devtools")}
devtools::install_github("khufkens/ecmwfr", build_vignettes = TRUE)
library("ecmwfr")

Use: ECMWF services

Create a ECMWF account by self registering and retrieving your key at https://api.ecmwf.int/v1/key/ after you log in. The key is a long series of numbers and characters (X in the example below).

{
    "url"   : "https://api.ecmwf.int/v1",
    "key"   : "XXXXXXXXXXXXXXXXXXXXXX",
    "email" : "john.smith@example.com"
}

Setup

Before starting save the provided key to your local keychain. The package does not allow you to use your key inline in scripts to limit security issues when sharing scripts on github or otherwise.

# set a key to the keychain
wf_set_key(email = "john.smith@example.com",
           key = "XXXXXXXXXXXXXXXXXXXXXX",
           service = "webapi")

# you can retrieve the key using
wf_get_key(email = "john.smith@example.com")

# the output should be the key you provided
# "XXXXXXXXXXXXXXXXXXXXXX"

# Alternatively you can input your login info with an interactive request
wf_set_key(service = "webapi")

# you will get a command line request to provide the required details

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/.

Data Requests

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. Be sure to specify which service to use, in this case webapi is the correct service to request data from.

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.

# this is an example of a request
my_request <- list(stream = "oper",
                   levtype = "sfc",
                   param = "165.128/166.128/167.128",
                   dataset = "interim",
                   step = "0",
                   grid = "0.75/0.75",
                   time = "00/06/12/18",
                   date = "2014-07-01/to/2014-07-31",
                   type = "an",
                   class = "ei",
                   area = "73.5/-27/33/45",
                   format = "netcdf",
                   target = "tmp.nc")

# an example download using fw_request()
# using the above request list()
# 
# data will be transferred to disk
# and saved in your home directory (~)
# set by the path argument

wf_request(
  email = "khrdev@outlook.com",
  request = my_request,
  transfer = TRUE,
  path = "~")

This operation might take a while. A progress indicator will keep you informed on the status of your request. Keep in mind that all data downloaded will be buffered in memory limiting the downloads to ~6GB on low end systems. You can track ongoing jobs at in the joblist at: https://apps.ecmwf.int/webmars/joblist/.

Use: Copernicus Climate Data Store (CDS)

Create a free CDS user account by self registering. Once your user account has been verified you can get your personal user ID and key by visiting the user profile. This information is required to be able to retrieve data via the ecmwfr package. Use the ecmwf wf_set_key function to store your login information in the system keyring (see below). Be aware, that unlike the API key for the ECMWF API your user does not correspond to the email address you use for the CDS login.

UID: 1234
API key: abcd1234-foo-bar-98765431-XXXXXXXXXX

Setup

If you preferr to use your local keychain (rather than using the .cdsapirc file) you have to save your login information first. The package does not allow you to use your key inline in scripts to limit security issues when sharing scripts on github or otherwise.

# set a key to the keychain
wf_set_key(user = "1234",
            key = "abcd1234-foo-bar-98765431-XXXXXXXXXX",
            service = "cds")

# you can retrieve the key using
wf_get_key(user = "1234")

# the output should be the key you provided
# "abcd1234-foo-bar-98765431-XXXXXXXXXX"

# Alternatively you can input your login info with an interactive request
wf_set_key(service = "cds")

# you will get a command line request to provide the required details

Before you can download any data you have to make sure to accept the terms and conditions here: Before downloading and processing data from CDS please make sure you acceppt the terms and conditions which can be found here: Copernicus Climate Data Store Disclaimer/Privacy.

Data Requests

To download data use the wf_request function, together with your user ID and a request string syntax as documented. Instead of json formatting the function uses a simple R list for all the arguments. Be sure to specify the service you want to use in your query in this case cds.

Note: the simplest way to get the requests is to go to the CDS website which offers an interactive interface to create these requests. E.g., for ERA-5 reanalysis:

# This is an example of a request for # downloading 'ERA-5' reanalysis data for
# 2000-04-04 00:00 UTC, temperature on # 850 hectopascal for an area covering #
northern Europe.
# File will be stored as "era5-demo.nc" (netcdf format).
request <- list("dataset" = "reanalysis-era5-pressure-levels",
                "product_type" = "reanalysis",
                "variable" = "temperature",
                "pressure_level" = "850",
                "year" = "2000",
                "month" = "04",
                "day" = "04",
                "time" = "00:00",
                "area" = "70/-20/00/60",
                "format" = "netcdf",
                "target" = "era5-demo.nc")


# If you have stored your user login information
# in the keyring by calling cds_set_key you can
# call:
file <- wf_request(user     = "1234",   # user ID (for authentification)
                   request  = request,  # the request
                   transfer = TRUE,     # download the file
                   path     = ".")      # store data in current working directory

The CDS services are quite fast, however, if you request a lot of variables, multiple levels, and data over several years these requests might take quite a while! Note: If you need to download larger amounts of data it is suggested to split the downloads, e.g., download the data in junks (e.g., month-by-month, or year-by-year). A progress indicator will keep you informed on the status of your request. Keep in mind that all data downloaded will be buffered in memory limiting the downloads to ~6GB on low end systems.

Acknowledgements

This project was in part supported by the Belgian Science Policy office COBECORE project (BELSPO; grant BR/175/A3/COBECORE) and a "Fonds voor Wetenschappelijk Onderzoek" travel grant (FWO; V438318N). Logo design elements are taken from the FontAwesome library according to these terms, where the globe element was inverted and intersected.

You can’t perform that action at this time.