Skip to content

EISFitpython.circuit_main

This module calculates the impedance of a circuit. It also creates model functions for scipy.optimize.curve_fit.

from EISFitpython import circuit_main as circuits

For the circuit syntax, the element equations and the parameter order, see Circuit models.

compute_impedance

compute_impedance(p, circuit_str, freqs)

Calculates the impedance of a circuit at the given frequencies.

Parameter Type Description
p sequence of float Element parameters in the order of the circuit string.
circuit_str str Circuit string, for example "R1+(R2|Q1)".
freqs NumPy array Frequencies in hertz. The values must be positive.

Returns a complex NumPy array with one value for each frequency. An incorrect circuit string causes a ValueError.

import numpy as np

Z = circuits.compute_impedance(
    [5.0, 20.0, 1e-6, 0.9],
    "R1+(R2|Q1)",
    np.array([1.0, 10.0, 100.0]),
)

Z_curve_fit

Z_curve_fit(circuit_str)

Creates a model function model(f, *params) for a fit with SciPy. The model function calculates the impedance of the circuit. It returns a real vector with 2 * len(f) values: first all real parts, then all imaginary parts.

Parameter Type Description
circuit_str str Circuit string for the model function.
model = circuits.Z_curve_fit("(R1|C1)")
y = model(f, 100.0, 1e-6)

Z_gen

Z_gen(circuit_string, return_type="concatenated")

Creates a model function model(f, *params) for a fit or for a simulation.

Parameter Type Default Description
circuit_string str necessary Circuit string for the model function.
return_type str "concatenated" "concatenated": real vector for a fit. "complex": complex impedance.

A different value of return_type causes a ValueError.

complex_model = circuits.Z_gen("R1+(R2|Q1)", return_type="complex")
Z = complex_model(f, 5.0, 20.0, 1e-6, 0.9)