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

2018-02-14 Thread Markus Neteler
On Wed, Feb 14, 2018 at 12:22 AM, Paulo van Breugel
 wrote:
> On Tue, Feb 13, 2018 at 5:15 PM, Markus Neteler  wrote:
...
>> Could you please check if this depends on the programming language in
>> which the respective module was written (Python, C, ...)?
>
> Installed r.area (C) en r.bioclim (Python) and indeed, the former shows up
> under the Modules tab in the addon group, the latter not.

Could you please open a bug report?

thanks,
Markus
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-13 Thread Paulo van Breugel
On Tue, Feb 13, 2018 at 5:15 PM, Markus Neteler  wrote:

> On Tue, Feb 13, 2018 at 12:45 AM, Paulo van Breugel
>  wrote:
> > Hi Dinarzarde and Helmut
> >
> > I checked on Windows (grass 7.4.0 installed using osgeo4w), and
> installing
> > r.vif using g.extension works fine, but after installing it does not
> appear
> > in the addon list in the Modules tab. The same is true for a number of
> other
> > addons I installed. There are, on the other hand, a number of addons that
> > appear in the list (r.regression.series, r.series.lwr, v.kriging, and 6
> > others).
>
>
> Could you please check if this depends on the programming language in
> which the respective module was written (Python, C, ...)?
>


Installed r.area (C) en r.bioclim (Python) and indeed, the former shows up
under the Modules tab in the addon group, the latter not.


>
> best,
> Markus
>
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-13 Thread Markus Neteler
On Tue, Feb 13, 2018 at 12:45 AM, Paulo van Breugel
 wrote:
> Hi Dinarzarde and Helmut
>
> I checked on Windows (grass 7.4.0 installed using osgeo4w), and installing
> r.vif using g.extension works fine, but after installing it does not appear
> in the addon list in the Modules tab. The same is true for a number of other
> addons I installed. There are, on the other hand, a number of addons that
> appear in the list (r.regression.series, r.series.lwr, v.kriging, and 6
> others).


Could you please check if this depends on the programming language in
which the respective module was written (Python, C, ...)?

best,
Markus
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-13 Thread Helmut Kudrnovsky
>Many thanks Paulo and Helmut. Have an osgeo4w installation of grass 7.4.0,
so will run it on the console. 

also in the winGRASS7.4.0 standalone installation invoking r.vif in the
console should work. 



-
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-13 Thread Helmut Kudrnovsky
>I checked on Windows (grass 7.4.0 installed using osgeo4w), and
>installing r.vif using g.extension works fine, but after installing it
>does not appear in the addon list in the Modules tab. The same is true
>for a number of other addons I installed. There are, on the other hand,
>a number of addons that appear in the list (r.regression.series,
>r.series.lwr, v.kriging, and 6 others). 

tested here in winGRASS7.4.0 and winGRASS7.5.svn; confirmed, only some
of the installed addons are in the modules tab.

maybe worth a ticket.



-
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-12 Thread Dinarzarde Raheem
Many thanks Paulo and Helmut. Have an osgeo4w installation of grass 7.4.0, so 
will run it on the console.

Best wishes,

Dinarzarde

From: Paulo van Breugel [p.vanbreu...@gmail.com]
Sent: 12 February 2018 23:45
To: Dinarzarde Raheem; Helmut Kudrnovsky
Cc: grass-user@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)

Hi Dinarzarde and Helmut

I checked on Windows (grass 7.4.0 installed using osgeo4w), and
installing r.vif using g.extension works fine, but after installing it
does not appear in the addon list in the Modules tab. The same is true
for a number of other addons I installed. There are, on the other hand,
a number of addons that appear in the list (r.regression.series,
r.series.lwr, v.kriging, and 6 others).

However, running these addons from the console (type in r.vif on the
console) works.


Best wishes

Paulo


