def calc_sens(fwd, ex_mat): """ see Adler2017 on IEEE TBME, pp 5, figure 6, Electrical Impedance Tomography: Tissue Properties to Image Measures """ # solving EIT problem p = fwd.solve_eit(ex_mat=ex_mat, parser='fmmu') v0 = p.v # normalized jacobian (note: normalize affect sensitivity) 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
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)
# Note: if the jac and the real-problem are generated using the same mesh, # then, data normalization in solve are not needed. # However, when you generate jac from a known mesh, but in real-problem # (mostly) the shape and the electrode positions are not exactly the same # as in mesh generating the jac, then data must be normalized. eit = jac.JAC( mesh_obj, el_pos, ex_mat=ex_mat, step=step, perm=1.0, parser="fmmu", ) eit.setup(p=0.5, lamb=0.01, method="kotre") ds = eit.solve(f1.v, f0.v, normalize=True) ds_n = sim2pts(pts, tri, np.real(ds)) # plot ground truth fig, ax = plt.subplots(figsize=(6, 4)) delta_perm = mesh_new["perm"] - mesh_obj["perm"] im = ax.tripcolor(x, y, tri, np.real(delta_perm), shading="flat") fig.colorbar(im) ax.set_aspect("equal") # plot EIT reconstruction fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor(x, y, tri, ds_n, shading="flat") for i, e in enumerate(el_pos): ax.annotate(str(i + 1), xy=(x[e], y[e]), color="r") fig.colorbar(im) ax.set_aspect("equal")
"y": 0.5, "d": 0.2, "perm": 20 }, { "x": -0.2, "y": -0.2, "d": 0.4, "perm": 10 }, ] ms1 = wrapper.set_perm(mesh_obj, anomaly=anomaly, background=1.0) # show delta permittivity on nodes (reverse interp) ele_ds = ms1["perm"] - ms0["perm"] node_ds = sim2pts(pts, tri, ele_ds) # plot fig, ax = plt.subplots(figsize=(6, 4)) # tripcolor shows values on nodes (shading='flat' or 'gouraud') im = ax.tripcolor( pts[:, 0], pts[:, 1], tri, np.real(node_ds), edgecolor="k", shading="flat", alpha=0.8, cmap=plt.cm.RdBu, ) # 'tricontour' interpolates values on nodes, for example
""" 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[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.,
f0 = fwd.solve_eit(ex_mat, step=step, perm=mesh_obj['perm']) f1 = fwd.solve_eit(ex_mat, step=step, perm=mesh_new['perm']) """ ax2. BP """ eit = bp.BP(mesh_obj, 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(mesh_obj, el_pos, ex_mat=ex_mat, step=step, perm=1., parser='std') # parameter tuning is needed for better EIT images eit.setup(p=0.5, lamb=0.1, method='kotre') # if the jacobian is not normalized, data may not to be normalized too. ds = eit.solve(f1.v, f0.v, normalize=False) ds_jac = sim2pts(pts, tri, ds) """ ax4. GREIT """ eit = greit.GREIT(mesh_obj, el_pos, ex_mat=ex_mat, step=step, parser='std') # parameter tuning is needed for better EIT images eit.setup(p=0.5, lamb=0.01) ds = eit.solve(f1.v, f0.v, normalize=False) x, y, ds_greit = eit.mask_value(ds, mask_value=np.NAN) """ build for EIT2016b (orig: 300p x 300p, 150dpi) """ size = (8, 6) axis_size = [-1.2, 1.2, -1.2, 1.2] im_size = [-2, 34, -2, 34] fig = plt.figure(figsize=size) gs = gridspec.GridSpec(2, 2)