Data HubContribute
Python & RLivestock15 min · Guide

Tropical Livestock Units from GLW4

Compute Tropical Livestock Units (TLU) by combining GLW4 species density layers with standard conversion factors, streaming directly from the Hub's Zarr store.

Data: Gridded livestock density for 2020 (GLW4)

Livestock density is published one species at a time — cattle, buffalo, sheep, goats — but many analyses want a single grazing-pressure number. The Tropical Livestock Unit (TLU) provides that: each animal counts as a fraction of a 250 kg reference animal, so species can be weighted and summed into one comparable layer.

This notebook builds a TLU/km² map from Gridded Livestock of the World v4, streaming just the data it needs — nothing is downloaded ahead of time.

python
import xarray as xr

Open the data

GLW4 lives on object storage as a Zarr cube, so xarray opens it over HTTPS and only ever reads the chunks a computation touches. Inspecting the dataset shows one density variable per species, in head/km².

python
ds = xr.open_zarr(
    "https://digital-atlas.s3.amazonaws.com/cdh/data/glw4-2020/glw4-2020.zarr"
)
python
ds
<xarray.Dataset> Size: 224MB
Dimensions:      (y: 2160, x: 4320)
Coordinates:
  * y            (y) float64 17kB 89.96 89.88 89.79 ... -89.79 -89.87 -89.96
  * x            (x) float64 35kB -180.0 -179.9 -179.8 ... 179.8 179.9 180.0
Data variables:
    buffalo      (y, x) float32 37MB dask.array<chunksize=(1080, 1080), meta=np.ndarray>
    cattle       (y, x) float32 37MB dask.array<chunksize=(1080, 1080), meta=np.ndarray>
    chicken      (y, x) float32 37MB dask.array<chunksize=(1080, 1080), meta=np.ndarray>
    goat         (y, x) float32 37MB dask.array<chunksize=(1080, 1080), meta=np.ndarray>
    pig          (y, x) float32 37MB dask.array<chunksize=(1080, 1080), meta=np.ndarray>
    sheep        (y, x) float32 37MB dask.array<chunksize=(1080, 1080), meta=np.ndarray>
    spatial_ref  int64 8B ...
Attributes:
    title:    GLW4 2020 livestock density
    source:   Gridded Livestock of the World v4 (GLW4), 2020, dasymetric

Weight species into TLU

The FAO weights express each species as a fraction of a 250 kg tropical reference animal — a head of cattle counts as 0.7 TLU, a sheep or goat as 0.1. Multiplying each species layer by its weight and summing collapses the cube into a single TLU/km² surface.

python
# Tropical Livestock Unit weights
# head/km² × weight = TLU/km².
TLU_RUMINANT = {
    "cattle": 0.7,
    "buffalo": 0.7,
    "sheep": 0.1,
    "goat": 0.1,
}
python
layers = [
    w * ds[sp].fillna(0) for sp, w in TLU_RUMINANT.items()
]
da = (
    xr.concat(layers, dim="species")
    .sum("species")
    .rename("TLU")
)
da.attrs["units"] = "TLU/km2"
python
da
<xarray.DataArray 'TLU' (y: 2160, x: 4320)> Size: 37MB
dask.array<sum-aggregate, shape=(2160, 4320), dtype=float32, chunksize=(1080, 1080), chunktype=numpy.ndarray>
Coordinates:
  * y        (y) float64 17kB 89.96 89.88 89.79 89.71 ... -89.79 -89.87 -89.96
  * x        (x) float64 35kB -180.0 -179.9 -179.8 -179.7 ... 179.8 179.9 180.0
Attributes:
    long_name:               Cattle density
    units:                   TLU/km2
    source_url:              https://storage.googleapis.com/fao-gismgr-glw4-2...
    spatial:dimensions:      ['y', 'x']
    spatial:bbox:            [-180.0, -89.99999999999994, 179.99999999999983,...
    spatial:transform_type:  affine
    spatial:transform:       [0.0833333333333333, 0.0, -180.0, 0.0, -0.083333...
    spatial:shape:           [2160, 4320]
    spatial:registration:    pixel
    proj:code:               EPSG:4326
    zarr_conventions:        [{'uuid': '689b58e2-cf7b-45e0-9fff-9cfc0883d6b4'...

Subset and plot a region

Everything so far is lazy — no pixels have moved yet. Slicing before plotting means only the chunks inside the window are downloaded: here a roughly 8°×10° box over Kenya and northern Tanzania. .plot() gives a quick look; the same array is ready for zonal statistics or export.

python
regional_tlu = da.sel(
    y=slice(5.0, -5.2), x=slice(34.0, 42.0)
)
python
regional_tlu.plot()

Cell output

Where to go next

Change the slice to your own region — the lazy reads mean any window costs only its own chunks. Per-species metadata, licensing, and the citation live on the GLW4 record page, and the weights dictionary is the place to add camels or other species if your context needs them.