{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Performing a basic analysis \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", "* **Prerequisites**: Users of this notebook should have a basic understanding of:\n", " * How to run a [Jupyter notebook](01_Jupyter_notebooks.ipynb)\n", " * The basic structure of the DEA [satellite datasets](02_DEA.ipynb)\n", " * Inspecting available [DEA products and measurements](03_Products_and_measurements.ipynb)\n", " * How to [load data from DEA](04_Loading_data.ipynb)\n", " * How to [plot loaded data](05_Plotting.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Background\n", "To understand the world around us, it's important to combine the key steps of loading, visualising, manipulating and interpreting satellite data.\n", "To perform an analysis, we begin with a question and use these steps to reach an answer." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Description\n", "This notebook demonstrates how to conduct a basic analysis with DEA data and the Open Data Cube.\n", "It will combine many of the steps that have been covered in the other beginner's notebooks.\n", "\n", "In this notebook, the analysis question is _\"How is the health of vegetation changing over time in a given area?\"_\n", "\n", "This could be related to a number of broader questions: \n", "\n", "* What is the effect of a particular fertilizer on a field of crops?\n", "* How has a patch of forest changed after a fire? \n", "* How does proximity to water affect vegetation throughout the year?\n", "\n", "For this notebook, the analysis question will be kept simple, without much real-world context. \n", "For more examples of notebooks that demonstrate how to use DEA to answer specific analysis questions, see the notebooks in the \"Real world examples\" folder. \n", "\n", "Topics covered in this notebook include:\n", "\n", "1. Choosing a study area.\n", "2. Loading data for the study area.\n", "3. Plotting the chosen data and exploring how it changes with time.\n", "4. Calculating a measure of vegetation health from the loaded data.\n", "5. Exporting the data for further analysis.\n", "\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Getting started\n", "To run this introduction to plotting data loaded from the datacube, run all the cells in the notebook starting with the \"Load packages\" cell. For help with running notebook cells, refer back to the [Jupyter Notebooks notebook](01_Jupyter_notebooks.ipynb). " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Load packages\n", "The cell below imports Python packages that are used for the analysis.\n", "The first command is `%matplotlib inline`, which ensures figures plot correctly in the Jupyter notebook.\n", "The following commands import various functionality: \n", "\n", "* `sys` provides access to helpful support functions in the `dea_plotting` module. \n", "* `datacube` provides the ability to query and load data.\n", "* `matplotlib` provides the ability to format and manipulate plots." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "import sys\n", "import datacube\n", "import matplotlib.pyplot as plt\n", "from datacube.utils.cog import write_cog\n", "\n", "sys.path.insert(1, '../Tools/')\n", "from dea_tools.plotting import display_map, rgb" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Connect to the datacube\n", "The next step is to connect to the datacube database.\n", "The resulting `dc` datacube object can then be used to load data.\n", "The `app` parameter is a unique name used to identify the notebook that does not have any effect on the analysis." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "dc = datacube.Datacube(app=\"06_Basic_analysis\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Choose a study area" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When working with the Open Data Cube, it's important to load only as much data as needed.\n", "This helps keep an analysis running quickly and avoids the notebook crashing due to insufficient memory.\n", "\n", "One way to set the study area is to set a central latitude and longitude coordinate pair, `(central_lat, central_lon)`, then specify how many degrees to include either side of the central latitude and longitude, known as the `buffer`.\n", "Together, these parameters specify a square study area, as shown below:\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Location\n", "Below, we have set the study area covering Dead Dog Creek, Queensland.\n", "To load a different area, you can provide your own `central_lat` and `central_lon` values.\n", "One way to source these is to Google a location, or click directly on the map in [Google Maps](https://www.google.com/maps/@-43.4539764,146.5660989,11642m/data=!3m1!1e3).\n", "Other options are:\n", "\n", "* **Giles Creek, Northern Territory**\n", "```\n", "central_lat = -23.765\n", "central_lon = 134.724\n", "```\n", "* **Lake Disappointment, Western Australia**\n", "```\n", "central_lat = -23.765\n", "central_lon = 134.724\n", "```\n", "* **Precipitous Bluff, Tasmania**\n", "```\n", "central_lat = -43.469\n", "central_lon = 146.604\n", "```\n", "\n", "> **Note**: If you change the study area latitude and longitude, you'll need to re-run all of the cells after to apply that change to the whole analysis." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Buffer\n", "Feel free to experiment with the `buffer` value to load different sized areas.\n", "We recommend that you keep the `buffer` relatively small, no higher than `buffer=0.1` degrees.\n", "This will help keep the loading times reasonable and prevent the notebook from crashing.\n", "\n", "> **Extension**: Can you modify the code to use a different `buffer` value for latitude and longitude? \n", "\n", "> *Hint*: You may want two variables, `buffer_lat` and `buffer_lon` that you can set independently. You'll then need to update the definitions of `study_area_lat` and `study_area_lon` with their corresponding buffer value." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Set the central latitude and longitude\n", "central_lat = -14.643\n", "central_lon = 144.900\n", "\n", "# Set the buffer to load around the central coordinates\n", "buffer = 0.025\n", "\n", "# Compute the bounding box for the study area\n", "study_area_lat = (central_lat - buffer, central_lat + buffer)\n", "study_area_lon = (central_lon - buffer, central_lon + buffer)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After choosing the study area, it can be useful to visualise it on an interactive map.\n", "This provides a sense of scale.\n", "> **Note**: The interactive map also returns latitude and longitude values when clicked.\n", "You can use this to generate new latitude and longitude values to try without leaving the notebook." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n", "Dimensions: (time: 9, y: 601, x: 597)\n", "Coordinates:\n", " * time (time) datetime64[ns] 2018-09-09T00:37:02.458000 ... 2018-11...\n", " * y (y) float64 -1.62e+06 -1.62e+06 ... -1.626e+06 -1.626e+06\n", " * x (x) float64 1.398e+06 1.398e+06 ... 1.404e+06 1.404e+06\n", " spatial_ref int32 3577\n", "Data variables:\n", " nbart_red (time, y, x) int16 448 438 426 413 383 ... 989 1062 888 878 846\n", " nbart_blue (time, y, x) int16 477 485 469 433 436 ... 725 730 679 640 652\n", " nbart_green (time, y, x) int16 673 634 599 576 554 ... 921 887 872 799 784\n", " nbart_nir_1 (time, y, x) int16 2094 2001 1964 2078 ... 2169 2194 2040 1979\n", "Attributes:\n", " crs: epsg:3577\n", " grid_mapping: spatial_ref