コード例 #1
0
def test_volume():
    vol = np.zeros((20, 20, 20), 'float32')
    vol[8:16, 8:16, :] = 1.0
    
    # Create
    V = scene.visuals.Volume(vol)
    assert V.clim == (0, 1)
    assert V.method == 'mip'
    assert V.interpolation == 'linear'

    # Set wrong data
    with raises(ValueError):
        V.set_data(np.zeros((20, 20), 'float32'))
    
    # Clim
    V.set_data(vol, (0.5, 0.8))
    assert V.clim == (0.5, 0.8)
    with raises(ValueError):
        V.set_data((0.5, 0.8, 1.0))
    
    # Method
    V.method = 'iso'
    assert V.method == 'iso'

    # Interpolation
    V.interpolation = 'nearest'
    assert V.interpolation == 'nearest'
        
    # Step size
    V.relative_step_size = 1.1
    assert V.relative_step_size == 1.1
    # Disallow 0 step size to avoid GPU stalling
    with raises(ValueError):
        V.relative_step_size = 0
コード例 #2
0
ファイル: test_node.py プロジェクト: djhoese/vispy
def test_topology():
    c = TestingCanvas()
    assert c.scene.canvas is c
    with raises(AttributeError):
        c.foo = 'bar'

    w = c.central_widget
    assert w.parent is c.scene
    assert w.scene_node is c.scene
    assert w.document_node is c.scene

    g = w.add_grid()
    with raises(AttributeError):
        g.foo = 'bar'

    grid_check = EventCheck(g.events.children_change)

    v1 = g.add_view(row=0, col=0)
    assert v1.parent is g
    assert v1.scene_node is c.scene

    assert len(grid_check.events) == 1

    v2 = g.add_view(row=1, col=0)
    assert v2.parent is g
    assert v2.scene_node is c.scene
    assert v2.document_node is c.scene

    assert len(grid_check.events) == 1

    n1 = Node()
    n1_parent_check = EventCheck(n1.events.parent_change)
    n1_child_check = EventCheck(n1.events.children_change)
    v1.add(n1)
    assert len(n1_parent_check.events) == 1
    assert n1.parent is v1.scene
    assert n1.scene_node is v1.scene
    assert n1.document_node is c.scene

    n2 = Node(parent=n1)
    n2_parent_check = EventCheck(n2.events.parent_change)
    assert n2.parent is n1
    assert n2.scene_node is v1.scene
    assert n2.document_node is c.scene
    assert len(n1_child_check.events) == 1

    assert len(grid_check.events) == 2

    v2.add(n1)
    assert len(grid_check.events) == 2
    assert len(n1_parent_check.events) == 1
    assert len(n2_parent_check.events) == 1
    assert n1.parent is v2.scene
    assert n2.scene_node is v2.scene
    assert n2.document_node is c.scene
コード例 #3
0
ファイル: test_node.py プロジェクト: Calvarez20/vispy
def test_topology():
    c = TestingCanvas()
    assert c.scene.canvas is c
    with raises(AttributeError):
        c.foo = 'bar'
    
    w = c.central_widget
    assert w.parent is c.scene
    assert w.scene_node is c.scene
    assert w.document_node is c.scene
    
    g = w.add_grid()
    with raises(AttributeError):
        g.foo = 'bar'
    
    grid_check = EventCheck(g.events.children_change)
    
    v1 = g.add_view(row=0, col=0)
    assert v1.parent is g
    assert v1.scene_node is c.scene
    
    assert len(grid_check.events) == 1
    
    v2 = g.add_view(row=1, col=0)
    assert v2.parent is g
    assert v2.scene_node is c.scene
    assert v2.document_node is c.scene
    
    assert len(grid_check.events) == 1
    
    n1 = Node()
    n1_parent_check = EventCheck(n1.events.parent_change)
    n1_child_check = EventCheck(n1.events.children_change)
    v1.add(n1)
    assert len(n1_parent_check.events) == 1
    assert n1.parent is v1.scene
    assert n1.scene_node is v1.scene
    assert n1.document_node is c.scene
    
    n2 = Node(parent=n1)
    n2_parent_check = EventCheck(n2.events.parent_change)
    assert n2.parent is n1
    assert n2.scene_node is v1.scene
    assert n2.document_node is c.scene
    assert len(n1_child_check.events) == 1
    
    assert len(grid_check.events) == 2
    
    v2.add(n1)
    assert len(grid_check.events) == 2
    assert len(n1_parent_check.events) == 1
    assert len(n2_parent_check.events) == 1
    assert n1.parent is v2.scene
    assert n2.scene_node is v2.scene
    assert n2.document_node is c.scene
