{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Detecting change in Australian forestry \n", "\n", "* **[Sign up to the DEA Sandbox](https://app.sandbox.dea.ga.gov.au/)** to run this notebook interactively from a browser\n", "* **Compatibility:** Notebook currently compatible with both the `NCI` and `DEA Sandbox` environments\n", "* **Products used:** \n", "[ga_s2am_ard_3](https://explorer.dea.ga.gov.au/ga_s2am_ard_3), \n", "[ga_s2bm_ard_3](https://explorer.dea.ga.gov.au/ga_s2bm_ard_3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Background\n", "Effective management of Australia's forests is critical for balancing environmental protection and sustainable growth of the industry.\n", "Methods for detecting meaningful and significant change in forests are important for those who manage and monitor large areas of forest.\n", "\n", "On-the-ground monitoring can be expensive and time-consuming, especially when forests are in difficult-to-navigate terrain.\n", "Aerial photography and LiDAR can provide detailed information about forests, but are often extremely expensive to acquire, even over small areas.\n", "\n", "### Sentinel-2 use case\n", "Satellite imagery from the [EU Copernicus Sentinel-2 mission](https://sentinel.esa.int/web/sentinel/missions/sentinel-2) is freely available and has a revisit time over Australia of ~5 days.\n", "Its 10 metre resolution makes it perfect for monitoring fine changes over very large areas of land.\n", "The archive of Sentinel-2 data stretches back to 2015, meaning that there is a good amount of data for change detection, allowing us to average out or focus on seasonal changes.\n", "\n", "## Description\n", "In this example, we measure the presence of vegetation from Sentinel-2 imagery and apply a hypothesis test to identify areas of significant change (along with the direction of the change).\n", "The worked example takes users through the code required to do the following:\n", "\n", "1. Load cloud-free Sentinel-2 images for an area of interest\n", "2. Compute an index to highlight presence of vegetation (NDVI)\n", "3. Apply a statistical hypothesis test to find areas of significant change\n", "4. Visualise the statistically significant areas.\n", "\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Getting started\n", "\n", "**To run this analysis**, run all the cells in the notebook, starting with the \"Load packages\" cell.\n", "\n", "**After finishing the analysis**, return to the \"Analysis parameters\" cell, modify some values (e.g. choose a different location or time period to analyse) and re-run the analysis.\n", "There are additional instructions on modifying the notebook at the end." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Load packages\n", "Load key Python packages and any supporting functions for the analysis." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "import datacube\n", "import numpy as np\n", "import xarray as xr\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "from scipy import stats\n", "from datacube.utils.cog import write_cog\n", "from datacube.utils.geometry import CRS\n", "\n", "import sys\n", "sys.path.insert(1, '../Tools/')\n", "from dea_tools.datahandling import load_ard\n", "from dea_tools.plotting import rgb, display_map\n", "from dea_tools.bandindices import calculate_indices\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Connect to the datacube\n", "Activate the datacube database, which provides functionality for loading and displaying stored Earth observation data." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "dc = datacube.Datacube(app=\"Change_detection\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Analysis parameters\n", "\n", "The following cell sets the parameters, which define the area of interest and the length of time to conduct the analysis over.\n", "There is also a parameter to define how the data is split in time; the split yields two non-overlapping samples, which is a requirement of the hypothesis test we want to run (more detail below).\n", "The parameters are:\n", "\n", "* `latitude`: The latitude range to analyse (e.g. `(-35.30, -35.331)`).\n", "For reasonable loading times, make sure the range spans less than ~0.1 degrees.\n", "* `longitude`: The longitude range to analyse (e.g. `(149.256, 149.30)`).\n", "For reasonable loading times, make sure the range spans less than ~0.1 degrees.\n", "* `time`: The date range to analyse (e.g. `('2015-01-01', '2018-12-31')`).\n", "Note that Sentinel-2 data is not available in Australia prior to 2015.\n", "For reasonable results, the range should span at least two years to prevent detecting seasonal changes.\n", "* `time_baseline`: The date at which to split the total sample into two non-overlapping samples (e.g. `'2017-12-01'`).\n", "For reasonable results, pick a date that is about halfway between the start and end dates specified in `time`.\n", "\n", "**If running the notebook for the first time**, keep the default settings below.\n", "This will demonstrate how the analysis works and provide meaningful results.\n", "The example covers the Kowen Forest, a commercial pine plantation in the Australian Capital Territory.\n", "\n", "**To run the notebook for a different area**, make sure Sentinel-2 data is available for the chosen area using the [DEA Explorer](https://explorer.dea.ga.gov.au/ga_s2am_ard_3).\n", "Use the drop-down menu to check both Sentinel-2A (`ga_s2am_ard_3`) and Sentinel-2B (`ga_s2bm_ard_3`)." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Define the area of interest\n", "latitude = (-35.30, -35.331)\n", "longitude = (149.256, 149.30)\n", "\n", "# Set the range of dates for the complete sample\n", "time = ('2015-01-01', '2018-12-31')\n", "\n", "# Set the date to separate the data into two samples for comparison\n", "time_baseline = '2017-12-01'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## View the selected location\n", "The next cell will display the selected area on an interactive map.\n", "The red border represents the area of interest of the study.\n", "Zoom in and out to get a better understanding of the area of interest.\n", "Clicking anywhere on the map will reveal the latitude and longitude coordinates of the clicked point." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n", "Dimensions: (time: 79, y: 198, x: 222)\n", "Coordinates:\n", " * time (time) datetime64[ns] 2015-09-13T00:06:31.458000 ... 2018-12...\n", " * y (y) float64 -3.961e+06 -3.961e+06 ... -3.965e+06 -3.965e+06\n", " * x (x) float64 1.561e+06 1.561e+06 ... 1.566e+06 1.566e+06\n", " spatial_ref int32 3577\n", "Data variables:\n", " nbart_red (time, y, x) float32 625.0 577.0 656.0 ... 1.47e+03 1.274e+03\n", " nbart_green (time, y, x) float32 740.0 741.0 773.0 ... 1.211e+03 1.039e+03\n", " nbart_blue (time, y, x) float32 495.0 473.0 508.0 ... 868.0 813.0 699.0\n", " nbart_nir_1 (time, y, x) float32 2.572e+03 2.481e+03 ... 2.363e+03\n", "Attributes:\n", " crs: EPSG:3577\n", " grid_mapping: spatial_ref