-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathprofile_ism_order.py
160 lines (137 loc) · 5 KB
/
profile_ism_order.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
151
152
153
154
155
156
157
158
159
160
import click
import time
import pprint
import numpy as np
import pickle
import matplotlib
import matplotlib.pyplot as plt
from utils import compute_room_irs, RoomSimSoftware
font = {"family": "Times New Roman", "weight": "normal", "size": 18}
matplotlib.rc("font", **font)
def plot_results(software, ism_order_vals, proc_time, proc_time_std, n_std):
markers = ["o", "^", "v", "x", ">", "<", "D", "+"]
plt.figure()
for i, _software in enumerate(software):
_proc_time = []
_proc_time_std = []
for ism_order in ism_order_vals:
if _software in proc_time[ism_order].keys():
_proc_time.append(proc_time[ism_order][_software])
_proc_time_std.append(proc_time_std[ism_order][_software])
else:
break
_proc_time = np.array(_proc_time)
_proc_time_std = np.array(_proc_time_std)
plt.plot(
ism_order_vals[: len(_proc_time)],
_proc_time,
label=_software,
marker=markers[i],
)
ax = plt.gca()
ax.fill_between(
ism_order_vals[: len(_proc_time)],
(_proc_time - n_std * _proc_time_std),
(_proc_time + n_std * _proc_time_std),
alpha=0.2,
)
plt.legend(loc="upper left")
plt.xlabel("Specular depth / ISM order")
plt.ylabel("Processing time (s)")
plt.grid()
plt.tight_layout()
ax = plt.gca()
ax.set_xticks(ism_order_vals)
plt.savefig("ism.png")
@click.command()
@click.option("--n_trials", type=int, default=100)
@click.option("--pickle_path", type=str, default=None)
def profile_room_gen(n_trials, pickle_path):
"""
Parameters
----------
n_trials : int
How many trials to average over. Ignored if `pickle_path` is provided.
pickle_path : str
File path to already computed results in order to plot them.
"""
if pickle_path is None:
print(
"\nCOMPARING ROOM SIMULATION SOFTWARE WITH {} TRIALS\n".format(
n_trials
)
)
software = [
RoomSimSoftware.PYGSOUND,
RoomSimSoftware.PYROOMACOUSTICS,
]
n_std = 1
# sweep number of rays
ism_order_vals = [2, 3, 4, 5, 6, 7]
n_rays = int(1e4)
proc_time = dict()
proc_time_std = dict()
for ism_order in ism_order_vals:
print("ISM order : {}".format(ism_order))
proc_time[ism_order] = dict()
proc_time_std[ism_order] = dict()
# loop through software
for _software in software:
ray_tracing_param = None
if _software == RoomSimSoftware.PYGSOUND:
ray_tracing_param = {
"diffuse_count": int(n_rays),
"specular_count": 6 ** ism_order,
"specular_depth": ism_order,
}
elif _software == RoomSimSoftware.PYROOMACOUSTICS:
ray_tracing_param = {"n_rays": int(n_rays)}
assert ray_tracing_param is not None
timing = []
for _ in range(n_trials):
start_time = time.time()
compute_room_irs(
room_dim=[8, 9, 3],
room_properties=0.5, # rt60
scattering=0.5,
ism_order=ism_order
if _software == RoomSimSoftware.PYROOMACOUSTICS
else None,
mic_pos=[0.3, 3, 0.2],
source_pos=[[3.2, 3, 1.8]],
software=_software,
ray_tracing_param=ray_tracing_param,
)
timing.append(time.time() - start_time)
proc_time[ism_order][_software] = np.mean(timing)
proc_time_std[ism_order][_software] = np.std(timing)
print(
"{} : {} seconds".format(
_software, proc_time[ism_order][_software]
)
)
pprint.pprint(proc_time)
pprint.pprint(proc_time_std)
data = {
"proc_time": proc_time,
"proc_time_std": proc_time_std,
"ism_order_vals": ism_order_vals,
"software": software,
"n_std": n_std,
"n_rays": n_rays,
"n_trials": n_trials,
}
with open("profile_ism_order.pickle", "wb") as handle:
pickle.dump(data, handle, protocol=pickle.HIGHEST_PROTOCOL)
else:
with open(pickle_path, "rb") as f:
data = pickle.load(f)
software = data["software"]
ism_order_vals = data["ism_order_vals"]
proc_time = data["proc_time"]
proc_time_std = data["proc_time_std"]
n_std = data["n_std"]
# plot results
plot_results(software, ism_order_vals, proc_time, proc_time_std, n_std)
if __name__ == "__main__":
profile_room_gen()