Tracing Typhoon Bavi (2020) in true colour¶
In late August 2020, Typhoon Bavi spun up east of Taiwan, curved north through the East China Sea
past Okinawa and Jeju, and made landfall near the China–North Korea border. From space its cloud spiral
is unmistakable, and a day-by-day true-colour time-lapse traces the whole track. We build one from
the earthlens gee backend and embed it as an animation.
The West Pacific's geostationary eye (Himawari, 10-minute imagery) isn't on Earth Engine, so we use the
next best thing: MODIS Terra (MOD09GA) daily surface reflectance — one true-colour snapshot per
day (~10:30 local overpass) to follow the storm north. (Aqua's MYD09GA reflectance is masked over this
region for the whole week, so Terra alone carries the time-lapse.)
Setup¶
pyramids reads the frames and animates the stack (DatasetCollection), and IPython.display.HTML
embeds the GIF. Earth Engine needs a service account, read from the GEE_SERVICE_ACCOUNT /
GEE_SERVICE_KEY environment variables.
import base64
import os
from pathlib import Path
import digitalearth as de
import matplotlib.pyplot as plt
from cleopatra.glyphs.gridded.array_glyph import Animation
from IPython.display import HTML, Image, display
from pyramids.dataset.collection import DatasetCollection
from earthlens.core import EarthLens
SERVICE_ACCOUNT = os.environ["GEE_SERVICE_ACCOUNT"]
SERVICE_KEY = os.environ["GEE_SERVICE_KEY"]
# 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")) / "bavi2020"
OUT.mkdir(parents=True, exist_ok=True)
BAVI = dict(
lat_lim=[18.0, 43.0], lon_lim=[116.0, 138.0]
) # East China Sea -> Korea, the whole track
One true-colour frame per day¶
For each day of Bavi's life we pull a daily true-colour composite from Terra (MOD09GA) — the
visible bands b01/b04/b03 (red/green/blue) — so the animation gets one clean frame a day to follow
the spiral. We keep them in chronological order.
days = [f"2020-08-{day:02d}" for day in range(21, 29)] # 21–28 Aug 2020
frames = [] # (date_label, path), one Terra composite per day, in chronological order
for day in days:
job = EarthLens(
data_source="gee",
dataset="MODIS/061/MOD09GA",
variables=["sur_refl_b01", "sur_refl_b04", "sur_refl_b03"],
start=day,
end=day,
temporal_resolution="daily",
scale=3000.0,
path=OUT / day,
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",
**BAVI,
)
job.authenticate(service_account=SERVICE_ACCOUNT, service_key=SERVICE_KEY)
got = job.download(progress_bar=False)
frames.append((day, got[0]))
len(frames)
Build the time-lapse¶
Load the ordered frames into a DatasetCollection, composite the true colour with
collection.plot(rgb_options={"rgb": [0, 1, 2], …}), label each frame with its date via glyph.animate(...), and write
the GIF with glyph.save_animation(...) — pyramids' native animation, no hand-rolled frame loop. The
GIF plays in any viewer with no JavaScript.
labels = [label for label, _ in frames]
paths = [path for _, path in frames]
cube = DatasetCollection.from_files(paths)
glyph = cube.plot(
rgb_options={"rgb": [0, 1, 2], "surface_reflectance": 3200}, figsize=(6, 5.5)
)
glyph.animate(
labels, playback=Animation(interval=350)
) # stamp each frame with its date
gif_path = OUT / "bavi_2020_timelapse.gif"
glyph.save_animation(
str(gif_path), fps=3
) # save_animation() also accepts a Path directly; str() here just keeps the call explicit
plt.close("all")
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:
- Per-frame titles as data, drawn as real axes titles rather than stamped into the pixels.
- 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 29% to 0% 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=cube.datasets[0].epsg, figsize=(6, 5.5))
scene.animate(
cube,
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),
titles=labels,
fps=3,
)
de_mp4, de_gif = scene.save_animation(
str(OUT / "bavi_digitalearth.mp4"), fps=3, gif=str(OUT / "bavi_digitalearth.gif")
)
plt.close("all")
display(Image(filename=de_gif))
Embed the GIF as a base64 data URI so the animation travels inside the notebook.
encoded = base64.b64encode(gif_path.read_bytes()).decode()
HTML(
f'<img src="data:image/gif;base64,{encoded}" alt="Typhoon Bavi 2020 true-colour time-lapse" />'
)
What you are watching¶
- 21–23 Aug — the storm organises east of Taiwan and the Ryukyus, its spiral tightening as it drifts north-northwest.
- 24–25 Aug — Bavi peaks over the warm East China Sea, a broad, cloud-filled pinwheel passing west of Kyushu and Jeju.
- 26–27 Aug — it races north and makes landfall near the China–North Korea border, the cloud mass smearing over the Korean peninsula.
- The black diagonal wedges that flit through some frames are MODIS orbital swath gaps — a normal artefact of stitching a once-daily polar-orbiting sensor into a single map.
Make it your own: move BAVI and days to any storm and window (MODIS has near-real-time data, so
a current typhoon works too), or drop scale for a sharper, heavier movie.