Skip to content

Commit cc5d8b5

Browse files
committed
Add function to compute value at a given return period
1 parent 5b34d18 commit cc5d8b5

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

examples/extreme_response_full_sea_state_example.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@
464464
"This object provides common statistical functions (PDF, CDF, PPF, etc.) and metrics (expected value, median, etc). \n",
465465
"Here, we will look at the survival function and the 100-year return level. \n",
466466
"\n",
467-
"The value of the survival function at a given return level (e.g. 100-years) (`s_t` in the code below) is $1/N$ where $N$ is the number of short-term periods in the return period. In this case $N$ is the number of 3-hour periods in a 100-year period, which gives `s_t`$\\approx 3e-6$. The corresponding response, i.e. the 100-year wave elevation in this case, is given as the inverse cumulative function (ppf) of $1-$`s_t`. This gives a 100-year wave of about 10.4 meters. "
467+
"The value of the survival function at a given return level (e.g. 100-years) \n",
468+
"may be calculated using the `return_year_value` function. This gives a 100-year wave of about 11.1 meters. "
468469
]
469470
},
470471
{
@@ -483,8 +484,7 @@
483484
"source": [
484485
"t_st_hr = t_st/(60.0*60.0)\n",
485486
"t_return_yr = 100.0\n",
486-
"s_t = 1.0/(365.25*24*t_return_yr/t_st_hr)\n",
487-
"x_t = lte.ppf(1-s_t)\n",
487+
"x_t = extreme.return_year_value(lte.ppf, t_return_yr, t_st_hr)\n",
488488
"\n",
489489
"print(f\"100-year elevation: {x_t} m\")"
490490
]
@@ -493,7 +493,7 @@
493493
"cell_type": "markdown",
494494
"metadata": {},
495495
"source": [
496-
"Finally we plot the survival function and show the 100-year return level (dashed grey lines). The 100-year value is about 104 m (where the grey line intersects the x-axis)"
496+
"Finally we plot the survival function and show the 100-year return level (dashed grey lines). The 100-year value is about 11.1 m (where the grey line intersects the x-axis)"
497497
]
498498
},
499499
{

mhkit/loads/extreme.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,3 +727,31 @@ def mler_export_time_series(rao, mler, sim, k):
727727
mler_ts = mler_ts.rename(columns={0: 'WaveHeight', 1: 'LinearResponse'})
728728

729729
return mler_ts
730+
731+
732+
def return_year_value(ppf, return_year, short_term_period_hr):
733+
"""
734+
Calculate the value from a given distribution corresponding to a particular
735+
return year.
736+
737+
Parameters
738+
----------
739+
ppf: callable function of 1 argument
740+
Percentage Point Function (inverse CDF) of short term distribution.
741+
return_year: int
742+
Return period in years.
743+
short_term_period_hr: int, float
744+
Short term period the distribution is created from in hours.
745+
746+
Returns
747+
-------
748+
value: float
749+
The value corresponding to the return period from the distribution.
750+
"""
751+
assert callable(ppf)
752+
assert isinstance(return_year, int)
753+
assert isinstance(short_term_period_hr, (float, int))
754+
755+
p = 1 / (return_year * 365.25 * 24 / short_term_period_hr)
756+
757+
return ppf(1 - p)

mhkit/tests/loads/test_loads.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,20 @@ def test_mler_export_time_series(self):
180180

181181
assert_frame_equal(self.mler_ts, mler_ts, atol=0.0001)
182182

183+
def test_return_year_value(self):
184+
dist = stats.norm
185+
return_year = 50
186+
short_term_period = 1
187+
188+
val = loads.extreme.return_year_value(dist.ppf, return_year, short_term_period)
189+
190+
# This is a little hard to test as there is not an indepedent means by
191+
# which we can do this calculation. The value below has been taken from
192+
# an initial calculation and will indicate if the return_year_value is
193+
# changed unexpectedly.
194+
want = 4.5839339
195+
self.assertAlmostEqual(want, val, 5)
196+
183197
def test_longterm_extreme(self):
184198
ste_1 = stats.norm
185199
ste_2 = stats.norm

0 commit comments

Comments
 (0)