Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r.univar: init max value with smallest possible value (G8.3) #3531

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion raster/r.univar/r.univar_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ static void process_raster(univar_stat *stats, int *fd, int *fdz,
double *max = G_malloc(n_alloc * sizeof(double));

for (i = 0; i < n_alloc; i++) {
max[i] = DBL_MIN;
max[i] = -DBL_MAX;
min[i] = DBL_MAX;
}

Expand Down
44 changes: 44 additions & 0 deletions raster/r.univar/testsuite/test_r_univar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def tearDownClass(cls):
def tearDown(self):
self.runModule("g.remove", flags="f", type="raster", name="map_a")
self.runModule("g.remove", flags="f", type="raster", name="map_b")
self.runModule("g.remove", flags="f", type="raster", name="map_negative")
self.runModule("g.remove", flags="f", type="raster", name="zone_map")
self.runModule("g.remove", flags="f", type="raster", name="zone_map_with_gap")

Expand All @@ -39,6 +40,11 @@ def setUp(self):
expression="zone_map_with_gap = if(row()> 20, 2, 9)",
overwrite=True,
)
self.runModule(
"r.mapcalc",
expression="map_negative = -double(10) - row() - col()",
overwrite=True,
)

def test_1(self):
# Output of r.univar
Expand Down Expand Up @@ -223,6 +229,44 @@ def test_multiple_3(self):
sep="=",
)

def test_negative(self):
"""
check map with only negative values
:return:
"""

univar_string = """n=8100
null_cells=0
cells=8100
min=-190
max=-12
range=178
mean=-101
mean_of_abs=101
stddev=36.7400780256838
variance=1349.83333333333
coeff_var=-36.3763148769146
sum=-818100"""

self.runModule("g.region", res=10)
self.assertModuleKeyValue(
module="r.univar",
map="map_negative",
flags="rg",
reference=univar_string,
precision=6,
sep="=",
)
self.assertModuleKeyValue(
module="r.univar",
map="map_negative",
flags="rg",
nprocs=4,
reference=univar_string,
precision=6,
sep="=",
)

def test_1_zone(self):
"""
one map and zone
Expand Down
Loading