Coder Social home page Coder Social logo

gmanatole / api-era5 Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 126 KB

Download ERA5 data from ECMWF's CDS (climate data store). ERA5 is the fifth generation ECMWF reanalysis for the global climate and weather for the past 8 decades. Data is available from 1940 onwards.

Python 2.53% Jupyter Notebook 97.47%
api ecmwf ecmwf-api ecmwf-data ecmwf-reanalysis-data era

api-era5's Introduction

READ ME FILE FOR THE API CODES USED TO DOWNLOAD CDS DATA

This code has been implemented in the OSmOSE project. 

I - Getting Started

These codes are used to download data from the CDS (Climate Data Store).
More precisely it can download any hourly single level data since 1950 anywhere in the world.
A list of the variables that can be downloaded is accessible here : https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels?tab=overview
So far, the code has been prepared for surface temperature, u10 and v10 wind speed, total precipitation and wave direction and period.

Adding variables :
Other variables can be added by looking for their correct names in : 
https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels?tab=form
After checking the desired variables, click on 'Show API request' and copy the variable list and paste it as the data list in the jupyter notebook.

Getting access to the CDS data requires an account. You can create one here :
https://cds.climate.copernicus.eu/user/login
After your account is created, clicking on the same link above gives you access to the UDI and key that you need to enter in the jupyter notebook. You can also find this information by clicking on your name in the upper right corner.

Make sure all the packages are installed, you can install them using conda in a terminal.


II - Using the Jupyter Notebook

This code is meant to be used locally, not on datamor for example. Both the jupyter notebook and the python script need to be in the same directory. 

The area from where to download data is defined by a 'square' whose borders are the cardinal boundaries.

The filename you define is only attributed to the raw data file downloaded from the cds. Additionnal formatted files are also created.
All file will be created in your home directory, in a subdirectory called 'api'.

III - Using the downloaded data

The data you have downloaded is three dimensional (space+time). Therefore, it is stored as a 3D numpy array you can read using np.read().
Each individual variable is saved in its own array.
All arrays have the same dimensions and shapes.
One other arrays is saved containing : 'timestamps', 'timestamps_epoch', 'latitude', 'longitude'
To read this stamps.npz array enter the following line : stamps = np.load('stamps.npz')
The line stamps.files will return the arrays stored inside the stamps files (ie. timestamps, timestamps_epoch, latitude, longitude).
To access a desired array, enter for exemple the line stamps['latitude'] or stamps['timestamps_epoch']
timestamps saves time data as a datetime, while timestamps_epoch saves time as an epoch time or the time in seconds since January 1, 1970, 00:00:00 at UTC.
Be advised that latitude data are stored in decreasing order, and longitude data stored in increasing order.
For chosen i,j,k values corresponding to time, latitude and longitude you will have  :
tp[i,j,k] = 3.2 (m/h)
The entire tp array will look like this :
> array([[[8.67361738e-19, 8.67361738e-19, 8.67361738e-19, ...,
         1.02081993e-06, 1.02081993e-06, 5.68742531e-06],
        [8.67361738e-19, 8.67361738e-19, 8.67361738e-19, ...,
         8.67361738e-19, 8.67361738e-19, 4.81243680e-06],
        [8.67361738e-19, 8.67361738e-19, 8.67361738e-19, ...,
         8.67361738e-19, 8.67361738e-19, 1.02081993e-06],
         ...
While stamps will be in the following format :
> timestamps = array([datetime.datetime(2019, 10, 1, 0, 0), ... , datetime.datetime(2019, 10, 8, 2, 0) ])
> latitude = array([ -41., -41.25, ... , -50.25, -50.5 ], dtype=float32)
> longitude = array([ 3.25, 3.5, ... , 11., 11.25 ], dtype=float32)

## Code to plot 2D image of one variable (here u10) :

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np
import matplotlib.pyplot as plt
import os
import sys

variable_name= 'u10'

if not os.path.exists(os.path.join(path,'api',variable_name+'_'+filename+'.npy')):
print('no ERA data with this variable')
sys.exit()

var1 = np.load(os.path.join(path,'api',variable_name+'_'+filename+'.npy'))
stamps = np.load(os.path.join(path,'api','stamps.npz'), allow_pickle=True)

mat_lat, mat_lon = np.meshgrid(stamps['latitude'],stamps['longitude'])

fig = plt.figure(figsize=(6,5))
if var1.shape[1:]==(1,1):
plt.plot(stamps['timestamps'],var1[:,0,0])
else:
plt.pcolormesh(mat_lon,mat_lat, var1[0,:,:].T, cmap=cm.jet)
plt.title('tp variable at time '+str(stamps['timestamps'][0]))
plt.colorbar()
plt.show()

api-era5's People

Contributors

gmanatole avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.