dea_tools.landcover

Plotting and animating Digital Earth Australia Land Cover data.

License: The code in this notebook is licensed under the Apache License, Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0). Digital Earth Australia data is licensed under the Creative Commons by Attribution 4.0 license (https://creativecommons.org/licenses/by/4.0/).

Contact: If you need assistance, please post a question on the Open Data Cube Slack channel (http://slack.opendatacube.org/) or on the GIS Stack Exchange (https://gis.stackexchange.com/questions/ask?tags=open-data-cube) using the open-data-cube tag (you can view previously asked questions here: https://gis.stackexchange.com/questions/tagged/open-data-cube).

If you would like to report an issue with this script, you can file one on Github (GeoscienceAustralia/dea-notebooks#new).

Last modified: January 2022

Functions

get_layer_name(measurement, da)

lc_animation(da[, file_name, measurement, ...])

Creates an animation of DEA Landcover though time beside corresponding stacked plots of the landcover classes.

lc_colourmap(colour_scheme[, colour_bar])

Returns colour map and normalisation for the provided DEA Land Cover measurement, for use in plotting with Matplotlib library

make_colorbar(fig, ax, measurement[, ...])

Adds a new colorbar with appropriate land cover colours and labels.

plot_land_cover(data[, year, measurement, ...])

Plot a single land cover measurement with appropriate colour scheme. :param data: A dataArray containing a DEA Land Cover classification. :type data: xarray.DataArray :param year: Can be used to select to plot a specific year. If not provided, all time slices are plotted. :type year: int, optional :param measurement: Name of the DEA land cover classification to be plotted. Passed to lc_colourmap to specify which colour scheme will be used. If non provided, reads data array name from da to determine. :type measurement: string, optional.

dea_tools.landcover.lc_animation(da, file_name='default_animation', measurement=None, stacked_plot=False, colour_bar=False, animation_interval=500, width_pixels=10, dpi=150, font_size=15, label_ax=True)[source]

Creates an animation of DEA Landcover though time beside corresponding stacked plots of the landcover classes. Saves the animation to a file and displays the animation in notebook.

Parameters:
  • da (xarray.DataArray) – An xarray.DataArray containing a multi-date stack of observations of a single landcover level.

  • file_name (string, optional.) – string used to create filename for saved animation file. Default: “default_animation” code adds .gif suffix.

  • measurement (string, optional) – Name of the DEA land cover classification to be plotted. Passed to lc_colourmap to specify which colour scheme will ve used. If non provided, reads data array name from da to determine.

  • stacked_plot (boolean, optional) – Determines if a stacked plot showing the percentage of area taken up by each class in each time slice is added to the animation. Default: False.

  • colour_bar (boolean, Optional) – Determines if a colour bar is generated for the stand alone animation. This is NOT recommended for use with level 4 data. Does not work with stacked plot. Default: False.

  • animation_interval (int , optional) – How quickly the frames of the animations should be re-drawn. Default: 500.

  • width_pixels (int, optional) – How wide in pixles the animation plot should be. Default: 10.

  • dpi (int, optional) – Stands for ‘Dots Per Inch’. Passed to the fuction that saves the animation and determines the resolution. A higher number will produce a higher resolution image but a larger file size and slower processing. Default: 150.

  • font_size (int, optional.) – Controls the size of the text which indicates the year displayed. Default: 15.

  • label_ax (boolean, optional) – Determines if animation plot should have tick marks and numbers on axes. Also removes white space around plot. default: True

Return type:

A GIF (.gif) animation file.

dea_tools.landcover.lc_colourmap(colour_scheme, colour_bar=False)[source]

Returns colour map and normalisation for the provided DEA Land Cover measurement, for use in plotting with Matplotlib library

Parameters:
  • colour_scheme (string) – Name of land cover colour scheme to use Valid options: ‘level3’, ‘level4’, ‘lifeform_veg_cat_l4a’, ‘canopyco_veg_cat_l4d’, ‘watersea_veg_cat_l4a_au’, ‘waterstt_wat_cat_l4a’, ‘inttidal_wat_cat_l4a’, ‘waterper_wat_cat_l4d_au’, ‘baregrad_phy_cat_l4d_au’.

  • colour_bar (bool, optional) – Controls if colour bar labels are returned as a list for plotting a colour bar. Default: False.

Returns:

  • cmap (matplotlib colormap) – Matplotlib colormap containing the colour scheme for the specified DEA Land Cover measurement.

  • norm (matplotlib colormap index) – Matplotlib colormap index based on the discrete intervals of the classes in the specified DEA Land Cover measurement. Ensures the colormap maps the colours to the class numbers correctly.

  • cblables (array) – A two dimentional array containing the numerical class values (first dim) and string labels (second dim) of the classes found in the chosen DEA Land Cover measurement.

dea_tools.landcover.make_colorbar(fig, ax, measurement, horizontal=False, animation=False)[source]

Adds a new colorbar with appropriate land cover colours and labels.

For DEA Land Cover Level 4 data, this function must be used with a double plot. The ‘ax’ should be on the left side of the figure, and the colour bar will added on the right hand side.

Parameters:
  • fig (matplotlib figure) – Figure to add colourbar to

  • ax (matplotlib ax) – Matplotlib figure ax to add colorbar to.

  • measurement (str) – Land cover measurement to use for colour map and labels.

dea_tools.landcover.plot_land_cover(data, year=None, measurement=None, out_width=15, cols=4)[source]

Plot a single land cover measurement with appropriate colour scheme. :param data: A dataArray containing a DEA Land Cover classification. :type data: xarray.DataArray :param year: Can be used to select to plot a specific year. If not provided,

all time slices are plotted.

Parameters:

measurement (string, optional) – Name of the DEA land cover classification to be plotted. Passed to lc_colourmap to specify which colour scheme will be used. If non provided, reads data array name from da to determine.