dgpost.transform.circuit_utils package

Submodules

dgpost.transform.circuit_utils.circuit_components module

dgpost.transform.circuit_utils.circuit_components.create_parameter(name, bounds, unit)

Creates a dictionary with keys name, bounds and unit

Parameters
  • name (str) – name of the parameter

  • bounds (tuple[float, float]) – default bounds of the parameter

  • unit (str) – SI unit of the parameter

Returns

dictionary containing the input values

Return type

dict

class dgpost.transform.circuit_utils.circuit_components.Component

Bases: object

A component stores information needed for the fitting.

static get_symbol()

Unique symbol used to identify the component in the circuit string

The symbol can only contain letters, i.e. a-z, A-Z

Return type

str

static get_parameters(name)

returns the parameter(s) that describe the component

A parameter is a dictionary with the keys: name, bounds and unit. The name of the parameter should be based on the symbol. It can also contain any character except a whitespace. The bounds are given as a tuple with the lower (lb) and upper bounds (ub) like (lb, ub). The unit needs to be recognised by pint

Parameters

name (str) – name of the component in the circuit string, made out of the symbol with an additional digit.

Returns

The parameters that describes the component. A parameter is a dictionary with 3 keys: ‘name’, ‘bounds’ and ‘unit’

Return type

list[dict]

static calc_impedance(param, name, freq)

Calculates the impedance of the component

Parameters
  • param (dict[str, float]) – dictionary of parameter values with the name as the key

  • name (str) – the name of the component

  • freq (array) – the frequencies at which the impedance should be calculated

Returns

numpy array with the complex impedance of the component for the given frequencies

Return type

np.array

class dgpost.transform.circuit_utils.circuit_components.Resistor

Bases: dgpost.transform.circuit_utils.circuit_components.Component

defines a resistor

static get_symbol()

Unique symbol used to identify the component in the circuit string

The symbol can only contain letters, i.e. a-z, A-Z

static get_parameters(name)

returns the parameter(s) that describe the component

A parameter is a dictionary with the keys: name, bounds and unit. The name of the parameter should be based on the symbol. It can also contain any character except a whitespace. The bounds are given as a tuple with the lower (lb) and upper bounds (ub) like (lb, ub). The unit needs to be recognised by pint

Parameters

name – name of the component in the circuit string, made out of the symbol with an additional digit.

Returns

The parameters that describes the component. A parameter is a dictionary with 3 keys: ‘name’, ‘bounds’ and ‘unit’

Return type

list[dict]

static calc_impedance(param, name, freq)

Calculates the impedance of the component

Parameters
  • param – dictionary of parameter values with the name as the key

  • name – the name of the component

  • freq – the frequencies at which the impedance should be calculated

Returns

numpy array with the complex impedance of the component for the given frequencies

Return type

np.array

class dgpost.transform.circuit_utils.circuit_components.Capacitor

Bases: dgpost.transform.circuit_utils.circuit_components.Component

defines a capacitor

static get_symbol()

Unique symbol used to identify the component in the circuit string

The symbol can only contain letters, i.e. a-z, A-Z

static get_parameters(name)

returns the parameter(s) that describe the component

A parameter is a dictionary with the keys: name, bounds and unit. The name of the parameter should be based on the symbol. It can also contain any character except a whitespace. The bounds are given as a tuple with the lower (lb) and upper bounds (ub) like (lb, ub). The unit needs to be recognised by pint

Parameters

name – name of the component in the circuit string, made out of the symbol with an additional digit.

Returns

The parameters that describes the component. A parameter is a dictionary with 3 keys: ‘name’, ‘bounds’ and ‘unit’

Return type

list[dict]

static calc_impedance(param, name, freq)

Calculates the impedance of the component

Parameters
  • param – dictionary of parameter values with the name as the key

  • name – the name of the component

  • freq – the frequencies at which the impedance should be calculated

Returns

numpy array with the complex impedance of the component for the given frequencies

Return type

np.array

class dgpost.transform.circuit_utils.circuit_components.CPE

Bases: dgpost.transform.circuit_utils.circuit_components.Component

defines a constant phase element

static get_symbol()

Unique symbol used to identify the component in the circuit string

The symbol can only contain letters, i.e. a-z, A-Z

static get_parameters(name)

returns the parameter(s) that describe the component

A parameter is a dictionary with the keys: name, bounds and unit. The name of the parameter should be based on the symbol. It can also contain any character except a whitespace. The bounds are given as a tuple with the lower (lb) and upper bounds (ub) like (lb, ub). The unit needs to be recognised by pint

Parameters

name – name of the component in the circuit string, made out of the symbol with an additional digit.

Returns

The parameters that describes the component. A parameter is a dictionary with 3 keys: ‘name’, ‘bounds’ and ‘unit’

Return type

list[dict]

static calc_impedance(param, name, freq)

Calculates the impedance of the component

Parameters
  • param – dictionary of parameter values with the name as the key

  • name – the name of the component

  • freq – the frequencies at which the impedance should be calculated

Returns

numpy array with the complex impedance of the component for the given frequencies

Return type

np.array

class dgpost.transform.circuit_utils.circuit_components.Warburg

Bases: dgpost.transform.circuit_utils.circuit_components.Component

defines a semi-infinite Warburg element

static get_symbol()

Unique symbol used to identify the component in the circuit string

The symbol can only contain letters, i.e. a-z, A-Z

static get_parameters(name)

returns the parameter(s) that describe the component

