Exemplo n.º 1
0
def test_reactive_draw():
    """Test reactive RectPolygon attributes"""
    with TestingCanvas() as c:
        rectpolygon = visuals.Rectangle(center=(50, 50, 0), height=40.,
                                        width=80., color='red',
                                        parent=c.scene)

        rectpolygon.radius = [20., 20, 0., 10.]

        assert_image_approved(c.render(),
                              'visuals/reactive_rectpolygon1.png')

        rectpolygon.center = (60, 60, 0)

        assert_image_approved(c.render(),
                              'visuals/reactive_rectpolygon2.png')

        rectpolygon.color = 'blue'

        assert_image_approved(c.render(),
                              'visuals/reactive_rectpolygon3.png')

        rectpolygon.border_color = 'yellow'

        assert_image_approved(c.render(),
                              'visuals/reactive_rectpolygon4.png')

        rectpolygon.radius = 10.

        assert_image_approved(c.render(),
                              'visuals/reactive_rectpolygon5.png')
Exemplo n.º 2
0
def test_perspective_render():
    with TestingCanvas(size=(120, 200)) as canvas:

        grid = canvas.central_widget.add_grid()
        imdata = io.load_crate().astype('float32') / 255

        views = []
        images = []
        for i, imethod in enumerate(['impostor', 'subdivide']):
            v = grid.add_view(row=i, col=0, border_color='white')
            v.camera = 'turntable'
            v.camera.fov = 50
            v.camera.distance = 30

            views.append(v)
            image = scene.visuals.Image(imdata, method=imethod, grid=(4, 4))
            image.transform = scene.STTransform(translate=(-12.8, -12.8),
                                                scale=(0.1, 0.1))
            v.add(image)
            images.append(image)

        image = canvas.render()
        canvas.close()

        # Allow many pixels to differ by a small amount--texture sampling and
        # exact triangle position will differ across platforms. However a
        # change in perspective or in the widget borders should trigger a
        # failure.
        assert_image_approved(image,
                              'scene/cameras/perspective_test.png',
                              'perspective test 1: 2 identical views with '
                              'correct perspective',
                              px_threshold=20,
                              px_count=60,
                              max_px_diff=200)
Exemplo n.º 3
0
def test_spectrogram():
    """Test spectrogram visual"""
    n_fft = 256
    n_freqs = n_fft // 2 + 1
    size = (100, n_freqs)
    with TestingCanvas(size=size) as c:
        np.random.seed(67853498)
        data = np.random.normal(size=n_fft * 100)
        spec = Spectrogram(data, n_fft=n_fft, step=n_fft, window=None,
                           color_scale='linear', cmap='grays')
        c.draw_visual(spec)
        #expected = np.zeros(size[::-1] + (3,))
        #expected[0] = 1.
        assert_image_approved("screenshot", "visuals/spectrogram.png")
        freqs = spec.freqs
        assert len(freqs) == n_freqs
        assert freqs[0] == 0
        assert freqs[-1] == 0.5

        # Try changing all properties
        spec.n_fft = 128
        spec.step = 128
        spec.fs = 2
        spec.window = 'hann'
        spec.normalize = True
        spec.color_scale = 'log'

        # Check color scale can be only 'log' or 'linear'
        with raises(ValueError):
            spec.color_scale = 'line_log'
