{
"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_ls8cls9c_gm_cyear_3](https://explorer.dea.ga.gov.au/ga_ls8cls9c_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": {
"tags": []
},
"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": {
"tags": []
},
"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": {
"tags": []
},
"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": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"
<xarray.Dataset> Size: 18MB\n", "Dimensions: (time: 5, y: 372, x: 375)\n", "Coordinates:\n", " * time (time) datetime64[ns] 40B 2013-07-02T11:59:59.999999 ... 20...\n", " * y (y) float64 3kB -3.165e+06 -3.165e+06 ... -3.176e+06\n", " * x (x) float64 3kB 2.066e+06 2.066e+06 ... 2.077e+06 2.077e+06\n", " spatial_ref int32 4B 3577\n", "Data variables:\n", " nbart_blue (time, y, x) int16 1MB 236 244 235 230 224 ... 286 275 276 287\n", " nbart_green (time, y, x) int16 1MB 354 369 358 350 343 ... 392 374 371 394\n", " nbart_red (time, y, x) int16 1MB 284 286 278 273 255 ... 353 334 326 346\n", " nbart_nir (time, y, x) int16 1MB 2484 2567 2580 2588 ... 1959 2048 2223\n", " nbart_swir_1 (time, y, x) int16 1MB 1069 1093 1054 1006 ... 1230 1149 1200\n", " nbart_swir_2 (time, y, x) int16 1MB 470 473 454 432 411 ... 657 581 530 543\n", " sdev (time, y, x) float32 3MB 0.0006154 0.0001635 ... 0.001664\n", " edev (time, y, x) float32 3MB 116.4 86.19 80.38 ... 162.9 156.3\n", " bcdev (time, y, x) float32 3MB 0.02473 0.01709 ... 0.03776 0.03605\n", " count (time, y, x) int16 1MB 8 8 8 8 8 8 8 ... 11 11 11 11 11 11 11\n", "Attributes:\n", " crs: EPSG:3577\n", " grid_mapping: spatial_ref
<xarray.DataArray 'nbart_swir_1' (time: 5, y: 372, x: 375)> Size: 1MB\n", "array([[[1069, 1093, 1054, ..., 38, 37, 37],\n", " [1085, 1074, 1021, ..., 37, 36, 36],\n", " [1067, 1036, 972, ..., 34, 34, 34],\n", " ...,\n", " [1249, 1294, 882, ..., 1097, 1092, 1139],\n", " [ 810, 801, 745, ..., 1095, 1066, 1145],\n", " [1123, 882, 865, ..., 1073, 1016, 1086]],\n", "\n", " [[1128, 1139, 1110, ..., 46, 45, 47],\n", " [1193, 1141, 1077, ..., 47, 45, 47],\n", " [1221, 1144, 1053, ..., 47, 45, 47],\n", " ...,\n", " [1355, 1344, 906, ..., 1107, 1105, 1177],\n", " [ 873, 895, 805, ..., 1100, 1070, 1171],\n", " [1184, 934, 871, ..., 1086, 1021, 1088]],\n", "\n", " [[1015, 1044, 1014, ..., 34, 33, 35],\n", " [1055, 1045, 977, ..., 33, 33, 30],\n", " [1078, 1014, 944, ..., 34, 33, 31],\n", " ...,\n", " [1237, 1343, 977, ..., 1066, 1038, 1095],\n", " [ 799, 828, 832, ..., 1072, 1045, 1114],\n", " [1225, 885, 843, ..., 1056, 999, 1067]],\n", "\n", " [[1068, 1071, 1039, ..., 38, 38, 38],\n", " [1114, 1081, 1012, ..., 37, 37, 37],\n", " [1140, 1061, 987, ..., 37, 37, 36],\n", " ...,\n", " [1287, 1343, 980, ..., 1107, 1088, 1161],\n", " [ 873, 914, 954, ..., 1101, 1059, 1157],\n", " [1227, 943, 896, ..., 1090, 1029, 1103]],\n", "\n", " [[1071, 1068, 1016, ..., 54, 55, 54],\n", " [1063, 1048, 975, ..., 55, 57, 56],\n", " [1094, 1032, 946, ..., 56, 58, 57],\n", " ...,\n", " [1257, 1269, 900, ..., 1250, 1193, 1228],\n", " [ 898, 880, 899, ..., 1244, 1176, 1238],\n", " [1232, 969, 939, ..., 1230, 1149, 1200]]], dtype=int16)\n", "Coordinates:\n", " * time (time) datetime64[ns] 40B 2013-07-02T11:59:59.999999 ... 201...\n", " * y (y) float64 3kB -3.165e+06 -3.165e+06 ... -3.176e+06 -3.176e+06\n", " * x (x) float64 3kB 2.066e+06 2.066e+06 ... 2.077e+06 2.077e+06\n", " spatial_ref int32 4B 3577\n", "Attributes:\n", " units: 1\n", " nodata: -999\n", " crs: EPSG:3577\n", " grid_mapping: spatial_ref
<xarray.DataArray 'nbart_swir_1' (y: 372, x: 375)> Size: 279kB\n", "array([[1069, 1093, 1054, ..., 38, 37, 37],\n", " [1085, 1074, 1021, ..., 37, 36, 36],\n", " [1067, 1036, 972, ..., 34, 34, 34],\n", " ...,\n", " [1249, 1294, 882, ..., 1097, 1092, 1139],\n", " [ 810, 801, 745, ..., 1095, 1066, 1145],\n", " [1123, 882, 865, ..., 1073, 1016, 1086]], dtype=int16)\n", "Coordinates:\n", " time datetime64[ns] 8B 2013-07-02T11:59:59.999999\n", " * y (y) float64 3kB -3.165e+06 -3.165e+06 ... -3.176e+06 -3.176e+06\n", " * x (x) float64 3kB 2.066e+06 2.066e+06 ... 2.077e+06 2.077e+06\n", " spatial_ref int32 4B 3577\n", "Attributes:\n", " units: 1\n", " nodata: -999\n", " crs: EPSG:3577\n", " grid_mapping: spatial_ref
<xarray.DataArray 'nbart_swir_1' (time: 1, y: 372, x: 375)> Size: 279kB\n", "array([[[1069, 1093, 1054, ..., 38, 37, 37],\n", " [1085, 1074, 1021, ..., 37, 36, 36],\n", " [1067, 1036, 972, ..., 34, 34, 34],\n", " ...,\n", " [1249, 1294, 882, ..., 1097, 1092, 1139],\n", " [ 810, 801, 745, ..., 1095, 1066, 1145],\n", " [1123, 882, 865, ..., 1073, 1016, 1086]]], dtype=int16)\n", "Coordinates:\n", " * time (time) datetime64[ns] 8B 2013-07-02T11:59:59.999999\n", " * y (y) float64 3kB -3.165e+06 -3.165e+06 ... -3.176e+06 -3.176e+06\n", " * x (x) float64 3kB 2.066e+06 2.066e+06 ... 2.077e+06 2.077e+06\n", " spatial_ref int32 4B 3577\n", "Attributes:\n", " units: 1\n", " nodata: -999\n", " crs: EPSG:3577\n", " grid_mapping: spatial_ref