<commit_before>
import hobo
import hobo.electrochemistry
import hobo.electrochemistry.data
import hobo.electrochemistry.models

import pylab as plt
import numpy as np
from math import sqrt

def test_ec_model():
    time,current = hobo.electrochemistry.data.read_cvsin_type_1('../../GC01_FeIII-1mM_1M-KCl_02_009Hz.txt')
    assert time[0] == 0
    assert current[0] == 2.464073e-05

    dim_params = {
        'reversed': True,
        'Estart': 0.5,
        'Ereverse': -0.1,
        'omega': 9.0152,
        'phase': 0,
        'dE': 0.08,
        'v': -0.08941,
        't_0': 0.001,
        'T': 297.0,
        'a': 0.07,
        'c_inf': 1*1e-3*1e-3,
        'D': 7.2e-6,
        'Ru': 8.0,
        'Cdl': 20.0*1e-6,
        'E0': 0.214,
        'k0': 0.0101,
        'alpha': 0.53
        }

    model = hobo.electrochemistry.models.ECModel(dim_params)

    #non dimensionalise data
    time = time/model.T0
    current = -current/model.I0

    # calculate model at time points given by the data file
    I,t = model.simulate(use_times=time)

    assert 0.1 > sqrt(np.sum(np.power(I-current,2))/np.sum(np.power(current,2)))


<commit_msg>#6: EC model returns a stan model, using an explicit solver<commit_after>
import hobo
import hobo.electrochemistry
import hobo.electrochemistry.data
import hobo.electrochemistry.models

import pylab as plt
import numpy as np
from math import sqrt
import pystan

def test_ec_model():
    time,current = hobo.electrochemistry.data.read_cvsin_type_1('../../GC01_FeIII-1mM_1M-KCl_02_009Hz.txt')
    assert time[0] == 0
    assert current[0] == 2.464073e-05

    dim_params = {
        'reversed': True,
        'Estart': 0.5,
        'Ereverse': -0.1,
        'omega': 9.0152,
        'phase': 0,
        'dE': 0.08,
        'v': -0.08941,
        't_0': 0.001,
        'T': 297.0,
        'a': 0.07,
        'c_inf': 1*1e-3*1e-3,
        'D': 7.2e-6,
        'Ru': 8.0,
        'Cdl': 20.0*1e-6,
        'E0': 0.214,
        'k0': 0.0101,
        'alpha': 0.53
        }

    model = hobo.electrochemistry.models.ECModel(dim_params)

    #non dimensionalise data
    time = time/model.T0
    current = -current/model.I0

    # calculate model at time points given by the data file
    I,t = model.simulate(use_times=time)

    # calculate model using stan
    # sm = model.get_stan_model()

    # combined_params = dict(T=len(time),ts=time)
    # combined_params.update(model.nondim_params)
    # op = sm.sampling(data=combined_params, chains=1, iter=1, warmup=0,algorithm='Fixed_param')

    # stan_current = op.extract('Itot')

    # f = plt.figure()
    # plt.plot(time,current,label='exp')
    # plt.plot(t,I,label='cpp')
    # plt.show()
    # plt.plot(time,stan_current,label='stan')

    assert 0.1 > sqrt(np.sum(np.power(I-current,2))/np.sum(np.power(current,2)))



{'fraction_non_alphanumeric': 0.15209665955934612, 'fraction_numerical': 0.06396588486140725, 'mean_word_length': 2.445532435740514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3985644', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1072, 'n_words': 214}