[GRASS-user] Phyton loop for IDW surfaces

francesco sapienza francesco.sapienza9491 at gmail.com
Mon Nov 19 19:21:53 PST 2018


Hello!!
I'm trying to run a loop to cross validate my IDW surfaces. The values that
i try to interpolate are pH values over a small zone in Siem Reap,
Cambodia. I've been using the following script:

from grass.pygrass.modules import Module
from subprocess import PIPE
import numpy as np
rsme = []
for i in range(1,5):
  idwout = "pH_CV"
  Module("v.extract", flags="r", input="pHsr", output="pHcalibration",
where="part={}".format(i),overwrite=True)
  Module("v.extract", input="pHsr", output="pHvalidation",
where="part={}".format(i),overwrite=True)
 Module("v.surf.idw",input="pHcalibration",column="dbl_3",npoints=12,power=2,output="pH_CV",
overwrite=True)
  Module("v.what.rast", map="pHvalidation", raster="pH_Surface",
column="actual")
  Module("v.what.rast", map="pHvalidation", raster="pH_CV",
column="estimated")
  sqlstat = "SELECT actual,estimated FROM pHvalidation"
  stats = Module("db.select", flags="c",
sql=sqlstat,stdout_=PIPE).outputs.stdout
  stats = stats.replace("\n", "|")[:-1].split("|")
  stats = (np.asarray([float(x) for x in stats],
dtype="float").reshape(len(stats)/2, 2))
  rsme = np.sqrt(np.mean(np.diff(stats, axis=1)**2))
  results = ("RSME (mean +/- stddev) = {} +/- {}".
  format(np.asarray(rsme).mean().round(2),
  np.asarray(rsme).std().round(2)))
  print results

The script is working but at the third round of the loop i get a Value
error (could not convert string to float). When i check the vector
pHvalidattion, i see that for some reason i have created a blank value in
the vector, that could not be used as a floating point number, of course...
which is really unexpected because all the values from the input are simple
numbers. (I've attached a screen of the vector with the blank value).

Another thing that bothers me is that the results are not printed the way i
wanted, instead of the RSME and +/- st.dev, i get different results for
RSME (one for each loop, i guess) +/- 0. Could be because i exchanged ±
with +/-?  (i was getting an unicode error using the first symbol). I doubt
that is the case because i think that "RSME (mean+/- stddev) = {} +/- {}"
is just specifing how i want the results printed.
In attached a screen of the display of the results.

Thank you for any kind of help! this mailing list has been of great help to
me since i started to use Gis GRASS! without your help everything would be
much more difficult for a beginner like me!

Best regards,
FS.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20181120/b6d661a3/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BlankValue.JPG
Type: image/jpeg
Size: 77527 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20181120/b6d661a3/attachment-0002.jpe>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Results.JPG
Type: image/jpeg
Size: 103245 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20181120/b6d661a3/attachment-0003.jpe>


More information about the grass-user mailing list