예제 #1
0
 def __init__(self):
     self.canvas = dviz.canvas(show_fps=True)
     self.panel = self.canvas.panel(controller='axes')
     self.visual = self.panel.visual('point')
     self.pvars = {'ms': 2., 'alpha': .03}
     self.gui = self.canvas.gui('XY')
     self.gui.control("label", "Coords", value="(0, 0)")
예제 #2
0
    def __init__(self, model):
        self.m = model

        # Canvas.
        self.canvas = canvas(show_fps=True,
                             width=1600,
                             height=700,
                             clear_color='black')
        self.scene = self.canvas.scene(rows=1, cols=2)

        # Shared 3D texture.
        self.tex = self.canvas.gpu().context().texture(*self.m.vol.shape)
        self.tex.upload(self.m.vol)
        self.tex.set_filter('linear')

        # Left panel.
        self.p0 = self.scene.panel(col=0, controller='axes', hide_grid=True)
        assert self.p0.col == 0
        vargs = (self.m.xlim, self.m.ylim, self.m.zlim)
        self.view0 = AtlasView(self.canvas, self.p0, self.tex, 0, *vargs)

        # Right panel.
        self.p1 = self.scene.panel(col=1, controller='axes', hide_grid=True)
        assert self.p1.col == 1
        self.view1 = AtlasView(self.canvas, self.p1, self.tex, 1, *vargs)

        self.canvas.connect(self.on_mouse_wheel)

        # GUI
        self.gui = self.canvas.gui("GUI")
        self.slider0 = self.gui.control('slider_float',
                                        'ap',
                                        vmin=self.m.zlim[0],
                                        vmax=self.m.zlim[1])
        self.slider0.connect(self.slice_z)

        self.slider1 = self.gui.control('slider_float',
                                        'ml',
                                        vmin=self.m.ylim[0],
                                        vmax=self.m.ylim[1])
        self.slider1.connect(self.slice_y)

        self.wz = self.slider0.get()
        self.wy = self.slider1.get()
예제 #3
0
    p1[:, 0] = 1
    p1[:, 1] = r[:, 1]

    v = panel.visual('rectangle')
    v.data('pos', p0, idx=0)
    v.data('pos', p1, idx=1)
    v.data('color', np.c_[rc, 255 * np.ones(n)].astype(np.uint8))


if __name__ == '__main__':
    eid, probe_id = get_eid_argv()
    one = ONE()
    m = Model(eid, probe_id, probe_idx=0, one=one)

    # Create the Datoviz view.
    c = canvas(width=1200 * 2, height=800 * 2, show_fps=False)
    scene = c.scene(rows=2, cols=2)

    # Panels.
    p0 = scene.panel(row=0, controller='axes', hide_grid=False)
    p1 = scene.panel(row=1, controller='axes', hide_grid=True)

    # Brain regions in the right panels.
    ps0 = scene.panel(row=0, col=1, controller='axes', hide_grid=True)
    ps1 = scene.panel(row=1, col=1, controller='axes', hide_grid=True)
    ps0.size('x', .2)

    plot_brain_regions(ps0, m.regions)
    plot_brain_regions(ps1, m.regions)

    # Views.
예제 #4
0
"""
# Quickstart tutorial with Python

"""

import time

import numpy as np
import numpy.random as nr

# Import the library.
from datoviz import canvas, run, colormap

# Create a new canvas and scene. There's only 1 subplot (panel) by default.
c = canvas(show_fps=True)

# Get a panel (by default, the one spanning the entire canvas)
# We specify the type of controller we want. Here, we want 2D axes.
panel = c.panel(controller='axes')

# We create a new "marker" visual.
visual = panel.visual('marker')

# We prepare the visual properties. Here, we set the marker positions, colors (RGBA bytes),
# and size (in pixels).
N = 100_000
pos = nr.randn(N, 3)
ms = nr.uniform(low=2, high=35, size=N)
color_values = nr.rand(N)

# Use a built-in colormap
예제 #5
0
파일: france.py 프로젝트: rougier/datoviz
pos = np.fromfile(ROOT / "data/misc/departements.polypoints.bin",
                  dtype=np.float64)
pos = pos.reshape((-1, 2))
pos = np.c_[pos[:, 1], pos[:, 0], np.zeros(pos.shape[0])]
# latitude, longitude, 0

# Web Mercator projection
lat, lon, _ = pos.T
lonrad = lon / 180.0 * np.pi
latrad = lat / 180.0 * np.pi
zoom = 1
c = 256 / 2 * np.pi * 2**zoom
x = c * (lonrad + np.pi)
y = -c * (np.pi - np.log(np.tan(np.pi / 4.0 + latrad / 2.0)))
pos = np.c_[x, y, _]

length = np.fromfile(ROOT / "data/misc/departements.polylengths.bin",
                     dtype=np.uint32)
N = len(length)
color = colormap(nr.rand(N), vmin=0, vmax=1, cmap='viridis')

c = canvas(show_fps=False)
panel = c.panel(controller='panzoom')
visual = panel.visual('polygon')

