-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathderivative.py
More file actions
executable file
·51 lines (34 loc) · 1.09 KB
/
Copy pathderivative.py
File metadata and controls
executable file
·51 lines (34 loc) · 1.09 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
import numpy as np
import sys
import matplotlib.pyplot as plt
def main():
for file in filelist:
# load data from histogram.txt file to var data
data = np.loadtxt(file)
xdata = []
ydata = []
der = []
for dp in data[:]:
xdata.append(dp[0])
ydata.append(dp[1])
# store the derivative
for i in range(len(ydata)-1):
der[i] = ydata[i+1]-ydata[i]
# plot the derivative
plt.plot(xdata[1:], der, label="Derivative")
# find the intersection of derivative and x axis
roots = []
for i in range(len(der)-1):
if der[i] * der[i+1] < 0:
roots.append(i)
thres = 0
for i in range(200):
if sum(ydata[i:i+3]) <= sum(ydata[i+1:i+4]) >= sum(ydata[i+2:i+5]):
thres = i + 2
break
with open("%s"%(file[:-4]+"_thres.txt"), "w") as myfile:
myfile.write("%d"%thres)
if __name__ == "__main__":
fit_num = int(sys.argv[1])
filelist = sys.argv[2:]
main()