Xiang
Xiang

Reputation: 495

Kriging in Python

I have use pykrige for interpolation-2d.

A few data (x, y, z) which is location and elevation.

But the outcome is not good on ordinaryKriging (‘spherical’).

How can I adjust the parameters to get better outcome.

Or any suggestion for kriging algorithm in python?

n = int(input("Enter the Slice number:"))
x = df_Points[n]['x']
y = df_Points[n]['y']
z = df_Points[n]['z']

gridx = np.arange(min(x) - 100, max(x) + 100, 10.0)
gridy = np.arange(min(y) - 100, max(y) + 100, 10.0)

# OrdinaryKriging
from pykrige.ok import OrdinaryKriging
# ordinary kriging with pykrige
OK = OrdinaryKriging(
    x,
    y,
    z,
    variogram_model='spherical')

z1, ss1 = OK.execute("grid", gridx, gridy)

Upvotes: 2

Views: 3774

Answers (1)

Jean A.
Jean A.

Reputation: 301

I don't know very well pykrige. In OpenTURNS library I am using the optimization of the parameters is done automatically.

In your case, you have a Pandas dataframe "df_Points" containing x, y and z. If I understand well, you want a metamodel: (x,y) -> z

import openturns as ot

# your input / output data can be easily formatted as samples for openturns
inputdata = ot.Sample(df[['x','y']].values)
outputdata = ot.Sample(df[['z']].values)

Then you can try spherical Kriging.

dimension = 2  # dimension of your input (x,y)
basis = ot.ConstantBasisFactory(dimension).build()
covarianceModel = ot.SphericalModel(dimension)
    
algo = ot.KrigingAlgorithm(inputdata, outputdata, covarianceModel, basis)
algo.run()
result = algo.getResult()
metamodel = result.getMetaModel()

metamodel is what you are looking for. You can execute it on a specific point

metamodel([x0, y0])

or on your entire meshgrid.

Upvotes: 1

Related Questions