Adding surface water levels#

Developed by R.A. Collenteur & D. Brakenhoff

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.

import pandas as pd

import pastas as ps

ps.show_versions()
ps.set_log_level("INFO")
Pastas version: 1.13.2
Python version: 3.11.12
NumPy version: 2.3.5
Pandas version: 2.3.3
SciPy version: 1.17.0
Matplotlib version: 3.10.8
Numba version: 0.63.1

1. import and plot data#

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.

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].

oseries = pd.read_csv("data/nb5_head.csv", parse_dates=True, index_col=0).squeeze()
rain = pd.read_csv("data/nb5_prec.csv", parse_dates=True, index_col=0).squeeze()
evap = pd.read_csv("data/nb5_evap.csv", parse_dates=True, index_col=0).squeeze()
waterlevel = pd.read_csv("data/nb5_riv.csv", parse_dates=True, index_col=0).squeeze()

ps.plots.series(oseries, [rain, evap, waterlevel], figsize=(10, 5), hist=False);
../_images/c4c5d27fa216177b5e466c4cbaf6dc943b9e1c191ab42c51316f9bf2161f1d6e.png

2. Create a timeseries model#

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.

ml = ps.Model(oseries.resample("D").mean().dropna(), name="River")
ml.add_noisemodel(ps.ArNoiseModel())

sm = ps.RechargeModel(rain, evap, rfunc=ps.Exponential(), name="recharge")
ml.add_stressmodel(sm)

ml.solve(tmin="2000", tmax="2019-10-29")
ml.plots.results(figsize=(12, 8));
Fit report River                     Fit Statistics
===================================================
nfev     19                     EVP           38.60
nobs     5963                   R2             0.39
noise    True                   RMSE           0.46
tmin     2000-01-27 00:00:00    AICc      -30348.81
tmax     2019-10-29 00:00:00    BIC       -30315.36
freq     D                      Obj           18.34
freq_obs None                   ___                
warmup   3650 days 00:00:00     Interp.          No
solver   LeastSquares           weights         Yes

Parameters (5 optimized)
===================================================
                optimal     initial  vary
recharge_A   502.962225  183.785267  True
recharge_a   212.211700   10.000000  True
recharge_f    -1.602030   -1.000000  True
constant_d     8.543667    8.547142  True
noise_alpha   67.006577    1.000000  True
../_images/aead6f743c5788bcecc37c6119b2fbc565b96719f8078871b1ec64a2266064ca.png

3. Adding river water levels#

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.

w = ps.StressModel(waterlevel, rfunc=ps.One(), name="waterlevel", settings="waterlevel")
ml.add_stressmodel(w)
ml.solve(tmin="2000", tmax="2019-10-29")
axes = ml.plots.results(figsize=(12, 8))
axes[-1].set_xlim(0, 10);  # By default, the axes between responses are shared.
Fit report River                     Fit Statistics
===================================================
nfev     16                     EVP           93.39
nobs     5963                   R2             0.93
noise    True                   RMSE           0.15
tmin     2000-01-27 00:00:00    AICc      -39083.23
tmax     2019-10-29 00:00:00    BIC       -39043.08
freq     D                      Obj            4.24
freq_obs None                   ___                
warmup   3650 days 00:00:00     Interp.          No
solver   LeastSquares           weights         Yes

Parameters (6 optimized)
===================================================
                 optimal     initial  vary
recharge_A    206.350313  183.785267  True
recharge_a    166.832790   10.000000  True
recharge_f     -1.265414   -1.000000  True
waterlevel_d    0.422351    1.000000  True
constant_d      8.477395    8.547142  True
noise_alpha    32.223426    1.000000  True
../_images/902dbb5ef9edfe93a5d82233929d793498df71493eddf51f9b9955a4ab5b64ab.png

4. Normalizing river water levels#

It can be helpful to normalize the river water levels by subtracting the mean or minimum water level value. Especially, when using a river level that is high above a certain datum (which is not the case in this example).