Skip to content

Commit 72d22a1

Browse files
committed
increase coverage
1 parent d33ba8b commit 72d22a1

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

tests/test_variogram.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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,35 @@ 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_error_checks(self):
141+
pos = np.array(((0.0, 1.0), (0.0, 1.0)), dtype=np.double)
142+
field = np.array(((1.0, 2.0),), dtype=np.double)
143+
bins = np.array((0.0, 1.0), dtype=np.double)
144+
145+
with self.assertRaises(ValueError):
146+
gs_cy.variogram.unstructured(field[:, :1], bins, pos)
147+
148+
with self.assertRaises(ValueError):
149+
gs_cy.variogram.unstructured(
150+
field, np.array((0.0,), dtype=np.double), pos
151+
)
152+
153+
pos_bad = np.array(((0.0, 1.0), (0.0, 1.0), (0.0, 1.0)), dtype=np.double)
154+
with self.assertRaises(ValueError):
155+
gs_cy.variogram.unstructured(field, bins, pos_bad, distance_type="h")
156+
76157
def test_structured(self):
77158
z = np.array(
78159
(41.2, 40.2, 39.7, 39.2, 40.1, 38.3, 39.1, 40.0, 41.1, 40.3),

0 commit comments

Comments
 (0)