Circuit fitting

deareis.fit_circuit(data, settings, num_procs=0)

Wrapper for the pyimpspec.fit_circuit function.

Fit a circuit to a data set.

Parameters:
  • data (DataSet) – The data set that the circuit will be fitted to.

  • settings (FitSettings) – The settings that determine the circuit and how the fit is performed.

  • num_procs (int, optional) – The maximum number of parallel processes to use when method is CNLSMethod.AUTO and/or weight is Weight.AUTO. A value less than 1 will result in an attempt to automatically figure out a suitable value.

Return type:

FitResult

Classes

class deareis.FitResult(uuid, timestamp, circuit, parameters, frequencies, impedances, residuals, mask, pseudo_chisqr, chisqr, red_chisqr, aic, bic, ndata, nfree, nfev, method, weight, settings)

A class containing the result of a circuit fit.

Parameters:
  • uuid (str) – The universally unique identifier assigned to this result.

  • timestamp (float) – The Unix time (in seconds) for when the test was performed.

  • circuit (Circuit) – The final, fitted circuit.

  • parameters (Dict[str, Dict[str, FittedParameter]]) – The mapping to the mappings of the final, fitted values of the element parameters.

  • frequencies (Frequencies) – The frequencies used to perform the fit.

  • impedances (ComplexImpedances) – The complex impedances of the fitted circuit at each of the frequencies.

  • residuals (ComplexResiduals) – The residuals of the real and imaginary parts of the fit.

  • mask (Dict[int, bool]) – The mask that was applied to the DataSet that the circuit was fitted to.

  • pseudo_chisqr (float) – The calculated \(\chi^2_{ps.}\) (eq. 14 in Boukamp, 1995).

  • chisqr (float) – The \(\chi^2\) calculated for the result.

  • red_chisqr (float) – The reduced \(\chi^2\) calculated for the result.

  • aic (float) – The calculated Akaike information criterion.

  • bic (float) – The calculated Bayesian information criterion.

  • ndata (int) – The number of data points.

  • nfree (int) – The degrees of freedom.

  • nfev (int) – The number of function evaluations.

  • method (CNLSMethod) – The iterative method that produced the result.

  • weight (Weight) – The weight function that produced the result.

  • settings (FitSettings) – The settings that were used to perform the fit.

classmethod from_dict(dictionary, data=None)

Create an instance from a dictionary.

Parameters:
  • dictionary (dict) – The dictionary to turn into a FitResult object.

  • data (Optional[DataSet], optional) – The DataSet object that this result is for.

Return type:

FitResult

get_bode_data(num_per_decade=-1)

Get the data required to plot the results as a Bode plot (Mod(Z) and -Phase(Z) vs f).

Parameters:

num_per_decade (int, optional) – If the value is greater than zero, then logarithmically distributed frequencies will be generated within the range of frequencies in the data set and used to calculate the impedance produced by the fitted circuit.

Return type:

Tuple[Frequencies, Impedancesy, Phases]

get_frequencies(num_per_decade=-1)

Get an array of frequencies within the range of frequencies in the data set.

Parameters:

num_per_decade (int, optional) – If the value is greater than zero, then logarithmically distributed frequencies will be generated within the range of fitted frequencies.

Return type:

Frequencies

get_impedances(num_per_decade=-1)

Get the complex impedances produced by the fitted circuit within the range of frequencies in the data set.

Parameters:

num_per_decade (int, optional) – If the value is greater than zero, then logarithmically distributed frequencies will be generated within the range of fitted frequencies and used to calculate the impedance produced by the fitted circuit.

Return type:

ComplexImpedances

get_label()

Generate a label for the result.

Return type:

str

get_nyquist_data(num_per_decade=-1)

Get the data required to plot the results as a Nyquist plot (-Im(Z) vs Re(Z)).

Parameters:

num_per_decade (int, optional) – If the value is greater than zero, then logarithmically distributed frequencies will be generated within the range of frequencies in the data set and used to calculate the impedance produced by the fitted circuit.

Return type:

Tuple[Impedances, Impedances]

get_residuals_data()

Get the data required to plot the residuals (real and imaginary vs f).

Return type:

Tuple[Frequencies, Residuals, Residuals]

to_dict(session)

Return a dictionary that can be used to recreate an instance.

Parameters:

session (bool) – If False, then a minimal dictionary is generated to reduce file size.

Return type:

dict

to_parameters_dataframe(running=False)

Get a pandas.DataFrame instance containing a table of fitted element parameters.

Parameters:

running (bool, optional) – Whether or not to use running counts as the lower indices of elements.

Return type:

pandas.DataFrame

to_statistics_dataframe()

Get the statistics related to the fit as a pandas.DataFrame object.

Return type:

DataFrame

class deareis.FitSettings(cdc, method, weight, max_nfev)

A class to store the settings used to perform a circuit fit.

Parameters:
  • cdc (str) – The circuit description code (CDC) for the circuit to fit.

  • method (CNLSMethod) – The iterative method to use when performing the fit.

  • weight (Weight) – The weight function to use when performing the fit.

  • max_nfev (int) – The maximum number of function evaluations to use when performing the fit.

classmethod from_dict(dictionary)

Create an instance from a dictionary.

Parameters:

dictionary (dict) – The dictionary to turn into a FitSettings object.

Return type:

FitSettings

to_dict()

Return a dictionary that can be used to recreate an instance.

Return type:

dict

Enums

class deareis.CNLSMethod(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Iterative methods used during complex non-linear least-squares fitting:

  • AUTO: try each method

  • BFGS

  • CG

  • LBFGSB

  • LEASTSQ

  • LEAST_SQUARES

  • NELDER

  • POWELL

  • SLSQP

  • TNC

class deareis.Weight(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Types of weights to use during complex non-linear least squares fitting:

  • AUTO: try each weight

  • BOUKAMP: \(1 / ({\rm Re}(Z)^2 + {\rm Im}(Z)^2)\) (eq. 13, Boukamp, 1995)

  • MODULUS: \(1 / |Z|\)

  • PROPORTIONAL: \(1 / {\rm Re}(Z)^2, 1 / {\rm Im}(Z)^2\)

  • UNITY: 1