myokit 1.35.0__py3-none-any.whl → 1.35.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. myokit/__init__.py +11 -14
  2. myokit/__main__.py +0 -3
  3. myokit/_config.py +1 -3
  4. myokit/_datablock.py +914 -12
  5. myokit/_model_api.py +1 -3
  6. myokit/_myokit_version.py +1 -1
  7. myokit/_protocol.py +14 -28
  8. myokit/_sim/cable.c +1 -1
  9. myokit/_sim/cable.py +3 -2
  10. myokit/_sim/cmodel.h +1 -0
  11. myokit/_sim/cvodessim.c +79 -42
  12. myokit/_sim/cvodessim.py +20 -8
  13. myokit/_sim/fiber_tissue.c +1 -1
  14. myokit/_sim/fiber_tissue.py +3 -2
  15. myokit/_sim/openclsim.c +1 -1
  16. myokit/_sim/openclsim.py +8 -11
  17. myokit/_sim/pacing.h +121 -106
  18. myokit/_unit.py +1 -1
  19. myokit/formats/__init__.py +178 -0
  20. myokit/formats/axon/_abf.py +911 -841
  21. myokit/formats/axon/_atf.py +62 -59
  22. myokit/formats/axon/_importer.py +2 -2
  23. myokit/formats/heka/__init__.py +38 -0
  24. myokit/formats/heka/_importer.py +39 -0
  25. myokit/formats/heka/_patchmaster.py +2512 -0
  26. myokit/formats/wcp/_wcp.py +318 -133
  27. myokit/gui/datablock_viewer.py +144 -77
  28. myokit/gui/datalog_viewer.py +212 -231
  29. myokit/tests/ansic_event_based_pacing.py +3 -3
  30. myokit/tests/{ansic_fixed_form_pacing.py → ansic_time_series_pacing.py} +6 -6
  31. myokit/tests/data/formats/abf-v2.abf +0 -0
  32. myokit/tests/test_datablock.py +84 -0
  33. myokit/tests/test_datalog.py +2 -1
  34. myokit/tests/test_formats_axon.py +589 -136
  35. myokit/tests/test_formats_wcp.py +191 -22
  36. myokit/tests/test_pacing_system_c.py +51 -23
  37. myokit/tests/test_pacing_system_py.py +18 -0
  38. myokit/tests/test_simulation_1d.py +62 -22
  39. myokit/tests/test_simulation_cvodes.py +52 -3
  40. myokit/tests/test_simulation_fiber_tissue.py +35 -4
  41. myokit/tests/test_simulation_opencl.py +28 -4
  42. {myokit-1.35.0.dist-info → myokit-1.35.2.dist-info}/LICENSE.txt +1 -1
  43. {myokit-1.35.0.dist-info → myokit-1.35.2.dist-info}/METADATA +1 -1
  44. {myokit-1.35.0.dist-info → myokit-1.35.2.dist-info}/RECORD +47 -44
  45. {myokit-1.35.0.dist-info → myokit-1.35.2.dist-info}/WHEEL +0 -0
  46. {myokit-1.35.0.dist-info → myokit-1.35.2.dist-info}/entry_points.txt +0 -0
  47. {myokit-1.35.0.dist-info → myokit-1.35.2.dist-info}/top_level.txt +0 -0
myokit/_datablock.py CHANGED
@@ -1148,9 +1148,13 @@ class DataBlock2d:
1148
1148
  data = self._2d[name]
1149
1149
  # Get color map
1150
1150
  color_map = ColorMap.get(colormap)
1151
+
1151
1152
  # Get lower and upper bounds for colormap scaling
1152
1153
  lower = np.min(data) if lower is None else float(lower)
1153
1154
  upper = np.max(data) if upper is None else float(upper)
1155
+ if upper < lower: # pragma: no cover
1156
+ upper = lower
1157
+
1154
1158
  # Create images
1155
1159
  frames = []
1156
1160
  for frame in data:
@@ -1687,8 +1691,8 @@ class ColorMap:
1687
1691
  @staticmethod
1688
1692
  def hsv_to_rgb(h, s, v):
1689
1693
  """
1690
- Converts hsv values in the range [0,1] to rgb values in the range
1691
- [0,255]. Adapted from Matplotlib.
1694
+ Converts hsv values in the range [0, 1] to rgb values in the range
1695
+ [0, 255].
1692
1696
  """
1693
1697
  r, g, b = np.empty_like(h), np.empty_like(h), np.empty_like(h)
1694
1698
  i = (h * 6).astype(int) % 6
@@ -1756,9 +1760,8 @@ class ColorMap:
1756
1760
 
1757
1761
 
1758
1762
  class ColorMapBlue(ColorMap):
1759
- """
1760
- A nice red colormap.
1761
- """
1763
+ """ A plain white-to-blue colormap. """
1764
+
1762
1765
  def __call__(self, floats, lower=None, upper=None, alpha=True, rgb=None):
1763
1766
  # Normalize floats
1764
1767
  f = ColorMap.normalize(floats, lower, upper)
@@ -1781,10 +1784,27 @@ class ColorMapBlue(ColorMap):
1781
1784
  return out
1782
1785
 
1783
1786
 
