<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p><br>
</p>
<div class="moz-cite-prefix">On 2/3/18 1:33 PM, Stefan Blumentrath
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:cf09d05037b441cfb2bfd112d4d9403c@NINSRV23.nina.no">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Hi
Paulo and Helmut,<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">Did you consider using cStringIO, if you need a
file-object?<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">That would avoid the temporary file and thus
should be more efficient too. See attached diff (it is
probably not necessary to remove the last line break
though).</span></p>
</div>
</blockquote>
Implemented your patch, thanks. Dinarzarde, can you test?<br>
<blockquote type="cite"
cite="mid:cf09d05037b441cfb2bfd112d4d9403c@NINSRV23.nina.no">
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">Just a suggestion.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">Yet, there might be even more efficient
solutions. For example raster2numpy from pygrass…<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB"><a
href="https://grass.osgeo.org/grass74/manuals/libpython/pygrass.raster.html#pygrass.raster.raster2numpy"
moz-do-not-send="true">https://grass.osgeo.org/grass74/manuals/libpython/pygrass.raster.html#pygrass.raster.raster2numpy</a><o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">Here however, you would have to mask NULL and I
am not sure how to (platform-independent) determine values
that represent NULL in a raster map. This gives pointers but
there are again issues with Windows it seems:
<a
href="https://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library#Interfacing_with_NumPy"
moz-do-not-send="true">
https://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library#Interfacing_with_NumPy</a><o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">And it leaves the question how to find out if a
raster is Integer or not…<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">With pygrass you could do:<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">from grass.pygrass import raster as r<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">p = np.ma.masked_equal(r.raster2numpy(raster),
np.nan)) # For floating point rasters on Linux<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">or<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">p = np.ma.masked_equal(r.raster2numpy(raster),
-2147483648)) # For integer rasters<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">Hints from experienced Python/Numpy developers
would be appreciated…<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">That makes me wonder if it would be worth to
add/collect recommendations for how to solve such common
operations (like e.g. parsing table output from grass
commands) either e.g. here: <a
href="https://trac.osgeo.org/grass/wiki/Submitting/Python"
moz-do-not-send="true">
https://trac.osgeo.org/grass/wiki/Submitting/Python</a> or
here: <a
href="https://grasswiki.osgeo.org/wiki/GRASS_and_Python"
moz-do-not-send="true">
https://grasswiki.osgeo.org/wiki/GRASS_and_Python</a> ?<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">Cheers<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB">Stefan<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"
lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"
lang="EN-GB"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif"
lang="EN-US">From:</span></b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif"
lang="EN-US"> grass-user
[<a class="moz-txt-link-freetext" href="mailto:grass-user-bounces@lists.osgeo.org">mailto:grass-user-bounces@lists.osgeo.org</a>]
<b>On Behalf Of </b>Paulo van Breugel<br>
<b>Sent:</b> lørdag 3. februar 2018 09.14<br>
<b>To:</b> Helmut Kudrnovsky <a class="moz-txt-link-rfc2396E" href="mailto:hellik@web.de"><hellik@web.de></a>;
<a class="moz-txt-link-abbreviated" href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><br>
<b>Subject:</b> Re: [GRASS-user] Issue with addon r.vif
in MS Windows GUI installations (stand-alone v. 7.2.2
and 7.0.5)<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p
style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm"><span
style="font-family:"Arial",sans-serif;color:black">On February
2, 2018 8:52:03 PM Helmut Kudrnovsky <<a
href="mailto:hellik@web.de" moz-do-not-send="true">hellik@web.de</a>>
wrote:<o:p></o:p></span></p>
<p
style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm"><span
style="font-family:"Arial",sans-serif;color:black">>>Any
idea how I can do that in such a way that it works on both
Linux and<br>
> Windows?<br>
><br>
> in r.vif script I've changed the relevant lines:<br>
><br>
> <----------------------------------------<br>
> # Get the raster values at sample points<br>
> fd, tmpcov = tempfile.mkstemp()<br>
> with open(tmpcov, "w") as text_file:<br>
> text_file.write(<br>
> gs.read_command("r.stats",
flags="1n", input=raster,<br>
> quiet=True,
separator="comma"))<br>
> p = np.loadtxt(tmpcov, skiprows=0, delimiter=",")<br>
><br>
> # Clean up<br>
> text_file.close()<br>
> os.close(fd)<br>
> os.remove(tmpcov)<br>
> if not n == "100%":<br>
> gs.run_command("r.mask", flags="r",
quiet=True)<br>
> if exist_mask['fullname']:<br>
> gs.run_command("g.rename",
raster=[mask_backup, "MASK"],<br>
> quiet=True)<br>
> return(p)<br>
> ----------------------------------------><br>
><br>
> and tested the script in winGRASS; it seems to work
in windows; not tested<br>
> on linux and mac.<br>
><br>
><br>
Ok, thanks Helmut, I'll see if that works in Linux too<br>
><br>
> -----<br>
> best regards<br>
> Helmut<br>
> --<br>
> Sent from: <a
href="http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html"
moz-do-not-send="true">
http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html</a><br>
> _______________________________________________<br>
> grass-user mailing list<br>
> <a href="mailto:grass-user@lists.osgeo.org"
moz-do-not-send="true">grass-user@lists.osgeo.org</a><br>
> <a
href="https://lists.osgeo.org/mailman/listinfo/grass-user"
moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/grass-user</a><o:p></o:p></span></p>
</div>
</div>
</blockquote>
</body>
</html>