On 2/12/18 8:40 PM, Dinarzarde Raheem wrote:
> Hi Helmut,
>
> I have been installing r.vif as you have indicated (i.e. by downloading from 
> the server using g.extension and opening the tree of installable raster 
> addons), but can now confirm after installing both the new and old versions 
> of r.vif on a Windows 10 (64 bit) machine, that r.vif isn't listed under the 
> Addons in the module tab in both Grass standalone GUI versions 7.2.2 and 
> 7.4.0 (i.e. there is no plus sign in front of Addons, so there is no way of 
> opening the tree of installed addons and selecting and running r.vif).
>
> Best wishes,
>
> Dinarzarde
>
>
> 
> From: Helmut Kudrnovsky [hel...@web.de]
> Sent: 11 February 2018 16:13
> To: Dinarzarde Raheem
> Cc: grass-user@lists.osgeo.org; Paulo van Breugel
> Subject: Aw: RE: [GRASS-user] Issue with addon r.vif in MS Windows GUI 
> installations (stand-alone v. 7.2.2 and 7.0.5)
>
>> Gesendet: Sonntag, 11. Februar 2018 um 16:36 Uhr
>> Von: "Dinarzarde Raheem" 
>> I tried GRASS GIS versions 7.4.0 (current stable) and GRASS GIS 7.2.2 (old 
>> stable) but can't see r.vif listed under Addons in the Modules tab (see 
>> attached >screenshot).
> you have to click on the + before "Raster" to open the tree of installable 
> raster addons.
>
>
>
>> One thing I noticed is that when you re-install Grass and then install r.vif 
>> you get this message:
>> (Sun Feb 11 16:29:48 2018)
>> g.extension extension=r.vif url=
>> WARNING: Extension  already installed. Re-installing...
>> Downloading precompiled GRASS Addons ...
>> Updating addons metadata file...
>> Installation of  successfully finished
>> (Sun Feb 11 16:29:57 2018) Command finished (9 sec)
> yes, it's an obvious message as you install the script from the server over 
> the local copy.
>
>> I guess by tomorrow the new version of r.vif should be available via the 
>> server so will try again tomorrow.
> the new version is already on the server and should be installable by 
> g.extension, see
>
> for winGRASS7.5.svn daily:
> https://wingrass.fsv.cvut.cz/grass75/x86_64/addons/grass-7.5.svn/
>
> for  winGRASS7.4.0:
> https://wingrass.fsv.cvut.cz/grass74/x86_64/addons/grass-7.4.0/
>
> etc
>
> kind regards
> Helmut
>
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-12 Thread Paulo van Breugel

Hi Dinarzarde and Helmut

I checked on Windows (grass 7.4.0 installed using osgeo4w), and 
installing r.vif using g.extension works fine, but after installing it 
does not appear in the addon list in the Modules tab. The same is true 
for a number of other addons I installed. There are, on the other hand, 
a number of addons that appear in the list (r.regression.series, 
r.series.lwr, v.kriging, and 6 others).


However, running these addons from the console (type in r.vif on the 
console) works.



Best wishes

Paulo


On 2/12/18 8:40 PM, Dinarzarde Raheem wrote:

Hi Helmut,

I have been installing r.vif as you have indicated (i.e. by downloading from 
the server using g.extension and opening the tree of installable raster 
addons), but can now confirm after installing both the new and old versions of 
r.vif on a Windows 10 (64 bit) machine, that r.vif isn't listed under the 
Addons in the module tab in both Grass standalone GUI versions 7.2.2 and 7.4.0 
(i.e. there is no plus sign in front of Addons, so there is no way of opening 
the tree of installed addons and selecting and running r.vif).

Best wishes,

Dinarzarde



From: Helmut Kudrnovsky [hel...@web.de]
Sent: 11 February 2018 16:13
To: Dinarzarde Raheem
Cc: grass-user@lists.osgeo.org; Paulo van Breugel
Subject: Aw: RE: [GRASS-user] Issue with addon r.vif in MS Windows GUI 
installations (stand-alone v. 7.2.2 and 7.0.5)


