def viz_mean_excitability(sid, rid): regpos, w, obsmask, surfaces, contacts = read_structural_data(sid, rid) vlines, vmeshes, vcontacts = viz_structure(regpos, w, surfaces, contacts) # Load results nreg = regpos.shape[0] res = io.parse_csv([ f"run/solo/INC/vep/id{sid:03d}/output/r{rid:02d}_all/chain_{chain}.csv" for chain in [1, 2] ]) cinf = res['c'] # cmean = np.mean(cinf, axis=0) # pexc = np.mean(cinf > 2.0, axis=0) scalar = np.percentile(cinf, 50, axis=0) # Regions cmap = 'plasma' # vmin = np.min(scalar) # vmax = np.max(scalar) vmin, vmax = -2, 2 vpoints = [] for i in range(nreg): if not obsmask[i]: vpoints.append( vp.Sphere(regpos[i], r=4, c=vp.colorMap(scalar[i], cmap, vmin, vmax))) else: vpoints.append( vp.Cube(regpos[i], side=6, c=vp.colorMap(scalar[i], cmap, vmin, vmax))) vbar = vp.Points(regpos, r=0.01).pointColors(scalar, cmap=cmap, vmin=vmin, vmax=vmax) vbar.addScalarBar(horizontal=True, pos=(0.8, 0.02)) def slider(widget, event): percentile = widget.GetRepresentation().GetValue() scalar = np.percentile(cinf, percentile, axis=0) for i in range(nreg): vpoints[i].color(vp.colorMap(scalar[i], cmap, vmin, vmax)) vplotter = vp.Plotter(axes=0) vplotter.addSlider2D(slider, 0., 100., value=50.0, pos=3, title="Percentile") vplotter.show(vpoints, vlines, vmeshes, vcontacts, vbar)
def viz_network_scalar(centres, scalars, weights, obsmask, surfs, view='topdown', size=(1000, 1000), cmap='viridis', vmin=None, vmax=None): vp.embedWindow(False) if vmin is None: vmin = np.min(scalars) if vmax is None: vmax = np.max(scalars) vlines, vmeshes = viz_structure(centres, weights, surfs, w_perc=3) nreg = centres.shape[0] # Regions vpoints = [] for i in range(nreg): if not obsmask[i]: vpoints.append( vp.Sphere(centres[i], r=4, c=vp.colorMap(scalars[i], cmap, vmin, vmax))) else: vpoints.append( vp.Cube(centres[i], side=6, c=vp.colorMap(scalars[i], cmap, vmin, vmax))) if view == 'topdown': args = dict(elevation=0, azimuth=0, roll=0, zoom=1.4) elif view == 'leftright': args = dict(elevation=0, azimuth=270, roll=90, zoom=1.4) elif view == 'rightleft': args = dict(elevation=0, azimuth=90, roll=270, zoom=1.4) else: raise ValueError(f"Unexpected view: {view}") vplotter = vp.Plotter(axes=0, offscreen=True, size=size) vplotter.show(vpoints, vlines, vmeshes, N=1, **args) img = vp.screenshot(None, scale=1, returnNumpy=True) vp.clear() vp.closePlotter() return img
def viz_excitability(sid, rid): regpos, w, obsmask, surfaces, contacts = read_structural_data(sid, rid) vlines, vmeshes, vcontacts = viz_structure(regpos, w, surfaces, contacts) # Load results nreg = regpos.shape[0] res = io.parse_csv([ f"run/solo/INC/vep/id{sid:03d}/output/r{rid:02d}_all/chain_{chain}.csv" for chain in [1, 2] ]) cinf = res['c'] ctr = 2.0 pexc = np.mean(cinf > ctr, axis=0) # Regions cmap = 'Reds' vmin, vmax = 0, 0.15 # vmin, vmax = -2, 0 vpoints = [] for i in range(nreg): if not obsmask[i]: vpoints.append( vp.Sphere(regpos[i], r=4, c=vp.colorMap(pexc[i], cmap, vmin, vmax))) else: vpoints.append( vp.Cube(regpos[i], side=6, c=vp.colorMap(pexc[i], cmap, vmin, vmax))) vbar = vp.Points(regpos, r=0.01).pointColors(pexc, cmap=cmap, vmin=vmin, vmax=vmax) vbar.addScalarBar(horizontal=True, pos=(0.8, 0.02)) def cslider(widget, event): ctr = widget.GetRepresentation().GetValue() pexc = np.mean(cinf > ctr, axis=0) for i in range(nreg): vpoints[i].color(vp.colorMap(pexc[i], cmap, vmin, vmax)) vplotter = vp.Plotter(axes=0) vplotter.addSlider2D(cslider, -3.0, 3.0, value=2.0, pos=3, title="c") vplotter.show(vpoints, vlines, vmeshes, vcontacts, vbar)
def viz_seizure(sid, rid): regpos, w, obsmask, surfaces, contacts = read_structural_data(sid, rid) vlines, vmeshes, vcontacts = viz_structure(regpos, w, surfaces, contacts) # Load results nreg = regpos.shape[0] res = io.parse_csv([ f"run/solo/INC/vep/id{sid:03d}/output/r{rid:02d}_all/chain_{chain}.csv" for chain in [1, 2] ]) tinf = res['t'] t = 0.0 psz = np.mean(tinf < t, axis=0) # Regions cmap = 'bwr' vmin, vmax = 0, 1 vpoints = [] for i in range(nreg): if not obsmask[i]: vpoints.append( vp.Sphere(regpos[i], r=4, c=vp.colorMap(psz[i], cmap, vmin, vmax))) else: vpoints.append( vp.Cube(regpos[i], side=6, c=vp.colorMap(psz[i], cmap, vmin, vmax))) vbar = vp.Points(regpos, r=0.01).pointColors(psz, cmap=cmap, vmin=vmin, vmax=vmax) vbar.addScalarBar(horizontal=True, pos=(0.8, 0.02)) def tslider(widget, event): t = widget.GetRepresentation().GetValue() psz = np.mean(tinf < t, axis=0) for i in range(nreg): vpoints[i].color(vp.colorMap(psz[i], cmap, vmin, vmax)) vplotter = vp.Plotter(axes=0) vplotter.addSlider2D(tslider, 0, 90.0, value=0.0, pos=3, title="t") vplotter.show(vpoints, vlines, vmeshes, vcontacts, vbar)
def viz_structure(regpos, w, surfaces, contacts): # Connections wmax = np.max(w) vlines = [] for reg1, reg2 in zip(*np.where(w > np.percentile(w.flat, 97))): vlines.append( vp.Line(regpos[reg1], regpos[reg2], c='k', lw=15 * w[reg1, reg2] / wmax)) # Brain surfaces vmeshes = [ vp.Mesh([verts, triangs], 'grey', alpha=0.05) for verts, triangs in surfaces ] # Electrodes ncontacts = contacts.shape[0] vcontacts = [] for i in range(ncontacts): vcontacts.append(vp.Sphere(contacts[i], r=0.8, c='green')) return vlines, vmeshes, vcontacts
def _buttonfunc(self): if self.timerId is not None: self.plotter.timerCallback("destroy", self.timerId) if not self.isplaying: self.timerId = self.plotter.timerCallback("create", dt=100) self.button.switch() self.isplaying = not self.isplaying def handle_timer(self, event): ##################################################################### ### Animate your stuff here ### ##################################################################### #print(event) # info about what was clicked and more #print(self.plotter.actors) # to access object from the internal list earth.rotateZ(1) # rotate the Earth by 1deg moon.color(self.counter) # change color to the Moon txt2d.text("Moon color is:").color(self.counter).background(self.counter,0.1) txt2d.text(vedo.getColorName(self.counter), "top-center") txt2d.text("..press q to quit", "bottom-right") self.plotter.render() self.counter += 1 viewer = Viewer(axes=1, dt=150).initialize() earth = vedo.Earth() moon = vedo.Sphere(r=0.1).x(1.5).color('k7') txt2d = vedo.CornerAnnotation().font("Kanopus") viewer.show(earth, moon, txt2d, viewup='z')
def make_video(sid, rid, video_file): regpos, w, obsmask, surfaces, contacts = read_structural_data(sid, rid) vlines, vmeshes, vcontacts = viz_structure(regpos, w, surfaces, contacts) # Load results res = io.parse_csv([ f"run/solo/INC/vep/id{sid:03d}/output/r{rid:02d}_all/chain_{chain}.csv" for chain in [1, 2] ]) tinf = res['t'] t = 0.0 psz = np.mean(tinf < t, axis=0) nreg = regpos.shape[0] # Regions cmap = 'bwr' vpoints = [] for i in range(nreg): if not obsmask[i]: vpoints.append( vp.Sphere(regpos[i], r=4, c=vp.colorMap(psz[i], cmap, 0, 1))) else: vpoints.append( vp.Cube(regpos[i], side=6, c=vp.colorMap(psz[i], cmap, 0, 1))) vbar = vp.Points(regpos, r=0.01).pointColors(psz, cmap=cmap, vmin=0, vmax=1) vbar.addScalarBar(horizontal=True, pos=(0.8, 0.02)) vtext = vp.Text2D(f"t = {t:4.1f} s", pos=0, s=2, c='black') center = np.mean(regpos, axis=0) dist = 2.5 * (np.max(regpos[:, 1]) - np.min(regpos[:, 1])) # Video ------------------------------------------------------- vplotter = vp.Plotter(axes=0, interactive=0, offscreen=True, size=(1800, 1800)) nframes = 3000 vplotter += vpoints vplotter += vlines vplotter += vmeshes video = vp.Video(name=video_file, duration=90) ratios = np.array([30, 3, 5, 30, 5, 3, 30, 10]) frames = (nframes * ratios / np.sum(ratios)).astype(int) # Run and pause animate(vplotter, video, frames[0], vpoints, tinf, pos=center + dist * np.r_[0, 0, 1], foc=center, viewup=(0, 1, 1), prange=(0, 45), time=lambda p: p) animate(vplotter, video, frames[1], vpoints, tinf, pos=center + dist * np.r_[0, 0, 1], foc=center, viewup=(0, 1, 1), time=45.) ## Fly around pos = lambda angle: center + dist * np.array( [0, -np.sin(angle), np.cos(angle)]) animate(vplotter, video, frames[2], vpoints, tinf, pos=pos, foc=center, viewup=(0, 1, 1), prange=(0, np.pi / 2), time=45., endpoint=False) pos = lambda angle: center + dist * np.array( [-np.sin(angle), -np.cos(angle), 0]) animate(vplotter, video, frames[3], vpoints, tinf, pos=pos, foc=center, viewup=(0, 0, 1), prange=(0, 2 * np.pi), time=45.) pos = lambda angle: center + dist * np.array( [0, -np.sin(angle), np.cos(angle)]) animate(vplotter, video, frames[4], vpoints, tinf, pos=pos, foc=center, viewup=(0, 1, 1), prange=(np.pi / 2, 0), time=45., startpoint=False) # Pause + run + pause animate(vplotter, video, frames[5], vpoints, tinf, pos=center + dist * np.r_[0, 0, 1], foc=center, viewup=(0, 1, 1), time=45.) animate(vplotter, video, frames[6], vpoints, tinf, pos=center + dist * np.r_[0, 0, 1], foc=center, viewup=(0, 1, 1), prange=(45, 90), time=lambda p: p) animate(vplotter, video, frames[7], vpoints, tinf, pos=center + dist * np.r_[0, 0, 1], foc=center, viewup=(0, 1, 1), time=90.) video.close()