from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0.0000208612, 0.0000200049, 0.0000198463],
[0.000370031, 0.000341052, 0.000372953],
[0.00106646, 0.000971541, 0.00109246],
[0.00207352, 0.00187286, 0.00214908],
[0.00337357, 0.00302498, 0.00353101],
[0.00495585, 0.00441477, 0.00523252],
[0.00681311, 0.00603271, 0.00725091],
[0.00894024, 0.00787147, 0.00958527],
[0.0113336, 0.00992524, 0.0122359],
[0.0139905, 0.0121892, 0.015204],
[0.016909, 0.0146594, 0.0184912],
[0.0200878, 0.0173325, 0.0220998],
[0.0235261, 0.0202055, 0.0260324],
[0.0272234, 0.023276, 0.030292],
[0.0311795, 0.0265417, 0.0348818],
[0.0353945, 0.0300009, 0.0398053],
[0.0398687, 0.0336518, 0.0448459],
[0.0444169, 0.0374929, 0.0498412],
[0.0489123, 0.0414968, 0.054803],
[0.053366, 0.0454661, 0.0597351],
[0.0577816, 0.0493894, 0.0646406],
[0.0621622, 0.0532697, 0.0695225],
[0.0665104, 0.0571099, 0.0743832],
[0.0708289, 0.0609126, 0.0792251],
[0.0751198, 0.0646799, 0.0840502],
[0.0793852, 0.068414, 0.0888605],
[0.0836268, 0.0721167, 0.0936575],
[0.0878465, 0.0757897, 0.0984429],
[0.0920458, 0.0794347, 0.103218],
[0.096226, 0.083053, 0.107985],
[0.100389, 0.086646, 0.112743],
[0.104535, 0.0902149, 0.117496],
[0.108666, 0.093761, 0.122242],
[0.112782, 0.0972851, 0.126985],
[0.116885, 0.100788, 0.131724],
[0.120976, 0.104272, 0.13646],
[0.125056, 0.107736, 0.141194],
[0.129125, 0.111182, 0.145928],
[0.133184, 0.114611, 0.150661],
[0.137234, 0.118022, 0.155394],
[0.141275, 0.121418, 0.160129],
[0.145309, 0.124798, 0.164865],
[0.149335, 0.128163, 0.169603],
[0.153355, 0.131514, 0.174344],
[0.157369, 0.134852, 0.179088],
[0.161377, 0.138176, 0.183836],
[0.165381, 0.141487, 0.188588],
[0.169379, 0.144786, 0.193346],
[0.173374, 0.148073, 0.198108],
[0.177365, 0.151349, 0.202876],
[0.181354, 0.154614, 0.20765],
[0.185339, 0.157868, 0.21243],
[0.189322, 0.161112, 0.217218],
[0.193303, 0.164346, 0.222013],
[0.197282, 0.16757, 0.226815],
[0.20126, 0.170785, 0.231625],
[0.205237, 0.173992, 0.236444],
[0.209213, 0.177189, 0.241271],
[0.21319, 0.180378, 0.246107],
[0.217166, 0.183559, 0.250952],
[0.221142, 0.186732, 0.255807],
[0.22512, 0.189898, 0.260672],
[0.229098, 0.193056, 0.265547],
[0.233077, 0.196208, 0.270433],
[0.237057, 0.199352, 0.275329],
[0.24104, 0.202489, 0.280236],
[0.245024, 0.205621, 0.285154],
[0.24901, 0.208746, 0.290084],
[0.252999, 0.211864, 0.295026],
[0.256991, 0.214977, 0.29998],
[0.260985, 0.218085, 0.304946],
[0.264982, 0.221187, 0.309925],
[0.268983, 0.224283, 0.314916],
[0.272987, 0.227374, 0.319921],
[0.276995, 0.230461, 0.324939],
[0.281007, 0.233542, 0.32997],
[0.285023, 0.236619, 0.335015],
[0.289044, 0.239691, 0.340074],
[0.293068, 0.242759, 0.345147],
[0.297098, 0.245822, 0.350234],
[0.301132, 0.248882, 0.355336],
[0.305172, 0.251937, 0.360453],
[0.309217, 0.254989, 0.365584],
[0.313267, 0.258036, 0.370731],
[0.317323, 0.261081, 0.375894],
[0.321384, 0.264121, 0.381072],
[0.325452, 0.267158, 0.386266],
[0.329526, 0.270192, 0.391475],
[0.333605, 0.273223, 0.396701],
[0.337692, 0.27625, 0.401944],
[0.341785, 0.279275, 0.407203],
[0.345884, 0.282297, 0.412479],
[0.349991, 0.285316, 0.417772],
[0.354105, 0.288332, 0.423082],
[0.358226, 0.291345, 0.42841],
[0.362354, 0.294357, 0.433755],
[0.36649, 0.297365, 0.439118],
[0.370633, 0.300372, 0.444499],
[0.374784, 0.303376, 0.449898],
[0.378943, 0.306378, 0.455316],
[0.383111, 0.309377, 0.460752],
[0.387286, 0.312375, 0.466207],
[0.39147, 0.315371, 0.47168],
[0.395662, 0.318365, 0.477173],
[0.399863, 0.321357, 0.482685],
[0.404073, 0.324347, 0.488217],
[0.408292, 0.327336, 0.493768],
[0.41252, 0.330323, 0.499339],
[0.416757, 0.333309, 0.504931],
[0.421003, 0.336293, 0.510542],
[0.425259, 0.339276, 0.516174],
[0.429525, 0.342257, 0.521826],
[0.4338, 0.345237, 0.5275],
[0.438085, 0.348216, 0.533194],
[0.442381, 0.351194, 0.538909],
[0.446686, 0.354171, 0.544646],
[0.451002, 0.357146, 0.550404],
[0.455328, 0.360121, 0.556184],
[0.459664, 0.363094, 0.561986],
[0.464012, 0.366067, 0.56781],
[0.46837, 0.369039, 0.573656],
[0.472739, 0.37201, 0.579525],
[0.477119, 0.37498, 0.585417],
[0.48151, 0.37795, 0.591331],
[0.485913, 0.380919, 0.597268],
[0.490327, 0.383887, 0.603229],
[0.494752, 0.386855, 0.609213],
[0.49919, 0.389823, 0.61522],
[0.502989, 0.393502, 0.619139],
[0.50615, 0.39789, 0.620963],
[0.509322, 0.402273, 0.622803],
[0.512505, 0.406651, 0.624659],
[0.515699, 0.411025, 0.626531],
[0.518904, 0.415396, 0.628419],
[0.52212, 0.419763, 0.630322],
[0.525347, 0.424127, 0.632242],
[0.528584, 0.428489, 0.634177],
[0.531833, 0.432848, 0.636127],
[0.535093, 0.437206, 0.638093],
[0.538365, 0.441562, 0.640075],
[0.541647, 0.445918, 0.642073],
[0.544941, 0.450272, 0.644085],
[0.548245, 0.454626, 0.646114],
[0.551561, 0.458981, 0.648158],
[0.554889, 0.463335, 0.650217],
[0.558227, 0.46769, 0.652292],
[0.561577, 0.472046, 0.654383],
[0.564939, 0.476402, 0.656488],
[0.568312, 0.48076, 0.65861],
[0.571696, 0.48512, 0.660747],
[0.575092, 0.489482, 0.662899],
[0.5785, 0.493846, 0.665067],
[0.581919, 0.498212, 0.66725],
[0.58535, 0.502581, 0.669449],
[0.588792, 0.506953, 0.671664],
[0.592247, 0.511328, 0.673894],
[0.595713, 0.515706, 0.676139],
[0.599191, 0.520088, 0.678401],
[0.602682, 0.524474, 0.680677],
[0.606184, 0.528863, 0.68297],
[0.609698, 0.533257, 0.685278],
[0.613225, 0.537655, 0.687603],
[0.616764, 0.542058, 0.689943],
[0.620315, 0.546466, 0.692298],
[0.623878, 0.550879, 0.69467],
[0.627454, 0.555297, 0.697058],
[0.631043, 0.55972, 0.699461],
[0.634644, 0.564149, 0.701881],
[0.638257, 0.568584, 0.704317],
[0.641883, 0.573025, 0.706768],
[0.645522, 0.577472, 0.709236],
[0.649174, 0.581925, 0.711721],
[0.652839, 0.586385, 0.714221],
[0.656517, 0.590851, 0.716738],
[0.660208, 0.595325, 0.719272],
[0.663912, 0.599805, 0.721822],
[0.667629, 0.604292, 0.724388],
[0.67136, 0.608787, 0.726972],
[0.675104, 0.613289, 0.729571],
[0.678862, 0.617799, 0.732188],
[0.682633, 0.622317, 0.734822],
[0.686417, 0.626843, 0.737472],
[0.690216, 0.631377, 0.74014],
[0.694028, 0.635919, 0.742824],
[0.697855, 0.64047, 0.745526],
[0.701695, 0.645029, 0.748245],
[0.705549, 0.649597, 0.750982],
[0.709418, 0.654174, 0.753736],
[0.7133, 0.65876, 0.756508],
[0.717198, 0.663356, 0.759297],
[0.721109, 0.66796, 0.762104],
[0.725035, 0.672575, 0.764928],
[0.728976, 0.677198, 0.767771],
[0.732932, 0.681832, 0.770632],
[0.736902, 0.686476, 0.773511],
[0.740888, 0.69113, 0.776408],
[0.744888, 0.695794, 0.779323],
[0.748904, 0.700468, 0.782257],
[0.752935, 0.705153, 0.78521],
[0.756982, 0.709849, 0.788181],
[0.761043, 0.714555, 0.791171],
[0.765121, 0.719273, 0.79418],
[0.769214, 0.724002, 0.797208],
[0.773323, 0.728741, 0.800255],
[0.777448, 0.733493, 0.803322],
[0.781589, 0.738256, 0.806408],
[0.785746, 0.74303, 0.809514],
[0.78992, 0.747817, 0.812639],
[0.79411, 0.752615, 0.815784],
[0.798316, 0.757426, 0.818949],
[0.802539, 0.762248, 0.822135],
[0.806779, 0.767083, 0.825341],
[0.811036, 0.771931, 0.828567],
[0.81531, 0.776791, 0.831813],
[0.819601, 0.781665, 0.835081],
[0.823909, 0.786551, 0.838369],
[0.828235, 0.79145, 0.841679],
[0.832578, 0.796362, 0.84501],
[0.836939, 0.801288, 0.848362],
[0.841318, 0.806228, 0.851736],
[0.845715, 0.811181, 0.855132],
[0.85013, 0.816147, 0.85855],
[0.854563, 0.821128, 0.86199],
[0.859015, 0.826123, 0.865453],
[0.863486, 0.831132, 0.868938],
[0.867975, 0.836155, 0.872446],
[0.872483, 0.841193, 0.875977],
[0.87701, 0.846245, 0.879532],
[0.881556, 0.851312, 0.88311],
[0.886122, 0.856394, 0.886713],
[0.890707, 0.861491, 0.890339],
[0.895313, 0.866603, 0.89399],
[0.899938, 0.87173, 0.897665],
[0.904583, 0.876872, 0.901366],
[0.909249, 0.88203, 0.905092],
[0.913935, 0.887204, 0.908844],
[0.918642, 0.892393, 0.912622],
[0.92337, 0.897599, 0.916427],
[0.928119, 0.90282, 0.920258],
[0.932889, 0.908057, 0.924117],
[0.937681, 0.91331, 0.928005],
[0.942496, 0.918579, 0.93192],
[0.947332, 0.923865, 0.935865],
[0.952191, 0.929167, 0.93984],
[0.957073, 0.934485, 0.943846],
[0.961978, 0.93982, 0.947883],
[0.966907, 0.945171, 0.951953],
[0.97186, 0.950539, 0.956057],
[0.976838, 0.955922, 0.960196],
[0.981841, 0.961322, 0.964373],
[0.98687, 0.966737, 0.968589],
[0.991926, 0.972167, 0.972849],
[0.997011, 0.977612, 0.977157],
[1., 0.98307, 0.98152],
[1., 0.988537, 0.985956],
[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()
