Lorenz
Lorenz

Reputation: 5

Pykrige: Kriging with Specified Drifts

I can´t figure out how to include specified drifts in the interpolation. My code is the following:

x = np.array([0, 1, 2, 3, 4])
y = np.array([0, 1, 2, 3, 4])
values = np.array([1, 2, 3, 5, 4])
drift = np.array([-14, 2, 6, 1, 3])

gridx = np.linspace(0, 4, 10)
gridy = np.linspace(0, 4, 10)

UK = UniversalKriging(
    x,
    y,
    values,
    variogram_model="linear",
    drift_terms=["specified"],
    specified_drift = [drift]
)

z, ss = UK.execute("grid", gridx, gridy)
plt.imshow(z)
plt.show()

I get an ValueError

ValueError: Must provide drift values for kriging points when using 'specified' drift capability.

Upvotes: 0

Views: 209

Answers (1)

MuellerSeb
MuellerSeb

Reputation: 859

If you want to use a specified drift, you also need to provide it at the target grid with the specified_drift_arrays argument in UK.execute (see the documentation)

grid_drift = ... # external drift at target locations
z, ss = UK.execute("grid", gridx, gridy, specified_drift_arrays=[grid_drift])

Note that the drift needs to be given in a list since there can be multiple drifts.

Hope this helps.

Upvotes: 0

Related Questions