Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev ex #73

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,13 @@ Convert lat/lon coordinates from degrees/minutes/seconds to decimals:

returns lat = 60.5

Estimate total depth of wave influence in meters:

.. code-block:: python

depth = depth_of_wave_influence(Hs=12, Tp=15, ref_depth=1000,spectrum='JONSWAP', theshold=0.01)

returns depth = 692.5

.. toctree::
:maxdepth: 1
47 changes: 47 additions & 0 deletions metocean_stats/stats/aux_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,50 @@ def degminsec_to_decimals(degrees,minutes,seconds):
else:
loc_decimals=degrees+(minutes/60)+(seconds/3600)
return loc_decimals


def calculate_Us_Tu(H_s, T_p, depth, ref_depth,spectrum='JONSWAP'):
df = 0.01
f=np.arange(0,1,df)
S_u = np.zeros((len(H_s),len(f)))
for i in range(len(H_s)):
if spectrum=='JONSWAP':
E = jonswap(f=f,hs=H_s[i],tp=T_p[i])
elif spectrum=='TORSEHAUGEN':
E = torsethaugen(f=f,hs=H_s[i],tp=T_p[i])

S_u[i,:] = velocity_spectrum(f, E, depth=depth, ref_depth=ref_depth)

M0 = np.trapz(S_u*df,axis=1)
M2 = np.trapz((f**2)*S_u*df,axis=1)
Us = 2*np.sqrt(M0)
Tu = np.sqrt(M0/M2)
return Us, Tu

def depth_of_wave_influence(Hs, Tp, ref_depth,spectrum='JONSWAP', theshold=0.01):
"""
Find the depth at which wave-induced current (Us) is zero.

Parameters:
- frequency: array-like, frequencies at which wave spectra are given.
- wave_spectra: array-like, wave spectra values corresponding to the frequencies.
- ref_depth: float, reference depth.
- theshold: minimum value in m/s for the wave-induced current to considered important default (0.01 m/s)

Returns:
- depth: float, total depth of wave influence
"""
df = 0.01
f=np.arange(0,1,df)
if spectrum=='JONSWAP':
E = jonswap(f=f,hs=Hs,tp=Tp)
elif spectrum=='TORSEHAUGEN':
E = torsethaugen(f=f,hs=Hs,tp=Tp)

depth_list = np.arange(0,ref_depth+0.5,0.5)
for depth in depth_list[::-1]:
S_u = velocity_spectrum(f, E, depth=depth, ref_depth=ref_depth)
M0 = np.trapz(S_u, x = f)
Us = 2 * np.sqrt(M0)
if Us>theshold:
return depth
4 changes: 3 additions & 1 deletion tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,4 +573,6 @@ def test_monthly_directional_percentiles_invalid_column():
)
assert False, "The function did not raise an error for an invalid column."
except KeyError:
print("test_monthly_directional_percentiles_invalid_column passed (KeyError raised as expected).")
print("test_monthly_directional_percentiles_invalid_column passed (KeyError raised as expected).")


Loading