impedance.py
impedance.py copied to clipboard
[BUG] Impedance must be complex-valued
Describe the bug When I pass real-valued data (integers or floats) into the impedance fitting function (as opposed to complex values) it fails.
To Reproduce Steps to reproduce the behavior:
- Code which generates the error '...'
from impedance.models.circuits import CustomCircuit
import numpy as np
frequencies = np.array([1, 2, 3])
Z = np.array([4, 5, 6.0])
circuit_spec = 'C1'
initial_guess = [40e-12]
circuit = CustomCircuit(circuit=circuit_spec, initial_guess=initial_guess)
circuit.fit(frequencies, Z)
- Full error info
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jordan.e/opt/miniconda3/lib/python3.7/site-packages/impedance/models/circuits/circuits.py", line 109, in fit
f'dtype (currently {impedance.dtype})')
TypeError: impedance array should have a complex dtype (currently int64)
Expected behavior I expect real-valued or integer-valued arrays to be cast into complex-valued arrays for the purpose of impedance-fitting. Sometimes data and circuits will be purely real, and will have an imaginary component of zero.
Additional context Add any other context about the problem here.