swiftsimio.visualisation.tools.cmaps module
Two-dimensional colour map support, along with example colour maps.
- swiftsimio.visualisation.tools.cmaps.ensure_rgba(input_color: Iterable[float]) array [source]
Ensures a colour is RGBA compliant.
Default alpha if missing: 1.0.
- Parameters:
input_color (iterable) – An iterable of maximum length 4, with RGBA values encoded as floating point 0.0 -> 1.0.
- Returns:
array_color – An array of length 4 as an RGBA color.
- Return type:
np.array
- swiftsimio.visualisation.tools.cmaps.apply_color_map(first_values, second_values, map_grid)[source]
Applies a 2D colour map by providing a 2D linear interpolation to the known fixed grid points. Not to be called on its own, as the map itself is provided by the
LinearSegmentedCmap2D
, but this is provided separately so it can benumba
-accelerated.- Parameters:
first_values (iterable[float]) – Array or list to loop over, containing floats ranging from 0.0 to 1.0. Provides the normalisation for the horizontal component. Must be one-dimensional.
second_values (iterable[float]) – Array or list to loop over, containing floats ranging from 0.0 to 1.0. Provides the normalisation for the vertical component. Must be one-dimensional.
map_grid (np.ndarray) – 2D numpy array proided by
LinearSegmentedCmap2D
.
- Returns:
An N by 4 array (where N is the length of
first_value
andsecond_value
) of RGBA components.- Return type:
np.ndarray
- class swiftsimio.visualisation.tools.cmaps.Cmap2D(name: str | None = None, description: str | None = None)[source]
Bases:
object
A generic two dimensional implementation of a colour map.
Developer use only.
- colors: List[List[float]] = None
- coordinates: List[List[float]] = None
- generate_color_map_grid()[source]
Generates the colour map grid and stores it in
_color_map_grid
. Imeplementation dependent.
- property color_map_grid
Generates, or gets, the color map grid.
- class swiftsimio.visualisation.tools.cmaps.LinearSegmentedCmap2D(colors: List[List[float]], coordinates: List[List[float]], name: str | None = None, description: str | None = None)[source]
Bases:
Cmap2D
A two dimensional implementation of the linear segmented colour map.
- class swiftsimio.visualisation.tools.cmaps.LinearSegmentedCmap2DHSV(colors: List[List[float]], coordinates: List[List[float]], name: str | None = None, description: str | None = None)[source]
Bases:
Cmap2D
A two dimensional implementation of the linear segmented colour map, using the HSV space to combine the colours.
- Parameters:
colors (List[List[float]]) – Individual colors (at
coordinates
below) that make up the color map.coordinates (List[List[float]]) – 2D coordinates in the plane to place the above
colors
at.name (str, optional) – Name of this color map (metadata)
description (str, optional) – Optional metadata description of this colour map.
See also
LinearSegmentedCmap2D
, a cousin of this class that combines colours using the RGB space rather than HSV used here.