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

Misleading explicit_color_map documentation #306

Closed
bartwalczak opened this issue May 13, 2023 · 6 comments
Closed

Misleading explicit_color_map documentation #306

bartwalczak opened this issue May 13, 2023 · 6 comments

Comments

@bartwalczak
Copy link

Hi,

If you follow the explicit_color_map documentation example as it is written, you will get the following error

time="2023-05-13T13:50:48Z" level=info msg=request URI="/v1/tc/singleband/tiff_orig/0/EMEP/PM10/A/2019/4/10/6.png?stretch_range=[0,27042.123]&colormap=explicit&explicit_color_map={0:(0,128,0,255),1:(255,43,36,255)}" method=GET status=500
marshmallow.exceptions.ValidationError: {'_schema': ['Could not decode value {0:(0,128,0,255),1:(255,43,36,255)} for explicit_color_map as JSON']}

The valid example should be a proper JSON:

 {"0":[0,128,0,255],"1":[255,43,36,255]}

And if Python data types are used, they should be marked as such. Otherwise this is misleading if one is making a request not using Python.

@bartwalczak
Copy link
Author

bartwalczak commented May 13, 2023

However, despite being properly parsed, this request does not seem to render the explicit color map - all pixel values are returned as transparent.

What am I missing?

@dionhaefner
Copy link
Collaborator

Thanks for the report. This will be fixed in #307.

However, despite being properly parsed, this request does not seem to render the explicit color map - all pixel values are returned as transparent.

Sounds like there is a misunderstanding regarding what an explicit color map means. This feature is really for categorical data, i.e., 1-to-1 mappings of raster values to colors. The keys of the given mapping relate to the values of the raster. So a query like this pretty much never makes sense:

?stretch_range=[0,27042.123]&colormap=explicit&explicit_color_map={"0":[0,128,0,255],"1":[255,43,36,255]}

Because the stretch_range argument suggests that you have a continuous range of values, but you're using a discrete mapping.

See also this tutorial on explicit color maps.

@bartwalczak
Copy link
Author

Thanks. Does this mean that there is no way to create a dynamic threshold map in Terracotta? I know that I can create a custom map file and upload it to the server, but I wanted to offer a relative scale based on percentiles for each file (and there is over a hundred of them).

@dionhaefner
Copy link
Collaborator

dionhaefner commented May 15, 2023

Correct, we only support linear transformations via stretch_range.

I suggest you rescale the rasters offline before ingestion. If that is not an option, you could use the /compute endpoint to transform the raster on the fly, but then you're still limited to simple algebraic expressions (which may suffice if using just a few percentiles).

@bartwalczak
Copy link
Author

Thanks a lot for your support.

dionhaefner added a commit that referenced this issue May 15, 2023
Fix explicit cmap example in apidoc (#306)
@dionhaefner
Copy link
Collaborator

Happy to help.

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

2 participants