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

Categorical color mapping #977

Merged
merged 10 commits into from
May 21, 2024
Merged

Categorical color mapping #977

merged 10 commits into from
May 21, 2024

Conversation

forman
Copy link
Member

@forman forman commented May 13, 2024

  • xcube server's tile API can now handle user-defined colormaps from xcube
    viewer. Custom color bars are still passed using query parameter cmap to
    endpoint /tiles/{datasetId}/{varName}/{z}/{y}/{x},
    but in the case of custom color bars it is a JSON-encoded object with the
    following format: {"name": <str>, "type": <str>, "colors": <list>}. (User-defined color bars #975)
    The object properties are

    • name: a unique name.
    • type: optional type of control values.
    • colors: a list of pairs [[<v1>,<c1>], [<v2>,<c2>], [<v3>,<c3>], ...]
      that map a control value to a hexadecimal color value using CSS format
      "#RRGGBBAA".

    The type values are

    • "node": control points are nodes of a continuous color gradient.
    • "bound": control points form bounds that map to a color, which means
      the last color is unused.
    • "key": control points are keys (integers) that identify a color.
  • xcube server's tile API now allows specifying the data normalisation step
    before a color mapping is applied to the variable data to be visualized.
    This affects endpoint /tiles/{datasetId}/{varName}/{z}/{y}/{x} and the WMTS
    API. The possible normalisation values are

    • lin: linear mapping of data values between vmin and vmax to range 0 to 1
      (uses matplotlib.colors.Normalize(vmin, vmax)).
    • log: logarithmic mapping of data values between vmin and vmax to range 0 to 1
      (uses matplotlib.colors.LogNorm(vmin, vmax)).
    • cat: categorical mapping of data values into to indexes into the color mapping.
      (uses matplotlib.colors.BoundaryNorm(categories)). This normalisation
      currently only works with user-defined colormaps of type
      key or bound (see above).

    The normalisation can be specified in three different ways (in order):

    1. As query parameter norm passed to the tile endpoint.
    2. Property Norm in the Styles/ColorMapping element in xcube server configuration.
    3. Data variable attribute color_norm.

The xcube viewer part of this PR is PR xcube-dev/xcube-viewer#338.

Checklist:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/source/*
  • Changes documented in CHANGES.md
  • GitHub CI passes
  • AppVeyor CI passes
  • Test coverage remains or increases (target 100%)

@forman forman requested a review from pont-us May 16, 2024 09:30
@forman forman marked this pull request as ready for review May 16, 2024 09:30
Copy link
Member

@pont-us pont-us left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Various change requests / suggestions but only minor stuff, so approving since I don't need to see it again.

`"#RRGGBBAA"`.

The `type` values are
- `"node"`: control points are nodes of a continuous color gradient.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A "control point" is what was called a "control value" in the previous paragraph, right? If so I'd prefer to standardize on a single term.

CHANGES.md Outdated Show resolved Hide resolved
test/util/test_cmaps.py Outdated Show resolved Hide resolved
test/util/test_cmaps.py Outdated Show resolved Hide resolved
test/util/test_cmaps.py Outdated Show resolved Hide resolved
xcube/core/_tile2.py Outdated Show resolved Hide resolved
Comment on lines +400 to +401
cmap_norm: Color map normalisation. One of "lin" (linear), "log"
(logarithmic), "cat" (categorical).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I instinctively want to introduce an enum, but I guess it's not worth it when we need the string representation to interface with the viewer anyway...

xcube/webapi/viewer/data/docs/add-layer-wms.en.md Outdated Show resolved Hide resolved
This service publishes its map layers via special URLs that
contain an image tile's x- and y-coordinates and an optional zoom level z.

**WTS Layer URL**: The URL of layer offered by a TMS. It must contain
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**WTS Layer URL**: The URL of layer offered by a TMS. It must contain
**WMTS Layer URL**: The URL of layer offered by a WMTS. It must contain

Co-authored-by: Pontus Lurcock <pontus.lurcock@brockmann-consult.de>
@forman forman merged commit 6b42c4a into main May 21, 2024
1 of 2 checks passed
@forman forman deleted the forman-categorical_color_bars branch May 21, 2024 12:32
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

Successfully merging this pull request may close these issues.

2 participants