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

TypeError: read() takes 1 positional argument but 2 were given + AttributeError: 'RasterLayer' object has no attribute 'seek' #48

Open
dbaldig opened this issue Feb 3, 2023 · 4 comments
Labels

Comments

@dbaldig
Copy link

dbaldig commented Feb 3, 2023

Hey Steven,
first of all, thanks a lot for your package...it's such a great help!

I followed along your Multi-Target Spatial Prediction using the Meuse Dataset tutorial to modify it for a RF implementation.
I tried to work with a stacked raster dataset of mine but eventually always run in the same error. For example, when executing this code:

elevation = 'C:/Users/.../DEM_filled.tif'
slope = 'C:/Users/.../slope.tif'
roughness = 'C:/Users/.../roughness.tif'
tri = 'C:/Users/.../tri.tif'
tpi = 'C:/Users/.../tpi.tif'
ndvi = 'C:/Users/.../ndvi.tif'
annual_prec = 'C:/Users/.../annual_prec.tif'
aspect = 'C:/Users/.../aspect.tif'
etc. 

predictor_files = [elevation, slope, roughness, tri, tpi, ndvi, annual_prec, aspect, etc.]
stack = Raster(predictor_files)
stack.names

xy_layer = xy_coordinates(
    layer=stack.iloc[0], 
    file_path=NamedTemporaryFile(suffix=".tif").name
)

it returns an:


TypeError Traceback (most recent call last)
TypeError: read() takes 1 positional argument but 2 were given
Exception ignored in: 'rasterio._filepath.filepath_read'
Traceback (most recent call last):
File "[c:...new_venv\lib\site-packages\rasterio\io.py]", line 224, in open
return DatasetReader(mempath, driver=driver, sharing=sharing, **kwargs)
TypeError: read() takes 1 positional argument but 2 were given

AttributeError Traceback (most recent call last)
File rasterio_filepath.pyx:141, in rasterio._filepath.filepath_seek()

AttributeError: 'RasterLayer' object has no attribute 'seek'
Exception ignored in: 'rasterio._env.log_error'
Traceback (most recent call last):
File "rasterio_filepath.pyx", line 141, in rasterio._filepath.filepath_seek
AttributeError: 'RasterLayer' object has no attribute 'seek'

Do you have an idea what could cause this? I made sure that all rasters have only one band

@dbaldig
Copy link
Author

dbaldig commented Feb 3, 2023

Sorry, I'm dealing with another issue. Let me know if you want me to open another issue seperately.

elevation = 'C:/Users/.../DEM_filled.tif'
slope = 'C:/Users/.../slope.tif'
roughness = 'C:/Users/.../roughness.tif'
tri = 'C:/Users/.../tri.tif'
tpi = 'C:/Users/.../tpi.tif'
ndvi = 'C:/Users/.../ndvi.tif'
annual_prec = 'C:/Users/.../annual_prec.tif'
aspect = 'C:/Users/.../aspect.tif'
etc.

predictor_files = [elevation, slope, roughness, tri, tpi, ndvi, annual_prec, aspect, etc.]
stack = Raster(predictor_files)
stack.names

stack.names returns the actual dict_keys for most of the rasters but as soon as I add annual_prec and/or "aspect" to predictor_files, it returns an empty "dict_keys([])". The path is correct and the resolution is also the same. Any idea why this could be?
It seems like it's quite random, cause I had a third raster which didn't work at first, but works now after processing it just the same way as before.

Thanks a lot!

EDIT:
So, I can stack the layers with rasterio and then load the stacked raster with pyspatialml. The bands are renamed by pyspatialml to stack_01, stack_02, etc. When I try to rename the the bands, I get the "read() takes 1 positional argument but 2 were given" and "read() takes 1 positional argument but 2 were given" errors but it eventually renames the names.
In the end, I got the model running like that.

@selvaje
Copy link

selvaje commented Apr 13, 2023

Dear @dbaldig & @stevenpawley
I'm getting the same error. I'm wondering if you find an alternative solution.
Thanks
Giuseppe

@pyaj0
Copy link

pyaj0 commented Jul 9, 2023

Hi, same issue. Raster() used to work just fine last year but now, I get

TypeError:` 'NoneType' object is not subscriptable

@selvaje
Copy link

selvaje commented Jul 9, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants