Utilitites¶
-
impedancefitter.utils.KK_integral_transform(omega, Z)[source]¶ Kramers-Kronig integral transform.
- Parameters
omega (
numpy.ndarray, double) – frequency arrayZ (
numpy.ndarray, complex) – impedance array
- Returns
The transformed impedance array.
- Return type
numpy.ndarray, complex
Notes
Implementation following [Urquidi1990]
- Urquidi1990
Urquidi-Macdonald, M., Real, S., & Macdonald, D. D. (1990). Applications of Kramers-Kronig transforms in the analysis of electrochemical impedance data-III. Stability and linearity. Electrochimica Acta, 35(10), 1559–1566. https://doi.org/10.1016/0013-4686(90)80010-L
-
impedancefitter.utils.available_file_format()[source]¶ List available file formats.
Currently available:
XLSX and CSV:
The file is structured like: frequency, real part of impedance, imaginary part of impedance. There may be many different sets of impedance data, i.e. there may be more columns with the real and the imaginary part. Then, the frequencies column must not be repeated. In fact, the number of columns equals the number of impedance data sets plus one (for the frequency).
Note
A single header line is needed in a CSV and XLSX file. It may contain for example frequency, Real Part, Imag Part. Otherwise the read-in function will fail.
CSV_E4980AL:
Read in data that is structured in 5 columns: frequency, real part, imaginary part of the impedance, voltage, current
Note
There is always only one data set in a file.
TXT:
These files contain frequency, real and imaginary part of the impedance (i.e., 3 columns). The TXT files may contain two traces; only one of them is read in. For TXT files you can specify the number of rows to skip. Moreover, the file ending is not strictly enforced here.
See also
-
impedancefitter.utils.check_parameters(bufdict)[source]¶ Check parameters for physical correctness.
- Parameters
bufdict (dict) – Contains all parameters and their values
Notes
All parameters are forced to be greater or equal zero. There are only two exceptions.
-
impedancefitter.utils.convert_diel_properties_to_impedance(omega, eps_r, sigma, c0)[source]¶ Return impedance from dielectric properties.
- Parameters
omega (
numpy.ndarray, double) – frequency arrayeps_r (
numpy.ndarray, double) – relative permittivitysigma (
numpy.ndarray, double) – conductivity in S/mc0 (double) – unit capacitance of device
- Returns
impedance array
- Return type
numpy.ndarray, complex
Notes
Use that the impedance is
\[Z = (j \omega \varepsilon_\mathrm{r}^\ast c_0)^{-1} ,\]where \(\varepsilon_\mathrm{r}^\ast\) is the relative complex permittivity (see for instance [Grant1958] for further explanation). Note that the vacuum permittivity \(\varepsilon_0\) is contained in \(c_0\).
In the function, the variable epsc describes the term
\[\omega \varepsilon_\mathrm{r}^\ast\]
-
impedancefitter.utils.draw_scheme(modelname, show=True, save=False)[source]¶ Show (and save) SchemDraw drawing.
- Parameters
modelname (str) – String representation of the equivalent circuit.
show (bool, optional) – Show scheme in matplotlib window.
save (bool, optional) – Save scheme to file. File is called scheme.svg.
-
impedancefitter.utils.get_equivalent_circuit_model(modelname, logscale=False, diel=False)[source]¶ Get LMFIT CompositeModel.
- Parameters
modelname (str) – String representation of the equivalent circuit.
logscale (bool) – Convert to logscale.
diel (bool) – Convert to complex permittivity and fit this instead of impedance.
- Returns
the final model of the entire circuit
- Return type
Notes
The parser is based on Pyparsing. It is sensitive towards extra ( or ) or +. Thus, keep the circuit simple.
-
impedancefitter.utils.get_labels(params)[source]¶ return the labels for every parameter in LaTex code.
- Parameters
params (list of string) – list with parameters names (possible prefixes included)
- Returns
labels – dictionary with parameter names as keys and LaTex code as values.
- Return type
dict
-
impedancefitter.utils.return_diel_properties(omega, Z, c0)[source]¶ Return relative permittivity and conductivity from impedance spectrum in cavity with known unit capacitance.
Notes
Use that the impedance is
\[Z = (j \omega \varepsilon_\mathrm{r}^\ast c_0)^{-1} ,\]where \(\varepsilon_\mathrm{r}^\ast\) is the relative complex permittivity (see for instance [Grant1958] for further explanation). Note that the vacuum permittivity \(\varepsilon_0\) is contained in \(c_0\).
When the unit capacitance \(c_0\) of the device is known, a direct mapping from impedance to relative complex permittivity is possible:
\[\varepsilon_\mathrm{r}^\ast = (j \omega Z c_0)^{-1} = \frac{\varepsilon^\ast}{\varepsilon_0}\]The unit capacitance (or air capacitance) of the device is defined as
\[c_0 = \frac{\varepsilon_0 A}{d}\]for a parallel-plate capacitor with electrode area A and spacing d but can also be measured in a calibration step.
The relative permittivity is the real part of \(\varepsilon_\mathrm{r}^\ast\) and the conductivity is the negative imaginary part times the frequency and the vacuum permittivity.
- Parameters
omega (
numpy.ndarray, double) – frequency arrayZ (
numpy.ndarray, complex) – impedance arrayc0 (double) – unit capacitance of device
- Returns
eps_r (
numpy.ndarray, double) – relative permittivityconductivity (
numpy.ndarray, double) – conductivity in S/m
References
- Grant1958(1,2)
Grant, F. A. (1958). Use of complex conductivity in the representation of dielectric phenomena. Journal of Applied Physics, 29(1), 76–80. https://doi.org/10.1063/1.1722949
-
impedancefitter.utils.return_dielectric_modulus(omega, Z, c0)[source]¶ Return dielectric modulus
Notes
The dielectric modulus is \(M = 1 / \varepsilon_\mathrm{r}^\ast\). See [Bordi2001] for further explanation.
- Parameters
omega (
numpy.ndarray, double) – frequency arrayZ (
numpy.ndarray, complex) – impedance arrayc0 (double) – unit capacitance of device
- Returns
ReM (
numpy.ndarray, double) – real part of modulusImM (
numpy.ndarray, double) – imaginary part of modulus
References
- Bordi2001
Bordi, F., & Cametti, C. (2001). Occurrence of an intermediate relaxation process in water-in-oil microemulsions below percolation: The electrical modulus formalism. Journal of Colloid and Interface Science, 237(2), 224–229. https://doi.org/10.1006/jcis.2001.7456
-
impedancefitter.utils.save_impedance(omega, impedance, format='CSV', filename='impedance')[source]¶ Save impedance to CSV or XLSX file.
- Parameters
omega (
numpy.ndarray, double) – frequency arrayimpedance (
numpy.ndarray, complex) – impedance arrayformat (str) – use either CSV or XLSX format. Based on the format, the correct ending is chosen.
filename (str) – specify a filename (without ending!). the default is impedance.csv or impedance.xlsx
-
impedancefitter.utils.set_parameters(model, parameterdict=None, emcee=False, weighting_model=False)[source]¶ - Parameters
model (
lmfit.model.Model) – The LMFIT model used for fitting.parameterdict (dict, optional) – A dictionary containing parameters for model with min, max, vary info for LMFIT. If it is None (default), the parameters are read in from a yaml-file.
emcee (bool, optional) – if emcee is used, an additional __lnsigma parameter will be set
weighting_model (bool, optional) – if a weighting model is used, the variance will be fit as well
- Returns
params – LMFIT Parameters object.
- Return type
-
impedancefitter.suspensionmodels.bh_eps_model(epsi_med, epsi_p, p)[source]¶ Complex permittvitiy of double shell model by Bruggeman-Hanai approach
- Parameters
epsi_med (
numpy.ndarray, complex) – Complex permittivity array of mediumepsi_p (
numpy.ndarray, complex) – Complex permittivity array of suspended particlesp (double) – volume fraction
- Returns
Complex permittivity array
- Return type
numpy.ndarray, complex
Notes
The implementation follows [Cottet2019]. Note that the approach here might not be numerically as accurate as the cubic equation solver (
impedancefitter.suspensionmodels.bhcubic_eps_model()). In the respective unit test, the deviation is below 1%, though.References
- Cottet2019
Cottet, J., Fabregue, O., Berger, C., Buret, F., Renaud, P., & Frénéa-Robin, M. (2019). MyDEP: A New Computational Tool for Dielectric Modeling of Particles and Cells. Biophysical Journal, 116(1), 12–18. https://doi.org/10.1016/j.bpj.2018.11.021
-
impedancefitter.suspensionmodels.bhcubic_eps_model(epsi_med, epsi_p, p)[source]¶ Complex permittvitiy of concentrated suspension model by Bruggeman-Hanai approach
- Parameters
epsi_med (
numpy.ndarray, complex) – Complex permittivity array of mediumepsi_p (
numpy.ndarray, complex) – Complex permittivity array of suspended particlesp (double) – volume fraction
- Returns
Complex permittivity array
- Return type
numpy.ndarray, complex
Notes
The complex permittivity of the suspension \(\varepsilon_\mathrm{sus}^\ast\) is given by [Hanai1979]
\[\frac{\varepsilon_\mathrm{sus}^\ast - \varepsilon_\mathrm{p}^\ast}{\varepsilon_\mathrm{med}^\ast - \varepsilon_\mathrm{p}^\ast} \left(\frac{\varepsilon_\mathrm{med}^\ast}{\varepsilon_\mathrm{sus}^\ast}\right)^{1/3} = 1 - p \enspace ,\]with \(\varepsilon_\mathrm{med}^\ast\) being the permittivity of the liquid medium and \(\varepsilon_\mathrm{p}^\ast\) the permittivity of the suspended particle (e.g., cells).
Cubing the equation yields a cubic equation. The cubic roots (three in total) are the possible solutions for the complex permittivity of the suspension. Only one of them is physical, which can be found by substituting the cubic roots into another function [Hanai1979].
A numerical solution is implemented in
impedancefitter.suspensionmodels.bh_eps_model()References
- Hanai1979(1,2)
Hanai, T., Asami, K., & Korzumi, N. (1979). Dielectric Theory of Concentrated Suspensions of Shell-Spheres in Particular Reference to the Analysis of Biological Cell Suspensions. Bull. Inst. Chem. Res., Kyoto Univ, 57(4), 297–305. http://hdl.handle.net/2433/76842
-
impedancefitter.suspensionmodels.eps_sus_MW(epsi_med, epsi_p, p)[source]¶ Maxwell-Wagner mixture model for dilute suspensions
- Parameters
epsi_med (
numpy.ndarray, complex) – complex permittivities of mediumepsi_p (
numpy.ndarray, complex) – complex permittivities of suspension phase (cells, particles…)p (double) – volume fraction
- Returns
Complex permittivity array
- Return type
numpy.ndarray, complex
Notes
The complex permittivity of the suspension \(\varepsilon_\mathrm{sus}^\ast\) is given by
\[\varepsilon_\mathrm{sus}^\ast = \varepsilon_\mathrm{med}^\ast\frac{(2\varepsilon_\mathrm{med}^\ast+\varepsilon_\mathrm{p}^\ast)-2p(\varepsilon_\mathrm{med}^\ast-\varepsilon_\mathrm{p}^\ast)}{(2\varepsilon_\mathrm{med}^\ast+\varepsilon_\mathrm{p}^\ast)+p(\varepsilon_\mathrm{med}^\ast-\varepsilon_\mathrm{p}^\ast)} \enspace ,\]with \(\varepsilon_\mathrm{med}^\ast\) being the permittivity of the liquid medium and \(\varepsilon_\mathrm{p}^\ast\) the permittivity of the suspended particle (e.g., cells).
-
impedancefitter.cubic_roots.get_cubic_roots(a, b, c)[source]¶ Get the roots of a cubic equation.
- Parameters
a (complex) – polynomial coefficient
b (complex) – polynomial coefficient
c (complex) – polynomial coefficient
- Returns
Complex permittivity array
- Return type
numpy.ndarray, complex
Notes
Return the roots of an expression
\[z^3 + a z^2 + b z + c = 0\]More details can be found in [Press2007].
References
- Press2007
Press, W.H., Teukolsky, S.A., Vetterling, W.T., and Flannery, B.P. (2007) Numerical recipes : the art of scientific computing. Cambridge Univ. Press, USA, 3rd edition