from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0.988235, 0.984314, 0.992157],
[0.988235, 0.984314, 0.992157],
[0.984314, 0.980392, 0.988235],
[0.984314, 0.980392, 0.988235],
[0.980392, 0.976471, 0.988235],
[0.980392, 0.976471, 0.988235],
[0.976471, 0.972549, 0.984314],
[0.976471, 0.972549, 0.984314],
[0.976471, 0.968627, 0.984314],
[0.972549, 0.968627, 0.984314],
[0.972549, 0.964706, 0.980392],
[0.968627, 0.964706, 0.980392],
[0.968627, 0.964706, 0.980392],
[0.968627, 0.960784, 0.980392],
[0.964706, 0.960784, 0.976471],
[0.964706, 0.956863, 0.976471],
[0.960784, 0.956863, 0.976471],
[0.960784, 0.952941, 0.976471],
[0.956863, 0.952941, 0.972549],
[0.956863, 0.94902, 0.972549],
[0.956863, 0.94902, 0.972549],
[0.952941, 0.94902, 0.972549],
[0.952941, 0.945098, 0.968627],
[0.94902, 0.945098, 0.968627],
[0.94902, 0.941176, 0.968627],
[0.94902, 0.941176, 0.968627],
[0.945098, 0.937255, 0.964706],
[0.945098, 0.937255, 0.964706],
[0.941176, 0.933333, 0.964706],
[0.941176, 0.933333, 0.964706],
[0.937255, 0.929412, 0.960784],
[0.937255, 0.929412, 0.960784],
[0.933333, 0.92549, 0.960784],
[0.933333, 0.92549, 0.956863],
[0.929412, 0.921569, 0.956863],
[0.92549, 0.921569, 0.956863],
[0.92549, 0.917647, 0.952941],
[0.921569, 0.913725, 0.952941],
[0.917647, 0.913725, 0.952941],
[0.917647, 0.909804, 0.952941],
[0.913725, 0.909804, 0.94902],
[0.909804, 0.905882, 0.94902],
[0.909804, 0.901961, 0.94902],
[0.905882, 0.901961, 0.945098],
[0.901961, 0.898039, 0.945098],
[0.901961, 0.898039, 0.945098],
[0.898039, 0.894118, 0.941176],
[0.898039, 0.894118, 0.941176],
[0.894118, 0.890196, 0.941176],
[0.890196, 0.886275, 0.937255],
[0.890196, 0.886275, 0.937255],
[0.886275, 0.882353, 0.937255],
[0.882353, 0.882353, 0.933333],
[0.882353, 0.878431, 0.933333],
[0.878431, 0.87451, 0.933333],
[0.87451, 0.87451, 0.933333],
[0.87451, 0.870588, 0.929412],
[0.870588, 0.870588, 0.929412],
[0.866667, 0.866667, 0.929412],
[0.866667, 0.862745, 0.92549],
[0.862745, 0.862745, 0.92549],
[0.858824, 0.858824, 0.92549],
[0.858824, 0.858824, 0.921569],
[0.854902, 0.854902, 0.921569],
[0.85098, 0.85098, 0.921569],
[0.847059, 0.847059, 0.917647],
[0.843137, 0.843137, 0.917647],
[0.839216, 0.839216, 0.913725],
[0.835294, 0.835294, 0.913725],
[0.831373, 0.835294, 0.909804],
[0.827451, 0.831373, 0.909804],
[0.827451, 0.827451, 0.905882],
[0.823529, 0.823529, 0.905882],
[0.819608, 0.819608, 0.901961],
[0.815686, 0.815686, 0.901961],
[0.811765, 0.811765, 0.898039],
[0.807843, 0.807843, 0.898039],
[0.803922, 0.803922, 0.894118],
[0.8, 0.8, 0.894118],
[0.796078, 0.8, 0.894118],
[0.792157, 0.796078, 0.890196],
[0.788235, 0.792157, 0.890196],
[0.784314, 0.788235, 0.886275],
[0.780392, 0.784314, 0.886275],
[0.776471, 0.780392, 0.882353],
[0.772549, 0.776471, 0.882353],
[0.768627, 0.772549, 0.878431],
[0.768627, 0.768627, 0.878431],
[0.764706, 0.764706, 0.87451],
[0.760784, 0.760784, 0.87451],
[0.756863, 0.760784, 0.870588],
[0.752941, 0.756863, 0.870588],
[0.74902, 0.752941, 0.866667],
[0.745098, 0.74902, 0.866667],
[0.741176, 0.745098, 0.862745],
[0.737255, 0.741176, 0.862745],
[0.733333, 0.737255, 0.858824],
[0.729412, 0.733333, 0.858824],
[0.72549, 0.729412, 0.854902],
[0.721569, 0.72549, 0.854902],
[0.717647, 0.721569, 0.85098],
[0.713725, 0.713725, 0.847059],
[0.709804, 0.709804, 0.847059],
[0.709804, 0.705882, 0.843137],
[0.705882, 0.701961, 0.839216],
[0.701961, 0.698039, 0.839216],
[0.698039, 0.694118, 0.835294],
[0.694118, 0.690196, 0.835294],
[0.690196, 0.686275, 0.831373],
[0.686275, 0.682353, 0.827451],
[0.682353, 0.678431, 0.827451],
[0.678431, 0.67451, 0.823529],
[0.67451, 0.666667, 0.819608],
[0.670588, 0.662745, 0.819608],
[0.666667, 0.658824, 0.815686],
[0.662745, 0.654902, 0.815686],
[0.658824, 0.65098, 0.811765],
[0.654902, 0.647059, 0.807843],
[0.65098, 0.643137, 0.807843],
[0.65098, 0.639216, 0.803922],
[0.647059, 0.635294, 0.8],
[0.643137, 0.631373, 0.8],
[0.639216, 0.623529, 0.796078],
[0.635294, 0.619608, 0.796078],
[0.631373, 0.615686, 0.792157],
[0.627451, 0.611765, 0.788235],
[0.623529, 0.607843, 0.788235],
[0.619608, 0.603922, 0.784314],
[0.615686, 0.6, 0.784314],
[0.611765, 0.596078, 0.780392],
[0.607843, 0.592157, 0.780392],
[0.603922, 0.588235, 0.776471],
[0.6, 0.584314, 0.776471],
[0.596078, 0.584314, 0.772549],
[0.592157, 0.580392, 0.772549],
[0.592157, 0.576471, 0.772549],
[0.588235, 0.572549, 0.768627],
[0.584314, 0.568627, 0.768627],
[0.580392, 0.564706, 0.764706],
[0.576471, 0.560784, 0.764706],
[0.572549, 0.556863, 0.760784],
[0.568627, 0.552941, 0.760784],
[0.564706, 0.54902, 0.756863],
[0.560784, 0.54902, 0.756863],
[0.556863, 0.545098, 0.756863],
[0.552941, 0.541176, 0.752941],
[0.54902, 0.537255, 0.752941],
[0.545098, 0.533333, 0.74902],
[0.541176, 0.529412, 0.74902],
[0.537255, 0.52549, 0.745098],
[0.533333, 0.521569, 0.745098],
[0.533333, 0.517647, 0.745098],
[0.529412, 0.513725, 0.741176],
[0.52549, 0.509804, 0.741176],
[0.521569, 0.509804, 0.737255],
[0.517647, 0.505882, 0.737255],
[0.513725, 0.501961, 0.733333],
[0.509804, 0.498039, 0.733333],
[0.505882, 0.494118, 0.729412],
[0.501961, 0.490196, 0.729412],
[0.498039, 0.486275, 0.72549],
[0.498039, 0.478431, 0.72549],
[0.494118, 0.47451, 0.721569],
[0.490196, 0.470588, 0.717647],
[0.490196, 0.462745, 0.713725],
[0.486275, 0.458824, 0.713725],
[0.482353, 0.45098, 0.709804],
[0.482353, 0.447059, 0.705882],
[0.478431, 0.443137, 0.705882],
[0.47451, 0.435294, 0.701961],
[0.470588, 0.431373, 0.698039],
[0.470588, 0.427451, 0.694118],
[0.466667, 0.419608, 0.694118],
[0.462745, 0.415686, 0.690196],
[0.462745, 0.407843, 0.686275],
[0.458824, 0.403922, 0.686275],
[0.454902, 0.4, 0.682353],
[0.454902, 0.392157, 0.678431],
[0.45098, 0.388235, 0.67451],
[0.447059, 0.384314, 0.67451],
[0.447059, 0.376471, 0.670588],
[0.443137, 0.372549, 0.666667],
[0.439216, 0.364706, 0.662745],
[0.439216, 0.360784, 0.662745],
[0.435294, 0.356863, 0.658824],
[0.431373, 0.34902, 0.654902],
[0.427451, 0.345098, 0.654902],
[0.427451, 0.341176, 0.65098],
[0.423529, 0.333333, 0.647059],
[0.419608, 0.329412, 0.643137],
[0.419608, 0.321569, 0.643137],
[0.415686, 0.317647, 0.639216],
[0.411765, 0.313725, 0.635294],
[0.411765, 0.305882, 0.635294],
[0.407843, 0.301961, 0.631373],
[0.403922, 0.298039, 0.631373],
[0.403922, 0.290196, 0.627451],
[0.4, 0.286275, 0.623529],
[0.396078, 0.282353, 0.623529],
[0.396078, 0.278431, 0.619608],
[0.392157, 0.270588, 0.615686],
[0.388235, 0.266667, 0.615686],
[0.384314, 0.262745, 0.611765],
[0.384314, 0.254902, 0.611765],
[0.380392, 0.25098, 0.607843],
[0.376471, 0.247059, 0.603922],
[0.376471, 0.239216, 0.603922],
[0.372549, 0.235294, 0.6],
[0.368627, 0.231373, 0.596078],
[0.368627, 0.223529, 0.596078],
[0.364706, 0.219608, 0.592157],
[0.360784, 0.215686, 0.592157],
[0.360784, 0.207843, 0.588235],
[0.356863, 0.203922, 0.584314],
[0.352941, 0.2, 0.584314],
[0.352941, 0.196078, 0.580392],
[0.34902, 0.188235, 0.576471],
[0.345098, 0.184314, 0.576471],
[0.341176, 0.180392, 0.572549],
[0.341176, 0.172549, 0.572549],
[0.337255, 0.168627, 0.568627],
[0.333333, 0.164706, 0.564706],
[0.333333, 0.156863, 0.564706],
[0.329412, 0.152941, 0.560784],
[0.32549, 0.14902, 0.556863],
[0.32549, 0.145098, 0.556863],
[0.321569, 0.137255, 0.552941],
[0.317647, 0.133333, 0.552941],
[0.317647, 0.129412, 0.54902],
[0.313725, 0.12549, 0.54902],
[0.309804, 0.117647, 0.545098],
[0.309804, 0.113725, 0.545098],
[0.305882, 0.109804, 0.541176],
[0.301961, 0.105882, 0.537255],
[0.301961, 0.101961, 0.537255],
[0.298039, 0.0941176, 0.533333],
[0.294118, 0.0901961, 0.533333],
[0.294118, 0.0862745, 0.529412],
[0.290196, 0.0823529, 0.529412],
[0.290196, 0.0784314, 0.52549],
[0.286275, 0.0705882, 0.521569],
[0.282353, 0.0666667, 0.521569],
[0.282353, 0.0627451, 0.517647],
[0.278431, 0.0588235, 0.517647],
[0.27451, 0.0509804, 0.513725],
[0.27451, 0.0470588, 0.513725],
[0.270588, 0.0431373, 0.509804],
[0.266667, 0.0392157, 0.509804],
[0.266667, 0.0352941, 0.505882],
[0.262745, 0.027451, 0.501961],
[0.258824, 0.0235294, 0.501961],
[0.258824, 0.0196078, 0.498039],
[0.254902, 0.0156863, 0.498039],
[0.25098, 0.00784314, 0.494118],
[0.25098, 0.00392157, 0.494118],
[0.247059, 0., 0.490196]]

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()