Gesendet: Sonntag, 11. Februar 2018 um 16:36 Uhr
Von: "Dinarzarde Raheem" 
I tried GRASS GIS versions 7.4.0 (current stable) and GRASS GIS 7.2.2 (old stable) 
but can't see r.vif listed under Addons in the Modules tab (see attached 
>screenshot).

you have to click on the + before "Raster" to open the tree of installable 
raster addons.




One thing I noticed is that when you re-install Grass and then install r.vif 
you get this message:
(Sun Feb 11 16:29:48 2018)
g.extension extension=r.vif url=
WARNING: Extension  already installed. Re-installing...
Downloading precompiled GRASS Addons ...
Updating addons metadata file...
Installation of  successfully finished
(Sun Feb 11 16:29:57 2018) Command finished (9 sec)

yes, it's an obvious message as you install the script from the server over the 
local copy.


I guess by tomorrow the new version of r.vif should be available via the server 
so will try again tomorrow.

the new version is already on the server and should be installable by 
g.extension, see

for winGRASS7.5.svn daily:
https://wingrass.fsv.cvut.cz/grass75/x86_64/addons/grass-7.5.svn/

for  winGRASS7.4.0:
https://wingrass.fsv.cvut.cz/grass74/x86_64/addons/grass-7.4.0/

etc

kind regards
Helmut


___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-10 Thread Helmut Kudrnovsky
>I have had a go with a Windows 10 (64 bit) machine with Grass version 7.0.5.

could you update to:

GRASS GIS 7.4.0 (current stable)
or
GRASS GIS 7.2.2 (old stable)

?

Grass version 7.0.5 is now really very old.



-
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-10 Thread Dinarzarde Raheem
Hi Paulo & Helmut,

I have had a go with a Windows 10 (64 bit) machine with Grass version 7.0.5. I 
copied the r.vif patch into the location 
C:\Users\YourUserName\AppData\Roaming\GRASS7\addons\scripts.

I get the following error message (I tried with the existing installation, 
uninstalled this and then tried again after re-installing grass). Would it make 
sense to wait until the server makes the new version of r.vif available through 
the g.extension option and try again? 

Dinarzarde

--error message---

(Sat Feb 10 21:46:00 2018)  
 
r.vif 
maps=2011_01_precip@climate_1970_2012,2011_02_precip@climate_1970_2012,2011_03_precip@climate_1970_2012,2011_04_precip@climate_1970_2012,2011_05_precip@climate_1970_2012,2011_06_precip@climate_1970_2012,2011_07_precip@climate_1970_2012,2011_08_precip@climate_1970_2012,2011_09_precip@climate_1970_2012,2011_10_precip@climate_1970_2012,2011_11_precip@climate_1970_2012,2011_12_precip@climate_1970_2012
 maxvif=10 file=C:\Users\draheem\Desktop\Jan 2017\results1.csv
Reading in the data ...
ERROR: Error reading reclass file for raster map 
<2011_01_precip@climate_1970_2012>
Traceback (most recent call last):
  File "C:\Users\draheem\AppData\Roaming\GRASS7\addons/scrip
ts/r.vif.py", line 361, in 
sys.exit(main(*gs.parser()))
  File "C:\Users\draheem\AppData\Roaming\GRASS7\addons/scrip
ts/r.vif.py", line 222, in main
p = ReadData(IPF, n)
  File "C:\Users\draheem\AppData\Roaming\GRASS7\addons/scrip
ts/r.vif.py", line 150, in ReadData
quiet=True, separator="comma").rstrip('\n'))
  File "C:\Program Files\GRASS GIS
7.0.5\etc\python\grass\script\core.py", line 446, in
read_command
return handle_errors(returncode, stdout, args, kwargs)
  File "C:\Program Files\GRASS GIS
