[GRASS-dev] [GRASS GIS] #2269: r.univar silent instead of NaN

#2269: r.univar silent instead of NaN
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.4
Component: Raster | Version: svn-releasebranch64
Keywords: r.univar | Platform: Unspecified
      Cpu: Unspecified |
-------------------------+--------------------------------------------------
r.univar should not remain silent when the computational
region is only containing NULL cells. Instead "NaN" should be
printed as result for the individual min, max, etc values.

{{{
GRASS 6.4.4svn (nc_spm_08):~ > g.region n=1 s=0 w=0 e=1 res=0.5 -p
projection: 99 (Lambert Conformal Conic)
zone: 0
datum: nad83
ellipsoid: a=6378137 es=0.006694380022900787
north: 1
south: 0
west: 0
east: 1
nsres: 0.5
ewres: 0.5
rows: 2
cols: 2
cells: 4
GRASS 6.4.4svn (nc_spm_08):~ > r.univar elevation
  100%
GRASS 6.4.4svn (nc_spm_08):~ > r.univar elevation -g
GRASS 6.4.4svn (nc_spm_08):~ >
}}}

The issue is in r.univar, stats.c line 123. However, not
that easy to fix since sometimes zones are considered,
sometimes not.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2269&gt;
GRASS GIS <http://grass.osgeo.org>

#2269: r.univar silent instead of NaN
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.4
Component: Raster | Version: svn-releasebranch64
Keywords: r.univar | Platform: Unspecified
      Cpu: Unspecified |
-------------------------+--------------------------------------------------

Comment(by hamish):

hmm, I thought there was already a ticket for this. guess not.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2269#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#2269: r.univar silent instead of NaN
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.4
Component: Raster | Version: svn-releasebranch64
Keywords: r.univar | Platform: Unspecified
      Cpu: Unspecified |
-------------------------+--------------------------------------------------

Comment(by wenzeslaus):

Do we have a standard how to represent NaN (''not a number'') in GRASS (as
a text)?

For example in Python:
{{{
#!python
>>> a = float('nan')
>>> a
nan
>>> a = float('NaN')
>>> a
nan
>>> a = float('NAN')
>>> a
nan
>>> a = float('nAn')
>>> a
nan
}}}

(And the same for `inf`.)

Is it even appropriate that `r.univar` would give NaNs? Wouldn't be non-
zero return code and a error message more appropriate? (Perhaps not, but
we should consider the options.)

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2269#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#2269: r.univar silent instead of NaN
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.4
Component: Raster | Version: svn-releasebranch64
Keywords: r.univar | Platform: Unspecified
      Cpu: Unspecified |
-------------------------+--------------------------------------------------

Comment(by wenzeslaus):

The same applies for `r3.univar`.

It is especially bad for `-g` flag where module is used as a part of
something bigger and the caller expects valid output when module ended
with non-zero return code. Now it can end in the best case report and
empty output when expecting something but no better error message can be
provided.

See also testing framework
([https://trac.osgeo.org/grass/browser/grass/trunk/lib/python/gunittest/case.py?rev=61459#L154
gunittest]) where `r.univar` and `r3.univar` are used to check map
properties and thus some informative error messages needs to be provided
when something is wrong. See particularly r61459.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2269#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>