from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0.0000208612, 0.0000200049, 0.0000198463],
[0.000329733, 0.000355235, 0.000388911],
[0.000918775, 0.00102323, 0.00115405],
[0.00174368, 0.0019877, 0.00229307],
[0.00278067, 0.00323034, 0.0038012],
[0.00401418, 0.00473922, 0.00567963],
[0.00543317, 0.00650563, 0.00793261],
[0.00702962, 0.00852271, 0.0105662],
[0.00879763, 0.0107848, 0.0135877],
[0.0107329, 0.0132871, 0.0170054],
[0.0128325, 0.0160254, 0.020828],
[0.0150947, 0.0189956, 0.0250652],
[0.0175184, 0.0221943, 0.0297267],
[0.0201037, 0.0256181, 0.0348227],
[0.0228514, 0.0292637, 0.0403638],
[0.0257629, 0.033128, 0.0460311],
[0.0288402, 0.037208, 0.0516775],
[0.0320861, 0.0414751, 0.0573087],
[0.0355039, 0.0457053, 0.0629281],
[0.0390975, 0.0498785, 0.0685389],
[0.0427903, 0.0539977, 0.0741437],
[0.0464561, 0.0580653, 0.0797447],
[0.0501092, 0.0620837, 0.0853437],
[0.0537537, 0.0660548, 0.0909422],
[0.0573935, 0.0699804, 0.0965417],
[0.0610323, 0.073862, 0.102143],
[0.0646736, 0.077701, 0.107747],
[0.0683205, 0.0814986, 0.113355],
[0.0719761, 0.085256, 0.118967],
[0.0756432, 0.0889741, 0.124584],
[0.0793245, 0.0926539, 0.130205],
[0.0830223, 0.0962961, 0.135831],
[0.0867391, 0.0999015, 0.141462],
[0.090477, 0.103471, 0.147097],
[0.0942382, 0.107004, 0.152737],
[0.0980244, 0.110503, 0.158381],
[0.101838, 0.113968, 0.16403],
[0.105679, 0.117398, 0.169681],
[0.109551, 0.120795, 0.175335],
[0.113455, 0.124159, 0.180991],
[0.117391, 0.12749, 0.186649],
[0.121362, 0.130789, 0.192308],
[0.125368, 0.134057, 0.197966],
[0.12941, 0.137292, 0.203623],
[0.133489, 0.140497, 0.209278],
[0.137607, 0.14367, 0.21493],
[0.141763, 0.146814, 0.220579],
[0.145959, 0.149927, 0.226222],
[0.150195, 0.15301, 0.231858],
[0.154472, 0.156064, 0.237487],
[0.158789, 0.159089, 0.243107],
[0.163148, 0.162085, 0.248718],
[0.167548, 0.165053, 0.254317],
[0.17199, 0.167992, 0.259903],
[0.176473, 0.170904, 0.265475],
[0.180999, 0.173789, 0.271032],
[0.185566, 0.176648, 0.276571],
[0.190175, 0.179479, 0.282093],
[0.194826, 0.182285, 0.287594],
[0.199518, 0.185066, 0.293074],
[0.204251, 0.187821, 0.298531],
[0.209025, 0.190552, 0.303964],
[0.213839, 0.193259, 0.309371],
[0.218693, 0.195943, 0.31475],
[0.223586, 0.198604, 0.3201],
[0.228519, 0.201242, 0.32542],
[0.23349, 0.203859, 0.330707],
[0.238498, 0.206455, 0.335961],
[0.243544, 0.20903, 0.341179],
[0.248626, 0.211586, 0.346361],
[0.253744, 0.214122, 0.351504],
[0.258896, 0.21664, 0.356607],
[0.264083, 0.219141, 0.361669],
[0.269304, 0.221624, 0.366688],
[0.274556, 0.224092, 0.371662],
[0.279841, 0.226544, 0.37659],
[0.285156, 0.228982, 0.381471],
[0.290501, 0.231406, 0.386304],
[0.295875, 0.233817, 0.391086],
[0.301276, 0.236216, 0.395817],
[0.306705, 0.238604, 0.400495],
[0.312159, 0.240982, 0.405119],
[0.317639, 0.243351, 0.409688],
[0.323142, 0.245711, 0.4142],
[0.328668, 0.248064, 0.418654],
[0.334216, 0.250411, 0.42305],
[0.339785, 0.252752, 0.427386],
[0.345373, 0.255088, 0.431661],
[0.35098, 0.257422, 0.435874],
[0.356605, 0.259753, 0.440024],
[0.362246, 0.262082, 0.444111],
[0.367902, 0.264411, 0.448134],
[0.373572, 0.266741, 0.452091],
[0.379256, 0.269072, 0.455982],
[0.384952, 0.271406, 0.459807],
[0.390658, 0.273744, 0.463565],
[0.396374, 0.276086, 0.467255],
[0.402099, 0.278435, 0.470877],
[0.407832, 0.28079, 0.474431],
[0.413571, 0.283153, 0.477916],
[0.419316, 0.285526, 0.481332],
[0.425065, 0.287908, 0.484679],
[0.430817, 0.290301, 0.487957],
[0.436571, 0.292706, 0.491165],
[0.442327, 0.295124, 0.494303],
[0.448082, 0.297557, 0.497373],
[0.453837, 0.300004, 0.500373],
[0.459589, 0.302467, 0.503305],
[0.465338, 0.304947, 0.506168],
[0.471083, 0.307446, 0.508962],
[0.476822, 0.309963, 0.511689],
[0.482556, 0.3125, 0.514348],
[0.488282, 0.315057, 0.51694],
[0.493999, 0.317636, 0.519467],
[0.499708, 0.320238, 0.521927],
[0.505406, 0.322863, 0.524323],
[0.511093, 0.325512, 0.526654],
[0.516767, 0.328186, 0.528923],
[0.522428, 0.330885, 0.531129],
[0.528076, 0.333612, 0.533274],
[0.533708, 0.336365, 0.535359],
[0.539323, 0.339147, 0.537385],
[0.544922, 0.341957, 0.539353],
[0.550503, 0.344797, 0.541264],
[0.556065, 0.347667, 0.543119],
[0.561608, 0.350568, 0.544921],
[0.56713, 0.3535, 0.546669],
[0.57263, 0.356465, 0.548367],
[0.578108, 0.359461, 0.550015],
[0.583563, 0.362491, 0.551614],
[0.588994, 0.365555, 0.553166],
[0.5944, 0.368653, 0.554674],
[0.599781, 0.371785, 0.556138],
[0.605135, 0.374953, 0.55756],
[0.610462, 0.378157, 0.558943],
[0.615761, 0.381396, 0.560287],
[0.621031, 0.384672, 0.561595],
[0.626272, 0.387985, 0.562868],
[0.631482, 0.391335, 0.564108],
[0.636661, 0.394722, 0.565318],
[0.641809, 0.398147, 0.566499],
[0.646924, 0.401611, 0.567654],
[0.652006, 0.405113, 0.568783],
[0.657054, 0.408653, 0.56989],
[0.662068, 0.412233, 0.570977],
[0.667047, 0.415851, 0.572045],
[0.67199, 0.419509, 0.573096],
[0.676897, 0.423207, 0.574133],
[0.681767, 0.426944, 0.575158],
[0.686599, 0.43072, 0.576173],
[0.691393, 0.434537, 0.57718],
[0.696148, 0.438393, 0.578182],
[0.700864, 0.44229, 0.57918],
[0.70554, 0.446226, 0.580178],
[0.710176, 0.450203, 0.581176],
[0.714771, 0.45422, 0.582178],
[0.719325, 0.458277, 0.583185],
[0.723837, 0.462374, 0.584201],
[0.728306, 0.466511, 0.585226],
[0.732733, 0.470687, 0.586264],
[0.737117, 0.474904, 0.587317],
[0.741457, 0.479161, 0.588387],
[0.745754, 0.483457, 0.589476],
[0.750006, 0.487793, 0.590587],
[0.754213, 0.492168, 0.591722],
[0.758376, 0.496582, 0.592883],
[0.762493, 0.501036, 0.594072],
[0.766565, 0.505528, 0.595292],
[0.770591, 0.510059, 0.596545],
[0.77457, 0.514628, 0.597833],
[0.778504, 0.519235, 0.599159],
[0.782391, 0.52388, 0.600524],
[0.786232, 0.528563, 0.601931],
[0.790025, 0.533283, 0.603382],
[0.793772, 0.53804, 0.60488],
[0.797472, 0.542834, 0.606426],
[0.801125, 0.547663, 0.608022],
[0.804731, 0.552529, 0.609671],
[0.80829, 0.55743, 0.611375],
[0.811801, 0.562367, 0.613136],
[0.815266, 0.567338, 0.614955],
[0.818684, 0.572343, 0.616836],
[0.822055, 0.577382, 0.618779],
[0.82538, 0.582455, 0.620787],
[0.828658, 0.58756, 0.622862],
[0.83189, 0.592698, 0.625005],
[0.835076, 0.597868, 0.627219],
[0.838216, 0.603069, 0.629505],
[0.841311, 0.608301, 0.631866],
[0.844362, 0.613564, 0.634302],
[0.847368, 0.618856, 0.636815],
[0.85033, 0.624178, 0.639408],
[0.853248, 0.629528, 0.642081],
[0.856124, 0.634906, 0.644837],
[0.858957, 0.640312, 0.647676],
[0.861749, 0.645745, 0.650601],
[0.864499, 0.651204, 0.653612],
[0.86721, 0.656688, 0.656711],
[0.869881, 0.662198, 0.659899],
[0.872514, 0.667732, 0.663178],
[0.875109, 0.673289, 0.666548],
[0.877667, 0.678869, 0.670011],
[0.88019, 0.684472, 0.673567],
[0.882678, 0.690096, 0.677218],
[0.885133, 0.695742, 0.680964],
[0.887555, 0.701407, 0.684806],
[0.889947, 0.707092, 0.688746],
[0.892309, 0.712795, 0.692783],
[0.894642, 0.718516, 0.696918],
[0.896949, 0.724255, 0.701152],
[0.89923, 0.73001, 0.705485],
[0.901487, 0.735781, 0.709917],
[0.903722, 0.741567, 0.71445],
[0.905936, 0.747367, 0.719082],
[0.908132, 0.753181, 0.723814],
[0.91031, 0.759007, 0.728646],
[0.912474, 0.764845, 0.733578],
[0.914624, 0.770695, 0.73861],
[0.916763, 0.776554, 0.743742],
[0.918892, 0.782424, 0.748972],
[0.921015, 0.788302, 0.754302],
[0.923133, 0.794189, 0.759729],
[0.925248, 0.800083, 0.765254],
[0.927363, 0.805983, 0.770876],
[0.92948, 0.811889, 0.776594],
[0.931602, 0.817801, 0.782407],
[0.933731, 0.823716, 0.788314],
[0.935869, 0.829636, 0.794314],
[0.93802, 0.835558, 0.800405],
[0.940186, 0.841482, 0.806587],
[0.942369, 0.847408, 0.812858],
[0.944572, 0.853335, 0.819216],
[0.946799, 0.859262, 0.82566],
[0.949053, 0.865188, 0.832188],
[0.951335, 0.871112, 0.838797],
[0.953649, 0.877035, 0.845487],
[0.955999, 0.882956, 0.852254],
[0.958387, 0.888872, 0.859097],
[0.960817, 0.894786, 0.866013],
[0.963291, 0.900694, 0.872999],
[0.965814, 0.906598, 0.880053],
[0.968387, 0.912495, 0.887171],
[0.971016, 0.918387, 0.894351],
[0.973704, 0.924271, 0.901588],
[0.976453, 0.930149, 0.908879],
[0.979269, 0.936017, 0.91622],
[0.982155, 0.941878, 0.923607],
[0.985115, 0.947728, 0.931033],
[0.988155, 0.953569, 0.938494],
[0.99128, 0.959398, 0.945981],
[0.994495, 0.965215, 0.953487],
[0.99781, 0.971018, 0.961],
[1., 0.976806, 0.968506],
[1., 0.982575, 0.975981],
[1., 0.988317, 0.98338],
[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()