1787
+ class ColorMapGray(ColorMap):
1788
+ """ A plain black-to-white colormap. """
1789
+
1790
+ def __call__(self, floats, lower=None, upper=None, alpha=True, rgb=None):
1791
+ # Normalize floats
1792
+ f = 255 * ColorMap.normalize(floats, lower, upper)
1793
+ # Offset for first color in (a)rgb or rgb(a)
1794
+ m = 1 if (alpha and rgb) else 0
1795
+ # Number of bytes per float
1796
+ n = 4 if alpha else 3
1797
+ # Create output
1798
+ out = 255 * np.ones(n * len(floats), dtype=np.uint8)
1799
+ out[m + 0::n] = f
1800
+ out[m + 1::n] = f
1801
+ out[m + 2::n] = f
1802
+ return out
1803
+
1804
+
1784
1805
  class ColorMapGreen(ColorMap):
1785
- """
1786
- A nice green colormap.
1787
- """
1806
+ """ A plain white-to-green colormap. """
1807
+
1788
1808
  def __call__(self, floats, lower=None, upper=None, alpha=True, rgb=None):
1789
1809
  # Normalize floats
1790
1810
  f = ColorMap.normalize(floats, lower, upper)
@@ -1808,9 +1828,8 @@ class ColorMapGreen(ColorMap):
1808
1828
 
1809
1829
 
1810
1830
  class ColorMapRed(ColorMap):
1811
- """
1812
- A nice red colormap.
1813
- """
1831
+ """ A plain white-to-red colormap. """
1832
+
1814
1833
  def __call__(self, floats, lower=None, upper=None, alpha=True, rgb=None):
1815
1834
  # Normalize floats
1816
1835
  f = ColorMap.normalize(floats, lower, upper)
@@ -1835,7 +1854,10 @@ class ColorMapRed(ColorMap):
1835
1854
 
1836
1855
  class ColorMapTraditional(ColorMap):
1837
1856
  """
1838
- Traditional hue-cycling colormap.
1857
+ A traditional hue-cycling colormap.
1858
+
1859
+ Probably best not to use in publications. See e.g.
1860
+ https://doi.org/10.1371/journal.pone.0199239
1839
1861
  """
1840
1862
  def __call__(self, floats, lower=None, upper=None, alpha=True, rgb=None):
1841
1863
  # Normalize floats
@@ -1859,6 +1881,886 @@ class ColorMapTraditional(ColorMap):
1859
1881
  return out
1860
1882
 
1861
1883
 
