Skip to content

Commit

Permalink
Merge a439418 into 57da93d
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaselsteiner committed Jan 27, 2020
2 parents 57da93d + a439418 commit 16fa920
Show file tree
Hide file tree
Showing 11 changed files with 9,263 additions and 123 deletions.
8 changes: 4 additions & 4 deletions examples/calculate_contours_similar_to_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
dep0 = (None, None, None) # All three parameters are independent.

# Define a Lognormal distribution representing spectral peak period.
my_sigma = FunctionParam(0.05, 0.2, -0.2, "exp3")
my_mu = FunctionParam(0.1, 1.5, 0.2, "power3")
my_sigma = FunctionParam('exp3', 0.05, 0.2, -0.2)
my_mu = FunctionParam('power3', 0.1, 1.5, 0.2)
dist1 = LognormalDistribution(sigma=my_sigma, mu=my_mu)
dep1 = (0, None, 0) # Parameter one and three depend on dist0.

Expand All @@ -34,9 +34,9 @@

# Plot the two contours.
plt.scatter(hdens_contour.coordinates[0][0], hdens_contour.coordinates[0][1],
label="highest density contour")
label='highest density contour')
plt.scatter(iform_contour.coordinates[0][0], iform_contour.coordinates[0][1],
label="IFORM contour")
label='IFORM contour')
plt.xlabel('significant wave height [m]')
plt.ylabel('spectral peak period [s]')
plt.legend()
Expand Down
10 changes: 5 additions & 5 deletions examples/compare_contour_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
scale = ConstantParam(2.776)
dist0 = WeibullDistribution(shape, loc, scale)
dep0 = (None, None, None) # All three parameters are independent.
my_sigma = FunctionParam(0.040, 0.175, -0.224, "exp3")
my_mu = FunctionParam(0.100, 1.489, 0.190, "power3")
my_sigma = FunctionParam('exp3', 0.040, 0.175, -0.224)
my_mu = FunctionParam('power3', 0.100, 1.489, 0.190)
dist1 = LognormalDistribution(sigma=my_sigma, mu=my_mu)
dep1 = (0, None, 0) # Parameter one and three depend on dist0.
distributions = [dist0, dist1]
Expand All @@ -31,11 +31,11 @@

# Plot the three contours.
plt.scatter(hdens_contour.coordinates[0][0], hdens_contour.coordinates[0][1],
label="highest density contour")
label='highest density contour')
plt.scatter(iform_contour.coordinates[0][0], iform_contour.coordinates[0][1],
label="IFORM contour")
label='IFORM contour')
plt.scatter(isorm_contour.coordinates[0][0], isorm_contour.coordinates[0][1],
label="ISORM contour")
label='ISORM contour')
plt.xlabel('significant wave height [m]')
plt.ylabel('zero-upcrossing period [s]')
plt.legend()
Expand Down
100 changes: 75 additions & 25 deletions tests/test_contours.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def test_HDC2d_WL(self):
scale = ConstantParam(2.776)
par1 = (shape, loc, scale)

mu = FunctionParam(0.1000, 1.489, 0.1901, 'power3')
sigma = FunctionParam(0.0400, 0.1748, -0.2243, 'exp3')
mu = FunctionParam('power3', 0.1000, 1.489, 0.1901)
sigma = FunctionParam('exp3', 0.0400, 0.1748, -0.2243)

#del shape, loc, scale

