|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +""" |
| 3 | +Assessing Stockdon et al (2006) runup model |
| 4 | +=========================================== |
| 5 | +
|
| 6 | +
|
| 7 | +In this example, we will evaluate the accuracy of the Stockdon et al (2006) runup |
| 8 | +model, using the Power et al (2018) dataset. |
| 9 | +
|
| 10 | +The Stockdon et al (2006) model looks like: |
| 11 | +
|
| 12 | +For dissipative beaches (i.e. :math:`\\zeta < 0.3`) Eqn (18) from the paper is used: |
| 13 | +
|
| 14 | +.. math:: R_{2} = 0.043(H_{s}L_{p})^{0.5} |
| 15 | +
|
| 16 | +For intermediate and reflective beaches (i.e. :math:`\\zeta > 0.3`), the function |
| 17 | +returns the result from Eqn (19): |
| 18 | +
|
| 19 | +.. math:: |
| 20 | +
|
| 21 | + R_{2} = 1.1 \\left( 0.35 \\beta (H_{s}L_{p})^{0.5} + \\frac{H_{s}L_{p}( |
| 22 | + 0.563 \\beta^{2} +0.004)^{0.5}}{2} \\right) |
| 23 | +
|
| 24 | +First, let's import the Power et al (2018) runup data, which is included in this |
| 25 | +package. |
| 26 | +""" |
| 27 | +import py_wave_runup |
| 28 | + |
| 29 | +df = py_wave_runup.datasets.load_power18() |
| 30 | +print(df.head()) |
| 31 | + |
| 32 | +############################################# |
| 33 | +# We can see that this dataset gives us :math:`H_{s}` (significant wave height), |
| 34 | +# :math:`T_{p}` (peak wave period), :math:`\tan \beta` (beach slope). Let's import |
| 35 | +# the Stockdon runup model and calculate the estimated :math:`R_{2}` runup value for |
| 36 | +# each row in this dataset. |
| 37 | + |
| 38 | +# Initalize the Stockdon 2006 model with values from the dataset |
| 39 | +sto06 = py_wave_runup.models.Stockdon2006(Hs=df.hs, Tp=df.tp, beta=df.beta) |
| 40 | + |
| 41 | +# Append a new column at the end of our dataset with Stockdon 2006 R2 estimations |
| 42 | +df["sto06_r2"] = sto06.R2 |
| 43 | + |
| 44 | +# Check the first few rows of observed vs. modelled R2 |
| 45 | +print(df[["r2", "sto06_r2"]].head()) |
| 46 | + |
| 47 | +############################################# |
| 48 | +# Let's now make a plot of observed vs. modelled R2 to assess performance |
| 49 | +import matplotlib.pyplot as plt |
| 50 | + |
| 51 | +fig, ax1 = plt.subplots(1, 1, figsize=(4, 4), dpi=300) |
| 52 | +ax1.plot(df.r2, df.sto06_r2, "b.", markersize=2, linewidth=0.5) |
| 53 | + |
| 54 | +# Add 1:1 line to indicate perfect fit |
| 55 | +ax1.plot([0, 12], [0, 12], "k-") |
| 56 | + |
| 57 | +# Add axis labels |
| 58 | +ax1.set_xlabel("Observed R2 (m)") |
| 59 | +ax1.set_ylabel("Modelled R2 (m)") |
| 60 | +ax1.set_title("Stockdon et al. (2006) Runup Model") |
| 61 | + |
| 62 | +plt.tight_layout() |
| 63 | + |
| 64 | +############################################# |
| 65 | +# Let's also check RMSE and coefficient of determination values: |
| 66 | + |
| 67 | +import numpy as np |
| 68 | +from sklearn.metrics import r2_score, mean_squared_error |
| 69 | + |
| 70 | +print(f"R2 Score: {r2_score(df.r2, df.sto06_r2):.2f}") |
| 71 | +print(f"RMSE: {np.sqrt(mean_squared_error(df.r2, df.sto06_r2)):.2f} m") |
0 commit comments