Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

More colormap options!

See original GitHub issue

Issue Description

With #90 @DanSchoppe added a third colormap to rio-tiler. While this is awesome, I think rio-tiler could do more for allowing user to define custom colormap.

colormap are used when translating a one band data array to the image format using the new array_to_image(using GDAL using a simple translation:

So here ☝️ a rio_tiler.utils.array_to_image compatible colormap object is usually an array of shape (256, 3)

c = get_colormap(format="gdal")
 (256, 3)
  [255 255 255]
  [250 250 250]
  [246 246 246]
  [242 242 242]
  [255   1 191]
  [255   1 207]
  [255   1 223]
  [255   1 239]

I first though we could have used a custom dict like

    0: [255, 255, 255],
    100: [255,   1, 191],

~to create a colormap fordiscrete values, but dict are not hashable so the current code in rio_tiler.utils.array_to_image won’t work.~

I do love the dict option for colormap (like Rasterio use so I first check if we can maybe change the rio_tiler.utils.get_colormap function to have to return a dictionary colormap (because it seems to be the default format for GDAL) and in the same time adapt the rio_tiler.utils.array_to_image to work with dict.

In a second time we could add another utility function to create colormaps, it seems that matplotlib has some functionality but I’m not sure we should had more required module to rio-tiler.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

vincentsaragocommented, Mar 26, 2019

FYI: in #92 I’ve updated rio_tiler.utils.array_to_image to allow discrete colormap passed as dictionary

vincentsaragocommented, Mar 15, 2019

[3 x 256] array is too large to pass as a query parameter, so if we stuck with our current colormap data structure, passing a full colormap at request time would probably be done via POST message body. At least it would compress well.

Nice thing about rio-tiler, is that it’s designed to be implementation agnostic to be used behind API or other functions (like rio-glui, remotepixel-tiler …). Passing a 3x256 array or dict via a POST message shouldn’t be a problem for you API. But I agree we need a tool which can create color map from a colormap definition (e.g. passing min/max color)

Perhaps there’s an elegant way to reduce the [3 x 256] array colormap schema to something more concise. You mentioned matplotlib, and I happened to find the same project for inspiration. If there’s a sufficiently concise way to describe a colormap, perhaps it would be palatable to include a colormap-producing description as a query param. Here’s the matplotlib colormap definitions for reference: I’m not sure there will be a flexible enough way to concisely describe colormaps without allowing the user to simply provide the full mapping for every index. For example, the colormap in #90 was produced by programmatically interpolating between colors in HSV colorspace.

Well as mentioned earlier, rio-tiler is agnostic, user could totally add Matplotlib to its API and apply the colormap using something else that rio-tiler.utils.array_to_image function. Meaning: I think at one point I’d like to keep rio-tiler as simple as possible so we focus on tiling performances and not on third party implementation (e.g: serving images).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Choosing Colormaps in Matplotlib
Here we briefly discuss how to choose between the many options. For help on creating your own colormaps, see Creating Colormaps in Matplotlib....
Read more >
View and set current colormap - MATLAB colormap - MathWorks
This MATLAB function sets the colormap for the current figure to one of the predefined colormaps.
Read more >
Colormaps — ProPlot documentation - Read the Docs
Proplot defines continuous colormaps as color palettes that sample some continuous function between two end colors. They are generally used to encode data ......
Read more >
Beautiful custom colormaps with Matplotlib | by Kerry Halupka
These are just a few examples of the colormaps you can use, for more details and options, check out this guide from Matplotlib....
Read more >
Colormaps in Matplotlib | When Graphic Designers Meet ...
Matplotlib provides some nice colormaps, such as Sequential colormaps, Diverging colormaps, Cyclic colormaps, and Qualitative colormaps.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found