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 colormap issue and raise a more descriptive error message #1105

Closed
vincentsarago opened this issue Mar 21, 2025 · 1 comment
Closed

Comments

@vincentsarago
Copy link
Member

Titiler/rio-tiler let the user to do a lot of things when it comes to image rendering. One issue that seems to come ofter is when users want to apply a colormap after some band maths, user would need to rescale the values to match the data type of the colormap (usually uint8, 0->255). Because we cannot automagically rescale the data (e.g using the min/max of the local array, which would cause each tile to look different) we should at least make sure the error message says something a bit more useful than "arrays used as indices must be of integer (or boolean) type" 😅

either in

if colormap:
data, alpha_from_cmap = apply_cmap(data, colormap)
# Combine both Mask from dataset and Alpha band from Colormap
mask = numpy.bitwise_and(alpha_from_cmap, mask)
datatype_range = (dtype_ranges[str(data.dtype)],)

or https://github.com/cogeotiff/rio-tiler/blob/ce62e555562fd7a38bde4671ab680dfb2b5bdd15/rio_tiler/colormap.py#L90-L135

ref: EOEPCA/data-access#142

@vincentsarago
Copy link
Member Author

in https://github.com/cogeotiff/rio-tiler/blob/main/CHANGES.md#721-2024-11-14 we've added a catch to make sure the issue mentioned in ☝ doesn't happen.

Most of colormap related issue are already caught in rio-tiler, and the most common one (data type issue) is handled so I'm going to closes this for now.

if anyone feels we should re-open this please post a reproducible example 🙏

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

No branches or pull requests

1 participant