mdbartos / pysheds

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

Bugfixes for D8 routing. #235

Closed groutr closed 8 months ago

groutr commented 8 months ago

This PR addresses two issues with _d8_flowdir_numba.

  1. The returned flowdir array was incorrect for nonzero values of nodata_out. The loops start with pixel at index (1, 1), which means there was always a border of zeros in the returned array. This is solved by simply initializing the array to the nodata_out value at the beginning before filling the array.
  2. Nodata cells were improperly considered when they were adjacent to a valid cell. The solution is the skip any cell neighbors that are also nodata cells. This prevents the possibility of flow being incorrectly routed because of the nodata value.
mdbartos commented 8 months ago

Thanks @groutr, this looks good and all tests are passing. Will pull in now.