Skip to content

Global-local fitting

The global-local fit uses a series of spectra as one problem. It fits all spectra together with one cost function. Each parameter is one of two types:

  • global: all spectra have the same value,
  • local: each spectrum has its own value.

When to use this fit

In a temperature series, the resistances change strongly with the temperature. Thus the resistances are local. Some parameters stay constant, for example the CPE parameters of the bulk.

A fit of each spectrum alone calculates these constant parameters again for each temperature. At high temperature, the bulk arc moves out of the measured frequency range. The parameters of this arc then have large errors.

In the global-local fit, all spectra together give the value of a global parameter. Spectra with a clear arc then help the spectra where the arc is not clear.

The start value sets the type

You do not mark a parameter as global or local. The form of its start value sets the type. For a series of N spectra:

Start value Type
One number Global
A list with N values Local. Each spectrum starts with its own value
A list with one value Global

A list with a different length causes a ValueError.

Give the parameters in the order of the circuit string. This example is for the seven spectra of EIS_Data/Example-3-4:

circuit = "(R1|Q1)+(R2|Q2)+Q3"

params = (
    [1.8e5, 1.3e5, 9.8e4, 7.1e4, 5.3e4, 3.2e4, 2.0e4],  # R1: local
    1.3e-11,                                             # Q1: global
    0.90,                                                # n1: global
    [2.2e6, 1.2e6, 7.1e5, 4.2e5, 2.5e5, 1.6e5, 1.0e5],  # R2: local
    [1.48e-10] * 7,                                      # Q2: local
    [0.90] * 7,                                          # n2: local
    [1.27e-6] * 7,                                       # Q3: local
    [0.50] * 7,                                          # n3: local
)

A batch fit or the Nyquist plots give good start values for the local resistances.

Stack the spectra

import numpy as np
from EISFitpython import data_extraction as data
from EISFitpython import singlechi

files = data.get_eis_files("EIS_Data", "Example-3-4")
f, Z = data.stack_NEISYS_files(files)
temperature_c = np.array([140, 150, 160, 170, 180, 190, 200])

The fit finds each spectrum in the stacked array by the start of its frequency sweep. Stack the files in the order of the measurement. Give one temperature for each spectrum.

Fit

popt, perror, Z_fit = singlechi.Single_chi_report(
    f, Z, params, temperature_c, circuit, weight_mtd="M"
)

The fit uses the Levenberg-Marquardt method without bounds. The function prints a report with these items:

  • the fit statistics,
  • the parameters and their standard errors,
  • the correlation matrix.

The function writes these files:

  • the report,
  • one file with the fitted data for each temperature,
  • one Nyquist figure for each temperature,
  • one stacked Bode figure.

If the fit cannot start, the function stops with the error. An incorrect circuit string is one possible cause.

Read the result

popt and perror are flat arrays. The parameters have the order of the circuit. A local parameter uses N positions in sequence. For the example above, with seven spectra:

Positions Parameter
0 to 6 R1 at the seven temperatures
7 Q1 (global)
8 n1 (global)
9 to 15 R2
16 to 22 Q2
23 to 29 n2
30 to 36 Q3
37 to 43 n3
R_bulk = popt[0:7]
Q_bulk, n_bulk = popt[7], popt[8]
R_gb = popt[9:16]

The positions change if you change the circuit or the type of a parameter. The printed report gives the name of each value. Compare your positions with the report.

Calculate the derived quantities

Use the resistances with plot_arrhenius and C_eff as you do after a batch fit (see Batch and Arrhenius analysis). Two functions give the input for the error of the effective capacitance:

  • Single_chi_bootstrap(f, Z, params, popt, circuit) does the full fit again on synthetic data. It returns the fit results in the same order as popt.
  • Single_chi_report(..., return_cov=True) returns the covariance matrix as a fourth result.

Example_scripts/Example4 contains the complete analysis.