from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0.0000208612, 0.0000200049, 0.0000198463],
[0.000378464, 0.000334228, 0.000406941],
[0.00109526, 0.000946811, 0.00122278],
[0.00213279, 0.00181849, 0.00245175],
[0.00347066, 0.002929, 0.00409539],
[0.0050945, 0.00426533, 0.00616089],
[0.00699278, 0.00581839, 0.00865833],
[0.00915552, 0.00758153, 0.0115996],
[0.0115736, 0.0095498, 0.0149977],
[0.0142383, 0.0117195, 0.0188666],
[0.0171413, 0.014088, 0.023221],
[0.0202742, 0.0166534, 0.0280761],
[0.0236288, 0.0194145, 0.0334475],
[0.0271967, 0.0223705, 0.0393512],
[0.0309693, 0.0255214, 0.0455235],
[0.0349381, 0.0288675, 0.0516749],
[0.0390942, 0.0324094, 0.05782],
[0.0433178, 0.0361482, 0.0639625],
[0.0474437, 0.0400853, 0.0701057],
[0.0514836, 0.044063, 0.0762523],
[0.0554396, 0.048003, 0.0824045],
[0.059313, 0.0519144, 0.0885641],
[0.0631051, 0.0558004, 0.0947325],
[0.0668168, 0.0596644, 0.100911],
[0.0704486, 0.0635092, 0.107101],
[0.0740011, 0.0673375, 0.113302],
[0.0774745, 0.0711518, 0.119515],
[0.0808688, 0.0749544, 0.125741],
[0.0841838, 0.0787476, 0.131979],
[0.0874195, 0.0825333, 0.138229],
[0.0905753, 0.0863135, 0.144492],
[0.0936507, 0.09009, 0.150766],
[0.0966453, 0.0938646, 0.157052],
[0.0995582, 0.0976388, 0.163349],
[0.102389, 0.101414, 0.169655],
[0.105136, 0.105192, 0.175971],
[0.107799, 0.108975, 0.182295],
[0.110376, 0.112762, 0.188626],
[0.112867, 0.116557, 0.194963],
[0.11527, 0.120359, 0.201305],
[0.117584, 0.124171, 0.207651],
[0.119807, 0.127992, 0.213999],
[0.121939, 0.131825, 0.220347],
[0.123977, 0.13567, 0.226695],
[0.12592, 0.139529, 0.23304],
[0.127766, 0.143401, 0.239381],
[0.129514, 0.147289, 0.245717],
[0.131161, 0.151192, 0.252045],
[0.132707, 0.155112, 0.258364],
[0.134148, 0.15905, 0.264671],
[0.135483, 0.163005, 0.270966],
[0.13671, 0.166979, 0.277245],
[0.137826, 0.170972, 0.283507],
[0.138829, 0.174986, 0.28975],
[0.139717, 0.179019, 0.295971],
[0.140486, 0.183073, 0.30217],
[0.141136, 0.187149, 0.308342],
[0.141661, 0.191246, 0.314487],
[0.142061, 0.195364, 0.320603],
[0.142331, 0.199506, 0.326686],
[0.142469, 0.203669, 0.332734],
[0.142471, 0.207856, 0.338747],
[0.142333, 0.212065, 0.34472],
[0.142052, 0.216297, 0.350653],
[0.141623, 0.220552, 0.356542],
[0.141043, 0.22483, 0.362386],
[0.140306, 0.229131, 0.368182],
[0.139408, 0.233456, 0.373929],
[0.138343, 0.237803, 0.379623],
[0.137105, 0.242173, 0.385263],
[0.135688, 0.246565, 0.390847],
[0.134084, 0.25098, 0.396373],
[0.132287, 0.255416, 0.401838],
[0.130288, 0.259875, 0.407241],
[0.128076, 0.264355, 0.41258],
[0.125642, 0.268855, 0.417852],
[0.122973, 0.273377, 0.423056],
[0.120055, 0.277918, 0.428189],
[0.116871, 0.282479, 0.433251],
[0.113404, 0.287059, 0.43824],
[0.109631, 0.291658, 0.443153],
[0.105526, 0.296274, 0.447989],
[0.101057, 0.300907, 0.452747],
[0.0961837, 0.305557, 0.457425],
[0.0908579, 0.310223, 0.462022],
[0.0850158, 0.314904, 0.466536],
[0.0785739, 0.319599, 0.470967],
[0.0714179, 0.324307, 0.475313],
[0.0633846, 0.329029, 0.479573],
[0.0542272, 0.333762, 0.483746],
[0.0435402, 0.338506, 0.487831],
[0.0311184, 0.34326, 0.491827],
[0.0182863, 0.348024, 0.495735],
[0.00518918, 0.352795, 0.499552],
[0., 0.357574, 0.503279],
[0., 0.36236, 0.506915],
[0., 0.367151, 0.51046],
[0., 0.371947, 0.513914],
[0., 0.376746, 0.517276],
[0., 0.381548, 0.520546],
[0., 0.386352, 0.523725],
[0., 0.391156, 0.526812],
[0., 0.39596, 0.529808],
[0., 0.400763, 0.532713],
[0., 0.405563, 0.535528],
[0., 0.410361, 0.538253],
[0., 0.415154, 0.540889],
[0., 0.419943, 0.543436],
[0., 0.424725, 0.545895],
[0., 0.4295, 0.548267],
[0., 0.434268, 0.550553],
[0., 0.439027, 0.552755],
[0., 0.443776, 0.554872],
[0., 0.448515, 0.556907],
[0., 0.453242, 0.558861],
[0., 0.457957, 0.560735],
[0., 0.46266, 0.562531],
[0., 0.467349, 0.56425],
[0., 0.472023, 0.565894],
[0., 0.476682, 0.567464],
[0., 0.481325, 0.568962],
[0., 0.485951, 0.57039],
[0., 0.49056, 0.571751],
[0., 0.495151, 0.573044],
[0., 0.499724, 0.574274],
[0., 0.504277, 0.575442],
[0., 0.50881, 0.576549],
[0., 0.513324, 0.577599],
[0., 0.517816, 0.578593],
[0., 0.522288, 0.579534],
[0., 0.526737, 0.580423],
[0., 0.531165, 0.581263],
[0., 0.535569, 0.582057],
[0., 0.539952, 0.582807],
[0., 0.54431, 0.583516],
[0., 0.548646, 0.584185],
[0., 0.552957, 0.584817],
[0., 0.557244, 0.585415],
[0., 0.561507, 0.585982],
[0., 0.565746, 0.586519],
[0., 0.56996, 0.58703],
[0., 0.574149, 0.587517],
[0., 0.578314, 0.587982],
[0., 0.582453, 0.588429],
[0., 0.586567, 0.58886],
[0., 0.590656, 0.589277],
[0., 0.59472, 0.589684],
[0., 0.59876, 0.590082],
[0., 0.602774, 0.590475],
[0., 0.606763, 0.590865],
[0., 0.610727, 0.591254],
[0., 0.614667, 0.591647],
[0., 0.618582, 0.592044],
[0.00946509, 0.622473, 0.592449],
[0.046316, 0.626339, 0.592864],
[0.0755715, 0.630182, 0.593292],
[0.0986812, 0.634001, 0.593736],
[0.118566, 0.637796, 0.594198],
[0.136422, 0.641568, 0.59468],
[0.152868, 0.645318, 0.595186],
[0.168275, 0.649044, 0.595717],
[0.182879, 0.652749, 0.596277],
[0.196845, 0.656431, 0.596868],
[0.210289, 0.660093, 0.597492],
[0.223301, 0.663733, 0.598151],
[0.235945, 0.667352, 0.598849],
[0.248276, 0.670951, 0.599587],
[0.260333, 0.67453, 0.600369],
[0.272151, 0.67809, 0.601195],
[0.283758, 0.681632, 0.602069],
[0.295175, 0.685154, 0.602993],
[0.306423, 0.688659, 0.603969],
[0.317517, 0.692147, 0.605],
[0.328472, 0.695618, 0.606087],
[0.339298, 0.699073, 0.607232],
[0.350006, 0.702512, 0.608439],
[0.360605, 0.705935, 0.609708],
[0.371102, 0.709345, 0.611042],
[0.381504, 0.712741, 0.612444],
[0.391817, 0.716123, 0.613913],
[0.402046, 0.719493, 0.615454],
[0.412196, 0.722851, 0.617067],
[0.422269, 0.726197, 0.618755],
[0.432271, 0.729533, 0.620519],
[0.442203, 0.732859, 0.622361],
[0.452069, 0.736176, 0.624282],
[0.461871, 0.739484, 0.626285],
[0.471612, 0.742784, 0.62837],
[0.481292, 0.746077, 0.63054],
[0.490915, 0.749364, 0.632795],
[0.500481, 0.752645, 0.635138],
[0.509992, 0.755921, 0.63757],
[0.519448, 0.759193, 0.640091],
[0.528852, 0.762461, 0.642703],
[0.538203, 0.765727, 0.645408],
[0.547503, 0.76899, 0.648207],
[0.556753, 0.772253, 0.6511],
[0.565952, 0.775515, 0.654088],
[0.575102, 0.778778, 0.657173],
[0.584203, 0.782042, 0.660356],
[0.593255, 0.785309, 0.663638],
[0.602258, 0.788578, 0.667018],
[0.611213, 0.791851, 0.670498],
[0.62012, 0.795128, 0.67408],
[0.62898, 0.798411, 0.677762],
[0.637791, 0.8017, 0.681546],
[0.646555, 0.804996, 0.685432],
[0.65527, 0.8083, 0.689421],
[0.663938, 0.811613, 0.693514],
[0.672558, 0.814935, 0.697709],
[0.68113, 0.818268, 0.702009],
[0.689654, 0.821612, 0.706412],
[0.698129, 0.824969, 0.710919],
[0.706557, 0.828338, 0.715529],
[0.714935, 0.831722, 0.720244],
[0.723265, 0.835121, 0.725063],
[0.731545, 0.838535, 0.729985],
[0.739776, 0.841966, 0.735011],
[0.747957, 0.845415, 0.74014],
[0.756089, 0.848882, 0.745371],
[0.76417, 0.852368, 0.750705],
[0.772201, 0.855875, 0.756141],
[0.780181, 0.859403, 0.761678],
[0.788109, 0.862952, 0.767316],
[0.795987, 0.866525, 0.773054],
[0.803812, 0.870122, 0.77889],
[0.811585, 0.873744, 0.784825],
[0.819306, 0.877391, 0.790856],
[0.826974, 0.881065, 0.796984],
[0.834588, 0.884766, 0.803207],
[0.842149, 0.888496, 0.809524],
[0.849656, 0.892256, 0.815933],
[0.857108, 0.896045, 0.822433],
[0.864506, 0.899866, 0.829022],
[0.871849, 0.903719, 0.835699],
[0.879136, 0.907605, 0.842462],
[0.886368, 0.911526, 0.849309],
[0.893543, 0.915481, 0.856238],
[0.900662, 0.919472, 0.863248],
[0.907724, 0.9235, 0.870334],
[0.914728, 0.927566, 0.877496],
[0.921675, 0.931671, 0.88473],
[0.928565, 0.935816, 0.892034],
[0.935395, 0.940002, 0.899403],
[0.942167, 0.944229, 0.906835],
[0.94888, 0.9485, 0.914325],
[0.955533, 0.952815, 0.92187],
[0.962126, 0.957176, 0.929463],
[0.968658, 0.961584, 0.937099],
[0.975129, 0.96604, 0.944771],
[0.981537, 0.970546, 0.952469],
[0.98788, 0.975106, 0.960183],
[0.994157, 0.979721, 0.967894],
[1., 0.984397, 0.975579],
[1., 0.989144, 0.983189],
[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()
