Skip to content

Issues with Kriging values #89

@donhalmina

Description

@donhalmina

I am performing an ordinary kriging and the results I get after performing the kriging are totally wrong. For simplicity, my grid points are also my data points. The working code is:

"Import libraries and modules"
import numpy as np
import gstools as gs
import tkinter as tk
from tkinter import filedialog
import pandas as pd
from scipy.spatial.distance import pdist, squareform

"Import data"
root = tk.Tk()
root.withdraw()
filepath = filedialog.askopenfilenames(parent=root, title='Choose a file')
data = pd.DataFrame()
for file in filepath:
    df = pd.read_excel(file)
    data = data.append(df)
data = data.iloc[:, :3]
data = data[~np.isnan(data).any(axis=1)]
data = np.array(data, dtype=np.float)

"Calculate semivariance"
sill = np.var(data[:, 2])
pwdist = squareform(pdist(data[:, :2]))
max_lag = np.int(np.ceil(np.max(pwdist)))
npoint = np.int(np.floor(max_lag/40)) 
firstlag = max_lag / 100
lags = np.linspace(firstlag, max_lag, npoint)
bin_center, gamma = gs.vario_estimate_unstructured((data[:,0], data[:,1]), data[:,2], lags)

"Fit theoretical variogram to data"
fit_model = gs.Stable(dim=2)
fit_model.set_arg_bounds(var=[0, sill])
fit_model.set_arg_bounds(len_scale=[0, 1000000])
fit_model.fit_variogram(bin_center, gamma, nugget=False)
ax = fit_model.plot(x_max=max_lag)
ax.plot(bin_center, gamma)
print(fit_model)

"Perform kriging"
OK = gs.krige.Ordinary(fit_model, [data[:, 0], data[:, 1]], data[:, 2])
OK.unstructured([data[:, 0], data[:, 1]])
ax = OK.plot()
ax.set_aspect("equal")

The semivariogram looks good (as attached below).
GSTool_Stable Variogram

The value of my kriging should range between 0 and 400 as data[:, 2] ranges between this value. However, i am getting values between -3000 and 8000.
GSTool_Unstructured_OK

Find attached the data to reproduce the problem

CNDA-ESP_SIMRAD_MDS_DGPS_2000_2001.xlsx

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or requestquestionFurther information is requested

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions