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.watershed: fix streams and basins #3140

Merged
merged 2 commits into from
Sep 11, 2023
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
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
Loading