Skip to content

Commit

Permalink
force discrete colormap when cmap does not have 256 values
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Dec 11, 2023
1 parent a260cd6 commit a37da62
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

# 6.2.8 (2023-12-11)

* apply `discrete` colormap when the provided colormap does not have 256 values

# 6.2.7 (2023-11-29)

* Adjusting dataset latitude for WarpedVRT parameters calculation when EPSG:4326 dataset latitudes overflows EPSG:3857 min/max latitude (https://github.com/cogeotiff/rio-tiler/pull/660)
Expand Down
4 changes: 2 additions & 2 deletions rio_tiler/colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ def apply_cmap(data: numpy.ndarray, colormap: ColorMapType) -> DataMaskType:
if isinstance(colormap, Sequence):
return apply_intervals_cmap(data, colormap)

# if colormap has more than 256 values OR its `max` key >= 256 we can't use
# if colormap has less or more than 256 values OR its `max` key >= 256 we can't use
# rio_tiler.colormap.make_lut, because we don't want to create a `lookup table`
# with more than 256 entries (256 x 4) array. In this case we use `apply_discrete_cmap`
# which can work with arbitrary colormap dict.
if len(colormap) > 256 or max(colormap) >= 256 or min(colormap) < 0:
if len(colormap) != 256 or max(colormap) >= 256 or min(colormap) < 0:
return apply_discrete_cmap(data, colormap)

lookup_table = make_lut(colormap)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ def test_apply_discrete_cmap():
mask[2:5, 2:5] = 255
mask[5:, 5:] = 255
numpy.testing.assert_array_equal(m, mask)
dd, mm = colormap.apply_cmap(data, cm)
numpy.testing.assert_array_equal(dd, d)
numpy.testing.assert_array_equal(mm, m)

data = data.astype("uint16")
d, m = colormap.apply_discrete_cmap(data, cm)
Expand Down

0 comments on commit a37da62

Please sign in to comment.