mdbartos / pysheds

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

Different API for Grid functions if running pysheds without numba #201

Open mheberger opened 2 years ago

mheberger commented 2 years ago

I wished to run pysheds without numba, and found it is possible to do so by simply uninstalling numba in my Python virtual environment where I am running pysheds scripts. But I also found that the API for the various functions in the class Grid have a different API, in the file pgrid.py rather than sgrid.py. I think it is an older version of the API from previous versions that has not been updated to match the docs? I was clued in by this error:

TypeError: from_raster() missing 1 required positional argument: 'data_name'

I was baffled for a while, but once I realized what was going on, it was easy enough to refer to the older tutorials at Hatari Labs, and the examples here on Github. For example, a snippet of code that no longer works without numba:

x_snap, y_snap = grid2.snap_to_mask(acc > 500, (x, y))
catch = grid.catchment(x=x_snap, y=y_snap, fdir=fdir, dirmap=dirmap, xytype='coordinate')

This version works:

[x_snap, y_snap], distance = grid.snap_to_mask(grid.acc > 500, (x, y))
grid.catchment(data='dir', x=x_snap, y=y_snap, dirmap=dirmap, xytype='label',
                       out_name='catch', recursionlimit=15000, nodata_out=0)

So my question is, do you plan any updates to the "old" API? Also posting this here in case others encounter the same error.