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_param_manifold(filename, size): data = np.load(filename) vline = vp.Tube(data['boundary_hns'], r=0.08) vline.color('g') # HNS manifold vmesh_hns = vp.Mesh([data['verts_hns'], data['triangs_hns']]) k = 3 prior = (2 * np.pi)**(-k / 2) * (np.exp( -0.5 * np.sum(vmesh_hns.points()**2, axis=1))) vmesh_hns.pointColors(prior, cmap='Reds', vmin=0) vmesh_hns.addScalarBar(horizontal=True, nlabels=6, c='k', pos=(0.74, 0.01), titleFontSize=44) vmesh_hns.scalarbar.SetLabelFormat("%.2g") vmesh_hns.scalarbar.SetBarRatio(1.0) # Inverted HNS manifold vmesh_hnsi = vp.Mesh([data['verts_hnsi'], data['triangs_hnsi']]) # vmesh_hnsi.color([0.68, 0.68, 0.68]) vmesh_hnsi.color([0.9, 0.9, 0.9]).alpha(0.0) # Invisible points to set the extent vpoints = vp.Points([(-5.01, -5.01, -5.01), (5.01, 5.01, 5.01)]).alpha(0.0) vplotter = vp.Plotter(offscreen=True, size=size, axes=dict(xyGrid=True, yzGrid=True, zxGrid=True, xTitleSize=0, yTitleSize=0, zTitleSize=0, xHighlightZero=True, yHighlightZero=True, zHighlightZero=True, xHighlightZeroColor='b', yHighlightZeroColor='b', zHighlightZeroColor='b', numberOfDivisions=10, axesLineWidth=5, tipSize=0.02, gridLineWidth=2, xLabelSize=0.05, yLabelSize=0.05, zLabelSize=0.05, xLabelOffset=0.05, yLabelOffset=0.05, zLabelOffset=0.0, zTitleRotation=225)) vlabels = [ vp.Text2D("H", (0.09 * size[0], 0.10 * size[1]), s=3, font='Arial'), vp.Text2D("N", (0.87 * size[0], 0.16 * size[1]), s=3, font='Arial'), vp.Text2D("S", (0.49 * size[0], 0.90 * size[1]), s=3, font='Arial') ] k = 2 vecs = np.array([[[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[k, -k, 0, 0, 0, 0], [0, 0, k, -k, 0, 0], [0, 0, 0, 0, k, -k]]]) varrows = vp.Arrows(vecs[0].T, vecs[1].T, s=1.2, c='k') vp.show([vline, vmesh_hns, vmesh_hnsi, vpoints, varrows] + vlabels, camera=dict(pos=(16, 13, 20), focalPoint=(0, 0, 1.5), viewup=(0, 0, 1))) img = vp.screenshot(None, scale=1, returnNumpy=True) vp.clear() vp.closePlotter() return img
def viz_observation_manifold(t3, tlim, size): tmin = 0 tmax = 2 * tlim # tlim line vline1 = vp.Tube([[tmin, tlim, t3], [tmax, tlim, t3]], r=2.0) vline1.color('g') # t = 0 line vline2 = vp.Tube([[tmin, tlim, t3], [tmin, tmax, t3]], r=2.0) vline2.color((1, 1, 1)) # Manifold verts = [[tmin, tlim, t3], [tmax, tlim, t3], [tmin, tmax, t3], [tmax, tmax, t3]] triangs = [[0, 1, 3], [0, 3, 2]] vmesh1 = vp.Mesh([verts, triangs]) vmesh1.color((1, 1, 1)) # Inverse manifold verts = [[tmin, tmin, t3], [tmax, tmin, t3], [tmin, tlim, t3], [tmax, tlim, t3]] triangs = [[0, 1, 3], [0, 3, 2]] vmesh2 = vp.Mesh([verts, triangs]) vmesh2.color((0.9, 0.9, 0.9)).alpha(0.0) # Invisible points to set the extent vpoints = vp.Points([(tmin - 0.1, tmin - 0.1, tmin - 0.1), (1.01 * tmax, 1.01 * tmax, 1.01 * tmax)]).alpha(0.0) lpos = [(p, str(p)) for p in [0, 50, 100, 150]] vplotter = vp.Plotter(offscreen=True, size=size, axes=dict(xyGrid=True, yzGrid=True, zxGrid=True, xTitleSize=0, yTitleSize=0, zTitleSize=0, xPositionsAndLabels=lpos, yPositionsAndLabels=lpos, zPositionsAndLabels=lpos[1:], axesLineWidth=5, tipSize=0.02, gridLineWidth=2, xLabelSize=0.05, yLabelSize=0.05, zLabelSize=0.05, xLabelOffset=0.05, yLabelOffset=0.05, zLabelOffset=0.0, zTitleRotation=225)) vlabels = [ vp.Text2D("H", (0.09 * size[0], 0.10 * size[1]), s=3, font='Arial'), vp.Text2D("N", (0.87 * size[0], 0.16 * size[1]), s=3, font='Arial'), vp.Text2D("S", (0.49 * size[0], 0.90 * size[1]), s=3, font='Arial') ] vp.show([vline1, vline2, vmesh1, vpoints] + vlabels, camera=dict(pos=(378, 324, 450), focalPoint=(tlim, tlim, tlim + 27), viewup=(0, 0, 1))) img = vp.screenshot(None, scale=1, returnNumpy=True) vp.clear() vp.closePlotter() return img
def close(self): closePlotter()