1884
+ class ColorMapCividis(ColorMap):
1885
+ """
1886
+ A colormap using "Cividis".
1887
+
1888
+ The values used by this color map are taken from supplement 3 in
1889
+ https://doi.org/10.1371/journal.pone.0199239, by Jamie R. Nuñez,
1890
+ Christopher R. Anderton, and Ryan S. Renslow.
1891
+ """
1892
+ _VALUES = np.array((
1893
+ (0, 32, 76),
1894
+ (0, 32, 78),
1895
+ (0, 33, 80),
1896
+ (0, 34, 81),
1897
+ (0, 35, 83),
1898
+ (0, 35, 85),
1899
+ (0, 36, 86),
1900
+ (0, 37, 88),
1901
+ (0, 38, 90),
1902
+ (0, 38, 91),
1903
+ (0, 39, 93),
1904
+ (0, 40, 95),
1905
+ (0, 40, 97),
1906
+ (0, 41, 99),
1907
+ (0, 42, 100),
1908
+ (0, 42, 102),
1909
+ (0, 43, 104),
1910
+ (0, 44, 106),
1911
+ (0, 45, 108),
1912
+ (0, 45, 109),
1913
+ (0, 46, 110),
1914
+ (0, 46, 111),
1915
+ (0, 47, 111),
1916
+ (0, 47, 111),
1917
+ (0, 48, 111),
1918
+ (0, 49, 111),
1919
+ (0, 49, 111),
1920
+ (0, 50, 110),
1921
+ (0, 51, 110),
1922
+ (0, 52, 110),
1923
+ (0, 52, 110),
1924
+ (1, 53, 110),
1925
+ (6, 54, 110),
1926
+ (10, 55, 109),
1927
+ (14, 55, 109),
1928
+ (18, 56, 109),
1929
+ (21, 57, 109),
1930
+ (23, 57, 109),
1931
+ (26, 58, 108),
1932
+ (28, 59, 108),
1933
+ (30, 60, 108),
1934
+ (32, 60, 108),
1935
+ (34, 61, 108),
1936
+ (36, 62, 108),
1937
+ (38, 62, 108),
1938
+ (39, 63, 108),
1939
+ (41, 64, 107),
1940
+ (43, 65, 107),
1941
+ (44, 65, 107),
1942
+ (46, 66, 107),
1943
+ (47, 67, 107),
1944
+ (49, 68, 107),
1945
+ (50, 68, 107),
1946
+ (51, 69, 107),
1947
+ (53, 70, 107),
1948
+ (54, 70, 107),
1949
+ (55, 71, 107),
1950
+ (56, 72, 107),
1951
+ (58, 73, 107),
1952
+ (59, 73, 107),
1953
+ (60, 74, 107),
1954
+ (61, 75, 107),
1955
+ (62, 75, 107),
1956
+ (64, 76, 107),
1957
+ (65, 77, 107),
1958
+ (66, 78, 107),
1959
+ (67, 78, 107),
1960
+ (68, 79, 107),
1961
+ (69, 80, 107),
1962
+ (70, 80, 107),
1963
+ (71, 81, 107),
1964
+ (72, 82, 107),
1965
+ (73, 83, 107),
1966
+ (74, 83, 107),
1967
+ (75, 84, 107),
1968
+ (76, 85, 107),
1969
+ (77, 85, 107),
1970
+ (78, 86, 107),
1971
+ (79, 87, 108),
1972
+ (80, 88, 108),
1973
+ (81, 88, 108),
1974
+ (82, 89, 108),
1975
+ (83, 90, 108),
1976
+ (84, 90, 108),
1977
+ (85, 91, 108),
1978
+ (86, 92, 108),
1979
+ (87, 93, 109),
1980
+ (88, 93, 109),
1981
+ (89, 94, 109),
1982
+ (90, 95, 109),
1983
+ (91, 95, 109),
1984
+ (92, 96, 109),
1985
+ (93, 97, 110),
1986
+ (94, 98, 110),
1987
+ (95, 98, 110),
1988
+ (95, 99, 110),
1989
+ (96, 100, 110),
1990
+ (97, 101, 111),
1991
+ (98, 101, 111),
1992
+ (99, 102, 111),
1993
+ (100, 103, 111),
1994
+ (101, 103, 111),
1995
+ (102, 104, 112),
1996
+ (103, 105, 112),
1997
+ (104, 106, 112),
1998
+ (104, 106, 112),
1999
+ (105, 107, 113),
2000
+ (106, 108, 113),
2001
+ (107, 109, 113),
2002
+ (108, 109, 114),
2003
+ (109, 110, 114),
2004
+ (110, 111, 114),
2005
+ (111, 111, 114),
2006
+ (111, 112, 115),
2007
+ (112, 113, 115),
2008
+ (113, 114, 115),
2009
+ (114, 114, 116),
2010
+ (115, 115, 116),
2011
+ (116, 116, 117),
2012
+ (117, 117, 117),
2013
+ (117, 117, 117),
2014
+ (118, 118, 118),
2015
+ (119, 119, 118),
2016
+ (120, 120, 118),
2017
+ (121, 120, 119),
2018
+ (122, 121, 119),
2019
+ (123, 122, 119),
2020
+ (123, 123, 120),
2021
+ (124, 123, 120),
2022
+ (125, 124, 120),
2023
+ (126, 125, 120),
2024
+ (127, 126, 120),
2025
+ (128, 126, 120),
2026
+ (129, 127, 120),
2027
+ (130, 128, 120),
2028
+ (131, 129, 120),
2029
+ (132, 129, 120),
2030
+ (133, 130, 120),
2031
+ (134, 131, 120),
2032
+ (135, 132, 120),
2033
+ (136, 133, 120),
2034
+ (137, 133, 120),
2035
+ (138, 134, 120),
2036
+ (139, 135, 120),
2037
+ (140, 136, 120),
2038
+ (141, 136, 120),
2039
+ (142, 137, 120),
2040
+ (143, 138, 120),
2041
+ (144, 139, 120),
2042
+ (145, 140, 120),
2043
+ (146, 140, 120),
2044
+ (147, 141, 120),
2045
+ (148, 142, 120),
2046
+ (149, 143, 120),
2047
+ (150, 143, 119),
2048
+ (151, 144, 119),
2049
+ (152, 145, 119),
2050
+ (153, 146, 119),
2051
+ (154, 147, 119),
2052
+ (155, 147, 119),
2053
+ (156, 148, 119),
2054
+ (157, 149, 119),
2055
+ (158, 150, 118),
2056
+ (159, 151, 118),
2057
+ (160, 152, 118),
2058
+ (161, 152, 118),
2059
+ (162, 153, 118),
2060
+ (163, 154, 117),
2061
+ (164, 155, 117),
2062
+ (165, 156, 117),
2063
+ (166, 156, 117),
2064
+ (167, 157, 117),
2065
+ (168, 158, 116),
2066
+ (169, 159, 116),
2067
+ (170, 160, 116),
2068
+ (171, 161, 116),
2069
+ (172, 161, 115),
2070
+ (173, 162, 115),
2071
+ (174, 163, 115),
2072
+ (175, 164, 115),
2073
+ (176, 165, 114),
2074
+ (177, 166, 114),
2075
+ (178, 166, 114),
2076
+ (180, 167, 113),
2077
+ (181, 168, 113),
2078
+ (182, 169, 113),
2079
+ (183, 170, 112),
2080
+ (184, 171, 112),
2081
+ (185, 171, 112),
2082
+ (186, 172, 111),
2083
+ (187, 173, 111),
2084
+ (188, 174, 110),
2085
+ (189, 175, 110),
2086
+ (190, 176, 110),
2087
+ (191, 177, 109),
2088
+ (192, 177, 109),
2089
+ (193, 178, 108),
2090
+ (194, 179, 108),
2091
+ (196, 180, 108),
2092
+ (197, 181, 107),
2093
+ (198, 182, 107),
2094
+ (199, 183, 106),
2095
+ (200, 184, 106),
2096
+ (201, 184, 105),
2097
+ (202, 185, 105),
2098
+ (203, 186, 104),
2099
+ (204, 187, 104),
2100
+ (205, 188, 103),
2101
+ (206, 189, 103),
2102
+ (207, 190, 102),
2103
+ (209, 191, 102),
2104
+ (210, 192, 101),
2105
+ (211, 192, 101),
2106
+ (212, 193, 100),
2107
+ (213, 194, 99),
2108
+ (214, 195, 99),
2109
+ (215, 196, 98),
2110
+ (216, 197, 98),
2111
+ (217, 198, 97),
2112
+ (219, 199, 96),
2113
+ (220, 200, 96),
2114
+ (221, 201, 95),
2115
+ (222, 202, 94),
2116
+ (223, 203, 93),
2117
+ (224, 203, 93),
2118
+ (225, 204, 92),
2119
+ (227, 205, 91),
2120
+ (228, 206, 91),
2121
+ (229, 207, 90),
2122
+ (230, 208, 89),
2123
+ (231, 209, 88),
2124
+ (232, 210, 87),
2125
+ (233, 211, 86),
2126
+ (235, 212, 86),
2127
+ (236, 213, 85),
2128
+ (237, 214, 84),
2129
+ (238, 215, 83),
2130
+ (239, 216, 82),
2131
+ (240, 217, 81),
2132
+ (242, 218, 80),
2133
+ (243, 219, 79),
2134
+ (244, 220, 78),
2135
+ (245, 221, 77),
2136
+ (246, 222, 76),
2137
+ (247, 223, 75),
2138
+ (249, 224, 73),
2139
+ (250, 224, 72),
2140
+ (251, 225, 71),
2141
+ (252, 226, 70),
2142
+ (253, 227, 69),
2143
+ (255, 228, 67),
2144
+ (255, 229, 66),
2145
+ (255, 230, 66),
2146
+ (255, 231, 67),
2147
+ (255, 232, 68),
2148
+ (255, 233, 69),
2149
+ ))
2150
+
2151
+ def __init__(self):
2152
+ self._n = len(self._VALUES)
2153
+
2154
+ def __call__(self, floats, lower=None, upper=None, alpha=True, rgb=None):
2155
+ # Normalize floats
2156
+ f = ColorMap.normalize(floats, lower, upper)
2157
+ # Get RGB
2158
+ val = self._VALUES[
2159
+ np.minimum(np.round(f * self._n).astype(int), self._n - 1)]
2160
+ # Color order
2161
+ rgb = (sys.byteorder == 'big') if rgb is None else rgb
2162
+ # Offset for first color in (a)rgb or rgb(a)
2163
+ m = 1 if (alpha and rgb) else 0
2164
+ # Number of bytes per float
2165
+ n = 4 if alpha else 3
2166
+ # Create output
2167
+ out = 255 * np.ones(n * len(floats), dtype=np.uint8)
2168
+ out[m + 0::n] = val[:, 0] if rgb else val[:, 2]
2169
+ out[m + 1::n] = val[:, 1]
2170
+ out[m + 2::n] = val[:, 2] if rgb else val[:, 0]
2171
+ return out
2172
+
2173
+
2174
+ class ColorMapViridis(ColorMap):
2175
+ """
2176
+ A colormap using "Viridis".
2177
+
2178
+ The values used by this color map are taken from
2179
+ https://github.com/BIDS/colormap/blob/master/colormaps.py
2180
+ and were distributed under a CC0 license.
2181
+
2182
+ Viridis was designed by Eric Firing, Nathaniel J. Smith, and Stefan van der
2183
+ Walt.
2184
+ """
2185
+ _VALUES = np.array((
2186
+ (68, 1, 84),
2187
+ (69, 2, 86),
2188
+ (69, 4, 87),
2189
+ (69, 5, 89),
2190
+ (70, 7, 90),
2191
+ (70, 8, 92),
2192
+ (70, 10, 93),
2193
+ (71, 11, 95),
2194
+ (71, 13, 96),
2195
+ (71, 14, 98),
2196
+ (71, 16, 99),
2197
+ (72, 17, 100),
2198
+ (72, 19, 102),
2199
+ (72, 20, 103),
2200
+ (72, 22, 104),
2201
+ (72, 23, 106),
2202
+ (72, 24, 107),
2203
+ (72, 26, 108),
2204
+ (72, 27, 109),
2205
+ (72, 28, 110),
2206
+ (72, 30, 112),
2207
+ (73, 31, 113),
2208
+ (72, 32, 114),
2209
+ (72, 34, 115),
2210
+ (72, 35, 116),
2211
+ (72, 36, 117),
2212
+ (72, 37, 118),
2213
+ (72, 39, 119),
2214
+ (72, 40, 120),
2215
+ (72, 41, 121),
2216
+ (72, 42, 122),
2217
+ (72, 44, 123),
2218
+ (71, 45, 124),
2219
+ (71, 46, 125),
2220
+ (71, 47, 125),
2221
+ (71, 49, 126),
2222
+ (70, 50, 127),
2223
+ (70, 51, 128),
2224
+ (70, 52, 128),
2225
+ (70, 54, 129),
2226
+ (69, 55, 130),
2227
+ (69, 56, 130),
2228
+ (69, 57, 131),
2229
+ (68, 58, 132),
2230
+ (68, 60, 132),
2231
+ (67, 61, 133),
2232
+ (67, 62, 133),
2233
+ (67, 63, 134),
2234
+ (66, 64, 134),
2235
+ (66, 66, 135),
2236
+ (65, 67, 135),
2237
+ (65, 68, 136),
2238
+ (65, 69, 136),
2239
+ (64, 70, 136),
2240
+ (64, 71, 137),
2241
+ (63, 73, 137),
2242
+ (63, 74, 138),
2243
+ (62, 75, 138),
2244
+ (62, 76, 138),
2245
+ (61, 77, 138),
2246
+ (61, 78, 139),
2247
+ (60, 79, 139),
2248
+ (60, 80, 139),
2249
+ (59, 81, 139),
2250
+ (59, 83, 140),
2251
+ (58, 84, 140),
2252
+ (58, 85, 140),
2253
+ (57, 86, 140),
2254
+ (57, 87, 140),
2255
+ (56, 88, 141),
2256
+ (56, 89, 141),
2257
+ (55, 90, 141),
2258
+ (55, 91, 141),
2259
+ (54, 92, 141),
2260
+ (54, 93, 141),
2261
+ (53, 94, 141),
2262
+ (53, 95, 142),
2263
+ (52, 96, 142),
2264
+ (52, 97, 142),
2265
+ (52, 98, 142),
2266
+ (51, 99, 142),
2267
+ (51, 100, 142),
2268
+ (50, 101, 142),
2269
+ (50, 102, 142),
2270
+ (49, 103, 142),
2271
+ (49, 104, 142),
2272
+ (48, 105, 142),
2273
+ (48, 106, 142),
2274
+ (48, 107, 143),
2275
+ (47, 108, 143),
2276
+ (47, 109, 143),
2277
+ (46, 110, 143),
2278
+ (46, 111, 143),
2279
+ (45, 112, 143),
2280
+ (45, 113, 143),
2281
+ (45, 114, 143),
2282
+ (44, 115, 143),
2283
+ (44, 116, 143),
2284
+ (43, 117, 143),
2285
+ (43, 118, 143),
2286
+ (43, 119, 143),
2287
+ (42, 120, 143),
2288
+ (42, 121, 143),
2289
+ (42, 122, 143),
2290
+ (41, 123, 143),
2291
+ (41, 123, 143),
2292
+ (40, 124, 143),
2293
+ (40, 125, 143),
2294
+ (40, 126, 143),
2295
+ (39, 127, 143),
2296
+ (39, 128, 143),
2297
+ (39, 129, 143),
2298
+ (38, 130, 143),
2299
+ (38, 131, 143),
2300
+ (37, 132, 143),
2301
+ (37, 133, 142),
2302
+ (37, 134, 142),
2303
+ (36, 135, 142),
2304
+ (36, 136, 142),
2305
+ (36, 137, 142),
2306
+ (35, 138, 142),
2307
+ (35, 139, 142),
2308
+ (35, 139, 142),
2309
+ (34, 140, 142),
2310
+ (34, 141, 142),
2311
+ (34, 142, 141),
2312
+ (33, 143, 141),
2313
+ (33, 144, 141),
2314
+ (33, 145, 141),
2315
+ (32, 146, 141),
2316
+ (32, 147, 141),
2317
+ (32, 148, 140),
2318
+ (32, 149, 140),
2319
+ (31, 150, 140),
2320
+ (31, 151, 140),
2321
+ (31, 152, 139),
2322
+ (31, 153, 139),
2323
+ (31, 154, 139),
2324
+ (31, 155, 139),
2325
+ (31, 156, 138),
2326
+ (31, 156, 138),
2327
+ (31, 157, 138),
2328
+ (31, 158, 137),
2329
+ (31, 159, 137),
2330
+ (31, 160, 137),
2331
+ (31, 161, 136),
2332
+ (31, 162, 136),
2333
+ (32, 163, 135),
2334
+ (32, 164, 135),
2335
+ (32, 165, 134),
2336
+ (33, 166, 134),
2337
+ (33, 167, 134),
2338
+ (34, 168, 133),
2339
+ (34, 169, 133),
2340
+ (35, 170, 132),
2341
+ (36, 170, 131),
2342
+ (37, 171, 131),
2343
+ (38, 172, 130),
2344
+ (38, 173, 130),
2345
+ (39, 174, 129),
2346
+ (40, 175, 128),
2347
+ (41, 176, 128),
2348
+ (43, 177, 127),
2349
+ (44, 178, 126),
2350
+ (45, 179, 126),
2351
+ (46, 180, 125),
2352
+ (48, 180, 124),
2353
+ (49, 181, 123),
2354
+ (50, 182, 123),
2355
+ (52, 183, 122),
2356
+ (53, 184, 121),
2357
+ (55, 185, 120),
2358
+ (56, 186, 119),
2359
+ (58, 187, 118),
2360
+ (60, 187, 118),
2361
+ (61, 188, 117),
2362
+ (63, 189, 116),
2363
+ (65, 190, 115),
2364
+ (67, 191, 114),
2365
+ (68, 192, 113),
2366
+ (70, 193, 112),
2367
+ (72, 193, 111),
2368
+ (74, 194, 110),
2369
+ (76, 195, 109),
2370
+ (78, 196, 108),
2371
+ (80, 197, 106),
2372
+ (82, 197, 105),
2373
+ (84, 198, 104),
2374
+ (86, 199, 103),
2375
+ (88, 200, 102),
2376
+ (90, 200, 101),
2377
+ (92, 201, 99),
2378
+ (95, 202, 98),
2379
+ (97, 203, 97),
2380
+ (99, 203, 95),
2381
+ (101, 204, 94),
2382
+ (103, 205, 93),
2383
+ (106, 206, 91),
2384
+ (108, 206, 90),
2385
+ (110, 207, 89),
2386
+ (113, 208, 87),
2387
+ (115, 208, 86),
2388
+ (117, 209, 84),
2389
+ (120, 210, 83),
2390
+ (122, 210, 81),
2391
+ (125, 211, 80),
2392
+ (127, 212, 78),
2393
+ (130, 212, 77),
2394
+ (132, 213, 75),
2395
+ (135, 213, 74),
2396
+ (137, 214, 72),
2397
+ (140, 215, 71),
2398
+ (142, 215, 69),
2399
+ (145, 216, 67),
2400
+ (147, 216, 66),
2401
+ (150, 217, 64),
2402
+ (153, 217, 62),
2403
+ (155, 218, 61),
2404
+ (158, 218, 59),
2405
+ (160, 219, 57),
2406
+ (163, 219, 55),
2407
+ (166, 220, 54),
2408
+ (168, 220, 52),
2409
+ (171, 221, 50),
2410
+ (174, 221, 49),
2411
+ (176, 222, 47),
2412
+ (179, 222, 45),
2413
+ (182, 222, 43),
2414
+ (184, 223, 42),
2415
+ (187, 223, 40),
2416
+ (190, 224, 38),
2417
+ (192, 224, 37),
2418
+ (195, 224, 35),
2419
+ (198, 225, 34),
2420
+ (201, 225, 32),
2421
+ (203, 225, 31),
2422
+ (206, 226, 29),
2423
+ (209, 226, 28),
2424
+ (211, 226, 27),
2425
+ (214, 227, 26),
2426
+ (216, 227, 26),
2427
+ (219, 227, 25),
2428
+ (222, 228, 25),
2429
+ (224, 228, 24),
2430
+ (227, 228, 24),
2431
+ (229, 229, 25),
2432
+ (232, 229, 25),
2433
+ (235, 229, 26),
2434
+ (237, 230, 27),
2435
+ (240, 230, 28),
2436
+ (242, 230, 29),
2437
+ (245, 231, 30),
2438
+ (247, 231, 32),
2439
+ (249, 231, 33),
2440
+ (252, 232, 35),
2441
+ (254, 232, 37),
2442
+ ))
2443
+
2444
+ def __init__(self):
2445
+ self._n = len(self._VALUES)
2446
+
2447
+ def __call__(self, floats, lower=None, upper=None, alpha=True, rgb=None):
2448
+ # Normalize floats
2449
+ f = ColorMap.normalize(floats, lower, upper)
2450
+ # Get RGB
2451
+ val = self._VALUES[
2452
+ np.minimum(np.round(f * self._n).astype(int), self._n - 1)]
2453
+ # Color order
2454
+ rgb = (sys.byteorder == 'big') if rgb is None else rgb
2455
+ # Offset for first color in (a)rgb or rgb(a)
2456
+ m = 1 if (alpha and rgb) else 0
2457
+ # Number of bytes per float
2458
+ n = 4 if alpha else 3
2459
+ # Create output
2460
+ out = 255 * np.ones(n * len(floats), dtype=np.uint8)
2461
+ out[m + 0::n] = val[:, 0] if rgb else val[:, 2]
2462
+ out[m + 1::n] = val[:, 1]
2463
+ out[m + 2::n] = val[:, 2] if rgb else val[:, 0]
2464
+ return out
2465
+
2466
+
2467
+ class ColorMapInferno(ColorMap):
2468
+ """
2469
+ A colormap using "Viridis".
2470
+
2471
+ The values used by this color map are taken from
2472
+ https://github.com/BIDS/colormap/blob/master/colormaps.py
2473
+ and were distributed under a CC0 license.
2474
+
2475
+ Viridis was designed by Eric Firing, Nathaniel J. Smith, and Stefan van der
2476
+ Walt.
2477
+ """
2478
+ _VALUES = np.array((
2479
+ (0, 0, 4),
2480
+ (1, 0, 5),
2481
+ (1, 1, 6),
2482
+ (1, 1, 8),
2483
+ (2, 1, 10),
2484
+ (2, 2, 12),
2485
+ (2, 2, 14),
2486
+ (3, 2, 16),
2487
+ (4, 3, 18),
2488
+ (4, 3, 21),
2489
+ (5, 4, 23),
2490
+ (6, 4, 25),
2491
+ (7, 5, 27),
2492
+ (8, 6, 29),
2493
+ (9, 6, 32),
2494
+ (10, 7, 34),
2495
+ (11, 7, 36),
2496
+ (12, 8, 38),
2497
+ (13, 8, 41),
2498
+ (14, 9, 43),
2499
+ (16, 9, 45),
2500
+ (17, 10, 48),
2501
+ (18, 10, 50),
2502
+ (20, 11, 53),
2503
+ (21, 11, 55),
2504
+ (22, 11, 58),
2505
+ (24, 12, 60),
2506
+ (25, 12, 62),
2507
+ (27, 12, 65),
2508
+ (28, 12, 67),
2509
+ (30, 12, 70),
2510
+ (31, 12, 72),
2511
+ (33, 12, 74),
2512
+ (35, 12, 77),
2513
+ (36, 12, 79),
2514
+ (38, 12, 81),
2515
+ (40, 11, 83),
2516
+ (42, 11, 85),
2517
+ (43, 11, 87),
2518
+ (45, 11, 89),
2519
+ (47, 10, 91),
2520
+ (49, 10, 93),
2521
+ (51, 10, 94),
2522
+ (52, 10, 96),
2523
+ (54, 9, 97),
2524
+ (56, 9, 98),
2525
+ (58, 9, 99),
2526
+ (59, 9, 100),
2527
+ (61, 9, 101),
2528
+ (63, 9, 102),
2529
+ (64, 10, 103),
2530
+ (66, 10, 104),
2531
+ (68, 10, 105),
2532
+ (69, 10, 105),
2533
+ (71, 11, 106),
2534
+ (73, 11, 107),
2535
+ (74, 12, 107),
2536
+ (76, 12, 108),
2537
+ (78, 13, 108),
2538
+ (79, 13, 108),
2539
+ (81, 14, 109),
2540
+ (83, 14, 109),
2541
+ (84, 15, 109),
2542
+ (86, 15, 110),
2543
+ (87, 16, 110),
2544
+ (89, 17, 110),
2545
+ (91, 17, 110),
2546
+ (92, 18, 110),
2547
+ (94, 18, 111),
2548
+ (95, 19, 111),
2549
+ (97, 20, 111),
2550
+ (99, 20, 111),
2551
+ (100, 21, 111),
2552
+ (102, 21, 111),
2553
+ (103, 22, 111),
2554
+ (105, 23, 111),
2555
+ (107, 23, 111),
2556
+ (108, 24, 111),
2557
+ (110, 24, 111),
2558
+ (111, 25, 111),
2559
+ (113, 25, 110),
2560
+ (115, 26, 110),
2561
+ (116, 27, 110),
2562
+ (118, 27, 110),
2563
+ (119, 28, 110),
2564
+ (121, 28, 110),
2565
+ (123, 29, 109),
2566
+ (124, 29, 109),
2567
+ (126, 30, 109),
2568
+ (127, 31, 109),
2569
+ (129, 31, 108),
2570
+ (130, 32, 108),
2571
+ (132, 32, 108),
2572
+ (134, 33, 107),
2573
+ (135, 33, 107),
2574
+ (137, 34, 107),
2575
+ (138, 34, 106),
2576
+ (140, 35, 106),
2577
+ (142, 36, 105),
2578
+ (143, 36, 105),
2579
+ (145, 37, 105),
2580
+ (146, 37, 104),
2581
+ (148, 38, 104),
2582
+ (150, 38, 103),
2583
+ (151, 39, 102),
2584
+ (153, 40, 102),
2585
+ (154, 40, 101),
2586
+ (156, 41, 101),
2587
+ (158, 41, 100),
2588
+ (159, 42, 100),
2589
+ (161, 43, 99),
2590
+ (162, 43, 98),
2591
+ (164, 44, 98),
2592
+ (165, 45, 97),
2593
+ (167, 45, 96),
2594
+ (169, 46, 95),
2595
+ (170, 46, 95),
2596
+ (172, 47, 94),
2597
+ (173, 48, 93),
2598
+ (175, 49, 92),
2599
+ (176, 49, 92),
2600
+ (178, 50, 91),
2601
+ (179, 51, 90),
2602
+ (181, 51, 89),
2603
+ (182, 52, 88),
2604
+ (184, 53, 87),
2605
+ (185, 54, 86),
2606
+ (187, 54, 85),
2607
+ (188, 55, 85),
2608
+ (190, 56, 84),
2609
+ (191, 57, 83),
2610
+ (193, 58, 82),
2611
+ (194, 59, 81),
2612
+ (196, 60, 80),
2613
+ (197, 60, 79),
2614
+ (198, 61, 78),
2615
+ (200, 62, 77),
2616
+ (201, 63, 76),
2617
+ (203, 64, 75),
2618
+ (204, 65, 74),
2619
+ (205, 66, 72),
2620
+ (207, 67, 71),
2621
+ (208, 68, 70),
2622
+ (209, 69, 69),
2623
+ (211, 70, 68),
2624
+ (212, 72, 67),
2625
+ (213, 73, 66),
2626
+ (214, 74, 65),
2627
+ (216, 75, 64),
2628
+ (217, 76, 62),
2629
+ (218, 77, 61),
2630
+ (219, 79, 60),
2631
+ (220, 80, 59),
2632
+ (221, 81, 58),
2633
+ (223, 82, 57),
2634
+ (224, 84, 56),
2635
+ (225, 85, 54),
2636
+ (226, 86, 53),
2637
+ (227, 88, 52),
2638
+ (228, 89, 51),
2639
+ (229, 90, 50),
2640
+ (230, 92, 48),
2641
+ (231, 93, 47),
2642
+ (232, 95, 46),
2643
+ (233, 96, 45),
2644
+ (234, 98, 43),
2645
+ (235, 99, 42),
2646
+ (235, 101, 41),
2647
+ (236, 102, 40),
2648
+ (237, 104, 38),
2649
+ (238, 105, 37),
2650
+ (239, 107, 36),
2651
+ (240, 109, 35),
2652
+ (240, 110, 33),
2653
+ (241, 112, 32),
2654
+ (242, 113, 31),
2655
+ (242, 115, 30),
2656
+ (243, 117, 28),
2657
+ (244, 118, 27),
2658
+ (244, 120, 26),
2659
+ (245, 122, 24),
2660
+ (246, 123, 23),
2661
+ (246, 125, 22),
2662
+ (247, 127, 20),
2663
+ (247, 129, 19),
2664
+ (248, 130, 18),
2665
+ (248, 132, 16),
2666
+ (249, 134, 15),
2667
+ (249, 136, 14),
2668
+ (249, 137, 12),
2669
+ (250, 139, 11),
2670
+ (250, 141, 10),
2671
+ (250, 143, 9),
2672
+ (251, 145, 8),
2673
+ (251, 146, 7),
2674
+ (251, 148, 7),
2675
+ (252, 150, 6),
2676
+ (252, 152, 6),
2677
+ (252, 154, 6),
2678
+ (252, 156, 6),
2679
+ (252, 158, 7),
2680
+ (253, 160, 7),
2681
+ (253, 161, 8),
2682
+ (253, 163, 9),
2683
+ (253, 165, 10),
2684
+ (253, 167, 12),
2685
+ (253, 169, 13),
2686
+ (253, 171, 15),
2687
+ (253, 173, 17),
2688
+ (253, 175, 19),
2689
+ (253, 177, 20),
2690
+ (253, 179, 22),
2691
+ (253, 181, 24),
2692
+ (252, 183, 27),
2693
+ (252, 185, 29),
2694
+ (252, 186, 31),
2695
+ (252, 188, 33),
2696
+ (252, 190, 35),
2697
+ (251, 192, 38),
2698
+ (251, 194, 40),
2699
+ (251, 196, 43),
2700
+ (251, 198, 45),
2701
+ (250, 200, 48),
2702
+ (250, 202, 50),
2703
+ (250, 204, 53),
2704
+ (249, 206, 56),
2705
+ (249, 208, 58),
2706
+ (248, 210, 61),
2707
+ (248, 212, 64),
2708
+ (247, 214, 67),
2709
+ (247, 216, 70),
2710
+ (246, 218, 73),
2711
+ (246, 220, 76),
2712
+ (245, 222, 80),
2713
+ (245, 224, 83),
2714
+ (244, 226, 86),
2715
+ (244, 228, 90),
2716
+ (244, 229, 94),
2717
+ (243, 231, 97),
2718
+ (243, 233, 101),
2719
+ (243, 235, 105),
2720
+ (242, 237, 109),
2721
+ (242, 238, 113),
2722
+ (242, 240, 117),
2723
+ (242, 241, 122),
2724
+ (243, 243, 126),
2725
+ (243, 244, 130),
2726
+ (244, 246, 134),
2727
+ (244, 247, 138),
2728
+ (245, 249, 142),
2729
+ (246, 250, 146),
2730
+ (247, 251, 150),
2731
+ (249, 252, 154),
2732
+ (250, 253, 158),
2733
+ (251, 254, 162),
2734
+ (253, 255, 165),
2735
+ ))
2736
+
2737
+ def __init__(self):
2738
+ self._n = len(self._VALUES)
2739
+
2740
+ def __call__(self, floats, lower=None, upper=None, alpha=True, rgb=None):
2741
+ # Normalize floats
2742
+ f = ColorMap.normalize(floats, lower, upper)
2743
+ # Get RGB
2744
+ val = self._VALUES[
2745
+ np.minimum(np.round(f * self._n).astype(int), self._n - 1)]
2746
+ # Color order
2747
+ rgb = (sys.byteorder == 'big') if rgb is None else rgb
2748
+ # Offset for first color in (a)rgb or rgb(a)
2749
+ m = 1 if (alpha and rgb) else 0
2750
+ # Number of bytes per float
2751
+ n = 4 if alpha else 3
2752
+ # Create output
2753
+ out = 255 * np.ones(n * len(floats), dtype=np.uint8)
2754
+ out[m + 0::n] = val[:, 0] if rgb else val[:, 2]
2755
+ out[m + 1::n] = val[:, 1]
2756
+ out[m + 2::n] = val[:, 2] if rgb else val[:, 0]
2757
+ return out
2758
+
2759
+
2760
+ ColorMap._colormaps['cividis'] = ColorMapCividis
2761
+ ColorMap._colormaps['inferno'] = ColorMapInferno
2762
+ ColorMap._colormaps['viridis'] = ColorMapViridis
2763
+ ColorMap._colormaps['gray'] = ColorMapGray
1862
2764
  ColorMap._colormaps['blue'] = ColorMapBlue
1863
2765
  ColorMap._colormaps['green'] = ColorMapGreen
1864
2766
  ColorMap._colormaps['red'] = ColorMapRed