from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0.0000208612, 0.0000200049, 0.0000198463],
[0.000441961, 0.000315831, 0.000344756],
[0.00132955, 0.00087912, 0.000991576],
[0.0026609, 0.00166601, 0.00192956],
[0.00443003, 0.00265192, 0.00314716],
[0.0066358, 0.00381984, 0.00464029],
[0.00927907, 0.00515679, 0.0064091],
[0.0123617, 0.00665239, 0.00845652],
[0.0158859, 0.008298, 0.0107875],
[0.0198542, 0.0100863, 0.0134088],
[0.0242691, 0.012011, 0.0163284],
[0.0291328, 0.0140665, 0.0195554],
[0.0344478, 0.0162479, 0.0231002],
[0.0402158, 0.0185511, 0.026974],
[0.0461021, 0.0209721, 0.031189],
[0.0519246, 0.0235075, 0.0357582],
[0.0576912, 0.0261543, 0.0406909],
[0.0634058, 0.0289097, 0.0457172],
[0.0690714, 0.0317715, 0.0507546],
[0.0746905, 0.0347374, 0.055808],
[0.0802653, 0.0378056, 0.0608816],
[0.0857976, 0.0409638, 0.0659791],
[0.091289, 0.044082, 0.0711041],
[0.0967406, 0.0471564, 0.0762594],
[0.102154, 0.0501901, 0.081448],
[0.107529, 0.0531857, 0.0866723],
[0.112867, 0.056146, 0.0919346],
[0.118169, 0.0590733, 0.0972369],
[0.123434, 0.0619699, 0.102581],
[0.128664, 0.0648381, 0.107969],
[0.133859, 0.06768, 0.113402],
[0.139018, 0.0704975, 0.118881],
[0.144141, 0.0732925, 0.124408],
[0.149229, 0.076067, 0.129984],
[0.154282, 0.0788226, 0.135609],
[0.159299, 0.0815612, 0.141285],
[0.16428, 0.0842843, 0.147012],
[0.169225, 0.0869938, 0.152791],
[0.174133, 0.0896911, 0.158622],
[0.179004, 0.0923778, 0.164505],
[0.183839, 0.0950555, 0.170442],
[0.188635, 0.0977258, 0.176431],
[0.193394, 0.10039, 0.182473],
[0.198113, 0.10305, 0.188569],
[0.202794, 0.105707, 0.194717],
[0.207434, 0.108362, 0.200918],
[0.212034, 0.111017, 0.207171],
[0.216593, 0.113673, 0.213476],
[0.221111, 0.116332, 0.219832],
[0.225585, 0.118995, 0.226239],
[0.230017, 0.121664, 0.232695],
[0.234405, 0.12434, 0.239201],
[0.238748, 0.127024, 0.245755],
[0.243046, 0.129717, 0.252356],
[0.247298, 0.132422, 0.259003],
[0.251503, 0.13514, 0.265696],
[0.255661, 0.137871, 0.272432],
[0.259769, 0.140617, 0.27921],
[0.263829, 0.14338, 0.286029],
[0.267838, 0.146161, 0.292887],
[0.271796, 0.14896, 0.299784],
[0.275702, 0.151781, 0.306716],
[0.279555, 0.154623, 0.313683],
[0.283355, 0.157489, 0.320682],
[0.2871, 0.160378, 0.327711],
[0.29079, 0.163294, 0.334769],
[0.294423, 0.166236, 0.341854],
[0.297999, 0.169207, 0.348962],
[0.301517, 0.172207, 0.356093],
[0.304977, 0.175237, 0.363243],
[0.308376, 0.178299, 0.370411],
[0.311715, 0.181394, 0.377593],
[0.314992, 0.184523, 0.384788],
[0.318207, 0.187686, 0.391993],
[0.321358, 0.190886, 0.399204],
[0.324446, 0.194122, 0.406421],
[0.327469, 0.197396, 0.413639],
[0.330426, 0.200709, 0.420855],
[0.333317, 0.204062, 0.428068],
[0.33614, 0.207455, 0.435275],
[0.338896, 0.21089, 0.442471],
[0.341583, 0.214366, 0.449655],
[0.344201, 0.217885, 0.456824],
[0.34675, 0.221447, 0.463974],
[0.349228, 0.225052, 0.471102],
[0.351635, 0.228702, 0.478206],
[0.35397, 0.232397, 0.485283],
[0.356233, 0.236136, 0.492328],
[0.358424, 0.239921, 0.499341],
[0.360543, 0.243751, 0.506316],
[0.362588, 0.247627, 0.513252],
[0.36456, 0.251549, 0.520145],
[0.366458, 0.255517, 0.526992],
[0.368282, 0.259531, 0.533791],
[0.370033, 0.26359, 0.540538],
[0.37171, 0.267695, 0.54723],
[0.373313, 0.271846, 0.553866],
[0.374842, 0.276042, 0.56044],
[0.376298, 0.280282, 0.566952],
[0.377681, 0.284567, 0.573399],
[0.378991, 0.288896, 0.579776],
[0.380228, 0.293268, 0.586083],
[0.381394, 0.297682, 0.592316],
[0.382489, 0.302139, 0.598474],
[0.383513, 0.306638, 0.604553],
[0.384468, 0.311176, 0.610551],
[0.385354, 0.315755, 0.616466],
[0.386173, 0.320372, 0.622296],
[0.386925, 0.325028, 0.628039],
[0.387612, 0.32972, 0.633694],
[0.388236, 0.334448, 0.639257],
[0.388798, 0.339211, 0.644727],
[0.389299, 0.344008, 0.650103],
[0.389742, 0.348838, 0.655383],
[0.390128, 0.353698, 0.660566],
[0.39046, 0.358589, 0.665651],
[0.39074, 0.363509, 0.670635],
[0.390969, 0.368457, 0.675519],
[0.391151, 0.37343, 0.680301],
[0.391288, 0.378429, 0.68498],
[0.391384, 0.383452, 0.689555],
[0.39144, 0.388496, 0.694026],
[0.39146, 0.393562, 0.698393],
[0.391447, 0.398647, 0.702654],
[0.391406, 0.40375, 0.706811],
[0.391338, 0.40887, 0.710861],
[0.391248, 0.414005, 0.714807],
[0.391141, 0.419155, 0.718647],
[0.391019, 0.424316, 0.722381],
[0.390887, 0.429489, 0.726011],
[0.390749, 0.434672, 0.729536],
[0.390609, 0.439863, 0.732958],
[0.390473, 0.445061, 0.736276],
[0.390345, 0.450264, 0.739492],
[0.390229, 0.455472, 0.742606],
[0.390131, 0.460683, 0.745619],
[0.390056, 0.465896, 0.748533],
[0.390008, 0.471109, 0.751348],
[0.389992, 0.476322, 0.754067],
[0.390015, 0.481532, 0.756689],
[0.390082, 0.486739, 0.759217],
[0.390197, 0.491942, 0.761653],
[0.390366, 0.497139, 0.763997],
[0.390594, 0.50233, 0.766252],
[0.390887, 0.507513, 0.768419],
[0.391251, 0.512687, 0.770501],
[0.39169, 0.517851, 0.772498],
[0.392209, 0.523005, 0.774414],
[0.392815, 0.528147, 0.776249],
[0.393512, 0.533277, 0.778008],
[0.394304, 0.538393, 0.77969],
[0.395198, 0.543496, 0.7813],
[0.396196, 0.548583, 0.782838],
[0.397305, 0.553654, 0.784308],
[0.398528, 0.558709, 0.785711],
[0.399869, 0.563747, 0.78705],
[0.401332, 0.568767, 0.788329],
[0.402921, 0.573769, 0.789548],
[0.404638, 0.578752, 0.79071],
[0.406488, 0.583716, 0.791819],
[0.408473, 0.588659, 0.792877],
[0.410594, 0.593583, 0.793886],
[0.412855, 0.598485, 0.794848],
[0.415257, 0.603367, 0.795767],
[0.417803, 0.608227, 0.796646],
[0.420492, 0.613065, 0.797486],
[0.423326, 0.617882, 0.79829],
[0.426305, 0.622676, 0.799062],
[0.429431, 0.627448, 0.799804],
[0.432702, 0.632197, 0.800517],
[0.436119, 0.636923, 0.801206],
[0.439681, 0.641627, 0.801873],
[0.443387, 0.646308, 0.80252],
[0.447236, 0.650966, 0.80315],
[0.451228, 0.655601, 0.803765],
[0.455359, 0.660213, 0.804369],
[0.459629, 0.664803, 0.804964],
[0.464036, 0.66937, 0.805552],
[0.468578, 0.673914, 0.806136],
[0.473252, 0.678436, 0.806718],
[0.478055, 0.682935, 0.807302],
[0.482986, 0.687413, 0.807889],
[0.488042, 0.691868, 0.808482],
[0.493219, 0.696302, 0.809084],
[0.498515, 0.700715, 0.809696],
[0.503927, 0.705106, 0.810322],
[0.509453, 0.709477, 0.810963],
[0.515088, 0.713827, 0.811622],
[0.52083, 0.718157, 0.812302],
[0.526676, 0.722468, 0.813004],
[0.532622, 0.726759, 0.813731],
[0.538666, 0.731031, 0.814485],
[0.544804, 0.735285, 0.815269],
[0.551034, 0.739521, 0.816083],
[0.557352, 0.743739, 0.816931],
[0.563754, 0.74794, 0.817815],
[0.570239, 0.752125, 0.818736],
[0.576802, 0.756293, 0.819697],
[0.583442, 0.760446, 0.820699],
[0.590154, 0.764583, 0.821745],
[0.596937, 0.768707, 0.822836],
[0.603787, 0.772816, 0.823974],
[0.610701, 0.776912, 0.825161],
[0.617677, 0.780995, 0.8264],
[0.624712, 0.785065, 0.82769],
[0.631804, 0.789125, 0.829035],
[0.638949, 0.793173, 0.830436],
[0.646145, 0.797211, 0.831894],
[0.653391, 0.801239, 0.833411],
[0.660683, 0.805258, 0.834989],
[0.668019, 0.809269, 0.836629],
[0.675396, 0.813272, 0.838332],
[0.682814, 0.817267, 0.840101],
[0.690268, 0.821257, 0.841935],
[0.697758, 0.825241, 0.843838],
[0.705281, 0.829219, 0.845809],
[0.712835, 0.833194, 0.847851],
[0.720418, 0.837165, 0.849963],
[0.728028, 0.841133, 0.852149],
[0.735664, 0.845099, 0.854408],
[0.743323, 0.849063, 0.856742],
[0.751004, 0.853027, 0.859151],
[0.758704, 0.856991, 0.861637],
[0.766423, 0.860956, 0.864201],
[0.774158, 0.864923, 0.866844],
[0.781908, 0.868892, 0.869566],
[0.789671, 0.872865, 0.872369],
[0.797445, 0.876841, 0.875252],
[0.805229, 0.880822, 0.878218],
[0.813022, 0.88481, 0.881266],
[0.820822, 0.888803, 0.884397],
[0.828627, 0.892804, 0.887612],
[0.836436, 0.896813, 0.890911],
[0.844247, 0.900832, 0.894295],
[0.852059, 0.90486, 0.897764],
[0.859871, 0.908899, 0.901319],
[0.86768, 0.91295, 0.90496],
[0.875485, 0.917014, 0.908687],
[0.883285, 0.921092, 0.912502],
[0.891079, 0.925185, 0.916403],
[0.898863, 0.929293, 0.920391],
[0.906638, 0.933419, 0.924466],
[0.9144, 0.937562, 0.928628],
[0.922148, 0.941726, 0.932877],
[0.92988, 0.945909, 0.937214],
[0.937593, 0.950115, 0.941637],
[0.945285, 0.954344, 0.946147],
[0.952953, 0.958599, 0.950744],
[0.960593, 0.962881, 0.955426],
[0.968201, 0.967193, 0.960193],
[0.975771, 0.971537, 0.965045],
[0.983296, 0.975918, 0.96998],
[0.990766, 0.980339, 0.974998],
[0.998162, 0.984809, 0.980097],
[1., 0.989343, 0.985275],
[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()
