Q3D-Calibration/main.py

80 lines
2.0 KiB
Python
Raw Normal View History

2022-07-08 21:21:48 +08:00
import os
import re
2022-07-11 16:24:14 +08:00
from qdx import Bind
from qdx.utils import get_hist, file_filter
2022-07-08 21:21:48 +08:00
from tqdm import tqdm
2022-07-11 16:24:14 +08:00
from matplotlib import pyplot as plt
2022-07-08 21:21:48 +08:00
path = 'result/bind'
file_list = os.listdir(path)
2022-07-11 09:18:23 +08:00
reg = re.compile(r'(([0-9]{4})-([0-9])-([0-9])).txt')
2022-07-08 21:21:48 +08:00
2022-07-11 16:24:14 +08:00
n, m = 5, 8
binds = [[j for j in range(m)] for i in range(n)]
for i in range(n):
for j in range(m):
binds[i][j] = Bind(i, j)
pbar = tqdm(desc="Gaussian Mixture Filter", total=len(file_list))
2022-07-08 21:21:48 +08:00
for file in file_list:
2022-07-11 16:24:14 +08:00
bind = binds[int(i)][int(j)]
name, E, i, j = reg.match(file).groups()
2022-07-08 21:21:48 +08:00
file = os.path.join(path, file)
2022-07-11 16:24:14 +08:00
_, data = file_filter(file)
# bind.draw_filter('result/GMM/' + name + '.png')
# np.savetxt('result/bind-GMM/' + name + '.txt', data, fmt='%d')
bind.add_data(int(E) / 100, data)
2022-07-08 21:21:48 +08:00
pbar.update(1)
2022-07-11 09:18:23 +08:00
pbar.close()
2022-07-08 21:21:48 +08:00
2022-07-11 16:24:14 +08:00
split_n = [8, 7, 7, 8, 8]
pbar = tqdm(desc="Bind Process", total=n * m)
for i in range(n):
for j in range(m):
bind: Bind = binds[i][j]
bind.filter()
bind.fit1()
bind.solve()
bind.split(n=split_n[i])
bind.fit2()
bind.draw_fit1('result/FIT1/' + bind.name + '.png')
bind.draw_fit2('result/FIT2/' + bind.name + '.png')
pbar.update(1)
2022-07-08 21:21:48 +08:00
pbar.close()
2022-07-11 16:24:14 +08:00
y = [
[620, 610, 600, 590, 580, 570, 560, 550],
[485, 475, 465, 455, 445, 435, 425],
[360, 350, 340, 330, 320, 310, 300],
[235, 225, 215, 205, 195, 185, 175, 165],
[100, 90, 80, 70, 60, 50, 40, 30]
]
for i in range(n):
k = 1
fig = plt.figure(figsize=(14, 6))
for j in range(m):
ax = fig.add_subplot(int(m / 2), 2, k)
bind = binds[i][j]
bind.fit3(y[i])
ny = bind.reg3.predict(bind.x1)
c, e = get_hist(ny, delta=0.5)
ax.scatter(e, c, s=0.5)
k += 1
fig.savefig('./Figure-' + str(i) + '.png', facecolor='w', transparent=False)
plt.tight_layout()
plt.close()
f = open('cal.txt', 'w')
for i in range(n):
for j in range(m):
bind = binds[i][j]
f.writelines('{:d} {:d} {:.5f} {:.5f} {:.5f}\n'.format(i, j, bind.k1, bind.k2, bind.b))