Earthkit-meteo: wind computations¶
In this notebook you will see how to:
compute the wind speed from NetCDF/Xarray and GRIB data
import earthkit.data as ekd
from earthkit.meteo import wind
import earthkit.plots as ekpXarray¶
First, we get some NetCDF data.ds = ekd.from_source("sample", "era5_tquv_pl_subarea.nc").to_xarray()
dsNext, we compute the wind speed with earthkit
sp = wind.speed(ds.u,ds.v)
spEarthkit-meteo is still work in progress and the metadata is not yet set in the resulting DataArray. We will set it manually.
sp.attrs["standard_name"] = "wind_speed"
sp.attrs["long_name"] = "wind_speed"
sp = sp.rename("ws")Finally, we plot some of the data for visual checking.
# select one level and step and plot wind field overlaid with the computed speed
u = ds.u.sel(pressure_level=700, valid_time="2016-09-26T12")
v = ds.v.sel(pressure_level=700, valid_time="2016-09-26T12")
sp1 = sp.sel(pressure_level=700, valid_time="2016-09-26T12")
chart = ekp.Map()
chart.contourf(sp1, units="m s-1", colors="Greens",
levels=list(range(5,45,5)), alpha=1)
chart.quiver(u=u, v=v, headwidth=2.5, width=0.002)
# Add map features
chart.coastlines()
chart.land()
chart.gridlines()
chart.legend()
# Show the plot
chart.show()Fieldlist¶
Fetch the same input data but this time in GRIB format and load it into a fieldlist.
fl = ekd.from_source("sample", "era5_tquv_pl_subarea.grib").to_fieldlist()
fl.head()Fieldlist based computations are experimental and limited to wind. The methods have to be imported from a dedicated submodule.
from earthkit.meteo.wind import fieldlist as wind_flTo compute the speed we need to extract the u and v components. The computations do not check if the u and v fields are aligned in terms of metadata, the user must ensure this. Luckily, our input data is properly sorted so we do not need to deal with it.
u = fl.sel({"parameter.variable": "u"})
v = fl.sel({"parameter.variable": "v"})When the speed is computed the metadata is correctly set in the results.
sp = wind_fl.speed(u, v)
sp.head()