forked from LCAV/TimeDomainAcousticRakeReceiver
/
figure_Experiment_plot.py
151 lines (115 loc) · 4.06 KB
/
figure_Experiment_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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import numpy as np
import matplotlib.pyplot as plt
import sys
import os
import fnmatch
import pyroomacoustics as pra
max_sources = 7
sim_data_dir = './data/'
beamformer_names = ['Rake Perceptual',
'Rake MVDR',]
bf_dict = dict(zip(beamformer_names,
range(len(beamformer_names))))
NBF = len(beamformer_names)
loops = 0
if len(sys.argv) < 2:
# if no argument is specified, use the datafile for the data used in the paper
files = [sim_data_dir + 'quality_measured_rir_20150429-184503.npz']
else:
files = sys.argv[1:]
# Empty data containers
good_source = np.zeros((3,0))
bad_source = np.zeros((3,0))
ipesq = np.zeros((0,2))
opesq_bf = np.zeros((0,2,NBF,max_sources))
# Read in all the data
for fname in files:
print 'Loading from',fname
a = np.load(fname)
good_source = np.concatenate((good_source, a['good_source']), axis=1)
bad_source = np.concatenate((bad_source, a['bad_source']), axis=1)
ipesq = np.concatenate((ipesq,a['pesq_input'][:,:,0]), axis=0)
opesq_bf = np.concatenate((opesq_bf,a['pesq_bf']), axis=0)
loops = good_source.shape[1]
print 'Number of loops:',loops
print 'Median input Raw MOS',np.median(ipesq[:,0])
print 'Median input MOS LQO',np.median(ipesq[:,1])
def nice_plot(x, ylabel, bf_order=None):
'''
Define a function to plot consistently the data
'''
if bf_order is None:
bf_order = beamformer_names
ax1 = plt.gca()
newmap = plt.get_cmap('gist_heat')
from itertools import cycle
# totally a hack to get the same line styles as Fig6/7
lines = ['-D','-v','->','-s','-o']
linecycler = cycle(lines)
# totally a hack to get the same line styles as Fig6/7
map1 = [newmap( k ) for k in np.linspace(0.25,0.9,5)]
map2 = [map1[3],map1[2],map1[4],map1[0],map1[1]]
ax1.set_color_cycle(map2)
# no clipping of the beautiful markers
plt.setp(ax1,'clip_on',False)
for bf in bf_order:
i = bf_dict[bf]
med, ci = pra.median(x, axis=0)
p, = plt.plot(range(0, max_sources),
#np.median(x[:,i,:], axis=0),
med[i,:],
next(linecycler),
linewidth=1,
markersize=4,
markeredgewidth=.5,
clip_on=False)
# confidence interval for the median
plt.fill_between(range(0, max_sources),
med[i,:]+ci[0,i,:], med[i,:]+ci[1,i,:],
#color='grey',
color=p.get_color(),
linewidth=0.05,
edgecolor='k',
alpha=0.3)
# Hide right and top axes
ax1.spines['top'].set_visible(False)
ax1.spines['right'].set_visible(False)
ax1.spines['bottom'].set_position(('outward', 10))
ax1.spines['left'].set_position(('outward', 15))
ax1.yaxis.set_ticks_position('left')
ax1.xaxis.set_ticks_position('bottom')
# Make ticks nicer
ax1.xaxis.set_tick_params(width=.3, length=3)
ax1.yaxis.set_tick_params(width=.3, length=3)
# Make axis lines thinner
for axis in ['bottom','left']:
ax1.spines[axis].set_linewidth(0.3)
# Set ticks fontsize
plt.xticks(size=9)
plt.yticks(size=9)
# Set labels
plt.xlabel(r'Number of images $K$', fontsize=10)
plt.ylabel(ylabel, fontsize=10)
plt.legend(bf_order, fontsize=7, loc='upper left', frameon=False, labelspacing=0)
# Here we plot the figure used in the paper (Fig. 10)
plt.figure(figsize=(4,3))
nice_plot(opesq_bf[:,0,:,:], 'PESQ [MOS]',
bf_order=['Rake Perceptual','Rake MVDR'])
# plot input SNR
med, ci = pra.median(ipesq[:,0])
o = np.ones(max_sources)
p, = plt.plot(np.arange(max_sources), np.median(ipesq[:,0])*o)
plt.text(5.0, 1.28, 'Input PESQ', fontsize=7)
'''
# confidence interval for the median
plt.fill_between(range(0, max_sources),
(med+ci[0])*o, (med+ci[1])*o,
#color='grey',
color=p.get_color(),
linewidth=0.05,
edgecolor='k',
alpha=0.3)
'''
plt.tight_layout(pad=0.2)
plt.savefig('figures/pesq_measured_rir.png')
plt.show()