Coverage for kwave/utils/colormap.py: 23%
22 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-24 11:55 -0700
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-24 11:55 -0700
1import numpy as np
4def get_color_map(num_colors=None):
5 """
6 DESCRIPTION:
7 getColorMap returns the default color map used for display and
8 visualisation across the k-Wave Toolbox. Zero values are displayed as
9 white, positive values are displayed as yellow through red to black,
10 and negative values are displayed as light to dark blue-greys. If no
11 value for num_colors is provided, cm will have 256 colors.
12 Args:
13 num_colors: number of colors in the color map (default is 256)
15 Returns:
16 cm: three column color map matrix which can be applied using colormap
17 """
18 if num_colors is None:
19 neg_pad = 48
20 num_colors = 256
21 else:
22 neg_pad = int(round(48 * num_colors / 256))
24 # define colour spectrums
25 neg = bone(num_colors // 2 + neg_pad)
26 neg = neg[neg_pad:, :]
27 pos = np.flipud(hot(num_colors // 2))
29 return np.vstack([neg, pos])
32def hot(m):
33 """
34 %HOT Red-yellow-white color map inspired by black body radiation
35 % HOT(M) returns an M-by-3 matrix containing a "hot" colormap.
36 % HOT, by itself, is the same length as the current figure's
37 % colormap. If no figure exists, MATLAB uses the length of the
38 % default colormap.
39 Args:
40 m:
42 Returns:
44 """
45 n = int(np.fix(3/8 * m))
47 r = np.concatenate([np.arange(1, n + 1) / n, np.ones(m-n)])
48 g = np.concatenate([np.zeros(n), np.arange(1, n + 1) / n, np.ones(m-2*n)])
49 b = np.concatenate([np.zeros(2*n), np.arange(1, m-2*n + 1)/(m-2*n)])
51 return np.hstack([r[:, None], g[:, None], b[:, None]])
54def bone(m):
55 return (7 * gray(m) + np.fliplr(hot(m))) / 8
58def gray(m):
59 g = np.arange(m) / max(m-1, 1)
60 g = g[:, None]
61 return np.hstack([g, g, g])