Skip to content

[Bug] r.univar returns nan for rasters with only negative values #3497

@wenzeslaus

Description

@wenzeslaus

Describe the bug

For rasters with only negative values, r.univar returns nan for maximum and range.

For positive values and a mix of positive and negative values, the module returns expected max and range values.

To Reproduce

grass -c ~/grassdata/nc_spm_08_grass7/test1
GRASS nc_spm_08_grass7/user1:grass > r.mapcalc "negative_const = -1"
 100%
GRASS nc_spm_08_grass7/user1:grass > r.mapcalc "negative_random = rand(-1, -0.01)" -s
 100%
GRASS nc_spm_08_grass7/user1:grass > r.univar negative_const
 100%
 100%
total null and non-null cells: 277200
total null cells: 0

Of the non-null cells:
----------------------
n: 277200
minimum: -1
maximum: nan
range: nan
mean: -1
mean of absolute values: 1
standard deviation: 0
variance: 0
variation coefficient: -0 %
sum: -277200
GRASS nc_spm_08_grass7/user1:grass > r.univar negative_random
 100%
 100%
total null and non-null cells: 277200
total null cells: 0

Of the non-null cells:
----------------------
n: 277200
minimum: -0.999997
maximum: nan
range: nan
mean: -0.505264
mean of absolute values: 0.505264
standard deviation: 0.285897
variance: 0.0817371
variation coefficient: -56.5837 %
sum: -140059.082419107

Same with the g flag.

Expected behavior

Maximum and range computed.

System description

  • Operating System: Linux
  • GRASS GIS version: main branch

I didn't do a full git bisect, but 8.2.0 is good and 8.3.0 is bad.

Metadata

Metadata

Assignees

Labels

CRelated code is in CbugSomething isn't workingrasterRelated to raster data processing

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions