Location: BG_HaiMurphy @ a67177c16af1 / parameter_finder / k1k6_fitting / k1k6_fitting.py

Author:
Shelley Fong <sfon036@UoA.auckland.ac.nz>
Date:
2022-05-20 10:22:46+12:00
Desc:
Adding exposure files
Permanent Source URI:
https://models.cellml.org/workspace/818/rawfile/a67177c16af102ea8ec4d69929c771407a9803c7/parameter_finder/k1k6_fitting/k1k6_fitting.py

# Fit a curve to time-varying k1/k6 parameters for the Hai Murphy smooth muscle contraction model

import numpy as np
import matplotlib.pyplot as plt
import scipy.optimize

def monoExp(t, m, q):
    return m * np.exp(-q * t)

time = np.linspace(0,60,2000)

k1_OG = [0.55*1 if t < 5 else 0.3 for t in time]

p0 = (1, 1) # start with values near those we expect
params, cv = scipy.optimize.curve_fit(monoExp, time, k1_OG, p0, maxfev=2000, ftol=1e-4) # (function, xdata, ydata, p_IC)
m, q = params
k_opt = monoExp(time, m, q)
print(f"kfit = {m} * e^({q} * t)")

# manual plots
k_test = monoExp(time, 1.66, 0.09995)

plt.figure
plt.plot(time, k1_OG)
plt.plot(time, k_opt)
plt.plot(time, k_test)
plt.legend(['original','fit','manual test against upper = 0.55*3'])
plt.show()