title: "Access Climate Data From the Copernicus Climate Data Store" author: "Ciaran Kelly" date: "8/13/2024" output: pdfdocument: default htmldocument: default ---

{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE)

Load necessary libraries for data manipulation and visualization

{r cars} library(ecmwfr) # Interface for the ECMWF Web API library(ncdf4) # Package for working with NetCDF data

Set up CDS API credentials

{r cars} cds.key <- "1c250f6d-50cc-42bf-b316-bd9b9aefb4f5" # API key for accessing Copernicus data wf_set_key(user = "73534", key = cds.key, service = "cds") # Function to set API key for CDS

Set up request for temperature data at 850 hPa pressure level

{r cars} request <- list( dataset_short_name = "reanalysis-era5-pressure-levels", # Dataset name product_type = "ensemble_mean", # Type of product requested format = "netcdf", # Output format of the data variable = "temperature", # Variable of interest pressure_level = "850", # Pressure level in hPa year = '1986', # Year of data month = "08", # Month of data day = '25', # Day of data time = "21:00", # Time of data in UTC # Area is specified as N, W, S, E area = c(70, -45, 35, 35), # Geographical bounding box for data grid = '0.1/0.1', # Spatial resolution of data target = "download_e5_pressure.nc" # Name of the output file )

Request data from CDS

{r cars} air2006 <- wf_request(user = "73534", request = request, transfer = TRUE, path = "~", # Path to save the downloaded file verbose = TRUE) # Print progress to console

Open the downloaded NetCDF file

{r cars} nc_data <- nc_open(air2006)