7.0.5\etc\python\grass\script\core.py", line 313, in
handle_errors
returncode=returncode)
grass.exceptions.CalledModuleError: Module run None
['r.stats', '--q', '-1n', 'input=2011_01_precip@climate_1970
_2012,2011_02_precip@climate_1970_2012,2011_03_precip@climat
e_1970_2012,2011_04_precip@climate_1970_2012,2011_05_precip@
climate_1970_2012,2011_06_precip@climate_1970_2012,2011_07_p
recip@climate_1970_2012,2011_08_precip@climate_1970_2012,201
1_09_precip@climate_1970_2012,2011_10_precip@climate_1970_20
12,2011_11_precip@climate_1970_2012,2011_12_precip@climate_1
970_2012', 'separator=comma'] ended with error
Process ended with non-zero return code 1. See errors in the
(error) output.
(Sat Feb 10 21:46:02 2018) Command finished (1 sec) 




From: grass-user [grass-user-boun...@lists.osgeo.org] on behalf of Helmut 
Kudrnovsky [hel...@web.de]
Sent: 10 February 2018 16:27
To: grass-user@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)

>> 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).
>Implemented your patch, thanks.  Dinarzarde, can you test?

tested here in OSGeo4W-winGRASS:

--
r.vif
maps=2011_01_precip,2011_02_precip,2011_03_precip,2011_04_precip,2011_05_precip,2011_06_precip,2011_07_precip,2011_08_precip,2011_09_precip,2011_10_precip,2011_11_precip,2011_12_precip
maxvif=10 file=D:\wd\rvif\test,csv
Reading in the data ...

Statistics are written to D:\wd\rvif\test,csv
VIF round 1
--
variablevif  sqrtvif
2011_01_precip 6.86 2.62
2011_02_precip 2.77 1.66
2011_03_precip33.17 5.76
2011_04_precip10.81 3.29
2011_05_precip 4.82 2.20
2011_06_precip 2.72 1.65
2011_07_precip 1.44 1.20
2011_08_precip10.04 3.17
2011_09_precip 3.16 1.78
2011_10_precip 2.50 1.58
2011_11_precip16.71 4.09
2011_12_precip50.81 7.13
VIF round 2
--
variablevif  sqrtvif
2011_01_precip 6.74 2.60
2011_02_precip 2.54 1.59
2011_03_precip18.23 4.27
2011_04_precip 8.99 3.00
2011_05_precip 4.72 2.17
2011_06_precip 2.69 1.64
2011_07_precip 1.40 1.18
2011_08_precip 9.11 3.02
2011_09_precip 3.08 1.75
2011_10_precip 2.42 1.55
2011_11_precip16.20 4.03
VIF round 3
--
variablevif  sqrtvif
2011_01_precip 5.63 2.37
2011_02_precip 2.14 1.46
2011_04_precip 5.71 2.39
2011_05_precip 4.63 2.15
2011_06_precip 2.52 1.59
2011_07_precip 1.33 1.15
2011_08_precip 9.01 3.00
2011_09_precip 3.08 1.75
2011_10_precip 2.14 1.46
2011_11_precip10.42 3.23
VIF round 4
--
variablevif  sqrtvif
2011_01_precip 5.53 

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

2018-02-10 Thread Helmut Kudrnovsky
>> 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).
>Implemented your patch, thanks.  Dinarzarde, can you test?

tested here in OSGeo4W-winGRASS:

--
r.vif
maps=2011_01_precip,2011_02_precip,2011_03_precip,2011_04_precip,2011_05_precip,2011_06_precip,2011_07_precip,2011_08_precip,2011_09_precip,2011_10_precip,2011_11_precip,2011_12_precip
maxvif=10 file=D:\wd\rvif\test,csv
Reading in the data ...

