From a2302cbc80a5138787f9c2c95f4664501114ca1d Mon Sep 17 00:00:00 2001 From: Vincent Sarago Date: Fri, 4 Oct 2024 11:00:19 +0200 Subject: [PATCH] do not lower case ColorMap Names (#742) --- CHANGES.md | 26 ++++++++++++++++++++++++++ rio_tiler/colormap.py | 12 ++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 78f2564d..40cf3838 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,19 +2,45 @@ # Unreleased * Enable dynamic definition of Asset **reader** in `MultiBaseReader` (https://github.com/cogeotiff/rio-tiler/pull/711/, https://github.com/cogeotiff/rio-tiler/pull/728) + * Adding `default_assets` for MultiBaseReader and STACReader (author @mccarthyryanc, https://github.com/cogeotiff/rio-tiler/pull/722) + * Adding `default_bands` for MultiBandReader (https://github.com/cogeotiff/rio-tiler/pull/722) + * Adding support for the STAC `Projection` extension to derive the `bounds`, `crs`, `minzoom` and `maxzoom` properties **breaking change** + * Refactor internal function and base classes for the `minzoom/maxzoom` calculation **breaking change** + * Adding `transform`, `height` and `width` attributes (outside init) for `SpatialMixin` class + * Moved `_dst_geom_in_tms_crs` from Reader to `SpatialMixin` class **breaking change** + * Removed use of rasterio's `is_tiled` method + * Enable **Alternate** asset's HREF for STAC by using `RIO_TILER_STAC_ALTERNATE_KEY` environment variable + * Adding support for GDAL VRT Connection string for STAC Assets + * Improve type hint definition + * make `ImageData.rescale` and `ImageData.apply_color_formula` to return `self` + * add support for `.json` colormap files +* do no `lowercase` colormap name in `ColorMaps.get` method **breaking change** + + ```python + from rio_tiler.colormap import cmap + + # before + assert cmap.get("Viridis") + + # now + assert cmap.get("Viridis") + >> InvalidColorMapName: Invalid colormap name: Viridis + ``` + + # 6.7.0 (2024-09-05) * raise `MissingCRS` or `InvalidGeographicBounds` errors when Xarray datasets have wrong geographic metadata diff --git a/rio_tiler/colormap.py b/rio_tiler/colormap.py index 04ec96f7..1f754e36 100644 --- a/rio_tiler/colormap.py +++ b/rio_tiler/colormap.py @@ -296,7 +296,7 @@ def get(self, name: str) -> ColorMapType: dict: colormap dictionary. """ - cmap = self.data.get(name.lower(), None) + cmap = self.data.get(name, None) if cmap is None: raise InvalidColorMapName(f"Invalid colormap name: {name}") @@ -308,7 +308,7 @@ def get(self, name: str) -> ColorMapType: colormap = numpy.load(cmap) assert colormap.shape == (256, 4) assert colormap.dtype == numpy.uint8 - return {idx: tuple(value) for idx, value in enumerate(colormap)} + cmap_data = {idx: tuple(value) for idx, value in enumerate(colormap)} elif cmap.suffix == ".json": with cmap.open() as f: @@ -326,9 +326,13 @@ def get(self, name: str) -> ColorMapType: for (inter, v) in cmap_data ] - return cmap_data + else: + raise ValueError(f"Not supported {cmap.suffix} extension for ColorMap") - raise ValueError(f"Not supported {cmap.suffix} extension for ColorMap") + # save the numpy array / dict / sequence in the data dict + # avoiding the need to re-load the data + self.data[name] = cmap_data + return cmap_data return cmap