diff --git a/How_to_guides/Tidal_modelling.ipynb b/How_to_guides/Tidal_modelling.ipynb index 297a748e3..7f52b9909 100644 --- a/How_to_guides/Tidal_modelling.ipynb +++ b/How_to_guides/Tidal_modelling.ipynb @@ -1,4 +1,6224 @@ { +<<<<<<< HEAD + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Combining satellite data with tidal modelling \n", + "\n", + "* [**Sign up to the DEA Sandbox**](https://docs.dea.ga.gov.au/setup/sandbox.html) to run this notebook interactively from a browser\n", + "* **Compatibility:** Notebook currently compatible with the `DEA Sandbox` environment only\n", + "* **Products used:** \n", + "[ga_ls8c_ard_3](https://explorer.sandbox.dea.ga.gov.au/ga_ls8c_ard_3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Background\n", + "\n", + "Ocean tides are the periodic rise and fall of the ocean caused by the gravitational pull of the moon and sun and the earth's rotation. \n", + "Tides in coastal areas can greatly influence how these environments appear in satellite imagery as water levels vary by up to 12 metres (e.g. in north-western Australia).\n", + "To be able to study coastal environments and processes along Australia's coastline, it is vital to obtain data on tidal conditions at the exact moment each satellite image was acquired.\n", + "\n", + "## Description\n", + "This notebook demonstrates how to combine remotely sensed imagery with information about ocean tides using functions from the [`dea_tools.coastal` module](../Tools/dea_tools/coastal.py), allowing us to analyse satellite imagery by tidal stage (e.g. low, high, ebb, flow). \n", + "These functions use the [Finite Element Solution 2014 (FES2014) tidal model](https://os.copernicus.org/articles/17/615/2021/) to calculate the height (relative to mean sea level, i.e. approximately equivalent to the Australian Height Datum or AHD) and stage of the tide at the exact moment each satellite image was acquired. \n", + "\n", + "These tide modelling tools and tide models underpin DEA products including [DEA Coastlines](https://cmi.ga.gov.au/data-products/dea/581/dea-coastlines#basics), [DEA Intertidal Extents (ITEM)](http://dx.doi.org/10.4225/25/5a602cc9eb358), [DEA High Low Tide Imagery (HLTC)](http://dx.doi.org/10.4225/25/5a615705d20f7), and [DEA Intertidal Elevation (NIDEM)](http://dx.doi.org/10.26186/5c4fc06a79f76).\n", + "\n", + "The notebook demonstrates how to:\n", + "\n", + "1. Model tide heights for specific coordinates and times using the `model_tides` function\n", + "2. Model tide heights for each satellite observation using the `tidal_tag` function\n", + "3. Use tide height data to produce median composites of the coast at low and high tide\n", + "4. Swap a dataset's dimensions to make it easier to select imagery from low to high tide.\n", + "5. Compute ebb or flow tide phase data to determine whether water levels were rising or falling in each satellite observation\n", + "\n", + "Advanced tools:\n", + "\n", + "6. Spatially model tides into each pixel of a satellite dataset using `pixel_tides`\n", + "7. Evaluate potential biases in the tidal conditions observed by a satellite using the `tidal_stats` function\n", + "\n", + "***" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Getting started\n", + "To run this analysis, run all the cells in the notebook, starting with the \"Load packages\" cell. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Load packages\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import datacube\n", + "import xarray as xr\n", + "import pandas as pd\n", + "import matplotlib.pyplot as plt\n", + "\n", + "import sys\n", + "\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.coastal import model_tides, tidal_tag, pixel_tides, tidal_stats\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Connect to the datacube\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "dc = datacube.Datacube(app='Tidal_modelling')\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Modelling tides for specific coordinates and times\n", + "To simply model tide heights for a specific location and set of times, we can use the `dea_tools.coastal.model_tides` function. \n", + "For example, we can model hourly tides across a one month period (September 2022):" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + " | x | \n", + "y | \n", + "tide_m | \n", + "
---|---|---|---|
time | \n", + "\n", + " | \n", + " | \n", + " |
2022-09-01 00:00:00 | \n", + "122.21 | \n", + "-18.2 | \n", + "-3.606787 | \n", + "
2022-09-01 01:00:00 | \n", + "122.21 | \n", + "-18.2 | \n", + "-2.470167 | \n", + "
2022-09-01 02:00:00 | \n", + "122.21 | \n", + "-18.2 | \n", + "-0.675034 | \n", + "
2022-09-01 03:00:00 | \n", + "122.21 | \n", + "-18.2 | \n", + "1.140802 | \n", + "
2022-09-01 04:00:00 | \n", + "122.21 | \n", + "-18.2 | \n", + "2.591887 | \n", + "
<xarray.Dataset>\n", + "Dimensions: (time: 136, y: 550, x: 564)\n", + "Coordinates:\n", + " * time (time) datetime64[ns] 2019-01-01T01:55:10.045362 ... 2021-12...\n", + " * y (y) float64 7.806e+06 7.806e+06 ... 7.789e+06 7.789e+06\n", + " * x (x) float64 -2.197e+06 -2.197e+06 ... -2.181e+06 -2.181e+06\n", + " spatial_ref int32 32755\n", + "Data variables:\n", + " nbart_red (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " nbart_green (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " nbart_blue (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + "Attributes:\n", + " crs: EPSG:32755\n", + " grid_mapping: spatial_ref
<xarray.Dataset>\n", + "Dimensions: (time: 136, y: 550, x: 564)\n", + "Coordinates:\n", + " * time (time) datetime64[ns] 2019-01-01T01:55:10.045362 ... 2021-12...\n", + " * y (y) float64 7.806e+06 7.806e+06 ... 7.789e+06 7.789e+06\n", + " * x (x) float64 -2.197e+06 -2.197e+06 ... -2.181e+06 -2.181e+06\n", + " spatial_ref int32 32755\n", + "Data variables:\n", + " nbart_red (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " nbart_green (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " nbart_blue (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " tide_m (time) float64 -0.3249 -0.6027 -0.2904 ... 2.083 -0.9091\n", + "Attributes:\n", + " crs: EPSG:32755\n", + " grid_mapping: spatial_ref
<xarray.Dataset>\n", + "Dimensions: (tide_m: 136, y: 550, x: 564)\n", + "Coordinates:\n", + " * y (y) float64 7.806e+06 7.806e+06 ... 7.789e+06 7.789e+06\n", + " * x (x) float64 -2.197e+06 -2.197e+06 ... -2.181e+06 -2.181e+06\n", + " spatial_ref int32 32755\n", + " * tide_m (tide_m) float64 -2.407 -2.372 -2.244 ... 3.562 3.739 3.787\n", + "Data variables:\n", + " nbart_red (tide_m, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " nbart_green (tide_m, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " nbart_blue (tide_m, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + "Attributes:\n", + " crs: EPSG:32755\n", + " grid_mapping: spatial_ref
<xarray.Dataset>\n", + "Dimensions: (time: 136, y: 550, x: 564)\n", + "Coordinates:\n", + " * time (time) datetime64[ns] 2019-01-01T01:55:10.045362 ... 2021-12...\n", + " * y (y) float64 7.806e+06 7.806e+06 ... 7.789e+06 7.789e+06\n", + " * x (x) float64 -2.197e+06 -2.197e+06 ... -2.181e+06 -2.181e+06\n", + " spatial_ref int32 32755\n", + "Data variables:\n", + " nbart_red (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " nbart_green (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " nbart_blue (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " tide_m (time) float64 -0.3249 -0.6027 -0.2904 ... 2.083 -0.9091\n", + " ebb_flow (time) <U4 'Ebb' 'Flow' 'Ebb' 'Flow' ... 'Flow' 'Ebb' 'Flow'\n", + "Attributes:\n", + " crs: EPSG:32755\n", + " grid_mapping: spatial_ref
\n", + " | tide_m | \n", + "ebb_flow | \n", + "
---|---|---|
time | \n", + "\n", + " | \n", + " |
2019-01-01 01:55:10.045362 | \n", + "-0.324911 | \n", + "Ebb | \n", + "
2019-01-10 01:49:22.019554 | \n", + "-0.602660 | \n", + "Flow | \n", + "
2019-01-17 01:55:07.420345 | \n", + "-0.290403 | \n", + "Ebb | \n", + "
2019-01-26 01:49:18.114348 | \n", + "-2.161653 | \n", + "Flow | \n", + "
2019-02-02 01:55:03.684910 | \n", + "1.490913 | \n", + "Flow | \n", + "
... | \n", + "... | \n", + "... | \n", + "
2021-11-22 01:55:38.241313 | \n", + "1.183009 | \n", + "Flow | \n", + "
2021-12-01 01:49:52.530438 | \n", + "0.991971 | \n", + "Ebb | \n", + "
2021-12-08 01:55:39.297251 | \n", + "-0.505351 | \n", + "Flow | \n", + "
2021-12-17 01:49:51.085894 | \n", + "2.083131 | \n", + "Ebb | \n", + "
2021-12-24 01:55:35.785667 | \n", + "-0.909079 | \n", + "Flow | \n", + "
136 rows × 2 columns
\n", + "" + ], + "text/plain": [ + " tide_m ebb_flow\n", + "time \n", + "2019-01-01 01:55:10.045362 -0.324911 Ebb\n", + "2019-01-10 01:49:22.019554 -0.602660 Flow\n", + "2019-01-17 01:55:07.420345 -0.290403 Ebb\n", + "2019-01-26 01:49:18.114348 -2.161653 Flow\n", + "2019-02-02 01:55:03.684910 1.490913 Flow\n", + "... ... ...\n", + "2021-11-22 01:55:38.241313 1.183009 Flow\n", + "2021-12-01 01:49:52.530438 0.991971 Ebb\n", + "2021-12-08 01:55:39.297251 -0.505351 Flow\n", + "2021-12-17 01:49:51.085894 2.083131 Ebb\n", + "2021-12-24 01:55:35.785667 -0.909079 Flow\n", + "\n", + "[136 rows x 2 columns]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ds_tidal[['time', 'tide_m', 'ebb_flow']].to_dataframe().drop('spatial_ref',\n", + " axis=1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We could for example use this data to filter our observations to keep ebbing phase observations only:" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "<xarray.Dataset>\n", + "Dimensions: (time: 43, y: 550, x: 564)\n", + "Coordinates:\n", + " * time (time) datetime64[ns] 2019-01-01T01:55:10.045362 ... 2021-12...\n", + " * y (y) float64 7.806e+06 7.806e+06 ... 7.789e+06 7.789e+06\n", + " * x (x) float64 -2.197e+06 -2.197e+06 ... -2.181e+06 -2.181e+06\n", + " spatial_ref int32 32755\n", + "Data variables:\n", + " nbart_red (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " nbart_green (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " nbart_blue (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " tide_m (time) float64 -0.3249 -0.2904 0.5182 ... 1.136 0.992 2.083\n", + " ebb_flow (time) object 'Ebb' 'Ebb' 'Ebb' 'Ebb' ... 'Ebb' 'Ebb' 'Ebb'\n", + "Attributes:\n", + " crs: EPSG:32755\n", + " grid_mapping: spatial_ref
<xarray.Dataset>\n", + "Dimensions: (time: 5, y: 550, x: 564)\n", + "Coordinates:\n", + " * time (time) datetime64[ns] 2019-01-10T01:49:22.019554 ... 2019-02...\n", + " * y (y) float64 7.806e+06 7.806e+06 ... 7.789e+06 7.789e+06\n", + " * x (x) float64 -2.197e+06 -2.197e+06 ... -2.181e+06 -2.181e+06\n", + " spatial_ref int32 32755\n", + "Data variables:\n", + " nbart_red (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " nbart_green (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " nbart_blue (time, y, x) float32 dask.array<chunksize=(1, 550, 564), meta=np.ndarray>\n", + " tide_m (time, y, x) float32 -0.5751 -0.5753 -0.5754 ... -1.923 -1.923\n", + " ebb_flow (time) <U4 'Flow' 'Ebb' 'Flow' 'Flow' 'Flow'\n", + "Attributes:\n", + " crs: EPSG:32755\n", + " grid_mapping: spatial_ref