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-2.0.0.tar.gz (58.7 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-2.0.0-py3-none-any.whl (60.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for impedance_extend-2.0.0.tar.gz
Algorithm Hash digest
SHA256 fb7829e18977e1e9b8153f76d6ec7fcf8e426ab1746329c23d9d291b31bd7429
MD5 de95279c32cc8c33fe56d9fc2cf8ec30
BLAKE2b-256 1eb3954694606fd448d34da4755acb3f34375ac1dd1ed625e8d1ef73818bf07c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for impedance_extend-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce9430efd8531b27b4f125f2fe1a5183c92de79184555f73afe1fccfa87fc15b
MD5 e9e6b170b845d50651eea21ac9df9ddf
BLAKE2b-256 ddb505daff677ec978ca4186ff0ffe20d665bb9aeeddd70cc63992ec9d910c3d

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