We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c232e3d commit e74224aCopy full SHA for e74224a
xrspatial/utils.py
@@ -5,6 +5,7 @@
5
import datashader.transfer_functions as tf
6
import numpy as np
7
import xarray as xr
8
+from datashader.colors import rgb
9
from numba import cuda, jit
10
11
try:
@@ -433,3 +434,13 @@ def canvas_like(
433
434
out = cvs.raster(raster, **kwargs)
435
436
return out
437
+
438
439
+def color_values(agg, color_key, alpha=255):
440
+ def _convert_color(c):
441
+ r, g, b = rgb(c)
442
+ return np.array([r, g, b, alpha]).astype(np.uint8).view(np.uint32)[0]
443
444
+ _converted_colors = {k: _convert_color(v) for k, v in color_key.items()}
445
+ f = np.vectorize(lambda v: _converted_colors.get(v, 0))
446
+ return tf.Image(f(agg.data))
0 commit comments