Skip to content

EISFitpython.singlechi

This module does the global-local fit of a series of stacked spectra. It can use all circuit elements in Circuit models.

from EISFitpython import singlechi

For the procedure and an example, see Global-local fitting.

Single_chi_report

Single_chi_report(f, Z, params, Temp, circuit_str, weight_mtd="M", return_cov=False)

Does the complete global-local fit. The function prints the report, writes the fitted data and the report, and makes the figures.

Parameter Description
f, Z Stacked frequency array and stacked complex impedance array.
params Start values in the order of the circuit string. One number is a global parameter. A list with one value for each spectrum is a local parameter.
Temp Temperatures in degrees Celsius, one for each spectrum.
circuit_str Circuit string.
weight_mtd "M", "P" or "U".
return_cov If True, the function also returns the covariance matrix.

Returns (popt, perror, Z_fit). With return_cov=True, it returns (popt, perror, Z_fit, pcov). The fit uses method="lm" without bounds.

The function writes these files:

  • Single-chi_Report.txt,
  • S-chi_fit_data_<Temp>C.txt for each spectrum,
  • one Nyquist figure for each spectrum,
  • one stacked Bode figure.

If the fit cannot start, the function gives the error.

Single_chi_bootstrap

Single_chi_bootstrap(
    f, Z, params, popt, circuit_str,
    weight_mtd="M", n_boot=1000, seed=0, noise="gaussian",
)

Does the global-local fit again on synthetic data (see EISFit_main.bootstrap_fit).

Parameter Description
f, Z The data of the fit.
params The start values that you gave to Single_chi_report. They set the global and the local parameters.
popt The fitted parameters from Single_chi_report.
circuit_str, weight_mtd The same values as in Single_chi_report.
n_boot Number of fits.
seed Start value of the random number generator. The same value gives the same result.
noise "gaussian" or "residual".

Returns an array with the shape (n_boot, len(popt)). The columns have the order of popt. Use the same positions as for popt to get the values of one parameter, for example for EIS_Batchfit.C_eff(..., boot=...).

flatten_params

flatten_params(params, circuit_str=None, N_sub=None)

Changes the structured start values into one flat list for the optimizer.

Parameter Description
params Numbers and lists in the order of the circuit string.
circuit_str Circuit string. The function uses it to find the element of each parameter.
N_sub Number of spectra.

One number gives one value. A list with N_sub values gives all its values. A list with one value gives that value. A list with a different length causes a ValueError.

Returns a Python list.

Single_chi

Single_chi(f, *params, circuit_str, circuit_type="fit")

Calculates the impedance of all spectra in a stacked frequency array. The function divides the array into spectra and gives each spectrum its parameter values.

Parameter Description
f Stacked frequency array. The function finds each spectrum by the start of its sweep.
*params One number for a global parameter. A list with one value for each spectrum for a local parameter.
circuit_str Circuit string. Give it as a keyword argument.
circuit_type "fit": real vector for the optimizer. "predict": complex impedance.

With "fit", the function returns a real array with 2 * len(f) values. With "predict", it returns a complex array with len(f) values.

format_circuit_output

format_circuit_output(
    popt,
    perror,
    CorrM,
    circuit_str,
    N_sub,
    Temp,
    param_template,
)

Makes the parameter table and the correlation table of the report.

param_template has one Boolean value for each circuit parameter. True is a local parameter with N_sub fitted values. False is a global parameter with one fitted value. The label of a local value contains its temperature in °C.

Returns (parameter_df, correlation_df) as pandas DataFrames. The parameter table has the columns Fit_Params, Value, Error and % error. The correlation table shows the values below the diagonal.

generate_plots

generate_plots(f, Z, Z_fit, Temp)

Makes one Nyquist figure for each spectrum and one stacked Bode figure. The function saves the figures as SVG files and shows them. Give one temperature for each spectrum.

Returns the last Nyquist figure and the Bode figure.

ELEMENT_PARAM_COUNT

ELEMENT_PARAM_COUNT = {
    "R": 1, "C": 1, "L": 1, "W": 1,
    "Q": 2, "F": 2, "G": 2, "H": 3,
}

This dictionary gives the number of parameters of each element type.