Meteorology 101: How To Download and Plot Meteorological Data from ERA5
Well, Hello Friends!
My name is Dwikita Ichsana, i am recent graduate from Bandung Institute of Technology majoring in Meteorology. This is my first post on medium explaining Meteorology. In this chapter, i will share with you Meteorology 101: How To Download and Plot Meteorological Data from ERA5!
DOWNLOAD THE DATA
According to type of the data, there are observation data that coming from measurement like weather station or vertical profiler (Radiosonde, SODAR, etc), and reanalysis data that combines model data with observation from across the world into a globally complete and consistent dataset using the law of physics (ERA5 Overview). One of the reanalysis data available on the internet is ERA5. ERA5 or ECMWF Reanalysis v5 is the reanalysis data that produced by ECMWF.
To access ERA5 data you can open this link https://cds.climate.copernicus.eu/#!/home, then go to Dataset on menu bar and search ERA5. There are two types of ERA5 data according to vertical and temporal resolution; on single or pressure level, and hourly or monthly average.
For example, let’s download some data from hourly average on single level. Oh, i almost forgot, to download the data you have to register first, hehe.
For the datetime i choose April 1st, 2023 for 24 hours. Then, for the geographical area, i choose Sub-region Extraction to get region that i wanted. In this case, i choose Indonesia region with coordinat 15N 15S 90W 150E. For format i choose NetCDF (experimental) because the data will be processed in python. For those of you who usually used Fortran you can choose GRIB format.
PLOT THE DATA
Then, how to plot from the data we have downloaded?
Let’s open our jupyter notebook!
First thing first, this is the library that you have to declared.
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import xarray as xr
from mpl_toolkits.basemap import Basemap
For this example i use Basemap to load the map (to be honest it is not easy to install the Basemap on python, error occurs frequently during installation :( ). You can also use Cartopy to load the map (see the documentation about Basemap and Cartopy here).
Next, let’s open the dataset (i renamed the dataset after downloading to ‘ERA5’).
data = xr.open_dataset('ERA5.nc')
data
The ‘data’ give us the information about dimensions, coordinate, variables, and attributes. From the overview ERA5 we know that it has a horizontal resolution of 0.25 x 0.25 degrees.
Now, to load the coordinates, let’s define latitude and longitude coordinates as ‘lat’ and ‘lon’.
lat = data.latitude
lon = data.longitude
Remember the variables that we have: 10m u-v component of wind, 2m dewpoint temperature, 2m temperature, and surface pressure right? Now, for the example, let’s plot the 2m temperature!
temp_2m = data.t2m[1,:,:]
Let’s define ‘temp_2m’ as t2m (2m temperature) variable that we want to plot. As we know from data information, the variables have 3 dimensional shape: time, latitude, longitude. Since we want to display all of Indonesia, let’s selected all latitude and longitude data denoted by a colon ‘:’.
So, how about the time? first of all we cannot include all the values of the variables to be plotted like coordinates dimensionional because the input of the data must be 2D (you can try the error by selected all time data like coordinates variable). The thing that we can do is choose ‘one’ of the time, either a certain time or maybe an average time like 3 hours or 24 hours average etc. For example, i choose time = 1 or at 01 UTC.
Next, let’s load the map by define ‘m’ as Basemap.
m = Basemap(projection='cyl', llcrnrlon=90, llcrnrlat=-15, urcrnrlon=150, urcrnrlat=15, resolution='i')
m.drawcoastlines(1)
m.drawcountries()
parallels = np.arange(-15,15+0.25,5)
m.drawparallels(parallels, labels=[1,0,0,0], linewidth=0.5)
meridians = np.arange(90,150+0.25,10)
m.drawmeridians(meridians, labels=[0,0,0,1], linewidth=0.5)
For the map projection that I use is Cylindrical. Next to ‘projection’, there are settings for the coordinates to be drawn and resolution for the map (for more information you can read tutorial basemap here). Next, we will draw and label the parallels and meridians of the map. Parallels and Meridians aim to describe how large a grid you want to draw (read the documentation here).
Here the visualization!
cf = plt.contourf(lon, lat, temp_2m, cmap='jet')
cb = plt.colorbar(cf, fraction=0.0235, pad=0.03)
cb.set_label(' \u00b0K', fontsize=15, rotation=0)
plt.show()
Contourf is used to visualize the temperature spatially so that information can be obtained about the temperature in each region in Indonesia. If you want to display a certain region by focusing on it, you can select the specific coordinates by adding the array range in ‘lon’ and ‘lat’ variables, and adjust also it on ‘temp_2m’ variable.
Note that the temperature is in Kelvin scale. You can convert to Celcius scale by subtracting 273.15 in ‘temp_2m’ (temp_2m-273.15). You can also modify the colormap in ‘cmap’ variable (list colormap here) and change the range of color bar.
I think that’s it. In general, you can try to plot another meteorology variable in a similiar way. If you have a question you can ask here in the comment section or through my LinkedIn here. You can access my code and ERA5 data via my Github here. Hopefully this tutorial useful for you!
Thank’s for reading!