Expand Down Expand Up @@ -82,8 +82,8 @@ def test_HDC2d_ExponentiatedWbl(self):
"""

# Define dependency tuple.
dep1 = (None, None, None, None)
dep2 = (None, None, 0, None)
dep1 = (None, None, None, None) # shape, location, scale, shape2
dep2 = (None, None, 0, None) # shape, location, scale, shape2

# Define parameters.
v_shape = ConstantParam(11)
Expand All @@ -94,7 +94,7 @@ def test_HDC2d_ExponentiatedWbl(self):

hs_shape = ConstantParam(1.4)
hs_loc = None
hs_scale = FunctionParam(0.15, 0.0033, 2.45, 'power3')
hs_scale = FunctionParam('power3', 0.15, 0.0033, 2.45)
hs_shape2 = ConstantParam(5)
par2 = (hs_shape, hs_loc, hs_scale, hs_shape2)

Expand Down Expand Up @@ -123,6 +123,56 @@ def test_HDC2d_ExponentiatedWbl(self):
# self.assertAlmostEqual(result0.loc[g, h], contour_coordinates.loc[g, h], places=8)


def test_omae2020_wind_wave_contour(self):
"""
Contour similar to the wind-wave contour in 'Global hierararchical models
for wind and wave contours', dataset D. First variable = wind speed,
second variable = significant wave height.
"""

# Define dependency tuple.
dep1 = (None, None, None, None) # shape, location, scale, shape2
dep2 = (0, None, 0, None) # shape, location, scale, shape2

# Define parameters.
v_shape = ConstantParam(2.42)
v_loc = None
v_scale = ConstantParam(10)
v_shape2 = ConstantParam(0.761)
par1 = (v_shape, v_loc, v_scale, v_shape2)

hs_shape = FunctionParam('logistics4', 0.582, 1.90, 0.248, 8.49)
hs_loc = None
hs_scale = FunctionParam('alpha3', 0.394, 0.0178, 1.88,
C1=0.582, C2=1.90, C3=0.248, C4=8.49)

hs_shape2 = ConstantParam(5)
par2 = (hs_shape, hs_loc, hs_scale, hs_shape2)

# Create distributions.
dist1 = ExponentiatedWeibullDistribution(*par1)
dist2 = ExponentiatedWeibullDistribution(*par2)

distributions = [dist1, dist2]
dependencies = [dep1, dep2]

mul_dist = MultivariateDistribution(distributions, dependencies)

# Calculate the contour.
n_years = 50
limits = [(0, 40), (0, 20)]
deltas = [0.1, 0.1]
test_contour_HDC = HighestDensityContour(mul_dist, n_years, 1,
limits, deltas)

# Compare the computed contours to the contours published in
# 'Global hierarchical models for wind and wave contours', Figure 8.
max_v = max(test_contour_HDC.coordinates[0][0])
self.assertAlmostEqual(max_v, 29.5, delta=0.5) # Should be about 29.5
max_hs = max(test_contour_HDC.coordinates[0][1])
self.assertAlmostEqual(max_hs, 14.5, delta=0.5) # Should be about 15


def test_HDC3d_WLL(self):
"""
Creating Contour example for 3-d HDC with Weibull, Lognormal and
Expand All @@ -139,8 +189,8 @@ def test_HDC3d_WLL(self):
scale = ConstantParam(2.776)
par1 = (shape, loc, scale)

mu = FunctionParam(0.1000, 1.489, 0.1901, "power3")
sigma = FunctionParam(0.0400, 0.1748, -0.2243, "exp3")
mu = FunctionParam('power3', 0.1000, 1.489, 0.1901)
sigma = FunctionParam('exp3', 0.0400, 0.1748, -0.2243)


#del shape, loc, scale
Expand Down Expand Up @@ -192,8 +242,8 @@ def test_HDC4d_WLLL(self):
scale = ConstantParam(0.8888)
par1 = (shape, loc, scale)

mu = FunctionParam(0.1000, 1.489, 0.1901, "power3")
sigma = FunctionParam(0.0400, 0.1748, -0.2243, "exp3")
mu = FunctionParam('power3', 0.1000, 1.489, 0.1901)
sigma = FunctionParam('exp3', 0.0400, 0.1748, -0.2243)

#create distributions
dist1 = WeibullDistribution(*par1)
Expand Down Expand Up @@ -235,8 +285,8 @@ def test_HDC2d_WN(self):
par1 = (shape, loc, scale)

shape = None
loc = FunctionParam(4, 10, 0.02, "power3")
scale = FunctionParam(0.1, 0.02, -0.1, "exp3")
loc = FunctionParam('power3', 4, 10, 0.02)
scale = FunctionParam('exp3', 0.1, 0.02, -0.1)
par2 = (shape, loc, scale)

#del shape, loc, scale
Expand Down Expand Up @@ -281,12 +331,12 @@ def test_HDC3d_WLN(self):
par1 = (shape, loc, scale)

