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-swh-probability
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.
This product takes in input one of these 4 parameters:
These are already calculated probabilities, so no need to download all ensemble members.
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)
parameters = ['swhg2', 'swhg4', 'swhg6', 'swhg8']
filename = 'medium-swh-probability.grib'
filename
'medium-swh-probability.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=48,
stream="waef",
type='ep',
levtype="sfc",
param=parameters,
target=filename
)
20241223000000-240h-waef-ep.grib2: 0%| | 0.00/759k [00:00<?, ?B/s]
<ecmwf.opendata.client.Result at 0x10da64c50>
Now we can use ecmwf.data to read the file.
data = mv.read(filename)
The describe() function will give us the overview of the dataset.
data.describe()
parameter | typeOfLevel | level | date | time | step | number | paramId | class | stream | type | experimentVersionNumber |
---|---|---|---|---|---|---|---|---|---|---|---|
swhg2 | meanSea | 0 | 20241223 | 0 | 48 | None | 131074 | od | waef | ep | 0001 |
swhg4 | meanSea | 0 | 20241223 | 0 | 48 | None | 131075 | od | waef | ep | 0001 |
swhg6 | meanSea | 0 | 20241223 | 0 | 48 | None | 131076 | od | waef | ep | 0001 |
swhg8 | meanSea | 0 | 20241223 | 0 | 48 | None | 131077 | od | waef | ep | 0001 |
And an overview of one parameter, where we can see more information, such as units or type of level.
data.describe('swhg4')
shortName | swhg4 |
---|---|
name | Significant wave height of at least 4 m |
paramId | 131075 |
units | % |
typeOfLevel | meanSea |
level | 0 |
date | 20241223 |
time | 0 |
step | 48 |
number | None |
class | od |
stream | waef |
type | ep |
experimentVersionNumber | 0001 |
We can use ls() function to list all the fields in the file we downloaded.
data.ls()
centre | shortName | typeOfLevel | level | dataDate | dataTime | stepRange | dataType | number | gridType | |
---|---|---|---|---|---|---|---|---|---|---|
Message | ||||||||||
0 | ecmf | swhg4 | meanSea | 0 | 20241223 | 0 | 48 | ep | None | regular_ll |
1 | ecmf | swhg6 | meanSea | 0 | 20241223 | 0 | 48 | ep | None | regular_ll |
2 | ecmf | swhg2 | meanSea | 0 | 20241223 | 0 | 48 | ep | None | regular_ll |
3 | ecmf | swhg8 | meanSea | 0 | 20241223 | 0 | 48 | ep | None | regular_ll |
The grib file contains all the parameters, and we will use the select() function to filter what we need.
Feel free to use describe() to inspect the other filtered fields.
swhg4 = data.select(shortName = 'swhg4')
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
swhg4_shade = mv.mcont(legend= "on",
contour_automatics_settings = "style_name",
contour_style_name = "sh_blup_f0t100lst")
title = mv.mtext(
text_lines=["Probabilities: significant wave height > 4 m",
"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, swhg4, swhg4_shade, title, ecmwf_text)
To generate the png file you can run the following cell.
png = mv.png_output(
output_name = "medium-swh-probability", # specify relative or full path
output_title = "medium-swh-probability", # title used by a viewer
output_width = 1000, # set width in pixels
)
mv.setoutput(png)
mv.plot(view, swhg4, swhg4_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.