Coverage for local_installation_linux/mumott/output_handling/orientation_image_mapper.py: 95%
21 statements
« prev ^ index » next coverage.py v7.3.2, created at 2025-05-05 21:21 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2025-05-05 21:21 +0000
1""" Container for class OrientationImageMapper. """
2from matplotlib.colors import Colormap
3from matplotlib.cm import get_cmap
4import colorcet # noqa
5from typing import Union
6import numpy as np
9class OrientationImageMapper():
11 def __init__(self,
12 colormap: Union[str, Colormap] = 'cet_cyclic_isoluminant'):
13 """
14 Helper class for generating a color wheel to be used in plots.
16 Parameters
17 ----------
18 colormap : Union[str, Colormap]
19 The colormap to be used for creating the colorwheel. Should be cyclic.
20 Default is ``cet_cyclic_isoluminant``.
21 """
22 self._colormap = get_cmap(colormap)
23 r = np.sqrt(np.linspace(1.0, 0.0, 360))
24 th = np.linspace(0, 2 * np.pi, 360)
25 th, r = np.meshgrid(th, r)
26 th_flip = np.arctan2(np.cos(th), np.sin(th))
27 thx = (th[:-1, :-1] - (th[:-1, :-1] > np.pi).astype(float) * np.pi) / np.pi
28 thx = self._colormap(thx)
29 self._wheel_properties = [th_flip, r, thx]
31 @property
32 def colormap(self) -> Colormap:
33 """ Returns the colormap used by the wheel. """
34 return self._colormap
36 @property
37 def wheel_properties(self) -> list:
38 """ Returns wheel properties as a list. The entry at
39 ``wheel_properties[0]`` contains the angles. ``wheel_properties[1]`` contains the radius.
40 ``wheel_properties[2]`` contains the RGBA values mapped to the angles. """
41 return self._wheel_properties