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