from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0.0000208612, 0.0000200049, 0.0000198463],
[0.000433825, 0.000328056, 0.000259842],
[0.00130303, 0.000922249, 0.000685286],
[0.00260938, 0.00175906, 0.00125001],
[0.0043517, 0.00281364, 0.00192826],
[0.00653459, 0.00406821, 0.00270299],
[0.0091654, 0.00550866, 0.00356212],
[0.0122531, 0.00712315, 0.00449676],
[0.0158076, 0.0089014, 0.00550033],
[0.0198394, 0.0108342, 0.006568],
[0.0243597, 0.0129132, 0.00769632],
[0.0293796, 0.0151307, 0.00888295],
[0.0349108, 0.0174794, 0.0101265],
[0.0409542, 0.0199527, 0.0114264],
[0.047106, 0.0225441, 0.0127829],
[0.0532301, 0.0252476, 0.0141967],
[0.0593308, 0.0280575, 0.0156692],
[0.0654122, 0.0309681, 0.0172025],
[0.0714773, 0.0339743, 0.0187988],
[0.0775288, 0.0370711, 0.0204612],
[0.083569, 0.0402535, 0.0221931],
[0.0895996, 0.0434012, 0.0239983],
[0.0956223, 0.0464804, 0.025881],
[0.101638, 0.0494967, 0.027846],
[0.107649, 0.0524526, 0.0298984],
[0.113654, 0.0553505, 0.0320437],
[0.119656, 0.0581925, 0.0342879],
[0.125654, 0.0609807, 0.0366373],
[0.131649, 0.063717, 0.0390987],
[0.137642, 0.066403, 0.0416481],
[0.143632, 0.0690406, 0.0442162],
[0.149619, 0.0716314, 0.0468158],
[0.155604, 0.0741769, 0.0494501],
[0.161587, 0.0766787, 0.0521223],
[0.167567, 0.0791381, 0.0548352],
[0.173544, 0.0815565, 0.0575918],
[0.179519, 0.0839355, 0.0603946],
[0.18549, 0.0862762, 0.0632463],
[0.191457, 0.08858, 0.0661491],
[0.197421, 0.0908482, 0.0691056],
[0.20338, 0.0930821, 0.0721178],
[0.209335, 0.0952829, 0.075188],
[0.215284, 0.0974519, 0.078318],
[0.221228, 0.0995904, 0.0815098],
[0.227165, 0.1017, 0.0847653],
[0.233095, 0.103781, 0.088086],
[0.239018, 0.105835, 0.0914738],
[0.244933, 0.107864, 0.0949301],
[0.250839, 0.109868, 0.0984564],
[0.256736, 0.111849, 0.102054],
[0.262622, 0.113809, 0.105724],
[0.268498, 0.115748, 0.109469],
[0.274362, 0.117668, 0.113288],
[0.280214, 0.11957, 0.117184],
[0.286053, 0.121455, 0.121156],
[0.291878, 0.123325, 0.125207],
[0.297689, 0.125181, 0.129337],
[0.303484, 0.127025, 0.133547],
[0.309263, 0.128857, 0.137837],
[0.315025, 0.13068, 0.142208],
[0.320769, 0.132494, 0.146661],
[0.326495, 0.134301, 0.151196],
[0.332201, 0.136103, 0.155814],
[0.337886, 0.137901, 0.160515],
[0.34355, 0.139696, 0.165299],
[0.349192, 0.14149, 0.170167],
[0.35481, 0.143285, 0.175119],
[0.360404, 0.145082, 0.180154],
[0.365973, 0.146883, 0.185273],
[0.371517, 0.148688, 0.190476],
[0.377033, 0.150501, 0.195763],
[0.382521, 0.152322, 0.201132],
[0.387981, 0.154152, 0.206585],
[0.39341, 0.155995, 0.21212],
[0.398809, 0.157851, 0.217738],
[0.404176, 0.159722, 0.223437],
[0.40951, 0.161609, 0.229217],
[0.41481, 0.163515, 0.235077],
[0.420076, 0.165441, 0.241016],
[0.425305, 0.167389, 0.247034],
[0.430498, 0.169359, 0.25313],
[0.435653, 0.171355, 0.259302],
[0.440769, 0.173378, 0.265549],
[0.445846, 0.17543, 0.27187],
[0.450881, 0.177511, 0.278263],
[0.455875, 0.179624, 0.284728],
[0.460825, 0.181771, 0.291262],
[0.465732, 0.183953, 0.297865],
[0.470594, 0.186172, 0.304533],
[0.47541, 0.188429, 0.311266],
[0.480179, 0.190727, 0.318062],
[0.484901, 0.193066, 0.324918],
[0.489573, 0.195448, 0.331832],
[0.494196, 0.197874, 0.338803],
[0.498767, 0.200347, 0.345828],
[0.503288, 0.202868, 0.352904],
[0.507755, 0.205437, 0.36003],
[0.512169, 0.208057, 0.367202],
[0.516528, 0.210729, 0.374418],
[0.520832, 0.213454, 0.381676],
[0.52508, 0.216233, 0.388973],
[0.52927, 0.219067, 0.396305],
[0.533402, 0.221958, 0.40367],
[0.537476, 0.224907, 0.411065],
[0.54149, 0.227914, 0.418486],
[0.545444, 0.230981, 0.425932],
[0.549337, 0.234108, 0.433398],
[0.553167, 0.237297, 0.440882],
[0.556936, 0.240547, 0.448379],
[0.560641, 0.24386, 0.455888],
[0.564282, 0.247236, 0.463403],
[0.567859, 0.250676, 0.470923],
[0.571372, 0.25418, 0.478444],
[0.574818, 0.257749, 0.485961],
[0.578199, 0.261382, 0.493472],
[0.581514, 0.265081, 0.500974],
[0.584762, 0.268844, 0.508462],
[0.587943, 0.272673, 0.515933],
[0.591057, 0.276567, 0.523384],
[0.594104, 0.280526, 0.530811],
[0.597083, 0.28455, 0.538211],
[0.599994, 0.288639, 0.545579],
[0.602838, 0.292792, 0.552914],
[0.605614, 0.297008, 0.560211],
[0.608322, 0.301288, 0.567466],
[0.610963, 0.305631, 0.574678],
[0.613536, 0.310036, 0.581841],
[0.616043, 0.314502, 0.588953],
[0.618483, 0.319029, 0.596012],
[0.620856, 0.323615, 0.603013],
[0.623164, 0.328261, 0.609953],
[0.625406, 0.332964, 0.61683],
[0.627584, 0.337724, 0.623641],
[0.629699, 0.342539, 0.630383],
[0.63175, 0.347409, 0.637052],
[0.633739, 0.352333, 0.643648],
[0.635667, 0.357308, 0.650166],
[0.637535, 0.362334, 0.656605],
[0.639343, 0.367409, 0.662961],
[0.641095, 0.372532, 0.669234],
[0.642789, 0.377702, 0.675421],
[0.644429, 0.382916, 0.681519],
[0.646015, 0.388174, 0.687527],
[0.647548, 0.393474, 0.693443],
[0.649032, 0.398815, 0.699266],
[0.650467, 0.404194, 0.704994],
[0.651855, 0.40961, 0.710625],
[0.653198, 0.415062, 0.716158],
[0.654498, 0.420547, 0.721593],
[0.655757, 0.426065, 0.726928],
[0.656978, 0.431613, 0.732162],
[0.658162, 0.437191, 0.737295],
[0.659311, 0.442795, 0.742325],
[0.660429, 0.448425, 0.747253],
[0.661518, 0.454079, 0.752079],
[0.66258, 0.459755, 0.756801],
[0.663618, 0.465451, 0.761419],
[0.664634, 0.471167, 0.765935],
[0.665631, 0.4769, 0.770348],
[0.666612, 0.482649, 0.774658],
[0.667581, 0.488412, 0.778865],
[0.668539, 0.494187, 0.782971],
[0.669489, 0.499973, 0.786976],
[0.670435, 0.505769, 0.79088],
[0.67138, 0.511574, 0.794685],
[0.672327, 0.517384, 0.798391],
[0.673279, 0.5232, 0.802],
[0.674239, 0.52902, 0.805512],
[0.67521, 0.534842, 0.808929],
[0.676195, 0.540665, 0.812253],
[0.677198, 0.546489, 0.815485],
[0.678221, 0.55231, 0.818626],
[0.679269, 0.55813, 0.821678],
[0.680343, 0.563945, 0.824642],
[0.681448, 0.569756, 0.827522],
[0.682586, 0.57556, 0.830317],
[0.683761, 0.581358, 0.833031],
[0.684975, 0.587147, 0.835666],
[0.686232, 0.592928, 0.838222],
[0.687534, 0.598699, 0.840704],
[0.688886, 0.604459, 0.843112],
[0.690288, 0.610207, 0.845449],
[0.691745, 0.615943, 0.847717],
[0.693259, 0.621666, 0.849919],
[0.694833, 0.627376, 0.852057],
[0.69647, 0.63307, 0.854133],
[0.698172, 0.63875, 0.85615],
[0.699941, 0.644414, 0.85811],
[0.70178, 0.650062, 0.860015],
[0.703691, 0.655694, 0.861869],
[0.705676, 0.661308, 0.863674],
[0.707738, 0.666905, 0.865432],
[0.709879, 0.672483, 0.867145],
[0.7121, 0.678044, 0.868817],
[0.714402, 0.683586, 0.87045],
[0.716789, 0.68911, 0.872047],
[0.719261, 0.694614, 0.873609],
[0.721819, 0.7001, 0.87514],
[0.724465, 0.705566, 0.876643],
[0.7272, 0.711013, 0.878119],
[0.730026, 0.71644, 0.879571],
[0.732942, 0.721848, 0.881003],
[0.73595, 0.727237, 0.882416],
[0.739051, 0.732606, 0.883813],
[0.742245, 0.737956, 0.885196],
[0.745533, 0.743286, 0.886569],
[0.748914, 0.748597, 0.887932],
[0.752389, 0.753889, 0.88929],
[0.755959, 0.759163, 0.890645],
[0.759622, 0.764417, 0.891998],
[0.76338, 0.769653, 0.893352],
[0.767232, 0.774871, 0.89471],
[0.771177, 0.780071, 0.896074],
[0.775215, 0.785254, 0.897446],
[0.779346, 0.790419, 0.898828],
[0.783569, 0.795567, 0.900224],
[0.787884, 0.800699, 0.901634],
[0.792288, 0.805814, 0.903062],
[0.796783, 0.810914, 0.904509],
[0.801366, 0.815998, 0.905978],
[0.806037, 0.821067, 0.907471],
[0.810795, 0.826122, 0.908989],
[0.815638, 0.831163, 0.910536],
[0.820566, 0.83619, 0.912112],
[0.825577, 0.841204, 0.913721],
[0.83067, 0.846206, 0.915363],
[0.835843, 0.851196, 0.917042],
[0.841095, 0.856175, 0.918758],
[0.846425, 0.861143, 0.920515],
[0.851831, 0.866101, 0.922313],
[0.857311, 0.871049, 0.924154],
[0.862864, 0.875988, 0.926042],
[0.868488, 0.880919, 0.927976],
[0.874182, 0.885843, 0.92996],
[0.879944, 0.890759, 0.931994],
[0.885772, 0.89567, 0.934082],
[0.891665, 0.900574, 0.936224],
[0.897619, 0.905474, 0.938422],
[0.903635, 0.91037, 0.940679],
[0.909709, 0.915263, 0.942995],
[0.915839, 0.920154, 0.945374],
[0.922024, 0.925042, 0.947816],
[0.928262, 0.92993, 0.950325],
[0.934549, 0.934819, 0.952901],
[0.940884, 0.939708, 0.955547],
[0.947264, 0.9446, 0.958265],
[0.953687, 0.949494, 0.961059],
[0.960148, 0.954394, 0.96393],
[0.966646, 0.959298, 0.966882],
[0.973175, 0.96421, 0.96992],
[0.97973, 0.969131, 0.973047],
[0.986307, 0.974063, 0.976271],
[0.992895, 0.979009, 0.979601],
[0.999483, 0.983972, 0.983051],
[1., 0.988961, 0.986652],
[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()
