-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
85 lines (64 loc) · 2.43 KB
/
plot.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
75
76
77
78
79
80
81
82
83
84
85
from pylab import *
from numpy import *
def load_data(file):
data = open(file, "r") #loads file
data=data.read() #reads file
data=data.split("\n")[0:-2] #turn one giant string into a list of line strings.
return data
def numbers(data,TAI=False):
times=[]
for line in data:
if line[line.find("c")+1]=="2":
# try: times.append( float(line[line.find("t")+1:-1]) /125000000/4096 - float(data[0][data[0].find("t")+1:-1]))
try:
seconds = float(line[line.find("t")+1:line.find("n")])
nanoseconds = float(line[line.find("n")+1:line.find("f")])
fractions = float(line[line.find("f")+1:-1])
startTime = seconds + nanoseconds * 8e-9 + fractions * 8e-9 / 4096
break
except:
# print("error?")
pass
if TAI:
startTime=TAI
'''
line=data[0]
seconds = float(line[line.find("t")+1:line.find("n")])
nanoseconds = float(line[line.find("n")+1:line.find("f")])
fractions = float(line[line.find("f")+1:-1])
startTime = 0#( seconds + nanoseconds * 8e-9 + fractions * 8e-9 / 4096)# - startTime)
'''
# startTime = float(data[0][data[0].find("t")+1:-1]) /125000000/4096
for line in data:
if line[line.find("c")+1]=="2":
# try: times.append( float(line[line.find("t")+1:-1]) /125000000/4096 - float(data[0][data[0].find("t")+1:-1]))
try:
seconds = float(line[line.find("t")+1:line.find("n")])
nanoseconds = float(line[line.find("n")+1:line.find("f")])
fractions = float(line[line.find("f")+1:-1])
times.append( seconds + nanoseconds * 8e-9 + fractions * 8e-9 / 4096 - startTime)
if seconds + nanoseconds * 8e-9 + fractions * 8e-9 / 4096 - startTime > endTime: break
except:
# print("error?")
pass
return times
#define desired time here in UTC
UTC=False
if UTC:
TAI=UTC+37
else:
TAI=False
file = 'timestamps.txt'
data = load_data(file)
data = numbers(data,TAI)
endTime=50
xlim(0,endTime)
binsies = linspace(0,endTime,4000)
hist(data,bins=binsies)
# y=data
# x=linspace(y[0],y[-1],)
# plot(x,y)
xlabel("time [s]")
ylabel("counts")
show()
savefig("Plot.png",dpi=100)