Generating continental-scale animations d6fa71fa5b904831a9ecb70b6c6bad93

Background

Using the DEA function xr_animation, which is based on matplotlib.animation and xarray, we can take a time series of Digital Earth Australia’s Geomedian annual satellite imagery composites and export a visually appealing time series animation for the entire Australian continent.

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

Description

This notebook demonstrates how to:

  1. Import a time series of Landsat 8 and 9 geomedians

  2. Export true colour animations


Getting started

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

Load packages

[1]:
import sys
import datacube
import matplotlib.pyplot as plt
from IPython.display import Image
from datacube.utils.masking import mask_invalid_data

sys.path.insert(1, '../Tools/')
from dea_tools.plotting import xr_animation, rgb
from dea_tools.bandindices import calculate_indices
from dea_tools.dask import create_local_dask_cluster

# Create local dask cluster to improve data load time
client = create_local_dask_cluster(return_client=True)

Client

Client-8b82390c-1f29-11f0-8242-e2efa053cb4c

Connection method: Cluster object Cluster type: distributed.LocalCluster
Dashboard: /user/robbi.bishoptaylor@ga.gov.au/proxy/8787/status

Cluster Info

Connect to the datacube

[2]:
dc = datacube.Datacube(app='Continental_scale_animations')

Load satellite data from datacube

We will use the dc.load function to load the geomedian data, and return an xarray.Dataset. This will allow us to create a visually appealing time series animation of observations for the selected time. In the default example, we only load two years of data to reduce the loading time.

Note: This cell takes approximately 12 minutes to run with the default Sandbox server.

[3]:
# Specify the time period
time_range = ('2023', '2024')

# Load geomedian data
ds = dc.load(
    product='ga_ls8cls9c_gm_cyear_3',
    measurements=['nbart_red', 'nbart_green', 'nbart_blue'],
    output_crs='EPSG:3577',
    time=time_range,
    resolution=(-5000, 5000),  # coarse-scale resolution
    resampling='bilinear',
    dask_chunks={'x': 500, 'y': 500},
)

# Remove no-data values
ds = mask_invalid_data(ds)

# Bring into memory
ds.load()
/env/lib/python3.10/site-packages/rasterio/warp.py:387: NotGeoreferencedWarning: Dataset has no geotransform, gcps, or rpcs. The identity matrix will be returned.
  dest = _reproject(
[3]:
<xarray.Dataset> Size: 16MB
Dimensions:      (time: 2, y: 788, x: 846)
Coordinates:
  * time         (time) datetime64[ns] 16B 2023-07-02T11:59:59.999999 2024-07...
  * y            (y) float64 6kB -9.625e+05 -9.675e+05 ... -4.892e+06 -4.898e+06
  * x            (x) float64 7kB -2.018e+06 -2.012e+06 ... 2.202e+06 2.208e+06
    spatial_ref  int32 4B 3577
Data variables:
    nbart_red    (time, y, x) float32 5MB nan nan nan nan ... nan nan nan nan
    nbart_green  (time, y, x) float32 5MB nan nan nan nan ... nan nan nan nan
    nbart_blue   (time, y, x) float32 5MB nan nan nan nan ... nan nan nan nan
Attributes:
    crs:           EPSG:3577
    grid_mapping:  spatial_ref

Animate the RGB time series

To learn more about the customising the xr_animation function, see the Animated_timeseries.ipynb notebook.

[4]:
# Produce the time series animation
xr_animation(ds=ds,
             output_path='rgb_continental_timeseries.gif',
             bands=["nbart_red", "nbart_green", "nbart_blue"],
             show_date='%Y',
             interval=600,
             percentile_stretch=(0.01, 0.99),
             colorbar_kwargs={'colors': 'black'},
             width_pixels=500,
             annotation_kwargs={
                 'color': 'black',
                 'animated': True
             })

# Plot animated gif
plt.close()
Image(filename='rgb_continental_timeseries.gif')
Exporting animation to rgb_continental_timeseries.gif
[4]:
<IPython.core.display.Image object>

Additional information

License: The code in this notebook is licensed under the Apache License, Version 2.0. Digital Earth Australia 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 Discord chat 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.

Last modified: April 2025

Compatible datacube version:

[5]:
print(datacube.__version__)
1.8.19

Tags

Tags: sandbox compatible, landsat 8, landsat 9, NCI compatible, sandbox compatible, annual geomedian, rgb, xr_animation, matplotlib.animation, animation,