Skip to main content

GitHub release

PyPI - Downloads All Contributors

Build Status Documentation Status Coverage Status

impedance_extend.py

impedance_extend.py is a Python package for making electrochemical impedance spectroscopy (EIS) analysis reproducible and easy-to-use. It extends impedance.py by adding least_squares, GA (using pygad), and PSO (using pyswarms) as additional optimization methods. impedance_extend.py additionally supports sequential optimization (such as running GA/PSO followed by least_squares), and adding soft-constraints (such as ensure R1 < R2 or R1*C1 < 1 etc.).

Aiming to create a consistent, scikit-learn-like API for impedance analysis, impedance.py contains modules for data preprocessing, validation, model fitting, and visualization.

For a little more in-depth discussion of the package background and capabilities, check out our Journal of Open Source Software paper.

If you have a feature request or find a bug, please file an issue or, better yet, make the code improvements and submit a pull request! The goal is to build an open-source tool that the entire impedance community can improve and use!

Motivation for extension

The parameters of the equivalent circuit, $p$, need to be calculated such that the impedance of the circuit, $Z(f,p)$ is "equal" to the target impedance, $Z_{tgt}(f)$. Since the impedance cannot always be made exactly equal, it is instead more practical to minimize the difference between the impedances instead. To this end $$ p=\underset{p}{argmin} ; J(p) $$ where the cost function, $$J(p)=\sum_{f} [Z(f,p)-Z_{tgt}(f)]^2$$

The original impedance.py uses curve_fit (which uses least_squares under the hood), and basinhopping when global_opt=True. least_squares is well suited for functions with a single minimum. If there are multiple minima, least_squares may get stuck at a local minimum; as such it is sensitive to initial conditions. basinhopping primarily uses local gradient methods to find the (local) minimum. The algorithm then uses a "hop" to perturb the parameter, and then checks if the cost function could have a logical global trend. Hence, the basinhopping works well if cost-function has "funnel" of "bowl" topology with some "pits".

We observed that basinhopping did not converge when data was noisy data. Hence, impedance_extend adds Particle Swarm Optimization (PSO) and Genetic Algorithm (GA) based optimization.

PSO works when the cost-function land scape is "Rugged & Noisy" with non-differentiable mountain range with many small, disconnected "false valleys,".

GA works well when the cost-function landscape has local minimum with "Strong Local Attraction.". Since GA spans the parameter space it is likely to reach the true minimum.

optimization Illustration of the different optimization algorithms (AI generated).

Plevris et al. 10.21105/joss.02349 may provide better insights into the optimization problem (providing a head-to-head comparison between GA and PSO-based optimization and classical optimization for a wide rage of multi-parameter functions).

Installation

The easiest way to install impedance_extend.py is from PyPI using pip.

pip install impedance_extend

See Getting started with impedance.py for instructions on getting started from scratch.

Dependencies

impedance.py requires:

  • Python (>=3.10)
  • SciPy (>=1.0)
  • NumPy (>=1.22.4)
  • Matplotlib (>=3.5)
  • Altair (>=3.0)
  • Pandas
  • Pygad (>=3.6.0)
  • Pyswarms (>=1.3)

Several example notebooks are provided in the docs/source/examples/ directory. Opening these will require Jupyter notebook or Jupyter lab.

Examples and Documentation

Several examples can be found in the docs/source/examples/ directory (the Fitting impedance spectra notebook is a great place to start) and the documentation can be found at impedancepy.readthedocs.io.

Citing the original impedance.py

DOI

If you use impedance.py in published work, please consider citing https://joss.theoj.org/papers/10.21105/joss.02349 as

@article{Murbach2020,
  doi = {10.21105/joss.02349},
  url = {https://doi.org/10.21105/joss.02349},
  year = {2020},
  publisher = {The Open Journal},
  volume = {5},
  number = {52},
  pages = {2349},
  author = {Matthew D. Murbach and Brian Gerwe and Neal Dawson-Elli and Lok-kun Tsui},
  title = {impedance.py: A Python package for electrochemical impedance analysis},
  journal = {Journal of Open Source Software}
}

Contributors ✨

This project was adapted from a fork of [impedance.py] (https://github.com/k-vijayaraghavan/impedance_extend.py). [Impedance.py] (https://github.com/k-vijayaraghavan/impedance_extend.py) was started at the 2018 Electrochemical Society (ECS) Hack Week in Seattle and has benefited from a community of users and contributors since. Thanks goes to these wonderful people (emoji key):

Krishna Vijayaraghavan
Krishna Vijayaraghavan

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Metadata

Release files for impedance-extend 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for impedance-extend 2.0.1
File Size Uploaded
impedance_extend-2.0.1.tar.gz 58.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for impedance-extend 2.0.1
File Interpreter ABI Platform
impedance_extend-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 119.2 kB

Release files / impedance_extend-2.0.1.tar.gz

Download URL impedance_extend-2.0.1.tar.gz
Size 58.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ef3740b66107976c73f5b2a02ee74581f53fcd0a1b2100f8f79b239755e7b98d
BLAKE2b-256 checksum
How to use checksums
ba028a809215d009c526d59ae1c263fe4e2c1cd3d435098e64598fe34783e29c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / impedance_extend-2.0.1-py3-none-any.whl

Download URL impedance_extend-2.0.1-py3-none-any.whl
Size 60.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2333827ba464284bd92e977944ab9af6c28c09e80a95bef7cfb97275f3fb9478
BLAKE2b-256 checksum
How to use checksums
a4c9fa499a66e98dce23cafca7af35b7cb30d0cd7bb241281dbad75beda248e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

2.0.3

2 release files

2.0.2

2 release files

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page