diff --git a/Beginners_guide/05_Plotting.ipynb b/Beginners_guide/05_Plotting.ipynb index e32c853d6..016c28869 100644 --- a/Beginners_guide/05_Plotting.ipynb +++ b/Beginners_guide/05_Plotting.ipynb @@ -1,2857 +1,3055 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Introduction to plotting \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_ls8c_nbart_gm_cyear_3](https://explorer.dea.ga.gov.au/ga_ls8c_nbart_gm_cyear_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)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Background\n", - "Data visualisation is an important component of working with Earth Observation data.\n", - "The `xarray` Python package provides a range of straightforward data plotting options that allow users to quickly generate simple plots from multi-dimensional datasets. \n", - "To generate more complex and informative plots, the DEA Notebooks repository also provides a custom plotting module with additional easy-to-use functionality." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Description\n", - "This introductory notebook demonstrates how to visualise DEA satellite data returned from running a datacube query.\n", - "The notebook demonstrates commonly used `xarray` plotting methods, as well as custom functions provided in the [dea_tools.plotting](../Tools/dea_tools/plotting.py) module.\n", - "\n", - "Topics covered in this notebook include:\n", - "\n", - "1. View an area of interest prior to querying the datacube\n", - "2. Querying the datacube and loading data\n", - "3. Plotting single band data (e.g. a single satellite band)\n", - " * Selecting and plotting individual timesteps\n", - " * Plotting multiple timesteps\n", - " * Customising plot appearance\n", - "4. Plotting three-band true or false colour imagery\n", - " * Plotting single timesteps\n", - " * Plotting multiple timesteps\n", - " * Customising plot appearance\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 first step is to run `%matplotlib inline`, which ensures figures plot correctly in the Jupyter notebook.\n", - "Next, load the `datacube` package to enable loading data, and a selection of custom DEA functions from the [dea_tools.plotting](../Tools/dea_tools/plotting.py) module." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "%matplotlib inline\n", - "\n", - "import datacube\n", - "import sys\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=\"05_Plotting\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Analysis parameters\n", - "\n", - "The following variables are required to establish a query for this notebook:\n", - "- `lat_range`: The latitude range to analyse (e.g. `(-27.715, -27.755)`). For reasonable load times, keep this to a range of ~0.1 degrees or less.\n", - "- `lon_range`: The longitude range to analyse (e.g. `(153.42, 153.46)`). For reasonable load times, keep this to a range of ~0.1 degrees or less.\n", - "- `time_range`: The date range to analyse (e.g. `(\"2013\", \"2017\")`).\n" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "lat_range = (-27.58, -27.666)\n", - "lon_range = (153.3, 153.4)\n", - "time_range = (\"2013\", \"2017\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## View the queried location\n", - "Before running a query and extracting and analysing data, it is useful to double-check that your location is correct.\n", - "The `display_map()` function shows your selected area as a red rectangle on an interactive map.\n", - "Clicking on any point of the map will reveal the latitude and longitude coordinates of that point." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
<xarray.Dataset>\n", - "Dimensions: (time: 5, y: 372, x: 375)\n", - "Coordinates:\n", - " * time (time) datetime64[ns] 2013-07-02T11:59:59.999999 ... 2017-07...\n", - " * y (y) float64 -3.165e+06 -3.165e+06 ... -3.176e+06 -3.176e+06\n", - " * x (x) float64 2.066e+06 2.066e+06 ... 2.077e+06 2.077e+06\n", - " spatial_ref int32 3577\n", - "Data variables:\n", - " blue (time, y, x) int16 236 244 236 231 224 ... 306 285 285 279 293\n", - " green (time, y, x) int16 353 369 359 351 343 ... 412 389 380 370 395\n", - " red (time, y, x) int16 284 287 279 274 256 ... 385 350 339 324 346\n", - " nir (time, y, x) int16 2480 2561 2579 2587 ... 1940 1956 2040 2213\n", - " swir1 (time, y, x) int16 1071 1093 1056 1007 ... 1333 1215 1126 1179\n", - " swir2 (time, y, x) int16 473 474 455 433 412 ... 758 648 575 520 534\n", - " sdev (time, y, x) float32 0.0006196 0.0001783 ... 0.001541 0.002267\n", - " edev (time, y, x) float32 116.4 83.31 79.72 ... 207.5 188.5 186.4\n", - " bcdev (time, y, x) float32 0.02475 0.01706 ... 0.04494 0.03912\n", - " count (time, y, x) int16 8 8 8 8 8 8 8 8 ... 14 14 14 14 14 15 14 14\n", - "Attributes:\n", - " crs: EPSG:3577\n", - " grid_mapping: spatial_ref
<xarray.DataArray 'swir1' (time: 5, y: 372, x: 375)>\n", - "array([[[1071, 1093, 1056, ..., 74, 72, 66],\n", - " [1084, 1075, 1021, ..., 77, 73, 68],\n", - " [1066, 1037, 971, ..., 77, 75, 68],\n", - " ...,\n", - " [1230, 1288, 900, ..., 1098, 1090, 1136],\n", - " [ 822, 802, 758, ..., 1097, 1064, 1140],\n", - " [1172, 946, 913, ..., 1075, 1014, 1079]],\n", - "\n", - " [[1130, 1138, 1112, ..., 56, 61, 97],\n", - " [1195, 1144, 1077, ..., 57, 47, 83],\n", - " [1223, 1146, 1055, ..., 48, 55, 55],\n", - " ...,\n", - " [1333, 1339, 915, ..., 1115, 1101, 1173],\n", - " [ 901, 897, 815, ..., 1101, 1066, 1163],\n", - " [1249, 1001, 912, ..., 1089, 1018, 1079]],\n", - "\n", - " [[1022, 1035, 1011, ..., 42, 38, 51],\n", - " [1051, 1031, 965, ..., 41, 50, 53],\n", - " [1063, 1005, 934, ..., 48, 50, 71],\n", - " ...,\n", - " [1209, 1334, 991, ..., 1080, 1044, 1098],\n", - " [ 827, 818, 846, ..., 1073, 1044, 1110],\n", - " [1285, 941, 895, ..., 1058, 996, 1059]],\n", - "\n", - " [[1086, 1083, 1049, ..., 38, 43, 38],\n", - " [1126, 1088, 1027, ..., 38, 43, 37],\n", - " [1148, 1075, 995, ..., 42, 43, 36],\n", - " ...,\n", - " [1267, 1344, 1005, ..., 1103, 1088, 1154],\n", - " [ 884, 891, 966, ..., 1098, 1058, 1138],\n", - " [1283, 994, 933, ..., 1104, 1038, 1096]],\n", - "\n", - " [[1081, 1078, 1031, ..., 56, 57, 57],\n", - " [1076, 1064, 999, ..., 60, 61, 60],\n", - " [1109, 1047, 972, ..., 61, 63, 62],\n", - " ...,\n", - " [1222, 1260, 901, ..., 1219, 1172, 1215],\n", - " [ 886, 849, 904, ..., 1213, 1152, 1223],\n", - " [1271, 996, 953, ..., 1215, 1126, 1179]]], dtype=int16)\n", - "Coordinates:\n", - " * time (time) datetime64[ns] 2013-07-02T11:59:59.999999 ... 2017-07...\n", - " * y (y) float64 -3.165e+06 -3.165e+06 ... -3.176e+06 -3.176e+06\n", - " * x (x) float64 2.066e+06 2.066e+06 ... 2.077e+06 2.077e+06\n", - " spatial_ref int32 3577\n", - "Attributes:\n", - " units: 1\n", - " nodata: -999\n", - " crs: EPSG:3577\n", - " grid_mapping: spatial_ref
<xarray.DataArray 'swir1' (y: 372, x: 375)>\n", - "array([[1071, 1093, 1056, ..., 74, 72, 66],\n", - " [1084, 1075, 1021, ..., 77, 73, 68],\n", - " [1066, 1037, 971, ..., 77, 75, 68],\n", - " ...,\n", - " [1230, 1288, 900, ..., 1098, 1090, 1136],\n", - " [ 822, 802, 758, ..., 1097, 1064, 1140],\n", - " [1172, 946, 913, ..., 1075, 1014, 1079]], dtype=int16)\n", - "Coordinates:\n", - " time datetime64[ns] 2013-07-02T11:59:59.999999\n", - " * y (y) float64 -3.165e+06 -3.165e+06 ... -3.176e+06 -3.176e+06\n", - " * x (x) float64 2.066e+06 2.066e+06 ... 2.077e+06 2.077e+06\n", - " spatial_ref int32 3577\n", - "Attributes:\n", - " units: 1\n", - " nodata: -999\n", - " crs: EPSG:3577\n", - " grid_mapping: spatial_ref
<xarray.DataArray 'swir1' (time: 1, y: 372, x: 375)>\n", - "array([[[1071, 1093, 1056, ..., 74, 72, 66],\n", - " [1084, 1075, 1021, ..., 77, 73, 68],\n", - " [1066, 1037, 971, ..., 77, 75, 68],\n", - " ...,\n", - " [1230, 1288, 900, ..., 1098, 1090, 1136],\n", - " [ 822, 802, 758, ..., 1097, 1064, 1140],\n", - " [1172, 946, 913, ..., 1075, 1014, 1079]]], dtype=int16)\n", - "Coordinates:\n", - " * time (time) datetime64[ns] 2013-07-02T11:59:59.999999\n", - " * y (y) float64 -3.165e+06 -3.165e+06 ... -3.176e+06 -3.176e+06\n", - " * x (x) float64 2.066e+06 2.066e+06 ... 2.077e+06 2.077e+06\n", - " spatial_ref int32 3577\n", - "Attributes:\n", - " units: 1\n", - " nodata: -999\n", - " crs: EPSG:3577\n", - " grid_mapping: spatial_ref