Skip to content

Commit

Permalink
r.watershed: fix streams and basins (#3140)
Browse files Browse the repository at this point in the history
* r.watershed: fix streams and basins, improve testsuite
  • Loading branch information
metzm committed Sep 11, 2023
1 parent 390f983 commit 05b017b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
6 changes: 4 additions & 2 deletions raster/r.watershed/ram/do_cum.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,12 @@ int do_cum_mfd(void)
aspect = -aspect;
asp[this_index] = aspect;
}
/*
if (mfd_cells == 1)
/* mfdir = (1 << nextmfd[max_side]); */
mfdir = (1 << nextmfd[max_side]);
*/

is_swale = FLAG_GET(swale, r, c);
is_swale = FLAG_GET(swale, r, c);
/* start new stream */
value = ABS(value) + 0.5;
if (!is_swale && (int)value >= threshold && stream_cells < 1 &&
Expand Down
6 changes: 4 additions & 2 deletions raster/r.watershed/seg/do_cum.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,12 @@ int do_cum_mfd(void)
else
af.asp = drain[r - r_max + 1][c - c_max + 1];
}
/*
if (mfd_cells == 1)
/* mfdir = (1 << nextmfd[max_side]); */
mfdir = (1 << nextmfd[max_side]);
*/

is_swale = FLAG_GET(af.flag, SWALEFLAG);
is_swale = FLAG_GET(af.flag, SWALEFLAG);
/* start new stream */
if (!is_swale && fabs(value) >= threshold && stream_cells < 1 &&
swale_cells < 1 && !flat) {
Expand Down
22 changes: 16 additions & 6 deletions raster/r.watershed/testsuite/r_watershed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ def test_thresholdsize(self):
)
# it is expected that 100k Threshold has a min=2 and max=12 for this
# data
self.assertRasterMinMax(self.basin, 2, 12)
reference = "min=2\nmax=12"
self.assertRasterFitsUnivar(
self.basin,
reference=reference,
msg="Basin values must be in the range [2, 12]",
)
# it is expected that 100k Threshold has a min=2 and max=256 for this
# data
self.assertModule(
Expand All @@ -173,7 +178,12 @@ def test_thresholdsize(self):
basin=self.basin,
overwrite=True,
)
self.assertRasterMinMax(self.basin, 2, 256)
reference = "min=2\nmax=256"
self.assertRasterFitsUnivar(
self.basin,
reference=reference,
msg="Basin values must be in the range [2, 256]",
)

def test_drainageDirection(self):
"""Test if the drainage direction is between -8 and 8."""
Expand All @@ -198,11 +208,11 @@ def test_basinValue(self):
# TODO: test just min, max is theoretically unlimited
# or set a lower value according to what is expected with this data
# TODO: add test which tests that 'max basin id' == 'num of basins'
self.assertRasterMinMax(
reference = "min=2\nmax=256"
self.assertRasterFitsUnivar(
self.basin,
0,
1000000,
msg="A basin value is less than 0 or greater than 1000000",
reference=reference,
msg="Basin values must be in the range [2, 256]",
)


Expand Down

0 comments on commit 05b017b

Please sign in to comment.