Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
annndruha committed Mar 12, 2024
1 parent 3ef1977 commit 1a36487
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 10 deletions.
15 changes: 8 additions & 7 deletions generate_dataset/dataset_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
6 changes: 3 additions & 3 deletions generate_dataset/parameters_changer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
85 changes: 85 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 1a36487

Please sign in to comment.