from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0.0000208612, 0.0000200049, 0.0000198463],
[0.000319677, 0.000366922, 0.000314833],
[0.000879454, 0.0010672, 0.000880754],
[0.0016498, 0.00208867, 0.00167853],
[0.00260034, 0.00341713, 0.00268861],
[0.00370851, 0.00504473, 0.00389925],
[0.00495592, 0.00696682, 0.00530302],
[0.00632677, 0.00918069, 0.00689533],
[0.00780704, 0.0116849, 0.00867356],
[0.00938396, 0.0144788, 0.0106366],
[0.0110458, 0.0175626, 0.0127847],
[0.0127814, 0.0209368, 0.0151189],
[0.0145805, 0.0246023, 0.0176413],
[0.0164332, 0.0285603, 0.0203547],
[0.0183301, 0.0328122, 0.0232626],
[0.0202622, 0.0373598, 0.026369],
[0.0222209, 0.0421539, 0.0296786],
[0.0241978, 0.0469229, 0.0331967],
[0.026185, 0.0516523, 0.036929],
[0.0281747, 0.0563456, 0.0408732],
[0.0301596, 0.0610058, 0.0448418],
[0.0321325, 0.0656356, 0.048806],
[0.0340866, 0.0702374, 0.0527697],
[0.0360153, 0.0748131, 0.0567364],
[0.0379124, 0.0793648, 0.0607092],
[0.0397718, 0.083894, 0.0646911],
[0.0415596, 0.088402, 0.0686849],
[0.0432484, 0.0928903, 0.072693],
[0.0448478, 0.09736, 0.0767178],
[0.0463589, 0.101812, 0.0807615],
[0.047783, 0.106247, 0.084826],
[0.0491212, 0.110667, 0.0889132],
[0.0503746, 0.115071, 0.0930249],
[0.0515443, 0.119461, 0.0971627],
[0.0526313, 0.123836, 0.101328],
[0.0536367, 0.128198, 0.105523],
[0.0545615, 0.132547, 0.109747],
[0.0554069, 0.136883, 0.114004],
[0.0561739, 0.141206, 0.118293],
[0.0568638, 0.145518, 0.122615],
[0.0574777, 0.149817, 0.126973],
[0.0580171, 0.154105, 0.131366],
[0.0584833, 0.15838, 0.135795],
[0.0588778, 0.162645, 0.140261],
[0.0592024, 0.166897, 0.144765],
[0.0594587, 0.171138, 0.149308],
[0.0596487, 0.175368, 0.153889],
[0.0597746, 0.179586, 0.15851],
[0.0598387, 0.183793, 0.163171],
[0.0598436, 0.187988, 0.167871],
[0.059792, 0.192171, 0.172613],
[0.0596871, 0.196342, 0.177394],
[0.0595323, 0.200501, 0.182217],
[0.0593312, 0.204649, 0.18708],
[0.059088, 0.208784, 0.191985],
[0.0588071, 0.212906, 0.19693],
[0.0584935, 0.217016, 0.201916],
[0.0581524, 0.221113, 0.206943],
[0.0577898, 0.225197, 0.212011],
[0.057412, 0.229268, 0.217119],
[0.057026, 0.233326, 0.222267],
[0.0566392, 0.237369, 0.227454],
[0.0562598, 0.241399, 0.232682],
[0.0558964, 0.245414, 0.237947],
[0.0555584, 0.249415, 0.243252],
[0.0552556, 0.253402, 0.248594],
[0.0549984, 0.257373, 0.253974],
[0.0547979, 0.261329, 0.25939],
[0.0546655, 0.26527, 0.264842],
[0.054613, 0.269195, 0.270329],
[0.0546523, 0.273103, 0.27585],
[0.0547956, 0.276996, 0.281405],
[0.055055, 0.280872, 0.286993],
[0.0554424, 0.284732, 0.292612],
[0.0559692, 0.288574, 0.298263],
[0.0566462, 0.292399, 0.303942],
[0.0574836, 0.296207, 0.309651],
[0.0584903, 0.299997, 0.315386],
[0.0596742, 0.303769, 0.321148],
[0.061042, 0.307524, 0.326935],
[0.062599, 0.311259, 0.332746],
[0.0643491, 0.314977, 0.33858],
[0.0662946, 0.318676, 0.344435],
[0.0684366, 0.322355, 0.350309],
[0.070775, 0.326017, 0.356202],
[0.0733082, 0.329658, 0.362112],
[0.0760336, 0.333281, 0.368038],
[0.0789478, 0.336885, 0.373978],
[0.0820465, 0.340469, 0.37993],
[0.0853248, 0.344033, 0.385893],
[0.0887772, 0.347579, 0.391866],
[0.0923978, 0.351104, 0.397846],
[0.0961807, 0.35461, 0.403832],
[0.10012, 0.358097, 0.409823],
[0.104208, 0.361564, 0.415817],
[0.10844, 0.365011, 0.421811],
[0.11281, 0.368439, 0.427806],
[0.11731, 0.371848, 0.433797],
[0.121936, 0.375237, 0.439785],
[0.126682, 0.378608, 0.445767],
[0.131541, 0.381959, 0.451741],
[0.13651, 0.385291, 0.457706],
[0.141582, 0.388605, 0.463659],
[0.146753, 0.391901, 0.4696],
[0.152019, 0.395178, 0.475526],
[0.157374, 0.398438, 0.481436],
[0.162814, 0.401679, 0.487327],
[0.168337, 0.404904, 0.493199],
[0.173936, 0.408111, 0.499048],
[0.17961, 0.411302, 0.504875],
[0.185354, 0.414476, 0.510676],
[0.191166, 0.417634, 0.51645],
[0.197041, 0.420777, 0.522196],
[0.202977, 0.423905, 0.527911],
[0.20897, 0.427018, 0.533595],
[0.215019, 0.430117, 0.539245],
[0.221119, 0.433202, 0.544861],
[0.227269, 0.436274, 0.550439],
[0.233466, 0.439334, 0.55598],
[0.239708, 0.442381, 0.56148],
[0.245992, 0.445417, 0.56694],
[0.252316, 0.448441, 0.572358],
[0.258677, 0.451456, 0.577731],
[0.265074, 0.45446, 0.583059],
[0.271504, 0.457456, 0.588341],
[0.277966, 0.460443, 0.593575],
[0.284457, 0.463422, 0.59876],
[0.290976, 0.466394, 0.603896],
[0.29752, 0.469359, 0.608979],
[0.304088, 0.472319, 0.614011],
[0.310679, 0.475274, 0.61899],
[0.317289, 0.478224, 0.623914],
[0.323919, 0.481171, 0.628783],
[0.330565, 0.484114, 0.633596],
[0.337227, 0.487056, 0.638353],
[0.343903, 0.489996, 0.643052],
[0.350591, 0.492935, 0.647693],
[0.357291, 0.495875, 0.652276],
[0.363999, 0.498815, 0.656799],
[0.370716, 0.501757, 0.661263],
[0.377439, 0.504702, 0.665666],
[0.384168, 0.507649, 0.670009],
[0.390901, 0.5106, 0.674291],
[0.397636, 0.513557, 0.678512],
[0.404373, 0.516518, 0.682672],
[0.41111, 0.519486, 0.68677],
[0.417846, 0.522461, 0.690807],
[0.42458, 0.525443, 0.694783],
[0.431311, 0.528434, 0.698697],
[0.438037, 0.531434, 0.70255],
[0.444758, 0.534444, 0.706342],
[0.451471, 0.537465, 0.710073],
[0.458178, 0.540498, 0.713743],
[0.464875, 0.543542, 0.717354],
[0.471563, 0.5466, 0.720904],
[0.47824, 0.549671, 0.724395],
[0.484906, 0.552756, 0.727828],
[0.491558, 0.555857, 0.731202],
[0.498198, 0.558973, 0.734518],
[0.504823, 0.562105, 0.737778],
[0.511433, 0.565255, 0.740981],
[0.518026, 0.568422, 0.744129],
[0.524603, 0.571608, 0.747222],
[0.531162, 0.574812, 0.750261],
[0.537703, 0.578036, 0.753248],
[0.544224, 0.581281, 0.756183],
[0.550726, 0.584546, 0.759066],
[0.557207, 0.587832, 0.7619],
[0.563666, 0.59114, 0.764685],
[0.570104, 0.594471, 0.767423],
[0.576519, 0.597825, 0.770114],
[0.58291, 0.601202, 0.77276],
[0.589278, 0.604604, 0.775361],
[0.595621, 0.60803, 0.77792],
[0.601939, 0.611481, 0.780438],
[0.608231, 0.614957, 0.782915],
[0.614497, 0.61846, 0.785353],
[0.620736, 0.621989, 0.787754],
[0.626948, 0.625545, 0.79012],
[0.633133, 0.629128, 0.79245],
[0.639289, 0.632739, 0.794747],
[0.645416, 0.636378, 0.797013],
[0.651515, 0.640045, 0.799249],
[0.657584, 0.643741, 0.801456],
[0.663623, 0.647467, 0.803636],
[0.669631, 0.651222, 0.805791],
[0.675609, 0.655007, 0.807922],
[0.681556, 0.658822, 0.81003],
[0.687472, 0.662667, 0.812118],
[0.693356, 0.666544, 0.814186],
[0.699208, 0.670451, 0.816238],
[0.705028, 0.67439, 0.818273],
[0.710815, 0.67836, 0.820294],
[0.71657, 0.682362, 0.822303],
[0.722291, 0.686396, 0.824301],
[0.72798, 0.690462, 0.82629],
[0.733634, 0.69456, 0.828271],
[0.739256, 0.698692, 0.830246],
[0.744843, 0.702856, 0.832218],
[0.750396, 0.707053, 0.834187],
[0.755915, 0.711283, 0.836155],
[0.7614, 0.715546, 0.838124],
[0.766851, 0.719843, 0.840095],
[0.772267, 0.724173, 0.842071],
[0.777649, 0.728536, 0.844053],
[0.782996, 0.732934, 0.846043],
[0.788309, 0.737365, 0.848042],
[0.793586, 0.74183, 0.850052],
[0.79883, 0.746329, 0.852074],
[0.804038, 0.750862, 0.854111],
[0.809212, 0.755429, 0.856164],
[0.814351, 0.76003, 0.858235],
[0.819456, 0.764664, 0.860325],
[0.824527, 0.769333, 0.862435],
[0.829563, 0.774036, 0.864568],
[0.834565, 0.778773, 0.866726],
[0.839532, 0.783544, 0.868909],
[0.844466, 0.788349, 0.87112],
[0.849367, 0.793188, 0.873359],
[0.854234, 0.798061, 0.875629],
[0.859067, 0.802967, 0.877931],
[0.863868, 0.807907, 0.880267],
[0.868636, 0.812881, 0.882638],
[0.873371, 0.817888, 0.885045],
[0.878074, 0.822928, 0.887491],
[0.882746, 0.828002, 0.889977],
[0.887387, 0.833109, 0.892504],
[0.891996, 0.838248, 0.895073],
[0.896575, 0.843421, 0.897687],
[0.901125, 0.848626, 0.900347],
[0.905645, 0.853863, 0.903053],
[0.910136, 0.859133, 0.905809],
[0.914599, 0.864434, 0.908614],
[0.919034, 0.869767, 0.911471],
[0.923443, 0.875132, 0.91438],
[0.927826, 0.880527, 0.917344],
[0.932183, 0.885954, 0.920363],
[0.936516, 0.891411, 0.92344],
[0.940826, 0.896898, 0.926575],
[0.945114, 0.902414, 0.92977],
[0.94938, 0.90796, 0.933026],
[0.953627, 0.913535, 0.936344],
[0.957855, 0.919138, 0.939727],
[0.962066, 0.924769, 0.943175],
[0.966262, 0.930427, 0.946691],
[0.970445, 0.936111, 0.950275],
[0.974616, 0.94182, 0.953929],
[0.978779, 0.947554, 0.957656],
[0.982936, 0.953312, 0.961457],
[0.987091, 0.959091, 0.965334],
[0.991248, 0.96489, 0.969291],
[0.995413, 0.970707, 0.97333],
[0.999595, 0.976537, 0.977458],
[1., 0.982376, 0.981681],
[1., 0.988212, 0.986016],
[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()
