我几乎完成了空间插值,但是结果图不是我想要的。我遵循了关于克里金法的 scikit-gstools 文档:https ://scikit-gstat.readthedocs.io/en/latest/tutorials/01_getting_started.html
最后一个情节是我想要的。
我当前的代码如下所示:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pprint import pprint
plt.style.use('ggplot')
from skgstat import Variogram, OrdinaryKriging
data = pd.read_csv("kerpencsv.csv")
print("Loaded %d rows and %d columns" % data.shape)
data.head()
data = pd.read_csv("kerpencsv.csv")
print("Loaded %d rows and %d columns" % data.shape)
data.head()
OUT:加载 1046 行 3 列
经纬度沉降
0 6.702397 50.91644 -6.317195
1 6.703119 50.91653 -5.610300
2 6.703386 50.91633 -4.985516
3 6.702680 50.91618 -5.956828
4 6.703945 50.91625 -4.455712
fig, ax = plt.subplots(1, 1, figsize=(9, 9))
art = ax.scatter(data.longitude,data.latitude, s=50, c=data.subsidence, cmap='plasma')
plt.colorbar(art);
V = Variogram(data[['longitude', 'latitude']].values, data.subsidence, normalize=False, maxlag=5, n_lags=15)
fig = V.plot(show=False)
print('Sample variance: %.2f Variogram sill: %.2f' % (data.subsidence.var(), V.describe()['sill']))
pprint(V.describe())
print(V)
print(V)
spherical Variogram
-------------------
Estimator: matheron
Effective Range: 0.05
Sill: 222.34
Nugget: 0.00
ok = OrdinaryKriging(V, min_points=5, max_points=15, mode='exact')
xx, yy = np.mgrid[6.67:6.69:6.72j, 50.86:50.88:50.92j]
field = ok.transform(xx.flatten(), yy.flatten()).reshape(xx.shape)
s2 = ok.sigma.reshape(xx.shape)
fig, axes = plt.subplots(1, 2, figsize=(20, 10))
art = axes[0].matshow(field.T, origin='lower', cmap='plasma')
axes[0].set_title('Interpolation')
axes[0].plot(data.longitude, data.latitude, '+k')
axes[0].set_xlim((6.67,6.72))
axes[0].set_ylim((50.86,50.92))
plt.colorbar(art, ax=axes[0])
art = axes[1].matshow(s2.T, origin='lower', cmap='YlGn_r')
axes[1].set_title('Kriging Error')
plt.colorbar(art, ax=axes[1])
axes[1].plot(data.longitude, data.latitude, '+w')
axes[1].set_xlim((6.67,6.72))
axes[1].set_ylim((50.86,50.92));
如您所见,我没有得到彩色克里金模型和反映非常高克里金误差的图。我不确定如何处理这个问题,如果有任何帮助,我将不胜感激!