自定义函数实现普通克里金插值法python代码
时间: 2023-11-13 17:47:38 浏览: 162
好的,下面是自定义函数实现普通克里金插值法的Python代码:
```
import numpy as np
from scipy.spatial.distance import cdist
def ordinary_kriging(xyz, xy, sill, nugget):
"""Ordinary Kriging interpolation using the Hill estimator"""
# Extracting coordinates and values from input arguments
x = xyz[:, 0]
y = xyz[:, 1]
z = xyz[:, 2]
xi = xy[:, 0]
yi = xy[:, 1]
# Computing Euclidean distances between input and interpolation points
d = cdist(np.column_stack((x, y)), np.column_stack((xi, yi)))
# Computing covariance matrix between input points and interpolation points
cov_mat = (sill - nugget) * np.exp(-d) + nugget * np.identity(len(xyz))
# Applying Hill estimator to covariance matrix to estimate observation variance
var_obs = np.mean(np.diag(cov_mat))
# Computing weights for interpolation points
weights = np.linalg.solve(cov_mat, z - np.mean(z))
# Computing interpolated values at interpolation points
iz = np.dot(d.T, weights) + np.mean(z)
return iz, var_obs
```
其中,参数说明如下:
- `xyz`:包含所有输入点的坐标和对应值的三列数组。
- `xy`:包含所有需要插值的点的坐标的二列数组。
- `sill`:变异函数的 sill 值。
- `nugget`:变异函数的 nugget 值。
函数返回值为:
- `iz`:插值点对应的插值值的一维数组。
- `var_obs`:观测方差的值。
阅读全文