Try this notebook in Binder.

Retrieving netCDF data from the CDS and plotting it with Metview

18f961feac5c4754be368abfe607e866 be44ba59a8254560878fc620e8c93dfe Demonstrates how to retrieve netCDF data from the Climate Data Store (CDS) and visualise it with Metview using automatic styling and a polar stereographic projection.

[1]:
import metview as mv
import cdsapi

Retrieves ERA5 instantaneous 10 metre wind gust data in netCDF format using the CDS API (access needs to be set up first). If you do not have access to the CDS-API then initialise variable use_cds = False. A copy of the data is provided on disk.

[2]:
use_cds = False
filename = "wgust_era5.nc"
if use_cds:
    c = cdsapi.Client()
    c.retrieve("reanalysis-era5-pressure-levels",
               {
                   "variable": "instantaneous_10m_wind_gust",
                   "product_type": "reanalysis",
                   "year": "2011",
                   "month": "08",
                   "day": "01",
                   "time": "00:00",
                   "format": "netcdf"
               },
               filename)
    ncdata = mv.read(filename)
else:
    if mv.exist(filename):
        ncdata = mv.read(filename)
    else:
        ncdata = mv.gallery.load_dataset(filename)

Defines the netCDF variable to be visualised using netcdf_visualiser().

[3]:
ncvis = mv.netcdf_visualiser(
    netcdf_plot_type          = "geo_matrix",
    netcdf_data               = ncdata,
    netcdf_latitude_variable  = "latitude",
    netcdf_longitude_variable = "longitude",
    netcdf_value_variable     = "i10fg"
    )

Defines a geoview() to customise parameters like map projection and geographical area.

[4]:
geoview = mv.geoview(
    map_projection      = "polar_stereographic",
    map_area_definition = "corners",
    area                = [33,-13,49,64]    #[S,W,N,E]
    )

Sets up the contouring style with mcont(), which provides much flexibility in choosing how to display the output data. It controls features such as isolines, shading and colour schemes. Here, we use a Magics automatic styling.

[5]:
cont = mv.mcont(
    contour_automatic_setting = "style_name",
    contour_style_name        = "sh_all_f03t70_beauf",
    legend                    = "on"
    )

To plot this, we first need to tell Metview to send the plot to Jupyter.

[6]:
mv.setoutput('jupyter')

Plot the netcdf data into the customised view and contouring style.

[7]:
mv.plot(geoview, ncvis, cont)
[7]:
../_images/examples_wind_gust_nc_era5_cds_14_0.png
[ ]: