Re: [GRASS-dev] Use 'from=' parameter in python script

2018-03-22 Thread Vaclav Petras
On Thu, Mar 22, 2018 at 5:36 AM, Nikos Alexandris 
wrote:

>
> rescale_output = g.read_command('r.rescale', overwrite=True, verbose=True,
>input=band, output=output_map_name, to=to_range)
> print rescale_output
>
> cls.runModule('r.rescale', overwrite=True, verbose=True,
>input=band, output=output_map_name, to=to_range)
> ```
>
> the former will print the output of `r.rescale`, the latter will not.
>
>
> Is there a way to get the output of `runModule`, while building a test
> suite?
>

It's a PyGRASS module, so just access `module.outputs.stdout` afterwards.
Please extend the documentation if needed.

Is the purpose of `expecting_stdout=False` in `runModule()` to test if a
> module emits something to stdout? [0]
>

Yes. It's for cases like when r.univar prints nothing when raster map
contains NULLs only (or region is outside its extent).

HTH,
Vaclav
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev

Re: [GRASS-dev] Use 'from=' parameter in python script

2018-03-22 Thread Nikos Alexandris

[all deleted]

In the same script,

```
import grass.script as g
from grass.gunittest.case import TestCase
```

and

```
rescale_output = g.read_command('r.rescale', overwrite=True, verbose=True,
   input=band, output=output_map_name, to=to_range)
print rescale_output

cls.runModule('r.rescale', overwrite=True, verbose=True,
   input=band, output=output_map_name, to=to_range)
```

the former will print the output of `r.rescale`, the latter will not.


Is there a way to get the output of `runModule`, while building a test suite?
And avoid using a `grass.script` function?

Is the purpose of `expecting_stdout=False` in `runModule()` to test if a
module emits something to stdout? [0]

Thanks, Nikos

[0] 
https://grass.osgeo.org/grass74/manuals/libpython/_modules/gunittest/case.html#TestCase.runModule.


signature.asc
Description: PGP signature
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev

Re: [GRASS-dev] Use 'from=' parameter in python script

2018-03-22 Thread Markus Neteler
On Thu, Mar 22, 2018 at 8:21 AM, Nikos Alexandris
 wrote:
...
> If I didn't miss anything, `grep` finds only 1 use of `r.rescale` within

FYI - you can find that best with "ag - the silver searcher" since you
can restrict the search to a programming language, here --python:

> a script. It is the addon `grass7/raster/r.mblend/r.mblend.py`, in line
> 270.

# core
ag --python r.rescale
gui/wxpython/iscatt/controllers.py
323:"(e. g. using r.rescale) below recommended
threshold.\n\n"

# software/grass-addons/grass7/
ag --python r.rescale
raster/r.mblend/r.mblend.py
207:gscript.run_command('r.rescale', input=dist_high, output=weights,

So: confirmed.

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

Re: [GRASS-dev] Use 'from=' parameter in python script

2018-03-22 Thread Nikos Alexandris

Nikos Alexandris wrote:


>
> how can I use the 'from' parameter in a python script? The following
> ```
> from_range=0,255
> to_range=0,511
> cls.runModule('r.rescale', input=band, output=output_map_name,
>from=from_range, to=to_range, overwrite=True)
> ```
>
> causes expectedly
> ```
> SyntaxError: invalid syntax
> ```



Vaclav Petras a écrit :


Try `from_`. I'm not sure at this point if it works in a gunittest (which
you seem to be using).

Vaclav


Nikos:


I already tried that and it does not work. Yes, trying to build tests for the 
"new" i.rgb.his.

Thank you, Nikos


Note to self: `r.rescale` works fine without the `from` parameter. The actual
minimum and the maximum values, of the `input` map are always used.

Thinking about: what would be a use case where the `from` values would need
to be user defined, which implies they would need to differ from the
map's actual minimum and maximum?

If I didn't miss anything, `grep` finds only 1 use of `r.rescale` within
a script. It is the addon `grass7/raster/r.mblend/r.mblend.py`, in line
270.

Nikos



signature.asc
Description: PGP signature
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev

Re: [GRASS-dev] Use 'from=' parameter in python script

2018-03-22 Thread Nikos Alexandris


Le Jeudi 22 mars 2018, Vaclav Petras a écrit :
> On Wed, Mar 21, 2018 at 7:57 PM, Nikos Alexandris 
> wrote:
> >
> > how can I use the 'from' parameter in a python script? The following
> > ```
> > from_range=0,255
> > to_range=0,511
> > cls.runModule('r.rescale', input=band, output=output_map_name,
> >from=from_range, to=to_range, overwrite=True)
> > ```
> >
> > causes expectedly
> > ```
> > SyntaxError: invalid syntax
> > ```
> 
> 
> Try `from_`. I'm not sure at this point if it works in a gunittest (which
> you seem to be using).
> 
> Vaclav

I already tried that and it does not work. Yes, trying to build tests for the 
"new" i.rgb.his.

 Thank you, Nikos

-- 
Envoyé depuis mon Jolla
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev

Re: [GRASS-dev] Use 'from=' parameter in python script

2018-03-21 Thread Vaclav Petras
On Wed, Mar 21, 2018 at 7:57 PM, Nikos Alexandris 
wrote:
>
> how can I use the 'from' parameter in a python script? The following
> ```
> from_range=0,255
> to_range=0,511
> cls.runModule('r.rescale', input=band, output=output_map_name,
>from=from_range, to=to_range, overwrite=True)
> ```
>
> causes expectedly
> ```
> SyntaxError: invalid syntax
> ```


Try `from_`. I'm not sure at this point if it works in a gunittest (which
you seem to be using).

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

[GRASS-dev] Use 'from=' parameter in python script

2018-03-21 Thread Nikos Alexandris

Dear all,

how can I use the 'from' parameter in a python script? The following
```
from_range=0,255
to_range=0,511
cls.runModule('r.rescale', input=band, output=output_map_name,
   from=from_range, to=to_range, overwrite=True)
```

causes expectedly
```
SyntaxError: invalid syntax
```

Nikos


signature.asc
Description: PGP signature
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev