diff --git a/Real_world_examples/Water_extent_sentinel_2-wofs.ipynb b/Real_world_examples/Water_extent_sentinel_2-wofs.ipynb new file mode 100644 index 000000000..fb3b9a9e7 --- /dev/null +++ b/Real_world_examples/Water_extent_sentinel_2-wofs.ipynb @@ -0,0 +1,1070 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Surface Water Detection using Water Observation from Space Algorithm on Sentinel-2 \n", + "* **Products used:** \n", + "[s2_l2a](https://explorer.digitalearth.africa/products/s2_l2a)," + ] + }, + { + "cell_type": "raw", + "metadata": { + "raw_mimetype": "text/restructuredtext" + }, + "source": [ + "**Keywords**: :index:`data used; sentinel-2`, :index:`water; extent`, :index:`analysis; WOfS Classifier`, " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Background\n", + "\n", + "Water Observations from Space (WOfS) is a service that uses satellite images to provide historical surface water observations. WOfS enables users to understand the location and movement of inland and coastal water over time. It shows where water is usually present; where it is seldom observed; and where inundation of the surface has been observed by satellite.\n", + "\n", + "The Water Observations from Space classification algorithm as described in Mueller et al. (2016), is applied to the Landsat dataset to create the available [WOfS products](https://docs.digitalearthafrica.org/en/latest/data_specs/Landsat_WOfS_specs.html). \n", + "\n", + "For this notebook, the WOfS classify will be applied to [Sentinel-2](https://docs.digitalearthafrica.org/en/latest/data_specs/Sentinel-2_Level-2A_specs.html) dataset instead of landsat imagery. \n", + "Although Sentinel-2 imagery have a high resolution as compare to Landsat, cloud masking of sentinel sometimes makes it hard to detect water as it seen as shadow therefore croping it out from the image. When running the notebook, be mindful of the area and take into consideration cloud masking." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Description\n", + "\n", + "The notebook demonstrates how to:\n", + "\n", + "1. Load and masking of satellite data over the water body of interest\n", + "2. Apply the WOfS algorithm on the dataset\n", + "3. Plot the results\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", + "Import Python packages that are used for the analysis." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/lib/python3.8/dist-packages/geopandas/_compat.py:112: UserWarning: The Shapely GEOS version (3.8.0-CAPI-1.13.1 ) is incompatible with the GEOS version PyGEOS was compiled with (3.10.3-CAPI-1.16.1). Conversions between both will be slow.\n", + " warnings.warn(\n" + ] + } + ], + "source": [ + "%matplotlib inline\n", + "\n", + "import datacube\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "import xarray as xr\n", + "\n", + "from deafrica_tools.datahandling import load_ard\n", + "from deafrica_tools.bandindices import calculate_indices\n", + "from deafrica_tools.plotting import display_map, rgb\n", + "from deafrica_tools.dask import create_local_dask_cluster\n", + "from deafrica_tools.wofsclassifier import wofs_classify" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Connect to the datacube\n", + "\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='water_extent_s2_classifier')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Set up a Dask cluster\n", + "\n", + "Dask can be used to better manage memory use and conduct the analysis in parallel. \n", + "For an introduction to using Dask with Digital Earth Africa, see the [Dask notebook](../Beginners_guide/08_Parallel_processing_with_dask.ipynb).\n", + "\n", + ">**Note**: We recommend opening the Dask processing window to view the different computations that are being executed; to do this, see the *Dask dashboard in DE Africa* section of the [Dask notebook](../Beginners_guide/08_Parallel_processing_with_dask.ipynb).\n", + "\n", + "To activate Dask, set up the local computing cluster using the cell below." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n",
+ "Client\n", + "
| \n",
+ "\n",
+ "Cluster\n", + "
| \n",
+ "