forked from katemartian/Photometry_data_processing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualize.py
executable file
·74 lines (63 loc) · 2.4 KB
/
visualize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from photometry_functions import *
from sklearn.linear_model import Lasso
data = pd.read_csv('/Users/xiaocao/Downloads/Python/Photometry_data_processing-master/example.csv')
data = data[100:]
exc_signal = data['MeanInt_470nm']
t_exc = data['Time_470nm']
ref_signal = data['MeanInt_410nm']
t_ref = data['Time_410nm']
# smooth signal
exc_signal_s = smooth_signal(exc_signal)
ref_signal_s = smooth_signal(ref_signal)
# airPLS
exc_signal_base = airPLS(exc_signal_s,50000,1,15)
ref_signal_base = airPLS(ref_signal_s,50000,1,15)
exc_subtracted = exc_signal_s - exc_signal_base
ref_subtracted = ref_signal_s - ref_signal_base
# normalize
exc_norm = (exc_subtracted - np.median(exc_subtracted))/np.std(exc_subtracted)
ref_norm = (ref_subtracted - np.median(ref_subtracted))/np.std(ref_subtracted)
# regression
lin = Lasso(alpha=0.0001,precompute=True,max_iter=1000, positive=True, random_state=9999, selection='random')
lin.fit(ref_norm.reshape(len(ref_norm),1),exc_norm.reshape(len(ref_norm),1))
ref_reg = lin.predict(ref_norm.reshape(len(ref_norm),1)).reshape(len(ref_norm),)
dff = exc_norm - ref_reg
plt.subplot(2,1,1)
plt.plot(t_exc,exc_signal,label='Raw')
plt.plot(t_exc,exc_signal_s,label='Smooth')
plt.plot(t_exc,exc_signal_base,label='Base')
plt.title('Smooth and Baseline')
plt.subplot(2,1,2)
plt.plot(t_ref,ref_signal,label='Raw')
plt.plot(t_ref,ref_signal_s,label='Smooth')
plt.plot(t_ref,ref_signal_base,label='Base')
plt.xlabel('Time (s)')
plt.ylabel('Fluorescence intensity (au)')
plt.legend()
plt.savefig('/Users/xiaocao/Downloads/Python/Photometry_data_processing-master/fig_1.png',dpi=300)
plt.figure()
plt.subplot(2,1,1)
plt.plot(t_exc,exc_subtracted,label='Corrected')
plt.legend()
plt.subplot(2,1,2)
plt.plot(t_ref,ref_subtracted,label='Corrected')
plt.legend()
plt.savefig('/Users/xiaocao/Downloads/Python/Photometry_data_processing-master/fig_2.png',dpi=300)
plt.figure()
plt.subplot(2,1,1)
plt.plot(t_exc,exc_norm,label='Normalized')
plt.legend()
plt.subplot(2,1,2)
plt.plot(t_ref,ref_norm,label='Normalized')
plt.legend()
plt.savefig('/Users/xiaocao/Downloads/Python/Photometry_data_processing-master/fig_3.png',dpi=300)
plt.figure()
plt.subplot(2,1,1)
plt.scatter(ref_norm,exc_norm,s=4)
plt.plot(ref_norm,ref_reg,c='r')
plt.subplot(2,1,2)
plt.plot(t_ref,dff)
plt.savefig('/Users/xiaocao/Downloads/Python/Photometry_data_processing-master/fig_4.png',dpi=300)