Skip to content
Snippets Groups Projects
Commit dffadc25 authored by Andrey Aristov's avatar Andrey Aristov
Browse files

get belaching rate from curve tails

parent d3602880
Branches
Tags
1 merge request!5fix testing and stuff
%% Cell type:code id: tags:
``` python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
```
%% Cell type:code id: tags:
``` python
intensities = pd.read_csv('/home/aaristov/Multicell/SGR/20200807-CIPRO-7ngml-rep1/intensities.csv')
```
%% Cell type:code id: tags:
``` python
intensities = pd.read_csv('/home/aaristov/Multicell/SGR/20200811-CIPRO-7ngml-rep2/intensities.csv')
```
%% Cell type:code id: tags:
``` python
curve = intensities.query('label == 42')[intensities.dye == 'GFP']
```
%% Output
<ipython-input-284-c23a68d30c38>:1: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
curve = intensities.query('label == 42')[intensities.dye == 'GFP']
%% Cell type:code id: tags:
``` python
plt.semilogy(c := curve.mean_intensity.values - curve.mean_intensity.values.min())
plt.semilogy(c * bleach_fun(np.arange(len(curve)), -.03))
```
%% Output
[<matplotlib.lines.Line2D at 0x7f08da2275b0>]
%% Cell type:code id: tags:
``` python
plt.plot(c)
plt.plot(c * bleach_fun(np.arange(len(curve)), -.03))
```
%% Output
[<matplotlib.lines.Line2D at 0x7f08dd6558e0>]
%% Cell type:code id: tags:
``` python
def plot_decay(label, intensities=intensities, dye='GFP', min_intensity=10, plot=False):
intensitites = intensities.copy()
curve = intensities.query(f'label == {label}')[intensities.dye == dye]
decay = curve[curve.mean_intensity.argmax():]
peak = decay.mean_intensity.values.max()
if peak < min_intensity:
return
else:
decay['normalized_intensity'] = decay.mean_intensity / peak
if plot:
decay.plot(x='time', y='mean_intensity')
decay.plot(x='time', y='normalized_intensity')
return decay
```
%% Cell type:code id: tags:
``` python
decays_list = list(filter(lambda x: x is not None, list(map(plot_decay, intensities.label.unique()[:]))))
```
%% Output
<ipython-input-185-2d3e970450fc>:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
curve = intensities.query(f'label == {label}')[intensities.dye == dye]
<ipython-input-185-2d3e970450fc>:9: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
decay['normalized_intensity'] = decay.mean_intensity / peak
%% Cell type:code id: tags:
``` python
decays_df = pd.concat(decays_list)
```
%% Cell type:code id: tags:
``` python
[plt.plot('time', 'normalized_intensity', data = df) for df in decays_list[:50]]
plt.show()
```
%% Output
%% Cell type:code id: tags:
``` python
def bleach_fun(x, rate):
return np.exp(- x * rate)
```
%% Cell type:code id: tags:
``` python
def err_fun(rate, df_list = decays_list):
errs = np.mean(list(map(lambda df: np.mean((df.normalized_intensity.values - bleach_fun(np.arange(len(df)), rate)) ** 2), df_list)))
return errs
```
%% Cell type:code id: tags:
``` python
from scipy.optimize import minimize
```
%% Cell type:code id: tags:
``` python
res = minimize(err_fun, (-1.,))
```
%% Cell type:code id: tags:
``` python
res.x
```
%% Output
array([0.02999389])
%% Cell type:code id: tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment