def quiver_demo(**kwargs): ''' quiver_demo(length = 1.0, normalize = True, facecolor = 'b', edgecolor = None, arrow_length_ratio = 0.3, shaftsize = 0.01, headsize = 0.01) ''' from ifigure.interactive import quiver, threed, figure, lighting, view, isec, nsec x, y, z = np.meshgrid(np.arange(-0.8, 1, 0.2), np.arange(-0.8, 1, 0.2), np.arange(-0.8, 1, 0.8)) u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z) v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z) w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) * np.sin(np.pi * z)) figure() nsec(2) isec(0) threed('on') lighting(light = 0.5, ambient = 0.7) view('noclip') quiver(x, y, z, u, v, w, length = 0.3, facecolor = 'b') isec(1) threed('on') lighting(light = 0.5, ambient = 0.7) view('noclip') quiver(x, y, z, u, v, w, cz = True, cdata = y, length = 0.3)
def onPlotTimeDep(self, e=None, *args, **kargs): def plot_data(time, data): x = np.array(time, dtype='float').flatten() y = np.array(data, dtype='float').flatten() x = [t for t in x if not np.isnan(t)] y = [t for t in y if not np.isnan(t)] return np.array(x), np.array(y) help = self.td._var0._help data = self.td._var0 import ifigure.interactive as plt plt.figure() time = data['18']['data'] new_plot = True for key in help: if not key in data: continue if key == '18': continue x, y = help[key] if y.startswith('-'): if not new_plot: plt.addpage() try: xdata, ydata = plot_data(time, data[key]['data']) plt.plot(xdata, ydata) plt.title(x) new_plot = False except: print('failed to generate picture for', key) new_plot = True pass
def surf_demo2(**kwargs): from mpl_toolkits.mplot3d import Axes3D import numpy as np from ifigure.interactive import surf, threed, figure, isec, nsec figure(gl=True) nsec(3) isec(0) threed('on') u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = 10 * np.outer(np.cos(u), np.sin(v)) y = 10 * np.outer(np.sin(u), np.sin(v)) z = 10 * np.outer(np.ones(np.size(u)), np.cos(v)) surf(x, y, z, cz=False, facecolor='b', edgecolor='k') isec(1) threed('on') surf(x, y, z, cstride=4, cz=True, edgecolor='k') isec(2) threed('on') surf(x, y, z, cz=True, cdata=y, edgecolor=None)
def specgram_demo(): ''' the demo in matplotlib. But calls interactive.specgram ''' from pylab import arange, sin, where, logical_and, randn, pi dt = 0.0005 t = arange(0.0, 20.0, dt) s1 = sin(2*pi*100*t) s2 = 2*sin(2*pi*400*t) # create a transient "chirp" mask = where(logical_and(t>10, t<12), 1.0, 0.0) s2 = s2 * mask # add some noise into the mix nse = 0.01*randn(len(t)) x = s1 + s2 + nse # the signal NFFT = 1024 # the length of the windowing segments Fs = int(1.0/dt) # the sampling frequency from ifigure.interactive import figure, specgram, nsec, plot, isec, clog, hold figure() hold(True) nsec(2) isec(0) plot(t, x) isec(1) specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900) clog()
def quiver_demo(**kwargs): ''' quiver_demo(length = 1.0, normalize = True, facecolor = 'b', edgecolor = None, arrow_length_ratio = 0.3, shaftsize = 0.01, headsize = 0.01) ''' from ifigure.interactive import quiver, threed, figure, lighting, view, isec, nsec x, y, z = np.meshgrid(np.arange(-0.8, 1, 0.2), np.arange(-0.8, 1, 0.2), np.arange(-0.8, 1, 0.8)) u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z) v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z) w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) * np.sin(np.pi * z)) figure() nsec(2) isec(0) threed('on') lighting(light=0.5, ambient=0.7) view('noclip') quiver(x, y, z, u, v, w, length=0.3, facecolor='b') isec(1) threed('on') lighting(light=0.5, ambient=0.7) view('noclip') quiver(x, y, z, u, v, w, cz=True, cdata=y, length=0.3)
def onSlice(self, event): from ifigure.interactive import figure, plot, nsec, isec, update, title, xlabel, ylabel if event.mpl_xydata[0] is None: return for a in self._artists: axes = a.axes if axes is None: return data1, data2 = self.get_slice(event.mpl_xy[0], event.mpl_xy[1], a) if data1 is None: continue if data2 is None: continue figure() nsec(2) ou = update() isec(0) plot(data1[0], data1[1]) title('y slice : y = '+str(event.mpl_xydata[1])) xlabel('x') isec(1) plot(data2[0], data2[1]) title('x slice : x = '+str(event.mpl_xydata[0])) xlabel('y') update(ou)
def surf_demo2(**kwargs): from mpl_toolkits.mplot3d import Axes3D import numpy as np from ifigure.interactive import surf, threed, figure, isec, nsec figure(gl = True) nsec(3) isec(0) threed('on') u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = 10 * np.outer(np.cos(u), np.sin(v)) y = 10 * np.outer(np.sin(u), np.sin(v)) z = 10 * np.outer(np.ones(np.size(u)), np.cos(v)) surf(x, y, z, cz = False, facecolor='b', edgecolor = 'k') isec(1) threed('on') surf(x, y, z, cstride=4, cz = True, edgecolor = 'k') isec(2) threed('on') surf(x, y, z, cz = True, cdata = y, edgecolor = None)
def spec_demo(): ''' the demo in matplotlib. But calls interactive.specgram ''' from pylab import arange, sin, where, logical_and, randn, pi dt = 0.0005 t = arange(0.0, 20.0, dt) s1 = sin(2 * pi * 100 * t) s2 = 2 * sin(2 * pi * 400 * t) # create a transient "chirp" mask = where(logical_and(t > 10, t < 12), 1.0, 0.0) s2 = s2 * mask # add some noise into the mix nse = 0.01 * randn(len(t)) x = s1 + s2 + nse # the signal NFFT = 1024 # the length of the windowing segments Fs = int(1.0 / dt) # the sampling frequency from ifigure.interactive import figure, spec, nsec, plot, isec, clog, hold figure() hold(True) nsec(2) isec(0) plot(t, x) isec(1) spec(t, x, NFFT=NFFT, noverlap=900) clog()
def plot_tiles3(): x, y, z = read_tile_data(list=True) figure() threed('on') hold('on') for k in range(100): m = k + 100 plot(x[m], y[m], z[m], facecolor=[1, 0, 0, 1])
def plot_tiles3(): x, y, z = read_tile_data(list = True) figure() threed('on') hold('on') for k in range(100): m = k+100 plot(x[m], y[m], z[m], facecolor = [1, 0, 0, 1])
def plot_tiles(): ''' line plot of tile data ''' x, y, z = read_tile_data() figure() threed('on') plot(x, y, z)
def image_demo(): from ifigure.interactive import image, figure x = np.linspace(-5, 5, 41) y = np.linspace(-5, 5, 41) X, Y = np.meshgrid(x, y) r = np.sqrt(X*X + Y*Y) z = np.cos(r/10.*6*3.14)*np.exp(-r/3) figure() image(x, y, z)
def image_demo(): from ifigure.interactive import image, figure x = np.linspace(-5, 5, 41) y = np.linspace(-5, 5, 41) X, Y = np.meshgrid(x, y) r = np.sqrt(X * X + Y * Y) z = np.cos(r / 10. * 6 * 3.14) * np.exp(-r / 3) figure() image(x, y, z)
def surf_demo(**kwargs): from ifigure.interactive import surf, threed, figure, hold, lighting figure() threed('on') # X = np.arange(-5, 5, 0.25) # Y = np.arange(-5, 5, 0.25) X = np.linspace(-5, 5, 40) Y = np.linspace(-5, 5, 40) X, Y = np.meshgrid(X, Y) R = np.sqrt(X**2 + Y**2) Z = np.sin(R) lighting(light=0.5, ambient=0.7) surf(X, Y, Z, cmap='coolwarm', shade='linear', **kwargs)
def surf_demo(**kwargs): from ifigure.interactive import surf, threed, figure, hold, lighting figure() threed('on') # X = np.arange(-5, 5, 0.25) # Y = np.arange(-5, 5, 0.25) X = np.linspace(-5, 5, 40) Y = np.linspace(-5, 5, 40) X, Y = np.meshgrid(X, Y) R = np.sqrt(X**2 + Y**2) Z = np.sin(R) lighting(light = 0.5, ambient = 0.7) surf(X, Y, Z, cmap='coolwarm', shade = 'linear', **kwargs)
def contourf_demo(**kwargs): import mpl_toolkits.mplot3d.axes3d as axes3d from ifigure.interactive import contourf, threed, figure X, Y, Z = axes3d.get_test_data(0.05) v = figure(gl=True) threed('on') contourf(X, Y, Z)
def test_ax(): v = figure() ax = v.get_axes() pl = v.plot(np.arange(30)) ret = check_prop_read(ax) check_prop_write(ax, ret)
def trisurf3d_demo(**kwargs): from matplotlib import cm import numpy as np from ifigure.interactive import figure, threed, trisurf, nsec, isec, lighting # preparing the data, the same as mplot3d demo n_angles = 36 n_radii = 8 radii = np.linspace(0.125, 1.0, n_radii) angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False) angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1) x = np.append(0, (radii * np.cos(angles)).flatten()) y = np.append(0, (radii * np.sin(angles)).flatten()) z = np.sin(-x * y) v = figure() nsec(3) isec(0) threed('on') trisurf(x, y, z, cmap=cm.jet, linewidth=0.2, cz=True) isec(1) threed('on') trisurf(x, y, z, linewidth=0.2, color='b') lighting(light=0.5, ambient=0.5) isec(2) threed('on') trisurf(x, y, z * 0, cmap=cm.jet, linewidth=0.2, cz=True, cdata=z, edgecolor=None)
def open_meshviewer(): viewer = figure(); viewer.threed(True) viewer.xlabel('x') viewer.ylabel('y') viewer.zlabel('z') w = viewer.attach_to_main() return w
def trisurf3d_demo(**kwargs): from matplotlib import cm import numpy as np from ifigure.interactive import figure, threed, trisurf , nsec, isec, lighting # preparing the data, the same as mplot3d demo n_angles = 36 n_radii = 8 radii = np.linspace(0.125, 1.0, n_radii) angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False) angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1) x = np.append(0, (radii*np.cos(angles)).flatten()) y = np.append(0, (radii*np.sin(angles)).flatten()) z = np.sin(-x*y) v = figure() nsec(3) isec(0) threed('on') trisurf(x, y, z, cmap=cm.jet, linewidth=0.2, cz = True) isec(1) threed('on') trisurf(x, y, z, linewidth=0.2, color='b') lighting(light = 0.5, ambient = 0.5) isec(2) threed('on') trisurf(x, y, z*0, cmap=cm.jet, linewidth=0.2, cz = True, cdata = z, edgecolor = None)
def contourf_demo(**kwargs): import mpl_toolkits.mplot3d.axes3d as axes3d from ifigure.interactive import contourf, threed, figure X, Y, Z = axes3d.get_test_data(0.05) v = figure(gl = True) threed('on') contourf(X, Y, Z)
def plot_shape(dof, ptx, shape, viewer = None): try: viewer.Validate() except: from ifigure.interactive import figure viewer = figure() ll = shape.shape[1] n = int(np.ceil(np.sqrt(ll))) viewer.cls() viewer.nsec(n, int(np.ceil(float(ll)/float(n)))) for i in range(ll): x = ptx[:, 0]; y= ptx[:, 1] viewer.isec(i) if len(shape.shape) == 3: viewer.tripcolor(ptx[:,0], ptx[:,1], ptx[:,1]*0) u=shape[:, i, 0]; v = shape[:, i, 1] viewer.quiver(x, y, u, v) else: viewer.tripcolor(ptx[:,0], ptx[:,1], shape[:,i]) idx = np.where(np.abs(shape[:,i]) < 1e-10)[0] if len(idx)>0: viewer.plot(ptx[idx,0], ptx[idx,1], 'gs') viewer.plot([dof[i][0]], [dof[i][1]], 'or')
def _doPlotExpr(self, value): model = self.parent.model.param.getvar('mfem_model') if model is None: return expr = str(value[0]) phys = str(value[3]) use_2dplot = model['Phys'][phys].dim == 1 from petram.utils import eval_expr try: engine = self.parent.engine d = eval_expr(model, engine, expr, value[1], phys=phys) except: dialog.showtraceback(parent=self, txt='Failed to evauate expression', title='Error', traceback=traceback.format_exc()) return from ifigure.interactive import figure v = figure() v.update(False) v.suptitle(expr) if use_2dplot: for k in d.keys(): v.plot(d[k][0][:, 0, 0].flatten(), d[k][1][:, 0].flatten()) v.update(True) else: from petram.pi.dlg_plot_sol import setup_figure setup_figure(v, self.GetParent()) for k in d.keys(): v.solid(d[k][0], cz=True, cdata=d[k][1]) v.update(True) v.view('noclip') v.lighting(light=0.5)
def image_demo(): from ifigure.interactive import image, threed, figure, hold figure(gl = True) threed('on') hold('on') X = np.linspace(-5, 5, 40) Y = np.linspace(-5, 5, 40) X, Y = np.meshgrid(X, Y) R = np.sqrt(X**2 + Y**2) Z = np.sin(R) image(Z, cmap='coolwarm', im_center = [0,0,1]) image(Z, cmap='coolwarm', im_center = [0,0,1], im_axes = ([0,0,1], [0,1,0])) image(Z, cmap='coolwarm', im_center = [0,0,1], im_axes = ([1/np.sqrt(2), 0,1/np.sqrt(2)], [0, 1, 0]))
def contour_demo2(**kwargs): import mpl_toolkits.mplot3d.axes3d as axes3d from ifigure.interactive import contourf, threed, figure, hold X, Y, Z = axes3d.get_test_data(0.05) v = figure(gl=True) threed('on') hold('on') contourf(X, Y, Z) contourf(X, Y, Z, zdir='x', offset=-40)
def trisurf3d_demo2(**kwargs): import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import matplotlib.tri as mtri from ifigure.interactive import figure # preparing the data, the same as mplot3d demo u = (np.linspace(0, 2.0 * np.pi, endpoint=True, num=50) * np.ones( (10, 1))).flatten() v = np.repeat(np.linspace(-0.5, 0.5, endpoint=True, num=10), repeats=50).flatten() # This is the Mobius mapping, taking a u, v pair and returning an x, y, z # triple x = (1 + 0.5 * v * np.cos(u / 2.0)) * np.cos(u) y = (1 + 0.5 * v * np.cos(u / 2.0)) * np.sin(u) z = 0.5 * v * np.sin(u / 2.0) # Triangulate parameter space to determine the triangles tri = mtri.Triangulation(u, v) v = figure(gl=True) v.nsec(2) v.isec(0) v.threed('on') v.trisurf(x, y, z, triangles=tri.triangles, cmap=plt.cm.Spectral, cz=True) # First create the x and y coordinates of the points. n_angles = 36 n_radii = 8 min_radius = 0.25 radii = np.linspace(min_radius, 0.95, n_radii) angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False) angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1) angles[:, 1::2] += np.pi / n_angles x = (radii * np.cos(angles)).flatten() y = (radii * np.sin(angles)).flatten() z = (np.cos(radii) * np.cos(angles * 3.0)).flatten() # Create the Triangulation; no triangles so Delaunay triangulation created. triang = mtri.Triangulation(x, y) # Mask off unwanted triangles. xmid = x[triang.triangles].mean(axis=1) ymid = y[triang.triangles].mean(axis=1) mask = np.where(xmid * xmid + ymid * ymid < min_radius * min_radius, 1, 0) triang.set_mask(mask) v.isec(1) v.threed('on') v.trisurf(triang, z, cmap=plt.cm.CMRmap, cz=True, shade='linear', edgecolor=None)
def contour_demo2(**kwargs): import mpl_toolkits.mplot3d.axes3d as axes3d from ifigure.interactive import contourf, threed, figure, hold X, Y, Z = axes3d.get_test_data(0.05) v = figure(gl = True) threed('on') hold('on') contourf(X, Y, Z) contourf(X, Y, Z, zdir = 'x', offset = -40)
def plot_faces(mesh, faces, refine=3, win=None, fc='b'): if win is None: win = figure() data = get_face_data(mesh, faces, refine=3) for k in data: ptx_x, ivert_x, iverte_x, attrs_x = data[k] win.solid(ptx_x, ivert_x, facecolor=fc, array_idx=attrs_x) win.solid(ptx_x, iverte_x, facecolor='k') return win
def solid_stl_demo(**kwargs): from stl import mesh from ifigure.interactive import solid, figure, threed import ifigure, os from os.path import dirname path = dirname(dirname(dirname(ifigure.__file__))) mymesh = mesh.Mesh.from_file(os.path.join(path, 'example', 'D_antenna.stl')) v = figure() threed('on') solid(mymesh.vectors, alpha = 0.5, **kwargs)
def revolve_demo(**kwargs): m = np.linspace(0, np.pi * 2, 30) r = 1.0 + 0.2 * np.cos(m) z = 0.25 * np.sin(m) from ifigure.interactive import revolve, figure, threed v = figure(gl=True) threed('on') revolve(r, z, raxis=[0.5, 1], rtheta=[0, 2 * np.pi / 3]) v.xlim(-1.5, 1.5) v.ylim(-1.5, 1.5) v.zlim(-1.5, 1.5)
def solid_stl_demo(**kwargs): from stl import mesh from ifigure.interactive import solid, figure, threed import ifigure, os from os.path import dirname path = dirname(dirname(dirname(ifigure.__file__))) mymesh = mesh.Mesh.from_file(os.path.join(path, 'example', 'D_antenna.stl')) v = figure() threed('on') solid(mymesh.vectors, alpha=0.5, **kwargs)
def image_demo(): from ifigure.interactive import image, threed, figure, hold figure(gl=True) threed('on') hold('on') X = np.linspace(-5, 5, 40) Y = np.linspace(-5, 5, 40) X, Y = np.meshgrid(X, Y) R = np.sqrt(X**2 + Y**2) Z = np.sin(R) image(Z, cmap='coolwarm', im_center=[0, 0, 1]) image(Z, cmap='coolwarm', im_center=[0, 0, 1], im_axes=([0, 0, 1], [0, 1, 0])) image(Z, cmap='coolwarm', im_center=[0, 0, 1], im_axes=([1 / np.sqrt(2), 0, 1 / np.sqrt(2)], [0, 1, 0]))
def revolve_demo(**kwargs): m = np.linspace(0, np.pi*2, 30) r = 1.0 + 0.2*np.cos(m) z = 0.25 * np.sin(m) from ifigure.interactive import revolve, figure, threed v = figure(gl = True) threed('on') revolve(r, z, raxis = [0.5, 1], rtheta = [0, 2*np.pi/3]) v.xlim(-1.5, 1.5) v.ylim(-1.5, 1.5) v.zlim(-1.5, 1.5)
def trisurf3d_demo2(**kwargs): import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import matplotlib.tri as mtri from ifigure.interactive import figure # preparing the data, the same as mplot3d demo u = (np.linspace(0, 2.0 * np.pi, endpoint=True, num=50) * np.ones((10, 1))).flatten() v = np.repeat(np.linspace(-0.5, 0.5, endpoint=True, num=10), repeats=50).flatten() # This is the Mobius mapping, taking a u, v pair and returning an x, y, z # triple x = (1 + 0.5 * v * np.cos(u / 2.0)) * np.cos(u) y = (1 + 0.5 * v * np.cos(u / 2.0)) * np.sin(u) z = 0.5 * v * np.sin(u / 2.0) # Triangulate parameter space to determine the triangles tri = mtri.Triangulation(u, v) v = figure(gl = True) v.nsec(2) v.isec(0) v.threed('on') v.trisurf(x, y, z, triangles=tri.triangles, cmap=plt.cm.Spectral, cz = True) # First create the x and y coordinates of the points. n_angles = 36 n_radii = 8 min_radius = 0.25 radii = np.linspace(min_radius, 0.95, n_radii) angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False) angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1) angles[:,1::2] += np.pi/n_angles x = (radii*np.cos(angles)).flatten() y = (radii*np.sin(angles)).flatten() z = (np.cos(radii)*np.cos(angles*3.0)).flatten() # Create the Triangulation; no triangles so Delaunay triangulation created. triang = mtri.Triangulation(x, y) # Mask off unwanted triangles. xmid = x[triang.triangles].mean(axis=1) ymid = y[triang.triangles].mean(axis=1) mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0) triang.set_mask(mask) v.isec(1) v.threed('on') v.trisurf(triang, z, cmap=plt.cm.CMRmap, cz = True, shade = 'linear', edgecolor = None)
def image_video_demo(): from ifigure.interactive import image, figure x = np.linspace(-5, 5, 41) y = np.linspace(-5, 5, 41) X, Y = np.meshgrid(x, y) z = [] for shift in np.linspace(-2., 2, 10): r = np.sqrt((X - shift)**2 + Y * Y) d = np.cos(r / 10. * 6 * 3.14) * np.exp(-r / 3) z.append(d[np.newaxis, :, :]) z = np.vstack(z) from ifigure.widgets.video_viewer import VideoViewer v = figure(viewer=VideoViewer) v.image(x, y, z)
def image_video_demo(): from ifigure.interactive import image, figure x = np.linspace(-5, 5, 41) y = np.linspace(-5, 5, 41) X, Y = np.meshgrid(x, y) z = [] for shift in np.linspace(-2., 2, 10): r = np.sqrt((X-shift)**2 + Y*Y) d = np.cos(r/10.*6*3.14)*np.exp(-r/3) z.append(d[np.newaxis, :,:]) z = np.vstack(z) from ifigure.widgets.video_viewer import VideoViewer v = figure(viewer = VideoViewer) v.image(x, y, z)
def plot_inverted(self, evt): from petram.mesh.mesh_inspect import plot_elements editor = evt.GetEventObject().GetTopLevelParent() viewer = editor.GetParent() mesh = viewer.model.variables.getvar('mesh') inverted = self._invalid_data[2] from ifigure.interactive import figure from petram.mfem_viewer import setup_figure win = figure() setup_figure(win) win.view('noclip') plot_elements(mesh, inverted, refine=10, win=win)
def _on_scope(self, obj, threed=False): # print self.getvar('mds_path') # print self._td.get_full_path(), self._path from ifigure.interactive import figure book = figure() viewer = book.get_root_parent().app.find_bookviewer(book) p = book.get_page(0) a = p.get_axes(0) a.set_3d(threed) name=a.get_next_name(obj.get_namebase()) a.add_child(name, obj) obj.realize() ifigure.events.SendPVAddFigobj(a) ifigure.events.SendChangedEvent(a, w = viewer.canvas)
def _on_scope(self, obj, threed=False): # print self.getvar('mds_path') # print self._td.get_full_path(), self._path from ifigure.interactive import figure book = figure() viewer = book.get_root_parent().app.find_bookviewer(book) p = book.get_page(0) a = p.get_axes(0) a.set_3d(threed) name = a.get_next_name(obj.get_namebase()) a.add_child(name, obj) obj.realize() ifigure.events.SendPVAddFigobj(a) ifigure.events.SendChangedEvent(a, w=viewer.canvas)
def tripcolor_phasor_demo2(): ''' Example using wave viewer ''' from ifigure.interactive import figure v = np.linspace(0.1, 10, 80) t = np.linspace(0, 3.1415, 80) V, T = np.meshgrid(v,t) x = (V*np.cos(T)).flatten() y = (V*np.sin(T)).flatten() r = np.sqrt(x*x + y*y) z = np.exp(1j*r/10.*6*3.14)*np.exp(-r/3) from ifigure.widgets.wave_viewer import WaveViewer v = figure(viewer = WaveViewer) v.tripcolor(x, y, z)
def tripcolor_phasor_demo2(): ''' Example using wave viewer ''' from ifigure.interactive import figure v = np.linspace(0.1, 10, 80) t = np.linspace(0, 3.1415, 80) V, T = np.meshgrid(v, t) x = (V * np.cos(T)).flatten() y = (V * np.sin(T)).flatten() r = np.sqrt(x * x + y * y) z = np.exp(1j * r / 10. * 6 * 3.14) * np.exp(-r / 3) from ifigure.widgets.wave_viewer import WaveViewer v = figure(viewer=WaveViewer) v.tripcolor(x, y, z)
def plot_faces_containing_elements(mesh, faces, refine=5, fcs=None, win=None): if fcs is None: fcs = 'bg' if win is None: win = figure() data1, data2 = get_faces_containing_elements_data(mesh, faces, refine=refine) for k in data1: ptx_x, ivert_x, iverte_x, attrs_x = data1[k] win.solid(ptx_x, ivert_x, facecolor=fcs[0], array_idx=attrs_x) win.solid(ptx_x, iverte_x, facecolor='k') for k in data2: ptx_x, ivert_x, iverte_x, attrs_x = data2[k] win.solid(ptx_x, ivert_x, facecolor=fcs[1], array_idx=attrs_x) win.solid(ptx_x, iverte_x, facecolor='k') return win
from petram.mfem_viewer import MFEMViewer if not obj.get_pymodel().has_child('mfembook'): from ifigure.interactive import figure v = figure() v.book.rename('mfembook') v.book.set_keep_data_in_tree(True) v.isec(0) v.threed('on') v.view('noclip') v.book.Close() v.book.move(obj.get_pymodel()) obj.get_pymodel().mfembook.Open(MFEMViewer) import wx wx.CallAfter(obj.get_pymodel().mfembook.find_bookviewer().Raise)
def onPlotEq(self, e=None, viewer=None): self_obj = self.td if self_obj.getvar0() is None: return path = self_obj.get_full_path() x = self_obj.get_contents("table", "rgrid") y = self_obj.get_contents("table", "zgrid") z = self_obj.get_contents("table", "psirz") try: xlim = self_obj.get_contents("table", "xlim") ylim = self_obj.get_contents("table", "ylim") rb = self_obj.get_contents("table", "rbbbs") zb = self_obj.get_contents("table", "zbbbs") fpol = self_obj.get_contents("table", "fpol") ssimag = self_obj.get_contents("table", "ssimag") ssibdry = self_obj.get_contents("table", "ssibdry") btrz = self_obj.get_contents("table", "btrz") brrz = self_obj.get_contents("table", "brrz") bzrz = self_obj.get_contents("table", "bzrz") jtrz = self_obj.get_contents("table", "jtrz") bnorm = sqrt(btrz**2 + brrz**2 + bzrz**2) bp = sqrt(brrz**2 + bzrz**2) bangle = np.arctan2(bp, bnorm) # isPlasma = self_obj.get_contents("table", "isPlasma") no_lim_b = False except: no_lim_b = True rmaxis = self_obj.get_contents("table", "rmaxis") zmaxis = self_obj.get_contents("table", "zmaxis") if viewer is None: from ifigure.interactive import figure plt = figure() else: plt = viewer plt.cls() plt.update(False) plt.subplot(4, 3, [0, 1, 2, 3], [4, 5, 6, 7]) plt.isec(4) plt.image(x, y, z, alpha=0.5) plt.contour(x, y, z, 30) if eval('self_obj[:]["table"]["nlim"]') != 0: plt.plot(xlim, ylim) if eval('self_obj[:]["table"]["nbbbs"]') != 0: plt.plot(rb, zb) plt.xlabel('R') plt.ylabel('Z') plt.title('PSI') if not no_lim_b: plt.isec(5) plt.title('B-norm') plt.image(x, y, bnorm, alpha=0.5) plt.contour(x, y, bnorm, 30) if self_obj[:]["table"]["nlim"] > 0: plt.plot(xlim, ylim) if self_obj[:]["table"]["nbbbs"] > 0: plt.plot(rb, zb) plt.xlabel('R') plt.ylabel('Z') plt.isec(0) pres = self_obj.get_contents("table", "pres") plt.plot(pres) plt.title('pressure') plt.xlabel('flux index') plt.isec(1) qpsi = self_obj.get_contents("table", "qpsi") plt.plot(qpsi) plt.title('qpsi') plt.xlabel('flux index') plt.isec(2) fpol = self_obj.get_contents("table", "fpol") plt.plot(fpol) plt.title('f_pol') plt.xlabel('flux index') plt.update(True) if no_lim_b: return from python_lib.analysis.efit_tools import flux_average, npsi2psi, npsi2npsit npsis = np.linspace(0.02, 0.99, 20) psis = [npsi2psi(self_obj, npsi) for npsi in npsis] sqrt_npsit = [np.sqrt(npsi2npsit(self_obj, npsi)) for npsi in npsis] jtor = [flux_average(x, y, z, rmaxis, zmaxis, jtrz, psi) for psi in psis] plt.isec(3) plt.plot(sqrt_npsit, jtor) plt.title('j_tor') plt.xlabel('sqrt_toroidal_flux') plt.update(True)
def plot_tiles2(): x, y, z = read_tile_data() figure() threed('on') plot(x, y, z, facecolor = [1, 0, 0, 1])
def solid_demo(**kwargs): ''' solid_demo2(cz = True, linewidths = 1.0, edgecolor='red') solid_demo2(facecolor='b', linewidths = 1.0, edgecolor='red') ''' from ifigure.interactive import solid, figure, threed, isec, nsec, lighting import ifigure, os # preparing the data, the same as mplot3d demo theta = np.linspace(0, 2.0 * np.pi, endpoint=True, num=50) r = np.linspace(0.01, 4.0, endpoint=True, num=50) # This is the Mobius mapping, taking a u, v pair and returning an x, y, z # triple THETA, R = np.meshgrid(theta, r) X = R*np.cos(THETA) Y = R*np.sin(THETA) Z = np.exp(- R*R) import matplotlib.tri as mtri tri = mtri.Triangulation(X.flatten(), Y.flatten()) # Triangulate parameter space to determine the triangles if 'cz' in kwargs and kwargs['cz']: v = np.dstack((tri.x[tri.triangles], tri.y[tri.triangles], Z.flatten()[tri.triangles],)) v = np.vstack((tri.x, tri.y, Z.flatten())) kwargs['cdata'] = 5*Z.flatten()[tri.triangles] kwargs['cdata'] = 5*Z.flatten() kwargs['cz'] = True # or # v = np.dstack((tri.x[tri.triangles], tri.y[tri.triangles], Z.flatten()[tri.triangles], 5 * Z.flatten()[tri.triangles],)) v = np.vstack((tri.x, tri.y, Z.flatten(), 5*Z.flatten())) elif 'twod' in kwargs and kwargs['twod']: v = np.dstack((tri.x[tri.triangles], tri.y[tri.triangles]),) v = np.vstack((tri.x, tri.y, )) kwargs.pop('twod') kwargs['zvalue'] = 1.0 else: v = np.dstack((tri.x[tri.triangles], tri.y[tri.triangles], Z.flatten()[tri.triangles],)) v = np.vstack((tri.x, tri.y, Z.flatten())) idxset=tri.triangles v = v.transpose() print v.shape, idxset.shape viewer = figure() nsec(3) isec(0) threed('on') solid(v, idxset, edgecolor = 'k', facecolor = 'b') lighting(light = 0.5, ambient = 0.5) isec(1) threed('on') solid(v, idxset, cz = True) lighting(light = 0.5, ambient = 0.5) isec(2) threed('on') solid(v, idxset, cz = True, cdata = v[...,0], shade='linear') lighting(light = 0.5, ambient = 0.5)
def onPlotMid(self, e=None): self_obj = self.td if self_obj.getvar0() is None: return proj=self_obj.get_root_parent() from ifigure.interactive import figure v = figure() v.nsec(1,5) path=self_obj.get_full_path() x = self_obj[:]["table"]["rgrid"] y = self_obj[:]["table"]["zgrid"] psi = self_obj[:]["table"]["psirz"] ssimag = self_obj[:]["table"]["ssimag"] ssibdry = self_obj[:]["table"]["ssibdry"] fpol = self_obj[:]["table"]["fpol"] pprime = self_obj[:]["table"]["pprime"] ffprim = self_obj[:]["table"]["ffprim"] pres = self_obj[:]["table"]["pres"] qpsi = self_obj[:]["table"]["qpsi"] zmaxis = self_obj[:]["table"]["zmaxis"] btmid = self_obj[:]["table"]["btmid"] #brmid = self_obj[:]["table"]["brmid"] bzmid = self_obj[:]["table"]["bzmid"] jtmid = self_obj[:]["table"]["jtmid"] pressmid = self_obj[:]["table"]["pressmid"] qmid = self_obj[:]["table"]["qmid"] nr = psi.shape[1] dr = x[1]-x[0] dz = y[1]-y[0] # br = psi[:][j+1] j=psi.shape[0]/2 psi_mid = psi[:][j] psi_mid = array([interp(zmaxis, y, psi[:,i]) for i in range(nr)]) v.update(False) v.isec(0) obj = v.plot(x,bzmid) v.title("$B_{\mathrm{tor, z}}\/\mathrm{(T)}$") obj._name = 'bz' #obj=FigPlot(x,bzmid) #axes.add_child('bz', obj) obj=v.plot(x, btmid) obj._name = 'bt' # obj=FigPlot(x,sqrt(bt_mid*bt_mid+br_mid*br_mid+bz_mid*bz_mid)) # axes.add_child('ball', obj) v.isec(1) v.title("$J_{\mathrm{tor}}\/\mathrm{(MA/m^2)}$") obj = v.plot(x,jtmid) obj._name = 'jtor' v.isec(2) v.title("$P\/\mathrm{(MPa)}$") obj = v.plot(x,pressmid/1e6) obj._name = 'pres' v.isec(3) v.title("$\mathrm{safety\,factor}$") obj = v.plot(x,qmid) obj._name = 'qpsi' v.isec(4) v.title("pitch angle") obj = v.plot(x,-np.arctan2(bzmid, btmid)*180/np.pi) obj._name = 'gamma' v.update(True)
def onPlotMid(self, e=None): self_obj = self.td if self_obj.getvar0() is None: return proj = self_obj.get_root_parent() from ifigure.interactive import figure v = figure() v.nsec(1, 5) path = self_obj.get_full_path() x = self_obj[:]["table"]["rgrid"] y = self_obj[:]["table"]["zgrid"] psi = self_obj[:]["table"]["psirz"] ssimag = self_obj[:]["table"]["ssimag"] ssibdry = self_obj[:]["table"]["ssibdry"] fpol = self_obj[:]["table"]["fpol"] pprime = self_obj[:]["table"]["pprime"] ffprim = self_obj[:]["table"]["ffprim"] pres = self_obj[:]["table"]["pres"] qpsi = self_obj[:]["table"]["qpsi"] zmaxis = self_obj[:]["table"]["zmaxis"] btmid = self_obj[:]["table"]["btmid"] #brmid = self_obj[:]["table"]["brmid"] bzmid = self_obj[:]["table"]["bzmid"] jtmid = self_obj[:]["table"]["jtmid"] pressmid = self_obj[:]["table"]["pressmid"] qmid = self_obj[:]["table"]["qmid"] nr = psi.shape[1] dr = x[1] - x[0] dz = y[1] - y[0] # br = psi[:][j+1] j = psi.shape[0] // 2 psi_mid = psi[:][j] psi_mid = array([interp(zmaxis, y, psi[:, i]) for i in range(nr)]) v.update(False) v.isec(0) obj = v.plot(x, bzmid) v.title("$B_{\mathrm{tor, z}}\/\mathrm{(T)}$") obj._name = 'bz' # obj=FigPlot(x,bzmid) #axes.add_child('bz', obj) obj = v.plot(x, btmid) obj._name = 'bt' # obj=FigPlot(x,sqrt(bt_mid*bt_mid+br_mid*br_mid+bz_mid*bz_mid)) # axes.add_child('ball', obj) v.isec(1) v.title("$J_{\mathrm{tor}}\/\mathrm{(MA/m^2)}$") obj = v.plot(x, jtmid) obj._name = 'jtor' v.isec(2) v.title("$P\/\mathrm{(MPa)}$") obj = v.plot(x, pressmid / 1e6) obj._name = 'pres' v.isec(3) v.title("$\mathrm{safety\,factor}$") obj = v.plot(x, qmid) obj._name = 'qpsi' v.isec(4) v.title("pitch angle") obj = v.plot(x, -np.arctan2(bzmid, btmid) * 180 / np.pi) obj._name = 'gamma' v.update(True)
def onPlotEq(self, e=None, viewer=None): self_obj = self.td if self_obj.getvar0() is None: return path=self_obj.get_full_path() x = self_obj.get_contents("table", "rgrid") y = self_obj.get_contents("table", "zgrid") z = self_obj.get_contents("table", "psirz") try: xlim = self_obj.get_contents("table", "xlim") ylim = self_obj.get_contents("table", "ylim") rb = self_obj.get_contents("table", "rbbbs") zb = self_obj.get_contents("table", "zbbbs") fpol = self_obj.get_contents("table", "fpol") ssimag = self_obj.get_contents("table", "ssimag") ssibdry = self_obj.get_contents("table", "ssibdry") btrz = self_obj.get_contents("table", "btrz") brrz = self_obj.get_contents("table", "brrz") bzrz = self_obj.get_contents("table", "bzrz") jtrz = self_obj.get_contents("table", "jtrz") bnorm = sqrt(btrz**2+brrz**2+bzrz**2) bp = sqrt(brrz**2+bzrz**2) bangle = np.arctan2(bp, bnorm) # isPlasma = self_obj.get_contents("table", "isPlasma") no_lim_b = False except: no_lim_b = True rmaxis = self_obj.get_contents("table", "rmaxis") zmaxis = self_obj.get_contents("table", "zmaxis") if viewer is None: from ifigure.interactive import figure plt = figure() else: plt =viewer plt.cls() plt.update(False) plt.subplot(4, 3,[0,1,2, 3], [4,5, 6, 7]) plt.isec(4) plt.image(x,y,z, alpha=0.5) plt.contour(x,y,z,30) if eval('self_obj[:]["table"]["nlim"]') !=0: plt.plot(xlim, ylim) if eval('self_obj[:]["table"]["nbbbs"]') !=0: plt.plot(rb, zb) plt.xlabel('R') plt.ylabel('Z') plt.title('PSI') if not no_lim_b: plt.isec(5) plt.title('B-norm') plt.image(x,y, bnorm, alpha=0.5) plt.contour(x,y,bnorm,30) if self_obj[:]["table"]["nlim"] > 0: plt.plot(xlim, ylim) if self_obj[:]["table"]["nbbbs"] > 0: plt.plot(rb, zb) plt.xlabel('R') plt.ylabel('Z') plt.isec(0) pres = self_obj.get_contents("table", "pres") plt.plot(pres) plt.title('pressure') plt.xlabel('flux index') plt.isec(1) qpsi = self_obj.get_contents("table", "qpsi") plt.plot(qpsi) plt.title('qpsi') plt.xlabel('flux index') plt.isec(2) fpol = self_obj.get_contents("table", "fpol") plt.plot(fpol) plt.title('f_pol') plt.xlabel('flux index') plt.update(True) if not no_lim_b: return from python_lib.analysis.efit_tools import flux_average, npsi2psi, npsi2npsit npsis = np.linspace(0.02, 0.99, 20) psis = [npsi2psi(self_obj, npsi) for npsi in npsis] sqrt_npsit = [np.sqrt(npsi2npsit(self_obj, npsi)) for npsi in npsis] jtor = [flux_average(x, y, z, rmaxis, zmaxis, jtrz, psi) for psi in psis] plt.isec(3) plt.plot(npsis, jtor) plt.title('f_pol') plt.xlabel('sqrt_toroidal_flux') plt.update(True)
def solid_demo(**kwargs): ''' solid_demo2(cz = True, linewidths = 1.0, edgecolor='red') solid_demo2(facecolor='b', linewidths = 1.0, edgecolor='red') ''' from ifigure.interactive import solid, figure, threed, isec, nsec, lighting import ifigure, os # preparing the data, the same as mplot3d demo theta = np.linspace(0, 2.0 * np.pi, endpoint=True, num=50) r = np.linspace(0.01, 4.0, endpoint=True, num=50) # This is the Mobius mapping, taking a u, v pair and returning an x, y, z # triple THETA, R = np.meshgrid(theta, r) X = R * np.cos(THETA) Y = R * np.sin(THETA) Z = np.exp(-R * R) import matplotlib.tri as mtri tri = mtri.Triangulation(X.flatten(), Y.flatten()) # Triangulate parameter space to determine the triangles if 'cz' in kwargs and kwargs['cz']: v = np.dstack(( tri.x[tri.triangles], tri.y[tri.triangles], Z.flatten()[tri.triangles], )) v = np.vstack((tri.x, tri.y, Z.flatten())) kwargs['cdata'] = 5 * Z.flatten()[tri.triangles] kwargs['cdata'] = 5 * Z.flatten() kwargs['cz'] = True # or # v = np.dstack(( tri.x[tri.triangles], tri.y[tri.triangles], Z.flatten()[tri.triangles], 5 * Z.flatten()[tri.triangles], )) v = np.vstack((tri.x, tri.y, Z.flatten(), 5 * Z.flatten())) elif 'twod' in kwargs and kwargs['twod']: v = np.dstack((tri.x[tri.triangles], tri.y[tri.triangles]), ) v = np.vstack(( tri.x, tri.y, )) kwargs.pop('twod') kwargs['zvalue'] = 1.0 else: v = np.dstack(( tri.x[tri.triangles], tri.y[tri.triangles], Z.flatten()[tri.triangles], )) v = np.vstack((tri.x, tri.y, Z.flatten())) idxset = tri.triangles v = v.transpose() print v.shape, idxset.shape viewer = figure() nsec(3) isec(0) threed('on') solid(v, idxset, edgecolor='k', facecolor='b') lighting(light=0.5, ambient=0.5) isec(1) threed('on') solid(v, idxset, cz=True) lighting(light=0.5, ambient=0.5) isec(2) threed('on') solid(v, idxset, cz=True, cdata=v[..., 0], shade='linear') lighting(light=0.5, ambient=0.5)
self.add_menu(extra_menu, wx.ID_ANY, "Plot Spectra...", "plot spectra of panel #1", self.onPlotSpectra) self.nsec(2) self.cls() self.data = self.AddSignalScript(experiment = exp, signals = {'y': node}, kind = 'plot') def onPlotSpectra(self, evt): try: p = self.data.get_child(0) x = p.getvar('x') y = p.getvar('y') self.isec(1) self.spec(x, y) except: import traceback traceback.print_exc() evt.Skip() if not obj.get_parent().has_child('mdsscope_extramenu_book'): v = figure() v.book.rename('mdsscope_extramenu_book') v.book.set_keep_data_in_tree(True) v.book.Close() obj.get_parent().mdsscope_extramenu_book.Open(MDSScopeExtraMenuGUI)