shading='flat', cmap=plt.cm.viridis) ax.set_title(r'$\Delta$ Conductivities') fig.colorbar(im) ax.axis('equal') fig.set_size_inches(6, 4) # fig.savefig('demo_bp_0.png', dpi=96) plt.show() """ 2. FEM forward simulations """ # setup EIT scan conditions # adjacent stimulation (el_dist=1), adjacent measures (step=1) el_dist, step = 1, 1 ex_mat = eit_scan_lines(16, el_dist) # calculate simulated data fwd = Forward(mesh_obj, el_pos) 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. naive inverse solver using back-projection """ eit = bp.BP(mesh_obj, el_pos, ex_mat=ex_mat, step=1, parser='std') eit.setup(weight='none') ds = 192.0 * eit.solve(f1.v, f0.v) # plot fig = plt.figure() ax1 = fig.add_subplot(111) im = ax1.tripcolor(pts[:, 0], pts[:, 1], tri, ds, cmap=plt.cm.viridis) ax1.set_title(r'$\Delta$ Conductivities') ax1.axis('equal')
bbox = [[-1, -1, -1], [1, 1, 1]] # save calling convention as distmesh 2D 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)
# save calling convention as distmesh 2D mesh_obj, el_pos = mesh.create(h0=0.15, bbox=bbox) 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)
# show fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor(pts[:, 0], pts[:, 1], tri, np.real(perm), shading="flat", cmap=plt.cm.viridis) fig.colorbar(im) ax.axis("equal") ax.set_title(r"$\Delta$ Conductivities") plt.show() """ 2. calculate simulated data """ el_dist, step = 1, 1 ex_mat = eit_scan_lines(n_el, el_dist) fwd = Forward(mesh_obj, el_pos) f1 = fwd.solve_eit(ex_mat, step, perm=mesh_new["perm"], parser="std") """ 3. solve_eit using gaussian-newton (with regularization) """ # number of stimulation lines/patterns eit = jac.JAC(mesh_obj, el_pos, ex_mat, step, perm=1.0, parser="std") eit.setup(p=0.25, lamb=1.0, method="lm") # lamb = lamb * lamb_decay ds = eit.gn(f1.v, lamb_decay=0.1, lamb_min=1e-5, maxiter=20, verbose=True) # plot fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor( pts[:, 0], pts[:, 1], tri, np.real(ds),
tri = mesh_obj['element'] perm = mesh_new['perm'] # show fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor(pts[:, 0], pts[:, 1], tri, np.real(perm), shading='flat', cmap=plt.cm.viridis) fig.colorbar(im) ax.axis('equal') ax.set_title(r'$\Delta$ Conductivities') plt.show() """ 2. calculate simulated data """ el_dist, step = 1, 1 ex_mat = eit_scan_lines(n_el, el_dist) fwd = Forward(mesh_obj, el_pos) f1 = fwd.solve_eit(ex_mat, step, perm=mesh_new['perm'], parser='std') """ 3. solve_eit using gaussian-newton (with regularization) """ # number of stimulation lines/patterns eit = jac.JAC(mesh_obj, el_pos, ex_mat, step, perm=1.0, parser='std') eit.setup(p=0.25, lamb=1.0, method='lm') # lamb = lamb * lamb_decay ds = eit.gn(f1.v, lamb_decay=0.1, lamb_min=1e-5, maxiter=20, verbose=True) # plot fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor(pts[:, 0], pts[:, 1], tri, np.real(ds), shading='flat', alpha=1.0, cmap=plt.cm.viridis) fig.colorbar(im) ax.axis('equal')
fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor(no2xy[:, 0], no2xy[:, 1], el2no, np.real(alpha), shading='flat') fig.colorbar(im) ax.axis('tight') ax.set_title(r'$\Delta$ Permitivity') """ 2. calculate simulated data using stack ex_mat """ el_dist, step = 7, 1 n_el = len(el_pos) ex_mat1 = eit_scan_lines(n_el, el_dist) ex_mat2 = eit_scan_lines(n_el, 1) ex_mat = np.vstack([ex_mat1, ex_mat2]) # forward solver fwd = Forward(ms, el_pos) f0 = fwd.solve(ex_mat, step, perm=ms['alpha']) f1 = fwd.solve(ex_mat, step, perm=ms1['alpha']) """ 3. solving using dynamic EIT """ # number of stimulation lines/patterns eit = jac.JAC(ms, el_pos, ex_mat=ex_mat, step=step, parser='std') eit.setup(p=0.40, lamb=1e-3, method='kotre') ds = eit.solve(f1.v, f0.v) """ 4. plot """ fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor(no2xy[:, 0], no2xy[:, 1], el2no, np.real(ds), shading='flat', alpha=0.90, cmap=plt.cm.viridis) fig.colorbar(im) ax.axis('tight')
'alpha': 0.1 }, { 'x': 0, 'y': -0.5, 'd': 0.1, 'alpha': 0.1 }] ms1 = mesh.set_alpha(ms, anomaly=anomaly, background=1.0) alpha = np.real(ms1['alpha'] - ms0['alpha']) """ ax1. FEM forward simulations """ # setup EIT scan conditions el_dist, step = 1, 1 ex_mat = eit_scan_lines(16, el_dist) # calculate simulated data fwd = Forward(ms, el_pos) f0 = fwd.solve(ex_mat, step=step, perm=ms0['alpha']) f1 = fwd.solve(ex_mat, step=step, perm=ms1['alpha']) """ ax2. BP """ eit = bp.BP(ms, el_pos, ex_mat=ex_mat, step=1, parser='std') ds = eit.solve(f1.v, f0.v, normalize=True) ds_bp = ds """ ax3. JAC """ eit = jac.JAC(ms, el_pos, ex_mat=ex_mat, step=step, perm=1., parser='std') eit.setup(p=0.2, lamb=0.001, method='kotre') # parameter tuning is needed for better display ds = eit.solve(f1.v, f0.v) ds_jac = pdeprtni(no2xy, el2no, ds) """ ax4. GREIT """ eit = greit.GREIT(ms, el_pos, ex_mat=ex_mat, step=step, parser='std') ds = eit.solve(f1.v, f0.v)
# show fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor(no2xy[:, 0], no2xy[:, 1], el2no, np.real(alpha), shading='flat', cmap=plt.cm.viridis) fig.colorbar(im) ax.axis('equal') ax.set_title(r'$\Delta$ Conductivities') plt.show() """ 2. calculate simulated data """ el_dist, step = 1, 1 ex_mat = eit_scan_lines(n_el, el_dist) fwd = Forward(ms, el_pos) f1 = fwd.solve(ex_mat, step, perm=ms1['alpha'], parser='std') """ 3. solve using gaussian-newton """ # number of stimulation lines/patterns eit = jac.JAC(ms, el_pos, ex_mat, step, perm=1.0, parser='std') eit.setup(p=0.25, lamb=1.0, method='lm') ds = eit.gn(f1.v, lamb_decay=0.1, lamb_min=1e-4, maxiter=20, verbose=True) # plot fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor(no2xy[:, 0], no2xy[:, 1], el2no, np.real(ds), shading='flat', alpha=1.0,
v0 = v0[:, np.newaxis] jac = p.jac / v0 # calculate sensitivity matrix s = np.linalg.norm(jac, axis=0) ae = tri_area(pts, tri) s = np.sqrt(s) / ae assert (any(s >= 0)) se = np.log10(s) sn = sim2pts(pts, tri, se) return sn """ 1. FEM forward setup """ # calculate simulated data using FEM fwd = Forward(mesh_obj, el_pos) # loop over EIT scan settings: vary the distance of stimulation nodes, AB ex_list = [1, 2, 4, 8] N = len(ex_list) s = [] for ex_dist in ex_list: ex_mat = eit_scan_lines(16, ex_dist) # TODO: ex_mat can also be stacked, see demo_dynamic_stack.py s0 = calc_sens(fwd, ex_mat) s.append(s0) """ 2. Plot (elements) sensitivity """ vmin = np.min(s) vmax = np.max(s) fig = plt.figure(figsize=(12, 2.5)) gs = gridspec.GridSpec(1, N) for ix in range(N):