2
2
import pytest
3
3
from scipy .spatial import SphericalVoronoi
4
4
5
- from pyroomacoustics . doa import fibonacci_spherical_sampling
5
+ import pyroomacoustics as pra
6
6
7
7
8
8
@pytest .mark .parametrize ("n" , [20 , 100 , 200 , 500 , 1000 , 2000 , 5000 , 10000 ])
@@ -18,7 +18,7 @@ def test_voronoi_area(n, tol):
18
18
We observed empirically that the relative max error is
19
19
around 6% so we set that as the threshold for the test
20
20
"""
21
- points = fibonacci_spherical_sampling (n_points = n )
21
+ points = pra . doa . fibonacci_spherical_sampling (n_points = n )
22
22
sphere_area = 4.0 * np .pi
23
23
area_one_pt = sphere_area / n
24
24
@@ -34,6 +34,43 @@ def test_voronoi_area(n, tol):
34
34
assert max_err < tol
35
35
36
36
37
+ def _check_grid_consistency (grid ):
38
+
39
+ cart = pra .doa .spher2cart (grid .azimuth , grid .colatitude )
40
+ assert np .allclose (grid .cartesian , np .array ([grid .x , grid .y , grid .z ]))
41
+ assert np .allclose (grid .cartesian , cart )
42
+
43
+ az , co , _ = pra .doa .cart2spher (grid .cartesian )
44
+ assert np .allclose (grid .spherical , np .array ([grid .azimuth , grid .colatitude ]))
45
+ assert np .allclose (grid .spherical , np .array ([az , co ]))
46
+
47
+
48
+ @pytest .mark .parametrize ("n_points" , [20 , 100 , 200 , 500 , 1000 ])
49
+ def test_grid_sphere_from_spherical (n_points ):
50
+
51
+ x , y , z = pra .doa .fibonacci_spherical_sampling (n_points )
52
+ az , co , _ = pra .doa .cart2spher (np .array ([x , y , z ]))
53
+
54
+ grid = pra .doa .GridSphere (spherical_points = np .array ([az , co ]))
55
+ _check_grid_consistency (grid )
56
+
57
+
58
+ @pytest .mark .parametrize ("n_points" , [20 , 100 , 200 , 500 , 1000 ])
59
+ def test_grid_sphere_from_cartesian (n_points ):
60
+
61
+ x , y , z = pra .doa .fibonacci_spherical_sampling (n_points )
62
+
63
+ grid = pra .doa .GridSphere (cartesian_points = np .array ([x , y , z ]))
64
+ _check_grid_consistency (grid )
65
+
66
+
67
+ @pytest .mark .parametrize ("n_points" , [20 , 100 , 200 , 500 , 1000 ])
68
+ def test_grid_sphere_from_fibonacci (n_points ):
69
+
70
+ grid = pra .doa .GridSphere (n_points = n_points )
71
+ _check_grid_consistency (grid )
72
+
73
+
37
74
if __name__ == "__main__" :
38
75
test_voronoi_area (20 , 0.01 )
39
76
test_voronoi_area (100 , 0.01 )
0 commit comments