I am writing a PyQGIS script to automate interpolation using the sagang:ordinarykriging algorithm (QGIS 3.28.13, SAGA 9.2.0).
While the algorithm runs successfully with the default linear variogram model ('a + b * x'), it fails when I try to specify a more complex non-linear model for my temperature data, such as Spherical or Exponential.
My main issue is that the formula syntax that works perfectly in the standalone SAGA desktop application causes the tool to fail within PyQGIS or QGIS UI.
For example, using the full exponential model formula results in the process failing or creating an output raster with values that make no sense.
Here is the relevant portion of my code:
kriging_params = { 'POINTS': point layer, 'FIELD': 'TMAVG', 'LOG': False, 'VAR_MODEL': 'n + (s-n) * (1 - exp(-k * x/r)); n=n; s=s; r=r; k=3', 'SEARCH_RADIUS': 15000, 'PREDICTION': 'path to output' } processing.run('sagang:ordinarykriging', kriging_params) What I have already tried for the VAR_MODEL parameter:
The full SAGA formula: As shown above, this causes the algorithm to fail. Also same formula but without the definition of n=n, s=s, etc. still fails.
Simple keywords: Using strings like 'spherical' or 'exponential' is not recognized.
Numeric codes: Older SAGA versions accepted codes like '1' for Spherical, but this syntax also causes an error in this version.
What is the correct string format to successfully define a non-linear variogram model (like Spherical or Exponential) for the VAR_MODEL parameter when calling sagang:ordinarykriging from a PyQGIS script?


n=n; s=s; r=r; k=3after a semicolon, try passing only the core formula'VAR_MODEL': 'n + (s-n) * (1 - exp(-k * x/r))'or use an if-function for spherical model"a + b * if(x > c, 1, 1.5 * x / c - 0.5 * x^3 / c^3)"