python - Python 中的克里金法
问题描述
我已经使用 pykrige 进行插值 2d。
一些数据(x,y,z)是位置和海拔。
但是在普通克里金法('球形')上结果并不好。
如何调整参数以获得更好的结果。
或者对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)
解决方案
我不太了解pykrige。在OpenTURNS库中,我使用的参数优化是自动完成的。
在您的情况下,您有一个包含 x、y 和 z 的 Pandas 数据框“df_Points”。如果我理解得很好,你想要一个元模型:(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)
然后你可以试试球面克里金法。
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([x0, y0])
或在您的整个网格上。