示例#1
0
    def test_standalone_rainforest(self):
        # Obtain the currently registered version of rainforest
        cmap_old = mplcm.get_cmap('cmr.rainforest')

        # Create standalone module for rainforest
        cmap_path = create_cmap_mod('rainforest')

        # Try to import this module
        spec = spec_from_file_location('rainforest', cmap_path)
        mod = module_from_spec(spec)
        spec.loader.exec_module(mod)

        # Check if the colormap in MPL has been updated
        cmap_new = mplcm.get_cmap('cmr.rainforest')
        assert cmap_new is mod.cmap
        assert cmap_old is not cmap_new

        # Check if the values in both colormaps are the same
        assert np.allclose(cmap_old.colors, cmap_new.colors)
示例#2
0
 def test_invalid_cmap(self):
     # Check if a ValueError is raised
     with pytest.raises(ValueError):
         create_cmap_mod('this is an incorrect colormap name')
示例#3
0
    # Obtain RGB values of colormap
    v = viscm.viscm_editor(uniform_space=cmap.uniform_space,
                           cmtype=cmap.cmtype,
                           method=cmap.method,
                           **cmap.params)
    rgb, _ = v.cmap_model.get_sRGB()

    # Register this colormap in CMasher
    register_cmap(name, rgb)

    # Obtain cmtype
    cmtype = get_cmap_type('cmr.{0}'.format(name))

    # Export as .py-file
    create_cmap_mod(name, save_dir=name)

    # Create colormap figure
    fig, ax = plt.subplots(figsize=(12.8, 3.2))
    ax.imshow(rgb[np.newaxis, ...], aspect='auto')
    ax.set_axis_off()
    plt.savefig("{0}/{0}.png".format(name),
                dpi=100,
                bbox_inches='tight',
                pad_inches=0)
    plt.close(fig)

    # Create txt-file with colormap data
    np.savetxt("cm_{0}.txt".format(name), rgb, fmt='%.8f')

    # Create txt-file with normalized colormap data