def update_vectors(self, vcount, vgrids, vcount_limits): vx, vy, vz = vgrids[:3] if vx is not None and vy is not None and vz is not None and vcount is not None: vcount = vcount[-1] # no multivolume render, just take the last selection vx = vx[-1] vy = vy[-1] vz = vz[-1] ok = np.isfinite(vx) & np.isfinite(vy) & np.isfinite(vz) vcount_min = None vcount_max = None if vcount_limits is not None: try: vcount_min, vcount_max = vcount_limits except: vcount_min = self.vcount_limits if vcount_min is not None: ok &= (vcount > vcount_min) if vcount_max is not None: ok &= (vcount < vcount_max) # TODO: we assume all dimensions are equal length x, y, z = xyz(vx.shape[0], limits=self.limits, sparse=False, centers=True) v1d = [k[ok] for k in [x, y, z, vx, vy, vz]] vsize = 5 vcolor = "grey" if self._first_time_vector: self._first_time_vector = False self.quiver = p3.quiver(*v1d, size=vsize, color=vcolor) else: with self.quiver.hold_trait_notifications(): self.quiver.x = x[ok] self.quiver.y = y[ok] self.quiver.z = z[ok] self.quiver.vx = vx[ok] self.quiver.vy = vy[ok] self.quiver.vz = vz[ok]
def _velocity_vectors_handler(self, change): import ipyvolume.pylab as p3 data = self.get_frame(self._widgets.frame.value)['arrays'] array_name = change['owner'].owner pa_widgets = self._widgets.particles[array_name] if change['new'] is False: self.vectors[array_name].size = 0 else: if array_name in self.vectors.keys(): vectors = self.vectors[array_name] vectors.x = data[array_name].x vectors.y = data[array_name].y vectors.z = data[array_name].z vectors.vx = getattr(data[array_name], 'u') vectors.vy = getattr(data[array_name], 'v') vectors.vz = getattr(data[array_name], 'w') vectors.size = pa_widgets.vector_size.value else: self.vectors[array_name] = p3.quiver( data[array_name].x, data[array_name].y, data[array_name].z, getattr(data[array_name], 'u'), getattr(data[array_name], 'v'), getattr(data[array_name], 'w'), size=pa_widgets.vector_size.value, )
def _update_image(self): with self.output: grid = self.get_grid() if self.smooth_pre: for i in range(grid.shape[0]): grid[i] = vaex.grids.gf(grid[i], self.smooth_pre) f = vaex.dataset._parse_f(self.f) fgrid = f(grid) if self.smooth_post: for i in range(grid.shape[0]): fgrid[i] = vaex.grids.gf(fgrid[i], self.smooth_post) ngrid, fmin, fmax = self.normalise(fgrid) print(ngrid.shape) if len(ngrid.shape) == 4: #if ngrid.shape[0] == 1: ngrid = ngrid[-1] p3.volshow(ngrid.T, controls=self._first_time) vx, vy, vz = self.vgrids[:3] vcount = self.vcount if vx is not None and vy is not None and vz is not None and vcount is not None: vcount = vcount[-1] # no multivolume render, just take the last selection vx = vx[-1] vy = vy[-1] vz = vz[-1] print(vx.shape) ok = np.isfinite(vx) & np.isfinite(vy) & np.isfinite(vz) vcount_min = None vcount_max = None if self.vcount_limits is not None: try: vcount_min, vcount_max = self.vcount_limits except: vcount_min = self.vcount_limits if vcount_min is not None: ok &= (vcount > vcount_min) if vcount_max is not None: ok &= (vcount < vcount_max) x, y, z = ipyvolume.examples.xyz(self.get_vshape()[0], limits=self.limits, sparse=False, centers=True) v1d = [k[ok] for k in [x, y, z, vx, vy, vz]] vsize = 5 vcolor = "grey" if self._first_time: self.quiver = p3.quiver(*v1d, size=vsize, color=vcolor) else: self.quiver.x = x[ok] self.quiver.y = y[ok] self.quiver.z = z[ok] self.quiver.vx = vx[ok] self.quiver.vy = vy[ok] self.quiver.vz = vz[ok] p3.xlim(*self.limits[0]) p3.ylim(*self.limits[1]) p3.zlim(*self.limits[2]) self._first_time = False
def init_vector(show=True): #This function initializes a figure with basis vectors in world frame - requires import ipyvolume.pylab as p3 outside scope #p3.clear() origin = np.array([0.0, 0.0, 0.0]) x = origin + np.array([1.0, 0.0, 0.0]) y = origin + np.array([0.0, 1.0, 0.0]) z = origin + np.array([0.0, 0.0, 1.0]) u = np.array([1.0, 0.0, 0.0]) v = np.array([0.0, 1.0, 0.0]) w = np.array([0.0, 0.0, 1.0]) quiver = p3.quiver(x, y, z, u, v, w, size=10, marker='arrow', color=np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])) #ipv.show() scatter = p3.scatter(np.array([origin[0]]), np.array([origin[0]]), np.array([origin[0]]), size=5, marker='sphere', color='red') line1 = p3.plot(np.array([origin[0], x[0]]), np.array([origin[0], x[1]]), np.array([origin[0], x[2]]), color='red') line2 = p3.plot(np.array([origin[0], y[0]]), np.array([origin[0], y[1]]), np.array([origin[0], y[2]]), color='green') line3 = p3.plot(np.array([origin[0], z[0]]), np.array([origin[0], z[1]]), np.array([origin[0], z[2]]), color='blue') #scatter = p3.scatter(x,y,z,size=2,marker = 'sphere',color='red') # the origin if show: p3.show() p3.style.box_off() handle = { 'origin': scatter, 'arrows': quiver, 'linex': line1, 'liney': line2, 'linez': line3 } #p3.style.axes_off() return handle
def update_vectors(self, vcount, vgrids, vcount_limits): vx, vy, vz = vgrids[:3] if vx is not None and vy is not None and vz is not None and vcount is not None: vcount = vcount[ -1] # no multivolume render, just take the last selection vx = vx[-1] vy = vy[-1] vz = vz[-1] ok = np.isfinite(vx) & np.isfinite(vy) & np.isfinite(vz) vcount_min = None vcount_max = None if vcount_limits is not None: try: vcount_min, vcount_max = vcount_limits except: vcount_min = self.vcount_limits if vcount_min is not None: ok &= (vcount > vcount_min) if vcount_max is not None: ok &= (vcount < vcount_max) # TODO: we assume all dimensions are equal length x, y, z = xyz(vx.shape[0], limits=self.limits, sparse=False, centers=True) v1d = [k[ok] for k in [x, y, z, vx, vy, vz]] vsize = 5 vcolor = "grey" if self._first_time_vector: self._first_time_vector = False self.quiver = p3.quiver(*v1d, size=vsize, color=vcolor) else: with self.quiver.hold_trait_notifications(): self.quiver.x = x[ok] self.quiver.y = y[ok] self.quiver.z = z[ok] self.quiver.vx = vx[ok] self.quiver.vy = vy[ok] self.quiver.vz = vz[ok]
def quickquiver(x, y, z, u, v, w, **kwargs): import ipyvolume.pylab as p3 p3.figure() p3.quiver(x, y, z, u, v, w, **kwargs) return p3.current.container
def test_quiver(): x, y, z, u, v, w = np.random.random((6, 100)) p3.quiver(x, y, z, u, v, w) p3.save("tmp/ipyolume_quiver.html")
Lz.material.visible = False Lz.line_material.visible = True # coordinate frame axes line segment tip arrows Xfv = Xf[:, 1, :] - Xf[:, 0, :] Yfv = Yf[:, 1, :] - Yf[:, 0, :] Zfv = Zf[:, 1, :] - Zf[:, 0, :] arrowcols = np.zeros((k, 3, 3)) arrowcols[0:k, 0, 0] = 1.0 arrowcols[0:k, 1, 1] = 1.0 arrowcols[0:k, 2, 2] = 1.0 q = p3.quiver(Xf[:, 1, :], Yf[:, 1, :], Zf[:, 1, :], Xfv[:, :], Yfv[:, :], Zfv[:, :], size=10, size_selected=5, color=arrowcols, color_selected='gray') # cylinder body surface s = p3.plot_surface(Xc, Yc, Zc, color='orange') # pass ipyvolume objects to animation controller and show p3.animation_control([Lx, Ly, Lz, q, s], interval=100) p3.show() # In[ ]: p3.save("shape_xform.html", offline=True)
def test_quiver_exception(): x, y, z, u, v, w = np.random.random((6, 100)) with pytest.raises(KeyError): p3.quiver(x, y, z, u, v, w, vx=u)
import ipyvolume.pylab as p3 import numpy as np fig = p3.figure() q = p3.quiver(*stream.data[:,0:50,:200], color="red", size=7) p3.style.use("dark") # looks better p3.animate_glyphs(q, interval=200) p3.show()
import ipyvolume.pylab as p3 import numpy as np fig = p3.figure() q = p3.quiver(*stream.data[:,0:50,:200], color="red", size=7) p3.style.use("dark") # looks better p3.animation_control(q, interval=200) p3.show()