-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathseries_statistics.py
More file actions
133 lines (101 loc) · 4.83 KB
/
Copy pathseries_statistics.py
File metadata and controls
133 lines (101 loc) · 4.83 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from __future__ import division, unicode_literals, print_function # for compatibility with Python 2 and 3
import warnings
import pandas as pd
import numpy as np
import scipy
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button
from scipy.stats import norm
matplotlib.rcParams['text.usetex'] = True
def distribution(x, lim_g, lim_pl, mu, sigma, exponent, coef_g, coef_pl, alpha, k):
if x <= lim_g:
dist = coef_g * gausspdf(x, mu, sigma)
elif x >= lim_pl:
dist = coef_pl * powerlawpdf(x, exponent, k)
else:
dist = coef_pl * x_powerlawpdf(
x, exponent, lim_g, lim_pl, alpha, k
) + coef_g * x_gausspdf(
x, mu, sigma, lim_g, lim_pl, alpha
)
return dist
def gausspdf(x, mu, sigma):
return 2 * norm(mu, sigma).pdf(x)
def x_gausspdf(x, mu, sigma, lim_g, lim_pl, alpha):
return (1 - ((x - lim_g) / (lim_pl - lim_g)) ** alpha) * gausspdf(x, mu, sigma)
def powerlawpdf(x, exponent, k):
return (x - k) ** exponent
def x_powerlawpdf(x, exponent, lim_g, lim_pl, alpha, k):
return ((x - lim_g) / (lim_pl - lim_g)) ** alpha * powerlawpdf(x, exponent, k)
def get_scaling_coef(muh0, sigmah0, exponent, lim_g, lim_pl, alpha, k, coef_g):
g1, g1e = scipy.integrate.quad(gausspdf, 0, lim_g, args=(muh0, sigmah0))
pl1, pl1e = scipy.integrate.quad(powerlawpdf, lim_pl, 1000, args=(exponent, k))
g2, g2e = scipy.integrate.quad(x_gausspdf, lim_g, lim_pl, args=(muh0, sigmah0, lim_g, lim_pl, alpha))
pl2, pl2e = scipy.integrate.quad(x_powerlawpdf, lim_g, lim_pl, args=(exponent, lim_g, lim_pl, alpha, k))
coef_pl = (1 - coef_g * g1 - coef_g * g2) / (pl1 + pl2)
return coef_pl
def series_statistics():
warnings.filterwarnings("ignore")
# path = '..\\Data\\Example3'
path = 'D:\\Microswimmers2D_SBR\\Data\\190808\\ANH_Chlamy_beads_Thickness18pt_60x_C001H001S0001'
# path = 'D:\\Microswimmers2D_SBR\\Data\\190808\\ANH_Chlamy_beads_ThicknessLessThan18pt_60x_C001H001S0001'
# ------------------------------------------------------
############################################################################
""" Figure settings """
fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)
ax.margins(x=0)
plt.ylim([5 * 10 ** (-3), 1 * 10 ** (0)])
plt.xlim([0.6, 4.0])
# plt.xlim([5 * 10 ** (-2), 5 * 10 ** (0)])
plt.title('Absolute reference frame')
plt.xlabel('$\|\Delta x\| / (<\Delta x ^ 2>)^{1/2} = 2.42 = 1.04$')
plt.ylabel('$P(\|\Delta x\|, \Delta t) / P(0, \Delta t)$')
""" Reading data """
###########################################################################
itertime = [2, 4, 8, 16, 40]
iterfactor = [
0.28121261171254236,
0.5130885574168105,
0.9395741289390831,
1.6757245894968638,
3.415859754082798
]
for counter, t in enumerate(itertime):
with open(path + '\\NoBackground_median\\Clear\\Dt{:03d}\\abs_dydx.csv'.format(t)) as csv_file:
# with open(path + '\\NoBackground_median\\cropped\\Bandpass\\phi07\\Dt004\\turning_dydx.csv') as csv_file:
col_data = pd.read_csv(csv_file,
delimiter=',',
dtype={'dx': float, 'dy': float},
usecols=['dx', 'dy']
)
############################################################################
""" Absolute values, to um """
col_data['dx_um'] = col_data['dx'].apply(lambda x: np.abs(x) * 0.425 / 3 * 2)
# col_data.append(colpre_data['dy'].apply(lambda x: np.abs(x) * 0.425 / 3 * 2))
############################################################################
""" Calculate pdf (absolute values) """
x = (np.histogram(col_data['dx_um'], bins=30))[1]
x1 = x[1:]
x2 = x[:-1]
x = (x1 + x2) / 2
xp = x
w = abs(x1 - x2)
px = (np.histogram(col_data['dx_um'], bins=30))[0] / len(col_data['dx_um']) / w[0]
normal = norm(0, 3.4).pdf(xp)/norm(0, 3.4).pdf(0)
xp = xp/iterfactor[counter]
px = px/px[0]
powerlaw = xp[13:] ** (-4) * 2
############################################################################
""" Plot histogram and pdf """
# plt.hist(col_data['dx_um'], 100, density=True, label='Histogram')
# plt.plot(xp, px, label='Prob density')
# plt.semilogy(xp, px, ':', label='Prob density $\Delta_t =$ {:03d} s'.format(t))
plt.loglog(xp, px, 's', markersize=3, label='Prob density $\Delta_t =$ {:03d} s'.format(t))
plt.loglog(xp, normal, 'k:', label='Gaussian distrbution')
plt.loglog(xp[13:], powerlaw, 'k--', label='$ \propto \Delta x ^{- a}$')
plt.legend()
plt.show()
if __name__ == "__main__":
series_statistics()