1

I want to use a Python script for interpolation in 1st image to have the result of 2nd one, this result is from simple kriging saga. I tried the code below but I have two main problems.

  1. Need a lot of time, over 3-4 hours to have
  2. The result is this in 3d image and it's really different.
from osgeo import gdal,ogr
import numpy as np
import gstools as gs
import time

#read a 2-D array from image
filefolder="C:/Users/fermi/Desktop/SUEWS/SUEWSapp/kriging/"
rasterinput=filefolder+"T2UFfill_T2_01_14.tif"
src_ds = gdal.Open( rasterinput )
b3 = np.array(src_ds.GetRasterBand(1).ReadAsArray())

# the coordinates of x and y
x= np.arange(322580., 335780., 100.)
y = np.arange(3906895., 3913695. , 100.)
start = time.time()
print("hello")

# your input data as x, y, data points
data = b3
cond_pos = gs.generate_grid((x,y))
cond_val = [1.0]
mean = np.mean(data)
# simple gaussian model since your plot looks rather smooth
model = gs.Gaussian(dim=2,len_scale=1)
krige = gs.krige.Simple(model, cond_pos, data)

# output on a structured grid (image) with specified axis
xaxis, yaxis = y,x
field = krige.structured([xaxis, yaxis], return_var=False)

enter image description here enter image description here

7
  • 1
    Simple Kriging is inappropriate for raster data (for both statistical and practical reasons, as you have learned). What really is your problem: do you just need to interpolate or do you really need to Krige for some reason?
    – whuber
    Aug 11, 2021 at 17:10
  • I want to interpolate, but using simple interpolation, like bilinear or other from warp, has not the result that i want. The 2nd image as you is produced from SAGA Simple Kriging model and it can be produced in less than a couple of minutes. So i m trying to use something similar in python script or a way to use SAGA in a standalone python. I found this library for Kriging and i m trying to use it without result. If there is another way to interpolate image 1 to image 2 i would be glad to hear it. Aug 12, 2021 at 8:40
  • There are enormous numbers of ways to interpolate. Please search this site for solutions.
    – whuber
    Aug 12, 2021 at 12:55
  • i tried some of them but i think i need kriging. Because using interpolation the doesn't change the value of the pixel. If you see the 2nd image it has different values. So if you know any way to use kriging i would be grateful for that. Or a way to use saga in a standalone python script could be the solution. Aug 13, 2021 at 10:42
  • It sounds like either you aren't interpolating correctly or you need something else besides interpolation.
    – whuber
    Aug 13, 2021 at 13:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.