@@ -3277,6 +3277,245 @@ def test_grid__hz_deg(self):
32773277 np .testing .assert_array_almost_equal (dirs_out , dirs_expect )
32783278 np .testing .assert_array_almost_equal (vals_out , vals_expect )
32793279
3280+ def test_bingrid (self ):
3281+ freq_in = np .array ([0.2 , 0.4 , 0.6 , 0.8 , 1.0 ])
3282+ dirs_in = np .array ([0.0 , 90.0 , 180.0 ])
3283+ vals_in = np .ones ((len (freq_in ), len (dirs_in )))
3284+ spectrum = DirectionalSpectrum (
3285+ freq_in ,
3286+ dirs_in ,
3287+ vals_in ,
3288+ freq_hz = True ,
3289+ degrees = True ,
3290+ clockwise = True ,
3291+ waves_coming_from = True ,
3292+ )
3293+
3294+ freq_out , dirs_out , vals_out = spectrum .bingrid (freq_hz = False , degrees = False )
3295+
3296+ freq_expect = 2.0 * np .pi * freq_in
3297+ dirs_expect = (np .pi / 180.0 ) * dirs_in
3298+ vals_expect = 1.0 / (2.0 * np .pi * (np .pi / 180.0 )) * vals_in
3299+
3300+ vals_expect [:, 0 ] *= 135.0 * (np .pi / 180.0 )
3301+ vals_expect [:, 1 ] *= 90.0 * (np .pi / 180.0 )
3302+ vals_expect [:, 2 ] *= 135.0 * (np .pi / 180.0 )
3303+
3304+ np .testing .assert_array_almost_equal (freq_out , freq_expect )
3305+ np .testing .assert_array_almost_equal (dirs_out , dirs_expect )
3306+ np .testing .assert_array_almost_equal (vals_out , vals_expect )
3307+
3308+ def test_bingrid2 (self ):
3309+ freq_in = np .array ([0.2 , 0.4 , 0.6 , 0.8 , 1.0 ]) * 2.0 * np .pi
3310+ dirs_in = np .radians (np .array ([0.0 , 90.0 , 180.0 ]))
3311+ vals_in = np .ones ((len (freq_in ), len (dirs_in )))
3312+ spectrum = DirectionalSpectrum (
3313+ freq_in ,
3314+ dirs_in ,
3315+ vals_in ,
3316+ freq_hz = False ,
3317+ degrees = False ,
3318+ clockwise = True ,
3319+ waves_coming_from = True ,
3320+ )
3321+
3322+ freq_out , dirs_out , vals_out = spectrum .bingrid (freq_hz = False , degrees = False )
3323+
3324+ freq_expect = freq_in
3325+ dirs_expect = dirs_in
3326+ vals_expect = vals_in
3327+
3328+ vals_expect [:, 0 ] *= 135.0 * (np .pi / 180.0 )
3329+ vals_expect [:, 1 ] *= 90.0 * (np .pi / 180.0 )
3330+ vals_expect [:, 2 ] *= 135.0 * (np .pi / 180.0 )
3331+
3332+ np .testing .assert_array_almost_equal (freq_out , freq_expect )
3333+ np .testing .assert_array_almost_equal (dirs_out , dirs_expect )
3334+ np .testing .assert_array_almost_equal (vals_out , vals_expect )
3335+
3336+ @pytest .mark .parametrize (
3337+ "dirs_in" ,
3338+ [
3339+ np .array ([0.0 , 90.0 , 180.0 , 270.0 ]),
3340+ np .array ([10.0 , 100.0 , 190.0 , 280.0 ]),
3341+ np .array ([85.0 , 175.0 , 265.0 , 355.0 ]),
3342+ ],
3343+ )
3344+ def test_bingrid_rads_rad (self , dirs_in ):
3345+ freq_in = np .arange (0.0 , 1 , 0.1 )
3346+ vals_in = np .column_stack (
3347+ [
3348+ np .zeros_like (freq_in ),
3349+ np .ones_like (freq_in ),
3350+ 4 * np .ones_like (freq_in ),
3351+ np .ones_like (freq_in ),
3352+ ]
3353+ )
3354+ spectrum = DirectionalSpectrum (
3355+ freq_in ,
3356+ dirs_in ,
3357+ vals_in ,
3358+ freq_hz = True ,
3359+ degrees = True ,
3360+ clockwise = True ,
3361+ waves_coming_from = True ,
3362+ )
3363+
3364+ freq_out , dirs_out , vals_out = spectrum .bingrid (freq_hz = False , degrees = False )
3365+
3366+ freq_expect = 2.0 * np .pi * freq_in
3367+ dirs_expect = (np .pi / 180.0 ) * dirs_in
3368+ vals_expect = np .column_stack (
3369+ [
3370+ 22.5 * np .ones_like (freq_in ),
3371+ 112.5 * np .ones_like (freq_in ),
3372+ 292.5 * np .ones_like (freq_in ),
3373+ 112.5 * np .ones_like (freq_in ),
3374+ ]
3375+ ) / (2.0 * np .pi )
3376+
3377+ np .testing .assert_array_almost_equal (freq_out , freq_expect )
3378+ np .testing .assert_array_almost_equal (dirs_out , dirs_expect )
3379+ np .testing .assert_array_almost_equal (vals_out , vals_expect )
3380+
3381+ @pytest .mark .parametrize (
3382+ "dirs_in" ,
3383+ [
3384+ np .array ([0.0 , 90.0 , 180.0 , 270.0 ]),
3385+ np .array ([10.0 , 100.0 , 190.0 , 280.0 ]),
3386+ np .array ([85.0 , 175.0 , 265.0 , 355.0 ]),
3387+ ],
3388+ )
3389+ def test_bingrid_hz_rad (self , dirs_in ):
3390+ freq_in = np .arange (0.0 , 1 , 0.1 )
3391+ vals_in = np .column_stack (
3392+ [
3393+ np .zeros_like (freq_in ),
3394+ np .ones_like (freq_in ),
3395+ 4 * np .ones_like (freq_in ),
3396+ np .ones_like (freq_in ),
3397+ ]
3398+ )
3399+
3400+ spectrum = DirectionalSpectrum (
3401+ freq_in ,
3402+ dirs_in ,
3403+ vals_in ,
3404+ freq_hz = True ,
3405+ degrees = True ,
3406+ clockwise = True ,
3407+ waves_coming_from = True ,
3408+ )
3409+
3410+ freq_out , dirs_out , vals_out = spectrum .bingrid (freq_hz = True , degrees = False )
3411+
3412+ freq_expect = freq_in
3413+ dirs_expect = dirs_in * (np .pi / 180.0 )
3414+ vals_expect = np .column_stack (
3415+ [
3416+ 22.5 * np .ones_like (freq_in ),
3417+ 112.5 * np .ones_like (freq_in ),
3418+ 292.5 * np .ones_like (freq_in ),
3419+ 112.5 * np .ones_like (freq_in ),
3420+ ]
3421+ )
3422+
3423+ np .testing .assert_array_almost_equal (freq_out , freq_expect )
3424+ np .testing .assert_array_almost_equal (dirs_out , dirs_expect )
3425+ np .testing .assert_array_almost_equal (vals_out , vals_expect )
3426+
3427+ @pytest .mark .parametrize (
3428+ "dirs_in" ,
3429+ [
3430+ np .array ([0.0 , 90.0 , 180.0 , 270.0 ]),
3431+ np .array ([10.0 , 100.0 , 190.0 , 280.0 ]),
3432+ np .array ([85.0 , 175.0 , 265.0 , 355.0 ]),
3433+ ],
3434+ )
3435+ def test_bingrid_rads_deg (self , dirs_in ):
3436+ freq_in = np .arange (0.0 , 1 , 0.1 )
3437+ vals_in = np .column_stack (
3438+ [
3439+ np .zeros_like (freq_in ),
3440+ np .ones_like (freq_in ),
3441+ 4 * np .ones_like (freq_in ),
3442+ np .ones_like (freq_in ),
3443+ ]
3444+ )
3445+
3446+ spectrum = DirectionalSpectrum (
3447+ freq_in ,
3448+ dirs_in ,
3449+ vals_in ,
3450+ freq_hz = True ,
3451+ degrees = True ,
3452+ clockwise = True ,
3453+ waves_coming_from = True ,
3454+ )
3455+
3456+ freq_out , dirs_out , vals_out = spectrum .bingrid (freq_hz = False , degrees = True )
3457+
3458+ freq_expect = 2.0 * np .pi * freq_in
3459+ dirs_expect = dirs_in
3460+ vals_expect = np .column_stack (
3461+ [
3462+ 22.5 * np .ones_like (freq_in ),
3463+ 112.5 * np .ones_like (freq_in ),
3464+ 292.5 * np .ones_like (freq_in ),
3465+ 112.5 * np .ones_like (freq_in ),
3466+ ]
3467+ ) / (2.0 * np .pi )
3468+
3469+ np .testing .assert_array_almost_equal (freq_out , freq_expect )
3470+ np .testing .assert_array_almost_equal (dirs_out , dirs_expect )
3471+ np .testing .assert_array_almost_equal (vals_out , vals_expect )
3472+
3473+ @pytest .mark .parametrize (
3474+ "dirs_in" ,
3475+ [
3476+ np .array ([0.0 , 90.0 , 180.0 , 270.0 ]),
3477+ np .array ([10.0 , 100.0 , 190.0 , 280.0 ]),
3478+ np .array ([85.0 , 175.0 , 265.0 , 355.0 ]),
3479+ ],
3480+ )
3481+ def test_bingrid_hz_deg (self , dirs_in ):
3482+ freq_in = np .arange (0.0 , 1 , 0.1 )
3483+ vals_in = np .column_stack (
3484+ [
3485+ np .zeros_like (freq_in ),
3486+ np .ones_like (freq_in ),
3487+ 4 * np .ones_like (freq_in ),
3488+ np .ones_like (freq_in ),
3489+ ]
3490+ )
3491+ spectrum = DirectionalSpectrum (
3492+ freq_in ,
3493+ dirs_in ,
3494+ vals_in ,
3495+ freq_hz = True ,
3496+ degrees = True ,
3497+ clockwise = True ,
3498+ waves_coming_from = True ,
3499+ )
3500+
3501+ freq_out , dirs_out , vals_out = spectrum .bingrid (freq_hz = True , degrees = True )
3502+
3503+ freq_expect = freq_in
3504+ dirs_expect = dirs_in
3505+ dirs_expect = dirs_in
3506+ vals_expect = np .column_stack (
3507+ [
3508+ 22.5 * np .ones_like (freq_in ),
3509+ 112.5 * np .ones_like (freq_in ),
3510+ 292.5 * np .ones_like (freq_in ),
3511+ 112.5 * np .ones_like (freq_in ),
3512+ ]
3513+ )
3514+
3515+ np .testing .assert_array_almost_equal (freq_out , freq_expect )
3516+ np .testing .assert_array_almost_equal (dirs_out , dirs_expect )
3517+ np .testing .assert_array_almost_equal (vals_out , vals_expect )
3518+
32803519 def test_from_spectrum1d (self ):
32813520 freq = np .array ([0.0 , 0.5 , 1.0 ])
32823521 dirs = np .array ([0.0 , 90.0 , 180.0 , 270.0 ])
0 commit comments