from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0.0000208612, 0.0000200049, 0.0000198463],
[0.00031118, 0.00036704, 0.000345557],
[0.000848739, 0.0010675, 0.000993082],
[0.00158242, 0.00208883, 0.00192971],
[0.00248168, 0.00341632, 0.00314156],
[0.00352421, 0.00504149, 0.00462195],
[0.00469227, 0.00695897, 0.00636811],
[0.00597097, 0.00916525, 0.00837981],
[0.00734746, 0.011658, 0.0106586],
[0.00881042, 0.0144356, 0.0132075],
[0.0103497, 0.0174973, 0.0160306],
[0.011956, 0.0208423, 0.0191328],
[0.0136211, 0.0244705, 0.0225201],
[0.0153372, 0.0283819, 0.0261989],
[0.0170973, 0.0325766, 0.0301766],
[0.018895, 0.0370549, 0.0344608],
[0.0207241, 0.0417811, 0.03906],
[0.0225792, 0.0464865, 0.0438391],
[0.0244554, 0.0511465, 0.0485992],
[0.0263479, 0.0557644, 0.0533542],
[0.0282527, 0.060343, 0.0581081],
[0.0301659, 0.0648851, 0.0628643],
[0.0320844, 0.0693929, 0.0676261],
[0.034005, 0.0738682, 0.0723963],
[0.0359253, 0.0783128, 0.0771774],
[0.0378432, 0.0827283, 0.0819718],
[0.0397569, 0.087116, 0.0867816],
[0.0416344, 0.0914771, 0.0916087],
[0.0434484, 0.0958125, 0.0964548],
[0.0452104, 0.100123, 0.101322],
[0.0469239, 0.10441, 0.10621],
[0.0485921, 0.108674, 0.111123],
[0.0502184, 0.112916, 0.116059],
[0.0518063, 0.117135, 0.121021],
[0.0533593, 0.121333, 0.12601],
[0.0548809, 0.12551, 0.131026],
[0.0563748, 0.129667, 0.13607],
[0.0578445, 0.133803, 0.141143],
[0.0592938, 0.137919, 0.146246],
[0.0607267, 0.142015, 0.151377],
[0.0621469, 0.146092, 0.15654],
[0.0635586, 0.150149, 0.161732],
[0.0649657, 0.154187, 0.166956],
[0.0663724, 0.158205, 0.17221],
[0.0677829, 0.162204, 0.177495],
[0.0692015, 0.166184, 0.182812],
[0.0706325, 0.170145, 0.188159],
[0.0720804, 0.174086, 0.193537],
[0.0735493, 0.178009, 0.198946],
[0.0750439, 0.181912, 0.204386],
[0.0765684, 0.185795, 0.209856],
[0.0781273, 0.189659, 0.215355],
[0.079725, 0.193504, 0.220885],
[0.0813656, 0.197329, 0.226443],
[0.0830534, 0.201135, 0.23203],
[0.0847926, 0.20492, 0.237645],
[0.0865871, 0.208686, 0.243287],
[0.0884409, 0.212432, 0.248955],
[0.0903577, 0.216158, 0.25465],
[0.0923409, 0.219863, 0.26037],
[0.094394, 0.223548, 0.266114],
[0.0965202, 0.227213, 0.271882],
[0.0987224, 0.230857, 0.277672],
[0.101003, 0.234481, 0.283483],
[0.103365, 0.238084, 0.289315],
[0.105811, 0.241666, 0.295166],
[0.108342, 0.245227, 0.301036],
[0.11096, 0.248767, 0.306922],
[0.113667, 0.252286, 0.312825],
[0.116464, 0.255784, 0.318742],
[0.119352, 0.259261, 0.324673],
[0.122332, 0.262717, 0.330615],
[0.125404, 0.266151, 0.336568],
[0.128569, 0.269564, 0.34253],
[0.131826, 0.272956, 0.348501],
[0.135176, 0.276327, 0.354477],
[0.138618, 0.279677, 0.360458],
[0.142152, 0.283005, 0.366443],
[0.145777, 0.286313, 0.372429],
[0.149493, 0.289599, 0.378416],
[0.153298, 0.292865, 0.384401],
[0.157192, 0.29611, 0.390383],
[0.161172, 0.299335, 0.39636],
[0.165239, 0.302539, 0.402331],
[0.16939, 0.305723, 0.408294],
[0.173624, 0.308887, 0.414247],
[0.17794, 0.312031, 0.420189],
[0.182335, 0.315155, 0.426117],
[0.186808, 0.318261, 0.43203],
[0.191358, 0.321347, 0.437927],
[0.195983, 0.324415, 0.443806],
[0.20068, 0.327464, 0.449664],
[0.205449, 0.330496, 0.4555],
[0.210286, 0.33351, 0.461313],
[0.215191, 0.336506, 0.467101],
[0.220161, 0.339487, 0.472861],
[0.225195, 0.34245, 0.478593],
[0.23029, 0.345398, 0.484294],
[0.235445, 0.348331, 0.489963],
[0.240657, 0.351249, 0.495599],
[0.245926, 0.354152, 0.501199],
[0.251248, 0.357042, 0.506761],
[0.256622, 0.359918, 0.512286],
[0.262047, 0.362782, 0.51777],
[0.26752, 0.365634, 0.523212],
[0.273039, 0.368475, 0.528612],
[0.278603, 0.371305, 0.533966],
[0.284209, 0.374125, 0.539274],
[0.289857, 0.376935, 0.544535],
[0.295544, 0.379737, 0.549747],
[0.301268, 0.382531, 0.554909],
[0.307028, 0.385318, 0.560019],
[0.312822, 0.388098, 0.565077],
[0.318648, 0.390872, 0.570081],
[0.324504, 0.393642, 0.57503],
[0.330389, 0.396407, 0.579922],
[0.336302, 0.399169, 0.584758],
[0.34224, 0.401928, 0.589535],
[0.348203, 0.404685, 0.594254],
[0.354187, 0.407441, 0.598913],
[0.360193, 0.410197, 0.603511],
[0.366218, 0.412954, 0.608047],
[0.37226, 0.415712, 0.612522],
[0.378319, 0.418472, 0.616933],
[0.384393, 0.421235, 0.621282],
[0.39048, 0.424002, 0.625566],
[0.39658, 0.426774, 0.629787],
[0.40269, 0.429551, 0.633942],
[0.408809, 0.432334, 0.638033],
[0.414936, 0.435125, 0.642058],
[0.421069, 0.437923, 0.646018],
[0.427208, 0.440731, 0.649913],
[0.433351, 0.443548, 0.653742],
[0.439497, 0.446375, 0.657505],
[0.445644, 0.449213, 0.661203],
[0.451791, 0.452064, 0.664835],
[0.457938, 0.454927, 0.668402],
[0.464082, 0.457803, 0.671904],
[0.470223, 0.460694, 0.675341],
[0.47636, 0.4636, 0.678714],
[0.482491, 0.466522, 0.682023],
[0.488616, 0.46946, 0.685268],
[0.494733, 0.472415, 0.688451],
[0.500842, 0.475389, 0.691571],
[0.50694, 0.478381, 0.69463],
[0.513029, 0.481392, 0.697628],
[0.519105, 0.484423, 0.700566],
[0.525169, 0.487474, 0.703444],
[0.53122, 0.490547, 0.706264],
[0.537256, 0.493642, 0.709027],
[0.543276, 0.496759, 0.711733],
[0.549281, 0.4999, 0.714383],
[0.555268, 0.503064, 0.716979],
[0.561238, 0.506252, 0.719522],
[0.567188, 0.509465, 0.722013],
[0.573119, 0.512703, 0.724452],
[0.57903, 0.515968, 0.726842],
[0.58492, 0.519258, 0.729184],
[0.590788, 0.522575, 0.731479],
[0.596633, 0.52592, 0.733728],
[0.602455, 0.529292, 0.735932],
[0.608254, 0.532693, 0.738094],
[0.614027, 0.536122, 0.740215],
[0.619775, 0.53958, 0.742295],
[0.625498, 0.543068, 0.744337],
[0.631193, 0.546585, 0.746343],
[0.636862, 0.550133, 0.748313],
[0.642503, 0.553711, 0.75025],
[0.648115, 0.55732, 0.752155],
[0.653699, 0.56096, 0.75403],
[0.659253, 0.564632, 0.755876],
[0.664777, 0.568336, 0.757695],
[0.670271, 0.572071, 0.759489],
[0.675734, 0.575839, 0.76126],
[0.681166, 0.579639, 0.763009],
[0.686565, 0.583473, 0.764738],
[0.691932, 0.587339, 0.766449],
[0.697267, 0.591239, 0.768144],
[0.702568, 0.595172, 0.769824],
[0.707836, 0.599138, 0.771492],
[0.71307, 0.603138, 0.773148],
[0.718269, 0.607173, 0.774796],
[0.723434, 0.611241, 0.776437],
[0.728564, 0.615344, 0.778072],
[0.733659, 0.61948, 0.779704],
[0.738718, 0.623652, 0.781334],
[0.743741, 0.627857, 0.782965],
[0.748728, 0.632098, 0.784598],
[0.753679, 0.636373, 0.786234],
[0.758593, 0.640682, 0.787877],
[0.76347, 0.645027, 0.789527],
[0.768311, 0.649406, 0.791186],
[0.773114, 0.65382, 0.792857],
[0.777879, 0.658269, 0.794541],
[0.782608, 0.662752, 0.79624],
[0.787298, 0.66727, 0.797956],
[0.791951, 0.671823, 0.799691],
[0.796566, 0.676411, 0.801446],
[0.801143, 0.681033, 0.803224],
[0.805682, 0.68569, 0.805025],
[0.810183, 0.690382, 0.806853],
[0.814646, 0.695108, 0.808708],
[0.819071, 0.699868, 0.810592],
[0.823458, 0.704662, 0.812508],
[0.827808, 0.709491, 0.814456],
[0.832119, 0.714353, 0.816439],
[0.836393, 0.719249, 0.818458],
[0.840629, 0.724179, 0.820516],
[0.844828, 0.729143, 0.822612],
[0.84899, 0.73414, 0.824751],
[0.853114, 0.73917, 0.826932],
[0.857202, 0.744233, 0.829157],
[0.861253, 0.749328, 0.831429],
[0.865268, 0.754457, 0.833749],
[0.869247, 0.759617, 0.836117],
[0.87319, 0.76481, 0.838537],
[0.877098, 0.770035, 0.841008],
[0.880971, 0.775291, 0.843534],
[0.88481, 0.780578, 0.846115],
[0.888615, 0.785897, 0.848752],
[0.892386, 0.791246, 0.851447],
[0.896125, 0.796626, 0.854202],
[0.899831, 0.802035, 0.857018],
[0.903505, 0.807475, 0.859895],
[0.907149, 0.812944, 0.862836],
[0.910762, 0.818442, 0.865842],
[0.914346, 0.823969, 0.868913],
[0.917902, 0.829524, 0.872052],
[0.921429, 0.835107, 0.875259],
[0.92493, 0.840717, 0.878535],
[0.928404, 0.846355, 0.881881],
[0.931854, 0.852019, 0.885299],
[0.93528, 0.85771, 0.888789],
[0.938684, 0.863426, 0.892353],
[0.942066, 0.869168, 0.895991],
[0.945429, 0.874934, 0.899704],
[0.948773, 0.880724, 0.903493],
[0.9521, 0.886538, 0.907359],
[0.955411, 0.892375, 0.911302],
[0.958709, 0.898234, 0.915324],
[0.961996, 0.904114, 0.919424],
[0.965273, 0.910016, 0.923604],
[0.968543, 0.915938, 0.927864],
[0.971807, 0.921878, 0.932203],
[0.97507, 0.927837, 0.936623],
[0.978334, 0.933814, 0.941124],
[0.981602, 0.939806, 0.945706],
[0.984878, 0.945813, 0.950369],
[0.988167, 0.951834, 0.955113],
[0.991474, 0.957865, 0.959938],
[0.994807, 0.963906, 0.964842],
[0.998174, 0.969951, 0.969827],
[1., 0.975998, 0.97489],
[1., 0.982039, 0.98003],
[1., 0.988059, 0.985245],
[1., 0.994001, 0.990529]]

test_cm = LinearSegmentedColormap.from_list(__file__, cm_data)


if __name__ == "__main__":
    import matplotlib.pyplot as plt
    import numpy as np

    try:
        from pycam02ucs.cm.viscm import viscm
        viscm(test_cm)
    except ImportError:
        print("pycam02ucs not found, falling back on simple display")
        plt.imshow(np.linspace(0, 100, 256)[None, :], aspect='auto',
                   cmap=test_cm)
    plt.show()
