[GRASS-user] Phyton loop for IDW surfaces
st_kiefer at web.de
st_kiefer at web.de
Mon Nov 19 23:43:00 PST 2018
Hi,
if you just copy-pasted you code, then it seems the third Module-call is not indented, i.e. is not executed in the loop.
Regards.
Stefan
> francesco sapienza <francesco.sapienza9491 at gmail.com> hat am 20. November 2018 um 04:21 geschrieben:
>
>
> 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.
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-user
More information about the grass-user
mailing list