Vector data resampling - bilinear interpolation¶
This section introduces resampling vector data onto your plot’s coordinate reference system (CRS) with bilinear interpolation. Bilinear interpolation ensures that vector data is uniformly distributed across the map projection, preventing overcrowding and providing a consistent density of arrows or flags.
Example: Wind from Storm Ophelia (October 2017)¶
In this example, we will use sample wind data from Storm Ophelia, which impacted the UK in October 2017.
[1]:
import earthkit.data as ekd
import earthkit.plots as ekp
data = ekd.from_source("sample", "storm_ophelia_wind_850.grib").to_fieldlist()
data.ls()
[1]:
| parameter.variable | time.valid_datetime | time.base_datetime | time.step | vertical.level | vertical.level_type | ensemble.member | geography.grid_type | |
|---|---|---|---|---|---|---|---|---|
| 0 | u | 2017-10-16 | 2017-10-16 | 0 days | 850 | pressure | 0 | regular_ll |
| 1 | v | 2017-10-16 | 2017-10-16 | 0 days | 850 | pressure | 0 | regular_ll |
Resampling with Bilinear¶
To resample our vector points onto our target grid, we can use the Bilinear class from earthkit.plots.resample.
You can specify the desired number of points in x and y. The points are evenly distributed over the plot, on your plot’s coordinate reference system. If we also plot the original grid cells, you can see that the new points are regridded onto our map’s coordinate system and are not aligned with the original grid.
[2]:
from earthkit.plots.resample import Bilinear
# Create a map of the region around the UK
chart = ekp.Map(domain=[-20, 5, 40, 60])
# Plot the original grid cells of the wind U component
chart.grid_cells(data[0], alpha=0.5)
# Plot wind arrows with 40 points in x and y
chart.quiver(data, resample=Bilinear(40))
# Add map features
chart.coastlines(color="white", linewidth=2)
chart.gridlines()
# Show the plot
chart.show()
Different densities in x and y¶
You can also specify different densities for x and y with the nx and ny arguments. Let’s do that now with 50 x points and 20 y points.
[3]:
# Create a map of the region around the UK
chart = ekp.Map(domain=[-20, 5, 40, 60])
# Plot the original grid cells of the wind U component
chart.grid_cells(data[0], alpha=0.5)
# Plot wind arrows at every third x point and every second y point
chart.quiver(data, resample=Bilinear(nx=50, ny=20))
# Add map features
chart.coastlines(color="white", linewidth=2)
chart.gridlines()
# Show the plot
chart.show()
NOTE: Unlike Subsample, with Bilinear you always get the number of points requested. You can also ask for a higher density than your source data.
[4]:
# Create a map of the region around the UK
chart = ekp.Map(domain=[-20, 5, 40, 60])
# Plot the original grid cells of the wind U component
chart.grid_cells(data[0], alpha=0.5)
# Plot wind arrows with 80 points in x and y
chart.quiver(data, resample=Bilinear(80))
# Add map features
chart.coastlines(color="white", linewidth=2)
chart.gridlines()
# Show the plot
chart.show()