Generating continental animated time series using xr_animation

Keywords data used; ndvi_anomaly, data methods; animation, band index; ndvi_mean

Minimum Required Memory Size: 32GB or higher

Please note that this notebook requires a minimum of 32GB memory or higher to run successfully within the Digital Earth Africa Sandbox. The default 16GB memory allocation may not be sufficient to run the notebook successfully.

If you encounter any memory-related issues, please consider increasing the memory allocation for your Digital Earth Africa Sandbox.

Note: The actual memory requirements may vary depending on the specific computations and data involved in the notebook.


Animations can be a powerful method for visualising change in the landscape across time using satellite imagery. Satellite data from Digital Earth Africa is an ideal subject for animations as it has been georeferenced, processed to analysis-ready surface reflectance, and stacked into a spatio-temporal ‘data cube’, allowing landscape conditions to be extracted and visualised consistently across time.

Using the DE Africa functions in Scripts/deafrica_plotting, which are based on matplotlib.animation and xarray, we can take a time series of Digital Earth Africa satellite imagery and export a visually appealing time series animation that shows how any location in Africa has changed.


This notebook demonstrates how to:

  1. Import a time series of mean monthly xarray dataset avaibale on the DE Africa platform. For this notebook we will be using the Mean NDVI and Anomalies service. More infomation on available dataset

  2. Export the resulting dataset in the form of animations as either a GIF or MP4

Getting started

To run this analysis, run all the cells in the notebook, starting with the “Load packages” cell.

Load packages

%matplotlib inline

import datacube
import matplotlib.pyplot as plt
from IPython.display import Image

from deafrica_tools.plotting import xr_animation
from deafrica_tools.dask import create_local_dask_cluster
/usr/local/lib/python3.8/dist-packages/geopandas/ UserWarning: The Shapely GEOS version (3.8.0-CAPI-1.13.1 ) is incompatible with the GEOS version PyGEOS was compiled with (3.10.3-CAPI-1.16.1). Conversions between both will be slow.



  • Workers: 1
  • Cores: 4
  • Memory: 28.14 GB

Connect to the datacube

dc = datacube.Datacube(app='export_animated_timeseries')

Load satellite data from datacube

We will use the dc load function to load data (i.e. ndvi_anomaly), and return an xarray.Dataset. This will allow us to create a visually appealing time series animation of observations for the selected time.

#Specify the time period
time_range = ('2019-01-01', '2019-12-31')

# Load available data
ds = dc.load(product='ndvi_anomaly',
              time = time_range,
              resolution=(-2500, 2500),

ds = ds.compute()


# Produce the time series animation
             imshow_kwargs={'cmap': 'RdYlGn', 'vmin': 0.0, 'vmax': 0.9},
             colorbar_kwargs={'colors': 'black'},
             annotation_kwargs= {'color':'black', 'animated': True}

# Plot animated gif
Exporting animation to ndvi_mean.gif
<IPython.core.display.Image object>

Additional information

License: The code in this notebook is licensed under the Apache License, Version 2.0. Digital Earth Africa data is licensed under the Creative Commons by Attribution 4.0 license.

Contact: If you need assistance, please post a question on the Open Data Cube Slack channel or on the GIS Stack Exchange using the open-data-cube tag (you can view previously asked questions here). If you would like to report an issue with this notebook, you can file one on Github.

Compatible datacube version:

[ ]:

Last Tested:

[ ]:
from datetime import datetime'%Y-%m-%d')