Skip to content

Commit

Permalink
Separate solve, solve_eit, compute_b, and compute_jac (#43)
Browse files Browse the repository at this point in the history
- Docstrings style back to numpy-style, NDArray>> np.ndarray
- Move the computation of H in setup()
- transform EitBase to an absclass with absmethod "setup" and "_compute_h"
- add "_check_solver_is_ready()" which raise SolverNotReadyError if setup() not called before solving  for example.
- modify msg of  _check_solver_is_ready and fix missing call in jac.gn
- bp, jac, greit and svd modified to fit ne EitBase
- "map" method only in eitBase (same impletation in fac, bp, greit)
- add/enhance doctring (numpy-format) in all 4 files and add typehints
- spliting computation of potential dist, jac, b (see new methods compute_*)
- using those directly in EitSolvers
- solve and solve_eit (assuring bck compatibility) with new implementation
- the method still return Fwd results (to minimize back compatility ) but contain only the voltages, can be extended with futher computed data e.g. diff_op or others info
- fix gn solver jac and v0 were not actualizated, now passing x0
- put old test in unit test frame! now bay calling the script all test are run and a protocols is printed in term
- to set the ref electrode a new set method has been added to Forward
- solve >> handle ex_line  (return f[0, :].ravel())
- jac=np.vstack(jac) also in compute_jac returns jac and not jac_i like the older solve
- b=np.vstack(b_matrix)
- Suppression of K^-1 for nodes potential
- the inversion is still used but only for building the jac
- correction of the output of f (ex_mat has not been cheke in the scope of of solve)
- add intern _get_boundary _volt method to avoid multple code reapting and add  note for v0 after calculation of jac!
  • Loading branch information
davmetz authored May 6, 2022
1 parent eebca7f commit 8c4e228
Show file tree
Hide file tree
Showing 21 changed files with 1,454 additions and 569 deletions.
8 changes: 4 additions & 4 deletions examples/eit_sensitivity2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
quality.stats(pts, tri)


def calc_sens(fwd, ex_mat):
def calc_sens(fwd:Forward, 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
jac = fwd.compute_jac(ex_mat=ex_mat, parser="fmmu")
v0 = fwd.v0
# normalized jacobian (note: normalize affect sensitivity)
v0 = v0[:, np.newaxis]
jac = p.jac # / v0 # (normalize or not)
jac = jac # / v0 # (normalize or not)
# calculate sensitivity matrix
s = np.linalg.norm(jac, axis=0)
ae = tri_area(pts, tri)
Expand Down
2 changes: 1 addition & 1 deletion examples/fem_forward2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

# calculate simulated data using FEM
fwd = Forward(mesh_obj, el_pos)
f, _ = fwd.solve(ex_line, perm=perm)
f = fwd.solve(ex_line, perm=perm)
f = np.real(f)

""" 2. plot """
Expand Down
2 changes: 1 addition & 1 deletion examples/fem_forward3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
node_perm = sim2pts(pts, tri, np.real(tri_perm))

# solving once using fem
f, _ = fwd.solve(ex_line, perm=tri_perm)
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)
Expand Down
2 changes: 1 addition & 1 deletion examples/mesh_multi_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
ex_line = ex_mat[0].ravel()

# solving once using fem
f, _ = fwd.solve(ex_line, perm=tri_perm)
f = fwd.solve(ex_line, perm=tri_perm)
f = np.real(f)
vf = np.linspace(min(f), max(f), 32)

Expand Down
2 changes: 1 addition & 1 deletion examples/softx/figure02.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

# calculate simulated data using FEM
fwd = Forward(mesh_obj, el_pos)
f, _ = fwd.solve(ex_line, perm=perm)
f = fwd.solve(ex_line, perm=perm)
f = np.real(f)

""" 2. plot """
Expand Down
9 changes: 5 additions & 4 deletions examples/softx/figure02b.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@
quality.stats(pts, tri)


def calc_sens(fwd, ex_mat):
def calc_sens(fwd:Forward, 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
# p = fwd.solve_eit(ex_mat=ex_mat, parser="fmmu")
jac= fwd.compute_jac(ex_mat=ex_mat, parser="fmmu")
v0 = fwd.v0
# normalized jacobian (note: normalize affect sensitivity)
v0 = v0[:, np.newaxis]
jac = p.jac # / v0
jac = jac # / v0
# calculate sensitivity matrix
s = np.linalg.norm(jac, axis=0)
ae = tri_area(pts, tri)
Expand Down
5 changes: 5 additions & 0 deletions pyeit/eit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@
- utils: EIT related helper function
- interp2d: Spatial interpolation for EIT
"""
from .bp import BP

__all__ = [
"BP",
]
Loading

0 comments on commit 8c4e228

Please sign in to comment.