# Modeling snow#

R.A. Collenteur, University of Graz / Eawag, November 2021

In this notebook it is shown how to account for snowfall and smowmelt on groundwater recharge and groundwater levels, using a degree-day snow model. This notebook is work in progress and will be extended in the future.

[1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.signal import fftconvolve

import pastas as ps

ps.set_log_level("ERROR")
ps.show_versions()
Python version: 3.10.12
NumPy version: 1.23.5
Pandas version: 2.0.3
SciPy version: 1.11.1
Matplotlib version: 3.7.2
Numba version: 0.57.1
LMfit version: 1.2.2
Latexify version: Not Installed
Pastas version: 1.1.0

In this notebook we will look at some data for a well near Heby, Sweden. All the meteorological data is taken from the E-OBS database. As can be observed from the temperature time series, the temparature regularly drops below zero in winter. Given this observation, we may expect precipitation to (partially) fall as snow during these periods.

[2]:

## 2. Make a simple model#

First we create a simple model with precipitation and potential evaporation as input, using the non-linear FlexModel to compute the recharge flux. We not not yet take snowfall into account, and thus assume all precipitation occurs as snowfall. The model is calibrated and the results are visualized for inspection.

[3]:
# Settings
tmin = "1985"  # Needs warmup
tmax = "2010"
[4]:
sm1 = ps.RechargeModel(
prec, evap, recharge=ps.rch.FlexModel(), rfunc=ps.Gamma(), name="rch"
)

# As the evaporation used is a very rough estimation, vary k_v
ml1.set_parameter("rch_kv", vary=True)

# Solve the Pastas model in two steps
ml1.solve(tmin=tmin, tmax=tmax, noise=False, fit_constant=False, report=False)
ml1.set_parameter("rch_srmax", vary=False)
ml1.solve(tmin=tmin, tmax=tmax, noise=True, fit_constant=False, initial=False)
ml1.plot(figsize=(10, 3));
===================================================
nfev    44                     EVP            50.72
nobs    590                    R2              0.51
noise   True                   RMSE            0.12
tmin    1985-01-01 00:00:00    AIC         -3286.93
tmax    2010-01-01 00:00:00    BIC         -3256.27
freq    D                      Obj             1.10
warmup  3650 days 00:00:00     ___
solver  LeastSquares           Interp.           No

Parameters (7 optimized)
===================================================
optimal   stderr     initial   vary
rch_A          2.879375  ±17.44%    0.567641   True
rch_n          0.569413   ±3.45%    2.522391   True
rch_a        769.097528  ±28.03%   79.332435   True
rch_srmax    133.482701     ±nan  133.482701  False
rch_lp         0.250000     ±nan    0.250000  False
rch_ks         0.784156   ±7.06%  207.280418   True
rch_gamma      0.510672  ±14.76%    0.404587   True
rch_kv         0.703780   ±4.00%    0.889225   True
rch_simax      2.000000     ±nan    2.000000  False
constant_d    77.083916     ±nan    0.000000  False
noise_alpha   94.804408   ±7.02%    1.000000   True

The model fit with the data is not too bad, but we are clearly missing the highs and lows of the observed groundwater levels. This could have many causes, but in this case we may suspect that the occurence of snowfall and melt impacts the results.

## 3. Account for snowfall and snow melt#

A second model is now created that accounts for snowfall and melt through a degree-day snow model (see e.g., Kavetski & Kuczera (2007). To run the model we add the keyword snow=True to the FlexModel and provide a time series of mean daily temperature to the RechargeModel. The temperature time series is used to split the precipitation into snowfall and rainfall.

[5]:
sm2 = ps.RechargeModel(
prec,
evap,
recharge=ps.rch.FlexModel(snow=True),
rfunc=ps.Gamma(),
name="rch",
temp=temp,
)

# As the evaporation used is a very rough estimation, vary k_v
ml2.set_parameter("rch_kv", vary=True)

# Solve the Pastas model in two steps
ml2.solve(tmin=tmin, tmax=tmax, noise=False, fit_constant=False, report=False)
ml2.set_parameter("rch_srmax", vary=False)
ml2.solve(tmin=tmin, tmax=tmax, noise=True, fit_constant=False, initial=False)
===================================================
nfev    33                     EVP            59.77
nobs    590                    R2              0.60
noise   True                   RMSE            0.11
tmin    1985-01-01 00:00:00    AIC         -3378.05
tmax    2010-01-01 00:00:00    BIC         -3338.63
freq    D                      Obj             0.93
warmup  3650 days 00:00:00     ___
solver  LeastSquares           Interp.           No

Parameters (9 optimized)
===================================================
optimal   stderr     initial   vary
rch_A          1.117071   ±7.40%    1.036110   True
rch_n          1.234812   ±1.45%    1.086034   True
rch_a        193.739953   ±8.00%  268.205486   True
rch_srmax     17.932229     ±nan   17.932229  False
rch_lp         0.250000     ±nan    0.250000  False
rch_ks        12.195025   ±5.70%   49.851369   True
rch_gamma      4.609062  ±10.45%    5.705883   True
rch_kv         1.324237   ±5.80%    1.134200   True
rch_simax      2.000000     ±nan    2.000000  False
rch_tt         1.299998  ±12.42%    2.097848   True
rch_k          1.874149   ±8.96%    2.094073   True
constant_d    77.970383     ±nan    0.000000  False
noise_alpha   97.392227   ±6.53%    1.000000   True

## Compare results#

From the fit_report we can already observe that the model fit improved quite a bit. We can also visualize the results to see how the model improved.

[6]:
ax = ml2.plot(figsize=(10, 3))
ml1.simulate().plot(ax=ax)
plt.legend(
[
"Observations",
"Model w Snow NSE={:.2f}".format(ml2.stats.nse()),
"Model w/o Snow NSE={:.2f}".format(ml1.stats.nse()),
],
ncol=3,
)
[6]:
<matplotlib.legend.Legend at 0x7f88306a9570>

## Extract the water balance (States & Fluxes)#

[7]:
df = ml2.stressmodels["rch"].get_water_balance(
ml2.get_parameters("rch"), tmin=tmin, tmax=tmax
)
df.plot(subplots=True, figsize=(10, 10));

## References#

• Kavetski, D. and Kuczera, G. (2007). Model smoothing strategies to remove microscale discontinuities and spurious secondary optima in objective functions in hydrological calibration. Water Resources Research, 43(3).