In case you want to make it go faster by reducing duplicated computations:
def CalcIDWvalue(unknowncell, knowncells):
weighted_values_sum = 0.0
sum_of_weights = 0.0
neg_half_sens = -sensitivity/2.0
for knowncell in knowncells:
weight = ((unknowncell.x-knowncell.x)**2 + (unknowncell.y-knowncell.y)**2)**neg_half_sens
sum_of_weights += weight
weighted_values_sum += weight * knowncell.value
return weighted_values_sum / sum_of_weights
You can see distance-based interpolation formula in following link:
http://www.gitta.info/ContiSpatVar/en/html/Interpolatio_learningObject2.xhtml
where p is distance weighting exponent and it probably was the parameter that is different between these 2 SAGA versions.
So, it's relatively easy to code this algorithm in PyQGIS. As follow, it has inside three arbitrary points to be interpolated and it was used a five points layer as base of interpolation.
from math import sqrt
def idw(pt, points, z, beta):
n = len(points)
sum_inv_dist_z = 0
sum_inv_dist = 0
for i in range(n):
inv_dist = 1/(sqrt(pt.sqrDist(points[i])))**beta
inv_dist_z = z[i]*inv_dist
sum_inv_dist_z += inv_dist_z
sum_inv_dist += inv_dist
z_j = sum_inv_dist_z/sum_inv_dist
return z_j
#Code starts here
layer = iface.activeLayer()
features = layer.getFeatures()
#get features for geometry
points = [feature.geometry().asPoint() for feature in features]
#get features for attributes
features = layer.getFeatures()
attr = [feature.attributes() for feature in features]
#selecting elevation field
z = [item[4] for item in attr]
print z
#set beta value
beta = 2
#defining arbitrary points
pt = [QgsPoint(398574.065172, 4452409.334),
QgsPoint(412049.303287, 4447317.71399),
QgsPoint(434741.145557, 4435557.70814)]
#calculating z value for each point
for item in pt:
print idw(item, points, z, beta)
Used layers look as at following image where green points will be interpolated and blue points have z values.
After running code at Python Console of QGIS I got:
[1694.0, 1700.0, 1368.0, 1439.0, 1368.0, 1943.0]
1709.79209934
1622.47616106
1436.15697073
where it can be observed that obtained values are similar to neighbors.
However, it's more useful when above algorithm was coded in my own IDW plugin to get a complete raster (perfectly aligned with base raster). In following composition I used 25 points and p different values (0.1, 0.5 and 2). It can be observed that p parameter is a smoothed factor.
By the way, my results are identical to obtained with IDW QGIS tool; except my interpolated rasters were perfectly aligned with base raster.
Best Answer
When you refer to the output being "gridded", I'm assuming you mean that the output is a raster.
The various IDW Interpolation tools all create rasters as their outputs. You can turn a raster into contours by an additional step, using any of these tools/algorithms:
To find these tools, search for "contour" in the processing toolbox.