@@ -3284,6 +3284,24 @@ def test_moment_m2_rads(self):
32843284 # not exactly same due to error in trapz for higher order functions
32853285 assert m_out == pytest .approx (m_expect , rel = 0.1 )
32863286
3287+ def test_tz (self ):
3288+ f0 = 0.0
3289+ f1 = 2.0
3290+
3291+ freq = np .linspace (f0 , f1 , 20 )
3292+ dirs = np .arange (5 , 360 , 10 )
3293+ vals = np .ones ((len (freq ), len (dirs )))
3294+ spectrum = DirectionalSpectrum (freq , dirs , vals , freq_hz = True , degrees = True )
3295+
3296+ tz_out = spectrum .tz
3297+
3298+ m0 = (0.0 - 360.0 ) * (f0 - f1 )
3299+ m2 = (1.0 / 3.0 ) * (0.0 - 360.0 ) * (f0 ** 3 - f1 ** 3 )
3300+
3301+ tz_expect = np .sqrt (m0 / m2 )
3302+
3303+ assert tz_out == pytest .approx (tz_expect , rel = 0.1 )
3304+
32873305 def test_from_grid (self ):
32883306 freq = np .linspace (0 , 1.0 , 10 )
32893307 dirs = np .linspace (0 , 360.0 , 15 , endpoint = False )
@@ -3352,6 +3370,69 @@ def test_imag_raises(self, directional_spectrum):
33523370 with pytest .raises (AttributeError ):
33533371 directional_spectrum .imag
33543372
3373+ def test_extreme_float (self ):
3374+ f0 = 0.0
3375+ f1 = 2.0
3376+
3377+ freq = np .linspace (f0 , f1 , 20 )
3378+ dirs = np .arange (5 , 360 , 10 )
3379+ vals = np .ones ((len (freq ), len (dirs )))
3380+ spectrum = wr .DirectionalSpectrum (freq , dirs , vals , freq_hz = True , degrees = True )
3381+
3382+ sigma = spectrum .std ()
3383+ tz = spectrum .tz
3384+
3385+ T = 360 * 24 * 60.0 ** 2
3386+ q = 0.99
3387+ extreme_out = spectrum .extreme (T , q = q )
3388+
3389+ extreme_expect = sigma * np .sqrt (2.0 * np .log ((T / tz ) / np .log (1.0 / q )))
3390+
3391+ assert extreme_out == pytest .approx (extreme_expect )
3392+
3393+ def test_extreme_list (self ):
3394+ f0 = 0.0
3395+ f1 = 2.0
3396+
3397+ freq = np .linspace (f0 , f1 , 20 )
3398+ dirs = np .arange (5 , 360 , 10 )
3399+ vals = np .ones ((len (freq ), len (dirs )))
3400+ spectrum = wr .DirectionalSpectrum (freq , dirs , vals , freq_hz = True , degrees = True )
3401+
3402+ sigma = spectrum .std ()
3403+ tz = spectrum .tz
3404+
3405+ T = 360 * 24 * 60.0 ** 2
3406+ q = [0.1 , 0.5 , 0.99 ]
3407+ extreme_out = spectrum .extreme (T , q = q )
3408+
3409+ extreme_expect = [
3410+ sigma * np .sqrt (2.0 * np .log ((T / tz ) / np .log (1.0 / q [0 ]))),
3411+ sigma * np .sqrt (2.0 * np .log ((T / tz ) / np .log (1.0 / q [1 ]))),
3412+ sigma * np .sqrt (2.0 * np .log ((T / tz ) / np .log (1.0 / q [2 ]))),
3413+ ]
3414+
3415+ np .testing .assert_array_almost_equal (extreme_out , extreme_expect )
3416+
3417+ def test_extreme_mpm (self ):
3418+ f0 = 0.0
3419+ f1 = 2.0
3420+
3421+ freq = np .linspace (f0 , f1 , 20 )
3422+ dirs = np .arange (5 , 360 , 10 )
3423+ vals = np .ones ((len (freq ), len (dirs )))
3424+ spectrum = wr .DirectionalSpectrum (freq , dirs , vals , freq_hz = True , degrees = True )
3425+
3426+ sigma = spectrum .std ()
3427+ tz = spectrum .tz
3428+
3429+ T = 360 * 24 * 60.0 ** 2
3430+ extreme_out = spectrum .extreme (T , q = 0.37 )
3431+
3432+ extreme_expect = sigma * np .sqrt (2.0 * np .log (T / tz ))
3433+
3434+ assert extreme_out == pytest .approx (extreme_expect , rel = 1e-3 )
3435+
33553436
33563437class Test_WaveSpectrum :
33573438 def test__init__ (self ):
@@ -3428,24 +3509,6 @@ def test_hs(self):
34283509
34293510 assert hs_out == pytest .approx (hs_expect )
34303511
3431- def test_tz (self ):
3432- f0 = 0.0
3433- f1 = 2.0
3434-
3435- freq = np .linspace (f0 , f1 , 20 )
3436- dirs = np .arange (5 , 360 , 10 )
3437- vals = np .ones ((len (freq ), len (dirs )))
3438- wave = WaveSpectrum (freq , dirs , vals , freq_hz = True , degrees = True )
3439-
3440- tz_out = wave .tz
3441-
3442- m0 = (0.0 - 360.0 ) * (f0 - f1 )
3443- m2 = (1.0 / 3.0 ) * (0.0 - 360.0 ) * (f0 ** 3 - f1 ** 3 )
3444-
3445- tz_expect = np .sqrt (m0 / m2 )
3446-
3447- assert tz_out == pytest .approx (tz_expect , rel = 0.1 )
3448-
34493512 def test_tp_hz (self ):
34503513 freq = np .linspace (0 , 2 , 20 )
34513514 dirs = np .arange (5 , 360 , 10 )
0 commit comments