[GRASS-user] negative accumulation with r.watershed in GRASS 7

Dear Grass users and developers,

The run-time messages of command r.watershed is pasted below.
This I ran as per suggestions on a threshold area of 100 sq km. Considerable number of basins are in the limit 1 to 100 sq km. The results represent are close to natural distribution of watersheds. However, from the results, it appears to me that the threshold limit should be considered only as a guideline and not to find basins of size larger than the threshold limit.
(Thu Nov 24 17:07:28 2011)
r.watershed elevation=ybdem@work threshold=12345 accumulation=ybdem100sqkm_acc drainage=ybdem100sqkm_fdir basin=ybdem100sqkm_basin stream=ybdem100sqkm_stream
SECTION 1a (of 5): Initiating Memory.
SECTION 1b (of 5): Determining Offmap Flow.
SECTION 2: A* Search.
SECTION 3: Accumulating Surface Flow with MFD.
SECTION 4: Watershed determination.
SECTION 5: Closing Maps.
(Thu Nov 24 17:09:38 2011) Command finished (130 sec)


In this part, I tried to ran r.watershed with SFD flag.

(Thu Nov 24 17:21:40 2011)
r.watershed -s elevation=ybdem@work threshold=12345 accumulation=ybdem100sqkm_acc_sfd drainage=ybdem100sqkm_fdir_sfd basin=ybdem100sqkm_basin_sfd stream=ybdem100sqkm_stream_sfd
SECTION 1a (of 5): Initiating Memory.
SECTION 1b (of 5): Determining Offmap Flow.
SECTION 2: A* Search.
SECTION 3: Accumulating Surface Flow with SFD.
SECTION 4: Watershed determination.
Subprocess failed with exit code 9
category information for [ybdem100sqkm_acc_sfd] in [work] missing or invalid
category information for [ybdem100sqkm_fdir_sfd] in [work] missing or invalid
category information for [ybdem100sqkm_basin_sfd] in [work] missing or invalid
category information for [ybdem100sqkm_stream_sfd] in [work] missing or invalid
(Fri Nov 25 09:46:01 2011) Command finished (59061 sec)

One can see that I had manually terminated the command from “system monitor”. It didn’t complete.
I tried again.

(Fri Nov 25 09:46:35 2011)
r.watershed -s --overwrite elevation=ybdem@work threshold=12345 accumulation=ybdem100sqkm_acc_sfd drainage=ybdem100sqkm_fdir_sfd basin=ybdem100sqkm_basin_sfd stream=ybdem100sqkm_stream_sfd
SECTION 1a (of 5): Initiating Memory.
SECTION 1b (of 5): Determining Offmap Flow.
SECTION 2: A* Search.
SECTION 3: Accumulating Surface Flow with SFD.
SECTION 4: Watershed determination.
Please note that the data are left in inconsistent state and may be corrupted
(Fri Nov 25 10:23:45 2011) Command aborted (2230 sec)

It wasn’t working. I found in “system monitor” that the program r.watershed.ram is using only 2gb ram.
The issue may be of interest to GRASS developers.
So, I tried again with “memory” mode and it worked.

(Fri Nov 25 10:24:33 2011)
r.watershed -s -m --overwrite elevation=ybdem@work threshold=12345 accumulation=ybdem100sqkm_acc_sfd drainage=ybdem100sqkm_fdir_sfd basin=ybdem100sqkm_basin_sfd stream=ybdem100sqkm_stream_sfd memory=12000
SECTION 1 beginning: Initiating Variables. 5 sections total.
SECTION 1a: Mark masked and NULL cells
SECTION 1b: Determining Offmap Flow.
SECTION 2: A* Search.
SECTION 3: Accumulating Surface Flow with SFD.
SECTION 4: Watershed determination.
SECTION 5: Closing Maps.
Closing stream segments map
Closing basins map
Closing accumulation map
Closing flow direction map
(Fri Nov 25 10:28:46 2011) Command finished (252 sec)

It was suggested that from the accumulation values equal to the number of cells of area required (i.e. 12345 for 100 sq km), one can find tentative points having watershed equal to the area desired.
In the accumulation values , I found that there is no value near 12345. And there are lot of negative values.

The results of r.report are pasted below:

±----------------------------------------------------------------------------+
| RASTER MAP CATEGORY REPORT |

