Skip to content

Repository to download, process, and visualize local climate data from ERA5

License

Notifications You must be signed in to change notification settings

RuthDD/ERA5_extraction_and_visualization

Repository files navigation

Local climate data extraction and visualization

Description

This repository shows how to request, download, process, and visualize local climate data from ERA5 database, using two localities at Catalonia (NE Spain) as an example.

Repository structure

I. The first section shows how to make a data request in Copernicus website, using the python code that the website creates for you.

II. The second part shows how to read the .nc files downloaded and extract data for points/locations using R.

III. The last section shows how to plot climate data using climatographs in R.

Steps for ERA5 data request (using the CDS API)

The following steps summarize how to make the ERA5 data request (for a detailed explanation see this video).

  1. Register in Copernicus website to obtain access to the Climate Data Store (CDS).

  2. Create a local file with your user information:

  • Open a text editor file and put the following lines:

    url: https://cds.climate.copernicus.eu/api/v2
    key: userID:api-key

    You can find the userID and api-key at the end of the page by clicking on your user-name on the Copernicus website.

  • Rename the created file to ".cdsapirc." (for Windows: the file must be in C:\Users'your_user')

  1. Go to the Copernicus website and select the data of interest:
  • Select the search tab and search for the data you want to download (ERA5 in this example).

  • Select the specific data set (e.g. 'ERA5-Land hourly data from 1950 to present').

  • In the Download data tab, select the data you want to download.

    • For this example I selected 2m temperature data from the Variable 'Temperature', and Total precipitation from the variable 'Wind, Pressure and Precipitation'.

    • I also specified years from 2015 to 2020, all months and days, and time from 11 h to 13 h for the sub-region '43, 0, 41, 3'.

  • Click on 'Show API request' buttom at the end of the page, and copy the code.

  1. Create a python file and run the request.

This step requires that you have python installed on your computer (follow this steps to install it via Conda).

  • Open the Anaconda Navigator and then a Jupyter Notebook (there are different ways to do this step, see this example)

  • Add this code at the beginning of the jupyter notebook:

    conda install -c conda-forge cdsapi
  • Paste the code from the API request in the jupyter notebook and run the notebook.

If your data request includes several years and/or several variables, you could consider making one request per year/variable. The file ERA5download_years.ipynb shows how to modify the code from the API request to make a request by year and to print the status of the request.

Data processing in R

The file ERA5_extraction.R shows how to process the downloaded .nc files using R. The code include the following procedure:

  • Read .nc files.

  • Apply the brick_extract() function to extract data from .nc files and create a data frame by site.

  • Save the data in a .rds file by site.

    • In case of multiple .nc files (by year/variable), the data will be saved for all years together per site.

Data visualization

In order to describe each location`s climate data I made a Climatograph by site (see the vignette Climatograph).

About

Repository to download, process, and visualize local climate data from ERA5

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages