I have some groundwater levels that I would like to interpolate over a region. I also want to take into consideration the effect of the topography. Thus, I did some research and it seems to be pretty common to use kriging with external drift to do the task. The problem is I'm getting a very ugly result, with some awkward vertical lines.
My code looks like this:
import numpy as npimport pandas as pdimport rasterioimport matplotlib.pyplot as pltfrom pykrige.uk import UniversalKriging# Coordinates and groundwater levels gw = {'x': [74061.23 , 74294.33 , 74055.93 , 74242.41 , 74028.914, 74255.65 ],'y':[217301.23, 217324.55, 217138.08, 217096.22, 217364.28, 217179.92],'h': [2.3 , 2.05, 1.78, 1.8 , 2.11, 1.96]}data = pd.DataFrame(gw, dtype=np.float32)X = data['x'].valuesY = data['y'].valuesZ = data['h'].values# Read dtm and get elevation (drift).dtm = 'sample_krig.tif'with rasterio.open(dtm) as src: drift = src.read(1) transform = src.transform# Create grid arrays for coordinates in rastergridx = np.arange(transform[2], transform[2] + transform[0] * src.width, transform[0])gridy = np.arange(transform[5], transform[5] + transform[4] * src.height, transform[4])# Set up kriging modeluk_model = UniversalKriging( X, Y, Z, variogram_model='exponential', # adjust better => check on this verbose=True, enable_plotting=False, drift_terms = 'external_Z', external_drift = drift, external_drift_x= gridx, external_drift_y= gridy)# Perfom krigingukr, ukv = uk_model.execute('grid', gridx, gridy)plt.imshow(ukr, extent=(gridx.min(), gridx.max(), gridy.min(), gridy.max()))plt.colorbar(label='Interpolated GW')plt.scatter(X, Y, c=Z, marker='o', edgecolors='k', label='Observed Wells')plt.title('Kriging Interpolation with Topography')plt.xlabel('X Coordinate')plt.ylabel('Y Coordinate')plt.legend()plt.show()The DTM is HEREI couldnt post the resulting image for some reason, but the interpolation looks very wrong. If I don't use external drift I get a pretty smooth result, but I want to include the effect of the elevation. Changing the variogram model does not have almost any effect on the result. Does anyone know if I'm doing something wrong during the set up?