mdbartos / pysheds

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

AttributeError: 'DatasetReader' object has no attribute 'read_band' #88

Closed PierreRCM closed 2 years ago

PierreRCM commented 5 years ago

Hi,

I could not find the read_band method which is from rasterio? This error appears in read_raster Maybe a problem of version ? if window is None: shape = f.shape if len(f.indexes) > 1: data = np.ma.filled(f.read_band(band)) else: data = np.ma.filled(f.read()) affine = f.transform data = data.reshape(shape)

Any ideas ? :D

mdbartos commented 5 years ago

Hi Pierre,

Sounds like rasterio may have updated their API and the change may have broken this function.

I will need to update the library. In the meantime, you can try downgrading rasterio.

The version I am currently using is 1.0.4.

Thanks, MDB

PierreRCM commented 5 years ago

Thanks for the answer,

I can't find 1.0.4 in all version proposed

There are :

1.0.22 1.0.21 1.0.13 0.36.0 0.25.0 0.24.0

which one would match with pysheds ?

Thanks

mdbartos commented 5 years ago

I think it should work with one of the 1.0.x versions.

mdbartos commented 5 years ago

What version do you currently have?

PierreRCM commented 5 years ago

The last one 1.0.22

mdbartos commented 5 years ago

Ah, I just looked at the rasterio docs. It looks like read_band was replaced with read in v1.0. I guess I just never had any test cases with multiple bands.

The line:

data = np.ma.filled(f.read_band(band))

Would need to be changed to:

data = np.ma.filled(f.read(band))
PierreRCM commented 5 years ago

Oh nice ! At least i didn't bother you for no reason :D

Thanks

mdbartos commented 2 years ago

Please reopen if this issue persists.

T4mmi commented 2 years ago

the error is fixed by replacing read_band() by read(band) ... but this patch does not appear in the current pysheds version (0.3.2) which is problematic for projects depending on pysheds :/

mdbartos commented 2 years ago

Thanks for letting me know. I didn't realize this was never fixed. Unit tests never raised this error because only single-band rasters were used. I will fix as soon as possible.