Hi Madi, thank you, that's just what I thought of... anyway do you know does r.univar consider MASK if it is existing?
/johannes -------- Original-Nachricht -------- > Datum: Fri, 25 May 2012 13:38:05 +0200 > Von: Margherita Di Leo <[email protected]> > An: Johannes Radinger <[email protected]> > CC: grass user list <[email protected]> > Betreff: Re: [GRASS-user] Getting statistical values (r.univar) via python > Hi Johannes, > > On Fri, May 25, 2012 at 1:12 PM, Johannes Radinger <[email protected]> > wrote: > > > Hi, > > > > I am trying to get statistical values for a raster map in a python > script. > > What I am doing so far is using r.univar (e.g. for the nc-dataset): > > > > grass.read_command("r.univar", map ="elevation") > > > > but how to get e.g the mean value as float? I thought of two > > options: > > > > 1) either indexing like > > float(grass.read_command("r.univar", map ="elevation")[x:y]) > > > > 2) or splitting the string into lines and then at the ":" > > > > > You can use the following: > > import sys > import os > import grass.script as grass > > univar = grass.read_command('r.univar', map='elevation') > > print univar #so that you can see how the output looks like > > The output is: > total null and non-null cells: 2025000 > total null cells: 0 > > Of the non-null cells: > ---------------------- > n: 2025000 > minimum: 55.5788 > maximum: 156.33 > range: 100.751 > mean: 110.375 > mean of absolute values: 110.375 > standard deviation: 20.3153 > variance: 412.712 > variation coefficient: 18.4057 % > sum: 223510266.5581016541 > > Now you want to split every line of the output with .split('\n'), you are > interested in the line [10], then you split against split(':') and take > the > argument [1]. > > mean = float(univar.split('\n')[10].split(':')[1]) > > Hope this helps, > > madi > -- > Ing. Margherita Di Leo, Ph.D. -- NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone! Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a _______________________________________________ grass-user mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/grass-user
