55
66__all__ = [
77 "get_tidal_hl" ,
8+ "get_tidal_hh_lh" ,
9+ "get_tidal_ll_hl" ,
810 "get_tidal_amplitude" ,
911 "get_tidal_hl_zerocrossing" ,
1012 "get_tidal_phase_diff" ,
@@ -56,6 +58,19 @@ def lmin(arr):
5658 return arr [idx ]
5759 else :
5860 return np .nan
61+ @numba .jit (nopython = True )
62+ def tlmax (arr ):
63+ """return HH(1) or LH (0)"""
64+ idx = np .argmax (arr ) # only the first occurence of the maxima is return
65+ # print(arr,idx)
66+ return idx
67+
68+ @numba .jit (nopython = True )
69+ def tlmin (arr ):
70+ """return LL(1) or HL(0)"""
71+ idx = np .argmin (arr )
72+ return idx
73+
5974
6075
6176def periods_per_window (moving_window_size : str , period_str : str ) -> int :
@@ -77,6 +92,25 @@ def periods_per_window(moving_window_size: str, period_str: str) -> int:
7792 / pd .to_timedelta (pd .tseries .frequencies .to_offset (period_str ))
7893 )
7994
95+ def get_tidal_hh_lh (sh ):
96+ """
97+ return HH(1) or LH (0) based from input tide highs (sh) using rolling window of 2 and tlmax function
98+ """
99+ sth = sh .rolling (2 ).apply (tlmax , raw = True )
100+ sth .iloc [0 ] = (
101+ 0 if sth .iloc [1 , 0 ] > 0 else 1
102+ ) # fill in the first value based on next value
103+ return sth .iloc [:, 0 ].map ({np .nan : "" , 0 : "LH" , 1 : "HH" }).astype (str )
104+
105+
106+ def get_tidal_ll_hl (sl ):
107+ """return LL(1) or HL (0) based from input tide lows (sl) using rolling window of 2 and tlmin function
108+ """
109+ stl = sl .rolling (2 ).apply (tlmin , raw = True )
110+ stl .iloc [0 ] = (
111+ 0 if stl .iloc [1 , 0 ] > 0 else 1
112+ ) # fill in the first value based on next value
113+ return stl .iloc [:, 0 ].map ({np .nan : "" , 0 : "HL" , 1 : "LL" }).astype (str )
80114
81115def tidal_highs (df , moving_window_size = "7h" ):
82116 """Tidal highs (could be upto two highs in a 25 hr period)
0 commit comments