You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
For dataset variables that provide a flag_values attribute, it would be convenient to get a matching matplotlib color mapping. For some variables we also provide flag_colors that should be used if so.
Describe the solution you'd like
Add method get_cmap() to xcube.core.maskset.MaskSet.
Additional context
CCI Land Cover datasets, lccs_class variable.
The text was updated successfully, but these errors were encountered:
Describe the bug MaskSet.get_cmap() method does not work, which has been added to xcube in #1012.
To Reproduce
In DeepESDL, use the CCI C3S land cover classification, create a mask and try to create a cmap. It creates a matplotlib.colors.ListedColormapinstance, and therefore the unit tests are working fine. If one wants to use the cmap, the following error is returned. ValueError: data mapping points must start with x=0 and end with x=1
Additional context
The values of the colormap needs to be normalized. Furthermore, no color flag is given for 'no_data'. Here is a workable example, where we address the two issues.
def get_cmap(maskset):
vals = maskset._flag_values
extent = vals.max() - vals.min()
vals_norm = (vals - vals.min()) / extent
colors = ["#000000"] + maskset._flag_colors
color_mapping = [(v, c) for v, c in zip(vals_norm, colors)]
return matplotlib.colors.LinearSegmentedColormap.from_list(
str(maskset._flag_var.name), color_mapping, N=len(vals)
)
Is your feature request related to a problem? Please describe.
For dataset variables that provide a
flag_values
attribute, it would be convenient to get a matching matplotlib color mapping. For some variables we also provideflag_colors
that should be used if so.Describe the solution you'd like
Add method
get_cmap()
toxcube.core.maskset.MaskSet
.Additional context
CCI Land Cover datasets,
lccs_class
variable.The text was updated successfully, but these errors were encountered: