On 14-04-16 16:20, Vaclav Petras wrote:

On Thu, Apr 14, 2016 at 9:55 AM, Paulo van Breugel <p.vanbreu...@gmail.com <mailto:p.vanbreu...@gmail.com>> wrote:

    I would have to go through the individual examples but sometimes
    it might be be clear what is a message to inform user about
    something and what is a text output of the module. A rule of
    thumb can be that modules which output maps, (usually) don't do
    text output, so they shouldn't use print().

    In this case (r.vif) the output is not a map, but a list of
    values, i.e., text output (see below). Based on the guidelines, I
    would assume I should use print()?


Then print() is the right thing. I would recommend finding a similar module and see its behavior. For example, r.univar will give you human readable report and also parseable output (in this case by grass.script.parse_command()). Both are written to standard output (the g.message wrappers use standard error output).

OK, will do that


    All variables

    ----------------------------------------

    variable                           vif      sqrtvif

    2000_01_precip@climate_1970_2012       2.30     1.52

    2000_03_tempmean@climate_1970_2012    24.95     5.00

    2000_11_precip@climate_1970_2012       3.54     1.88

    2001_02_precip@climate_1970_2012       4.55     2.13

    2001_04_tempmean@climate_1970_2012    25.01     5.00

    Variable '2001_04_tempmean@climate_1970_2012' removed

    ----------------------------------------

    variable                           vif      sqrtvif

    2000_01_precip@climate_1970_2012       2.30     1.52

    2000_03_tempmean@climate_1970_2012     2.19     1.48

    2000_11_precip@climate_1970_2012       3.48     1.87

    2001_02_precip@climate_1970_2012       4.54     2.13

    Final selected variables are: 2000_01_precip, 2000_03_tempmean, 
2000_11_precip, 2001_02_precip

    with as maximum VIF: 5.69787583189



This definitively looks like something from r.report or r.info <http://r.info>.

        Perhaps the most important thing is that one should avoid
        mixing the two, which is something that maybe could go
        somewhere in the wiki?


    Feel free to extent either wiki or guidelines if you think it is
    not clear enough.

    I wouldn't mind doing so, but I probably should understand better
    myself what exactly the issue is with using both print() and
    grass.info <http://grass.info>() in one script. Based on what I
    read in the guidelines, I am not clear whether using both is
    against the guidelines as such,


You can use both in one script. The difference is what you use them for. For example, a lot of modules will tell which map was created (this is done through g.message or its C equivalents), while g.region -p will use standard output. Some cases are unclear, for example v.in.lidar uses standard output (fprintf(stdout,...)) to tell how many points imported. G_message() might be more appropriate here because it is an message to the user while the output is the vector map. If G_message() would be used, this output could be silenced by --quiet.

    but technically it seems it can cause problems as you explained
    (and I experienced).


They are mostly related to syncing of stdout and strerr streams which is more challenging for the GUI (and may need some fixing there).

_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to