0

Here is my code

refPath = '/Users/admin/Downloads/Landsat8/'
ext = '_NDWI.tif'
for file in sorted(os.listdir(refPath)):
    if file.endswith(ext):
        print(file)
        ndwiopen = rs.open(file)
        ndwiread = ndwiopen.read(1)
 

Here is the error

2014_NDWI.tif
---------------------------------------------------------------------------
CPLE_OpenFailedError                      Traceback (most recent call last)
File rasterio/_base.pyx:302, in rasterio._base.DatasetBase.__init__()

File rasterio/_base.pyx:213, in rasterio._base.open_dataset()

File rasterio/_err.pyx:217, in rasterio._err.exc_wrap_pointer()

CPLE_OpenFailedError: 2014_NDWI.tif: No such file or directory

During handling of the above exception, another exception occurred:

RasterioIOError                           Traceback (most recent call last)
Input In [104], in <cell line: 33>()
     34 if file.endswith(ext):
     35     print(file)
---> 36     ndwiopen = rs.open(file)
     38     ndwiread = ndwiopen.read(1)
     39     plt.figure(figsize = (20, 15))

File /Applications/anaconda3/lib/python3.9/site-packages/rasterio/env.py:442, in ensure_env_with_credentials.<locals>.wrapper(*args, **kwds)
    439     session = DummySession()
    441 with env_ctor(session=session):
--> 442     return f(*args, **kwds)

File /Applications/anaconda3/lib/python3.9/site-packages/rasterio/__init__.py:277, in open(fp, mode, driver, width, height, count, crs, transform, dtype, nodata, sharing, **kwargs)
    274 path = _parse_path(raw_dataset_path)
    276 if mode == "r":
--> 277     dataset = DatasetReader(path, driver=driver, sharing=sharing, **kwargs)
    278 elif mode == "r+":
    279     dataset = get_writer_for_path(path, driver=driver)(
    280         path, mode, driver=driver, sharing=sharing, **kwargs
    281     )

File rasterio/_base.pyx:304, in rasterio._base.DatasetBase.__init__()

RasterioIOError: 2014_NDWI.tif: No such file or directory
    

As it is shown that the file is getting printed as an output but that can not be opened by the RasterIO (as rs). Can't understand what is missing in the script.

1 Answers1

0

Unsure if this is your exact problem, but I rammed my head against this same exact error for 5-10 hours before I realized that the '.tif' file I was trying to read had an extension in all caps, as in '.TIF'. This is apparently the default for the Landsat 8 image bands that I was working with.

I was doing similar concatenation but my string would result in 'filename.tif' instead of the correct 'filename.TIF', so rasterio would be unable to read it. It was really frustrating, so I figured I would share how I was able to solve it since you have not yet received any replies, even though I cannot know if this was your issue. When I searched this error, this post is one of the first and most similar that would pop up but was unanswered, so I thought I would post in case any one with my issue might stumble across it as well (or, for myself when I inevitably forget in a few months how I had solved this).

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 07 '22 at 11:55