0% found this document useful (0 votes)
763 views5 pages

Alberto Boschetti, Luca Massaron - Python Data Science Essentials - Learn The Fundamentals of Data Science With Python-Packt Publishing (2015)

EIT con python

Uploaded by

mjcarri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
763 views5 pages

Alberto Boschetti, Luca Massaron - Python Data Science Essentials - Learn The Fundamentals of Data Science With Python-Packt Publishing (2015)

EIT con python

Uploaded by

mjcarri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

SoftwareX 7 (2018) 304–308

Contents lists available at ScienceDirect

SoftwareX
journal homepage: www.elsevier.com/locate/softx

Original software publication

pyEIT: A python based framework for Electrical Impedance


Tomography
Benyuan Liu, Bin Yang, Canhua Xu, Junying Xia, Meng Dai, Zhenyu Ji, Fusheng You,

Xiuzhen Dong, Xuetao Shi, Feng Fu
Department of Biomedical Engineering, Fourth Military Medical University, Xi’an, 710032, PR China

article info a b s t r a c t

Article history: We present a Python-based, open source Electrical Impedance Tomography (EIT) library called pyEIT. It is a
Received 25 July 2018 multiplatform software released under the Apache License v2.0. pyEIT has a clean architecture and is well
Received in revised form 19 September 2018 documented. It implements state-of-the-art EIT imaging algorithms and is also capable of simple 2D/3D
Accepted 19 September 2018
meshing. pyEIT is written in Python. It accelerates the analysis of offline EIT data and can be incorporated
Keywords: into clinical EIT applications. In this paper, we focus on illustrating the fundamental design principles of
Electrical Impedance Tomography pyEIT by using some intuitive examples about EIT forward computing and inverse solving.
Inverse problems © 2018 The Authors. Published by Elsevier B.V. This is an open access article under the CC BY license
Finite element method (http://creativecommons.org/licenses/by/4.0/).
Unstructrual mesh

Code metadata
Current code version 1.0.0
Permanent link to code/repository used for this code version https://github.com/ElsevierSoftwareX/SOFTX_2018_114
Legal Code License https://github.com/liubenyuan/pyEIT/blob/master/LICENSE.txt
Code versioning system used git
Software code languages, tools, and services used Python and the following Python packages: numpy, scipy, matplotlib, pandas
Compilation requirements, operating environments & dependencies Linux, Windows, Mac OS
If available Link to developer documentation/manual https://github.com/liubenyuan/pyEIT/tree/master/examples
Support email for questions [email protected]

1. Motivation and significance of cerebrospinal fluid [9] create a shielding effect where only a
small amount of current applies on the cerebral. But brain EIT is
Electrical impedance tomography (EIT) is a low-cost, also life-saving. For example, the early identification of cerebral
non-invasive, radiation-free imaging method [1,2]. It is sensitive injuries [10] is of great value to clinical surgeons. To advance
to the changes of internal electrical properties, which has potential the development of brain EIT, we need to conduct large-scale 3D
in bedside monitoring during hospital care. Nowadays, lung EIT [3] finite element (FE) simulations, implement various sophisticated
and brain EIT [4] are two major clinical research directions. In lung EIT imaging algorithms and process a large amount of in-vivo data
EIT, the ventilation and perfusion distribution in the thorax are in a closed loop.
imaged and evaluated in real-time [3]. In brain EIT, the pathological In this paper, we propose a Python-based EIT simulation and
intracranial changes, such as haemorrhage [5], ischemia [6] or imaging framework called pyEIT. pyEIT ties the backend such as
infarction [7], can be continuously monitored and imaged using Finite Element Method (FEM) simulation, EIT inverse solving and
EIT. Most of the latest brain EIT researches are limited to phantom imaging to the frontend applications. It may accelerate the evolu-
models or animal studies. in-vivo brain EIT is hard. The size of tion of in-vivo EIT studies.
the skull is large, and the internal structure is complex. Moreover, Recently, we have used EIT in-vivo in cerebral imaging and
the high resistivity of the skull [8] and the high conductivity monitoring during total aortic arch replacement [10]. The imaging
speed of EIT is one frame per second. The data in [10] contain
∗ Corresponding author. 42 subjects where the overall length is approximately 160 h. We
E-mail address: [email protected] (F. Fu). constructed a pipeline processing where data filtering, meshing,

https://doi.org/10.1016/j.softx.2018.09.005
2352-7110/© 2018 The Authors. Published by Elsevier B.V. This is an open access article under the CC BY license (http://creativecommons.org/licenses/by/4.0/).
B. Liu et al. / SoftwareX 7 (2018) 304–308 305

Fig. 1. The software architecture of pyEIT. pyEIT consists of 3 parts: meshing, solving forward and inverse problem. Blue texts denote corresponding Python modules.

2.2. Software functionalities

The fem module solves the forward problem of EIT. The mathe-
matic model of EIT is formulated as a boundary value problem,
∇ · (σ ∇ u) = 0, in Ω
∂ u ⏐⏐

σ =g
∂ n ⏐∂ Ω

u=0
∂Ω

Fig. 2. A 16-electrode configuration EIT system for cerebral imaging.


where Ω is the 2D or 3D domain to be imaged, and ∂ Ω is the
boundary. In EIT, we inject a safe current at a fixed frequency
through a pair of electrodes attached to the boundary and measure
the voltage differences on remaining electrode pairs. Fig. 2 shows
EIT imaging, image postprocessing, feature extraction and clas-
a typical 16-electrode configuration. A frame of data, denoted by
sification are built upon pyEIT and other open source machine v ∈ RM , is formed by rotating and repeating this process iteratively
learning packages. over all 16 electrodes.
The EIDORS toolkit [11] has been proposed for nearly 20 years EIT imaging is an inverse problem, which reconstructs the con-
and it is widely used for developing and evaluating EIT algorithms. ductivities or the changes in conductivities inside the subject from
pyEIT is less developed compared to EIDORS. Some features such boundary voltages,
as Complete Electrode Model (CEM) and Total Variation (TV) reg-
ularization are missing in pyEIT. But, pyEIT is written in Python σ = min ∥v − f (Ω , σ )∥22 + λ∥σ − σ0 ∥22 (1)
σ ,Ω
and extensible. These features can be added as a plugin module.
where σ0 is the initial distribution of the conductivities, a forward
Furthermore, EIDORS is based on MATLAB, which is essentially a
operator f maps Ω and σ to boundary voltages v. By assuming a
functional programming language and has weak Object Oriented
perfect geometry (i.e., boundary shape and electrodes positions are
Programming (OOP) capability. In clinical EIT studies, most GUIs
known a priori), the jacobians of σ is computed as,
are written in C++ or Python. The algorithms developed in MATLAB
need to be optimized and translated which consumes lots of work. ∂ f (σ )
J=
pyEIT has clean IO and is suited for rapid prototyping EIT systems ∂σ
and benchmarking EIT reconstruction algorithms. Gauss–Newton method is used to solve (1) iteratively,
The architecture of pyEIT is introduced in Section 2. Illustrative
examples are given in Section 3. The impact of pyEIT is highlighted σ (k+1) = σ (k) + (JT J + λI)−1 JT (v − f (σ (k) )) (2)
in Section 4. Regularization terms can be incorporated into EIT easily by modi-
fying the norms in (1) accordingly.
2. Software description The base module records the boundary voltages and the Ja-
cobians [12]. All the EIT imaging modules are built upon base.
Static EIT imaging calculates (2) iteratively. A dynamic EIT imaging
2.1. Software architecture
algorithm can image the changes of conductivities at two frames.
In pyEIT, typical dynamic EIT imaging methods such as back pro-
The architecture of pyeit is given in Fig. 1. The mesh module jection (bp), GREIT [13] and NOSER [14] are implemented.
is capable of partitioning Ω into triangles (2D) or tetrahedrons
(3D). pyEIT wraps around a linear fem module. fem solves the EIT 3. Illustrative examples
forward problem using a 4-electrode model, and the intermediate
variables such as boundary voltages v and the Jacobians J are 3.1. Creating triangle meshes on a unit circle
recorded by the module base. pyEIT implements state-of-the-art
EIT algorithms that support both dynamic EIT imaging (or time- pyEIT reimplements distmesh using Python. It also provides a
difference imaging) and static EIT imaging. standard layered circle mesh. In the mesh module, create and
306 B. Liu et al. / SoftwareX 7 (2018) 304–308

Fig. 3. Triangle meshes on a unit circle using the distmesh2d and a standard layered circle meshing method. The electrodes are highlighted using red nodes.

layer_circle are used. These functions return two objects, the first
one is the mesh structure, which is a named tuple with ’node’,
’element’ and ’perm’. In 2D, node is a N × 2 matrix specifies the
xy coordinates of nodes, element is an M × 3 matrix describes the
connectivity structure of the mesh. The second one is el_pos which
specifies the numbered locations of the electrodes (see Fig. 3).
mesh0 , el_pos0 = create ( n_el =16)
mesh1 , el_pos1 = l a y e r _ c i r c l e ( n_el =1 , n_fan =8 ,
n_layer =8)
xy = mesh0 [ ’ node ’] # Nx2 matrix
t = mesh0 [ ’ element ’] # Mx3 matrix

3.2. Solving EIT forward problems

We use the Finite Element Method (FEM) to solve EIT forward


problems. In the forward class, we used a simple electrode model
where the electrical current is assumed to flow into and out of the
imaging area Ω through boundary nodes. Those special boundary
nodes are called electrodes. It should be noted that this is a simpli-
fication and the complete electrode model (CEM) is preferred. We Fig. 4. Solving an EIT forward problem. The current is injected via electrode 1 (the
are planning to add CEM in a future version of pyEIT. indices of Python start from 0) and sank on electrode 8. Equi-potential lines are
A single stimulation pattern is represented by a 2 × 1 row vector drawing in this figure for a better understanding of the distribution of electronic
fields.
called e. The source and the sink of the electrical current must be
specified on two boundary electrodes. For example, e = [0, 7]
means that the electrical current is injected into the 1st electrode
and outflowed from the 8th electrode. pyEIT allows users to construct any stimulation pattern. It has
pyEIT supports multi-frequency EIT analysis where permittiv- the flexibility of specifying any two electrodes as either a current
ities on Ω can be either real valued or complex valued. The per- source or sink in ei . The number of rows of E is not limited. We
mittivities are not mandatory. The forward solver class is initialized provide a simple wrapper called eit_scan_lines which produces a
using the unstructured mesh object and the positions of electrodes. typical 16 × 2 stimulation patterns in EIT [2] where the distance
The perms on elements are initialized using the mesh object. The from the electrical current source to the current sink is specified
values of elements can be modified and we provided a method of by a parameter called dist. E can be stacked, for example, E =
the mesh class called set_perm (see Fig. 4). [ET1 , ET2 ]T . In brain EIT applications, we can use fused stimulation
# setup ( AB ) electrical current path patterns. For example,
ex_line = [0 , 7] # Python index starts from 0
# calculate simulated data using FEM """
fwd = Forward ( mesh_obj , el_pos ) stimulation pattern can be specified as a matrix
f , _ = fwd . solve ( ex_line , perm = perm ) ex_mat = [[0 , 1] ,
f = np . real ( f ) [1 , 2] ,
[1 , 7]] ,
The forward class has a method called solve_eit, it requires a or it can also be stacked using multiple ex_mat
parameter called ex_mat which thereafter we denoted it by E. E """
is a M × 2 matrix, where each row of it represents a stimulation ex_mat1 = eit_scan_lines (16 , dist =4)
pattern. For example, the ith row of E is ei = [2, 5], which means ex_mat2 = eit_scan_lines (16 , dist =7)
that in our simple electrode model, the electrical current is injected ex_mat = np . vstack ([ ex_mat1 , ex_mat2 ])
through the electrode 3 and sank at the electrode 6. solve_eit p = fwd . solve_eit ( ex_mat = ex_mat , parser = ’ fmmu ’ ,
iterates over ei , expanded it into boundary conditions and then step =1)
solve the forward problem. The potentials at boundary electrodes
are extracted. The voltage differences on two electrodes (specified We reproduce the sensitivity analysis in [2]. In Fig. 5, multiple
by the parameter step) are computed and rearranged (specified by ’skip k’ stimulation patterns are simulated and the sensitivity of
the parameter parser). elements are visualized.
B. Liu et al. / SoftwareX 7 (2018) 304–308 307

Fig. 5. Sensitivity of different skip-k patterns.

Fig. 6. Solving EIT inverse problems.

3.3. Solving EIT inverse problems monitoring the status of the brain non-invasively during cardio-
vascular surgeries [10]. The data consist approximately 160 hours
In the following, we present examples of dynamic EIT imaging. recordings and are processed using pyEIT. We evaluated various
Dynamic EIT uses two frames and reconstructs the changes in the image segmentation algorithms. The characteristics of EIT images
conductivities. It is also called time difference EIT imaging (see are then analyzed to postoperative outcomes. A predictive model
Fig. 6). of early cerebral injuries is built. Then it is incorporated into the
final in-vivo EIT application, which is beneficial in clinical brain EIT
4. Impact studies.

pyEIT is the first Python package in the fields of Electrical


5. Conclusions
Impedance Tomography. It is OOP based and has clean architec-
ture. The forward computing and inverse EIT imaging modules
are stable. Advanced EIT imaging algorithms that use different In this paper, we presented a Python-based platform called
regularization penalties can be easily incorporated. pyEIT. It is well documented and a complete set of examples
The main impact of pyEIT is that it enables rapid prototyping regarding meshing, 2D/3D EIT forward simulation, dynamic or
of EIT systems and applications. The frontend GUI of EIT is usually static EIT imaging are provided. It also has IO features that are
developed using C++ or Python, the backends of these applications capable of loading binary data or patient-specific meshes. The APIs
can use pyEIT directly for meshing, imaging or data pre-processing. of pyEIT are versatile and extensible. The members of the EIT
Our group designed an EIT GUI using PyQT whose core function- community may benefit from pyEIT by sharing data and developed
alities are provided by pyEIT. Recently, an open source project EIT algorithms. pyEIT is also the getting started point for academic
called OpenEIT1 uses pyEIT as its backend. pyEIT can also be used in or industry users who are unfamiliar with EIT.
Electrical Impedance Spectroscopy (EIS) and Electrical Capacitance
Tomography (ECT) applications. Acknowledgments
pyEIT accelerates offline EIT data analysis. A pipeline processing
can be constructed using the state-of-the-art machine learning This work was in part supported by Natural Science Basic Re-
and image process Python packages. We have used brain EIT in search Plan in Shaanxi Province of China (Program No. 2017JQ8008)
and National Natural Science Foundation of China (Grant No.
1 https://github.com/OpenEIT. 61571445, 81570231, 81671846).
308 B. Liu et al. / SoftwareX 7 (2018) 304–308

References [7] Yang B, Shi X, Dai M, Xu C, You F, Fu F, et al. Real-time imaging of cerebral
infarction in rabbits using electrical impedance tomography. J Int Med Res
[1] Holder DS. Electrical impedance tomography: methods, history and applica- 2014;42(1):173–83.
tions. CRC Press; 2004. [8] Tang C, You F, Cheng G, Gao D, Fu F, Yang G, et al. Correlation between
[2] Adler A, Boyle A. Electrical impedance tomography: Tissue properties to structure and resistivity variations of the live human skull. IEEE Trans Biomed
image measures. IEEE Trans Biomed Eng 2017;64(11):2494–504. Eng 2008;55(9):2286–92.
[3] Frerichs I, Amato MB, van Kaam AH, Tingay DG, Zhao Z, Grychtol B, et al. Chest [9] Baumann SB, Wozny DR, Kelly SK, Meno FM. The electrical conductivity
electrical impedance tomography examination, data analysis, terminology, of human cerebrospinal fluid at body temperature. IEEE Trans Biomed Eng
clinical use and recommendations: consensus statement of the translational 1997;44(3):220–3.
eit development study group. Thorax 2016;1–11. http://dx.doi.org/10.1136/ [10] Li Y, Zhang D, Liu B, Jin Z, Duan W, Dong X, et al. Noninvasive cerebral imaging
thoraxjnl-2016-208357. and monitoring using electrical impedance tomography during total aortic
[4] Fu F, Li B, Dai M, Hu SJ, Li X, Xu CH, et al. Use of electrical impedance arch replacement. J Cardiothoracic Vascular Anesthesia 2018 [in press]. http:
tomography to monitor regional cerebral edema during clinical dehydration //dx.doi.org/10.1053/j.jvca.2018.05.002.
treatment. PLoS One 2014;9(12). e113202. [11] Adler A, Lionheart WR. Uses and abuses of EIDORS: an extensible software
[5] Xu C, Wang L, Shi X, You F, Fu F, Liu R, et al. Real-time imaging and detection base for EIT. Physiological Measurement 2006;27(5):S25.
of intracranial haemorrhage by electrical impedance tomography in a piglet [12] Gómez-Laberge C, Adler A. Direct EIT Jacobian calculations for con-
model. J Int Med Res 2010;38(5):1596–604. ductivity change and electrode movement. Physiological Measurement
[6] Shi X, You F, Fu F, Liu R, You Y, Dai M, et al. Preliminary research on monitor- 2008;29(6):S89.
ing of cerebral ischemia using electrical impedance tomography technique. [13] Adler A, Arnold JH, Bayford R, Borsic A, Brown B, Dixon P, et al. GREIT: a unified
In: 2008 30th annual international conference of the IEEE engineering in approach to 2D linear EIT reconstruction of lung images. Physiol Measure
medicine and biology society; 2008. p. 1188–91 http://dx.doi.org/10.1109/ 2009;30(6):S35.
IEMBS.2008.4649375. [14] Cheney M, Isaacson D, Newell JC. Electrical impedance tomography. SIAM Rev
1999;41(1):85–101.

You might also like