mdbartos / pysheds

:earth_americas: Simple and fast watershed delineation in python.
GNU General Public License v3.0
707 stars 191 forks source link

[error] flow accumulation along nodata values differs to GRASS GIS #69

Closed itati01 closed 5 years ago

itati01 commented 5 years ago

I test pysheds for the first time, so please be patient with me.

I have started with a flow direction grid (D8) created by the GRASS GIS tool r.watershed. The direction codes range from 1 == NE to 8 == E (actually, it also contains the negative values to indicate edge contamination, c.f. What are the meaning of Grass drainage direction values from r.watershed) . The difference between the flow accumulation is zero (light blue in the attachment), as expected, except for raster cells next to nodata values (white color).

These nodata cells are necessary to exclude a channel crossing the catchment. As some streams cross the channel, I had to keep some of its raster cells, though. Any help is appreciated.

grid = Grid.from_raster(fdir, data_name='dir')
dirmap=(2,1,8,7,6,5,4,3) # coding r.watershed from N->NW
grid.dir = np.abs(grid.dir) # ignore flag edge contamination
grid.accumulation(data="dir", out_name="acc", dirmap=dirmap)

diff_grass_pysheds

mdbartos commented 5 years ago

Hi @itati01,

Do you have an image of what it's supposed to look like? Alternatively, do you know what might be happening that causes the difference?

itati01 commented 5 years ago

Hi @mdbartos,

The differences are actually rather small, up to 2500 cells compared to 1.1e7 cells of cumulated flow. By the way, your values are higher than the reference. As they also cumulate, the bluish "streams" in the difference image above follow the "real" streams.

Interestingly, these differences do not necessarily start exactly at the nodata but also nearby. After looking more closely, I now suspect that the GRASS algorithm has an issue with edge contamination (or I am missing something important). The attached map shows that the colour (=flow accumulation) does not change within the rectangle despite the flow towards the 2nd cell in the upper row. I'll close this issue and will open one at osgeo.org.

error_facc_grass