-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot-coherence-signal.py
executable file
·119 lines (91 loc) · 3.03 KB
/
plot-coherence-signal.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
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
#!/usr/bin/env python
import sys, matplotlib
import numpy as np
import matplotlib.pyplot as plt
if len(sys.argv) not in [2,3,4]:
print("useage: %s file [show] [azimuths]" % sys.argv[0])
exit(1)
fname = sys.argv[1]
show = "show" in sys.argv
show_azimuths = "azimuths" in sys.argv
# return number of valid floats in a line of text
def nums_in(line):
n = 0
for l in line.split():
try:
float(l.strip())
n += 1
except: None
return n
def figname(targets):
suffix = "-{}".format("-".join(targets))
if show_azimuths: suffix += "-azimuths"
return fname.replace(".txt",suffix+".png")
def line_plot(targets,k_DD,f_DD,coherence):
plot = plt.plot(f_DD,coherence,"k-",linewidth=2)
plt.xlim(0,f_DD[-1])
plt.ylim(-1,1)
plt.xlabel("$f_{}$".format(k_DD))
plt.ylabel("Coherence")
plt.tight_layout()
plt.savefig(figname(targets))
if show: plt.show()
def mod(x,m=1):
while x < 0: x += m
while x >= m: x -= m
return x
def color_plot(targets,k_DD,f_DD,coherence,azimuths):
f_DD_boundaries = ( f_DD - (f_DD[1]-f_DD[0])/2 )
d_phi = 1/coherence.shape[1]
angles_over_pi = np.arange(0,1+d_phi,1/coherence.shape[1])
plt.pcolor(angles_over_pi,f_DD_boundaries,coherence)
if show_azimuths:
for azimuth in azimuths:
plt.axvline(mod(azimuth),color="k",linewidth=2)
plt.xlim(0,1)
plt.ylim(0,f_DD_boundaries[-1])
plt.clim(-1,1)
plt.xlabel(r"$\phi_{DD}/\pi$")
plt.ylabel("$f_{}$".format(k_DD))
cbar = plt.colorbar()
cbar.set_label("Coherence")
plt.tight_layout()
plt.savefig(figname(targets))
if show: plt.show()
def make_plot(targets,k_DD,f_DD,coherence,azimuths,time):
if coherence.shape[0] == 0: return None
plt.figure()
plt.title("$t={}$ ms".format(round(time)))
if coherence.shape[1] == 1:
line_plot(targets,k_DD,f_DD,coherence)
else:
color_plot(targets,k_DD,f_DD,coherence,azimuths)
reading_data = False
with open(fname,"r") as f:
for line in f:
if "Coherence signal results" in line:
reading_data = True
continue
if reading_data:
if "#" in line:
if "k_DD" in line:
k_DD = int(line.split()[-1])
continue
if "azimuths" in line:
azimuths = [ float(a) for a in line.split()[2:]]
continue
if "measurement_time" in line:
time = float(line.split()[-1])
if "targets" in line:
try: make_plot(targets,k_DD,f_DD,coherence,azimuths,time)
except: None
targets = line.split()[2:]
f_DD = []
coherence = []
else:
f_DD.append(float(line.split()[0]))
coherence.append([ float(n) for n in line.split()[1:]])
f_DD = np.array(f_DD)
coherence = np.array(coherence)
make_plot(targets,k_DD,f_DD,coherence,azimuths,time)
plt.show()