I've previously used ArcGIS for Ordinary Kriging, but I now need a Python alternative.
I found the
PyKrige module which i decided to give a try, but I am bit confused by it.
So far, I have read my XYZ file into a numpy array like so
import matplotlib.pyplot as plt import numpy as np import pykrige.kriging_tools as kt from pykrige.ok import OrdinaryKriging from numpy import genfromtxt np.set_printoptions(suppress=True) my_data = genfromtxt('C:/myfile.xyz') data = np.array(my_data) print(data)
which prints my data like so
[[626769.27 233220.76 14.66] [626768.91 233221.02 14.65] [626768.58 233221.26 14.64] ...
However, the next part of the PyKrige example found at https://geostat-framework.readthedocs.io/projects/pykrige/en/stable/examples/00_ordinary.html#sphx-glr-examples-00-ordinary-py uses the following code after reading the data into an array
gridx = np.arange(0.0, 5.5, 0.5) gridy = np.arange(0.0, 5.5, 0.5) OK = OrdinaryKriging( data[:, 0], data[:, 1], data[:, 2], variogram_model="linear", verbose=False, enable_plotting=False, ) z, ss = OK.execute("grid", gridx, gridy) kt.write_asc_grid(gridx, gridy, z, filename="pykrigoutput.asc") plt.imshow(z) plt.show()
This is what's confusing me. I don't know how the
gridy are determined?
z, ss the variable name or what is this?
My output will be a GeoTiff (hopefully that's supported) and I hope to set an output cell size of 0.5
But can anyone advise me how to successfully use this module as the documentation gives no explanation of the example.