From e00197f0aed70c01ba345c3c3c37b90edaccb63d Mon Sep 17 00:00:00 2001 From: vyrjana <41105805+vyrjana@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:48:18 +0200 Subject: [PATCH] Updated m(RQ)-fit method implementation --- CHANGELOG.md | 1 + src/pyimpspec/analysis/drt/mrq_fit.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b37ac7..12d502f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - Updated the `fit_circuit` function to ignore `RuntimeWarning`s during fitting. - Updated the `Warburg` element class to include an `n` exponent (fixed at 0.5 by default). - Updated the `plot_gamma` function to include a horizontal line marking zero on the y-axis. +- Updated the automatic adjustment of initial values of circuit parameters to be bypassed when a non-default value is detected in a `Circuit` that is provided to the m(RQ)-fit method without a corresponding `FitResult`. - Fixed a bug that caused methods such as `DRTResult.get_peaks` to miss peaks at the time constant extremes. - Fixed a bug that caused an element's parameters in `FitResult.to_parameters_dataframe` to not be in a sorted order. - Fixed the previously unimplemented `FitResult.get_parameters` method. diff --git a/src/pyimpspec/analysis/drt/mrq_fit.py b/src/pyimpspec/analysis/drt/mrq_fit.py index aa88d91..36e1439 100644 --- a/src/pyimpspec/analysis/drt/mrq_fit.py +++ b/src/pyimpspec/analysis/drt/mrq_fit.py @@ -334,6 +334,16 @@ def _validate_circuit(circuit: Circuit): def _adjust_initial_values(circuit: Circuit, data: DataSet) -> Circuit: + element: Union[Element, Connection] + for element in circuit.get_elements(recursive=True): + defaults: Dict[str, float] = element.get_default_values() + + key: str + value: float + for key, value in element.get_values().items(): + if not isclose(value, defaults[key]): + return circuit + f: Frequencies = data.get_frequencies() Z_exp: ComplexImpedances = data.get_impedances() @@ -342,7 +352,6 @@ def _adjust_initial_values(circuit: Circuit, data: DataSet) -> Circuit: if not isinstance(series, Series): raise TypeError(f"Expected a Series instead of {series=}") - element: Union[Element, Connection] for element in series: if isinstance(element, Resistor): if not element.is_fixed("R"):