From f6a816b7b831c20bd01f2721f2f3aa734b927d70 Mon Sep 17 00:00:00 2001 From: konstntokas Date: Tue, 6 Aug 2024 11:09:59 +0200 Subject: [PATCH] Norman's review adressed --- CHANGES.md | 4 +++- docs/source/cli/xcube_serve.rst | 13 ++++++++++--- xcube/util/cmaps.py | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9af26233c..05842e62d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -25,7 +25,9 @@ (#935, #940) * xcube serve now allows to configure custom color maps via the configuration file. - It supports continuous, stepwise and categorical colormaps. (#1055) + It supports continuous, stepwise and categorical colormaps, which may be + configured as shown in the [section CustomColorMaps of the xcube serve documentation](docs/source/cli/xcube_serve.rst/`customcolormaps`) + (#1055) ### Fixes diff --git a/docs/source/cli/xcube_serve.rst b/docs/source/cli/xcube_serve.rst index 4e18f1045..ff98b3ec5 100644 --- a/docs/source/cli/xcube_serve.rst +++ b/docs/source/cli/xcube_serve.rst @@ -672,9 +672,16 @@ CustomColorMaps [optional] In this section, the user can customize colormaps. Xcube server supports three types of colormaps, namely -* Continuous -* Stepwise -* Categorical +* Continuous: Continuous color assignment, where each represents a support + point of a color gradient. +* Stepwise: Stepwise color mapping where values within the range of two subsequent + s are mapped to the same color. A gets associated with the first + of each boundary range, while the last color gets ignored. +* Categorical: Values represent unique categories or indexes that are mapped to a color. + The data and the must be of type integer. If a category does not have a + in the color mapping, it will be displayed as transparent. Suitable for + categorical datasets. + which can be configured as shown below: diff --git a/xcube/util/cmaps.py b/xcube/util/cmaps.py index c4b46e355..3706dd2cf 100644 --- a/xcube/util/cmaps.py +++ b/xcube/util/cmaps.py @@ -230,7 +230,7 @@ def __init__( cmap_alpha: Optional[matplotlib.colors.Colormap] = None, norm: Optional[matplotlib.colors.Normalize] = None, values: Optional[Sequence[Union[int, float]]] = None, - cm_code: Optional[str] = None, + cm_code: Optional[dict[str, Any]] = None, ): assert_instance(cm_name, str) if cm_type is None: @@ -536,7 +536,7 @@ def parse_cm_code(cm_code: str) -> tuple[str, Optional[Colormap]]: cat_name=CUSTOM_CATEGORY.name, cmap=cmap, values=values, - cm_code=cm_code, + cm_code=user_color_map, ) except (SyntaxError, KeyError, ValueError, TypeError): # If we arrive here, the submitted user-specific cm_code is wrong