Utilitites

impedancefitter.utils.KK_integral_transform(omega, Z)[source]

Kramers-Kronig integral transform.

Parameters
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.

impedancefitter.utils.available_models()[source]

return list of available models

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 array

  • eps_r (numpy.ndarray, double) – relative permittivity

  • sigma (numpy.ndarray, double) – conductivity in S/m

  • c0 (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

lmfit.model.CompositeModel or lmfit.model.Model

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 array

  • Z (numpy.ndarray, complex) – impedance array

  • c0 (double) – unit capacitance of device

Returns

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 array

  • Z (numpy.ndarray, complex) – impedance array

  • c0 (double) – unit capacitance of device

Returns

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 array

  • impedance (numpy.ndarray, complex) – impedance array

  • format (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

lmfit.parameter.Parameters