shape = None
loc = FunctionParam(4, 10, 0.02, "power3")
scale = FunctionParam(0.1, 0.02, -0.1, "exp3")
loc = FunctionParam('power3', 4, 10, 0.02)
scale = FunctionParam('exp3', 0.1, 0.02, -0.1)
par2 = (shape, loc, scale)

mu = FunctionParam(0.1, 1.5, 0.2, "power3")
sigma = FunctionParam(0.1, 0.2, -0.2, "exp3")
mu = FunctionParam('power3', 0.1, 1.5, 0.2)
sigma = FunctionParam('exp3', 0.1, 0.2, -0.2)

#create distributions
dist1 = WeibullDistribution(*par1)
Expand Down Expand Up @@ -335,8 +385,8 @@ def test_IForm2d_WL(self):
scale = ConstantParam(2.776)
par1 = (shape, loc, scale)

mu = FunctionParam(0.1000, 1.489, 0.1901, "power3")
sigma = FunctionParam(0.0400, 0.1748, -0.2243, "exp3")
mu = FunctionParam('power3', 0.1000, 1.489, 0.1901)
sigma = FunctionParam('exp3', 0.0400, 0.1748, -0.2243)

# Create distributions
dist1 = WeibullDistribution(*par1)
Expand Down Expand Up @@ -373,8 +423,8 @@ def test_IForm2d_WN(self):
par1 = (shape, loc, scale)

shape = None
loc = FunctionParam(7, 1.489, 0.1901, "power3")
scale = FunctionParam(1.5, 0.1748, -0.2243, "exp3")
loc = FunctionParam('power3', 7, 1.489, 0.1901)
scale = FunctionParam('exp3', 1.5, 0.1748, -0.2243)
par2 = (shape, loc, scale)

# Create distributions.
Expand Down Expand Up @@ -412,8 +462,8 @@ def test_IForm3d(self): # TODO what does this test do
scale = ConstantParam(2.776)
par1 = (shape, loc, scale)

mu = FunctionParam(0.1000, 1.489, 0.1901, "power3")
sigma = FunctionParam(0.0400, 0.1748, -0.2243, "exp3")
mu = FunctionParam('power3', 0.1000, 1.489, 0.1901)
sigma = FunctionParam('exp3', 0.0400, 0.1748, -0.2243)

#del shape, loc, scale

Expand Down Expand Up @@ -446,8 +496,8 @@ def test_isorm2d_WL(self):
scale = ConstantParam(2.776)
par1 = (shape, loc, scale)

mu = FunctionParam(0.1000, 1.489, 0.1901, "power3")
sigma = FunctionParam(0.0400, 0.1748, -0.2243, "exp3")
mu = FunctionParam('power3', 0.1000, 1.489, 0.1901)
sigma = FunctionParam('exp3', 0.0400, 0.1748, -0.2243)

# Create distributions
dist1 = WeibullDistribution(*par1)
Expand All @@ -474,8 +524,8 @@ def _setup(self, limits=[(0, 20), (0, 20)], deltas=[0.05, 0.05],
n_years = 25, dep1=(None, None, None), dep2=(0, None, 0),
par1=(ConstantParam(1.471), ConstantParam(0.8888),
ConstantParam(2.776)),
par2=(FunctionParam(0.0400, 0.1748, -0.2243, "exp3"), None,
FunctionParam(0.1, 1.489, 0.1901, "power3"))):
par2=(FunctionParam('exp3', 0.0400, 0.1748, -0.2243), None,
FunctionParam('power3', 0.1, 1.489, 0.1901))):
"""
Creating Contour example
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class MultivariateDistributionTest(unittest.TestCase):
scale = ConstantParam(2.776)
par1 = (shape, loc, scale)

shape = FunctionParam(0.0400, 0.1748, -0.2243, "exp3")
shape = FunctionParam('exp3', 0.0400, 0.1748, -0.2243)
loc = None
scale = FunctionParam(0.1, 1.489, 0.1901, "power3")
scale = FunctionParam('power3', 0.1, 1.489, 0.1901)
par2 = (shape, loc, scale)

del shape, loc, scale
Expand Down

0 comments on commit 16fa920

Please sign in to comment.