Skip to main content

A package for analyzing electrochemical impedance data (with support for GA, PSO and least_squares or combinations thereof)

Project description

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

impedance_extend-1.0.1.tar.gz (52.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

impedance_extend-1.0.1-py3-none-any.whl (54.2 kB view details)

Uploaded Python 3

File details

Details for the file impedance_extend-1.0.1.tar.gz.

File metadata

  • Download URL: impedance_extend-1.0.1.tar.gz
  • Upload date:
  • Size: 52.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for impedance_extend-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3becbfbfa5823b4692495a557bcc01b059194db815e65073b1cc4dd5780dc43d
MD5 245e4dd0a26c6cb552884b8a430b6c0b
BLAKE2b-256 245912420b4f87600ba730424eeeb7446cb6eb864920d55b6b626770229c80ac

See more details on using hashes here.

File details

Details for the file impedance_extend-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for impedance_extend-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4d81a10ff61367cc70cf4e499a44277c4830cb6760f678f2c898695b11eab08d
MD5 f5c7eb53433d5f32c892018c76000869
BLAKE2b-256 a83dc675bebd18a5c490da9551d120750a7ce5d35574e317b1ad356aa139ab08

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page