From 6b19f6bcba8d8d219bc9c375375a1dbd29ab0736 Mon Sep 17 00:00:00 2001 From: Robbi Bishop-Taylor Date: Sun, 29 Sep 2024 13:31:40 +0000 Subject: [PATCH] Update notebooks --- docs/notebooks/Model_tides.ipynb | 229 +-------------- docs/notebooks/Satellite_data.ipynb | 400 +++++++++++++++++++++++++++ docs/notebooks/Tide_statistics.ipynb | 34 +++ eo_tides/validation.py | 2 +- mkdocs.yml | 4 +- 5 files changed, 450 insertions(+), 219 deletions(-) create mode 100644 docs/notebooks/Satellite_data.ipynb create mode 100644 docs/notebooks/Tide_statistics.ipynb diff --git a/docs/notebooks/Model_tides.ipynb b/docs/notebooks/Model_tides.ipynb index e71e615..16a2850 100644 --- a/docs/notebooks/Model_tides.ipynb +++ b/docs/notebooks/Model_tides.ipynb @@ -13,21 +13,6 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], - "source": [ - "from eo_tides.model import model_tides, pixel_tides\n", - "from eo_tides.validation import eval_metrics, load_gauge_gesla\n", - "import pandas as pd\n", - "import matplotlib.pyplot as plt\n", - "\n", - "%load_ext autoreload\n", - "%autoreload 2\n" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, "outputs": [ { "name": "stdout", @@ -42,7 +27,7 @@ "" ] }, - "execution_count": 2, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" }, @@ -58,6 +43,9 @@ } ], "source": [ + "from eo_tides.model import model_tides\n", + "import pandas as pd\n", + "\n", "modelled_df = model_tides(\n", " x=122.2186, \n", " y=-18.0008, \n", @@ -78,14 +66,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "/workspaces/eo-tides/.venv/lib/python3.10/site-packages/geopandas/array.py:403: UserWarning: Geometry is in a geographic CRS. Results from 'sjoin_nearest' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.\n", + "/workspaces/eo-tides/.venv/lib/python3.12/site-packages/geopandas/array.py:403: UserWarning: Geometry is in a geographic CRS. Results from 'sjoin_nearest' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.\n", "\n", " warnings.warn(\n", "/workspaces/eo-tides/eo_tides/validation.py:157: FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", @@ -381,12 +369,14 @@ "[5 rows x 26 columns]" ] }, - "execution_count": 3, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "from eo_tides.validation import eval_metrics, load_gauge_gesla\n", + "\n", "# Load gauge data, subtracting to observed mean sea level\n", "gauge_df = load_gauge_gesla(\n", " x=122.3186,\n", @@ -401,7 +391,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -416,7 +406,7 @@ "dtype: float64" ] }, - "execution_count": 4, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" }, @@ -437,201 +427,6 @@ "joined_df.plot.scatter(x=\"sea_level\", y=\"tide_m\")\n", "eval_metrics(x=joined_df.sea_level, y=joined_df.tide_m)" ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Combining satellite data with tides using `pixel_tides`\n", - "\n", - "### Load satellite data using STAC" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "import odc.stac\n", - "import pystac_client\n", - "\n", - "# Connect to stac catalogue\n", - "catalog = pystac_client.Client.open(\"https://explorer.dea.ga.gov.au/stac\")\n", - "\n", - "# Set cloud defaults\n", - "odc.stac.configure_rio(\n", - " cloud_defaults=True,\n", - " aws={\"aws_unsigned\": True},\n", - ")\n", - "\n", - "# Build a query with the parameters above\n", - "bbox = [122.2186 - 0.03, -18.0008 - 0.03, 122.2186 + 0.03, -18.0008 + 0.03]\n", - "query = catalog.search(\n", - " bbox=bbox,\n", - " collections=[\"ga_ls8c_ard_3\"],\n", - " datetime=\"2018-01-01/2018-01-31\",\n", - ")\n", - "\n", - "# Search the STAC catalog for all items matching the query\n", - "ds = odc.stac.load(\n", - " list(query.items()),\n", - " bands=[\"nbart_red\", \"nbart_green\", \"nbart_blue\"],\n", - " crs=\"utm\",\n", - " resolution=30,\n", - " groupby=\"solar_day\",\n", - " bbox=bbox,\n", - " fail_on_error=False,\n", - " chunks={},\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/workspaces/eo-tides/.venv/lib/python3.10/site-packages/rasterio/warp.py:344: NotGeoreferencedWarning: Dataset has no geotransform, gcps, or rpcs. The identity matrix will be returned.\n", - " _reproject(\n" - ] - }, - { - "data": { - "text/html": [ - "
Make this Notebook Trusted to load map: File -> Trust Notebook
" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ds.isel(time=0).odc.explore(vmin=0, vmax=2000)" - ] } ], "metadata": { @@ -650,7 +445,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.0" + "version": "3.12.1" } }, "nbformat": 4, diff --git a/docs/notebooks/Satellite_data.ipynb b/docs/notebooks/Satellite_data.ipynb new file mode 100644 index 0000000..27e6d87 --- /dev/null +++ b/docs/notebooks/Satellite_data.ipynb @@ -0,0 +1,400 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Combining with satellite data\n", + "\n", + "## Load satellite data using `odc-stac`\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/workspaces/eo-tides/.venv/lib/python3.12/site-packages/odc/geo/_rgba.py:56: RuntimeWarning: invalid value encountered in cast\n", + " return x.astype(\"uint8\")\n", + "/workspaces/eo-tides/.venv/lib/python3.12/site-packages/rasterio/warp.py:344: NotGeoreferencedWarning: Dataset has no geotransform, gcps, or rpcs. The identity matrix will be returned.\n", + " _reproject(\n" + ] + }, + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import odc.stac\n", + "import pystac_client\n", + "\n", + "# Connect to stac catalogue\n", + "catalog = pystac_client.Client.open(\"https://explorer.dea.ga.gov.au/stac\")\n", + "\n", + "# Set cloud defaults\n", + "odc.stac.configure_rio(\n", + " cloud_defaults=True,\n", + " aws={\"aws_unsigned\": True},\n", + ")\n", + "\n", + "# Build a query with the parameters above\n", + "bbox = [122.2186 - 0.05, -18.0008 - 0.05, 122.2186 + 0.05, -18.0008 + 0.05]\n", + "query = catalog.search(\n", + " bbox=bbox,\n", + " collections=[\"ga_ls8c_ard_3\"],\n", + " datetime=\"2024-01-01/2024-01-31\",\n", + ")\n", + "\n", + "# Search the STAC catalog for all items matching the query\n", + "ds = odc.stac.load(\n", + " list(query.items()),\n", + " bands=[\"nbart_red\", \"nbart_green\", \"nbart_blue\"],\n", + " crs=\"utm\",\n", + " resolution=30,\n", + " groupby=\"solar_day\",\n", + " bbox=bbox,\n", + " fail_on_error=False,\n", + " chunks={},\n", + ")\n", + "\n", + "ds.isel(time=0).odc.explore(vmin=0, vmax=2000)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Using `pixel_tides`\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Creating reduced resolution 5000 x 5000 metre tide modelling array\n", + "Modelling tides using FES2014 in parallel\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 5/5 [00:05<00:00, 1.03s/it]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Reprojecting tides into original array\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + }, + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from eo_tides.model import pixel_tides\n", + "\n", + "tides_highres, tides_lowres = pixel_tides(\n", + " ds=ds,\n", + " model=\"FES2014\",\n", + " directory=\"../../tests/data/tide_models_tests\"\n", + ")\n", + "\n", + "tides_highres.isel(time=0).odc.explore()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/docs/notebooks/Tide_statistics.ipynb b/docs/notebooks/Tide_statistics.ipynb new file mode 100644 index 0000000..5ad4e34 --- /dev/null +++ b/docs/notebooks/Tide_statistics.ipynb @@ -0,0 +1,34 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Calculating tide statistics and satellite biases\n", + "\n", + "## Using `tide_stats`" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/eo_tides/validation.py b/eo_tides/validation.py index 6036f61..3cd435f 100644 --- a/eo_tides/validation.py +++ b/eo_tides/validation.py @@ -158,7 +158,7 @@ def _load_gesla_dataset(site, path, na_value): path, skiprows=41, names=["date", "time", "sea_level", "qc_flag", "use_flag"], - sep="\s+", + sep=r"\s+", # sep="\s+", parse_dates=[[0, 1]], index_col=0, na_values=na_value, diff --git a/mkdocs.yml b/mkdocs.yml index f5385b2..37a0778 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -11,8 +11,10 @@ nav: - Home: index.md - Installation: install.md - Setting up tide models: setup.md - - Usage examples: + - Usage: - notebooks/Model_tides.ipynb + - notebooks/Satellite_data.ipynb + - notebooks/Tide_statistics.ipynb - Package: - API reference: api.md - Reference: