Ordinary Kriging + SGSIM#

This example shows how to run SGSIM ordinary kriging and plot the interpolated field.

from krigekit import Kriging
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid

data = pd.read_csv("../test_data/pc2d.csv")
grid = pd.read_csv("../test_data/grid2d.csv")

# nsim is the number of realizations
k = Kriging(nsim=3, bounds=[0,1])
k.set_obs(ivar=1, coord=data[["x", "y"]], value=data["pc"], nmax=100)
k.set_grid(coord=grid[["x", "y"]])
k.set_vgm(ivar=1, jvar=1, vtype="sph", sill=0.12, a_major=5000.0)
k.set_sim()
k.set_search()
k.solve()
df = k.get_result_df()
del k
print(df)

fig = plt.figure(figsize=(11, 5))
axs = ImageGrid(fig, 111,  # similar to subplot(111)
                nrows_ncols=(1, 3),
                axes_pad=0.1,
                label_mode="L",
                cbar_mode="single", cbar_size="7%", cbar_pad="2%"
                )

for i, ax in enumerate(axs):
    est = df[f"sim_{i+1}"].values.reshape([80, 60])
    im = ax.imshow(est, cmap="turbo", vmin=0, vmax=1)
    ax.set(title=f"Realization {i+1}")
ax.cax.colorbar(im, label="Coarse Fraction")
Realization 1, Realization 2, Realization 3
             x          y     sim_1     sim_2     sim_3  variance
0     573349.0  4400382.0  1.000000  0.731292  0.750907  0.012934
1     573554.0  4400525.0  1.000000  0.854433  1.000000  0.030130
2     573759.0  4400669.0  0.779674  0.750865  0.993003  0.008011
3     573964.0  4400812.0  0.952092  0.758432  0.873084  0.009427
4     574169.0  4400956.0  0.902022  0.642182  0.480121  0.010194
...        ...        ...       ...       ...       ...       ...
4795  595941.0  4392091.0  0.876785  0.552378  0.652102  0.011601
4796  596146.0  4392234.0  0.887029  0.806161  0.502084  0.007966
4797  596351.0  4392377.0  0.703353  0.811100  0.354487  0.009490
4798  596555.0  4392521.0  0.778547  0.706754  0.406360  0.016269
4799  596760.0  4392664.0  0.788158  0.624648  0.400711  0.013203

[4800 rows x 6 columns]

<matplotlib.colorbar.Colorbar object at 0x7e698042d950>

Change Seed#

Let’s change seed number and see how different the results are.

k = Kriging(nsim=3, bounds=[0,1], seed=1000)
k.set_obs(ivar=1, coord=data[["x", "y"]], value=data["pc"], nmax=100)
k.set_grid(coord=grid[["x", "y"]])
k.set_vgm(ivar=1, jvar=1, vtype="sph", sill=0.12, a_major=5000.0)
k.set_sim()
k.set_search()
k.solve()
df = k.get_result_df()
del k
print(df)

fig = plt.figure(figsize=(11, 5))
axs = ImageGrid(fig, 111,  # similar to subplot(111)
                nrows_ncols=(1, 3),
                axes_pad=0.1,
                label_mode="L",
                cbar_mode="single", cbar_size="7%", cbar_pad="2%"
                )

for i, ax in enumerate(axs):
    est = df[f"sim_{i+1}"].values.reshape([80, 60])
    im = ax.imshow(est, cmap="turbo", vmin=0, vmax=1)
    ax.set(title=f"Realization {i+1}")
ax.cax.colorbar(im, label="Coarse Fraction")
Realization 1, Realization 2, Realization 3
             x          y     sim_1     sim_2     sim_3  variance
0     573349.0  4400382.0  0.930852  0.995609  0.750976  0.013098
1     573554.0  4400525.0  0.974483  1.000000  0.805975  0.018788
2     573759.0  4400669.0  0.849792  0.837587  0.843582  0.008706
3     573964.0  4400812.0  0.827087  0.968541  1.000000  0.013434
4     574169.0  4400956.0  1.000000  0.919989  1.000000  0.008672
...        ...        ...       ...       ...       ...       ...
4795  595941.0  4392091.0  0.556118  0.867091  0.423065  0.021341
4796  596146.0  4392234.0  0.442233  0.751838  0.704909  0.011170
4797  596351.0  4392377.0  0.519492  0.704493  0.797495  0.007828
4798  596555.0  4392521.0  0.629894  0.790397  0.935313  0.015007
4799  596760.0  4392664.0  0.560905  0.895621  0.962170  0.009910

[4800 rows x 6 columns]

<matplotlib.colorbar.Colorbar object at 0x7e69800bed10>

Total running time of the script: (0 minutes 3.394 seconds)

Gallery generated by Sphinx-Gallery