def set_spikes(self, spikes): pos = np.c_[spikes.times, spikes.depths, np.zeros_like(spikes.times)] color = dviz.colormap(20 * np.log10(spikes.amps), cmap='cividis', alpha=self.pvars['alpha']) self.visual.data('pos', pos) self.visual.data('color', color) self.visual.data('ms', np.array([self.pvars['ms']]))
def on_change(value): # Recompute the colors. color = colormap(color_values, vmin=0, vmax=1, alpha=.75 * np.ones(N), cmap=cmaps[value]) # Update the color visual visual.data('color', color)
def to_image(self, data): # CAR data -= data.mean(axis=0) # Vrange # self.vmin = data.min() if self.vmin is None else self.vmin # self.vmax = data.max() if self.vmax is None else self.vmax self.vmin = CMIN if self.vmin is None else self.vmin self.vmax = CMAX if self.vmax is None else self.vmax # Colormap img = colormap(data.ravel().astype(np.double), vmin=self.vmin, vmax=self.vmax, cmap='gray') img = img.reshape(data.shape + (-1, )) assert img.shape == data.shape[:2] + (4, ) return img
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 color = colormap(color_values, vmin=0, vmax=1, alpha=.75 * np.ones(N), cmap='viridis') # Set the visual props. visual.data('pos', pos) visual.data('color', color) visual.data('ms', ms) # We define an event callback to implement mouse picking @c.connect def on_mouse_click(x, y, button, modifiers=()): # x, y are in pixel coordinates # First, we find the picked panel p = c.panel_at(x, y)
visual = panel.visual('line_strip') n_signals = 200 n_points = 2000 n_vert = n_signals * n_points t = np.linspace(0, 5, n_points) x = np.tile(t, (n_signals,)) assert x.ndim == 1 y = .2 * nr.randn(n_signals, n_points) offsets = np.tile(np.arange(n_signals)[:, np.newaxis], (1, n_points)) y += offsets pos = np.c_[x, y.ravel(), np.zeros(n_vert)] color = np.repeat(colormap(np.linspace(0, 1, n_signals), cmap='glasbey'), n_points, axis=0) length = np.repeat(np.array([n_points]), n_signals) assert pos.shape == (n_vert, 3) assert color.shape == (n_vert, 4) assert length.shape == (n_signals,) visual.data('pos', pos) visual.data('color', color) visual.data('length', length) i = 0 k = 50 def f(): global i yk = .2 * nr.randn(n_signals, k)
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()
c = canvas(show_fps=True) panel = c.panel(controller='panzoom') visual = panel.visual('path') # Create a horizontal thick line. n = 256 x = np.linspace(-1, 1, n) y = np.zeros(n) z = np.zeros(n) pos = np.c_[x, y, z] # Create a custom color map, ranging from red to green. cmap = np.c_[np.arange(256), np.arange(256)[::-1], np.zeros(256), 255 * np.ones(256)] cmap = cmap.astype(np.uint8) # Register the custom colormap. c.colormap('mycmap', cmap) # Use the custom colormap in the visual. color = colormap(np.linspace(0, 1, n), cmap='mycmap') visual.data('pos', pos) visual.data('color', color) visual.data('linewidth', np.array([50])) visual.data('cap_type', np.array([0])) run()
# Data loading. x = np.load('spikeloc/x_position.npy') 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",
spikes, clusters, channels = bbone.load_spike_sorting_with_channel( eid, aligned=True, one=one) c = canvas(show_fps=False) panel = c.panel(controller='arcball') visual = panel.visual('point', depth_test=True) clusters_pass = np.where(clusters['probe00']['metrics']['label'] == 1)[0] amps = spikes['probe00']['amps'][np.isin(spikes['probe00']['clusters'], clusters_pass)] spike_clusters = spikes['probe00']['clusters'][np.isin( spikes['probe00']['clusters'], clusters_pass)] spike_depths = spikes['probe00']['depths'][np.isin( spikes['probe00']['clusters'], clusters_pass)] spike_times = spikes['probe00']['times'][np.isin(spikes['probe00']['clusters'], clusters_pass)] N = len(spike_times) C = len(np.unique(spike_clusters)) print(f"{N} spikes") print(f"{C} neurons") pos = np.c_[spike_times, spike_depths, amps * 1000000] color = colormap(spike_clusters.astype(np.float64), cmap='glasbey', alpha=0.5) visual.data('pos', pos) visual.data('color', color) visual.data('ms', np.array([5.])) run()
""" # 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()