Statistics are written to D:\wd\rvif\test,csv
VIF round 1
--
variablevif  sqrtvif
2011_01_precip 6.86 2.62
2011_02_precip 2.77 1.66
2011_03_precip33.17 5.76
2011_04_precip10.81 3.29
2011_05_precip 4.82 2.20
2011_06_precip 2.72 1.65
2011_07_precip 1.44 1.20
2011_08_precip10.04 3.17
2011_09_precip 3.16 1.78
2011_10_precip 2.50 1.58
2011_11_precip16.71 4.09
2011_12_precip50.81 7.13
VIF round 2
--
variablevif  sqrtvif
2011_01_precip 6.74 2.60
2011_02_precip 2.54 1.59
2011_03_precip18.23 4.27
2011_04_precip 8.99 3.00
2011_05_precip 4.72 2.17
2011_06_precip 2.69 1.64
2011_07_precip 1.40 1.18
2011_08_precip 9.11 3.02
2011_09_precip 3.08 1.75
2011_10_precip 2.42 1.55
2011_11_precip16.20 4.03
VIF round 3
--
variablevif  sqrtvif
2011_01_precip 5.63 2.37
2011_02_precip 2.14 1.46
2011_04_precip 5.71 2.39
2011_05_precip 4.63 2.15
2011_06_precip 2.52 1.59
2011_07_precip 1.33 1.15
2011_08_precip 9.01 3.00
2011_09_precip 3.08 1.75
2011_10_precip 2.14 1.46
2011_11_precip10.42 3.23
VIF round 4
--
variablevif  sqrtvif
2011_01_precip 5.53 2.35
2011_02_precip 2.13 1.46
2011_04_precip 3.09 1.76
2011_05_precip 4.10 2.03
2011_06_precip 2.52 1.59
2011_07_precip 1.24 1.11
2011_08_precip 4.26 2.06
2011_09_precip 3.01 1.74
2011_10_precip 2.14 1.46
/n
selected variables are: 
--
2011_01_precip, 2011_02_precip, 2011_04_precip, 2011_05_precip,
2011_06_precip, 2011_07_precip, 2011_08_precip, 2011_09_precip,
2011_10_precip
(Sat Feb 10 17:24:14 2018) Command finished (31 sec)
---

to use the new version by g.extension, you have to wait until tomorrow when
the server delivers the precompiled addons for winGRASS.

or just download it manually from

https://trac.osgeo.org/grass/browser/grass-addons/grass7/raster/r.vif

and copy r.vif.py into

C:\Users\YourUserName\AppData\Roaming\GRASS7\addons\scripts



-
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-10 Thread Paulo van Breugel


On 2/3/18 1:33 PM, Stefan Blumentrath wrote:


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).



Implemented your patch, thanks.  Dinarzarde, can you test?


Just a suggestion.

Yet, there might be even more efficient solutions. For example 
raster2numpy from pygrass…


https://grass.osgeo.org/grass74/manuals/libpython/pygrass.raster.html#pygrass.raster.raster2numpy

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


or

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 
 ?


Cheers

Stefan

*From:*grass-user [mailto:grass-user-boun...@lists.osgeo.org] *On 
Behalf Of *Paulo van Breugel

*Sent:* lørdag 3. februar 2018 09.14
*To:* Helmut Kudrnovsky ; grass-user@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 > 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@lists.osgeo.org 
> https://lists.osgeo.org/mailman/listinfo/grass-user

___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-03 Thread Stefan Blumentrath
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...
https://grass.osgeo.org/grass74/manuals/libpython/pygrass.raster.html#pygrass.raster.raster2numpy
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
or
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 ?

Cheers
Stefan


From: grass-user [mailto:grass-user-boun...@lists.osgeo.org] On Behalf Of Paulo 
van Breugel
Sent: lørdag 3. februar 2018 09.14
To: Helmut Kudrnovsky ; grass-user@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 
> 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@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-user


r.vif.diff
Description: r.vif.diff
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-03 Thread Paulo van Breugel



On February 2, 2018 8:52:03 PM Helmut Kudrnovsky  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@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-02 Thread Helmut Kudrnovsky
>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.




-
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-02 Thread Helmut Kudrnovsky
>Any idea how I can do that in such a way that it works on both Linux and
Windows?

or maybe something like:

>>> import os
>>> import tempfile
>>> fd, tmpcov = tempfile.mkstemp()
>>> with open(tmpcov, "w") as text_file:
... text_file.write("jshdfhg")
>>> text_file.close()
>>> os.close(fd)
>>> os.remove(tmpcov)



-
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-02 Thread Helmut Kudrnovsky
>I see you commented out the line that removes the temporary file.

it was just for debugging to find the issue.

