Learn Before
Inverse Distance Weighted (IDW) Interpolation Method
IDW interpolation method is used to predict numerical values of a variable at areas with unknown values. The algorithm uses known variable values surrounding the unknown location to predict the numerical attribute value of that location. The known values closest to the prediction (unknown value) location have more influence on the predicted value than those farther away. IDW assumes that local (surrounding) influence on the predicted value diminishes with distance raised to the power of p. It gives greater weights to points closest to the prediction location, and the weights diminish as a function of distance, hence the name inverse distance weighted.
The code below demonstrates how the IDW algorithm can be run in Python.
Description: Interpolationing Unknown Elevation from Known Elevations of Neighbouring Points by IDW
Variable description: z = elevation; d = distance; p = power
print ("Welcome to the IDW Interpolation Method Program")
print ("===============================================")
print ("")
Entering input parameters
z1 = float (input ("Input the known elevation value of the first location and press ENTER: "))
d1 = float (input ("Input the known distance value from the first location and press ENTER: "))
print ("")
z2 = float (input ("Input the known elevation value of the second location and press ENTER: "))
d2 = float (input ("Input the known distance value from the second location and press ENTER: "))
print ("")
z3 = float (input ("Input the known elevation value of the third location and press ENTER: "))
d3 = float (input ("Input the known distance value from the third location and press ENTER: "))
print ("")
z4 = float (input ("Input the known elevation value of the fourth location and press ENTER: "))
d4 = float (input ("Input the known distance value from the fourth location and press ENTER: "))
print ("")
p = float(input ("Input the value of power (p) and press ENTER. For optimal results, p usually ranges between 1 and 2: "))
print ("")
Simplifying variables
A1 = z1/(d1**p)
A2 = z2/(d2**p)
A3 = z3/(d3**p)
A4 = z4/(d4**p)
B1 = 1/(d1**p)
B2 = 1/(d2**p)
B3 = 1/(d3**p)
B4 = 1/(d4**p)
Calculting unknown elevation from known elevation points
Z = (A1 + A2 + A3 + A4)/(B1 + B2 + B3 + B4)
Printing the result rounded up to 3 decimal places
print ("The Inverse Distance Weighted (IDW) elevation value of the unknown location is", round (Z,3))
print ("======================================================================================") print ("")
End of program
print ("End of the program ...")
0
1
Tags
Python Programming Language
Data Science