Skip to content
Snippets Groups Projects
Commit 01bc68fd authored by Felix Reichel's avatar Felix Reichel :beers:
Browse files

Add new fit functions to the shape analysis

parent c2784fc6
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import os import os
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import seaborn as sns import seaborn as sns
from scipy.optimize import curve_fit from scipy.optimize import curve_fit
import warnings import warnings
warnings.filterwarnings('ignore') warnings.filterwarnings('ignore')
``` ```
%% Cell type:code id: tags:
``` python
# folder to save all panels for figure 2
# savefolder = r"plots\fig2"
# file containing the data for the controls
results_ctrl_file = r"data\shape_analysis\histograms_HealthyControl_deformed_undeformed.txt"
```
%% Cell type:code id: tags:
``` python
def logistic_growth(x, A, x_0, k):
'''The logistic growth fct'''
return A/(1+np.exp(-k*(x-x_0)))
def logistic_growth_simple(x, x_0, k):
'''A simplified logistic growth fct'''
return 1/(1+np.exp(-k*(x-x_0)))
def hyperbola(x, a):
'''Hyperbolic function with growth rate a and limit 1 with
root at f(0)=0: f(x) = a/(x-a) + 1
'''
return a/(x-a) + 1
def exponential_inverted(x, a):
return 1 - np.exp(-a*x)
```
%% Cell type:code id: tags:
``` python
results_ctrl = np.loadtxt(results_ctrl_file)
v_min = 0.
v_max = 3.
v_ctrl = results_ctrl[:,0]
probs_ctrl = results_ctrl[:,3]
probs_ctrl_err = results_ctrl[:,4]
# fit_bounds=(0, [1, np.inf, np.inf])
ind_vmax = v_ctrl <= v_max
v_ctrl = v_ctrl[ind_vmax]
probs_ctrl = probs_ctrl[ind_vmax]
probs_ctrl_err = probs_ctrl_err[ind_vmax]
popt_ctrl, pcov_ctrl = curve_fit(logistic_growth_simple, v_ctrl, probs_ctrl,
sigma = probs_ctrl_err, absolute_sigma=False,
# bounds = fit_bounds
)
popt_ctrl_exp, pcov_ctrl_exp = curve_fit(exponential_inverted, v_ctrl, probs_ctrl,
sigma = probs_ctrl_err, absolute_sigma=False,
# p0=-15,
# bounds = fit_bounds
)
v_plot = np.linspace(v_min, v_max, 100)
with sns.axes_style("darkgrid"):
plt.figure(0,(5,3.5))
plt.errorbar(v_ctrl, probs_ctrl, probs_ctrl_err, color='k', marker='.', alpha=.5, label='CTRL', lw=2, zorder=1)
plt.plot(v_plot, logistic_growth_simple(v_plot, *popt_ctrl), 'r-', alpha=1, lw=2, zorder=100)
plt.plot(v_plot, exponential_inverted(v_plot, *popt_ctrl_exp), c='C0', alpha=1, lw=2, zorder=100)
plt.axhline(1, c='C0', ls='--', lw=1.5)
plt.vlines(0.5, -0.1, 0.5, ls='--', color='orange', lw=1.5)
plt.xlim(0,3)
plt.ylim(0,1.05)
plt.xlabel("Cell velocity [mm/s]")
plt.ylabel("Probability")
plt.title("Probability for deformed cell", fontsize=12)
plt.legend(loc='lower right')
plt.tight_layout()
# savename = "fig2A_explain_LogGrowth_FitValues"
# savepath = os.path.join(savefolder,savename)
# plt.savefig(savepath+".pdf", dpi=900, format='pdf')
```
%% Output
%% Cell type:code id: tags:
``` python
popt_ctrl_exp
```
%% Output
array([2.03423702])
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment