eitcom / pyEIT

Python based toolkit for Electrical Impedance Tomography
Other
169 stars 96 forks source link

Issues importing the library #55

Closed akarshp28 closed 2 years ago

akarshp28 commented 2 years ago

hi @liubenyuan

Hope you are doing well. Just today, I installed pyEIT using pip and I am getting TypeError's while importing stuff. I am just trying to run the fem_forward2d.py. I have attached a screenshot below for reference.

Thanks for the great work.

image

liubenyuan commented 2 years ago

Could you try modify the 145 and 147 line of protocol.py as

from typing import Union, List
...
dist_exc: Union[int, List[int]] = 1,
step_meas: int = 1,
parser_meas: Union[str, List[str]] = "std",

If this works, you can commit a PR!

Or, may be you should update to python >= 3.9? see: https://stackoverflow.com/questions/71041586/typeerror-type-object-is-not-subscriptable

akarshp28 commented 2 years ago

Thanks for the quick reply.

Just to test, I downloaded the entire github repo as zip and everything works perfectly without any issues right out of the box. I uninstalled the pip installation before I did this just to be sure.

I then deleted the zip folder and reinstalled the pip version and I get this issue back. So I think the issue is with pip installation?

liubenyuan commented 2 years ago

I install from pip and run examples from the github folder, and it did not report any error...

akarshp28 commented 2 years ago

Okay thanks for confirming, atleast I am glad that the issue is from my end. I will look into it. Thanks again.

akarshp28 commented 2 years ago

And sorry since this question is not related to the current issue. I just wanted to learn more about the function found here. Is this function accurate to compute the element wise gradients of the electric potential and conductivity? I see that the function is deprecated, so is there a more accurate method or recommended way to compute this data?

I did the following: cx, cy = pdegrad(mesh_pts, tri_pts, cond_data) ux, uy = pdegrad(mesh_pts, tri_pts, u_exp_1_data) I plotted this data as a quiver plot and it looked like this. I didn't know who to ask and verify its correctness hence I am posting here. Do these plots look correct?

Sigma gradients: image

Potential gradients: image

Thank you.

liubenyuan commented 2 years ago

Could you provide a minimal example on this? I used this function pdegrad as a learning process, and you may found a MATLAB equivalent pdegrad with much more detailed documentation.

akarshp28 commented 2 years ago

hi @liubenyuan

thanks for the response. Here is a simple example i setup with the fem_forward2d.py.


import matplotlib.pyplot as plt
import numpy as np
import pyeit.eit.protocol as protocol
import pyeit.mesh as mesh
from pyeit.eit.fem import Forward
from pyeit.mesh.wrapper import PyEITAnomaly_Circle
from pyeit.eit.interp2d import sim2pts, pdegrad

n_el = 16  # nb of electrodes
mesh_obj = mesh.create(n_el, h0=0.05)
el_pos = mesh_obj.el_pos

pts = mesh_obj.node
tri = mesh_obj.element
mesh_obj.print_stats()

anomaly = PyEITAnomaly_Circle(center=[0.4, 0.5], r=0.2, perm=100.0)
mesh_new = mesh.set_perm(mesh_obj, anomaly=anomaly, background=1.0)
perm = mesh_new.perm

protocol_obj = protocol.create(n_el, dist_exc=7, step_meas=1, parser_meas="std")
ex_line = protocol_obj.ex_mat[0].ravel()

fwd = Forward(mesh_new)
f = fwd.solve(ex_line)
f = np.real(f)

s = sim2pts(pts, tri, perm)
sx, sy = pdegrad(pts, tri, s)
sx = np.expand_dims(sim2pts(pts, tri, sx), axis=1)
sy = np.expand_dims(sim2pts(pts, tri, sy), axis=1)

plt.figure(figsize=(15,5))
plt.subplot(131)
plt.quiver(pts[:, 0], pts[:, 1], np.squeeze(sx), np.squeeze(sy))
plt.subplot(132)
plt.tripcolor(pts[:, 0], pts[:, 1], np.squeeze(sx))
plt.subplot(133)
plt.tripcolor(pts[:, 0], pts[:, 1], np.squeeze(sy))
plt.show()

ux, uy = pdegrad(pts, tri, np.expand_dims(f,1))
ux = np.expand_dims(sim2pts(pts, tri, ux), axis=1)
uy = np.expand_dims(sim2pts(pts, tri, uy), axis=1)

plt.figure(figsize=(15,5))
plt.subplot(131)
plt.quiver(pts[:, 0], pts[:, 1], np.squeeze(ux), np.squeeze(uy))
plt.subplot(132)
plt.tripcolor(pts[:, 0], pts[:, 1], np.squeeze(ux))
plt.subplot(133)
plt.tripcolor(pts[:, 0], pts[:, 1], np.squeeze(uy))
plt.show()
liubenyuan commented 2 years ago

The potential gradients looks like this: I think this might be right?

Figure_2

akarshp28 commented 2 years ago

I also agree that they look correct. Thank you for all the help and providing the great library.