From 1a364876c23ec92b0f44a11e9a1b62a3c7768f7b Mon Sep 17 00:00:00 2001 From: Andrey Marakulin Date: Tue, 12 Mar 2024 15:48:39 +0300 Subject: [PATCH] Add test --- generate_dataset/dataset_generator.py | 15 ++--- generate_dataset/parameters_changer.py | 6 +- test.py | 85 ++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 test.py diff --git a/generate_dataset/dataset_generator.py b/generate_dataset/dataset_generator.py index 58768d4..c0648a7 100644 --- a/generate_dataset/dataset_generator.py +++ b/generate_dataset/dataset_generator.py @@ -29,7 +29,8 @@ def generate_dataset(save_png=False, debug=False): changer = ParametersChanger(cir_path, parameters_settings) changer.generate_circuits(debug) - changer.dump_circuits_on_disk(output_path) + if not debug: + changer.dump_circuits_on_disk(output_path) simulator = SimulatorIVC(measurement_variant) @@ -42,10 +43,10 @@ def generate_dataset(save_png=False, debug=False): simulator.save_ivc(circuit.plot_title, analysis, uzf_name) simulator.save_plot(circuit.plot_title, analysis, png_name, scheme_png_path, save_png=save_png) - # for noise_number in range(measurement_variant['noise_settings']['with_noise']): - # analysis = simulator.add_noise(analysis, measurement_variant['noise_settings']['SNR']) + for noise_number in range(measurement_variant['noise_settings']['with_noise']): + analysis = simulator.add_noise(analysis, measurement_variant['noise_settings']['SNR']) - # uzf_name = os.path.join(output_path, f'{i}_noise{noise_number}.uzf') - # png_name = os.path.join(output_path, f'{i}_noise{noise_number}.png') - # simulator.save_ivc(circuit.plot_title, analysis, uzf_name) - # simulator.save_plot(circuit.plot_title, analysis, png_name, scheme_png_path, save_png=save_png) + uzf_name = os.path.join(output_path, f'{i}_noise{noise_number}.uzf') + png_name = os.path.join(output_path, f'{i}_noise{noise_number}.png') + simulator.save_ivc(circuit.plot_title, analysis, uzf_name) + simulator.save_plot(circuit.plot_title, analysis, png_name, scheme_png_path, save_png=save_png) diff --git a/generate_dataset/parameters_changer.py b/generate_dataset/parameters_changer.py index 6a7f916..9858b20 100644 --- a/generate_dataset/parameters_changer.py +++ b/generate_dataset/parameters_changer.py @@ -91,9 +91,9 @@ def dump_circuits_on_disk(self, base_folder) -> None: :param base_folder: Folder to save .cir files. (If not exist - it's ok) """ os.makedirs(base_folder, exist_ok=True) - # for i, circuit in enumerate(self.circuits): - # with open(os.path.join(base_folder, f'{i}.cir'), 'w+') as f: - # f.write(str(circuit)) + for i, circuit in enumerate(self.circuits): + with open(os.path.join(base_folder, f'{i}.cir'), 'w+') as f: + f.write(str(circuit)) def _params_combination_to_circuit(self, params_combination): # Make from combination-dict a circuit with this params. diff --git a/test.py b/test.py new file mode 100644 index 0000000..b1d4e7a --- /dev/null +++ b/test.py @@ -0,0 +1,85 @@ +# Cut screenshots from EPLab +# import numpy as np +# import os +# import glob +# import cv2 +# +# +# files = glob.glob('C:\\dev\\ivc-circuit-detector\\dataset_human_compare\\original\\*\\*.png') +# +# for file in files: +# img = cv2.imread(file) +# img = img[100:900, 120:1600, :] +# filename = file.replace("original", "cutted") +# if not os.path.exists(os.path.split(filename)[0]): +# os.makedirs(os.path.split(filename)[0]) +# cv2.imwrite(filename, img) +import glob + +from epcore.elements import Board +from epcore.filemanager import save_board_to_ufiv, load_board_from_ufiv +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.ticker import MultipleLocator +import glob +import os + +PATH = "dataset/measurement_1kHz_middle_5v/*.uzf" +files = glob.glob(PATH) +fig = plt.figure() +axe = fig.gca(polar=True) + +for file in files: + board = load_board_from_ufiv(file) + a = board.to_json() + v = np.array(a['elements'][0]['pins'][0]['iv_curves'][0]['voltages'])[:100] + i = np.array(a['elements'][0]['pins'][0]['iv_curves'][0]['currents'])[:100] + + v = (v - v.min())/(v.max() - v.min()) + i = (i - i.min()) / (i.max() - i.min()) + + w = a['elements'][0]['pins'][0]['iv_curves'][0]['measurement_settings']['probe_signal_frequency'] + dt = np.linspace(start=0, stop=(1 / w), num=len(v)) + + A = np.sqrt(v ** 2 + i ** 2) + + thetas = np.linspace(0, 2 * np.pi, 100) + axe.plot(thetas, A, label=os.path.basename(file)) + + # plt.plot(dt, v) + # plt.plot() +angle = np.deg2rad(67.5) +plt.legend(loc="lower left") +plt.show() + + +# files = glob.glob(PATH) +# for file in files: +# board = load_board_from_ufiv(file).to_json() +# v = np.array(board['elements'][0]['pins'][0]['iv_curves'][0]['voltages'])[:100] +# i = np.array(board['elements'][0]['pins'][0]['iv_curves'][0]['currents'])[:100] +# +# # v = (v - v.min())/(v.max() - v.min()) +# # i = (i - i.min()) / (i.max() - i.min()) +# +# w = board['elements'][0]['pins'][0]['iv_curves'][0]['measurement_settings']['probe_signal_frequency'] +# dt = np.linspace(start=0, stop=(1 / w), num=len(v)) +# +# phi = np.linspace(0, 2, num=100) +# +# plt.plot(phi, i, label=os.path.basename(file)) +# # plt.plot(dt, v, label=os.path.basename(file)) +# +# # A = np.sqrt(v ** 2 + i ** 2) +# # plt.plot(dt, A, label=os.path.basename(file)) +# +# +# plt.ylabel('I, amps') +# gc = plt.gca() +# gc.xaxis.set_major_formatter(plt.FormatStrFormatter('%g $\pi$')) +# gc.xaxis.set_major_locator(MultipleLocator(base=0.25)) +# plt.grid() +# plt.title(PATH.split('/')[1]) +# plt.xlabel('period') +# plt.legend() +# plt.show()