예제 #1
0
def postprocessRC():

    f = np.logspace(1, 8)
    omega = 2. * np.pi * f
    R = 1000.
    C = 1e-6

    data = OrderedDict()
    data['f'] = f

    samples = 50

    model = "parallel(R, C)"
    m = get_equivalent_circuit_model(model)
    for i in range(samples):
        Ri = 0.05 * R * np.random.randn() + R
        Ci = 0.05 * C * np.random.randn() + C

        Z = m.eval(omega=omega, R=Ri, C=Ci)
        Z += np.random.randn(Z.size)

        data['real' + str(i)] = Z.real
        data['imag' + str(i)] = Z.imag
    pd.DataFrame(data=data).to_csv('test.csv', index=False)

    fitter = Fitter('CSV', LogLevel='WARNING')
    parameters = {'R': {'value': R}, 'C': {'value': C}}
    fitter.run(model, parameters=parameters)
    os.remove('test.csv')
    return PostProcess(fitter.fit_data)
예제 #2
0
def fitter2():
    f = np.logspace(1, 8)
    omega = 2. * np.pi * f

    data = OrderedDict()
    data['f'] = f

    samples = 5

    m = get_equivalent_circuit_model(model2)
    for i in range(samples):
        km1 = 0.05 * km * np.random.randn() + km
        em1 = 0.05 * em * np.random.randn() + em

        Z = m.eval(omega=omega,
                   Rc=Rc,
                   dm=dm,
                   km=km1,
                   em=em1,
                   ecp=ecp,
                   kcp=kcp,
                   kmed=kmed,
                   emed=emed,
                   p=p,
                   c0=c0,
                   k=k,
                   alpha=alpha)
        Z += np.random.randn(Z.size)

        data['real' + str(i)] = Z.real
        data['imag' + str(i)] = Z.imag
    pd.DataFrame(data=data).to_csv('test.csv', index=False)

    fitter = Fitter('CSV', LogLevel='WARNING')
    os.remove('test.csv')
    return fitter
예제 #3
0
def fitter():
    f = np.logspace(1, 8)
    omega = 2. * np.pi * f

    data = OrderedDict()
    data['f'] = f

    samples = 5

    m = get_equivalent_circuit_model(model)
    for i in range(samples):
        Ri = 0.05 * R * np.random.randn() + R
        Ci = 0.05 * C * np.random.randn() + C

        Z = m.eval(omega=omega, R=Ri, C=Ci)
        Z += np.random.randn(Z.size)

        data['real' + str(i)] = Z.real
        data['imag' + str(i)] = Z.imag
    pd.DataFrame(data=data).to_csv('test.csv', index=False)

    fitter = Fitter('CSV', LogLevel='WARNING')
    os.remove('test.csv')
    return fitter
예제 #4
0
#    along with this program.  If not, see <https://www.gnu.org/licenses/>.

import impedancefitter
import numpy

# parameters
frequencies = numpy.logspace(0, 8)
Rct = 100.
Rs = 20.
Aw = 300.
C0 = 25e-6


# generate model by user-defined circuit
model = 'R_s + parallel(R_ct + W, C)'
lmfit_model = impedancefitter.get_equivalent_circuit_model(model)
Z = lmfit_model.eval(omega=2. * numpy.pi * frequencies,
                     ct_R=Rct, s_R=Rs,
                     C=C0, Aw=Aw)
impedancefitter.plot_impedance(2. * numpy.pi * frequencies, Z)

# use pre-implemented circuit
model = 'Randles'
lmfit_model = impedancefitter.get_equivalent_circuit_model(model)
Z2 = lmfit_model.eval(omega=2. * numpy.pi * frequencies,
                      Rct=Rct, Rs=Rs,
                      C0=C0, Aw=Aw)

# check that both are equal
if numpy.all(numpy.isclose(Z, Z2)):
    print("Both formulations are equal.")
예제 #5
0
def test_randles_CPE_model():
    Z = Z_randles_CPE(omega, Rct, Rs, Aw, k, alpha)
    m = get_equivalent_circuit_model(model2)
    Z_m = m.eval(omega=omega, ct_R=Rct, s_R=Rs, k=k, alpha=alpha, Aw=Aw)
    assert np.all(np.isclose(Z, Z_m))
예제 #6
0
def test_randles_model():
    Z = Z_randles(omega, Rct, Rs, Aw, C0)
    m = get_equivalent_circuit_model(model1)
    Z_m = m.eval(omega=omega, ct_R=Rct, s_R=Rs, C=C0, Aw=Aw)
    assert np.all(np.isclose(Z, Z_m))
예제 #7
0
def test_in_model():
    model = "R + L"
    m = get_equivalent_circuit_model(model)
    Z = Z_in(omega, L, R)
    Z_m = m.eval(omega=omega, L=L * 1e-9, R=R)
    assert np.all(np.isclose(Z, Z_m))
예제 #8
0
def test_loss_model():
    model = "parallel(R, parallel(L, C))"
    m = get_equivalent_circuit_model(model)
    Z = Z_loss(omega, L, C, R)
    Z_m = m.eval(omega=omega, L=L * 1e-9, R=R, C=C * 1e-12)
    assert np.all(np.isclose(Z, Z_m))
예제 #9
0
rcParams['figure.figsize'] = [20, 10]

# parameters
f = np.logspace(1, 8)
omega = 2. * np.pi * f
R = 1000.
C = 1e-6

data = OrderedDict()
data['f'] = f

samples = 1000

model = "parallel(R, C)"
m = get_equivalent_circuit_model(model)
# generate random samples
for i in range(samples):
    Ri = 0.05 * R * np.random.randn() + R
    Ci = 0.05 * C * np.random.randn() + C

    Z = m.eval(omega=omega, R=Ri, C=Ci)
    # add some noise
    Z += np.random.randn(Z.size)

    data['real' + str(i)] = Z.real
    data['imag' + str(i)] = Z.imag

# save data to file
pd.DataFrame(data=data).to_csv('test.csv', index=False)