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

catch and expend image encoding error #767

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

vincentsarago
Copy link
Member

ref developmentseed/titiler#1031

cc @drnextgis

from rio_tiler.models import ImageData
import numpy
arr = numpy.ma.zeros((5,266,256), dtype="uint8")
ImageData(arr).render()
---------------------------------------------------------------------------
ObjectNullError                           Traceback (most recent call last)
~/Dev/CogeoTiff/rio-tiler/rio_tiler/utils.py in render(data, mask, img_format, colormap, **creation_options)
    608 
--> 609                 return memfile.read()
    610 

~/Dev/venv/py39/lib/python3.9/site-packages/rasterio/io.py in __exit__(self, *args)
    167     def __exit__(self, *args):
--> 168         self._env.close()
    169         self.close()

/opt/homebrew/Cellar/python@3.9/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py in close(self)
    539         """Immediately unwind the context stack."""
--> 540         self.__exit__(None, None, None)
    541 

/opt/homebrew/Cellar/python@3.9/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py in __exit__(self, *exc_details)
    531                 fixed_ctx = exc_details[1].__context__
--> 532                 raise exc_details[1]
    533             except BaseException:

/opt/homebrew/Cellar/python@3.9/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py in __exit__(self, *exc_details)
    516             try:
--> 517                 if cb(*exc_details):
    518                     suppressed_exc = True

rasterio/_base.pyx in rasterio._base.DatasetBase.__exit__()

rasterio/_base.pyx in rasterio._base.DatasetBase.close()

rasterio/_io.pyx in rasterio._io.BufferedDatasetWriterBase.stop()

rasterio/_err.pyx in rasterio._err.exc_wrap_pointer()

ObjectNullError: Pointer 'hSrcDS' is NULL in 'GDALCreateCopy'. 

The above exception was the direct cause of the following exception:

InvalidFormat                             Traceback (most recent call last)
<ipython-input-4-5f988547d155> in <cell line: 1>()
----> 1 ImageData(arr).render()

~/Dev/CogeoTiff/rio-tiler/rio_tiler/models.py in render(self, add_mask, img_format, colormap, **kwargs)
    705 
    706         if add_mask:
--> 707             return render(
    708                 array.data,
    709                 self.mask,  # We use dataset mask for rendering

~/Dev/CogeoTiff/rio-tiler/rio_tiler/utils.py in render(data, mask, img_format, colormap, **creation_options)
    610 
    611     except Exception as e:
--> 612         raise InvalidFormat(
    613             f"Could not encode array of shape ({count},{height},{width}) and of datatype {data.dtype} using {img_format} driver"
    614         ) from e

InvalidFormat: Could not encode array of shape (5,266,256) and of datatype uint8 using PNG driver

@vincentsarago vincentsarago merged commit 444289e into main Nov 18, 2024
8 checks passed
@vincentsarago vincentsarago deleted the patch/image-encoding-error-message branch November 18, 2024 07:24
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 this pull request may close these issues.

1 participant