-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdyadic_wrapper.py
33 lines (29 loc) · 1.28 KB
/
dyadic_wrapper.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
import os
import subprocess
import numpy
def dyadic_wrapper(power_of_two_num_points, sigma, opt_steps=1000):
dyadicbin_path = os.path.join(os.path.dirname(__file__), 'dyadic_mod/build/net-optimize-pointers')
assert os.path.exists(dyadicbin_path) or os.path.exists(dyadicbin_path + '.exe')
tempfile_sites = 'net.txt'
if os.path.exists(tempfile_sites):
os.remove(tempfile_sites)
cmd_str = dyadicbin_path + " -q v -s " + str(sigma) + " -n " + str(opt_steps) + " " + str(2**power_of_two_num_points)
print(subprocess.run(cmd_str, shell=True))
points = []
with open(tempfile_sites) as filesites:
lines = filesites.readlines()
for line in lines[1:]:
fields = line.strip('\n').split(' ')
if len(fields) == 2:
points.append(numpy.array([float(fields[0]), float(fields[1])]))
assert len(points) == 2**power_of_two_num_points
return points
if __name__ == '__main__':
import psa_wrapper
num_samples = 20
samples = []
for sample in range(num_samples):
points = dyadic_wrapper(power_of_two_num_points=10, sigma=0.5)
samples.append(points)
(effnyquist, oscillations, data_rp, data_ani, data_rdf) = psa_wrapper.psa_wrapper(samples)
psa_wrapper.plot_data(data_ani, 'Frequency', 'Anisotropy', 'plot_ani')