Exemplo n.º 4
0
def test_reactive_draw():
    """Test reactive regular polygon attributes"""
    with TestingCanvas() as c:
        rpolygon = visuals.RegularPolygon(pos=[50, 50, 0.], radius=20, sides=8,
                                          color='yellow')
        c.draw_visual(rpolygon)

        rpolygon.pos = [70, 40, 0.]
        c.draw_visual(rpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_regular_polygon1.png')

        rpolygon.radius = 25
        c.draw_visual(rpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_regular_polygon2.png')

        rpolygon.color = 'red'
        c.draw_visual(rpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_regular_polygon3.png')

        rpolygon.border_color = 'yellow'
        c.draw_visual(rpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_regular_polygon4.png')

        rpolygon.sides = 6
        c.draw_visual(rpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_regular_polygon5.png')
Exemplo n.º 5
0
def test_reactive_draw():
    """Test reactive regular polygon attributes"""
    with TestingCanvas() as c:
        rpolygon = visuals.RegularPolygon(center=[50, 50, 0.], radius=20,
                                          sides=8,
                                          color='yellow',
                                          parent=c.scene)

        rpolygon.center = [70, 40, 0.]
        assert_image_approved(c.render(),
                              'visuals/reactive_regular_polygon1.png')

        rpolygon.radius = 25
        assert_image_approved(c.render(),
                              'visuals/reactive_regular_polygon2.png')

        rpolygon.color = 'red'
        assert_image_approved(c.render(),
                              'visuals/reactive_regular_polygon3.png')

        rpolygon.border_color = 'yellow'
        assert_image_approved(c.render(),
                              'visuals/reactive_regular_polygon4.png')

        rpolygon.sides = 6
        assert_image_approved(c.render(),
                              'visuals/reactive_regular_polygon5.png')
Exemplo n.º 6
0
def test_reactive_draw():
    """Test reactive RectPolygon attributes"""
    with TestingCanvas() as c:
        rectpolygon = visuals.Rectangle(pos=(50, 50, 0), height=40.,
                                        width=80., color='red')
        c.draw_visual(rectpolygon)

        rectpolygon.radius = [20., 20, 0., 10.]
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_rectpolygon1.png')

        rectpolygon.pos = (60, 60, 0)
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_rectpolygon2.png')

        rectpolygon.color = 'blue'
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_rectpolygon3.png')

        rectpolygon.border_color = 'yellow'
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_rectpolygon4.png')

        rectpolygon.radius = 10.
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_rectpolygon5.png')
Exemplo n.º 7
0
def test_arrow_transform_draw():
    """Tests the ArrowVisual when a transform is applied"""

    # TODO: fix AppVeyor - error comes up with bollu/vispy:cassowary-constaints
    # commit SHA: 29303009a76d5c6931b1991aa7bdf5192ace9c4f
    if os.getenv('APPVEYOR', '').lower() == 'true':
        raise SkipTest('AppVeyor has unknown failure')

    old_numpy = LooseVersion(np.__version__) < '1.8'
    if os.getenv('TRAVIS', 'false') == 'true' and (sys.version[:3] == '2.6'
                                                   or old_numpy):
        # TODO: Fix this (issue #1042
        raise SkipTest('Travis fails due to FB stack problem')

    with TestingCanvas() as c:
        for arrow_type in ARROW_TYPES:
            arrow = visuals.Arrow(pos=vertices,
                                  arrow_type=arrow_type,
                                  arrows=arrows,
                                  arrow_size=10,
                                  color='red',
                                  connect="segments",
                                  parent=c.scene)
            arrow.transform = transforms.STTransform(scale=(0.5, 0.75),
                                                     translate=(-20, -20))

            assert_image_approved(
                c.render(), 'visuals/arrow_transform_type_%s.png' % arrow_type)

            arrow.parent = None
Exemplo n.º 8
0
def test_text():
    """Test basic text support"""

    with TestingCanvas(bgcolor='w', size=(92, 92), dpi=92) as c:
        pos = [92 // 2] * 2
        text = Text('testing', font_size=20, color='k',
                    pos=pos, anchor_x='center', anchor_y='baseline',
                    parent=c.scene)
        # Test image created in Illustrator CS5, 1"x1" output @ 92 DPI
        assert_image_approved(c.render(), 'visuals/text1.png')
        
        text.text = ['foo', 'bar']
        text.pos = [10, 10]  # should auto-replicate
        try:
            text.pos = [10]
        except Exception:
            pass
        else:
            raise AssertionError('Exception not raised')
        c.update()
        c.app.process_events()
        text.pos = [[10, 10], [10, 20]]
        text.text = 'foobar'
        c.update()
        c.app.process_events()
Exemplo n.º 9
0
def test_set_data():
    """Test InfiniteLineVisual"""

    pos = 5.0
    color = [1.0, 1.0, 0.5, 0.5]
    expected_color = np.array(color, dtype=np.float32)

    for is_vertical, reference_image in [(True, 'infinite_line.png'),
                                         (False, 'infinite_line_h.png')]:

        with TestingCanvas() as c:
            # Check set_data is working correctly within visual constructor
            region = visuals.InfiniteLine(pos=pos,
                                          color=color,
                                          vertical=is_vertical,
                                          parent=c.scene)
            assert region.pos == pos
            assert np.all(region.color == expected_color)
            assert region.is_vertical == is_vertical

            # Check tuple color argument is accepted
            region.set_data(color=tuple(color))
            assert np.all(region.color == expected_color)

            assert_image_approved(c.render(), 'visuals/%s' % reference_image)

            # Check only numbers are accepted
            assert_raises(TypeError, region.set_data, pos=[[1, 2], [3, 4]])

            # Check color argument can be only a 4 length 1D array
            assert_raises(ValueError, region.set_data, color=[[1, 2], [3, 4]])
            assert_raises(ValueError, region.set_data, color=[1, 2])
Exemplo n.º 10
0
def test_reactive_draw():
    """Test reactive regular polygon attributes"""
    with TestingCanvas() as c:
        rpolygon = visuals.RegularPolygon(center=[50, 50, 0.],
                                          radius=20,
                                          sides=8,
                                          color='yellow',
                                          parent=c.scene)

        rpolygon.center = [70, 40, 0.]
        assert_image_approved(c.render(),
                              'visuals/reactive_regular_polygon1.png')

        rpolygon.radius = 25
        assert_image_approved(c.render(),
                              'visuals/reactive_regular_polygon2.png')

        rpolygon.color = 'red'
        assert_image_approved(c.render(),
                              'visuals/reactive_regular_polygon3.png')

        rpolygon.border_color = 'yellow'
        assert_image_approved(c.render(),
                              'visuals/reactive_regular_polygon4.png')

        rpolygon.sides = 6
        assert_image_approved(c.render(),
                              'visuals/reactive_regular_polygon5.png')
Exemplo n.º 11
0
def test_set_data():
    """Test InfiniteLineVisual"""
    pos = 5.0
    color = [1.0, 1.0, 0.5, 0.5]
    expected_color = np.array(color, dtype=np.float32)

    for is_vertical, reference_image in [(True, 'infinite_line.png'),
                                         (False, 'infinite_line_h.png')]:

        with TestingCanvas() as c:
            # Check set_data is working correctly within visual constructor
            region = visuals.InfiniteLine(pos=pos,
                                          color=color,
                                          vertical=is_vertical,
                                          parent=c.scene)
            assert region.pos == pos
            assert np.all(region.color == expected_color)
            assert region.is_vertical == is_vertical

            # Check tuple color argument is accepted
            region.set_data(color=tuple(color))
            assert np.all(region.color == expected_color)

            assert_image_approved(c.render(), 'visuals/%s' % reference_image)

            # Check only numbers are accepted
            assert_raises(TypeError, region.set_data, pos=[[1, 2], [3, 4]])

            # Check color argument can be only a 4 length 1D array
            assert_raises(ValueError, region.set_data, color=[[1, 2], [3, 4]])
            assert_raises(ValueError, region.set_data, color=[1, 2])
Exemplo n.º 12
0
def test_reactive_draw():
    """Test reactive RectPolygon attributes"""
    with TestingCanvas() as c:
        rectpolygon = visuals.Rectangle(center=(50, 50, 0),
                                        height=40.,
                                        width=80.,
                                        color='red',
                                        parent=c.scene)

        rectpolygon.radius = [20., 20, 0., 10.]

        assert_image_approved(c.render(), 'visuals/reactive_rectpolygon1.png')

        rectpolygon.center = (60, 60, 0)

        assert_image_approved(c.render(), 'visuals/reactive_rectpolygon2.png')

        rectpolygon.color = 'blue'

        assert_image_approved(c.render(), 'visuals/reactive_rectpolygon3.png')

        rectpolygon.border_color = 'yellow'

        assert_image_approved(c.render(), 'visuals/reactive_rectpolygon4.png')

        rectpolygon.radius = 10.

        assert_image_approved(c.render(), 'visuals/reactive_rectpolygon5.png')
Exemplo n.º 13
0
def test_rectangle_draw():
    """Test drawing rectpolygons without transform using RectPolygonVisual"""
    with TestingCanvas() as c:
        rectpolygon = visuals.Rectangle(pos=(50, 50, 0), height=40.,
                                        width=80., color='red')
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot", 'visuals/rectpolygon1.png')

        rectpolygon = visuals.Rectangle(pos=(50, 50, 0), height=40.,
                                        width=80., radius=10., color='red')
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot", 'visuals/rectpolygon2.png')

        rectpolygon = visuals.Rectangle(pos=(50, 50, 0), height=40.,
                                        width=80., radius=10., color='red',
                                        border_color=(0, 1, 1, 1))
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot", 'visuals/rectpolygon3.png')

        rectpolygon = visuals.Rectangle(pos=(50, 50, 0), height=40.,
                                        width=80., radius=10.,
                                        border_color='white')
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot", 'visuals/rectpolygon4.png',
                              min_corr=0.5)

        rectpolygon = visuals.Rectangle(pos=(50, 50, 0), height=60.,
                                        width=80., radius=[25, 10, 0, 15],
                                        color='red', border_color=(0, 1, 1, 1))
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot", 'visuals/rectpolygon5.png')
Exemplo n.º 14
0
def test_linear_region_vertical_horizontal():
    """Test vertical and horizontal LinearRegionVisual with a single color"""

    # Definition of the region
    pos = np.array([5, 15, 24, 36, 40, 42], dtype=np.float32)
    # Expected internal pos buffer for vertical region
    expected_pos_v = np.array([[5.0, -1.],
                               [5.0, 1.],
                               [15.0, -1.],
                               [15.0, 1.],
                               [24.0, -1.],
                               [24.0, 1.],
                               [36.0, -1.],
                               [36.0, 1.],
                               [40.0, -1.],
                               [40.0, 1.],
                               [42.0, -1.],
                               [42.0, 1.]], dtype=np.float32)
    # Expected internal pos buffer for horizontal region
    expected_pos_h = np.array([expected_pos_v[:, 1] * -1,
                               expected_pos_v[:, 0]], dtype=np.float32).T

    # Test both horizontal and vertical region
    for is_vertical, reference_image in [(True, 'linear_region1.png'),
                                         (False, 'linear_region1_h.png')]:

        expected_pos = expected_pos_v if is_vertical else expected_pos_h

        with TestingCanvas() as c:
            # Check set_data is working correctly within visual constructor
            region = visuals.LinearRegion(pos=pos,
                                          color=[0.0, 1.0, 0.0, 0.5],
                                          vertical=is_vertical,
                                          parent=c.scene)
            assert np.all(region._pos == expected_pos)
            assert np.all(region.pos == pos)
            assert region.is_vertical == is_vertical

            # Check set_data is working as expected when passing a list as
            # pos argument
            region.set_data(pos=list(pos))
            assert np.all(region._pos == expected_pos)
            assert np.all(region.pos == pos)

            # Check set_data is working as expected when passing a tuple as
            # pos argument
            region.set_data(pos=tuple(pos))
            assert np.all(region._pos == expected_pos)
            assert np.all(region.pos == pos)

            # Test with different dtypes that must be converted to float32
            for t in [np.int64, np.float64, np.int32]:
                region.set_data(pos=pos.astype(t))
                assert np.all(region._pos == expected_pos)
                assert np.all(region.pos == pos)

            assert_image_approved(c.render(), 'visuals/%s' % reference_image)

            # Check ValueError is raised when pos is not 1D
            assert_raises(ValueError, region.set_data, pos=[[1, 2], [3, 4]])
Exemplo n.º 15
0
def test_reactive_draw():
    """Test reactive RectPolygon attributes"""
    with TestingCanvas() as c:
        rectpolygon = visuals.Rectangle(pos=(50, 50, 0),
                                        height=40.,
                                        width=80.,
                                        color='red')
        c.draw_visual(rectpolygon)

        rectpolygon.radius = [20., 20, 0., 10.]
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_rectpolygon1.png')

        rectpolygon.pos = (60, 60, 0)
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_rectpolygon2.png')

        rectpolygon.color = 'blue'
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_rectpolygon3.png')

        rectpolygon.border_color = 'yellow'
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_rectpolygon4.png')

        rectpolygon.radius = 10.
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot",
                              'visuals/reactive_rectpolygon5.png')
Exemplo n.º 16
0
def test_arrow_transform_draw():
    """Tests the ArrowVisual when a transform is applied"""

    # TODO: fix AppVeyor - error comes up with bollu/vispy:cassowary-constaints
    # commit SHA: 29303009a76d5c6931b1991aa7bdf5192ace9c4f
    if os.getenv('APPVEYOR', '').lower() == 'true':
        raise SkipTest('AppVeyor has unknown failure')

    old_numpy = LooseVersion(np.__version__) < '1.8'
    if os.getenv('TRAVIS', 'false') == 'true' and (sys.version[:3] == '2.6' or
                                                   old_numpy):
        # TODO: Fix this (issue #1042
        raise SkipTest('Travis fails due to FB stack problem')

    with TestingCanvas() as c:
        for arrow_type in ARROW_TYPES:
            arrow = visuals.Arrow(pos=vertices, arrow_type=arrow_type,
                                  arrows=arrows, arrow_size=10, color='red',
                                  connect="segments", parent=c.scene)
            arrow.transform = transforms.STTransform(scale=(0.5, 0.75),
                                                     translate=(-20, -20))

            assert_image_approved(c.render(),
                                  'visuals/arrow_transform_type_%s.png' %
                                  arrow_type)

            arrow.parent = None
Exemplo n.º 17
0
def test_colormap_coolwarm():
    """Test colormap support using coolwarm preset colormap"""
    with TestingCanvas(size=size, bgcolor='w') as c:
        idata = np.linspace(255, 0, size[0] * size[1]).astype(np.ubyte)
        data = idata.reshape((size[0], size[1]))
        image = Image(cmap='coolwarm', clim='auto', parent=c.scene)
        image.set_data(data)
        assert_image_approved(c.render(), "visuals/colormap_coolwarm.png")
Exemplo n.º 18
0
def test_colormap_coolwarm():
    """Test colormap support using coolwarm preset colormap"""
    with TestingCanvas(size=size, bgcolor='w') as c:
        idata = np.linspace(255, 0, size[0]*size[1]).astype(np.ubyte)
        data = idata.reshape((size[0], size[1]))
        image = Image(cmap='coolwarm', clim='auto', parent=c.scene)
        image.set_data(data)
        assert_image_approved(c.render(), "visuals/colormap_coolwarm.png")
Exemplo n.º 19
0
def test_colormap_single_hue():
    """Test colormap support using a single hue()"""
    with TestingCanvas(size=size, bgcolor='w') as c:
        idata = np.linspace(255, 0, size[0]*size[1]).astype(np.ubyte)
        data = idata.reshape((size[0], size[1]))
        image = Image(cmap=get_colormap('single_hue', 255),
                      clim='auto', parent=c.scene)
        image.set_data(data)
        assert_image_approved(c.render(), "visuals/colormap_hue.png")
Exemplo n.º 20
0
def test_colormap_CubeHelix():
    """Test colormap support using cubehelix colormap in only blues"""
    with TestingCanvas(size=size, bgcolor='w') as c:
        idata = np.linspace(255, 0, size[0]*size[1]).astype(np.ubyte)
        data = idata.reshape((size[0], size[1]))
        image = Image(cmap=get_colormap('cubehelix', rot=0, start=0),
                      clim='auto', parent=c.scene)
        image.set_data(data)
        assert_image_approved(c.render(), "visuals/colormap_cubehelix.png")
Exemplo n.º 21
0
def test_colorbar_widget():
    with TestingCanvas() as c:
        colorbar_top = create_colorbar(pos=(50, 50),
                                       label="my label",
                                       orientation='top')

        c.draw_visual(colorbar_top)
        assert_image_approved(c.render(), 'visuals/colorbar/top.png')
        assert colorbar_top.label.text == "my label"
Exemplo n.º 22
0
def test_colormap_discrete_nu():
    """Test discrete colormap with non-uniformly distributed control-points"""
    with TestingCanvas(size=size, bgcolor='w') as c:
        idata = np.linspace(255, 0, size[0]*size[1]).astype(np.ubyte)
        data = idata.reshape((size[0], size[1]))
        image = Image(cmap=Colormap(np.array([[0, .75, 0], [.75, .25, .5]]),
                      [0., .25, 1.], interpolation='zero'),
                      clim='auto', parent=c.scene)
        image.set_data(data)
        assert_image_approved(c.render(), "visuals/colormap_nu.png")
Exemplo n.º 23
0
def test_colormap_CubeHelix():
    """Test colormap support using cubehelix colormap in only blues"""
    with TestingCanvas(size=size, bgcolor='w') as c:
        idata = np.linspace(255, 0, size[0] * size[1]).astype(np.ubyte)
        data = idata.reshape((size[0], size[1]))
        image = Image(cmap=get_colormap('cubehelix', rot=0, start=0),
                      clim='auto',
                      parent=c.scene)
        image.set_data(data)
        assert_image_approved(c.render(), "visuals/colormap_cubehelix.png")
Exemplo n.º 24
0
def test_text():
    """Test basic text support"""
    
    with TestingCanvas(bgcolor='w', size=(92, 92), dpi=92) as c:
        pos = [92 // 2] * 2
        text = Text('testing', font_size=20, color='k',
                    pos=pos, anchor_x='center', anchor_y='baseline')
        c.draw_visual(text)
        # Test image created in Illustrator CS5, 1"x1" output @ 92 DPI
        assert_image_approved("screenshot", 'visuals/text1.png')
Exemplo n.º 25
0
def test_colormap_discrete():
    """Test discrete RGB colormap"""
    with TestingCanvas(size=size, bgcolor='w') as c:
        idata = np.linspace(255, 0, size[0]*size[1]).astype(np.ubyte)
        data = idata.reshape((size[0], size[1]))
        image = Image(cmap=Colormap(colors=['r', 'g', 'b'],
                      interpolation='zero'),
                      clim='auto', parent=c.scene)
        image.set_data(data)
        assert_image_approved(c.render(), "visuals/colormap_rgb.png")
Exemplo n.º 26
0
def test_colormap_single_hue():
    """Test colormap support using a single hue()"""
    with TestingCanvas(size=size, bgcolor='w') as c:
        idata = np.linspace(255, 0, size[0] * size[1]).astype(np.ubyte)
        data = idata.reshape((size[0], size[1]))
        image = Image(cmap=get_colormap('single_hue', 255),
                      clim='auto',
                      parent=c.scene)
        image.set_data(data)
        assert_image_approved(c.render(), "visuals/colormap_hue.png")
Exemplo n.º 27
0
def test_histogram():
    """Test histogram visual"""
    size = (200, 100)
    with TestingCanvas(size=size, bgcolor='w') as c:
        np.random.seed(2397)
        data = np.random.normal(size=100)
        hist = Histogram(data, bins=20, color='k', parent=c.scene)
        hist.transform = STTransform((size[0] // 10, -size[1] // 20, 1),
                                     (100, size[1]))
        assert_image_approved(c.render(), "visuals/histogram.png")
Exemplo n.º 28
0
def test_colormap():
    """Test colormap support for non-uniformly distributed control-points"""
    with TestingCanvas(size=size, bgcolor='w') as c:
        idata = np.linspace(255, 0, size[0]*size[1]).astype(np.ubyte)
        data = idata.reshape((size[0], size[1]))
        image = Image(cmap=Colormap(colors=['k', 'w', 'r'],
                      controls=[0.0, 0.1, 1.0]),
                      clim='auto', parent=c.scene)
        image.set_data(data)
        assert_image_approved(c.render(), "visuals/colormap_kwr.png")
Exemplo n.º 29
0
def test_histogram():
    """Test histogram visual"""
    size = (200, 100)
    with TestingCanvas(size=size, bgcolor='w') as c:
        np.random.seed(2397)
        data = np.random.normal(size=100)
        hist = Histogram(data, bins=20, color='k')
        hist.transform = STTransform((size[0] // 10, -size[1] // 20, 1),
                                     (100, size[1]))
        c.draw_visual(hist)
        assert_image_approved("screenshot", "visuals/histogram.png")
Exemplo n.º 30
0
def test_rectangle_draw():
    """Test drawing rectpolygons without transform using RectPolygonVisual"""
    with TestingCanvas() as c:
        rectpolygon = visuals.Rectangle(center=(50, 50, 0),
                                        height=40.,
                                        width=80.,
                                        color='red',
                                        parent=c.scene)

        assert_image_approved(c.render(), 'visuals/rectpolygon1.png')

        rectpolygon.parent = None
        rectpolygon = visuals.Rectangle(center=(50, 50, 0),
                                        height=40.,
                                        width=80.,
                                        radius=10.,
                                        color='red',
                                        parent=c.scene)

        assert_image_approved(c.render(), 'visuals/rectpolygon2.png')

        rectpolygon.parent = None
        rectpolygon = visuals.Rectangle(center=(50, 50, 0),
                                        height=40.,
                                        width=80.,
                                        radius=10.,
                                        color='red',
                                        border_color=(0, 1, 1, 1),
                                        parent=c.scene)

        assert_image_approved(c.render(), 'visuals/rectpolygon3.png')

        rectpolygon.parent = None
        rectpolygon = visuals.Rectangle(center=(50, 50, 0),
                                        height=40.,
                                        width=80.,
                                        radius=10.,
                                        border_color='white',
                                        parent=c.scene)

        assert_image_approved(c.render(),
                              'visuals/rectpolygon4.png',
                              min_corr=0.5)

        rectpolygon.parent = None
        rectpolygon = visuals.Rectangle(center=(50, 50, 0),
                                        height=60.,
                                        width=80.,
                                        radius=[25, 10, 0, 15],
                                        color='red',
                                        border_color=(0, 1, 1, 1),
                                        parent=c.scene)

        assert_image_approved(c.render(), 'visuals/rectpolygon5.png')
Exemplo n.º 31
0
def test_image(is_3d):
    """Test image visual"""
    size = (100, 50)
    with TestingCanvas(size=size, bgcolor='w') as c:
        image = Image(cmap='grays', clim=[0, 1], parent=c.scene)
        shape = (size[1] - 10, size[0] - 10) + ((3, ) if is_3d else ())
        np.random.seed(379823)
        data = np.random.rand(*shape)
        image.set_data(data)
        assert_image_approved(
            c.render(), "visuals/image%s.png" % ("_rgb" if is_3d else "_mono"))
Exemplo n.º 32
0
def test_colormap_discrete():
    """Test discrete RGB colormap"""
    with TestingCanvas(size=size, bgcolor='w') as c:
        idata = np.linspace(255, 0, size[0] * size[1]).astype(np.ubyte)
        data = idata.reshape((size[0], size[1]))
        image = Image(cmap=Colormap(colors=['r', 'g', 'b'],
                                    interpolation='zero'),
                      clim='auto',
                      parent=c.scene)
        image.set_data(data)
        assert_image_approved(c.render(), "visuals/colormap_rgb.png")
Exemplo n.º 33
0
def test_arrow_reactive():
    """Tests the reactive behaviour of the ArrowVisual properties."""
    with TestingCanvas() as c:
        arrow = visuals.Arrow(pos=vertices, arrows=arrows,
                              connect="segments", parent=c.scene)

        arrow.arrow_type = "stealth"
        assert_image_approved(c.render(), 'visuals/arrow_reactive1.png')

        arrow.arrow_size = 20
        assert_image_approved(c.render(), 'visuals/arrow_reactive2.png')
Exemplo n.º 34
0
def test_colormap():
    """Test colormap support for non-uniformly distributed control-points"""
    with TestingCanvas(size=size, bgcolor='w') as c:
        idata = np.linspace(255, 0, size[0] * size[1]).astype(np.ubyte)
        data = idata.reshape((size[0], size[1]))
        image = Image(cmap=Colormap(colors=['k', 'w', 'r'],
                                    controls=[0.0, 0.1, 1.0]),
                      clim='auto',
                      parent=c.scene)
        image.set_data(data)
        assert_image_approved(c.render(), "visuals/colormap_kwr.png")
Exemplo n.º 35
0
def test_image():
    """Test image visual"""
    size = (100, 50)
    with TestingCanvas(size=size, bgcolor='w') as c:
        image = Image(cmap='grays', clim=[0, 1], parent=c.scene)
        for three_d in (True, False):
            shape = (size[1]-10, size[0]-10) + ((3,) if three_d else ())
            np.random.seed(379823)
            data = np.random.rand(*shape)
            image.set_data(data)
            assert_image_approved(c.render(), "visuals/image%s.png" %
                                  ("_rgb" if three_d else "_mono"))
Exemplo n.º 36
0
def test_windbarb_draw():
    """Test drawing arrows without transforms"""
    with TestingCanvas(size=(250, 33), bgcolor='white') as c:

        Windbarb(pos=grid,
                 wind=vectors,
                 trig=False,
                 edge_color='black',
                 face_color='black',
                 size=length,
                 parent=c.scene)
        assert_image_approved(c.render(), 'visuals/windbarb.png')
Exemplo n.º 37
0
def test_image():
    """Test image visual"""
    size = (100, 50)
    with TestingCanvas(size=size, bgcolor='w') as c:
        for three_d in (True, False):
            shape = (size[1]-10, size[0]-10) + ((3,) if three_d else ())
            np.random.seed(379823)
            data = np.random.rand(*shape)
            image = Image(data, cmap='grays', clim=[0, 1])
            c.draw_visual(image)
            assert_image_approved("screenshot", "visuals/image%s.png" %
                                  ("_rgb" if three_d else "_mono"))
Exemplo n.º 38
0
def test_volume_draw():
    with TestingCanvas(bgcolor='k', size=(100, 100)) as c:
        v = c.central_widget.add_view()
        v.camera = 'turntable'
        v.camera.fov = 70
        # Create
        np.random.seed(2376)
        vol = np.random.normal(size=(20, 20, 20), loc=0.5, scale=0.2)
        vol[8:16, 8:16, :] += 1.0
        V = scene.visuals.Volume(vol, parent=v.scene)  # noqa
        v.camera.set_range()
        assert_image_approved(c.render(), 'visuals/volume.png')
Exemplo n.º 39
0
def test_volume_draw():
    with TestingCanvas(bgcolor='k', size=(100, 100)) as c:
        v = c.central_widget.add_view()
        v.camera = 'turntable'
        v.camera.fov = 70
        # Create
        np.random.seed(2376)
        vol = np.random.normal(size=(20, 20, 20), loc=0.5, scale=0.2)
        vol[8:16, 8:16, :] += 1.0
        scene.visuals.Volume(vol, parent=v.scene)  # noqa
        v.camera.set_range()
        assert_image_approved(c.render(), 'visuals/volume.png')
Exemplo n.º 40
0
def test_colormap_discrete_nu():
    """Test discrete colormap with non-uniformly distributed control-points"""
    with TestingCanvas(size=size, bgcolor='w') as c:
        idata = np.linspace(255, 0, size[0] * size[1]).astype(np.ubyte)
        data = idata.reshape((size[0], size[1]))
        image = Image(cmap=Colormap(np.array([[0, .75, 0], [.75, .25, .5]]),
                                    [0., .25, 1.],
                                    interpolation='zero'),
                      clim='auto',
                      parent=c.scene)
        image.set_data(data)
        assert_image_approved(c.render(), "visuals/colormap_nu.png")
Exemplo n.º 41
0
def test_arrow_reactive():
    """Tests the reactive behaviour of the ArrowVisual properties."""
    with TestingCanvas() as c:
        arrow = visuals.Arrow(pos=vertices,
                              arrows=arrows,
                              connect="segments",
                              parent=c.scene)

        arrow.arrow_type = "stealth"
        assert_image_approved(c.render(), 'visuals/arrow_reactive1.png')

        arrow.arrow_size = 20
        assert_image_approved(c.render(), 'visuals/arrow_reactive2.png')
Exemplo n.º 42
0
def test_image():
    """Test image visual"""
    size = (100, 50)
    with TestingCanvas(size=size, bgcolor='w') as c:
        for three_d in (True, False):
            shape = (size[1] - 10, size[0] - 10) + ((3, ) if three_d else ())
            np.random.seed(379823)
            data = np.random.rand(*shape)
            image = Image(data, cmap='grays', clim=[0, 1])
            c.draw_visual(image)
            assert_image_approved(
                "screenshot",
                "visuals/image%s.png" % ("_rgb" if three_d else "_mono"))
Exemplo n.º 43
0
def test_rectpolygon_draw():
    """Test drawing transformed rectpolygons using RectPolygonVisual"""
    with TestingCanvas() as c:
        rectpolygon = visuals.Rectangle(pos=(0., 0.), height=20.,
                                        width=20., radius=10., color='blue')
        rectpolygon.transform = transforms.STTransform(scale=(2.0, 3.0),
                                                       translate=(50, 50))
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot", 'visuals/rectpolygon6.png')

        rectpolygon = visuals.Rectangle(pos=(0., 0.), height=20.,
                                        width=20., radius=10.,
                                        color='blue', border_color='red')
        rectpolygon.transform = transforms.STTransform(scale=(2.0, 3.0),
                                                       translate=(50, 50))
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot", 'visuals/rectpolygon7.png')

        rectpolygon = visuals.Rectangle(pos=(0., 0.), height=60.,
                                        width=60., radius=10.,
                                        border_color='red')
        rectpolygon.transform = transforms.STTransform(scale=(1.5, 0.5),
                                                       translate=(50, 50))
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot", 'visuals/rectpolygon8.png',
                              min_corr=0.5)

        rectpolygon = visuals.Rectangle(pos=(0., 0.), height=60.,
                                        width=60., radius=[25, 10, 0, 15],
                                        color='blue', border_color='red')
        rectpolygon.transform = transforms.STTransform(scale=(1.5, 0.5),
                                                       translate=(50, 50))
        c.draw_visual(rectpolygon)
        assert_image_approved("screenshot", 'visuals/rectpolygon9.png')
Exemplo n.º 44
0
def test_text():
    """Test basic text support"""

    with TestingCanvas(bgcolor='w', size=(92, 92), dpi=92) as c:
        pos = [92 // 2] * 2
        text = Text('testing',
                    font_size=20,
                    color='k',
                    pos=pos,
                    anchor_x='center',
                    anchor_y='baseline')
        c.draw_visual(text)
        # Test image created in Illustrator CS5, 1"x1" output @ 92 DPI
        assert_image_approved("screenshot", 'visuals/text1.png')
Exemplo n.º 45
0
def test_colorbar_draw():
    """Test drawing Colorbar without transform using ColorbarVisual"""
    with TestingCanvas() as c:
        colorbar_top = create_colorbar(center_pos=(50, 50),
                                       halfdim=(30, 2),
                                       orientation='top')

        c.draw_visual(colorbar_top)
        assert_image_approved("screenshot", 'visuals/colorbar/top.png')

        colorbar_bottom = create_colorbar(center_pos=(50, 50),
                                          halfdim=(30, 2),
                                          orientation='bottom')

        c.draw_visual(colorbar_bottom)
        assert_image_approved("screenshot", 'visuals/colorbar/bottom.png')

        colorbar_left = create_colorbar(center_pos=(50, 50),
                                        halfdim=(2, 30),
                                        orientation='left')

        c.draw_visual(colorbar_left)
        assert_image_approved("screenshot", 'visuals/colorbar/left.png')

        colorbar_right = create_colorbar(center_pos=(50, 50),
                                         halfdim=(2, 30),
                                         orientation='right')

        c.draw_visual(colorbar_right)
        assert_image_approved("screenshot", 'visuals/colorbar/right.png')
Exemplo n.º 46
0
def test_colorbar_draw():
    """Test drawing Colorbar without transform using ColorbarVisual"""
    with TestingCanvas() as c:
        colorbar_top = create_colorbar(center_pos=(50, 50),
                                       halfdim=(30, 2),
                                       orientation='top')

        c.draw_visual(colorbar_top)
        assert_image_approved(c.render(), 'visuals/colorbar/top.png')
        colorbar_top.parent = None

        colorbar_bottom = create_colorbar(center_pos=(50, 50),
                                          halfdim=(30, 2),
                                          orientation='bottom')

        c.draw_visual(colorbar_bottom)
        assert_image_approved(c.render(), 'visuals/colorbar/bottom.png')
        colorbar_bottom.parent = None

        colorbar_left = create_colorbar(center_pos=(50, 50),
                                        halfdim=(2, 30),
                                        orientation='left')

        c.draw_visual(colorbar_left)
        assert_image_approved(c.render(), 'visuals/colorbar/left.png')
        colorbar_left.parent = None

        colorbar_right = create_colorbar(center_pos=(50, 50),
                                         halfdim=(2, 30),
                                         orientation='right')

        c.draw_visual(colorbar_right)
        assert_image_approved(c.render(), 'visuals/colorbar/right.png')
Exemplo n.º 47
0
def test_colorbar_draw():
    """Test drawing Colorbar without transform using ColorbarVisual"""
    with TestingCanvas() as c:
        colorbar_top = create_colorbar(pos=(50, 50),
                                       size=(60, 4),
                                       orientation='top')

        c.draw_visual(colorbar_top)
        assert_image_approved(c.render(), 'visuals/colorbar/top.png')
        colorbar_top.parent = None

        colorbar_bottom = create_colorbar(pos=(50, 50),
                                          size=(60, 4),
                                          orientation='bottom')

        c.draw_visual(colorbar_bottom)
        assert_image_approved(c.render(), 'visuals/colorbar/bottom.png')
        colorbar_bottom.parent = None

        colorbar_left = create_colorbar(pos=(50, 50),
                                        size=(60, 4),
                                        orientation='left')

        c.draw_visual(colorbar_left)
        assert_image_approved(c.render(), 'visuals/colorbar/left.png')
        colorbar_left.parent = None

        colorbar_right = create_colorbar(pos=(50, 50),
                                         size=(60, 4),
                                         orientation='right')

        c.draw_visual(colorbar_right)
        assert_image_approved(c.render(), 'visuals/colorbar/right.png')
Exemplo n.º 48
0
def test_arc_draw1():
    """Test drawing arcs using EllipseVisual"""
    with TestingCanvas() as c:
        ellipse = visuals.Ellipse(pos=(50., 50.), radius=(20, 15),
                                  start_angle=150., span_angle=120.,
                                  color=(0, 0, 1, 1))
        c.draw_visual(ellipse)
        assert_image_approved("screenshot", 'visuals/arc1.png')

        ellipse = visuals.Ellipse(pos=(50., 50.), radius=(20, 15),
                                  start_angle=150., span_angle=120.,
                                  border_color=(1, 0, 0, 1))
        c.draw_visual(ellipse)
        assert_image_approved("screenshot", 'visuals/arc2.png', 
                              min_corr=0.6)
Exemplo n.º 49
0
def test_arrow_draw():
    """Test drawing arrows without transforms"""
    with TestingCanvas() as c:
        if os.getenv('TRAVIS', 'false') == 'true' and \
                c.app.backend_name.lower() == 'pyqt4':
            # TODO: Fix this (issue #1042
            raise SkipTest('Travis fails due to FB stack problem')
        for arrow_type in ARROW_TYPES:
            arrow = visuals.Arrow(pos=vertices, arrow_type=arrow_type,
                                  arrows=arrows, arrow_size=10, color='red',
                                  connect="segments", parent=c.scene)

            assert_image_approved(c.render(), 'visuals/arrow_type_%s.png' %
                                  arrow_type)

            arrow.parent = None
Exemplo n.º 50
0
def test_arc_draw1():
    """Test drawing arcs using EllipseVisual"""
    with TestingCanvas() as c:
        ellipse = visuals.Ellipse(center=(50., 50.), radius=(20, 15),
                                  start_angle=150., span_angle=120.,
                                  color=(0, 0, 1, 1),
                                  parent=c.scene)
        assert_image_approved(c.render(), 'visuals/arc1.png')

        ellipse.parent = None
        ellipse = visuals.Ellipse(center=(50., 50.), radius=(20, 15),
                                  start_angle=150., span_angle=120.,
                                  border_color=(1, 0, 0, 1),
                                  parent=c.scene)
        assert_image_approved(c.render(), 'visuals/arc2.png',
                              min_corr=0.6)
Exemplo n.º 51
0
def test_markers():
    """Test basic marker / point-sprite support"""
    # this is probably too basic, but it at least ensures that point sprites
    # work for people
    np.random.seed(57983)
    data = np.random.normal(size=(30, 2), loc=50, scale=10)
    
    with TestingCanvas() as c:
        marker = Markers(parent=c.scene)
        marker.set_data(data)
        assert_image_approved(c.render(), "visuals/markers.png")

    # Test good correlation at high-dpi
    with TestingCanvas(px_scale=2) as c:
        marker = Markers(parent=c.scene)
        marker.set_data(data)
        assert_image_approved(c.render(), "visuals/markers.png")
Exemplo n.º 52
0
def test_arrow_reactive():
    """Tests the reactive behaviour of the ArrowVisual properties"""

    # TODO: fix AppVeyor - error comes up with bollu/vispy:cassowary-constaints
    # commit SHA: 29303009a76d5c6931b1991aa7bdf5192ace9c4f
    if os.getenv('APPVEYOR', '').lower() == 'true':
        raise SkipTest('AppVeyor has unknown failure')

    with TestingCanvas() as c:
        arrow = visuals.Arrow(pos=vertices, arrows=arrows,
                              connect="segments", parent=c.scene)

        arrow.arrow_type = "stealth"
        assert_image_approved(c.render(), 'visuals/arrow_reactive1.png')

        arrow.arrow_size = 20
        assert_image_approved(c.render(), 'visuals/arrow_reactive2.png')
Exemplo n.º 53
0
def test_spectrogram():
    """Test spectrogram visual"""
    n_fft = 256
    n_freqs = n_fft // 2 + 1
    size = (100, n_freqs)
    with TestingCanvas(size=size) as c:
        np.random.seed(67853498)
        data = np.random.normal(size=n_fft * 100)
        spec = Spectrogram(data, n_fft=n_fft, step=n_fft, window=None,
                           color_scale='linear', cmap='grays')
        c.draw_visual(spec)
        #expected = np.zeros(size[::-1] + (3,))
        #expected[0] = 1.
        assert_image_approved("screenshot", "visuals/spectrogram.png")
        freqs = spec.freqs
        assert len(freqs) == n_freqs
        assert freqs[0] == 0
        assert freqs[-1] == 0.5