2

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)
Xiang
  • 230
  • 2
  • 10
  • "Not good" is a comparative adjective. The "outcome is not good" compared to what? Does ArcGIS kriging, for example, produce better results? There's plenty of examples on PyKrige project page, so try different version of kriging algorithms and see what works better. – NotAName Jul 26 '20 at 06:52
  • 1
    The question would be more useful with a given value of `n`, instead of reading this from the user (the fact that this comes from the user is not relevant). I suggest to also add a set of given values of `z`, so that consistent answers can be provided. I guess that you omitted to import pandas in the beginning of the script: adding this import would allow to reproduce the script more easily. – Michael Baudin Oct 16 '20 at 17:07

1 Answers1

1

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.

josephmure
  • 208
  • 1
  • 9
Jean A.
  • 291
  • 1
  • 17