def test_edge_color_colormap(): """Test creating Vectors where edge color is set by a colormap""" shape = (10, 2) shape = (10, 2, 2) data = np.random.random(shape) data[:, 0, :] = 20 * data[:, 0, :] properties = {'angle': np.array([0, 1.5] * int(shape[0] / 2))} layer = Vectors( data, properties=properties, edge_color='angle', edge_colormap='gray', ) np.testing.assert_equal(layer.properties, properties) assert layer.edge_color_mode == 'colormap' edge_color_array = transform_color(['black', 'white'] * int(shape[0] / 2)) assert np.all(layer.edge_color == edge_color_array) # change the color cycle - edge_color should not change layer.edge_color_cycle = ['red', 'blue'] assert np.all(layer.edge_color == edge_color_array) # adjust the clims layer.edge_contrast_limits = (0, 3) layer.refresh_colors(update_color_mapping=False) np.testing.assert_allclose(layer.edge_color[-1], [0.5, 0.5, 0.5, 1]) # change the colormap new_colormap = 'viridis' layer.edge_colormap = new_colormap assert layer.edge_colormap.name == new_colormap # test adding a colormap with a vispy Colormap object layer.edge_colormap = get_colormap('gray') assert 'unnamed colormap' in layer.edge_colormap.name
def test_empty_layer_with_edge_color_cycle(): """ Test creating an empty layer where the edge color is a color cycle """ shape = (0, 2, 2) data = np.empty(shape) default_properties = {'vector_type': np.array(['A'])} layer = Vectors( data=data, properties=default_properties, edge_color='vector_type', ) assert layer.edge_color_mode == 'cycle' # edge_color should remain empty when refreshing colors layer.refresh_colors(update_color_mapping=True) np.testing.assert_equal(layer.edge_color, np.empty((0, 4)))
def test_empty_layer_with_edge_colormap(): """Test creating an empty layer where the edge color is a colormap""" shape = (0, 2, 2) data = np.empty(shape) default_properties = {'angle': np.array([1.5], dtype=float)} layer = Vectors( data=data, property_choices=default_properties, edge_color='angle', edge_colormap='grays', ) assert layer.edge_color_mode == 'colormap' # edge_color should remain empty when refreshing colors layer.refresh_colors(update_color_mapping=True) np.testing.assert_equal(layer.edge_color, np.empty((0, 4)))