Skip to content

Commit fbcf0ff

Browse files
mbruggsakeeste
andauthored
Provide function to convert from Te to Tp using ITTC approximation (#210)
* Provide function to convert from Te to Tp using ITTC approximation * Apply suggestions from code review Co-authored-by: Adam Keester <[email protected]>
1 parent 4a781d4 commit fbcf0ff

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

mhkit/tests/wave/test_resource_metrics.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,26 @@ def test_moments(self):
201201
self.assertLess(error, 0.01)
202202

203203

204+
def test_energy_period_to_peak_period(self):
205+
# This test checks that if we perform the
206+
# Te to Tp conversion, we create a spectrum
207+
# (using Tp) that has the provided Te.
208+
Hs = 2.5
209+
Te = np.linspace(5, 20, 10)
210+
gamma = np.linspace(1, 7, 7)
211+
212+
for g in gamma:
213+
for T in Te:
214+
Tp = wave.resource.energy_period_to_peak_period(T, g)
215+
216+
f = np.linspace(1 / (10 * Tp), 3 / Tp, 100)
217+
S = wave.resource.jonswap_spectrum(f, Tp, Hs, g)
218+
219+
Te_calc = wave.resource.energy_period(S).values[0][0]
220+
221+
error = np.abs(T - Te_calc)/Te_calc
222+
self.assertLess(error, 0.01)
223+
204224

205225
def test_metrics(self):
206226
for file_i in self.valdata2.keys(): # for each file MC, AH, CDiP
@@ -356,6 +376,6 @@ def test_plot_monthly_cumulative_distribution(self):
356376

357377
self.assertTrue(isfile(filename))
358378

359-
379+
360380
if __name__ == '__main__':
361381
unittest.main()

mhkit/wave/resource.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,34 @@ def energy_flux(S, h, deep=False, rho=1025, g=9.80665, ratio=2):
591591
return J
592592

593593

594+
def energy_period_to_peak_period(Te, gamma):
595+
"""
596+
Convert from spectral energy period (Te) to peak period (Tp) using ITTC approximation for JONSWAP Spectrum.
597+
598+
Approximation is given in "The Specialist Committee on Waves, Final Report
599+
and Recommendations to the 23rd ITTC", Proceedings of the 23rd ITTC - Volume
600+
2, Table A4.
601+
602+
Parameters:
603+
----------
604+
Te: float or array
605+
Spectral energy period [s]
606+
gamma: float or int
607+
Peak enhancement factor for JONSWAP spectrum
608+
609+
Returns
610+
-------
611+
Tp: float or array
612+
Spectral peak period [s]
613+
"""
614+
assert isinstance(Te, (float, np.ndarray)), 'Te must be a float or a ndarray'
615+
assert isinstance(gamma, (float, int)), 'gamma must be of type float or int'
616+
617+
factor = 0.8255 + 0.03852*gamma - 0.005537*gamma**2 + 0.0003154*gamma**3
618+
619+
return Te / factor
620+
621+
594622
def wave_celerity(k, h, g=9.80665, depth_check=False, ratio=2):
595623
"""
596624
Calculates wave celerity (group velocity)

0 commit comments

Comments
 (0)