コード例 #4
0
def test_attributes():
    """Test if attribute checks are in place"""
    with TestingCanvas():
        rectpolygon = visuals.Rectangle(pos=(50, 50, 0), height=40.,
                                        width=80., color='red')
        with raises(ValueError):
            rectpolygon.height = 0
        with raises(ValueError):
            rectpolygon.width = 0
        with raises(ValueError):
            rectpolygon.radius = [10, 0, 5]
        with raises(ValueError):
            rectpolygon.radius = [10.]
        with raises(ValueError):
            rectpolygon.radius = 21.
コード例 #5
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'
コード例 #6
0
ファイル: test_colorbar.py プロジェクト: djhoese/vispy
def test_attributes():
    """Test if attribute checks are in place"""
    with TestingCanvas():

        # initialize with major axis < minor axis
        with raises(ValueError):
            create_colorbar(pos=(50, 50), size=(1, 30), orientation='top')

        # set major axis to 0
        with raises(ValueError):
            create_colorbar(pos=(50, 50), size=(0, 1), orientation='right')

        # set negative major axis
        with raises(ValueError):
            create_colorbar(pos=(50, 50), size=(-10, 1), orientation='right')

        # set negative minor axis
        with raises(ValueError):
            create_colorbar(pos=(50, 50), size=(1, -10), orientation='right')

        # set minor axis to 0
        with raises(ValueError):
            create_colorbar(pos=(50, 50), size=(1, 0), orientation='right')

        # set invalid orientation
        with raises(ValueError):
            create_colorbar(pos=(50, 50),
                            size=(60, 4),
                            orientation='top-invalid')
コード例 #7
0
ファイル: test_colorbar.py プロジェクト: jay3sh/vispy
def test_attributes():
    """Test if attribute checks are in place"""
    with TestingCanvas():

        # initialize with wrong dimensions for orientations
        with raises(ValueError):
            create_colorbar(center_pos=(50, 50),
                            halfdim=(1, 30),
                            orientation='top')

        with raises(ValueError):
            create_colorbar(center_pos=(50, 50),
                            halfdim=(1, 30),
                            orientation='bottom')

        with raises(ValueError):
            create_colorbar(center_pos=(50, 50),
                            halfdim=(30, 1),
                            orientation='left')

        with raises(ValueError):
            create_colorbar(center_pos=(50, 50),
                            halfdim=(30, 1),
                            orientation='right')

        # set width to 0
        with raises(ValueError):
            create_colorbar(center_pos=(50, 50),
                            halfdim=(0, 1),
                            orientation='right')

        # set height to 0
        with raises(ValueError):
            create_colorbar(center_pos=(50, 50),
                            halfdim=(1, 0),
                            orientation='right')

        # set invalid orientation
        with raises(ValueError):
            create_colorbar(center_pos=(50, 50),
                            halfdim=(30, 2),
                            orientation='top-invalid')
コード例 #8
0
def test_attributes():
    """Test if attribute checks are in place"""
    with TestingCanvas():

        # initialize with wrong dimensions for orientations
        with raises(ValueError):
            create_colorbar(center_pos=(50, 50),
                            halfdim=(1, 30),
                            orientation='top')

        with raises(ValueError):
            create_colorbar(center_pos=(50, 50),
                            halfdim=(1, 30),
                            orientation='bottom')

        with raises(ValueError):
            create_colorbar(center_pos=(50, 50),
                            halfdim=(30, 1),
                            orientation='left')

        with raises(ValueError):
            create_colorbar(center_pos=(50, 50),
                            halfdim=(30, 1),
                            orientation='right')

        # set width to 0
        with raises(ValueError):
            create_colorbar(center_pos=(50, 50),
                            halfdim=(0, 1),
                            orientation='right')

        # set height to 0
        with raises(ValueError):
            create_colorbar(center_pos=(50, 50),
                            halfdim=(1, 0),
                            orientation='right')

        # set invalid orientation
        with raises(ValueError):
            create_colorbar(center_pos=(50, 50),
                            halfdim=(30, 2),
                            orientation='top-invalid')
コード例 #9
0
ファイル: test_colorbar.py プロジェクト: Calvarez20/vispy
def test_attributes():
    """Test if attribute checks are in place"""
    with TestingCanvas():

        # initialize with major axis < minor axis
        with raises(ValueError):
            create_colorbar(pos=(50, 50),
                            size=(1, 30),
                            orientation='top')

        # set major axis to 0
        with raises(ValueError):
            create_colorbar(pos=(50, 50),
                            size=(0, 1),
                            orientation='right')

        # set negative major axis
        with raises(ValueError):
            create_colorbar(pos=(50, 50),
                            size=(-10, 1),
                            orientation='right')

        # set negative minor axis
        with raises(ValueError):
            create_colorbar(pos=(50, 50),
                            size=(1, -10),
                            orientation='right')

        # set minor axis to 0
        with raises(ValueError):
            create_colorbar(pos=(50, 50),
                            size=(1, 0),
                            orientation='right')

        # set invalid orientation
        with raises(ValueError):
            create_colorbar(pos=(50, 50),
                            size=(60, 4),
                            orientation='top-invalid')