from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0.0000208612, 0.0000200049, 0.0000198463],
[0.000416818, 0.000332934, 0.000276231],
[0.00123547, 0.000942769, 0.000738989],
[0.00244633, 0.00181075, 0.00135835],
[0.00403612, 0.00291717, 0.00210444],
[0.00599681, 0.00424959, 0.00295557],
[0.0083226, 0.00579953, 0.00389471],
[0.0110088, 0.007561, 0.00490782],
[0.0140512, 0.00952973, 0.00598298],
[0.0174459, 0.0117028, 0.00710993],
[0.021189, 0.0140781, 0.00827965],
[0.0252763, 0.0166546, 0.00948423],
[0.0297038, 0.0194317, 0.0107166],
[0.0344669, 0.0224097, 0.0119706],
[0.0395611, 0.0255889, 0.0132406],
[0.0447677, 0.0289706, 0.0145216],
[0.0498881, 0.032556, 0.0158092],
[0.0549352, 0.036347, 0.0170996],
[0.059912, 0.0403458, 0.0183893],
[0.0648211, 0.0443723, 0.0196753],
[0.0696645, 0.0483684, 0.020955],
[0.0744439, 0.0523393, 0.0222263],
[0.0791608, 0.0562885, 0.0234871],
[0.0838165, 0.0602188, 0.0247361],
[0.088412, 0.0641331, 0.025972],
[0.092948, 0.0680337, 0.0271938],
[0.0974252, 0.0719231, 0.0284011],
[0.101844, 0.0758033, 0.0295933],
[0.106205, 0.0796763, 0.0307705],
[0.110509, 0.0835438, 0.0319328],
[0.114756, 0.0874076, 0.0330806],
[0.118945, 0.0912691, 0.0342145],
[0.123077, 0.0951298, 0.0353355],
[0.127152, 0.0989911, 0.0364446],
[0.131171, 0.102854, 0.0375431],
[0.135132, 0.10672, 0.0386325],
[0.139035, 0.11059, 0.0397145],
[0.142882, 0.114465, 0.0407845],
[0.14667, 0.118346, 0.0418267],
[0.150401, 0.122233, 0.0428523],
[0.154074, 0.126128, 0.0438645],
[0.157688, 0.130032, 0.0448661],
[0.161244, 0.133944, 0.0458603],
[0.164741, 0.137866, 0.04685],
[0.168178, 0.141799, 0.0478381],
[0.171556, 0.145742, 0.0488278],
[0.174874, 0.149696, 0.0498221],
[0.178132, 0.153662, 0.050824],
[0.181329, 0.15764, 0.0518365],
[0.184465, 0.161631, 0.0528627],
[0.187539, 0.165634, 0.0539056],
[0.190552, 0.16965, 0.0549683],
[0.193503, 0.17368, 0.0560538],
[0.196391, 0.177724, 0.0571652],
[0.199217, 0.181781, 0.0583054],
[0.201979, 0.185852, 0.0594774],
[0.204678, 0.189937, 0.0606842],
[0.207313, 0.194037, 0.0619287],
[0.209884, 0.19815, 0.0632137],
[0.212391, 0.202278, 0.0645421],
[0.214833, 0.20642, 0.0659166],
[0.21721, 0.210577, 0.0673399],
[0.219522, 0.214747, 0.0688147],
[0.221768, 0.218932, 0.0703435],
[0.223949, 0.223131, 0.0719288],
[0.226064, 0.227344, 0.0735728],
[0.228112, 0.231571, 0.075278],
[0.230095, 0.235811, 0.0770465],
[0.232011, 0.240065, 0.0788803],
[0.233861, 0.244332, 0.0807814],
[0.235645, 0.248613, 0.0827517],
[0.237362, 0.252906, 0.0847929],
[0.239013, 0.257211, 0.0869067],
[0.240598, 0.261529, 0.0890944],
[0.242116, 0.265859, 0.0913577],
[0.243568, 0.270201, 0.0936976],
[0.244955, 0.274554, 0.0961154],
[0.246275, 0.278918, 0.0986122],
[0.247531, 0.283292, 0.101189],
[0.248721, 0.287677, 0.103846],
[0.249847, 0.292071, 0.106585],
[0.250909, 0.296475, 0.109406],
[0.251907, 0.300888, 0.112309],
[0.252842, 0.305309, 0.115296],
[0.253715, 0.309738, 0.118366],
[0.254527, 0.314175, 0.121519],
[0.255278, 0.318619, 0.124757],
[0.255969, 0.32307, 0.128078],
[0.256601, 0.327526, 0.131483],
[0.257176, 0.331988, 0.134972],
[0.257695, 0.336455, 0.138545],
[0.258158, 0.340927, 0.142202],
[0.258568, 0.345402, 0.145942],
[0.258926, 0.349881, 0.149764],
[0.259233, 0.354362, 0.15367],
[0.259492, 0.358846, 0.157658],
[0.259704, 0.363331, 0.161727],
[0.259872, 0.367817, 0.165878],
[0.259996, 0.372304, 0.170109],
[0.260081, 0.37679, 0.17442],
[0.260128, 0.381275, 0.178811],
[0.26014, 0.385759, 0.18328],
[0.260119, 0.390241, 0.187827],
[0.26007, 0.394721, 0.192451],
[0.259994, 0.399196, 0.197151],
[0.259895, 0.403668, 0.201927],
[0.259777, 0.408136, 0.206776],
[0.259642, 0.412598, 0.211699],
[0.259497, 0.417055, 0.216695],
[0.259343, 0.421505, 0.221761],
[0.259185, 0.425948, 0.226898],
[0.259028, 0.430383, 0.232103],
[0.258877, 0.43481, 0.237377],
[0.258735, 0.439228, 0.242717],
[0.258608, 0.443637, 0.248122],
[0.258502, 0.448036, 0.253591],
[0.25842, 0.452424, 0.259123],
[0.258369, 0.456801, 0.264716],
[0.258355, 0.461166, 0.270369],
[0.258382, 0.465519, 0.276081],
[0.258458, 0.46986, 0.281849],
[0.258586, 0.474186, 0.287673],
[0.258775, 0.478499, 0.29355],
[0.259029, 0.482798, 0.29948],
[0.259355, 0.487081, 0.30546],
[0.259759, 0.49135, 0.311489],
[0.260247, 0.495602, 0.317565],
[0.260824, 0.499839, 0.323686],
[0.261498, 0.504059, 0.329851],
[0.262273, 0.508261, 0.336058],
[0.263155, 0.512447, 0.342305],
[0.264151, 0.516614, 0.348591],
[0.265265, 0.520764, 0.354912],
[0.266502, 0.524895, 0.361268],
[0.267867, 0.529007, 0.367657],
[0.269365, 0.533101, 0.374076],
[0.270999, 0.537175, 0.380523],
[0.272775, 0.54123, 0.386997],
[0.274694, 0.545265, 0.393496],
[0.276761, 0.54928, 0.400018],
[0.278978, 0.553276, 0.40656],
[0.281347, 0.557251, 0.41312],
[0.28387, 0.561206, 0.419697],
[0.286548, 0.565141, 0.426289],
[0.289383, 0.569056, 0.432893],
[0.292374, 0.572951, 0.439507],
[0.295523, 0.576825, 0.44613],
[0.298829, 0.580679, 0.452759],
[0.302291, 0.584513, 0.459393],
[0.305908, 0.588327, 0.466028],
[0.309679, 0.592121, 0.472664],
[0.313602, 0.595895, 0.479298],
[0.317675, 0.599649, 0.485928],
[0.321896, 0.603385, 0.492553],
[0.326262, 0.607101, 0.49917],
[0.330771, 0.610798, 0.505777],
[0.335419, 0.614477, 0.512373],
[0.340204, 0.618138, 0.518955],
[0.345121, 0.621781, 0.525522],
[0.350168, 0.625406, 0.532072],
[0.355341, 0.629014, 0.538603],
[0.360636, 0.632605, 0.545113],
[0.366049, 0.636181, 0.551602],
[0.371577, 0.63974, 0.558066],
[0.377216, 0.643284, 0.564504],
[0.382961, 0.646814, 0.570915],
[0.388809, 0.650329, 0.577297],
[0.394756, 0.653831, 0.583649],
[0.400799, 0.657319, 0.589969],
[0.406932, 0.660796, 0.596256],
[0.413153, 0.66426, 0.602508],
[0.419458, 0.667713, 0.608724],
[0.425843, 0.671156, 0.614904],
[0.432304, 0.674589, 0.621044],
[0.438838, 0.678013, 0.627146],
[0.445441, 0.681428, 0.633206],
[0.45211, 0.684836, 0.639225],
[0.458841, 0.688236, 0.645202],
[0.465632, 0.691631, 0.651134],
[0.472478, 0.69502, 0.657023],
[0.479377, 0.698404, 0.662866],
[0.486326, 0.701785, 0.668663],
[0.493322, 0.705162, 0.674413],
[0.500361, 0.708537, 0.680116],
[0.507441, 0.711911, 0.685772],
[0.51456, 0.715284, 0.691379],
[0.521714, 0.718657, 0.696937],
[0.528901, 0.722031, 0.702445],
[0.536119, 0.725406, 0.707905],
[0.543365, 0.728785, 0.713314],
[0.550637, 0.732166, 0.718674],
[0.557933, 0.735552, 0.723983],
[0.56525, 0.738944, 0.729243],
[0.572586, 0.742341, 0.734451],
[0.579939, 0.745744, 0.73961],
[0.587308, 0.749156, 0.744719],
[0.59469, 0.752575, 0.749777],
[0.602084, 0.756004, 0.754786],
[0.609487, 0.759443, 0.759745],
[0.616899, 0.762893, 0.764655],
[0.624316, 0.766354, 0.769516],
[0.631739, 0.769828, 0.774329],
[0.639165, 0.773315, 0.779094],
[0.646593, 0.776816, 0.783811],
[0.654021, 0.780332, 0.788481],
[0.661448, 0.783863, 0.793105],
[0.668873, 0.787411, 0.797683],
[0.676295, 0.790975, 0.802216],
[0.683712, 0.794558, 0.806705],
[0.691123, 0.798158, 0.811151],
[0.698527, 0.801778, 0.815553],
[0.705923, 0.805418, 0.819915],
[0.713309, 0.809079, 0.824235],
[0.720686, 0.812761, 0.828515],
[0.728052, 0.816464, 0.832757],
[0.735406, 0.820191, 0.83696],
[0.742747, 0.82394, 0.841127],
[0.750074, 0.827714, 0.845258],
[0.757388, 0.831512, 0.849355],
[0.764686, 0.835335, 0.853418],
[0.771968, 0.839184, 0.857448],
[0.779234, 0.843059, 0.861448],
[0.786482, 0.846961, 0.865418],
[0.793713, 0.85089, 0.869359],
[0.800925, 0.854848, 0.873273],
[0.808119, 0.858834, 0.877162],
[0.815292, 0.862849, 0.881026],
[0.822446, 0.866893, 0.884867],
[0.829579, 0.870968, 0.888686],
[0.836692, 0.875073, 0.892485],
[0.843783, 0.879209, 0.896265],
[0.850852, 0.883377, 0.900029],
[0.857898, 0.887576, 0.903776],
[0.864922, 0.891808, 0.90751],
[0.871923, 0.896073, 0.911231],
[0.8789, 0.900371, 0.914941],
[0.885854, 0.904702, 0.918643],
[0.892783, 0.909068, 0.922337],
[0.899688, 0.913468, 0.926025],
[0.906567, 0.917902, 0.92971],
[0.913421, 0.922373, 0.933394],
[0.92025, 0.926878, 0.937077],
[0.927052, 0.93142, 0.940763],
[0.933827, 0.935998, 0.944454],
[0.940575, 0.940613, 0.948151],
[0.947294, 0.945265, 0.951858],
[0.953985, 0.949955, 0.955578],
[0.960647, 0.954683, 0.959313],
[0.967277, 0.959449, 0.963066],
[0.973875, 0.964255, 0.966843],
[0.980439, 0.969101, 0.970648],
[0.986965, 0.973987, 0.974486],
[0.993449, 0.978916, 0.978368],
[0.999884, 0.983889, 0.982306],
[1., 0.988911, 0.986326],
[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()
