{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Adding surface water levels\n", "*Developed by R.A. Collenteur & D. Brakenhoff*\n", "\n", "In this example it is shown how to create a Pastas model that not only includes precipitation and evaporation, but also observed river levels. We will consider observed heads that are strongly influenced by river level, based on a visual interpretation of the raw data." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import pastas as ps\n", "import matplotlib.pyplot as plt\n", "\n", "ps.show_versions()\n", "ps.set_log_level(\"INFO\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. import and plot data\n", "Before a model is created, it is generally a good idea to try and visually interpret the raw data and think about possible relationship between the time series and hydrological variables. Below the different time series are plotted.\n", "\n", "The top plot shows the observed heads, with different observation frequencies and some gaps in the data. Below that the observed river levels, precipitation and evaporation are shown. Especially the river level show a clear relationship with the observed heads. Note however how the range in the river levels is about twice the range in the heads. Based on these observations, we would expect the the final step response of the head to the river level to be around 0.5 [m/m]. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "oseries = pd.read_csv(\"data/nb5_head.csv\", parse_dates=True, index_col=0).squeeze()\n", "rain = pd.read_csv(\"data/nb5_prec.csv\", parse_dates=True, index_col=0).squeeze()\n", "evap = pd.read_csv(\"data/nb5_evap.csv\", parse_dates=True, index_col=0).squeeze()\n", "waterlevel = pd.read_csv(\"data/nb5_riv.csv\", parse_dates=True, index_col=0).squeeze()\n", "\n", "ps.plots.series(oseries, [rain, evap, waterlevel], figsize=(10, 5), hist=False);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. Create a timeseries model\n", "First we create a model with precipitation and evaporation as explanatory time series. The results show that precipitation and evaporation can explain part of the fluctuations in the observed heads, but not all of them." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ml = ps.Model(oseries.resample(\"D\").mean().dropna(), name=\"River\")\n", "\n", "sm = ps.RechargeModel(rain, evap, rfunc=ps.Exponential(), name=\"recharge\")\n", "ml.add_stressmodel(sm)\n", "\n", "ml.solve(tmin=\"2000\", tmax=\"2019-10-29\")\n", "ml.plots.results(figsize=(12, 8));" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Adding river water levels\n", "Based on the analysis of the raw data, we expect that the river levels can help to explain the fluctuations in the observed heads. Here, we add a stress model (`ps.StressModel`) to add the rivers level as an explanatory time series to the model. The model fit is greatly improved, showing that the rivers help in explaining the observed fluctuations in the observed heads. It can also be observed how the response of the head to the river levels is a lot faster than the response to precipitation and evaporation." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "w = ps.StressModel(waterlevel, rfunc=ps.One(), name=\"waterlevel\", settings=\"waterlevel\")\n", "ml.add_stressmodel(w)\n", "ml.solve(tmin=\"2000\", tmax=\"2019-10-29\")\n", "axes = ml.plots.results(figsize=(12, 8))\n", "axes[-1].set_xlim(0, 10); # By default, the axes between responses are shared." ] } ], "metadata": { "kernelspec": { "display_name": "pastas_dev", "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.9.15 | packaged by conda-forge | (main, Nov 22 2022, 08:41:22) [MSC v.1929 64 bit (AMD64)]" }, "vscode": { "interpreter": { "hash": "29475f8be425919747d373d827cb41e481e140756dd3c75aa328bf3399a0138e" } } }, "nbformat": 4, "nbformat_minor": 4 }