Tutorials
Juyter Logo

Detrended Kriging

%matplotlib widget
import matplotlib.pyplot as plt
plt.ioff()
# turn of warnings
import warnings
warnings.filterwarnings('ignore')
import numpy as np
import gstools as gs


def trend(*pos):
    """Example for a simple linear trend."""
    return pos[0] * 0.1 + 1


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