True-colour approach 5 — a daily MODIS time-lapse of the middle-Danube corridor¶
Sentinel-2/Landsat resolve a single reach; to watch a whole corridor dry out day by day you need a
daily sensor. MODIS (MOD09GA, ~500 m, daily) is too coarse for channel width but perfect for a
smooth basin-scale true-colour movie — the land browning and the big rivers/reservoirs standing out
across the drought. We animate the middle-Danube corridor through summer 2026.
Needs
GEE_SERVICE_ACCOUNT/GEE_SERVICE_KEYandpyramids-core[viz].
Setup¶
pyramids reads and plots the GeoTIFFs (Dataset / DatasetCollection); earthlens provides the
EarthLens entry point. Earth Engine credentials come from a repo-root .env.
import os
import warnings
from pathlib import Path
import digitalearth as de
import matplotlib.pyplot as plt
from IPython.display import Image, display
from loguru import logger
from pyramids.dataset import DatasetCollection
from earthlens.core import EarthLens
warnings.filterwarnings("ignore")
logger.remove()
plt.rcParams["figure.dpi"] = 80
from dotenv import find_dotenv, load_dotenv
load_dotenv(find_dotenv(usecwd=True))
SERVICE_ACCOUNT = os.environ["GEE_SERVICE_ACCOUNT"]
SERVICE_KEY = os.environ["GEE_SERVICE_KEY"]
The corridor and the window¶
A wide box over the middle Danube (Hungary–Serbia) and a daily MODIS true-colour frame across the
drought. MODIS bands sur_refl_b01/b04/b03 are red/green/blue.
CORRIDOR = {"lat_lim": [44.0, 48.5], "lon_lim": [16.0, 22.0]}
MODIS = "MODIS/061/MOD09GA"
# Satellite granules are big, so they are cached off the system drive. Override with
# EARTHLENS_CACHE if your cache lives elsewhere.
OUT = (
Path(os.environ.get("EARTHLENS_CACHE", "D:/earthlens-cache")) / "tc5_modis_corridor"
)
raw = OUT / "daily"
raw.mkdir(parents=True, exist_ok=True)
Pull one daily true-colour frame per day (cached)¶
One daily MODIS true-colour GeoTIFF per day over the corridor, mid-June to mid-July 2026 (the peak of the drought). Cached, so re-runs skip the pulls.
cached = sorted(raw.glob("*.tif"))
if cached:
frames = cached
else:
job = EarthLens(
data_source="gee",
dataset=MODIS,
variables=["sur_refl_b01", "sur_refl_b04", "sur_refl_b03"],
start="2026-06-15",
end="2026-07-15",
temporal_resolution="daily",
scale=2000.0,
path=raw,
export_via="url",
# engine="ee": the default engine="auto" prefers the pyramids-eo EEDAI
# reader whenever it is installed (the dev group installs it), and that
# reader cannot read MODIS' sinusoidal CRS -- GDAL leaves the projection
# empty and the read dies on "OGR Error: Corrupt data". Pinned to Earth
# Engine's own getDownloadURL until pyramids-eo#108 is released; see
# earthlens#1194 for the removal steps.
engine="ee",
**CORRIDOR,
)
job.authenticate(service_account=SERVICE_ACCOUNT, service_key=SERVICE_KEY)
frames = job.download(progress_bar=False)
len(frames)
Animate the corridor day by day¶
Read the daily frames into one collection and animate the true colour. MODIS surface reflectance needs a
brightness stretch, which pyramids applies via surface_reflectance.
dc = DatasetCollection.read_multiple_files(str(raw), date=False)
gif = OUT / "modis_corridor.gif"
dc.plot(
rgb_options={"rgb": [0, 1, 2], "surface_reflectance": 3200},
figsize=(6, 5),
title="Middle Danube corridor - MODIS true colour, Jun-Jul 2026",
).save_animation(str(gif), fps=3)
plt.close("all")
display(Image(filename=str(gif)))
The same stack, through Digital-Earth¶
digitalearth composes the same pyramids rasters and cleopatra glyphs, but hands back a Map that owns
the whole scene — so the identical frames can be rebuilt with things the cell above cannot do:
- The same tuned stretch, applied through one call. These bands carry a long bright tail (cloud tops,
snow), and a 2-98 percentile stretch spends most of its range on it — measured on this stack it drops the
colour separation from 86% to 7% of pixels. So the notebook's own
surface_reflectance=3200is kept and handed toMap.animateaslimits, which pins it across every frame rather than re-deriving anything. Measured beats hand-tuned only when the measurement suits the scene; here it does not. - One render, two files.
save_animation(..., gif=...)encodes the MP4 and derives the GIF from that file rather than redrawing every frame.
scene = de.Map(crs=dc.datasets[0].epsg, figsize=(6, 5))
scene.animate(
dc,
kind="rgb_composite",
# Keep this notebook's own reflectance divisor rather than letting the
# renderer derive 2-98 percentiles: these bands have a long bright tail, and
# a percentile stretch spends its range there and flattens the colour.
limits=[(0.0, 3200)] * 3,
bands=(1, 2, 3),
fps=3,
)
de_mp4, de_gif = scene.save_animation(
str(OUT / "modis_corridor_digitalearth.mp4"),
fps=3,
gif=str(OUT / "modis_corridor_digitalearth.gif"),
)
plt.close("all")
display(Image(filename=de_gif))
Notes¶
- MODIS is basin-scale, not channel-scale: watch the land brown and the reservoirs/large reaches, not individual sandbars. Cloudy days are part of a daily time-lapse (the weather moving through).
- Swap
MOD09GA(Terra, morning) forMYD09GA(Aqua, afternoon), or widen the box to the whole basin.