Skip to content

Commit d3a7501

Browse files
committed
Merge branch 'develop'
2 parents 869e702 + 7e37ada commit d3a7501

File tree

4 files changed

+120
-34
lines changed

4 files changed

+120
-34
lines changed

docs/conf.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
# add these directories to sys.path here. If the directory is relative to the
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
#
13-
# import os
14-
# import sys
15-
# sys.path.insert(0, os.path.abspath('.'))
13+
import os
14+
import sys
15+
16+
sys.path.insert(0, os.path.abspath("../py_wave_runup/"))
1617

1718

1819
# -- Project information -----------------------------------------------------
@@ -26,11 +27,10 @@
2627

2728

2829
# -- General configuration ---------------------------------------------------
29-
3030
# Add any Sphinx extension module names here, as strings. They can be
3131
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3232
# ones.
33-
extensions = []
33+
extensions = ["sphinx.ext.autodoc"]
3434

3535
# Add any paths that contain templates here, relative to this directory.
3636
templates_path = ["_templates"]
@@ -43,6 +43,10 @@
4343
# The master toctree document.
4444
master_doc = "index"
4545

46+
source_suffix = ".rst"
47+
autoclass_content = "both"
48+
49+
4650
# -- Options for HTML output -------------------------------------------------
4751

4852
# The theme to use for HTML and HTML Help pages. See the documentation for
@@ -54,3 +58,15 @@
5458
# relative to this directory. They are copied after the builtin static files,
5559
# so a file named "default.css" will overwrite the builtin "default.css".
5660
html_static_path = ["_static"]
61+
62+
pygments_style = "sphinx"
63+
64+
65+
def autodoc_skip_member(app, what, name, obj, skip, options):
66+
exclusions = ("RunupModel",)
67+
exclude = name in exclusions
68+
return skip or exclude
69+
70+
71+
def setup(app):
72+
app.connect("autodoc-skip-member", autodoc_skip_member)

docs/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Welcome to py-wave-runup's documentation!
1010
:maxdepth: 2
1111
:caption: Contents:
1212

13+
.. automodule:: models
14+
:members:
15+
:undoc-members:
1316

1417

1518
Indices and tables

py_wave_runup/models.py

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,97 @@
1+
from abc import ABCMeta, abstractmethod
2+
13
import numpy as np
24

35

4-
class Stockdon2006(object):
6+
class RunupModel(object):
57
"""
6-
Empirical wave runup model as per Stockdon et al. (2006).
7-
DOI: 10.1016/j.coastaleng.2005.12.005
8+
Abstract base class which our empirical runup models will inherit from
89
"""
910

10-
def __init__(self, Hs, beta, Lp=None, Tp=None):
11+
__metaclass__ = ABCMeta
12+
13+
doi = None
14+
15+
def __init__(self, Hs=None, Tp=None, beta=None, Lp=None):
16+
"""
17+
Test
18+
19+
:param Hs: description
20+
:param Tp: description
21+
:param beta: description
22+
:param Lp: description
23+
"""
24+
25+
self.Hs = Hs
26+
self.Tp = Tp
27+
self.beta = beta
28+
self.Lp = Lp
1129

1230
# Ensure wave length or peak period is specified
1331
if all(v is None for v in [Lp, Tp]):
1432
raise ValueError("Expected either Lp or Tp args")
1533

34+
# Ensure input is atleast 1d numpy array, this is so we can handle lists,
35+
# arrays and floats.
36+
self.Hs = np.atleast_1d(Hs)
37+
self.beta = np.atleast_1d(beta)
38+
1639
# Calculate wave length if it hasn't been specified.
1740
if not Lp:
1841
self.Tp = np.atleast_1d(Tp)
1942
self.Lp = 9.81 * (self.Tp ** 2) / 2 / np.pi
2043
else:
2144
self.Lp = np.atleast_1d(Lp)
45+
self.Tp = np.sqrt(2 * np.pi * self.Lp / 9.81)
2246

23-
self.Hs = np.atleast_1d(Hs)
24-
self.beta = np.atleast_1d(beta)
47+
# Ensure arrays are of the same size
48+
if len(set(x.size for x in [self.Hs, self.Tp, self.beta, self.Lp])) != 1:
49+
raise ValueError("Input arrays are not the same length")
2550

2651
# Calculate Iribarren number. Need since there are different
2752
# parameterizations for dissipative and intermediate/reflective beaches.
2853
self.zeta = self.beta / (self.Hs / self.Lp) ** (0.5)
2954

