from gstools import CovModel import numpy as np # use CovModel as the base-class class Gau(CovModel): def correlation(self, r): return np.exp(-(r / self.len_scale)**2) model = Gau(dim=2, var=2.0, len_scale=10) from gstools.covmodel.plot import plot_variogram plot_variogram(model) print(model.dim, model.var, model.len_scale, model.nugget, model.sill) model.dim = 3 model.var = 1 model.len_scale = 15 model.nugget = 0.1 print(model.dim, model.var, model.len_scale, model.nugget, model.sill) model = Gau(dim=3, var=2.0, len_scale=10, anis=0.5) print(model.anis) print(model.len_scale_vec) model = Gau(dim=3, var=2.0, len_scale=[10, 5, 4]) print(model.anis) print(model.len_scale) print(model.len_scale_vec)
bins = np.linspace(0, 10, 50) print('Estimating unstructured variogram') bin_center, gamma = vario_estimate_unstructured( (x_u, y_u), herten_log_trans.reshape(-1), bins, sampling_size=2000, sampling_seed=19920516, ) # fit an exponential model fit_model = Exponential(dim=2) fit_model.fit_variogram(bin_center, gamma, nugget=False) pt.plot(bin_center, gamma) plot_variogram(fit_model, x_max=bins[-1]) ############################################################################### # estimate the variogram on a structured grid ################################# ############################################################################### # estimate the variogram on a structured grid # use only every 10th value, otherwise calculations would take very long x_s_skip = x_s[::10] y_s_skip = y_s[::10] herten_trans_skip = herten_log_trans[::10, ::10] print('Estimating structured variograms') gamma_x = vario_estimate_structured(herten_trans_skip, direction='x') gamma_y = vario_estimate_structured(herten_trans_skip, direction='y')
# # Next, we need to compute a variogram for the temperature probe data and fit that variogram to an exponential model bins = np.linspace(0, 12300, 1000) bin_center, gamma = vario_estimate_unstructured( project["Observed Temperature"].points.T, project["Observed Temperature"]["temperature (C)"], bins, ) fit_model = Exponential(dim=3) fit_model.fit_variogram(bin_center, gamma, nugget=False) plt.figure(figsize=(10, 5)) plt.plot(bin_center, gamma) plot_variogram(fit_model, x_max=bins[-1], ax=plt.gca()) plt.xlabel("Lag Distance") plt.ylabel("Variogram") plt.show() ############################################################################### # Performing the Kriging # ^^^^^^^^^^^^^^^^^^^^^^ # Then we pass the fitted exponential model when instantiating the kriging operator from GSTools. # Create the kriging model krig = krige.Ordinary( fit_model, project["Observed Temperature"].points.T, project["Observed Temperature"]["temperature (C)"], )