zennit.cmap
Create color maps from a color-map specification language
Classes
Tokens used by the lexer of ColorMap. |
|
Compile a color map from color-map specification language (cmsl) source code. |
|
Nodes produced by the parser of ColorMap. |
|
Dict-like object to store sources for colormaps, and compile and cache them lazily. |
- class zennit.cmap.CMapToken(type: str, value: str, pos: int)[source]
Bases:
NamedTuple
Tokens used by the lexer of ColorMap.
- pos: int
Alias for field number 2
- type: str
Alias for field number 0
- value: str
Alias for field number 1
- class zennit.cmap.ColorMap(source)[source]
Bases:
object
Compile a color map from color-map specification language (cmsl) source code.
The color-map specification language (cmsl) is used to specify linear color maps with comma-separated colors supplied as hexadecimal values for each color channel in RGB, with either 1 or 2 values per channel. Optionally, a hexadecimal index with either one or two digits may be supplied in front of each color, followed by a colon, to indicate the index which should be the color. Values for the ColorMap in-between colors will be interpolated linearly. If no index is supplied, colors without indices will be spaced evenly between indices. If the first and last indices are supplied but not 0 (or 00) and f (or ff) respectively, they will be added as an additional node in the color map, with the same color as the colors with the lowest and highest index respectively. If indices are provided, they must be in ascending order from left to right, with an arbitrary number of non-indexed colors. If the first and/or last color are not indexed, they are assumed to be 0 (or 00) and f (or ff) respectively.
- Parameters:
source (str) – Source code to generate the color map.
- palette(level=1.0)[source]
Create an 8-bit palette.
- Parameters:
level (float) – The level of the color map. 1.0 is default. Values below zero reduce the color range, with only a single color used at value 0.0. Values above 1.0 clip the value earlier towards the maximum, with an increasingly steep transition at the center of the image.
- Returns:
obj – The palette described by an unsigned 8-bit numpy array with 256 entries.
- Return type:
numpy.ndarray
- property source: str
Source code property used to generate the color map. May be overwritten with a new string, which will be compiled to change the color map.