Beispiel #1
0
    def test_ordinary(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])
            krige = gs.krige.Ordinary(model, self.cond_pos[0], self.cond_val)
            crf = gs.CondSRF(krige, seed=19970221)
            field_1 = crf.unstructured(self.pos[0])
            field_2 = crf.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)

            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],
                )
                krige = gs.krige.Ordinary(model, self.cond_pos[:dim],
                                          self.cond_val)
                crf = gs.CondSRF(krige, seed=19970221)
                field_1 = crf.unstructured(self.pos[:dim])
                field_2 = crf.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)
Beispiel #2
0
 def test_setter(self):
     krige1 = gs.krige.Krige(gs.Exponential(), self.cond_pos, self.cond_val)
     krige2 = gs.krige.Krige(
         gs.Gaussian(var=2),
         self.cond_pos,
         self.cond_val,
         mean=-1,
         trend=-2,
         normalizer=gs.normalizer.YeoJohnson(),
     )
     crf1 = gs.CondSRF(krige1)
     crf2 = gs.CondSRF(krige2, seed=19970221)
     # update settings
     crf1.model = gs.Gaussian(var=2)
     crf1.mean = -1
     crf1.trend = -2
     # also checking correctly setting uninitialized normalizer
     crf1.normalizer = gs.normalizer.YeoJohnson
     # check if setting went right
     self.assertTrue(crf1.model == crf2.model)
     self.assertTrue(crf1.normalizer == crf2.normalizer)
     self.assertAlmostEqual(crf1.mean, crf2.mean)
     self.assertAlmostEqual(crf1.trend, crf2.trend)
     # reset kriging
     crf1.krige.set_condition()
     # compare fields
     field1 = crf1(self.pos, seed=19970221)
     field2 = crf2(self.pos)
     self.assertTrue(np.all(np.isclose(field1, field2)))
    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])
            krige = gs.krige.Simple(model, self.cond_pos[0], self.cond_val,
                                    self.mean)
            crf = gs.CondSRF(krige, seed=19970221)
            field_1 = crf.unstructured(self.pos[0])
            field_2 = crf.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)

            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],
                )
                krige = gs.krige.Simple(model, self.cond_pos[:dim],
                                        self.cond_val, self.mean)
                crf = gs.CondSRF(krige, seed=19970221)
                field_1 = crf.unstructured(self.pos[:dim])
                field_2 = crf.structured(self.pos[:dim])
                # check reuse
                raw_kr2 = copy(crf["raw_krige"])
                crf(seed=19970222)
                self.assertTrue(np.allclose(raw_kr2, crf["raw_krige"]))
                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)
Beispiel #4
0
 def test_cond_srf(self):
     bin_max = np.deg2rad(8)
     bin_edges = np.linspace(0, bin_max, 5)
     emp_vario = gs.vario_estimate(
         (self.data[:, 0], self.data[:, 1]),
         self.data[:, 2],
         bin_edges,
         latlon=True,
     )
     mod = gs.Spherical(latlon=True, rescale=gs.EARTH_RADIUS)
     mod.fit_variogram(*emp_vario, nugget=False)
     krige = gs.krige.Ordinary(mod, (self.data[:, 0], self.data[:, 1]),
                               self.data[:, 2])
     crf = gs.CondSRF(krige)
     field = crf((self.data[:, 0], self.data[:, 1]))
     for i, dat in enumerate(self.data[:, 2]):
         self.assertAlmostEqual(field[i], dat, 3)
Beispiel #5
0
 def test_nugget(self):
     model = gs.Gaussian(
         nugget=0.01,
         var=0.5,
         len_scale=2,
         anis=[0.1, 1],
         angles=[0.5, 0, 0],
     )
     krige = gs.krige.Ordinary(model,
                               self.cond_pos,
                               self.cond_val,
                               exact=True)
     crf = gs.CondSRF(krige, seed=19970221)
     field_1 = crf.unstructured(self.pos)
     field_2 = crf.structured(self.pos)
     for i, val in enumerate(self.cond_val):
         self.assertAlmostEqual(val, field_1[i], places=2)
         self.assertAlmostEqual(val, field_2[3 * (i, )], places=2)
Beispiel #6
0
"""
import numpy as np
import matplotlib.pyplot as plt
import gstools as gs

# conditioning data (x, y, value)
cond_pos = [[0.3, 1.9, 1.1, 3.3, 4.7], [1.2, 0.6, 3.2, 4.4, 3.8]]
cond_val = [0.47, 0.56, 0.74, 1.47, 1.74]

# grid definition for output field
x = np.arange(0, 5, 0.1)
y = np.arange(0, 5, 0.1)

model = gs.Gaussian(dim=2, var=0.5, len_scale=5, anis=0.5, angles=-0.5)
krige = gs.Krige(model, cond_pos=cond_pos, cond_val=cond_val)
cond_srf = gs.CondSRF(krige)

###############################################################################
# We create a list containing the generated conditioned fields.

ens_no = 4
field = []
for i in range(ens_no):
    field.append(cond_srf.structured([x, y], seed=i))

###############################################################################
# Now let's have a look at the pairwise differences between the generated
# fields. We will see, that they coincide at the given conditions.

fig, ax = plt.subplots(ens_no + 1, ens_no + 1, figsize=(8, 8))
# plotting kwargs for scatter and image