from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0.0000208612, 0.0000200049, 0.0000198463],
[0.00034119, 0.00036335, 0.000268974],
[0.000964717, 0.00105174, 0.000711985],
[0.00185447, 0.00204919, 0.00129674],
[0.00299415, 0.00333741, 0.00199108],
[0.00437576, 0.00490418, 0.0027712],
[0.00599607, 0.00674023, 0.00361804],
[0.00785502, 0.00883798, 0.0045156],
[0.00995489, 0.0111909, 0.00545014],
[0.0122998, 0.0137929, 0.00640964],
[0.0148953, 0.0166387, 0.00738343],
[0.0177484, 0.0197229, 0.00836202],
[0.0208671, 0.0230406, 0.00933692],
[0.0242605, 0.0265866, 0.0103005],
[0.0279385, 0.0303562, 0.0112459],
[0.0319117, 0.0343443, 0.012167],
[0.0361919, 0.0385461, 0.0130583],
[0.0407846, 0.0428713, 0.0139149],
[0.0454492, 0.0471217, 0.0147326],
[0.050126, 0.0513059, 0.0155076],
[0.0548192, 0.0554265, 0.0162365],
[0.0595325, 0.059486, 0.0169166],
[0.0642693, 0.0634864, 0.0175454],
[0.0690323, 0.0674294, 0.0181211],
[0.0738242, 0.0713166, 0.0186421],
[0.078647, 0.0751494, 0.0191073],
[0.0835027, 0.078929, 0.0195157],
[0.0883929, 0.0826565, 0.0198669],
[0.093319, 0.0863329, 0.0201607],
[0.0982822, 0.0899591, 0.0203974],
[0.103284, 0.0935359, 0.0205772],
[0.108324, 0.097064, 0.020701],
[0.113404, 0.100544, 0.0207695],
[0.118523, 0.103977, 0.0207841],
[0.123684, 0.107363, 0.0207461],
[0.128885, 0.110703, 0.0206571],
[0.134127, 0.113996, 0.020519],
[0.139409, 0.117245, 0.0203337],
[0.144733, 0.120449, 0.0201034],
[0.150097, 0.123608, 0.0198304],
[0.155502, 0.126724, 0.0195173],
[0.160947, 0.129796, 0.0191665],
[0.166431, 0.132824, 0.018781],
[0.171955, 0.13581, 0.0183636],
[0.177517, 0.138754, 0.0179173],
[0.183118, 0.141655, 0.0174452],
[0.188757, 0.144515, 0.0169506],
[0.194432, 0.147334, 0.0164368],
[0.200144, 0.150112, 0.0159072],
[0.205891, 0.15285, 0.0153655],
[0.211673, 0.155548, 0.0148153],
[0.217489, 0.158206, 0.0142603],
[0.223338, 0.160825, 0.0137043],
[0.229219, 0.163405, 0.0131515],
[0.235132, 0.165948, 0.0126058],
[0.241075, 0.168453, 0.0120714],
[0.247047, 0.17092, 0.0115526],
[0.253048, 0.173351, 0.011054],
[0.259077, 0.175746, 0.0105799],
[0.265132, 0.178105, 0.0101352],
[0.271212, 0.18043, 0.00972474],
[0.277317, 0.18272, 0.00935349],
[0.283446, 0.184976, 0.00902666],
[0.289596, 0.187199, 0.00874962],
[0.295768, 0.18939, 0.00852796],
[0.30196, 0.191549, 0.00836746],
[0.308171, 0.193677, 0.00827414],
[0.314401, 0.195774, 0.00825427],
[0.320646, 0.197843, 0.00831437],
[0.326908, 0.199882, 0.00846125],
[0.333184, 0.201894, 0.00870202],
[0.339473, 0.203878, 0.0090441],
[0.345775, 0.205837, 0.00949526],
[0.352087, 0.20777, 0.0100636],
[0.358409, 0.209679, 0.0107578],
[0.36474, 0.211565, 0.0115865],
[0.371078, 0.213428, 0.0125594],
[0.377423, 0.21527, 0.013686],
[0.383772, 0.217092, 0.0149768],
[0.390126, 0.218895, 0.0164426],
[0.396481, 0.220679, 0.0180947],
[0.402838, 0.222447, 0.0199451],
[0.409195, 0.2242, 0.0220062],
[0.415551, 0.225938, 0.0242911],
[0.421905, 0.227663, 0.0268137],
[0.428255, 0.229376, 0.0295884],
[0.434599, 0.231079, 0.0326304],
[0.440938, 0.232772, 0.0359554],
[0.447269, 0.234458, 0.0395802],
[0.453591, 0.236137, 0.0434061],
[0.459903, 0.237812, 0.0473259],
[0.466204, 0.239483, 0.0513461],
[0.472492, 0.241152, 0.0554646],
[0.478765, 0.242821, 0.0596797],
[0.485024, 0.244492, 0.0639898],
[0.491266, 0.246165, 0.0683938],
[0.49749, 0.247842, 0.0728908],
[0.503695, 0.249526, 0.0774801],
[0.50988, 0.251217, 0.082161],
[0.516042, 0.252918, 0.086933],
[0.522181, 0.25463, 0.091796],
[0.528296, 0.256355, 0.0967495],
[0.534385, 0.258094, 0.101793],
[0.540447, 0.25985, 0.106928],
[0.54648, 0.261623, 0.112152],
[0.552484, 0.263417, 0.117466],
[0.558456, 0.265232, 0.122871],
[0.564396, 0.267071, 0.128365],
[0.570302, 0.268935, 0.133949],
[0.576173, 0.270826, 0.139623],
[0.582007, 0.272745, 0.145386],
[0.587804, 0.274695, 0.151238],
[0.593562, 0.276678, 0.157179],
[0.599279, 0.278694, 0.163209],
[0.604955, 0.280746, 0.169327],
[0.610587, 0.282835, 0.175532],
[0.616176, 0.284964, 0.181825],
[0.621719, 0.287133, 0.188204],
[0.627216, 0.289345, 0.194668],
[0.632664, 0.291601, 0.201218],
[0.638063, 0.293902, 0.207851],
[0.643412, 0.296251, 0.214568],
[0.648709, 0.298648, 0.221366],
[0.653954, 0.301095, 0.228245],
[0.659144, 0.303593, 0.235203],
[0.664279, 0.306144, 0.242239],
[0.669358, 0.30875, 0.249352],
[0.67438, 0.311411, 0.256539],
[0.679343, 0.314128, 0.263799],
[0.684246, 0.316903, 0.27113],
[0.689089, 0.319738, 0.278531],
[0.693871, 0.322631, 0.285999],
[0.698589, 0.325586, 0.293531],
[0.703245, 0.328603, 0.301127],
[0.707835, 0.331682, 0.308782],
[0.71236, 0.334825, 0.316496],
[0.716819, 0.338031, 0.324265],
[0.721211, 0.341303, 0.332087],
[0.725535, 0.34464, 0.339958],
[0.729791, 0.348042, 0.347876],
[0.733977, 0.351511, 0.355839],
[0.738093, 0.355047, 0.363843],
[0.742139, 0.35865, 0.371884],
[0.746113, 0.36232, 0.37996],
[0.750016, 0.366057, 0.388068],
[0.753847, 0.369862, 0.396204],
[0.757605, 0.373735, 0.404365],
[0.761289, 0.377675, 0.412548],
[0.764901, 0.381682, 0.420748],
[0.768439, 0.385757, 0.428963],
[0.771904, 0.389899, 0.437188],
[0.775294, 0.394107, 0.445421],
[0.778611, 0.398382, 0.453657],
[0.781853, 0.402723, 0.461894],
[0.785022, 0.407129, 0.470127],
[0.788116, 0.411601, 0.478352],
[0.791137, 0.416136, 0.486567],
[0.794085, 0.420736, 0.494767],
[0.79696, 0.425398, 0.502949],
[0.799761, 0.430122, 0.511109],
[0.802491, 0.434908, 0.519243],
[0.805149, 0.439755, 0.527349],
[0.807736, 0.444661, 0.535422],
[0.810252, 0.449625, 0.543459],
[0.812699, 0.454647, 0.551456],
[0.815077, 0.459726, 0.559411],
[0.817387, 0.46486, 0.56732],
[0.819631, 0.470049, 0.575179],
[0.821809, 0.47529, 0.582986],
[0.823922, 0.480583, 0.590738],
[0.825971, 0.485927, 0.598431],
[0.827959, 0.49132, 0.606063],
[0.829886, 0.496762, 0.613631],
[0.831754, 0.502249, 0.621132],
[0.833565, 0.507783, 0.628563],
[0.83532, 0.513359, 0.635923],
[0.83702, 0.518979, 0.643209],
[0.838669, 0.524639, 0.650419],
[0.840266, 0.530339, 0.65755],
[0.841816, 0.536077, 0.6646],
[0.843319, 0.541852, 0.671569],
[0.844777, 0.547662, 0.678453],
[0.846194, 0.553505, 0.685252],
[0.84757, 0.559381, 0.691964],
[0.848909, 0.565287, 0.698588],
[0.850213, 0.571222, 0.705122],
[0.851485, 0.577185, 0.711565],
[0.852726, 0.583175, 0.717918],
[0.853939, 0.589188, 0.724178],
[0.855128, 0.595225, 0.730345],
[0.856295, 0.601284, 0.736419],
[0.857441, 0.607363, 0.742399],
[0.858572, 0.61346, 0.748285],
[0.859688, 0.619575, 0.754077],
[0.860793, 0.625706, 0.759776],
[0.86189, 0.631852, 0.76538],
[0.862982, 0.638011, 0.770891],
[0.864072, 0.644181, 0.776309],
[0.865163, 0.650362, 0.781634],
[0.866257, 0.656553, 0.786867],
[0.867358, 0.662752, 0.79201],
[0.86847, 0.668957, 0.797061],
[0.869594, 0.675168, 0.802024],
[0.870734, 0.681383, 0.806898],
[0.871893, 0.687602, 0.811686],
[0.873074, 0.693823, 0.816387],
[0.87428, 0.700046, 0.821004],
[0.875514, 0.706268, 0.825539],
[0.876779, 0.712489, 0.829992],
[0.878078, 0.718709, 0.834365],
[0.879415, 0.724926, 0.838661],
[0.880791, 0.73114, 0.84288],
[0.882209, 0.737349, 0.847025],
[0.883674, 0.743552, 0.851098],
[0.885186, 0.74975, 0.855101],
[0.88675, 0.755942, 0.859036],
[0.888367, 0.762125, 0.862904],
[0.89004, 0.768301, 0.866709],
[0.891772, 0.774468, 0.870452],
[0.893565, 0.780626, 0.874136],
[0.895421, 0.786775, 0.877763],
[0.897344, 0.792913, 0.881335],
[0.899334, 0.79904, 0.884856],
[0.901395, 0.805156, 0.888326],
[0.903528, 0.811261, 0.89175],
[0.905735, 0.817354, 0.895129],
[0.908018, 0.823435, 0.898465],
[0.910378, 0.829504, 0.901763],
[0.912819, 0.83556, 0.905023],
[0.91534, 0.841603, 0.90825],
[0.917944, 0.847634, 0.911444],
[0.920632, 0.853651, 0.914611],
[0.923406, 0.859654, 0.917751],
[0.926266, 0.865645, 0.920867],
[0.929213, 0.871622, 0.923964],
[0.932249, 0.877586, 0.927042],
[0.935375, 0.883536, 0.930106],
[0.938591, 0.889472, 0.933158],
[0.941897, 0.895396, 0.936201],
[0.945296, 0.901306, 0.939238],
[0.948787, 0.907202, 0.942272],
[0.95237, 0.913086, 0.945306],
[0.956047, 0.918956, 0.948344],
[0.959817, 0.924814, 0.95139],
[0.96368, 0.930658, 0.954445],
[0.967637, 0.936489, 0.957515],
[0.971688, 0.942308, 0.960604],
[0.975834, 0.948114, 0.963715],
[0.980073, 0.953907, 0.966855],
[0.984406, 0.959687, 0.970028],
[0.988834, 0.965453, 0.973242],
[0.993358, 0.971206, 0.976505],
[0.997977, 0.976943, 0.979829],
[1., 0.982662, 0.983234],
[1., 0.988357, 0.986754],
[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()
