from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0.0000208612, 0.0000200049, 0.0000198463],
[0.000345979, 0.00034648, 0.000411877],
[0.000974988, 0.000992261, 0.00124038],
[0.00186144, 0.00192128, 0.00248938],
[0.00297788, 0.00311617, 0.00415938],
[0.00430369, 0.00456658, 0.00625593],
[0.00582166, 0.00626587, 0.00878699],
[0.00751655, 0.00820976, 0.0117617],
[0.0093743, 0.0103956, 0.01519],
[0.0113816, 0.0128219, 0.0190823],
[0.0135257, 0.0154882, 0.023449],
[0.0157941, 0.0183946, 0.0283007],
[0.0181744, 0.0215422, 0.0336481],
[0.0206545, 0.0249322, 0.0395016],
[0.0232222, 0.0285667, 0.0455857],
[0.0258655, 0.032448, 0.0516303],
[0.028572, 0.0365788, 0.0576489],
[0.0313296, 0.0409517, 0.0636445],
[0.0341259, 0.0453386, 0.0696196],
[0.0369486, 0.0496969, 0.0755762],
[0.0397851, 0.0540304, 0.0815158],
[0.0425538, 0.0583428, 0.0874394],
[0.0451989, 0.0626372, 0.093348],
[0.0477282, 0.0669165, 0.099242],
[0.0501415, 0.0711832, 0.105122],
[0.0524381, 0.0754398, 0.110987],
[0.0546171, 0.0796884, 0.116839],
[0.0566772, 0.0839311, 0.122675],
[0.058617, 0.0881698, 0.128497],
[0.0604348, 0.0924061, 0.134302],
[0.0621285, 0.0966416, 0.140092],
[0.0636958, 0.100878, 0.145864],
[0.0651342, 0.105116, 0.151618],
[0.0664408, 0.109358, 0.157353],
[0.0676124, 0.113604, 0.163068],
[0.0686456, 0.117855, 0.168761],
[0.0695366, 0.122113, 0.174431],
[0.070281, 0.126379, 0.180077],
[0.0708744, 0.130653, 0.185698],
[0.0713114, 0.134936, 0.191291],
[0.0715865, 0.139229, 0.196857],
[0.0716934, 0.143532, 0.202392],
[0.0716251, 0.147846, 0.207895],
[0.0713738, 0.152172, 0.213366],
[0.0709308, 0.15651, 0.218801],
[0.0702863, 0.16086, 0.2242],
[0.0694289, 0.165223, 0.22956],
[0.068346, 0.169599, 0.234881],
[0.0670226, 0.173989, 0.240159],
[0.0654417, 0.178392, 0.245395],
[0.0635829, 0.182809, 0.250585],
[0.061422, 0.187239, 0.255727],
[0.0589296, 0.191684, 0.260821],
[0.0560699, 0.196142, 0.265865],
[0.0527975, 0.200615, 0.270856],
[0.0490542, 0.205101, 0.275793],
[0.044763, 0.209601, 0.280675],
[0.0398103, 0.214115, 0.285499],
[0.0342592, 0.218642, 0.290264],
[0.0283208, 0.223182, 0.294968],
[0.0219941, 0.227736, 0.29961],
[0.0152787, 0.232301, 0.304188],
[0.00817508, 0.23688, 0.3087],
[0.000684751, 0.241469, 0.313146],
[0., 0.246071, 0.317523],
[0., 0.250684, 0.32183],
[0., 0.255307, 0.326065],
[0., 0.25994, 0.330229],
[0., 0.264583, 0.334318],
[0., 0.269234, 0.338333],
[0., 0.273894, 0.342271],
[0., 0.278562, 0.346132],
[0., 0.283237, 0.349915],
[0., 0.287919, 0.353619],
[0., 0.292606, 0.357243],
[0., 0.297299, 0.360785],
[0., 0.301996, 0.364247],
[0., 0.306696, 0.367626],
[0., 0.3114, 0.370922],
[0., 0.316105, 0.374135],
[0., 0.320812, 0.377264],
[0., 0.32552, 0.380309],
[0., 0.330227, 0.38327],
[0., 0.334933, 0.386146],
[0., 0.339638, 0.388938],
[0., 0.34434, 0.391644],
[0., 0.349038, 0.394267],
[0., 0.353732, 0.396805],
[0., 0.358421, 0.399259],
[0., 0.363104, 0.401629],
[0., 0.367781, 0.403915],
[0., 0.372449, 0.406119],
[0., 0.37711, 0.40824],
[0., 0.381761, 0.41028],
[0., 0.386402, 0.412238],
[0., 0.391033, 0.414117],
[0., 0.395652, 0.415916],
[0., 0.400259, 0.417636],
[0., 0.404853, 0.41928],
[0., 0.409433, 0.420847],
[0., 0.413998, 0.42234],
[0., 0.418549, 0.423759],
[0., 0.423083, 0.425105],
[0., 0.427601, 0.426381],
[0., 0.432102, 0.427588],
[0., 0.436585, 0.428726],
[0., 0.441049, 0.429799],
[0., 0.445494, 0.430807],
[0., 0.44992, 0.431752],
[0., 0.454326, 0.432637],
[0., 0.458711, 0.433462],
[0., 0.463074, 0.43423],
[0., 0.467416, 0.434944],
[0., 0.471736, 0.435604],
[0., 0.476033, 0.436213],
[0., 0.480308, 0.436773],
[0., 0.484559, 0.437287],
[0., 0.488786, 0.437757],
[0., 0.492989, 0.438184],
[0., 0.497168, 0.438572],
[0., 0.501322, 0.438922],
[0., 0.505451, 0.439237],
[0., 0.509555, 0.43952],
[0., 0.513634, 0.439772],
[0., 0.517687, 0.439997],
[0., 0.521714, 0.440197],
[0., 0.525716, 0.440375],
[0., 0.529692, 0.440533],
[0., 0.533641, 0.440673],
[0., 0.537565, 0.440799],
[0., 0.541463, 0.440913],
[0., 0.545335, 0.441017],
[0., 0.54918, 0.441115],
[0., 0.553, 0.441209],
[0., 0.556793, 0.441303],
[0., 0.560561, 0.441397],
[0., 0.564303, 0.441496],
[0., 0.56802, 0.441603],
[0., 0.571711, 0.441719],
[0., 0.575377, 0.441848],
[0., 0.579018, 0.441992],
[0., 0.582634, 0.442155],
[0., 0.586225, 0.442339],
[0., 0.589793, 0.442547],
[0., 0.593336, 0.442781],
[0.0141229, 0.596856, 0.443045],
[0.0558402, 0.600352, 0.443341],
[0.0862152, 0.603826, 0.443672],
[0.110285, 0.607277, 0.444041],
[0.130971, 0.610705, 0.444451],
[0.149499, 0.614112, 0.444903],
[0.166513, 0.617498, 0.445401],
[0.182401, 0.620862, 0.445948],
[0.197414, 0.624206, 0.446547],
[0.211726, 0.627531, 0.447199],
[0.225462, 0.630836, 0.447908],
[0.238716, 0.634121, 0.448675],
[0.251559, 0.637389, 0.449505],
[0.264049, 0.640639, 0.450399],
[0.27623, 0.643871, 0.451359],
[0.288139, 0.647087, 0.452389],
[0.299805, 0.650286, 0.45349],
[0.311254, 0.65347, 0.454665],
[0.322507, 0.65664, 0.455916],
[0.333581, 0.659795, 0.457246],
[0.344492, 0.662936, 0.458657],
[0.355252, 0.666064, 0.460151],
[0.365872, 0.669181, 0.46173],
[0.376363, 0.672286, 0.463396],
[0.386733, 0.675379, 0.465152],
[0.396989, 0.678463, 0.466999],
[0.407137, 0.681538, 0.468938],
[0.417184, 0.684603, 0.470973],
[0.427133, 0.687661, 0.473105],
[0.436991, 0.690712, 0.475335],
[0.44676, 0.693757, 0.477666],
[0.456444, 0.696795, 0.480098],
[0.466047, 0.69983, 0.482633],
[0.47557, 0.70286, 0.485273],
[0.485017, 0.705887, 0.488019],
[0.494388, 0.708911, 0.490873],
[0.503688, 0.711935, 0.493835],
[0.512916, 0.714957, 0.496907],
[0.522075, 0.71798, 0.500089],
[0.531165, 0.721004, 0.503384],
[0.540188, 0.72403, 0.506791],
[0.549145, 0.727058, 0.510311],
[0.558037, 0.730091, 0.513946],
[0.566865, 0.733128, 0.517696],
[0.575628, 0.73617, 0.521561],
[0.584328, 0.739219, 0.525543],
[0.592965, 0.742275, 0.529641],
[0.60154, 0.745339, 0.533856],
[0.610052, 0.748412, 0.538188],
[0.618502, 0.751496, 0.542638],
[0.62689, 0.75459, 0.547205],
[0.635217, 0.757697, 0.551889],
[0.643481, 0.760816, 0.556691],
[0.651684, 0.763949, 0.561611],
[0.659825, 0.767097, 0.566647],
[0.667905, 0.77026, 0.571801],
[0.675922, 0.77344, 0.577071],
[0.683877, 0.776638, 0.582457],
[0.691769, 0.779854, 0.587959],
[0.699599, 0.78309, 0.593575],
[0.707367, 0.786346, 0.599307],
[0.715071, 0.789623, 0.605151],
[0.722712, 0.792923, 0.611109],
[0.73029, 0.796246, 0.617178],
[0.737803, 0.799593, 0.623358],
[0.745253, 0.802965, 0.629648],
[0.752638, 0.806364, 0.636046],
[0.759958, 0.809789, 0.642552],
[0.767213, 0.813242, 0.649165],
[0.774403, 0.816725, 0.655881],
[0.781527, 0.820237, 0.662702],
[0.788584, 0.823779, 0.669623],
[0.795576, 0.827354, 0.676645],
[0.802501, 0.83096, 0.683766],
[0.809359, 0.8346, 0.690983],
[0.816149, 0.838275, 0.698294],
[0.822873, 0.841984, 0.705699],
[0.829528, 0.84573, 0.713194],
[0.836116, 0.849512, 0.720778],
[0.842635, 0.853332, 0.728448],
[0.849086, 0.85719, 0.736202],
[0.855468, 0.861087, 0.744039],
[0.861782, 0.865025, 0.751954],
[0.868027, 0.869003, 0.759946],
[0.874203, 0.873023, 0.768012],
[0.880311, 0.877085, 0.776149],
[0.88635, 0.881191, 0.784355],
[0.89232, 0.88534, 0.792626],
[0.898222, 0.889533, 0.800959],
[0.904055, 0.893771, 0.809351],
[0.90982, 0.898055, 0.8178],
[0.915518, 0.902385, 0.8263],
[0.921148, 0.906762, 0.834849],
[0.926711, 0.911187, 0.843444],
[0.932208, 0.915659, 0.852079],
[0.93764, 0.92018, 0.860751],
[0.943007, 0.924749, 0.869456],
[0.94831, 0.929368, 0.878189],
[0.95355, 0.934037, 0.886945],
[0.958729, 0.938755, 0.895719],
[0.963848, 0.943524, 0.904505],
[0.968908, 0.948343, 0.913297],
[0.973913, 0.953213, 0.922087],
[0.978863, 0.958134, 0.930869],
[0.983763, 0.963105, 0.939632],
[0.988615, 0.968128, 0.948364],
[0.993426, 0.973202, 0.957052],
[0.9982, 0.978326, 0.965675],
[1., 0.983501, 0.9742],
[1., 0.988726, 0.982567],
[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()
