@@ -34,6 +34,58 @@ def test_directional(self):
3434 self .assertAlmostEqual (gamma [1 , len (gamma [0 ]) // 2 ], var , places = 2 )
3535 self .assertAlmostEqual (gamma [1 , - 1 ], var , places = 2 )
3636
37+ def test_directional_separate_dirs (self ):
38+ pos = np .array (((0.0 , 1.0 ), (0.0 , 0.0 )), dtype = np .double )
39+ dirs = np .array (((1.0 , 0.0 ), (1.0 , 0.0 )), dtype = np .double )
40+ field = np .array (((1.0 , 2.0 ),), dtype = np .double )
41+ bins = np .array ((0.0 , 2.0 ), dtype = np .double )
42+
43+ _ , counts = gs_cy .variogram .directional (
44+ field , bins , pos , dirs , angles_tol = np .pi , separate_dirs = True
45+ )
46+
47+ self .assertEqual (counts [0 , 0 ], 1 )
48+ self .assertEqual (counts [1 , 0 ], 0 )
49+
50+ def test_directional_bandwidth_cressie (self ):
51+ pos = np .array (((0.0 , 0.0 , 1.0 ), (0.0 , 1.0 , 0.0 )), dtype = np .double )
52+ dirs = np .array (((1.0 , 0.0 ),), dtype = np .double )
53+ field = np .array (((1.0 , 2.0 , 5.0 ),), dtype = np .double )
54+ bins = np .array ((0.0 , 2.0 ), dtype = np .double )
55+
56+ gamma , counts = gs_cy .variogram .directional (
57+ field ,
58+ bins ,
59+ pos ,
60+ dirs ,
61+ angles_tol = np .pi ,
62+ bandwidth = 0.5 ,
63+ estimator_type = "c" ,
64+ )
65+
66+ self .assertEqual (counts [0 , 0 ], 1 )
67+ f_diff = field [0 , 2 ] - field [0 , 0 ]
68+ raw = np .sqrt (abs (f_diff ))
69+ expected = 0.5 * raw ** 4 / (0.457 + 0.494 + 0.045 )
70+ self .assertAlmostEqual (gamma [0 , 0 ], expected , places = 6 )
71+
72+ def test_directional_error_checks (self ):
73+ pos = np .array (((0.0 , 1.0 ), (0.0 , 1.0 )), dtype = np .double )
74+ dirs = np .array (((1.0 , 0.0 ),), dtype = np .double )
75+ bins = np .array ((0.0 , 1.0 ), dtype = np .double )
76+ field = np .array (((1.0 , 2.0 ),), dtype = np .double )
77+
78+ with self .assertRaises (ValueError ):
79+ gs_cy .variogram .directional (field [:, :1 ], bins , pos , dirs )
80+
81+ with self .assertRaises (ValueError ):
82+ gs_cy .variogram .directional (
83+ field , np .array ((0.0 ,), dtype = np .double ), pos , dirs
84+ )
85+
86+ with self .assertRaises (ValueError ):
87+ gs_cy .variogram .directional (field , bins , pos , dirs , angles_tol = 0.0 )
88+
3789 def test_unstructured (self ):
3890 x = np .arange (1 , 11 , 1 , dtype = np .double )
3991 z = np .array (
@@ -73,6 +125,46 @@ def test_unstructured(self):
73125 self .assertAlmostEqual (gamma [len (gamma ) // 2 ], var , places = 2 )
74126 self .assertAlmostEqual (gamma [- 1 ], var , places = 2 )
75127
128+ def test_unstructured_haversine (self ):
129+ pos = np .array (((0.0 , 0.0 ), (0.0 , 90.0 )), dtype = np .double )
130+ field = np .array (((1.0 , 3.0 ),), dtype = np .double )
131+ bins = np .array ((0.0 , 2.0 ), dtype = np .double )
132+
133+ gamma , counts = gs_cy .variogram .unstructured (
134+ field , bins , pos , distance_type = "h"
135+ )
136+
137+ self .assertEqual (counts [0 ], 1 )
138+ self .assertAlmostEqual (gamma [0 ], 2.0 , places = 6 )
139+
140+ def test_unstructured_num_threads (self ):
141+ pos = np .array (((0.0 , 1.0 , 2.0 ),), dtype = np .double )
142+ field = np .array (((1.0 , 3.0 , 2.0 ),), dtype = np .double )
143+ bins = np .array ((0.0 , 2.0 ), dtype = np .double )
144+
145+ gamma_default , counts_default = gs_cy .variogram .unstructured (field , bins , pos )
146+ gamma_threads , counts_threads = gs_cy .variogram .unstructured (
147+ field , bins , pos , num_threads = 2
148+ )
149+
150+ np .testing .assert_allclose (gamma_threads , gamma_default )
151+ np .testing .assert_array_equal (counts_threads , counts_default )
152+
153+ def test_unstructured_error_checks (self ):
154+ pos = np .array (((0.0 , 1.0 ), (0.0 , 1.0 )), dtype = np .double )
155+ field = np .array (((1.0 , 2.0 ),), dtype = np .double )
156+ bins = np .array ((0.0 , 1.0 ), dtype = np .double )
157+
158+ with self .assertRaises (ValueError ):
159+ gs_cy .variogram .unstructured (field [:, :1 ], bins , pos )
160+
161+ with self .assertRaises (ValueError ):
162+ gs_cy .variogram .unstructured (field , np .array ((0.0 ,), dtype = np .double ), pos )
163+
164+ pos_bad = np .array (((0.0 , 1.0 ), (0.0 , 1.0 ), (0.0 , 1.0 )), dtype = np .double )
165+ with self .assertRaises (ValueError ):
166+ gs_cy .variogram .unstructured (field , bins , pos_bad , distance_type = "h" )
167+
76168 def test_structured (self ):
77169 z = np .array (
78170 (41.2 , 40.2 , 39.7 , 39.2 , 40.1 , 38.3 , 39.1 , 40.0 , 41.1 , 40.3 ),
0 commit comments