Skip to content

Commit 883ab37

Browse files
committed
Add gallery of examples
1 parent 93474ff commit 883ab37

File tree

10 files changed

+376
-31
lines changed

10 files changed

+376
-31
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ instance/
6565

6666
# Sphinx documentation
6767
docs/_build/
68+
docs/auto_examples/
6869

6970
# PyBuilder
7071
target/

docs/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ BUILDDIR = _build
1111
help:
1212
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
1313

14+
# Need to remove auto generated examples as well
15+
clean:
16+
rm -rf $(BUILDDIR)/*
17+
rm -rf auto_examples/
18+
1419
.PHONY: help Makefile
1520

1621
# Catch-all target: route all unknown targets to Sphinx using the new

docs/conf.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"sphinx.ext.mathjax",
3636
"sphinx.ext.napoleon",
3737
"sphinx.ext.autosummary",
38+
"sphinx_gallery.gen_gallery",
3839
]
3940

4041
# Add any paths that contain templates here, relative to this directory.
@@ -48,6 +49,12 @@
4849
# The master toctree document.
4950
master_doc = "index"
5051

52+
sphinx_gallery_conf = {
53+
"examples_dirs": "../examples", # path to your example scripts
54+
"gallery_dirs": "auto_examples", # path to where to save gallery generated output
55+
"download_all_examples": False,
56+
}
57+
5158
source_suffix = ".rst"
5259
autoclass_content = "both"
5360

@@ -66,10 +73,6 @@
6673

6774
pygments_style = "sphinx"
6875

69-
html_sidebars = {
70-
"**": ["globaltoc.html", "relations.html", "sourcelink.html", "searchbox.html"]
71-
}
72-
7376
html_sidebars = {
7477
"**": ["about.html", "navigation.html", "relations.html", "searchbox.html"]
7578
}

docs/datasets.rst

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Datasets
2+
=========
3+
4+
This module also includes a number of wave runup datasets which can be used to test or create your own wave runup model.
5+
6+
------------
7+
8+
.. automodule:: datasets
9+
:members:
10+
:undoc-members:

docs/index.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ Contents
3838
installation
3939
usage
4040
models
41-
42-
..
41+
datasets
42+
auto_examples/index
4343

examples/README.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Examples
2+
~~~~~~~~
3+
4+
Here we show examples of how to apply py-wave-runup in practice:

examples/plot_stockdon.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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

Comments
 (0)