[GRASS-user] Issue with addon r.vif in MS Windows GUI installations (stand-alone v. 7.2.2 and 7.0.5)

Stefan Blumentrath Stefan.Blumentrath at nina.no
Sat Feb 3 04:33:01 PST 2018

Hi Paulo and Helmut,

Did you consider using cStringIO, if you need a file-object?
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).

Just a suggestion.
Yet, there might be even more efficient solutions. For example raster2numpy from pygrass...
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: https://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library#Interfacing_with_NumPy
And it leaves the question how to find out if a raster is Integer or not...

With pygrass you could do:
from grass.pygrass import raster as r
p = np.ma.masked_equal(r.raster2numpy(raster), np.nan)) # For floating point rasters on Linux
p = np.ma.masked_equal(r.raster2numpy(raster), -2147483648)) # For integer rasters

Hints from experienced Python/Numpy developers would be appreciated...

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: https://trac.osgeo.org/grass/wiki/Submitting/Python or here: https://grasswiki.osgeo.org/wiki/GRASS_and_Python ?


From: grass-user [mailto:grass-user-bounces at lists.osgeo.org] On Behalf Of Paulo van Breugel
Sent: lørdag 3. februar 2018 09.14
To: Helmut Kudrnovsky <hellik at web.de>; grass-user at lists.osgeo.org
Subject: Re: [GRASS-user] Issue with addon r.vif in MS Windows GUI installations (stand-alone v. 7.2.2 and 7.0.5)

On February 2, 2018 8:52:03 PM Helmut Kudrnovsky <hellik at web.de<mailto:hellik at web.de>> wrote:

>>Any idea how I can do that in such a way that it works on both Linux and
> Windows?
> in r.vif script I've changed the relevant lines:
> <----------------------------------------
>     # Get the raster values at sample points
>     fd, tmpcov = tempfile.mkstemp()
>     with open(tmpcov, "w") as text_file:
>         text_file.write(
>                 gs.read_command("r.stats", flags="1n", input=raster,
>                                 quiet=True, separator="comma"))
>     p = np.loadtxt(tmpcov, skiprows=0, delimiter=",")
>     # Clean up
>     text_file.close()
>     os.close(fd)
>     os.remove(tmpcov)
>     if not n == "100%":
>         gs.run_command("r.mask", flags="r", quiet=True)
>         if exist_mask['fullname']:
>             gs.run_command("g.rename", raster=[mask_backup, "MASK"],
>                            quiet=True)
>     return(p)
> ---------------------------------------->
> and tested the script in winGRASS; it seems to work in windows; not tested
> on linux and mac.
Ok, thanks Helmut, I'll see if that works in Linux too
> -----
> best regards
> Helmut
> --
> Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org<mailto:grass-user at lists.osgeo.org>
> https://lists.osgeo.org/mailman/listinfo/grass-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20180203/fc64b592/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: r.vif.diff
Type: application/octet-stream
Size: 1082 bytes
Desc: r.vif.diff
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20180203/fc64b592/attachment-0001.obj>

More information about the grass-user mailing list