예제 #1
0
 def test_universal(self):
     # "quad" -> to few conditional points
     for drift in ["linear", 0, 1, trend]:
         for Model in self.cov_models:
             for dim in self.dims:
                 model = Model(
                     dim=dim,
                     var=2,
                     len_scale=10,
                     anis=[0.9, 0.8],
                     angles=[2, 1, 0.5],
                 )
                 universal = krige.Universal(
                     model, self.cond_pos[:dim], self.cond_val, drift
                 )
                 field_1, __ = universal.unstructured(self.grids[dim - 1])
                 field_1 = field_1.reshape(self.grid_shape[:dim])
                 field_2, __ = universal.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_2[self.data_idx[:dim]][i], val, places=2
                     )
예제 #2
0
was added. The resulting samples are then used as input for Universal kriging.

The "linear" drift is then estimated during the interpolation.
To access only the estimated mean/drift, we provide a switch `only_mean`
in the call routine.
"""
import numpy as np
from gstools import SRF, Gaussian, krige

# synthetic condtions with a drift
drift_model = Gaussian(dim=1, var=0.1, len_scale=2)
drift = SRF(drift_model, seed=101)
cond_pos = np.linspace(0.1, 8, 10)
cond_val = drift(cond_pos) + cond_pos * 0.1 + 1
# resulting grid
gridx = np.linspace(0.0, 15.0, 151)
drift_field = drift(gridx) + gridx * 0.1 + 1
# kriging
model = Gaussian(dim=1, var=0.1, len_scale=2)
krig = krige.Universal(model, cond_pos, cond_val, "linear")
krig(gridx)
ax = krig.plot()
ax.scatter(cond_pos, cond_val, color="k", zorder=10, label="Conditions")
ax.plot(gridx, gridx * 0.1 + 1, ":", label="linear drift")
ax.plot(gridx, drift_field, "--", label="original field")

mean = krig(gridx, only_mean=True)
ax.plot(gridx, mean, label="estimated drift")

ax.legend()