Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ impedance.py requires:
- Matplotlib (>=3.5)
- Altair (>=3.0)
- Pandas
- pygad>=3.6.0
- pyswarms>=1.3

Several example notebooks are provided in the `docs/source/examples/` directory. Opening these will require Jupyter notebook or Jupyter lab.

Expand Down
351 changes: 305 additions & 46 deletions docs/source/examples/fitting_example.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/source/validation.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Validation
==========

Interpreting EIS data fundamentally relies on the the system conforming to
Interpreting EIS data fundamentally relies on the system conforming to
conditions of causality, linearity, and stability. For an example of how
the adherence to the Kramers-Kronig relations, see the `Validation Example Jupyter Notebook
<examples/validation_example.ipynb>`_
Expand Down
16 changes: 5 additions & 11 deletions impedance/models/circuits/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,14 @@ def predict(self, frequencies, use_initial=False):
Predicted impedance at each frequency
"""
frequencies = np.array(frequencies, dtype=float)

buildCircuit_text=buildCircuit(self.circuit, constants=self.constants,
eval_string='', index=0)[0]
builtCircuit = eval('lambda frequencies,parameters : ' + buildCircuit_text, circuit_elements)
if self._is_fit() and not use_initial:
return eval(buildCircuit(self.circuit, frequencies,
*self.parameters_,
constants=self.constants, eval_string='',
index=0)[0],
circuit_elements)
return builtCircuit(frequencies,self.parameters_)
else:
warnings.warn("Simulating circuit based on initial parameters")
return eval(buildCircuit(self.circuit, frequencies,
*self.initial_guess,
constants=self.constants, eval_string='',
index=0)[0],
circuit_elements)
return builtCircuit(frequencies,self.initial_guess)

def get_param_names(self):
""" Converts circuit string to names and units """
Expand Down
56 changes: 42 additions & 14 deletions impedance/models/circuits/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@ def Wo(p, f):
"""
omega = 2 * np.pi * np.array(f)
Z0, tau = p[0], p[1]
Z = Z0 / (np.sqrt(1j * omega * tau) * np.tanh(np.sqrt(1j * omega * tau)))

arg = np.sqrt(1j * omega * tau)
tanh = np.ones_like(arg, dtype=complex)
tanh[arg.real <= -100] = -1.0
mask = np.abs(arg.real) < 100
tanh[mask] = np.tanh(arg[mask])

Z = Z0 / (arg * tanh)
return Z # Zw(omega)


Expand All @@ -186,7 +193,14 @@ def Ws(p, f):
"""
omega = 2 * np.pi * np.array(f)
Z0, tau = p[0], p[1]
Z = Z0 * np.tanh(np.sqrt(1j * omega * tau)) / np.sqrt(1j * omega * tau)

arg = np.sqrt(1j * omega * tau)
tanh = np.ones_like(arg, dtype=complex)
tanh[arg.real <= -100] = -1.0
mask = np.abs(arg.real) < 100
tanh[mask] = np.tanh(arg[mask])

Z = Z0 * tanh / arg
return Z


Expand Down Expand Up @@ -288,10 +302,14 @@ def Gs(p, f):
"""
omega = 2 * np.pi * np.array(f)
R_G, t_G, phi = p[0], p[1], p[2]
Z = R_G / (
np.sqrt(1 + 1j * omega * t_G)
* np.tanh(phi * np.sqrt(1 + 1j * omega * t_G))
)

arg = phi * np.sqrt(1 + 1j * omega * t_G)
tanh = np.ones_like(arg, dtype=complex)
tanh[arg.real <= -100] = -1.0
mask = np.abs(arg.real) < 100
tanh[mask] = np.tanh(arg[mask])

Z = R_G / (np.sqrt(1 + 1j * omega * t_G) * tanh)
return Z


Expand Down Expand Up @@ -350,7 +368,14 @@ def TLMQ(p, f):
omega = 2 * np.pi * np.array(f)
Rion, Qs, gamma = p[0], p[1], p[2]
Zs = 1 / (Qs * (1j * omega) ** gamma)
Z = np.sqrt(Rion * Zs) / np.tanh(np.sqrt(Rion / Zs))

arg = np.sqrt(Rion / Zs)
tanh = np.ones_like(arg, dtype=complex)
tanh[arg.real <= -100] = -1.0
mask = np.abs(arg.real) < 100
tanh[mask] = np.tanh(arg[mask])

Z = np.sqrt(Rion * Zs) / tanh
return Z


Expand Down Expand Up @@ -388,14 +413,17 @@ def T(p, f):
A, B, a, b = p[0], p[1], p[2], p[3]
beta = (a + 1j * omega * b) ** (1 / 2)

sinh = []
for x in beta:
if x < 100:
sinh.append(np.sinh(x))
else:
sinh.append(1e10)
mask = np.abs(beta.real) < 100

sinh = np.ones_like(beta, dtype=complex) * 1e10
sinh[beta.real <= -100] = -1e10
sinh[mask] = np.sinh(beta[mask])

tanh = np.ones_like(beta, dtype=complex)
tanh[beta.real <= -100] = -1.0
tanh[mask] = np.tanh(beta[mask])

Z = A / (beta * np.tanh(beta)) + B / (beta * np.array(sinh))
Z = A / (beta * tanh) + B / (beta * sinh)
return Z


Expand Down
Loading