A parameter is a dictionary with the keys: name, bounds and unit. The name of the parameter should be based on the symbol. It can also contain any character except a whitespace. The bounds are given as a tuple with the lower (lb) and upper bounds (ub) like (lb, ub). The unit needs to be recognised by pint

Parameters

name – name of the component in the circuit string, made out of the symbol with an additional digit.

Returns

The parameters that describes the component. A parameter is a dictionary with 3 keys: ‘name’, ‘bounds’ and ‘unit’

Return type

list[dict]

static calc_impedance(param, name, freq)

Calculates the impedance of the component

Parameters
  • param – dictionary of parameter values with the name as the key

  • name – the name of the component

  • freq – the frequencies at which the impedance should be calculated

Returns

numpy array with the complex impedance of the component for the given frequencies

Return type

np.array

class dgpost.transform.circuit_utils.circuit_components.WarburgOpen

Bases: dgpost.transform.circuit_utils.circuit_components.Component

defines a finite-space Warburg element

static get_symbol()

Unique symbol used to identify the component in the circuit string

The symbol can only contain letters, i.e. a-z, A-Z

static get_parameters(name)

returns the parameter(s) that describe the component

A parameter is a dictionary with the keys: name, bounds and unit. The name of the parameter should be based on the symbol. It can also contain any character except a whitespace. The bounds are given as a tuple with the lower (lb) and upper bounds (ub) like (lb, ub). The unit needs to be recognised by pint

Parameters

name – name of the component in the circuit string, made out of the symbol with an additional digit.

Returns

The parameters that describes the component. A parameter is a dictionary with 3 keys: ‘name’, ‘bounds’ and ‘unit’

Return type

list[dict]

static calc_impedance(param, name, freq)

Calculates the impedance of the component

Parameters
  • param – dictionary of parameter values with the name as the key

  • name – the name of the component

  • freq – the frequencies at which the impedance should be calculated

Returns

numpy array with the complex impedance of the component for the given frequencies

Return type

np.array

class dgpost.transform.circuit_utils.circuit_components.WarburgShort

Bases: dgpost.transform.circuit_utils.circuit_components.Component

defines a finite-length Warburg element

static get_symbol()

Unique symbol used to identify the component in the circuit string

The symbol can only contain letters, i.e. a-z, A-Z

static get_parameters(name)

returns the parameter(s) that describe the component

A parameter is a dictionary with the keys: name, bounds and unit. The name of the parameter should be based on the symbol. It can also contain any character except a whitespace. The bounds are given as a tuple with the lower (lb) and upper bounds (ub) like (lb, ub). The unit needs to be recognised by pint

Parameters

name – name of the component in the circuit string, made out of the symbol with an additional digit.

Returns

The parameters that describes the component. A parameter is a dictionary with 3 keys: ‘name’, ‘bounds’ and ‘unit’

Return type

list[dict]

static calc_impedance(param, name, freq)

Calculates the impedance of the component

Parameters
  • param – dictionary of parameter values with the name as the key

  • name – the name of the component

  • freq – the frequencies at which the impedance should be calculated

Returns

numpy array with the complex impedance of the component for the given frequencies

Return type

np.array

dgpost.transform.circuit_utils.circuit_parser module

dgpost.transform.circuit_utils.circuit_parser.parse_circuit(circ)

Extended Backus–Naur form (EBNF) parser for a circuit string.

Implements an extended Backus–Naur form (EBNF) to parse a string containing a description of a circuit.

The syntax of the EBNF is given by:
  • circuit = element | element-circuit

  • element = component | parallel

  • parallel = p(circuit {,circuit})

  • component = a circuit component defined in circuit_components

So to put elements in series connect them through ‘-’ Parallel elements are created by p(…,… ,…)

To use a component in the circuit string use its symbol. The symbol can be followed by a digit to differentiate similar components. Already implemented circuit elements are located in dgpost.transform.circuit_utils.circuit_components.py.

From this a function is generated and which evaluates the impedance of the circuit.

Parameters

circ (str) – String describing a circuit

Return type

Tuple[list[dict], Callable[[dict, ndarray], ndarray]]

Returns

  • param_info – list of used parameter. For more information about parameters look in circuit_components

  • calculate

dgpost.transform.circuit_utils.circuit_parser.fit_routine(opt_func, fit_guess, bounds, repeat=1)

Fitting routine which uses scipy least_squares and minimize.

Least_squares is a good fitting method but will get stuck in local minima. For this reason, the Nelder-Mead-Simplex algorithm is used to get out of these local minima. The fitting routine is inspired by Relaxis 3 fitting procedure. More information about it can be found on page 188 of revision 1.25 of Relaxis User Manual. https://www.rhd-instruments.de/download/manuals/relaxis_manual.pdf

Open issue is estimate the errors of the parameters. For further information look: - https://github.com/andsor/notebooks/blob/master/src/nelder-mead.md - https://math.stackexchange.com/questions/2447382/nelder-mead-function-fit-error-estimation-via-surface-fit - https://stats.stackexchange.com/questions/424073/calculate-the-uncertainty-of-a-mle

Parameters
  • opt_func (Callable[[list], float]) – function that gets minimized

  • fit_guess (list[float]) – initial guess for minimization

  • bounds (list[tuple]) – bounds of the fitting parameters

  • repeat (int) – how many times the least squares and minimize step gets repeated

Returns

opt_result – the result of the optimization from the last step of Nelder-Mead.

Return type

scipy.optimize.OptimizeResult