LOCATION: only_yamuna Fri Nov 25 11:00:55 2011
north: 32:00:02.953919N east: 82:00:02.881919E
REGION south: 21:59:59.96832N west: 72:59:59.89488E
res: 0:00:02.999999 res: 0:00:02.999999
-----------------------------------------------------------------------------
MASK:none
-----------------------------------------------------------------------------
MAP: Watershed accumulation: overland flow that traverses each cell (ybdem100
-----------------------------------------------------------------------------
Category Information
#
-----------------------------------------------------------------------------
-43691083–43505559.796078
-43505559.796078–43320036.592157
-43320036.592157–43134513.388235
-43134513.388235–42948990.184314
-42948990.184314–42763466.980392
-42577943.776471–42392420.572549
-42392420.572549–42206897.368627
-42206897.368627–42021374.164706
-38496433.290196–38310910.086275
-38310910.086275–38125386.882353
-38125386.882353–37939863.678431
-32374167.560784–32188644.356863
-31632074.745098–31446551.541176
-31261028.337255–31075505.133333
-27550564.258824–27365041.054902
-18274404.062745–18088880.858824
-18088880.858824–17903357.654902
-17903357.654902–17717834.45098
-17346788.043137–17161264.839216
-17161264.839216–16975741.635294
-16975741.635294–16790218.431373
-9925859.886275–9740336.682353
-9369290.27451–9183767.070588
-9183767.070588–8998243.866667
-7885104.643137–7699581.439216
-7699581.439216–7514058.235294
-6957488.623529–6771965.419608
-6029872.603922–5844349.4
-5844349.4–5658826.196078
-5658826.196078–5473302.992157
-5473302.992157–5287779.788235
-5287779.788235–5102256.584314
-5102256.584314–4916733.380392
-4916733.380392–4731210.176471
-4731210.176471–4545686.972549
-4545686.972549–4360163.768627
-4360163.768627–4174640.564706
-3803594.156863–3618070.952941
-3618070.952941–3432547.74902
-3432547.74902–3247024.545098
-3247024.545098–3061501.341176
-3061501.341176–2875978.137255
-2875978.137255–2690454.933333
-2690454.933333–2504931.729412
-2504931.729412–2319408.52549
-2319408.52549–2133885.321569
-2133885.321569–1948362.117647
-1948362.117647–1762838.913725
-1762838.913725–1577315.709804
-1577315.709804–1391792.505882
-1391792.505882–1206269.301961
-1206269.301961–1020746.098039
-1020746.098039–835222.894118
-835222.894118–649699.690196
-649699.690196–464176.486275
-464176.486275–278653.282353
-278653.282353–93130.078431
-93130.078431-92393.12549
92393.12549-277916.329412
277916.329412-463439.533333
463439.533333-648962.737255
648962.737255-834485.941176
834485.941176-1020009.145098
1020009.145098-1205532.34902
1205532.34902-1391055.552941
1391055.552941-1576578.756863
1576578.756863-1762101.960784
1947625.164706-2133148.368627
2133148.368627-2318671.572549
2689717.980392-2875241.184314
3246287.592157-3431810.796078
3431810.796078-3617334
*
±----------------------------------------------------------------------------+

I have changed the colour of negative values to red and positive values to green.

I have read that negative values mean that area getting flow outside the current region.
That’s simply not possible in my case. I have created this basin from r.water.outlet. I used that as mask to cut the DEM of only that area.

Can anyone please shed some more light on it. Or share their experiences with us in this regard.
Basically, I have two queries now. 1. How to get positive accumulation values. 2. How to find the accumulation value representing 100 sq km basin area.

My idea to find 100 sq km basin area by walking along the rivers till we reach the desired point is still under development.

Pankaj Kr Sharma wrote:

Dear Grass users and developers,

The run-time messages of command r.watershed is pasted below.
This I ran as per suggestions on a threshold area of 100 sq km. Considerable

Be aware that the threshold option of r.watershed does not refer to
catchment area (basin) size but to stream initiation. That means that
a stream is started if the surface flow accumulation reaches the
threshold value. All all upstream cells have consequently a flow
accumulation value lower than the threshold value. That means also
that exterior basins are larger than <threshold value> because
catchments (basins) are calculated from the last confluence upstream
which has necessarily a flow accumulation value larger than
<threshold>. That also means that the attempt to identify basins of a
fixed size does not make sense from a hydrological perspective because
basins are more realistically defined upstream of a point of
confluence (which in turn is dependent of the threshold value), i.e.
the catchment areas of the tributaries joining at a given point of
confluence. This in turn means that interior basins can have a size
from 1 to <threshold>

number of basins are in the limit 1 to 100 sq km. The results represent are
close to natural distribution of watersheds. However, from the results, it
appears to me that the threshold limit should be considered only as a
guideline and not to find basins of size larger than the threshold limit.
(Thu Nov 24 17:07:28
2011)
r.watershed elevation=ybdem@work threshold=12345
accumulation=ybdem100sqkm_acc drainage=ybdem100sqkm_fdir
basin=ybdem100sqkm_basin stream=ybdem100sqkm_stream
SECTION 1a (of 5): Initiating Memory.
SECTION 1b (of 5): Determining Offmap Flow.
SECTION 2: A* Search.
SECTION 3: Accumulating Surface Flow with MFD.
SECTION 4: Watershed determination.
SECTION 5: Closing Maps.
(Thu Nov 24 17:09:38 2011) Command finished (130 sec)

-----------------------------------------------------------------------------------------------------------------------------

In this part, I tried to ran r.watershed with SFD flag.

(Thu Nov 24 17:21:40
2011)
r.watershed -s elevation=ybdem@work threshold=12345
accumulation=ybdem100sqkm_acc_sfd drainage=ybdem100sqkm_fdir_sfd
basin=ybdem100sqkm_basin_sfd stream=ybdem100sqkm_stream_sfd
SECTION 1a (of 5): Initiating Memory.
SECTION 1b (of 5): Determining Offmap Flow.
SECTION 2: A* Search.
SECTION 3: Accumulating Surface Flow with SFD.
SECTION 4: Watershed determination.
Subprocess failed with exit code 9
category information for [ybdem100sqkm_acc_sfd] in [work] missing or invalid
category information for [ybdem100sqkm_fdir_sfd] in [work] missing or
invalid
category information for [ybdem100sqkm_basin_sfd] in [work] missing or
invalid
category information for [ybdem100sqkm_stream_sfd] in [work] missing or
invalid
(Fri Nov 25 09:46:01 2011) Command finished (59061 sec)

One can see that I had manually terminated the command from "system
monitor". It didn't complete.
I tried again.

(Fri Nov 25 09:46:35
2011)
r.watershed -s --overwrite elevation=ybdem@work threshold=12345
accumulation=ybdem100sqkm_acc_sfd drainage=ybdem100sqkm_fdir_sfd
basin=ybdem100sqkm_basin_sfd stream=ybdem100sqkm_stream_sfd
SECTION 1a (of 5): Initiating Memory.
SECTION 1b (of 5): Determining Offmap Flow.
SECTION 2: A* Search.
SECTION 3: Accumulating Surface Flow with SFD.
SECTION 4: Watershed determination.
Please note that the data are left in inconsistent state and may be
corrupted
(Fri Nov 25 10:23:45 2011) Command aborted (2230 sec)

It wasn't working. I found in "system monitor" that the program
r.watershed.ram is using only 2gb ram.
The issue may be of interest to GRASS developers.
So, I tried again with "memory" mode and it worked.

(Fri Nov 25 10:24:33
2011)
r.watershed -s -m --overwrite elevation=ybdem@work threshold=12345
accumulation=ybdem100sqkm_acc_sfd drainage=ybdem100sqkm_fdir_sfd
basin=ybdem100sqkm_basin_sfd stream=ybdem100sqkm_stream_sfd memory=12000
SECTION 1 beginning: Initiating Variables. 5 sections total.
SECTION 1a: Mark masked and NULL cells
SECTION 1b: Determining Offmap Flow.
SECTION 2: A* Search.
SECTION 3: Accumulating Surface Flow with SFD.
SECTION 4: Watershed determination.
SECTION 5: Closing Maps.
Closing stream segments map
Closing basins map
Closing accumulation map
Closing flow direction map
(Fri Nov 25 10:28:46 2011) Command finished (252 sec)

I would like to test why it does not work with the all-in-memory mode.
Unfortunately, I was not able to reproduce it with the GRASS sample
datasets. Could you provide a link to the DEM in question? Thanks!

It was suggested that from the accumulation values equal to the number of
cells of area required (i.e. 12345 for 100 sq km), one can find tentative
points having watershed equal to the area desired.
In the accumulation values , I found that there is no value near 12345. And

As mentioned above, this does not make sense. Imagine two streams of
upstream catchment areas of 12344 joining at a confluence. The next
cell will have a surface flow accumulation value of 2 * 12344 which is
larger than 12345. Same principle for two streams joining, one with
12344, the other with 2. You get the idea.

there are lot of negative values.

[snip]

I have read that negative values mean that area getting flow outside the
current region.
That's simply not possible in my case. I have created this basin from
r.water.outlet. I used that as mask to cut the DEM of only that area.

This is to be expected because an upstream catchment area (basin) is
defined such that all neighboring cells (cells just outside the
catchment area) do not contribute to the basin in question. This can
obviously only be determined if the elevation of these neighboring
cells is known. If the elevation of these neighboring cells is unknown
(in your case MASK'ed), it must be assumed that some unknown amount of
surface flow from these neighboring cells pours into the basin of
question. The solution is to grow the MASK by at least one cell,
better two cells. The objective is to have all cells that are adjacent
to the basin in question un-MASK'ed (the other way around: the basin
in question must not be bordered by NULL cells that are not NULL cells
in the original DEM). Only then run r.watershed. This will give you
only positive accumulation values for the basin in question (granted
that the basin is surrounded by elevation values that are not NULL).

Can anyone please shed some more light on it. Or share their experiences
with us in this regard.
Basically, I have two queries now. 1. How to get positive accumulation
values. 2. How to find the accumulation value representing 100 sq km basin
area.

About the accumulation value representing 100 sq km basin: from a
hydrological perspective, it does not make sense IMHO. Why do you want
to identify basins of a fixed size?

Markus M

PS: for the time being, you will have to use grass7 in text mode
because the GUI is not working.