def plot(self,input=None,**kwargs): import matplotlib.pylab as plt if input is None: input=self.true_perm if 'ax' in kwargs: ax=kwargs.pop('ax') if self.gdim==2: if len(input)==self.dim: input=self._pts2sim(input) im=ax.tripcolor(self.pts[:,0],self.pts[:,1],self.tri,np.real(input),shading='flat') elif self.gdim==3: if len(input)==self.fwd.n_tri: input=self._sim2pts(input) plt.axes(ax) im=mplot.tetplot(self.pts,self.tri,vertex_color=np.real(input),alpha=1.0) return im else: if self.gdim==2: if len(input)==self.dim: input=self._pts2sim(input) plt.tripcolor(self.pts[:,0],self.pts[:,1],self.tri,np.real(input),shading='flat') elif self.gdim==3: if len(input)==self.fwd.n_tri: input=self._sim2pts(input) mplot.tetplot(self.pts,self.tri,vertex_color=np.real(input),alpha=1.0) plt.show()
ms, el_pos = mesh.create(h0=0.15, bbox=bbox) no2xy = ms['node'] el2no = ms['element'] # report the status of the 2D mesh quality.stats(no2xy, el2no) """ 1. FEM forward simulations """ # setup EIT scan conditions el_dist, step = 7, 1 ex_mat = eit_scan_lines(16, el_dist) # calculate simulated data fwd = Forward(ms, el_pos) # in python, index start from 0 ex_line = ex_mat[1].ravel() # change alpha anomaly = [{'x': 0.40, 'y': 0.40, 'z': 0.0, 'd': 0.30, 'alpha': 100.0}] ms_test = mesh.set_alpha(ms, anomaly=anomaly, background=1.0) tri_perm = ms_test['alpha'] node_perm = pdeprtni(no2xy, el2no, np.real(tri_perm)) # solving once using fem f, _ = fwd.solve_once(ex_line, tri_perm) f = np.real(f) # mplot.tetplot(p, t, edge_color=(0.2, 0.2, 1.0, 1.0), alpha=0.01) mplot.tetplot(no2xy, el2no, vertex_color=f, alpha=1.0)
pts = mesh_obj['node'] tri = mesh_obj['element'] # report the status of the 2D mesh quality.stats(pts, tri) """ 1. FEM forward simulations """ # setup EIT scan conditions el_dist, step = 7, 1 ex_mat = eit_scan_lines(16, el_dist) # calculate simulated data fwd = Forward(mesh_obj, el_pos) # in python, index start from 0 ex_line = ex_mat[1].ravel() # change alpha anomaly = [{'x': 0.40, 'y': 0.40, 'z': 0.0, 'd': 0.30, 'perm': 100.0}] mesh_new = mesh.set_perm(mesh_obj, anomaly=anomaly, background=1.0) tri_perm = mesh_new['perm'] node_perm = sim2pts(pts, tri, np.real(tri_perm)) # solving once using fem f, _ = fwd.solve(ex_line, perm=tri_perm) f = np.real(f) # mplot.tetplot(p, t, edge_color=(0.2, 0.2, 1.0, 1.0), alpha=0.01) mplot.tetplot(pts, tri, vertex_color=f, alpha=1.0)
ex_mat = eit_scan_lines(16, el_dist) # calculate simulated data fwd = Forward(ms, el_pos) # in python, index start from 0 ex_line = ex_mat[2].ravel() # change alpha anomaly = [{'x': 0.40, 'y': 0.40, 'z': 0.0, 'd': 0.30, 'alpha': 100.0}] ms_test = mesh.set_alpha(ms, anomaly=anomaly, background=1.0) tri_perm = ms_test['alpha'] node_perm = pdeprtni(no2xy, el2no, np.real(tri_perm)) # solving once using fem # f, _ = fwd.solve_once(ex_line, tri_perm) # f = np.real(f) # calculate simulated data f0 = fwd.solve(ex_mat, step=step, perm=ms['alpha']) f1 = fwd.solve(ex_mat, step=step, perm=ms_test['alpha']) """ 3. JAC solver """ # number of stimulation lines/patterns eit = jac.JAC(ms, el_pos, ex_mat=ex_mat, step=step, perm=1., parser='std') eit.setup(p=0.50, lamb=1e-4, method='kotre') ds = eit.solve(f1.v, f0.v) node_ds = pdeprtni(no2xy, el2no, np.real(ds)) # mplot.tetplot(p, t, edge_color=(0.2, 0.2, 1.0, 1.0), alpha=0.01) mplot.tetplot(no2xy, el2no, vertex_color=node_ds, alpha=1.0)
# coding: utf-8 # pylint: disable=invalid-name """ demo for distmesh 3D """ # Copyright (c) Benyuan Liu. All Rights Reserved. # Distributed under the (new) BSD License. See LICENSE.txt for more info. from __future__ import division, absolute_import, print_function import numpy as np import pyeit.mesh as mesh import pyeit.mesh.plot as mplot # tetrahedron meshing in a 3D bbox bbox = [[-1.2, -1.2, -1.2], [1.2, 1.2, 1.2]] ms, el_pos = mesh.create(h0=0.15, bbox=bbox) # print mesh quality p = ms['node'] t = ms['element'] print('points =', p.shape) print('simplices =', t.shape) # plot mplot.tetplot(p, t, edge_color=(0.2, 0.2, 1.0, 1.0), alpha=0.01) # create random color f = np.random.randn(p.shape[0]) # mplot.tetplot(p, t, f, alpha=0.25)
# in python, index start from 0 ex_line = ex_mat[2].ravel() # change alpha anomaly = [{'x': 0.40, 'y': 0.40, 'z': 0.0, 'd': 0.30, 'perm': 100.0}] mesh_new = mesh.set_perm(mesh_obj, anomaly=anomaly, background=1.0) tri_perm = mesh_new['perm'] node_perm = sim2pts(pts, tri, np.real(tri_perm)) # solving once using fem # f, _ = fwd.solve(ex_line, tri_perm) # f = np.real(f) # calculate simulated data f0 = fwd.solve_eit(ex_mat, step=step, perm=mesh_obj['perm']) f1 = fwd.solve_eit(ex_mat, step=step, perm=mesh_new['perm']) """ 3. JAC solver """ # number of stimulation lines/patterns eit = jac.JAC(mesh_obj, el_pos, ex_mat=ex_mat, step=step, perm=1., parser='std') eit.setup(p=0.50, lamb=1e-3, method='kotre') ds = eit.solve(f1.v, f0.v, normalize=False) node_ds = sim2pts(pts, tri, np.real(ds)) # mplot.tetplot(p, t, edge_color=(0.2, 0.2, 1.0, 1.0), alpha=0.01) mplot.tetplot(pts, tri, vertex_color=node_ds, alpha=1.0)
# coding: utf-8 # pylint: disable=invalid-name # author: benyuan liu """ demo for distmesh """ from __future__ import division, absolute_import, print_function import numpy as np import pyeit.mesh as mesh import pyeit.mesh.plot as mplot # build tetrahedron # 3D tetrahedron must have a bbox bbox = [[-1, -1, -1], [1, 1, 1]] # save calling convention as distmesh 2D ms, elPos = mesh.create(h0=0.2, bbox=bbox) p = ms['node'] t = ms['element'] # print mesh quality print('points =', p.shape) print('simplices =', t.shape) # create random color f = np.random.randn(p.shape[0]) # mplot.tetplot(p, t, edge_color=(0.2, 0.2, 1.0, 1.0), alpha=0.01) mplot.tetplot(p, t, f, alpha=0.25)
# test # pylint: disable=no-member """ demo for distmesh """ from __future__ import absolute_import import numpy as np import pyeit.mesh as mesh import pyeit.mesh.plot as mplot # build tetrahedron # 3D tetrahedron must have a bbox bbox = [[-1, -1, -1], [1, 1, 1]] # save calling convention as distmesh 2D ms, elPos = mesh.create(h0=0.2, bbox=bbox) p = ms['node'] t = ms['element'] # print mesh quality print('points =', p.shape) print('simplices =', t.shape) # create random color f = np.random.randn(p.shape[0]) # mplot.tetplot(p, t, edge_color=(0.2, 0.2, 1.0, 1.0), alpha=0.01) mplot.tetplot(p, t, f, alpha=0.25)
no2xy = ms['node'] el2no = ms['element'] # report the status of the 2D mesh quality.fstats(no2xy, el2no) """ 1. FEM forward simulations """ # setup EIT scan conditions elDist, step = 7, 1 exMtx = eit_scan_lines(16, elDist) # calculate simulated data fwd = forward(ms, elPos) # in python, index start from 0 exLine = exMtx[1].ravel() # change alpha anomaly = [{'x': 0.40, 'y': 0.40, 'z': 0.0, 'd': 0.30, 'alpha': 100.0}] ms_test = mesh.set_alpha(ms, anom=anomaly, background=1.0) tri_perm = ms_test['alpha'] node_perm = pdeprtni(no2xy, el2no, np.real(tri_perm)) # solving once using fem f, _ = fwd.solve_once(exLine, tri_perm) f = np.real(f) # mplot.tetplot(p, t, edge_color=(0.2, 0.2, 1.0, 1.0), alpha=0.01) mplot.tetplot(no2xy, el2no, vertex_color=f, alpha=1.0)
# calculate simulated data fwd = forward(ms, elPos) # in python, index start from 0 exLine = exMtx[2].ravel() # change alpha anomaly = [{'x': 0.40, 'y': 0.40, 'z': 0.0, 'd': 0.30, 'alpha': 100.0}] ms_test = mesh.set_alpha(ms, anom=anomaly, background=1.0) tri_perm = ms_test['alpha'] node_perm = pdeprtni(no2xy, el2no, np.real(tri_perm)) # solving once using fem # f, _ = fwd.solve_once(exLine, tri_perm) # f = np.real(f) # calculate simulated data f0 = fwd.solve(exMtx, step=step, perm=ms['alpha']) f1 = fwd.solve(exMtx, step=step, perm=ms_test['alpha']) """ 3. JAC solver """ # number of excitation lines & excitation patterns eit = jac.JAC(ms, elPos, exMtx=exMtx, step=step, perm=1., parser='std', p=0.50, lamb=1e-4, method='kotre') ds = eit.solve(f1.v, f0.v) node_ds = pdeprtni(no2xy, el2no, np.real(ds)) # mplot.tetplot(p, t, edge_color=(0.2, 0.2, 1.0, 1.0), alpha=0.01) mplot.tetplot(no2xy, el2no, vertex_color=node_ds, alpha=1.0)