import os import re from qdx import Bind from qdx.utils import get_hist, file_filter from tqdm import tqdm from matplotlib import pyplot as plt path = 'result/bind' file_list = os.listdir(path) reg = re.compile(r'(([0-9]{4})-([0-9])-([0-9])).txt') 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)) for file in file_list: bind = binds[int(i)][int(j)] name, E, i, j = reg.match(file).groups() file = os.path.join(path, file) _, 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) pbar.update(1) pbar.close() 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) pbar.close() 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))