Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameters property function to BaseCircuit class #303

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions impedance/models/circuits/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ def load(self, filepath, fitted_as_initial=False):
self.parameters_ = np.array(json_data["Parameters"])
self.conf_ = np.array(json_data["Confidence"])

@property
def parameters(self):
"""Returns the model parameters."""
return self.parameters_


class Randles(BaseCircuit):
""" A Randles circuit model class """
Expand Down
6 changes: 6 additions & 0 deletions impedance/tests/test_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_BaseCircuit():
# check initial_guess is loaded in correctly
base_circuit = BaseCircuit(initial_guess)
assert base_circuit.initial_guess == initial_guess
assert base_circuit.parameters is None

# improper input_guess types raise an TypeError
with pytest.raises(TypeError):
Expand Down Expand Up @@ -69,6 +70,7 @@ def test_Randles():
np.array([1.86235717e-02, 1.16804085e-02,
6.27121224e-02, 2.21232935e+02,
1.17171440e+00]), decimal=2)
np.testing.assert_array_equal(randles.parameters, randles.parameters_)

# compare with known impedance predictions
assert np.isclose(randles.predict(np.array([10.0])),
Expand Down Expand Up @@ -193,6 +195,10 @@ def test_CustomCircuit():
circuit=custom_string)
custom_circuit.fit([1, 2, 3], [4, 4, 4])
assert custom_circuit.parameters_[0] == 4
np.testing.assert_array_equal(
custom_circuit.parameters,
custom_circuit.parameters_
)

# space in circuit string
circuit = circuit = 'R0-p(R1, C1)'
Expand Down
Loading