Exemplo n.º 1
0
def test_edge_color_map_non_numeric_property():
    """Test setting edge_color as a color map of a
    non-numeric property raises an error
    """
    np.random.seed(0)
    shape = (10, 2, 2)
    data = np.random.random(shape)
    data[:, 0, :] = 20 * data[:, 0, :]
    properties = {'vector_type': np.array(['A', 'B'] * int((shape[0] / 2)))}
    color_cycle = ['red', 'blue']
    initial_color = [0, 1, 0, 1]
    layer = Vectors(
        data,
        properties=properties,
        edge_color=initial_color,
        edge_color_cycle=color_cycle,
        edge_colormap='gray',
    )
    # layer should start out in direct edge color mode with all green vectors
    assert layer.edge_color_mode == 'direct'
    np.testing.assert_allclose(layer.edge_color,
                               np.repeat([initial_color], shape[0], axis=0))

    # switching to colormap mode should raise an error because the 'vector_type' is non-numeric
    layer.edge_color = 'vector_type'
    with pytest.raises(TypeError):
        layer.edge_color_mode = 'colormap'
Exemplo n.º 2
0
def test_properties_color_mode_without_properties():
    """Test that switching to a colormode requiring
    properties without properties defined raises an exceptions
    """
    np.random.seed(0)
    shape = (10, 2, 2)
    data = np.random.random(shape)
    data[:, 0, :] = 20 * data[:, 0, :]
    layer = Vectors(data)
    assert layer.properties == {}

    with pytest.raises(ValueError):
        layer.edge_color_mode = 'colormap'

    with pytest.raises(ValueError):
        layer.edge_color_mode = 'cycle'
Exemplo n.º 3
0
def test_switching_edge_color_mode():
    """Test transitioning between all color modes"""
    np.random.seed(0)
    shape = (10, 2, 2)
    data = np.random.random(shape)
    data[:, 0, :] = 20 * data[:, 0, :]
    properties = {
        'magnitude': np.arange(shape[0]),
        'vector_type': np.array(['A', 'B'] * int(shape[0] / 2)),
    }
    color_cycle = ['red', 'blue']
    initial_color = [0, 1, 0, 1]
    layer = Vectors(
        data,
        properties=properties,
        edge_color=initial_color,
        edge_color_cycle=color_cycle,
        edge_colormap='gray',
    )
    # layer should start out in direct edge color mode with all green vectors
    assert layer.edge_color_mode == 'direct'
    np.testing.assert_allclose(
        layer.edge_color, np.repeat([initial_color], shape[0], axis=0)
    )

    # there should not be an edge_color_property
    assert layer._edge_color_property == ''

    # transitioning to colormap should raise a warning
    # because there isn't an edge color property yet and
    # the first property in Vectors.properties is being automatically selected
    with pytest.warns(RuntimeWarning):
        layer.edge_color_mode = 'colormap'
    assert layer._edge_color_property == next(iter(properties))
    np.testing.assert_allclose(layer.edge_color[-1], [1, 1, 1, 1])

    # switch to color cycle
    layer.edge_color_mode = 'cycle'
    layer.edge_color = 'vector_type'
    edge_color_array = transform_color(color_cycle * int(shape[0] / 2))
    np.testing.assert_allclose(layer.edge_color, edge_color_array)

    # switch back to direct, edge_colors shouldn't change
    edge_colors = layer.edge_color
    layer.edge_color_mode = 'direct'
    np.testing.assert_allclose(layer.edge_color, edge_colors)