55+
def _return_one_or_array(self, val):
56+
# If only calculating a single value, return a single value and not an array
57+
# with length one.
58+
if val.size == 1:
59+
return val.item()
60+
else:
61+
return val
62+
3063
@property
64+
@abstractmethod
3165
def R2(self):
66+
raise NotImplementedError
67+
68+
@property
69+
@abstractmethod
70+
def setup(self):
71+
raise NotImplementedError
72+
73+
@property
74+
@abstractmethod
75+
def sinc(self):
76+
raise NotImplementedError
77+
78+
@property
79+
@abstractmethod
80+
def sig(self):
81+
raise NotImplementedError
3282

83+
@property
84+
@abstractmethod
85+
def swash(self):
86+
raise NotImplementedError
87+
88+
89+
class Stockdon2006(RunupModel):
90+
91+
doi = "10.1016/j.coastaleng.2005.12.005"
92+
93+
@property
94+
def R2(self):
3395
# Generalized runup (Eqn 19)
3496
result = 1.1 * (
3597
0.35 * self.beta * (self.Hs * self.Lp) ** 0.5
@@ -63,10 +125,8 @@ def sig(self):
63125
result = self._return_one_or_array(result)
64126
return result
65127

66-
def _return_one_or_array(self, val):
67-
# If only calculating a single value, return a single value and not an array
68-
# with length one.
69-
if val.size == 1:
70-
return val.item()
71-
else:
72-
return val
128+
@property
129+
def swash(self):
130+
result = np.sqrt(self.sinc ** 2 + self.sig ** 2)
131+
result = self._return_one_or_array(result)
132+
return result

tests/test_models.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
from py_wave_runup import models
2-
import pytest
2+
from pytest import raises, approx
33

44

55
class TestStockdon2006(object):
66
def test_reflective(self):
77
model = models.Stockdon2006(Hs=4, Tp=11, beta=0.1)
8-
assert model.R2 == pytest.approx(2.54, abs=0.01)
9-
assert model.setup == pytest.approx(0.96, abs=0.01)
10-
assert model.sig == pytest.approx(1.65, abs=0.01)
11-
assert model.sinc == pytest.approx(2.06, abs=0.01)
8+
assert model.R2 == approx(2.54, abs=0.01)
9+
assert model.setup == approx(0.96, abs=0.01)
10+
assert model.sig == approx(1.65, abs=0.01)
11+
assert model.sinc == approx(2.06, abs=0.01)
12+
assert model.swash == approx(2.64, abs=0.01)
1213

1314
def test_dissipative(self):
1415
model = models.Stockdon2006(Hs=4, Tp=11, beta=0.001)
15-
assert model.R2 == pytest.approx(1.18, abs=0.01)
16-
assert model.setup == pytest.approx(0.0096, abs=0.01)
17-
assert model.sig == pytest.approx(1.65, abs=0.01)
18-
assert model.sinc == pytest.approx(0.02, abs=0.01)
16+
assert model.R2 == approx(1.18, abs=0.01)
17+
assert model.setup == approx(0.0096, abs=0.01)
18+
assert model.sig == approx(1.65, abs=0.01)
19+
assert model.sinc == approx(0.02, abs=0.01)
20+
assert model.swash == approx(1.65, abs=0.01)
1921

2022
def test_wave_length(self):
2123
model = models.Stockdon2006(Hs=4, Lp=200, beta=0.05)
22-
assert model.R2 == pytest.approx(1.69, 0.1)
24+
assert model.R2 == approx(1.69, 0.1)
2325

2426
def test_list_input(self):
2527
model = models.Stockdon2006(Hs=[1, 2], Lp=[100, 200], beta=[0.05, 0.1])
26-
assert model.R2 == pytest.approx((0.59, 1.84), abs=0.1)
27-
assert model.setup == pytest.approx((0.17, 0.70), abs=0.1)
28-
assert model.sig == pytest.approx((0.6, 1.2), abs=0.1)
29-
assert model.sinc == pytest.approx((0.37, 1.5), abs=0.1)
28+
assert model.R2 == approx((0.59, 1.84), abs=0.1)
29+
assert model.setup == approx((0.17, 0.70), abs=0.1)
30+
assert model.sig == approx((0.6, 1.2), abs=0.1)
31+
assert model.sinc == approx((0.37, 1.5), abs=0.1)
32+
assert model.swash == approx((0.71, 1.92), abs=0.01)
3033

3134
def test_no_wave_length(self):
32-
with pytest.raises(ValueError):
33-
models.Stockdon2006(Hs=4, beta=0.1)
35+
with raises(ValueError):
36+
models.Stockdon2006(Hs=1, beta=0.1)
37+
38+
def test_different_list_input(self):
39+
with raises(ValueError):
40+
models.Stockdon2006(Hs=[1, 2], Lp=[100, 200], beta=[0.1])

0 commit comments

Comments
 (0)