Skip to content

Commit

Permalink
more temporal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MuellerSeb committed Jun 14, 2023
1 parent f4bc0d1 commit fad4afe
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
16 changes: 10 additions & 6 deletions tests/test_latlon.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def fix_dim(self):
class TestLatLon(unittest.TestCase):
def setUp(self):
self.cmod = gs.Gaussian(
latlon=True, var=2, len_scale=777, rescale=gs.KM_SCALE
latlon=True, var=2, len_scale=777, geo_scale=gs.KM_SCALE
)
self.lat = self.lon = range(-80, 81)

Expand Down Expand Up @@ -66,7 +66,10 @@ def test_conv(self):
6, self.cmod.anisometrize(self.cmod.isometrize((8, 6)))[1, 0]
)
self.assertAlmostEqual(
1, self.cmod.isometrize(self.cmod.anisometrize((1, 0, 0)))[0, 0]
gs.EARTH_RADIUS,
self.cmod.isometrize(
self.cmod.anisometrize((gs.EARTH_RADIUS, 0, 0))
)[0, 0],
)

def test_cov_model(self):
Expand All @@ -91,15 +94,16 @@ def test_vario_est(self):
srf = gs.SRF(self.cmod, seed=12345)
field = srf.structured((self.lat, self.lon))

bin_edges = [0.01 * i for i in range(30)]
bin_edges = np.linspace(0, 3 * 777, 30)
bin_center, emp_vario = gs.vario_estimate(
*((self.lat, self.lon), field, bin_edges),
latlon=True,
mesh_type="structured",
sampling_size=2000,
sampling_seed=12345,
geo_scale=gs.KM_SCALE,
)
mod = gs.Gaussian(latlon=True, rescale=gs.KM_SCALE)
mod = gs.Gaussian(latlon=True, geo_scale=gs.KM_SCALE)
mod.fit_variogram(bin_center, emp_vario, nugget=False)
# allow 10 percent relative error
self.assertLess(_rel_err(mod.var, self.cmod.var), 0.1)
Expand All @@ -114,7 +118,7 @@ def test_krige(self):
bin_edges,
latlon=True,
)
mod = gs.Spherical(latlon=True, rescale=gs.KM_SCALE)
mod = gs.Spherical(latlon=True, geo_scale=gs.KM_SCALE)
mod.fit_variogram(*emp_vario, nugget=False)
kri = gs.krige.Ordinary(
mod,
Expand All @@ -134,7 +138,7 @@ def test_cond_srf(self):
bin_edges,
latlon=True,
)
mod = gs.Spherical(latlon=True, rescale=gs.KM_SCALE)
mod = gs.Spherical(latlon=True, geo_scale=gs.KM_SCALE)
mod.fit_variogram(*emp_vario, nugget=False)
krige = gs.krige.Ordinary(
mod, (self.data[:, 0], self.data[:, 1]), self.data[:, 2]
Expand Down
38 changes: 35 additions & 3 deletions tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@

class TestTemporal(unittest.TestCase):
def setUp(self):
...
self.mod = gs.Gaussian(
latlon=True,
temporal=True,
len_scale=1000,
anis=0.5,
geo_scale=gs.KM_SCALE,
)

def test_latlon(self):
mod = gs.Gaussian(
Expand All @@ -28,15 +34,41 @@ def test_latlon(self):
self.assertTrue(np.allclose(mod1.anis, mod2.anis))
self.assertAlmostEqual(mod1.len_scale, mod2.len_scale)

def test_latlon2pos(self):
self.assertAlmostEqual(
8, self.mod.anisometrize(self.mod.isometrize((8, 6, 9)))[0, 0]
)
self.assertAlmostEqual(
6, self.mod.anisometrize(self.mod.isometrize((8, 6, 9)))[1, 0]
)
self.assertAlmostEqual(
9, self.mod.anisometrize(self.mod.isometrize((8, 6, 9)))[2, 0]
)
self.assertAlmostEqual(
gs.EARTH_RADIUS,
self.mod.isometrize(
self.mod.anisometrize((gs.EARTH_RADIUS, 0, 0, 10))
)[0, 0],
)
self.assertAlmostEqual(
10,
self.mod.isometrize(
self.mod.anisometrize((gs.EARTH_RADIUS, 0, 0, 10))
)[3, 0],
)

def test_rotation(self):
mod = gs.Gaussian(dim=3, temporal=True, angles=[1, 2, 3, 4, 5, 6])
self.assertTrue(np.allclose(mod.angles, [1, 2, 3, 0, 0, 0]))

def test_krige(self):
mod = gs.Gaussian(latlon=True, temporal=True)
# auto-fitting latlon-temporal model in kriging not possible
with self.assertRaises(ValueError):
kri = gs.Krige(mod, 3 * [[1, 2, 3]], [1, 2, 3], fit_variogram=True)
kri = gs.Krige(self.mod, 3 * [[1, 2]], [1, 2], fit_variogram=True)

def test_field(self):
srf = gs.SRF(self.mod)
self.assertTrue(srf.temporal)


if __name__ == "__main__":
Expand Down

0 comments on commit fad4afe

Please sign in to comment.