impedance.py: A Python package for electrochemical impedance analysis

License Authors of papers retain copyright and release the work under a Creative Commons Attribution 4.0 International License (CC BY 4.0). impedance.py is a community-driven Python package for making the analysis of electrochemical impedance spectroscopy (EIS) data easier and more reproducible. impedance.py currently provides several useful features commonly used in the typical impedance analysis workflow:

impedance.py is a community-driven Python package for making the analysis of electrochemical impedance spectroscopy (EIS) data easier and more reproducible. impedance.py currently provides several useful features commonly used in the typical impedance analysis workflow: • preprocessing: functions for importing data from a variety of instruments and file types • data validation: easy-to-use methods for checking measurement validity • model fitting: a simple and powerful interface for quickly fitting models to analyze data • model selection: parameter error estimates and model confidence bounds • visualization: interactive and publication-ready Nyquist and Bode plots

Background
Electrochemical impedance spectroscopy (EIS) is a powerful technique for noninvasively probing the physicochemical processes governing complex electrochemical systems by measuring the relationship between voltage and current (i.e. the impedance) as a function of frequency (Orazem & Tribollet, 2008). Analysis of EIS spectra often involves the construction and fitting of models to represent the system response. Equivalent circuit models, a popular method for interpreting impedance spectra, represent processes in an electrochemical system with elements in a circuit allowing quantitative characterization of the data. EIS inherently requires the system response is linear, causal and stable over the measurement time. As such, researchers must also ensure their data complies with these assumptions -often through some implementation of Kramers-Kronig analysis. Following the approach outlined above, workers have applied EIS to problems ranging from measuring the dielectric properties of biological systems (Semenov et al., 2001) to corrosion rates of coated metals (Bonora, Deflorian, & Fedrizzi, 1996). More recently, EIS has been widely adopted for studying processes governing batteries (Rodrigues, Munichandraiah, & Shukla, 2000;Tröltzsch, Kanoun, & Tränkler, 2006) and fuel cells (Springer, Zawodzinski, Wilson, & Gottesfeld, 1996;Wagner, Schnurnberger, Müller, & Lang, 1998).

Statement of Need
To date, typical impedance analysis solutions have relied on either instrument-specific, proprietary software or ad hoc, lab-specific code written for internal use. These proprietary or home-grown solutions lack cross-platform support, and users of Linux or MacOS are unable to perform analysis on their computers. In addition to making reproducible analysis difficult, these solutions can be restrictive to defining custom circuit elements and processing large datasets. By providing an open-source, cross-platform (Windows, MacOS, and Linux), community-driven package for the full impedance analysis pipeline from data management to parameter extraction and publication-ready figures, impedance.py seeks to encourage reproducible, easy-to-use, and transparent analysis. In addition to decades of electrochemical research, many new methods for validating (Schönleber, Klotz, & Ivers-Tiffée, 2014) and analyzing (Buteau & Dahn, 2019; impedance spectra have been developed by researchers. By lowering the barrier to use tried-and-true methods along side cutting-edge analytical techniques via a consistent interface, impedance.py also serves to grow as a community repository of best-practices while facilitating the adoption of new techniques.

Current impedance.py functionality Preprocessing
Once you've collected your data, the last thing you want to do is worry about how to turn the files generated by the instrument into results you can learn from. impedance.py offers easy-to-use functions for importing data from BioLogic, CH Instruments, Gamry, PARSTAT, VersaStudio, and ZView files. Don't see your instrument yet? Create an issue with a sample file and help contribute to the project!

Data validation
Ensuring that the system under measurement is linear, stable, and causal is an important, but often overlooked part of impedance analysis. impedance.py provides several methods (measurement models, Lin-KK algorithm (Schönleber et al., 2014)) for data validation as a part of the same easy-to-use package.

Equivalent circuit fitting
impedance.py equivalent circuit fitting combines an extremely flexible circuit definition scheme with a range of available circuit elements -from simple L, R, C, and constantphase elements to electrochemistry specific elements such as Warburg, Gerischer (Boukamp & Bouwmeester, 2003), and transmission-line models (Paasch, Micka, & Gersdorf, 1993). Custom elements can be easily added to a single users installation or to the overall project by creating an issue. Additional model fitting features include parameter bounds, holding circuit elements constant, weighted fitting, and even saving/loading models to a human readable .json file. Fitting is performed by non-linear least squares regression of the circuit model to impedance data via curve_fit from the scipy.optimize package (Virtanen et al., 2020).

Model selection
One of the biggest challenges in extracting parameters from EIS spectra is quantitatively evaluating the fit of different models. impedance.py returns estimated parameter error bars with every fit and comes with a built in method for calculating the confidence bounds of a fit model.

Data visualization
EIS is often qualitatively interpreted by examing the shape of a spectrum which relies on properly defined axes. impedance.py eliminates the tedium of manually formatting plots by providing built-in methods to generate clean, publication-ready figures including interactive plots via Altair (VanderPlas et al., 2018) and customizable Nyquist or Bode plots via matplotlib (Hunter, 2007).

An example of the simple model API
The documentation for impedance.py contains a guide on getting started and several examples of what a typical analysis workflow might look like using the package. Here we show how importing data, defining and fitting an equivalent circuit model, and visualizing the results can be done with just a handful of lines in impedance.py: