{ "cells": [ { "cell_type": "markdown", "id": "03046ab4", "metadata": {}, "source": [ "# Analyzing hysteresis loops using the *General T-Q SOM*\n", "This tutorial will demonstrate a basic workflow for analyzing suspended sediment transport hysteresis loops using the pre-trained *General T-Q SOM*. For details on how this SOM was trained, check out our [research paper](https://egusphere.copernicus.org/preprints/2025/egusphere-2025-2146/). \n", "The workflow will be illustrated using a time series of discharge and turbidity for which a set of hydrologic events where previously delineated. \n", " \n", "Beyond `HySOM` (and its dependencies: `numpy`, `matplotlib` and `numba`), `Pandas` is required to run this notebook, so make sure you have it installed." ] }, { "cell_type": "code", "execution_count": null, "id": "1e4e86c3", "metadata": {}, "outputs": [], "source": [ "from hysom.utils.datasets import get_01191000_qt_data, get_01191000_events_data\n", "from hysom.utils.plots import heat_map, heatmap_frequency\n", "from hysom.pretrainedSOM import get_generalTQSOM\n", "from dataclasses import dataclass, field\n", "import matplotlib.pyplot as plt\n", "from datetime import datetime\n", "import numpy.typing as npt \n", "from typing import Any \n", "import pandas as pd\n", "import numpy as np" ] }, { "cell_type": "markdown", "id": "da854b17", "metadata": {}, "source": [ "## Load data\n", "First, let's load a sample dataset included in the `HySOM` package. The dataset contains two main pices of data: \n", "\n", "\n", "1. `qt`: Pandas dataframe with time series data of discharge and turbidity\n", "2. `event_times`: list of (`start`,`end`) times for each event" ] }, { "cell_type": "code", "execution_count": 29, "id": "9258b9e8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "253 events. First 5:\n", "(datetime.datetime(2016, 6, 4, 8, 8, 46, tzinfo=datetime.timezone.utc), datetime.datetime(2016, 6, 9, 6, 2, 42, tzinfo=datetime.timezone.utc))\n", "(datetime.datetime(2016, 6, 9, 19, 8, 42, tzinfo=datetime.timezone.utc), datetime.datetime(2016, 6, 14, 17, 2, 39, tzinfo=datetime.timezone.utc))\n", "(datetime.datetime(2016, 6, 29, 8, 33, 29, tzinfo=datetime.timezone.utc), datetime.datetime(2016, 7, 4, 6, 27, 25, tzinfo=datetime.timezone.utc))\n", "(datetime.datetime(2016, 7, 6, 15, 57, 4, tzinfo=datetime.timezone.utc), datetime.datetime(2016, 7, 9, 9, 27, 2, tzinfo=datetime.timezone.utc))\n", "(datetime.datetime(2016, 7, 9, 11, 16, 12, tzinfo=datetime.timezone.utc), datetime.datetime(2016, 7, 11, 20, 34, 55, tzinfo=datetime.timezone.utc))\n", "\n", "Time Series:\n" ] }, { "data": { "text/html": [ "
| \n", " | Qcms | \n", "turb | \n", "
|---|---|---|
| datetime | \n", "\n", " | \n", " |
| 2016-05-31 21:15:00+00:00 | \n", "0.387941 | \n", "2.4 | \n", "
| 2016-05-31 21:30:00+00:00 | \n", "0.387941 | \n", "2.5 | \n", "
| 2016-05-31 21:45:00+00:00 | \n", "0.370951 | \n", "2.3 | \n", "
| 2016-05-31 22:00:00+00:00 | \n", "0.370951 | \n", "2.3 | \n", "
| 2016-05-31 22:15:00+00:00 | \n", "0.370951 | \n", "2.3 | \n", "