11 · barbs¶
Map.barbs draws wind-barb glyphs from two rasters (u, v) (cleopatra VectorGlyph). Barbs are large, so use a coarse grid.
Setup — inline plots and the path to the bundled Lisbon DEM.
In [1]:
Copied!
%matplotlib inline
from pathlib import Path
# Locate the bundled Lisbon DEM from the repo root (works from docs/ or the repo root).
ROOT = Path.cwd()
while not (ROOT / "examples" / "data" / "LisbonElevation.tif").exists() and ROOT != ROOT.parent:
ROOT = ROOT.parent
DEM = str(ROOT / "examples" / "data" / "LisbonElevation.tif")
from pyramids.dataset import Dataset, GeoReference
from digitalearth.static import Map
ds = Dataset.read_file(DEM)
vb = ds.resample(ds.cell_size * 20)
import numpy as np
z = np.nan_to_num(vb.read_array(band=0).astype('float32'))
dy, dx = np.gradient(z)
u = Dataset.from_array(arr=(-dx).astype('float32'), geo_ref=GeoReference(geo=vb.geotransform, epsg=vb.epsg))
v = Dataset.from_array(arr=(dy).astype('float32'), geo_ref=GeoReference(geo=vb.geotransform, epsg=vb.epsg))
%matplotlib inline
from pathlib import Path
# Locate the bundled Lisbon DEM from the repo root (works from docs/ or the repo root).
ROOT = Path.cwd()
while not (ROOT / "examples" / "data" / "LisbonElevation.tif").exists() and ROOT != ROOT.parent:
ROOT = ROOT.parent
DEM = str(ROOT / "examples" / "data" / "LisbonElevation.tif")
from pyramids.dataset import Dataset, GeoReference
from digitalearth.static import Map
ds = Dataset.read_file(DEM)
vb = ds.resample(ds.cell_size * 20)
import numpy as np
z = np.nan_to_num(vb.read_array(band=0).astype('float32'))
dy, dx = np.gradient(z)
u = Dataset.from_array(arr=(-dx).astype('float32'), geo_ref=GeoReference(geo=vb.geotransform, epsg=vb.epsg))
v = Dataset.from_array(arr=(dy).astype('float32'), geo_ref=GeoReference(geo=vb.geotransform, epsg=vb.epsg))
Render the (downhill-gradient) field as wind barbs.
In [2]:
Copied!
m = Map(crs=vb.epsg, figsize=(9, 7))
m.barbs(u, v)
m.set_title('barbs')
m.fig;
m = Map(crs=vb.epsg, figsize=(9, 7))
m.barbs(u, v)
m.set_title('barbs')
m.fig;