└── README.md
/README.md:
--------------------------------------------------------------------------------
1 | # Download ERA data with python
2 |
3 | Since the ECMWF currently advice user to migrate from ERA-interim to ERA5 ([due ERA Interim is being phased out](https://apps.ecmwf.int/datasets/data/interim-full-daily/levtype=sfc/)) and also to [migrate from ECMWF Web API to CDS API](https://confluence.ecmwf.int/display/CKB/How+to+migrate+from+ECMWF+Web+API+to+CDS+API), in this tutorial I will teach you how to download ERA5 data with python using CDS API.
4 |
5 | ## Instalation
6 |
7 | The CDS API can be installed with Conda or Pip, and it is recommended to install it within a python environment.
8 |
9 | Installation using conda:
10 | ```
11 | conda config --add channels conda-forge
12 | conda install cdsapi
13 | ```
14 |
15 | Installation using pip:
16 | ```
17 | pip install cdsapi
18 | ```
19 |
20 | ## Creates an account
21 |
22 | Creates a CDS account [here](https://cds.climate.copernicus.eu/user/register).
23 |
24 | ## Install the CDS API key
25 |
26 | - You need to login to continue, login [here](https://cds.climate.copernicus.eu/user/login?destination=%2F%23!%2Fhome).
27 | - After login, click [here](https://cds.climate.copernicus.eu/user).
28 | - Scroll down in the pageweb until the API key section and copy the **UID** and **API Key** codes.
29 | - Creates .cdsapirc file
30 |
31 | **For Linux**:
32 | creates the file $HOME/.cdsapirc
33 |
34 | **For Windows**:
35 | creates the file at %USERPROFILE%\\.cdsapirc
36 |
37 | More information for windows [here](https://confluence.ecmwf.int/display/CKB/How+to+install+and+use+CDS+API+on+Windows) and [here](https://confluence.ecmwf.int/pages/viewpage.action?pageId=139068264).
38 |
39 | - Copy the next code within .cdsapirc
40 |
41 | url: https://cds.climate.copernicus.eu/api/v2
42 | key: {**uid**}:{**api-key**}
43 |
44 |
45 | For more detail see [here](https://cds.climate.copernicus.eu/api-how-to).
46 |
47 | ## Accept data licence and generate a basic CDS API script using the CDS web interface
48 | - Go to the C3S [climate data store (CDS)](https://cds.climate.copernicus.eu/#!/home)
49 | - On the top menu bar, click on **Datasets**.
50 | - On the left-hand side menu, expand **Product type** and select product type of interest (e.g. **Seasonal forecasts** to get all seasonal forecasts data listed, **Reanalysis** for ERA5 datasets)
51 | - Follow the dataset title link of interest to the full dataset record
52 | - Accept dataset licence and generate basic CDS API script
53 |
54 | In my case, I selected **Reanalysis** in **Product type**, and I selected
55 | **ERA5 hourly data on pressure levels from 1979 to present** as a dataset. Then, selected the variables that I want to download and I did click on **Show API request** to see the python script.
56 |
57 |
58 | ```python
59 | import cdsapi
60 |
61 | c = cdsapi.Client()
62 |
63 | c.retrieve(
64 | 'reanalysis-era5-pressure-levels',
65 | {
66 | 'product_type': 'reanalysis',
67 | 'format': 'netcdf',
68 | 'variable': [
69 | 'geopotential', 'potential_vorticity', 'temperature',
70 | 'u_component_of_wind', 'v_component_of_wind',
71 | ],
72 | 'pressure_level': [
73 | '100', '125', '150',
74 | '175', '200', '225',
75 | '250', '300', '350',
76 | '400', '450', '500',
77 | '550', '600', '650',
78 | '700', '750', '775',
79 | '800', '825', '850',
80 | '875', '900', '925',
81 | '950', '975', '1000',
82 | ],
83 | 'year': '1979',
84 | 'month': '01',
85 | 'day': [
86 | '01', '02', '03',
87 | '04', '05', '06',
88 | '07', '08', '09',
89 | '10', '11', '12',
90 | '13', '14', '15',
91 | '16', '17', '18',
92 | '19', '20', '21',
93 | '22', '23', '24',
94 | '25', '26', '27',
95 | '28', '29', '30',
96 | '31',
97 | ],
98 | 'time': [
99 | '00:00', '01:00', '02:00',
100 | '03:00', '04:00', '05:00',
101 | '06:00', '07:00', '08:00',
102 | '09:00', '10:00', '11:00',
103 | '12:00', '13:00', '14:00',
104 | '15:00', '16:00', '17:00',
105 | '18:00', '19:00', '20:00',
106 | '21:00', '22:00', '23:00',
107 | ],
108 | 'area': [
109 | 10, -120, -60,
110 | -20,
111 | ],
112 | },
113 | 'download.nc')
114 | ```
115 |
116 | Finally, I did run the python code from python environment where was installed CDS API, and I downloaded the ERA5 data.
117 |
--------------------------------------------------------------------------------