EISFitpython.EISFit_main¶
This module contains the simulation, the fit of one spectrum, the reports and the plots. It also contains the Arrhenius analysis and the electric modulus.
EISFit¶
Fits a circuit to one spectrum with scipy.optimize.curve_fit. The fit uses
the real parts and the imaginary parts of the impedance together.
| Parameter | Description |
|---|---|
f |
Frequency array in hertz. |
Z |
Complex impedance array with the same length as f. |
params |
Start values in the order of the circuit string. |
circuit |
Circuit string if single_chi="No". Model function if single_chi="Yes". |
UB, LB |
Upper bounds and lower bounds. Give empty lists for a fit without bounds. |
weight_mtd |
"M" (modulus), "P" (proportional) or "U" (unit). |
method |
Method of SciPy: "lm", "trf" or "dogbox". |
single_chi |
"No": the function makes the model function from the circuit string. "Yes": the function uses circuit as the model function. |
Returns (fit_stats, popt, perror, CorrMat):
fit_stats: dictionary of the fit statistics.fit_stats["pcov"]is the covariance matrix of the fitted parameters.popt: fitted parameters.perror: standard errors of the parameters,sqrt(diag(pcov)).CorrMat: correlation matrix of the parameters.
For the weighting, the bounds and the statistics, see Fitting one spectrum.
fit_report¶
Does the fit with EISFit and prints three items: the fit statistics, the
parameter table and the correlation matrix. The correlation matrix shows the
values below the diagonal.
Returns (popt, perror). With return_cov=True, it returns
(popt, perror, pcov). Use this function with a circuit string and
single_chi="No".
full_EIS_report¶
full_EIS_report(
freq,
Z,
params,
circuit,
UB,
LB,
weight_mtd,
method,
single_chi,
plot_type="both",
)
Does the fit, prints the report and writes the result files. Returns
(popt, perror, Z_fit).
Use this function with a circuit string and single_chi="No". It writes
EIS_fit_report.txt, EIS_fit_data_<circuit>.txt and the figures of
plot_fit. The rows of the fitted data go from high frequency to low
frequency.
bootstrap_fit¶
bootstrap_fit(
f, Z, popt, circuit, UB, LB,
weight_mtd="M", method="lm", single_chi="No",
n_boot=1000, seed=0, noise="gaussian", groups=None,
)
Fits many synthetic spectra to find the statistical distribution of the fitted
parameters. Each synthetic spectrum is the fitted model with added noise. The
noise has the same size as the differences between the data and the fit. Each
fit uses the same circuit, weighting and method as the original fit, and starts
at popt.
| Parameter | Description |
|---|---|
f, Z |
The data of the original fit. |
popt |
Fitted parameters from EISFit or fit_report. |
circuit, UB, LB, weight_mtd, method, single_chi |
The same values as in EISFit. |
n_boot |
Number of fits. |
seed |
Start value of the random number generator. The same value gives the same result. |
noise |
"gaussian": normal noise, with the size from the fit weights and the reduced chi-squared. "residual": the weighted differences of the original fit in random order, as pairs of real part and imaginary part. |
groups |
Number of points of each spectrum in stacked data. With noise="residual", the function then uses the differences of each spectrum only for that spectrum. |
Returns an array with the shape (n_boot, n_params). A fit that does not
converge gives a row of NaN.
You can calculate a derived quantity for each row. The standard deviation of
these values is the error of the derived quantity. This procedure includes the
correlation between the parameters (see EIS_Batchfit.C_eff).
logf_gen¶
Returns num_points frequencies from start_freq to end_freq with equal
steps on the logarithmic scale. The two frequencies must be positive. If
start_freq is larger than end_freq, the array goes from high frequency to
low frequency.
predict_Z¶
Simulates the impedance of a circuit. The function makes the frequencies with
logf_gen, calculates the impedance and saves the result. Returns (f, Z).
| Parameter | Type | Description |
|---|---|---|
start_freq, end_freq |
int or float |
First frequency and last frequency in hertz. |
no_points |
positive int |
Number of frequencies. |
params |
sequence of float | Circuit parameters. |
circuit_str |
str |
Circuit string. |
The function writes EIS-SIM_<circuit>.txt. The rows in the file go from high
frequency to low frequency.
circuit_components¶
Returns the elements of a circuit string in their order.
The function finds only elements that have a number. Thus give each element a number.
nyquistPlot¶
Plots -Z.imag as a function of Z.real into the axes ax. The function
selects the unit (ohm, kilohm, megohm or gigohm) from the largest impedance in
Z. It sets the axis labels and equal scales on the two axes. Returns ax.
The function gives the items of param_dict to Axes.plot.
bodePlot¶
Plots the selected quantities as a function of the frequency. The possible
values in plot_types are "magnitude", "phase", "real" and
"imaginary". Without plot_types, the function plots the imaginary part and
the phase. Give one axes object for each quantity.
With all_Z, a list of all spectra, the function selects one common impedance
unit. Returns the list axes.
plot_fit¶
Makes the figures of the data and the fit, saves them and shows them.
plot_type is "nyquist", "bode" or "both".
The function writes these files:
Nyquist-plot_with_fit.svgorNyquist-plot_data_only.svg,Bode-magnitude_with_fit.svgorBode-magnitude_data_only.svg,Bode-phase_with_fit.svgorBode-phase_data_only.svg.
For your own figures, see the plotting guide.
EA¶
Fits the Arrhenius equation to conductivity data and plots the result.
| Parameter | Description |
|---|---|
ax |
Matplotlib axes. |
T |
Temperatures in kelvin. |
conductivity |
Conductivities in S/cm. The values must be positive. |
plot_params |
Dictionary for the appearance of the data points. |
The function fits a straight line to log(conductivity * T) as a function of
1000 / T. It prints these results:
- R-squared of the straight line,
- the activation energy and its standard error,
- the pre-exponential factor and its standard error,
- the conductivity at room temperature (298.15 K) and its standard error.
The error of the pre-exponential factor is the factor multiplied by the
standard error of the intercept. The error of the conductivity at room
temperature is the standard error of the straight line at 1000 / 298.15. This
error includes the correlation between the slope and the intercept.
Returns ax.
modulus_plot¶
Calculates the electric modulus and plots it as a function of the frequency.
diameter and thickness are the dimensions of the pellet in centimeters. The
possible values in plot_types are "magnitude", "real" and "imaginary".
Without plot_types, the function plots the imaginary part.
Returns the list axes.