Exemplo n.º 1
0
def test_config():
    """Test vispy config methods and file downloading"""
    assert_raises(TypeError, config.update, data_path=dict())
    assert_raises(KeyError, config.update, foo="bar")  # bad key
    data_dir = op.join(temp_dir, "data")
    assert_raises(IOError, set_data_dir, data_dir)  # didn't say to create
    orig_val = os.environ.get("_VISPY_CONFIG_TESTING", None)
    os.environ["_VISPY_CONFIG_TESTING"] = "true"
    try:
        assert_raises(IOError, set_data_dir, data_dir)  # doesn't exist yet
        set_data_dir(data_dir, create=True, save=True)
        assert_equal(config["data_path"], data_dir)
        config["data_path"] = data_dir
        print(config)  # __repr__
        load_data_file("CONTRIBUTING.txt")
        fid = open(op.join(data_dir, "test-faked.txt"), "w")
        fid.close()
        load_data_file("test-faked.txt")  # this one shouldn't download
        assert_raises(RuntimeError, load_data_file, "foo-nonexist.txt")
        save_config()
    finally:
        if orig_val is not None:
            os.environ["_VISPY_CONFIG_TESTING"] = orig_val
        else:
            del os.environ["_VISPY_CONFIG_TESTING"]
Exemplo n.º 2
0
def test_config():
    """Test vispy config methods and file downloading"""
    assert_raises(TypeError, config.update, data_path=dict())
    assert_raises(KeyError, config.update, foo='bar')  # bad key
    data_dir = op.join(temp_dir, 'data')
    assert_raises(IOError, set_data_dir, data_dir)  # didn't say to create
    orig_val = os.environ.get('_VISPY_CONFIG_TESTING', None)
    os.environ['_VISPY_CONFIG_TESTING'] = 'true'
    try:
        assert_raises(IOError, set_data_dir, data_dir)  # doesn't exist yet
        set_data_dir(data_dir, create=True, save=True)
        assert_equal(config['data_path'], data_dir)
        config['data_path'] = data_dir
        print(config)  # __repr__
        load_data_file('CONTRIBUTING.txt')
        fid = open(op.join(data_dir, 'test-faked.txt'), 'w')
        fid.close()
        load_data_file('test-faked.txt')  # this one shouldn't download
        assert_raises(RuntimeError, load_data_file, 'foo-nonexist.txt')
        save_config()
    finally:
        if orig_val is not None:
            os.environ['_VISPY_CONFIG_TESTING'] = orig_val
        else:
            del os.environ['_VISPY_CONFIG_TESTING']
Exemplo n.º 3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vispy: testskip
# -----------------------------------------------------------------------------
# Copyright (c) 2014, Nicolas P. Rougier. All Rights Reserved.
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------

from vispy import app, gloo
from vispy.util import load_data_file
from vispy.util.svg import Document
from vispy.visuals.collections import PathCollection, PolygonCollection
from vispy.visuals.transforms import PanZoomTransform

path = load_data_file('tiger/tiger.svg')
tiger = Document(path)

width, height = int(tiger.viewport.width), int(tiger.viewport.height)
canvas = app.Canvas(size=(width, height), show=True, keys='interactive')
gloo.set_viewport(0, 0, width, height)
gloo.set_state("translucent", depth_test=True)

panzoom = PanZoomTransform(canvas, aspect=1.0)
paths = PathCollection("agg+",
                       linewidth='shared',
                       color="shared",
                       transform=panzoom)
polys = PolygonCollection("agg", transform=panzoom)
paths.update.connect(canvas.update)

z = 0
Exemplo n.º 4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vispy: testskip

import json

import numpy as np

from vispy import app, gloo
from vispy.util import load_data_file
from vispy.visuals.collections import PathCollection, PolygonCollection
from vispy.visuals.transforms import PanZoomTransform

path = load_data_file('uscounties/uscounties.geojson')
with open(path, 'r') as f:
    geo = json.load(f)


def unique_rows(data):
    v = data.view(data.dtype.descr * data.shape[1])
    _, idx = np.unique(v, return_index=True)
    return data[np.sort(idx)]


def add(P, color):
    P = np.array(P)
    if len(P) < 2:
        return
    P = np.array(P) / 20.0 + (5, -2)
    p = np.zeros((len(P), 3))
    p[:, :2] = P
Exemplo n.º 5
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vispy: testskip
# -----------------------------------------------------------------------------
# Copyright (c) 2014, Nicolas P. Rougier. All Rights Reserved.
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------

from vispy import app, gloo
from vispy.util import load_data_file
from vispy.util.svg import Document
from vispy.visuals.collections import PathCollection, PolygonCollection
from vispy.visuals.transforms import PanZoomTransform

path = load_data_file('tiger/tiger.svg')
tiger = Document(path)

width, height = int(tiger.viewport.width), int(tiger.viewport.height)
canvas = app.Canvas(size=(width, height), show=True, keys='interactive')
gloo.set_viewport(0, 0, width, height)
gloo.set_state("translucent", depth_test=True)

panzoom = PanZoomTransform(canvas, aspect=1.0)
paths = PathCollection(
    "agg+", linewidth='shared', color="shared", transform=panzoom)
polys = PolygonCollection("agg", transform=panzoom)
paths.update.connect(canvas.update)

z = 0
for path in tiger.paths:
    for vertices, closed in path.vertices:
Exemplo n.º 6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vispy: testskip

import json

import numpy as np

from vispy import app, gloo
from vispy.util import load_data_file
from vispy.visuals.collections import PathCollection, PolygonCollection
from vispy.visuals.transforms import PanZoomTransform


path = load_data_file('uscounties/uscounties.geojson')
with open(path, 'r') as f:
    geo = json.load(f)


def unique_rows(data):
    v = data.view(data.dtype.descr * data.shape[1])
    _, idx = np.unique(v, return_index=True)
    return data[np.sort(idx)]


def add(P, color):
    P = np.array(P)
    if len(P) < 2:
        return
    P = np.array(P) / 20.0 + (5, -2)
    p = np.zeros((len(P), 3))