def test_colours(): """Test colour conversions. """ assert rgb_to_hex([0, 0, 0]) == '#000000' assert rgb_to_hex([255, 128, 128]) == '#FF8080' assert hex_to_rgb('#000000') == (0, 0, 0) assert hex_to_rgb('#ff8080') == (255, 128, 128) # case
def striplog_legend_to_omf_legend(legend): """ Creates an omf.data.Legend object from a striplog.Legend object Parameters ----------- legend : striplog.Legend object Returns -------- omf.data.Legend Legends to be used with DataMap indices ListedColormap(new_colors) matplotlib colormap """ # we must add colors as a parameter to allow to change colors style omf_legend = [] new_colors = [np.array([0.9, 0.9, 0.9, 1.])] for i in legend: omf_legend.append(i.colour) new_colors.append( np.hstack([np.array(hex_to_rgb(i.colour)) / 255, np.array([1.])])) return omf.data.Legend( description='', name='', values=omf.data.ColorArray(omf_legend)), ListedColormap(new_colors)
def test_colours(): """Test colour conversions. """ assert rgb_to_hex([0, 0, 0]) == '#000000' assert rgb_to_hex([0, 0.5, 0.5]) == '#008080' assert rgb_to_hex([255, 128, 128]) == '#ff8080' assert hex_to_rgb('#000000') == (0, 0, 0) assert hex_to_rgb('#ff8080') == (255, 128, 128) # case # And exceptions: with pytest.raises(Exception): _ = rgb_to_hex([0, 0, -1]) assert _ with pytest.raises(Exception): _ = rgb_to_hex([0, 0, 256]) assert _ with pytest.raises(Exception): _ = rgb_to_hex([0, 0.1, 2]) assert _
def test_colours(): assert rgb_to_hex([0, 0, 0]) == '#000000' assert rgb_to_hex([255, 128, 128]) == '#FF8080' assert hex_to_rgb('#000000') == (0, 0, 0) assert hex_to_rgb('#ff8080') == (255, 128, 128) # case
def test_colours(): assert rgb_to_hex([0, 0, 0]) == "#000000" assert rgb_to_hex([255, 128, 128]) == "#FF8080" assert hex_to_rgb("#000000") == (0, 0, 0) assert hex_to_rgb("#ff8080") == (255, 128, 128) # case