Repository: MET-OM/metocean-stats (language: python)

Issue:
update



Discussion / hints:

Fix patch:
diff --git a/docs/index.rst b/docs/index.rst
index 1ff1f5b..1a6a12d 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -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
diff --git a/metocean_stats/stats/aux_funcs.py b/metocean_stats/stats/aux_funcs.py
index 79e3aac..e75fdbb 100644
--- a/metocean_stats/stats/aux_funcs.py
+++ b/metocean_stats/stats/aux_funcs.py
@@ -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
\ No newline at end of file


Test patch:
diff --git a/tests/test_tables.py b/tests/test_tables.py
index e5e6e61..1240733 100644
--- a/tests/test_tables.py
+++ b/tests/test_tables.py
@@ -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).")
\ No newline at end of file
+        print("test_monthly_directional_percentiles_invalid_column passed (KeyError raised as expected).")
+
+