def test_simple(self): for Model in self.cov_models: model = Model(dim=1, var=0.5, len_scale=2, anis=[0.1, 1], angles=[0.5, 0, 0]) simple = krige.Simple(model, self.mean, self.cond_pos[0], self.cond_val) field_1, __ = simple.unstructured(self.pos[0]) field_2, __ = simple.structured(self.pos[0]) for i, val in enumerate(self.cond_val): self.assertAlmostEqual(val, field_1[i], places=2) self.assertAlmostEqual(val, field_2[(i, )], places=2) self.assertAlmostEqual(self.mean, field_1[-1], places=2) self.assertAlmostEqual(self.mean, field_2[(-1, )], places=2) for dim in self.dims[1:]: model = Model( dim=dim, var=0.5, len_scale=2, anis=[0.1, 1], angles=[0.5, 0, 0], ) simple = krige.Simple(model, self.mean, self.cond_pos[:dim], self.cond_val) field_1, __ = simple.unstructured(self.pos[:dim]) field_2, __ = simple.structured(self.pos[:dim]) for i, val in enumerate(self.cond_val): self.assertAlmostEqual(val, field_1[i], places=2) self.assertAlmostEqual(val, field_2[dim * (i, )], places=2) self.assertAlmostEqual(self.mean, field_1[-1], places=2) self.assertAlmostEqual(self.mean, field_2[dim * (-1, )], places=2)
def test_simple(self): for Model in self.cov_models: for dim in self.dims: model = Model( dim=dim, var=2, len_scale=2, anis=[0.9, 0.8], angles=[2, 1, 0.5], ) simple = krige.Simple(model, self.cond_pos[:dim], self.cond_val, self.mean) field_1, __ = simple.unstructured(self.grids[dim - 1]) field_1 = field_1.reshape(self.grid_shape[:dim]) field_2, __ = simple.structured(self.pos[:dim]) self.assertAlmostEqual(np.max(np.abs(field_1 - field_2)), 0.0, places=2) for i, val in enumerate(self.cond_val): self.assertAlmostEqual(field_1[self.data_idx[:dim]][i], val, places=2)
Thereby :math:`c(x_i,x_j)` is the covariance of the given observations. Example ^^^^^^^ Here we use simple kriging in 1D (for plotting reasons) with 5 given observations/conditions. The mean of the field has to be given beforehand. """ import numpy as np from gstools import Gaussian, krige # condtions cond_pos = [0.3, 1.9, 1.1, 3.3, 4.7] cond_val = [0.47, 0.56, 0.74, 1.47, 1.74] # resulting grid gridx = np.linspace(0.0, 15.0, 151) # spatial random field class model = Gaussian(dim=1, var=0.5, len_scale=2) ############################################################################### krig = krige.Simple(model, mean=1, cond_pos=cond_pos, cond_val=cond_val) krig(gridx) ############################################################################### ax = krig.plot() ax.scatter(cond_pos, cond_val, color="k", zorder=10, label="Conditions") ax.legend()