>Any idea how I can do that in such a way that it works on both Linux and
Windows?

https://docs.python.org/2/library/tempfile.html

that's maybe an alternative:


tempfile.TemporaryFile([mode='w+b'[, bufsize=-1[, suffix=''[, prefix='tmp'[,
dir=None])

Return a file-like object that can be used as a temporary storage area.
The file is created using mkstemp(). It will be destroyed as soon as it is
closed (including an implicit close when the object is garbage collected).
Under Unix, the directory entry for the file is removed immediately after
the file is created. Other platforms do not support this; your code should
not rely on a temporary file created using this function having or not
having a visible name in the file system.

The mode parameter defaults to 'w+b' so that the file created can be
read and written without being closed. Binary mode is used so that it
behaves consistently on all platforms without regard for the data that is
stored. bufsize defaults to -1, meaning that the operating system default is
used.

The dir, prefix and suffix parameters are passed to mkstemp().

The returned object is a true file object on POSIX platforms. On other
platforms, it is a file-like object whose file attribute is the underlying
true file object. This file-like object can be used in a with statement,
just like a normal file.






-
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-02 Thread Paulo van Breugel
On Thu, Feb 1, 2018 at 12:04 PM, Helmut Kudrnovsky  wrote:

> Dinarzarde Raheem wrote
> > I have been trying to run the addon r.vif using Grass for MS Windows
> > standalone v. 7.2.2 and v. 7.0.5 on three separate PCs (two have Windows
> 7
> > 32bit/64 bit, one runs Windows 10 Home 64 bit). I have been testing the
> > r.vif installation using the example on the r.vif page of the Grass 7
> > addons manual (i.e. this uses  the GRASS 7 Climatic data time series NC
> > location nc_climate_spm_2000_2012).
> >
> > With v. 7.2.2 (in both Windows 7 and 10) I can load the extension, and
> can
> > visualise Addons in the search modules tab, but the r.vif. tool is not
> > visible under Addons.
> >
> > With v. 7.0.5  (in both Windows 7 and 10), I can load r. vif, visualise
> it
> > under Addons in  the Search Modules tab and run it, but I get the
> > following error message:
> >
> >
> > (Wed Jan 31 15:06:21 2018)
> >
> > r.vif
> > maps=2011_01_precip@climate_1970_2012,2011_02_precip@climate
> _1970_2012,2011_03_precip@climate_1970_2012,2011_04_
> precip@climate_1970_2012,2011_05_precip@climate_1970_2012,
> 2011_06_precip@climate_1970_2012,2011_07_precip@climate_
> 1970_2012,2011_08_precip@climate_1970_2012,2011_09_
> precip@climate_1970_2012,2011_10_precip@climate_1970_2012,
> 2011_11_precip@climate_1970_2012,2011_12_precip@climate_1970_2012
> > maxvif=10 file=C:\grassworkspace\2011test
> >
> > Reading in the data ...
> >
> > Traceback (most recent call last):
> >
> >   File "C:\Users\dinr\AppData\Roaming\GRASS7\addons/scripts/
> >
> > r.vif.py", line 365, in
> > 
> > sys.exit(main(*gs.parser()))
> >
> >   File "C:\Users\dinr\AppData\Roaming\GRASS7\addons/scripts/
> >
> > r.vif.py", line 226, in main
> >
> > p = ReadData(IPF, n)
> >
> >   File "C:\Users\dinr\AppData\Roaming\GRASS7\addons/scripts/
> >
> > r.vif.py", line 156, in ReadData
> >
> > os.remove(tmpcov)
> >
> > WindowsError: [Error 32] The process cannot access the file
> >
> > because it is being used by another process:
> >
> > 'c:\\users\\dinr\\appdata\\local\\temp\\tmpsggohd'
> >
> > (Wed Jan 31 15:06:25 2018) Command finished (4 sec)
> >
> > Is there anything I can do to fix this issue?
>
> the reason for the error are these lines of code in the r.vif script:
>
> <-
> [...]
> 155# Clean up
> 156os.remove(tmpcov)
> -->
>
> the temporary file tmpcov isn't closed, therefore the temporary file can't
> be deleted.
>
> just for testing I changed locally here in the script
>
> <-
> [...]
> 155# Clean up
> 156# os.remove(tmpcov)
> -->
>
> now the script finishes with results.
>
> the reason is that handling of temporary files in python is different in
> linux and windows.
>
> ping the script author (mentioned in [1]) and ask him to adapt the script
> that it's also working in windows.
>
>
>
> [1] https://grass.osgeo.org/grass74/manuals/addons/r.vif.html
>
>
>
> Hi Dinarzard, I will have a look at it. Helmut, I see you commented out
the line that removes the temporary file. Any idea how I can do that in
such a way that it works on both Linux and Windows?


>
> -
> best regards
> Helmut
> --
> Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html
> ___
> grass-user mailing list
> grass-user@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-user
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

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

2018-02-01 Thread Helmut Kudrnovsky
Dinarzarde Raheem wrote
> I have been trying to run the addon r.vif using Grass for MS Windows
> standalone v. 7.2.2 and v. 7.0.5 on three separate PCs (two have Windows 7
> 32bit/64 bit, one runs Windows 10 Home 64 bit). I have been testing the
> r.vif installation using the example on the r.vif page of the Grass 7
> addons manual (i.e. this uses  the GRASS 7 Climatic data time series NC
> location nc_climate_spm_2000_2012).
> 
> With v. 7.2.2 (in both Windows 7 and 10) I can load the extension, and can
> visualise Addons in the search modules tab, but the r.vif. tool is not
> visible under Addons.
> 
> With v. 7.0.5  (in both Windows 7 and 10), I can load r. vif, visualise it
> under Addons in  the Search Modules tab and run it, but I get the
> following error message:
> 
> 
> (Wed Jan 31 15:06:21 2018)
> 
> r.vif
> maps=2011_01_precip@climate_1970_2012,2011_02_precip@climate_1970_2012,2011_03_precip@climate_1970_2012,2011_04_precip@climate_1970_2012,2011_05_precip@climate_1970_2012,2011_06_precip@climate_1970_2012,2011_07_precip@climate_1970_2012,2011_08_precip@climate_1970_2012,2011_09_precip@climate_1970_2012,2011_10_precip@climate_1970_2012,2011_11_precip@climate_1970_2012,2011_12_precip@climate_1970_2012
> maxvif=10 file=C:\grassworkspace\2011test
> 
> Reading in the data ...
> 
> Traceback (most recent call last):
> 
>   File "C:\Users\dinr\AppData\Roaming\GRASS7\addons/scripts/
> 
> r.vif.py", line 365, in 
> 
> sys.exit(main(*gs.parser()))
> 
>   File "C:\Users\dinr\AppData\Roaming\GRASS7\addons/scripts/
> 
> r.vif.py", line 226, in main
> 
> p = ReadData(IPF, n)
> 
>   File "C:\Users\dinr\AppData\Roaming\GRASS7\addons/scripts/
> 
> r.vif.py", line 156, in ReadData
> 
> os.remove(tmpcov)
> 
> WindowsError: [Error 32] The process cannot access the file
> 
> because it is being used by another process:
> 
> 'c:\\users\\dinr\\appdata\\local\\temp\\tmpsggohd'
> 
> (Wed Jan 31 15:06:25 2018) Command finished (4 sec)
> 
> Is there anything I can do to fix this issue?

the reason for the error are these lines of code in the r.vif script:

<-
[...]
155# Clean up
156os.remove(tmpcov)
-->

the temporary file tmpcov isn't closed, therefore the temporary file can't
be deleted.

just for testing I changed locally here in the script

<-
[...]
155# Clean up
156# os.remove(tmpcov)
-->

now the script finishes with results.

the reason is that handling of temporary files in python is different in
linux and windows.

ping the script author (mentioned in [1]) and ask him to adapt the script
that it's also working in windows.



[1] https://grass.osgeo.org/grass74/manuals/addons/r.vif.html




-
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user