from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0.0000208612, 0.0000200049, 0.0000198463],
[0.000381304, 0.000347563, 0.000269457],
[0.00110461, 0.000996324, 0.000717086],
[0.00215165, 0.00193067, 0.00131503],
[0.00350131, 0.00313368, 0.00203575],
[0.00513845, 0.00459538, 0.00286018],
[0.00705078, 0.00630954, 0.00377399],
[0.0092275, 0.00827219, 0.00476596],
[0.0116587, 0.010481, 0.00582707],
[0.014335, 0.0129347, 0.00694994],
[0.0172474, 0.015633, 0.00812848],
[0.0203868, 0.0185764, 0.00935766],
[0.0237445, 0.0217657, 0.0106334],
[0.0273117, 0.0252026, 0.0119521],
[0.0310794, 0.0288888, 0.0133113],
[0.0350387, 0.0328265, 0.0147087],
[0.0391805, 0.0370185, 0.0161427],
[0.0433815, 0.0414431, 0.0176121],
[0.0474829, 0.0458637, 0.0191161],
[0.0514973, 0.0502547, 0.0206545],
[0.0554271, 0.0546197, 0.0222273],
[0.0592741, 0.0589618, 0.0238349],
[0.0630402, 0.063284, 0.0254779],
[0.0667267, 0.0675888, 0.0271574],
[0.0703349, 0.0718785, 0.0288748],
[0.0738657, 0.0761552, 0.0306317],
[0.0773199, 0.0804208, 0.03243],
[0.0806984, 0.084677, 0.0342719],
[0.0840017, 0.0889254, 0.0361598],
[0.0872303, 0.0931673, 0.0380965],
[0.0903844, 0.0974041, 0.040085],
[0.0934645, 0.101637, 0.0420808],
[0.0964707, 0.105867, 0.0440705],
[0.0994031, 0.110095, 0.0460623],
[0.102262, 0.114322, 0.0480593],
[0.105047, 0.118548, 0.0500642],
[0.107759, 0.122775, 0.05208],
[0.110397, 0.127003, 0.0541092],
[0.112961, 0.131233, 0.0561546],
[0.115451, 0.135466, 0.0582187],
[0.117867, 0.139701, 0.0603039],
[0.120209, 0.143939, 0.0624128],
[0.122477, 0.148181, 0.0645476],
[0.12467, 0.152426, 0.0667106],
[0.126788, 0.156676, 0.068904],
[0.128831, 0.16093, 0.07113],
[0.130798, 0.16519, 0.0733905],
[0.13269, 0.169454, 0.0756877],
[0.134507, 0.173722, 0.0780234],
[0.136247, 0.177997, 0.0803995],
[0.137911, 0.182276, 0.0828177],
[0.139498, 0.186561, 0.0852799],
[0.141008, 0.19085, 0.0877875],
[0.142441, 0.195146, 0.0903422],
[0.143797, 0.199446, 0.0929456],
[0.145076, 0.203752, 0.095599],
[0.146276, 0.208062, 0.0983038],
[0.147399, 0.212378, 0.101061],
[0.148444, 0.216699, 0.103873],
[0.149411, 0.221024, 0.106739],
[0.150299, 0.225354, 0.109662],
[0.151109, 0.229688, 0.112642],
[0.151841, 0.234027, 0.11568],
[0.152494, 0.238369, 0.118777],
[0.153069, 0.242715, 0.121934],
[0.153566, 0.247064, 0.125152],
[0.153985, 0.251417, 0.128431],
[0.154327, 0.255772, 0.131773],
[0.154591, 0.26013, 0.135176],
[0.154777, 0.26449, 0.138643],
[0.154888, 0.268851, 0.142173],
[0.154922, 0.273215, 0.145768],
[0.15488, 0.277579, 0.149426],
[0.154764, 0.281944, 0.153149],
[0.154574, 0.286309, 0.156937],
[0.154311, 0.290675, 0.16079],
[0.153975, 0.295039, 0.164707],
[0.15357, 0.299403, 0.16869],
[0.153094, 0.303766, 0.172738],
[0.152551, 0.308126, 0.176851],
[0.151942, 0.312485, 0.181028],
[0.151269, 0.31684, 0.185271],
[0.150533, 0.321192, 0.189577],
[0.149738, 0.325541, 0.193948],
[0.148885, 0.329886, 0.198383],
[0.147978, 0.334225, 0.202881],
[0.14702, 0.33856, 0.207442],
[0.146014, 0.342889, 0.212066],
[0.144964, 0.347212, 0.216752],
[0.143874, 0.351528, 0.221499],
[0.142748, 0.355837, 0.226307],
[0.141592, 0.360139, 0.231175],
[0.14041, 0.364432, 0.236102],
[0.139209, 0.368717, 0.241088],
[0.137995, 0.372992, 0.246132],
[0.136774, 0.377258, 0.251232],
[0.135555, 0.381514, 0.256388],
[0.134344, 0.385759, 0.2616],
[0.13315, 0.389993, 0.266865],
[0.131982, 0.394215, 0.272183],
[0.13085, 0.398425, 0.277553],
[0.129764, 0.402623, 0.282973],
[0.128735, 0.406808, 0.288443],
[0.127774, 0.410979, 0.293961],
[0.126892, 0.415137, 0.299526],
[0.126103, 0.41928, 0.305136],
[0.125418, 0.423408, 0.310791],
[0.12485, 0.427522, 0.316488],
[0.124413, 0.43162, 0.322227],
[0.124119, 0.435701, 0.328005],
[0.123981, 0.439767, 0.333822],
[0.124012, 0.443816, 0.339676],
[0.124224, 0.447848, 0.345564],
[0.124628, 0.451863, 0.351487],
[0.125235, 0.45586, 0.357441],
[0.126055, 0.459839, 0.363426],
[0.127096, 0.4638, 0.369439],
[0.128366, 0.467743, 0.375479],
[0.129869, 0.471667, 0.381544],
[0.131612, 0.475572, 0.387632],
[0.133596, 0.479458, 0.393742],
[0.135824, 0.483325, 0.399872],
[0.138294, 0.487173, 0.406019],
[0.141007, 0.491001, 0.412182],
[0.143959, 0.49481, 0.41836],
[0.147147, 0.498599, 0.424549],
[0.150566, 0.502368, 0.430749],
[0.15421, 0.506118, 0.436958],
[0.158073, 0.509847, 0.443173],
[0.162148, 0.513558, 0.449392],
[0.166428, 0.517248, 0.455615],
[0.170904, 0.520919, 0.461838],
[0.17557, 0.524571, 0.46806],
[0.180416, 0.528203, 0.474279],
[0.185435, 0.531816, 0.480494],
[0.190619, 0.535409, 0.486701],
[0.19596, 0.538984, 0.4929],
[0.20145, 0.542541, 0.499089],
[0.207082, 0.546078, 0.505265],
[0.212847, 0.549598, 0.511427],
[0.21874, 0.5531, 0.517573],
[0.224753, 0.556585, 0.523702],
[0.230879, 0.560052, 0.529811],
[0.237113, 0.563502, 0.535899],
[0.243448, 0.566936, 0.541964],
[0.249879, 0.570354, 0.548004],
[0.2564, 0.573757, 0.554019],
[0.263005, 0.577144, 0.560005],
[0.26969, 0.580517, 0.565963],
[0.276451, 0.583875, 0.57189],
[0.283281, 0.58722, 0.577784],
[0.290178, 0.590552, 0.583645],
[0.297137, 0.593871, 0.58947],
[0.304154, 0.597179, 0.59526],
[0.311225, 0.600475, 0.601011],
[0.318347, 0.60376, 0.606724],
[0.325516, 0.607036, 0.612396],
[0.332728, 0.610301, 0.618027],
[0.339982, 0.613558, 0.623615],
[0.347273, 0.616807, 0.629161],
[0.3546, 0.620049, 0.634661],
[0.361958, 0.623284, 0.640117],
[0.369346, 0.626512, 0.645526],
[0.376761, 0.629736, 0.650888],
[0.3842, 0.632955, 0.656202],
[0.391662, 0.63617, 0.661467],
[0.399143, 0.639382, 0.666684],
[0.406642, 0.642591, 0.67185],
[0.414157, 0.6458, 0.676966],
[0.421686, 0.649007, 0.682032],
[0.429227, 0.652214, 0.687046],
[0.436777, 0.655422, 0.692009],
[0.444336, 0.658632, 0.696919],
[0.451901, 0.661844, 0.701778],
[0.459471, 0.665059, 0.706584],
[0.467045, 0.668278, 0.711338],
[0.47462, 0.671502, 0.716039],
[0.482195, 0.674731, 0.720688],
[0.489769, 0.677966, 0.725285],
[0.497341, 0.681208, 0.729829],
[0.504909, 0.684459, 0.73432],
[0.512472, 0.687717, 0.73876],
[0.520028, 0.690985, 0.743148],
[0.527577, 0.694264, 0.747485],
[0.535117, 0.697553, 0.75177],
[0.542647, 0.700853, 0.756005],
[0.550167, 0.704166, 0.76019],
[0.557675, 0.707493, 0.764325],
[0.56517, 0.710833, 0.768411],
[0.572651, 0.714187, 0.772449],
[0.580118, 0.717557, 0.776438],
[0.587569, 0.720943, 0.780381],
[0.595004, 0.724345, 0.784277],
[0.602422, 0.727765, 0.788128],
[0.609822, 0.731203, 0.791933],
[0.617203, 0.73466, 0.795695],
[0.624565, 0.738135, 0.799414],
[0.631907, 0.741631, 0.803091],
[0.639229, 0.745148, 0.806727],
[0.646529, 0.748686, 0.810323],
[0.653807, 0.752245, 0.813879],
[0.661063, 0.755827, 0.817398],
[0.668296, 0.759432, 0.82088],
[0.675506, 0.763061, 0.824326],
[0.682692, 0.766714, 0.827738],
[0.689853, 0.770392, 0.831116],
[0.69699, 0.774094, 0.834462],
[0.704101, 0.777823, 0.837778],
[0.711187, 0.781578, 0.841063],
[0.718247, 0.785359, 0.844321],
[0.725281, 0.789168, 0.847551],
[0.732288, 0.793004, 0.850756],
[0.739268, 0.796869, 0.853936],
[0.746221, 0.800762, 0.857094],
[0.753146, 0.804685, 0.86023],
[0.760044, 0.808636, 0.863346],
[0.766914, 0.812618, 0.866443],
[0.773756, 0.816629, 0.869523],
[0.780569, 0.820672, 0.872587],
[0.787354, 0.824745, 0.875637],
[0.794111, 0.82885, 0.878674],
[0.800839, 0.832986, 0.881699],
[0.807538, 0.837154, 0.884715],
[0.814208, 0.841354, 0.887723],
[0.820849, 0.845588, 0.890723],
[0.827461, 0.849853, 0.893719],
[0.834044, 0.854153, 0.896711],
[0.840598, 0.858485, 0.899701],
[0.847123, 0.862851, 0.90269],
[0.853619, 0.867251, 0.905681],
[0.860085, 0.871685, 0.908674],
[0.866523, 0.876154, 0.911672],
[0.872931, 0.880657, 0.914675],
[0.879311, 0.885194, 0.917687],
[0.885661, 0.889767, 0.920708],
[0.891983, 0.894375, 0.923741],
[0.898276, 0.899017, 0.926786],
[0.904541, 0.903696, 0.929847],
[0.910777, 0.908409, 0.932923],
[0.916985, 0.913158, 0.936019],
[0.923164, 0.917943, 0.939135],
[0.929316, 0.922764, 0.942274],
[0.935439, 0.92762, 0.945438],
[0.941535, 0.932513, 0.948628],
[0.947603, 0.937441, 0.951848],
[0.953644, 0.942405, 0.9551],
[0.959658, 0.947405, 0.958387],
[0.965644, 0.952441, 0.961712],
[0.971603, 0.957513, 0.965078],
[0.977535, 0.962621, 0.968491],
[0.983439, 0.967764, 0.971954],
[0.989316, 0.972942, 0.975476],
[0.995163, 0.978156, 0.979065],
[1., 0.983404, 0.982736],
[1., 0.988687, 0.986518],
[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()
