Download CDS ERA5 data using R

Users can download CDS data using the ecmwfr package in R with “cds” as the "service" although it is not supported by C3S. In the examples below, "KEY" and "UID" are your CDS API key and UID respectively.

Please have a look at the following example to download ERA5 2m temperature for a selected area in netCDF format: 

library(ecmwfr)
 
cds.key <- "Insert_your_CDS_API_KEY_here"
wf_set_key(user = "Insert_your_CDS_UID_here", key = cds.key, service = "cds")
 
request <- list(
dataset_short_name = "reanalysis-era5-single-levels",
product_type   = "reanalysis",
format = "netcdf",
variable = "2m_temperature",
year = "2016",
month = "08",
day = "16",
time = c("00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00"),
# area is specified as N, W, S, E
area = c(50, -20, 30, 20),
target = "download_e5_single.nc"
)
 
file <- wf_request(user = "Insert_your_CDS_UID_here",
                     request = request,
                     transfer = TRUE,
                     path = "~",
                     verbose = TRUE)

This would return the data to a file called download_e5_single.nc.

The code below retrieves ERA5pressure level temperature data at 850hpa for a selected area in netCDF format:

library(ecmwfr)
 
cds.key <- "Insert_your_CDS_API_KEY_here"
wf_set_key(user = "Insert_your_CDS_UID_here", key = cds.key, service = "cds")
 
request <- list(
dataset_short_name = "reanalysis-era5-pressure-levels",
product_type   = "reanalysis",
format = "netcdf",
variable = "temperature",
pressure_level = "850"
year = "2016",
month = "08",
day = "16",
time = c("00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00"),
# area is specified as N, W, S, E
area = c(50, -20, 30, 20),
target = "download_e5_pressure.nc"
)
 
file <- wf_request(user = "Insert_your_CDS_UID_here",
                     request = request,
                     transfer = TRUE,
                     path = "~",
                     verbose = TRUE)

Thanks. This really helps. Just wondering, is there a way to pass the 'area' argument (to subset the data by bounding box) for those datasets that are not on a regular lon lat grid. Example UERRA dataset which is on a Lambert Conformal Conic grid. For such datasets, the 'Geographical area' option does not appear when selecting/filtering the variable. I see there is a related question here (though this question in fact is for another dataset that is already on a regular lon lat grid, yet not available to subset the bounding box). I am not sure why it would be difficult to transform the user defined regular lon lat coordinates to the dataset's native projection on the back-end, i.e. the Show API request should be able to do this in the background and display the 'area' coordinates for subsetting.

Hi Malcolm,

No, at this time I don't think it is possible to perform an area subset in the way you describe using the CDS API, but it is a good suggestion for a future development,

Thanks,

Kevin 

Hi Kevin,

Thanks again! 

Rgds

Malcolm

Hi Kevin, thank you, that helped a lot. Do you know if we ca use “ecmwfr” R package to download cmip6 projections ?
Best,