ecmwfr
Provides easy access to the European Centre for Medium-Range Weather Forecasts web API services and Copernicus Climate Data Store from within R, matching and expanding upon the ECMWF Python tools.
https://github.com/bluegreen-labs/ecmwfr
Category: Climate Change
Sub Category: Climate Data Access and Visualization
Keywords
cds climate-data copernicus ecmwf-api ecmwf-services r-package rstats
Keywords from Contributors
geolocation soil climate ecology bird oceanography
Last synced: about 18 hours ago
JSON representation
Repository metadata
Interface to the public ECMWF API Web Services
- Host: GitHub
- URL: https://github.com/bluegreen-labs/ecmwfr
- Owner: bluegreen-labs
- License: other
- Created: 2018-11-06T04:17:38.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-04-16T10:11:22.000Z (11 days ago)
- Last Synced: 2025-04-17T21:24:05.217Z (9 days ago)
- Topics: cds, climate-data, copernicus, ecmwf-api, ecmwf-services, r-package, rstats
- Language: R
- Homepage: https://bluegreen-labs.github.io/ecmwfr/
- Size: 14.4 MB
- Stars: 113
- Watchers: 5
- Forks: 31
- Open Issues: 2
- Releases: 7
-
Metadata Files:
- Readme: README.md
- Changelog: NEWS.md
- License: LICENSE
- Codemeta: codemeta.json
README.md
ecmwfr
Programmatic interface to the two European Centre for Medium-Range
Weather Forecasts API services. The package
provides easy access to all available Data Stores from within R, matching and
expanding upon the ECMWF python tools. Support is provided for the
Climate Data Store, the
Atmosphere Data Store and the
Early Warning Data Store (from the
Copernicus Emergency Management Services).
How to cite this package
You can cite this package like this "we obtained data from the European
Centre for Medium-Range Weather Forecasts API using the ecmwf R package
(Hufkens, Stauffer, and Campitelli 2019)". Here is the full
bibliographic reference to include in your reference list (don't forget
to update the 'last accessed' date):
Hufkens, K., R. Stauffer, & E. Campitelli. (2019). ecmwfr:
Programmatic interface to the two European Centre for Medium-Range
Weather Forecasts API services. Zenodo.
https://doi.org/10.5281/zenodo.2647531.
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(remotes)){install.packages("remotes")}
remotes::install_github("bluegreen-labs/ecmwfr")
library("ecmwfr")
Vignettes are not rendered by default, if you want to include additional
documentation please use:
if(!require(remotes)){install.packages("remotes")}
remotes::install_github("bluegreen-labs/ecmwfr", build_vignettes = TRUE)
library("ecmwfr")
breaking changes (>= 2.0.0)
querying data
With the introduction of version 2.0.0 and the migration to the new API some
changes to the package were implemented which will cause breaking changes. In particular
the wf_request()
function(s) now use a default ecmwfr
user field due to the
consolidation of the API, with a single sign-on across all services and the use
of a Personal Access Token (PAT) rather than user and password credentials.
In order to migrate to version >=2.0.0 you will have to provide a new PAT using wf_set_key()
and remove the user argument from any wf_request()
call, i.e.:
# The original v1.x.x call
wf_request(
request,
user = "your_id"
)
# The new v2.x.x call
wf_request(
request
)
The requests themselves should translate mostly without intervention
and remain nested lists of parameters.
netCDF data format
In comparison with the original services the new API regresses in terms
of netCDF support. Those relying on common netCDF support such as ecosystem modellers will find this troubling. Note that both CDS and ADS have different policies and use different methods. Note that this regression in usability is not caused
by this package. Please forward any issues you have with formatting of the data
to the ECMWF using the public forum. We suggest to fall back to grib files, and convert internally if netCDF driver files are needed. Sadly, consistency for now is not, and will not be, guaranteed it seems.
Use:
Create a ECMWF account by self
registering. Once your user account has been verified you can get your API token (or key
in ecmwfr
) by visiting one of the Data Stores user profiles, for example the CDS user profile.
The API Token is a UUID and should look something like:
API: abcd1234-foo-bar-98765431-XXXXXXXXXX
This API Token gives you access to all Data Store services, including the climate atmosphere and emergency management services. This information is required to be able to retrieve data via the ecmwfr
package. Use the
ecmwfr
wf_set_key
function to store
your login information in the system keyring (see below).
In order to download the data, you will also need to accept the licence agreement on the bottom of the user profile page.
Setup
Before using the package in R
to download data you have to save your login
information. The package does not allow you to use your key inline in scripts
to limit security issues when sharing scripts on github or otherwise.
The following lines should NEVER be included in any script and run only once at setup.
# set a key to the keychain
wf_set_key(key = "abcd1234-foo-bar-98765431-XXXXXXXXXX")
# you can retrieve the key using
wf_get_key()
# the output should be the key you provided
# "abcd1234-foo-bar-98765431-XXXXXXXXXX"
# Alternatively you can input your login info with an interactive request
# if you do not put in the key directly
wf_set_key()
# 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 accept the terms and conditions in the profile
pages of your Data Store of choice.
Data Requests
To download data use the wf_request
function, and a request string syntax. The simplest way to get the requests is
to go to the Data Store website which offers an interactive interface to create
these requests e.g., for the CDS ERA-5 reanalysis data:
After formatting the request online copy the API request python code to your script.
The request should include the dataset, request and target field (if available).
Instead of json
formatting as shown in the online form the ecmwfr
package
uses a R lists for all the arguments. This makes changing variables less prone
to error, although overall we suggest not to manually create requests and use
the RStudio Addin to translate the python json
request to R as shown below.
Just select the whole query, including the dataset and target fields, and click
on the Addins > ECMWF Python to list. The original python query is listed below
so you can try this routine yourself.
# The full python query, which you can translate to an R
# list using the Addin
dataset = "reanalysis-era5-pressure-levels"
request = {
'product_type': ['reanalysis'],
'variable': ['temperature'],
'year': ['2000'],
'month': ['04'],
'day': ['04'],
'time': ['00:00'],
'pressure_level': ['850'],
'data_format': 'netcdf',
'download_format': 'unarchived',
'area': [70, -20, 60, 30]
}
This will give you a request as an annotated list. If no target file is
specified in the original request a target field will be added to the list
with a default name TMPFILE
. Replace this filename with something that matches
your preference and the specified data format. In this case the default name
was changed to era5-demo.nc
, a netcdf file. This formatted request can now be
used by the wf_request
function to query and download the
data. By default the process is verbose, and will give you plenty of feedback
on progress.
# This is an example of a request as converted from
request <- list(
dataset_short_name = "reanalysis-era5-pressure-levels",
product_type = "reanalysis",
variable = "temperature",
year = "2000",
month = "04",
day = "04",
time = "00:00",
pressure_level = "850",
data_format = "netcdf",
download_format = "unarchived",
area = c(70, -20, 60, 30),
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(
request = request, # the request
transfer = TRUE, # download the file
path = "." # store data in current working directory
)
The Data Store 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! You can check the scope of your query and if
it is out of bounds in the right hand Request Validation
panel when
formatting your original data request in the web interface.
Note: If you need to download larger
amounts of data it is suggested to split the downloads, e.g., download
the data in chunks (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.
ERA5 demo
The above request uses ERA-5 reanalysis data on pressure levels.
dataset
: downloading ERA-5 reanalysis on pressure level(s)product_type
: (deterministic) reanalysis datavariable
/pressure_level
: requesting temperature on 850 hectopascalyear
/month
/day
: April 4, 2000 (one day in this example)time
: valid at 00:00 UTC (date/time always in UTC),area
: custom subset covering northern Europeformat
: output format NetCDFtarget
: local output fileera5-demo.nc
The data set as specified above can be downloaded calling the
wf_request
function, and upon request returns the location of the
NetCDF file on your system. The file
variable can then be used directly
for further processing (note: should the download be interupted the job ID in your
download queue is returned and the job can be resumed using wf_transfer()
).
Once the retrieval has finished you should now be the owner of a NetCDF containing
the requested information located in the current working directory, called era5-demo.nc
.
We can quickly visualize this data using the terra
geospatial library using:
# Open NetCDF file and plot the data
# (trap read error on mac - if gdal netcdf support is missing)
r <- terra::rast(file)
terra::plot(r, main = "ERA-5 Reanalysis Demo (2m Temperature 850 hPa)")
maps::map("world", add = TRUE)
File and system based keychains
On linux you can opt to use a file based keyring, instead of a GUI based
keyring manager. This is helpful for headless setups such as servers.
For this option to work linux users must set an environmental option.
options(keyring_backend="file")
You will be asked to provide a password to encrypt the keyring with.
Upon the start of each session you will be asked to provide this
password, unlocking all ecmwfr
credentials for this session. Should
you ever forget the password just delete the file at:
~/.config/r-keyring/ecmwfr.keyring
and re-enter all your credentials.
Date specification
For those familiar with the old ECMWF mars syntax: CDS/ADS/CEMS does not accept
date = "2000-01-01/to/2000-12-31"
specifications. It is possible to
specify one specific date via date = "2000-01-01"
or multiple days via
date = ["2000-01-01","2000-01-02","2000-10-20"]
or
date = "YYYY-MM-DD/YYYY-MM-DD"
.
Citation
Hufkens, K., R. Stauffer, & E. Campitelli. (2019). ecmwfr: Programmatic
interface to the two European Centre for Medium-Range Weather Forecasts
API services. Zenodo. https://doi.org/10.5281/zenodo.2647531.
Acknowledgements
This project is maintained by BlueGreen Labs (BV). This project was in the past
partially supported by the Belgian Science Policy office
COBECORE project (BELSPO; grant BR/175/A3/COBECORE), a "Fonds voor
Wetenschappelijk Onderzoek" travel grant (FWO; V438318N) and the Marie
Skłodowska-Curie Action (H2020 grant 797668). Logo design elements are
taken from the FontAwesome library according to these
terms, where the globe element was
inverted and intersected.
Owner metadata
- Name: BlueGreen Labs
- Login: bluegreen-labs
- Email: [email protected]
- Kind: organization
- Description: BlueGreen open science labs & consulting, providing environmental research infrastructure and editorial solutions.
- Website: http://bluegreenlabs.org
- Location: Melsele, Belgium
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/65854203?v=4
- Repositories: 17
- Last ynced at: 2023-03-09T08:10:34.683Z
- Profile URL: https://github.com/bluegreen-labs
GitHub Events
Total
- Create event: 2
- Release event: 1
- Issues event: 15
- Watch event: 11
- Delete event: 3
- Issue comment event: 24
- Push event: 24
- Pull request event: 10
- Fork event: 1
Last Year
- Create event: 2
- Release event: 1
- Issues event: 15
- Watch event: 11
- Delete event: 3
- Issue comment event: 24
- Push event: 24
- Pull request event: 10
- Fork event: 1
Committers metadata
Last synced: 5 days ago
Total Commits: 662
Total Committers: 7
Avg Commits per committer: 94.571
Development Distribution Score (DDS): 0.15
Commits in past year: 144
Committers in past year: 2
Avg Commits per committer in past year: 72.0
Development Distribution Score (DDS) in past year: 0.035
Name | Commits | |
---|---|---|
Koen Hufkens | k****s@g****m | 563 |
Elio Campitelli | e****i@g****m | 63 |
Reto Stauffer | r****r@u****t | 28 |
Raphaël Nussbaumer | r****s@g****m | 5 |
Martin Morlot | m****t@g****m | 1 |
David LeBauer | d****r@a****u | 1 |
Darío Hereñú | m****a@g****m | 1 |
Committer domains:
- arizona.edu: 1
- uibk.ac.at: 1
Issue and Pull Request metadata
Last synced: 2 days ago
Total issues: 111
Total pull requests: 57
Average time to close issues: 3 months
Average time to close pull requests: 6 days
Total issue authors: 41
Total pull request authors: 8
Average comments per issue: 4.0
Average comments per pull request: 1.77
Merged pull request: 54
Bot issues: 0
Bot pull requests: 0
Past year issues: 25
Past year pull requests: 12
Past year average time to close issues: 7 days
Past year average time to close pull requests: 7 days
Past year issue authors: 8
Past year pull request authors: 2
Past year average comments per issue: 2.24
Past year average comments per pull request: 0.58
Past year merged pull request: 12
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- khufkens (40)
- eliocamp (18)
- Rafnuss (7)
- retostauffer (4)
- victofs (2)
- alextaf2017 (2)
- danielreispereira (2)
- Gizem-9395 (2)
- princess97 (2)
- Marc-Girondot (1)
- mpaulacaldas (1)
- ErikKusch (1)
- pedroalencar1 (1)
- jmertic (1)
- sofialafuente (1)
Top Pull Request Authors
- eliocamp (28)
- khufkens (21)
- Rafnuss (2)
- retostauffer (2)
- kant (1)
- dlebauer (1)
- martindoublem (1)
- olivroy (1)
Top Issue Labels
- bug (7)
- enhancement (5)
- wontfix (2)
- question (2)
- help wanted (1)
Top Pull Request Labels
Package metadata
- Total packages: 2
-
Total downloads:
- cran: 1,584 last-month
- Total dependent packages: 1 (may contain duplicates)
- Total dependent repositories: 12 (may contain duplicates)
- Total versions: 21
- Total maintainers: 1
proxy.golang.org: github.com/bluegreen-labs/ecmwfr
- Homepage:
- Documentation: https://pkg.go.dev/github.com/bluegreen-labs/ecmwfr#section-documentation
- Licenses: other
- Latest release: v2.0.3+incompatible (published 3 months ago)
- Last Synced: 2025-04-25T12:04:54.455Z (2 days ago)
- Versions: 7
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent packages count: 6.999%
- Average: 8.173%
- Dependent repos count: 9.346%
cran.r-project.org: ecmwfr
Interface to 'ECMWF' and 'CDS' Data Web Services
- Homepage: https://github.com/bluegreen-labs/ecmwfr
- Documentation: http://cran.r-project.org/web/packages/ecmwfr/ecmwfr.pdf
- Licenses: AGPL-3
- Latest release: 2.0.3 (published 3 months ago)
- Last Synced: 2025-04-25T12:04:54.731Z (2 days ago)
- Versions: 14
- Dependent Packages: 1
- Dependent Repositories: 12
- Downloads: 1,584 Last month
-
Rankings:
- Forks count: 3.202%
- Stargazers count: 4.116%
- Dependent repos count: 8.402%
- Average: 11.634%
- Downloads: 14.613%
- Dependent packages count: 27.838%
- Maintainers (1)
Dependencies
- R >= 3.6 depends
- R6 * imports
- curl * imports
- getPass * imports
- httr * imports
- keyring * imports
- memoise * imports
- covr * suggests
- jsonlite * suggests
- knitr * suggests
- maps * suggests
- ncdf4 * suggests
- raster * suggests
- rlang * suggests
- rmarkdown * suggests
- rstudioapi * suggests
- terra * suggests
- testthat * suggests
- actions/checkout v3 composite
- r-lib/actions/check-r-package v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
- actions/checkout v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- JamesIves/github-pages-deploy-action v4.4.1 composite
- actions/checkout v3 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
Score: 14.067350403744783