visual.data('pos', pos)
visual.data('length', length)
visual.data('color', color)

run()
예제 #6
0
y = np.load('spikeloc/y_position.npy')
z = np.load('spikeloc/z_position.npy')
pos = np.c_[x, z, y]

st = np.load('spikeloc/spike_times.npy') / 3e4
amp = np.load('spikeloc/amplitudes.npy')
alpha = np.load('spikeloc/alphas.npy')

# Color.
log_ptp = amp
log_ptp[log_ptp >= 30] = 30
ptp_rescaled = (log_ptp - log_ptp.min()) / (log_ptp.max() - log_ptp.min())
color = colormap(ptp_rescaled, alpha=5. / 255, cmap='spring')

# Create the visual.
c = canvas(width=800, height=1000, show_fps=True)
v = c.scene().panel(controller='arcball').visual('point', depth_test=True)

# Visual prop data.
v.data('pos', pos)
v.data('color', color)
v.data('ms', np.array([2]))

# GUI with slider.
t = 0
dt = 20.0
gui = c.gui("GUI")
slider_offset = gui.control("slider_float",
                            "time offset",
                            vmin=0,
                            vmax=st[-1] - dt,
예제 #7
0
    *7 Tesla MRI Followed by Histological 3D Reconstructions in Whole-Brain Specimens*

    Front. Neuroanat. 14:536838
    doi: 10.3389/fnana.2020.536838

Acknowledgements to Pierre-Louis Bazin and Julia Huntenburg for data access.

"""

from pathlib import Path
import numpy as np

from datoviz import canvas, run, colormap

c = canvas(show_fps=True, width=1024, height=768)
panel = c.scene().panel(controller='arcball')
visual = panel.visual('mesh', transform='auto')

ROOT = Path(__file__).resolve().parent.parent / "datoviz"
pos = np.load(ROOT / "data/mesh/brain_highres.vert.npy")
faces = np.load(ROOT / "data/mesh/brain_highres.faces.npy")

assert pos.ndim == 2
assert pos.shape[1] == 3
assert faces.ndim == 2
assert faces.shape[1] == 3

print(f"Mesh has {len(faces)} triangles and {len(pos)} vertices")

visual.data('pos', pos)
예제 #8
0
"""
# Test with two panels and different controllers

"""

import numpy as np
import numpy.random as nr

from datoviz import canvas, run, colormap

N = 100_000
pos = nr.randn(N, 3)
ms = nr.uniform(low=2, high=40, size=N)
color = colormap(nr.rand(N), vmin=0, vmax=1, alpha=.75 * np.ones(N))

c = canvas(rows=1, cols=2, show_fps=True)

panel0 = c.panel(0, 0, controller='axes')
panel1 = c.panel(0, 1, controller='arcball')

visual = panel0.visual('marker')
visual.data('pos', pos)
visual.data('color', color)
visual.data('ms', ms)

visual1 = panel1.visual('marker', depth_test=True)
visual1.data('pos', pos)
visual1.data('color', color)
visual1.data('ms', ms)

run()
예제 #9
0
from pathlib import Path

import numpy as np
import numpy.random as nr

from ibllib.atlas import AllenAtlas

ba = AllenAtlas()

from datoviz import canvas, run, colormap

c = canvas(show_fps=True, pick=True, high_dpi=True)
ctx = c.gpu().context()
panel = c.scene().panel(controller='arcball')
visual = panel.visual('volume')

texshape = np.array([456, 320, 528])
coef = .004
shape = coef * texshape[[1, 0, 2]]

visual.data('pos', np.atleast_2d(-shape / 2), idx=0)
visual.data('pos', np.atleast_2d(+shape / 2), idx=1)

# Box shape.
visual.data('length', np.atleast_2d(shape))

# Transfer function.
fun = np.linspace(0, .05, 256).astype(np.float32)
transfer = ctx.texture(256, ndim=1)
transfer.upload(fun)
visual.texture(transfer)
예제 #10
0
bg_data2 = load_surf_data(fsaverage['sulc_right'])

# Concatenate.
coords = np.vstack((coords, coords2))
faces = np.vstack((faces, faces2 + faces.max() + 1))
bg_data = np.concatenate((bg_data, bg_data2))

# Depth background data.
bg_data = (bg_data - bg_data.min()) / (bg_data.max() - bg_data.min())
N = bg_data.shape[0]
# HACK: uv tex coords to fetch the right colormap value. To be improved
cmap = 0
uv = np.c_[bg_data, np.ones(N) * cmap / 256.0 + .5 / 256.0]

# Plot the data:
c = canvas(show_fps=False, width=1024, height=768)
panel = c.panel(controller='arcball')
visual = panel.visual('mesh', transform='auto')

visual.data('pos', coords)
visual.data('texcoords', uv)
visual.data('index', faces.ravel())

# Light parameters
light_params = np.zeros((4, 4))  # up to 4 lights
# ambient, diffuse, specular, specular exponent
light_params[0, :] = (.4, .4, .2, 64)
visual.data('light_params', light_params)

gui = c.gui("GUI")