from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0.0000208612, 0.0000200049, 0.0000198463],
[0.000432858, 0.000323548, 0.000305383],
[0.0012966, 0.000907901, 0.000841242],
[0.00258831, 0.00173151, 0.00157896],
[0.00430134, 0.00277202, 0.00248894],
[0.00643418, 0.00401448, 0.00354896],
[0.0089875, 0.005448, 0.0047407],
[0.0119631, 0.00706425, 0.00604835],
[0.0153632, 0.00885666, 0.00745783],
[0.0191904, 0.01082, 0.00895632],
[0.0234471, 0.0129501, 0.010532],
[0.0281358, 0.0152436, 0.012174],
[0.0332588, 0.0176978, 0.0138721],
[0.0388181, 0.0203107, 0.0156166],
[0.0446142, 0.0230807, 0.0173985],
[0.0503431, 0.0260069, 0.0192093],
[0.0560173, 0.0290887, 0.021041],
[0.0616403, 0.0323257, 0.022886],
[0.0672149, 0.0357181, 0.0247373],
[0.0727435, 0.0392664, 0.0265882],
[0.078228, 0.0428854, 0.0284325],
[0.0836702, 0.0464599, 0.0302643],
[0.0890712, 0.0500033, 0.0320782],
[0.0944322, 0.053519, 0.0338691],
[0.099754, 0.05701, 0.0356324],
[0.105037, 0.0604793, 0.0373638],
[0.110283, 0.0639296, 0.0390593],
[0.11549, 0.0673633, 0.0407105],
[0.12066, 0.0707828, 0.042273],
[0.125794, 0.0741903, 0.0437585],
[0.13089, 0.0775879, 0.0451692],
[0.135948, 0.0809776, 0.0465074],
[0.14097, 0.0843611, 0.0477752],
[0.145954, 0.0877404, 0.0489746],
[0.150901, 0.0911169, 0.0501078],
[0.155809, 0.0944925, 0.0511767],
[0.16068, 0.0978684, 0.0521834],
[0.165512, 0.101246, 0.05313],
[0.170305, 0.104628, 0.0540183],
[0.175059, 0.108013, 0.0548506],
[0.179773, 0.111405, 0.0556286],
[0.184448, 0.114804, 0.0563546],
[0.189081, 0.11821, 0.0570304],
[0.193673, 0.121627, 0.0576583],
[0.198224, 0.125053, 0.0582401],
[0.202732, 0.128491, 0.0587781],
[0.207198, 0.131941, 0.0592743],
[0.21162, 0.135404, 0.0597309],
[0.215999, 0.138881, 0.06015],
[0.220333, 0.142373, 0.060534],
[0.224622, 0.145881, 0.060885],
[0.228865, 0.149404, 0.0612054],
[0.233063, 0.152945, 0.0614976],
[0.237214, 0.156504, 0.0617639],
[0.241317, 0.16008, 0.0620069],
[0.245372, 0.163676, 0.0622291],
[0.249379, 0.16729, 0.0624331],
[0.253337, 0.170925, 0.0626216],
[0.257246, 0.17458, 0.0627974],
[0.261104, 0.178255, 0.0629632],
[0.264912, 0.181952, 0.0631221],
[0.268668, 0.18567, 0.0632771],
[0.272372, 0.18941, 0.0634311],
[0.276024, 0.193172, 0.0635875],
[0.279623, 0.196957, 0.0637495],
[0.283169, 0.200764, 0.0639205],
[0.28666, 0.204593, 0.064104],
[0.290098, 0.208446, 0.0643035],
[0.29348, 0.212321, 0.0645226],
[0.296807, 0.21622, 0.0647652],
[0.300078, 0.220142, 0.065035],
[0.303293, 0.224088, 0.0653359],
[0.306452, 0.228056, 0.0656719],
[0.309553, 0.232048, 0.0660469],
[0.312597, 0.236063, 0.066465],
[0.315583, 0.240102, 0.0669304],
[0.31851, 0.244163, 0.0674471],
[0.32138, 0.248248, 0.0680191],
[0.324191, 0.252355, 0.0686506],
[0.326942, 0.256485, 0.0693456],
[0.329635, 0.260637, 0.0701081],
[0.332268, 0.264812, 0.070942],
[0.334841, 0.269009, 0.0718511],
[0.337355, 0.273227, 0.072839],
[0.339809, 0.277467, 0.0739093],
[0.342202, 0.281728, 0.0750655],
[0.344536, 0.28601, 0.0763106],
[0.34681, 0.290313, 0.0776477],
[0.349024, 0.294635, 0.0790797],
[0.351178, 0.298978, 0.0806091],
[0.353272, 0.30334, 0.0822383],
[0.355306, 0.30772, 0.0839694],
[0.357281, 0.312119, 0.0858044],
[0.359197, 0.316536, 0.0877449],
[0.361054, 0.320971, 0.0897924],
[0.362852, 0.325422, 0.091948],
[0.364592, 0.32989, 0.0942127],
[0.366275, 0.334374, 0.0965874],
[0.367901, 0.338874, 0.0990725],
[0.369469, 0.343388, 0.101668],
[0.370983, 0.347916, 0.104375],
[0.37244, 0.352458, 0.107193],
[0.373844, 0.357013, 0.110122],
[0.375194, 0.361581, 0.113161],
[0.376491, 0.36616, 0.116311],
[0.377736, 0.370751, 0.11957],
[0.378931, 0.375352, 0.122938],
[0.380077, 0.379962, 0.126414],
[0.381174, 0.384582, 0.129997],
[0.382225, 0.38921, 0.133687],
[0.38323, 0.393846, 0.137482],
[0.384191, 0.398489, 0.141382],
[0.38511, 0.403139, 0.145385],
[0.385988, 0.407793, 0.14949],
[0.386827, 0.412453, 0.153696],
[0.387629, 0.417117, 0.158001],
[0.388396, 0.421784, 0.162405],
[0.389131, 0.426454, 0.166907],
[0.389834, 0.431126, 0.171504],
[0.390509, 0.435799, 0.176196],
[0.391158, 0.440472, 0.180981],
[0.391783, 0.445145, 0.185858],
[0.392388, 0.449817, 0.190825],
[0.392974, 0.454487, 0.195881],
[0.393544, 0.459155, 0.201025],
[0.394103, 0.463819, 0.206255],
[0.394651, 0.468479, 0.21157],
[0.395194, 0.473134, 0.216968],
[0.395733, 0.477784, 0.222447],
[0.396273, 0.482427, 0.228006],
[0.396816, 0.487063, 0.233644],
[0.397367, 0.491692, 0.239359],
[0.397928, 0.496312, 0.245149],
[0.398504, 0.500923, 0.251013],
[0.399099, 0.505525, 0.256948],
[0.399716, 0.510116, 0.262954],
[0.400359, 0.514696, 0.269029],
[0.401032, 0.519264, 0.27517],
[0.40174, 0.52382, 0.281376],
[0.402486, 0.528362, 0.287645],
[0.403274, 0.532892, 0.293975],
[0.404109, 0.537407, 0.300365],
[0.404995, 0.541907, 0.306812],
[0.405936, 0.546392, 0.313315],
[0.406936, 0.550862, 0.319872],
[0.407999, 0.555315, 0.32648],
[0.409129, 0.559752, 0.333137],
[0.410331, 0.564171, 0.339843],
[0.411608, 0.568573, 0.346594],
[0.412965, 0.572957, 0.353388],
[0.414404, 0.577322, 0.360224],
[0.41593, 0.581669, 0.367099],
[0.417547, 0.585997, 0.374011],
[0.419257, 0.590305, 0.380958],
[0.421064, 0.594594, 0.387937],
[0.422971, 0.598863, 0.394948],
[0.424981, 0.603112, 0.401986],
[0.427098, 0.607341, 0.409051],
[0.429322, 0.61155, 0.41614],
[0.431658, 0.615738, 0.42325],
[0.434107, 0.619905, 0.43038],
[0.43667, 0.624052, 0.437528],
[0.439351, 0.628178, 0.44469],
[0.44215, 0.632284, 0.451865],
[0.445068, 0.636368, 0.459051],
[0.448107, 0.640433, 0.466245],
[0.451267, 0.644477, 0.473445],
[0.45455, 0.6485, 0.48065],
[0.457954, 0.652504, 0.487856],
[0.461482, 0.656487, 0.495061],
[0.465131, 0.660451, 0.502265],
[0.468903, 0.664395, 0.509464],
[0.472796, 0.66832, 0.516656],
[0.47681, 0.672226, 0.523839],
[0.480944, 0.676114, 0.531012],
[0.485197, 0.679983, 0.538172],
[0.489568, 0.683835, 0.545317],
[0.494054, 0.687669, 0.552446],
[0.498655, 0.691487, 0.559556],
[0.503368, 0.695288, 0.566645],
[0.508192, 0.699073, 0.573713],
[0.513125, 0.702843, 0.580757],
[0.518164, 0.706599, 0.587775],
[0.523307, 0.71034, 0.594765],
[0.528553, 0.714067, 0.601727],
[0.533897, 0.717782, 0.608658],
[0.539339, 0.721484, 0.615557],
[0.544875, 0.725175, 0.622423],
[0.550503, 0.728855, 0.629254],
[0.55622, 0.732524, 0.636049],
[0.562023, 0.736185, 0.642806],
[0.56791, 0.739836, 0.649524],
[0.573878, 0.74348, 0.656203],
[0.579924, 0.747116, 0.662841],
[0.586045, 0.750747, 0.669436],
[0.592239, 0.754371, 0.675989],
[0.598502, 0.757991, 0.682498],
[0.604832, 0.761607, 0.688962],
[0.611227, 0.76522, 0.69538],
[0.617683, 0.768831, 0.701753],
[0.624198, 0.772441, 0.708078],
[0.63077, 0.77605, 0.714356],
[0.637395, 0.77966, 0.720586],
[0.64407, 0.783271, 0.726767],
[0.650795, 0.786884, 0.7329],
[0.657565, 0.7905, 0.738983],
[0.664379, 0.79412, 0.745017],
[0.671234, 0.797745, 0.751001],
[0.678127, 0.801376, 0.756935],
[0.685057, 0.805013, 0.76282],
[0.692021, 0.808658, 0.768654],
[0.699018, 0.812311, 0.774439],
[0.706043, 0.815974, 0.780174],
[0.713097, 0.819647, 0.785859],
[0.720176, 0.823331, 0.791495],
[0.727279, 0.827026, 0.797082],
[0.734404, 0.830735, 0.80262],
[0.741548, 0.834457, 0.80811],
[0.748711, 0.838194, 0.813552],
[0.75589, 0.841946, 0.818947],
[0.763083, 0.845714, 0.824295],
[0.770288, 0.849499, 0.829597],
[0.777505, 0.853302, 0.834853],
[0.784732, 0.857124, 0.840064],
[0.791966, 0.860965, 0.845232],
[0.799207, 0.864827, 0.850356],
[0.806453, 0.868709, 0.855438],
[0.813703, 0.872613, 0.860478],
[0.820955, 0.87654, 0.865478],
[0.828207, 0.880491, 0.870439],
[0.83546, 0.884465, 0.875361],
[0.84271, 0.888465, 0.880246],
[0.849958, 0.89249, 0.885095],
[0.857201, 0.896541, 0.889909],
[0.864439, 0.900619, 0.894689],
[0.871671, 0.904726, 0.899437],
[0.878894, 0.90886, 0.904155],
[0.886109, 0.913024, 0.908842],
[0.893314, 0.917218, 0.913502],
[0.900507, 0.921443, 0.918135],
[0.907689, 0.925699, 0.922743],
[0.914856, 0.929987, 0.927328],
[0.922009, 0.934308, 0.931891],
[0.929145, 0.938663, 0.936435],
[0.936264, 0.943052, 0.940961],
[0.943364, 0.947476, 0.945471],
[0.950443, 0.951936, 0.949968],
[0.957499, 0.956434, 0.954455],
[0.964529, 0.960969, 0.958933],
[0.971532, 0.965544, 0.963407],
[0.978503, 0.97016, 0.967879],
[0.985437, 0.97482, 0.972356],
[0.992327, 0.979524, 0.976842],
[0.999161, 0.984279, 0.981347],
[1., 0.989093, 0.985888],
[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()
