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

Indexing Error in _d8_distance_from_ridge #255

Open
JonKing93 opened this issue May 24, 2024 · 0 comments · May be fixed by #260
Open

Indexing Error in _d8_distance_from_ridge #255

JonKing93 opened this issue May 24, 2024 · 0 comments · May be fixed by #260

Comments

@JonKing93
Copy link
Contributor

The "distance_to_ridge" function produces an off-by-one indexing error for D8 flow routing. For example, the following code triggers the error:

from pysheds.grid import Grid
from math import nan

grid = Grid.from_raster("fdir.tif")
fdir = grid.read_raster("fdir.tif")
weights = grid.read_raster("weights.tif")
assert fdir.shape == weights.shape

# Causes an off-by-one indexing error
grid.distance_to_ridge(
    fdir, weights, nodata_out=nan, routing="d8", dirmap=(3, 2, 1, 8, 7, 6, 5, 4)
)

With error stack:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "path\to\issue.py", line 10, in <module>
    grid.distance_to_ridge(
  File "path\to\Lib\site-packages\pysheds\sgrid.py", line 1649, in distance_to_ridge
    rdist = self._d8_distance_to_ridge(fdir=fdir, weights=weights,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "path\to\Lib\site-packages\pysheds\sgrid.py", line 1676, in _d8_distance_to_ridge
    startnodes = startnodes[(indegree == 0)]
                 ~~~~~~~~~~^^^^^^^^^^^^^^^^^
IndexError: boolean index did not match indexed array along dimension 0; dimension is 6205794 but corresponding boolean dimension is 6205763
@JonKing93 JonKing93 linked a pull request Nov 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant