This notebook will provide you guidance how to explore and plot ECMWF open dataset to produce the map from the ECMWF open charts web product.
The original product can be found on this link: https://charts.ecmwf.int/products/medium-t500-mean-spread
The full list of available Open data products can be found here, and more information can be found in the User documentation.
Access to ECMWF Open data is governed by the Creative Commons CC-BY-4.0 licence and associated Terms of Use.
In applying this licence, ECMWF does not waive the privileges and immunities granted to it by virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction
To find out how to obtain the access to the full forecast dataset at higher resolution please visit our Access page.
In this example, we will use:
First we need to install them in the current Jupyter kernel:
#!pip install ecmwf-opendata metview metview-python
import metview as mv
from ecmwf.opendata import Client
client = Client("ecmwf", beta=True)
For the geopotential height at 500 hPa, ensemble mean and spread are available for download.
Ensemble mean and ensemble spread have different type in the request.
One data request can have only one type, so we need to have two requests to download this datasets.
parameters = ['gh']
em_filename = 'medium-t500-mean-spread_em.grib'
es_filename = 'medium-t500-mean-spread_es.grib'
Setting date to 0 will download today's data.
Removing date and time altogether from the request will download the latest data.
Try commenting out date and time to download latest forecast!
client.retrieve(
date=-1,
time=0,
step=144,
stream="enfo",
type="em",
levtype="pl",
levelist=[500],
param=parameters,
target=em_filename
)
20250107000000-240h-enfo-ep.grib2: 0%| | 0.00/447k [00:00<?, ?B/s]
<ecmwf.opendata.client.Result at 0x18080a3d0>
client.retrieve(
date=-1,
time=0,
step=144,
stream="enfo",
type="es",
levtype="pl",
levelist=[500],
param=parameters,
target=es_filename
)
20250107000000-240h-enfo-ep.grib2: 0%| | 0.00/458k [00:00<?, ?B/s]
<ecmwf.opendata.client.Result at 0x180de1290>
Now we can use ecmwf.data to read the file.
gh_em = mv.read(em_filename)
gh_es = mv.read(es_filename)
The describe() function will give us the overview of the dataset.
gh_em.describe('gh')
shortName | gh |
---|---|
name | Geopotential height |
paramId | 156 |
units | gpm |
typeOfLevel | isobaricInhPa |
level | 500 |
date | 20250107 |
time | 0 |
step | 144 |
number | None |
class | od |
stream | enfo |
type | em |
experimentVersionNumber | 0001 |
gh_es.describe()
parameter | typeOfLevel | level | date | time | step | number | paramId | class | stream | type | experimentVersionNumber |
---|---|---|---|---|---|---|---|---|---|---|---|
gh | isobaricInhPa | 500 | 20250107 | 0 | 144 | None | 156 | od | enfo | es | 0001 |
We can use ls() function to list all the fields in the file we downloaded.
gh_es.ls()
centre | shortName | typeOfLevel | level | dataDate | dataTime | stepRange | dataType | number | gridType | |
---|---|---|---|---|---|---|---|---|---|---|
Message | ||||||||||
0 | ecmf | gh | isobaricInhPa | 500 | 20250107 | 0 | 144 | es | None | regular_ll |
Geopotential height has units gpm (geopotential meters), but on the ECMWF Open charts it is plotted in geopotential decameters. To reproduce the plot we need to divide by 10.
gh_em /= 10
gh_es = gh_es/10
And finally, we can plot the data on the map.
# define coastlines
coast = mv.mcoast(
map_coastline_colour="charcoal",
map_coastline_resolution="medium",
map_coastline_land_shade="on",
map_coastline_land_shade_colour="cream",
map_coastline_sea_shade="off",
map_boundaries="on",
map_boundaries_colour= "charcoal",
map_boundaries_thickness = 1,
map_disputed_boundaries = "off",
map_grid_colour="tan",
map_label_height=0.35,
)
# define view
view = mv.geoview(
area_mode="name",
area_name="europe",
coastlines=coast
)
#define styles
gh_es_shade = mv.mcont(legend= "on",
contour_automatics_settings = "style_name",
contour_style_name = "sh_blu_f02t50")
gh_em_shade = mv.mcont(legend= "on",
contour_automatics_settings = "style_name",
contour_style_name = "ct_red_i5_t2")
title = mv.mtext(
text_lines=["Ensemble mean and spread for 300 hPa geopotential",
"START TIME: <grib_info key='base-date' format='%a %d %B %Y %H'/> ",
"VALID TIME: <grib_info key='valid-date' format='%a %d %B %Y %H'/>, STEP: <grib_info key='step' />"],
text_font_size=0.4,
text_colour = 'charcoal')
ecmwf_text = mv.mtext(
text_lines = ["© European Centre for Medium-Range Weather Forecasts (ECMWF)",
"Source: www.ecmwf.int Licence: CC-BY-4.0 and ECMWF Terms of Use",
"https://apps.ecmwf.int/datasets/licences/general/"],
text_justification = 'center',
text_font_size = 0.3,
text_mode = "positional",
text_box_x_position = 6.,
text_box_y_position = -0.2,
text_box_x_length = 8,
text_box_y_length = 2,
text_colour = 'charcoal')
# generate plot
mv.setoutput('jupyter', plot_widget=False)
mv.plot(view, gh_es, gh_es_shade, gh_em, gh_em_shade, title, ecmwf_text)
To generate the png file you can run the following cell.
png = mv.png_output(
output_name = "medium-t500-mean-spread", # specify relative or full path
output_title = "medium-t500-mean-spread", # title used by a viewer
output_width = 1000, # set width in pixels
)
mv.setoutput(png)
mv.plot(view, gh_es, gh_es_shade, gh_em, gh_em_shade, title, ecmwf_text)
Note that plot produced using open data dataset will slightly differ from one from Open Charts. This is due to different resolution of the data.
Open data is on 0.25x0.25 resolution, while high resolution data is 0.1x0.1 grid.