Skip to content

Commit

Permalink
load logic optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis S committed Jul 13, 2023
1 parent 089b5c8 commit 17fc1bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
4 changes: 2 additions & 2 deletions cases/sound_waves/configuration/sound_estimator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pickle

from test.test_sound_simulator import load_file_from_path
from gefest.core.structure.structure import Structure, get_random_structure
from gefest.tools.estimators.simulators.sound_wave.sound_interface import (
SoundSimulator,
Expand All @@ -22,8 +23,7 @@ def configurate_estimator(domain: "Domain", path_best_struct=None):
rnd_structure = get_random_structure(domain)
best_spl = generate_map(domain, rnd_structure)
else:
with open(path_best_struct, "rb") as f:
best_structure = pickle.load(f)
best_structure = load_file_from_path(path_best_struct)
best_spl = sound.estimate(best_structure)
best_spl = np.nan_to_num(best_spl, nan=0, neginf=0, posinf=0)

Expand Down
16 changes: 5 additions & 11 deletions cases/sound_waves/sound_viz.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
import pickle
import matplotlib.pyplot as plt

from cases.main_conf import opt_params
from cases.sound_waves.configuration import sound_domain
from gefest.tools.estimators.simulators.sound_wave.sound_interface import SoundSimulator


def upload_file(path: str):
with open(path, "rb") as f:
file = pickle.load(f)
f.close()
return file

from test.test_sound_simulator import load_file_from_path

init_path = "best_structure.pickle"
optimized_path = "optimized_structure.pickle"


if __name__ == "__main__":
domain, _ = sound_domain.configurate_domain(
poly_num=opt_params.n_polys,
points_num=opt_params.n_points,
is_closed=opt_params.is_closed,
)

init_structure = upload_file(init_path)
optimized_archive = upload_file(optimized_path)
init_structure = load_file_from_path(init_path)
optimized_archive = load_file_from_path(optimized_path)
optimized_structure = optimized_archive[0]

sound = SoundSimulator(domain)
Expand Down
6 changes: 3 additions & 3 deletions test/test_sound_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from cases.sound_waves.configuration import sound_domain


def upload_file(path: str):
def load_file_from_path(path: str):
with open(path, "rb") as f:
file = pickle.load(f)
f.close()
Expand All @@ -21,8 +21,8 @@ def upload_file(path: str):
structure_path = "test/files/standart_structure.pickle"
spl_path = "test/files/standart_spl.pickle"

standart_spl = upload_file(spl_path)
standart_structure = upload_file(structure_path)
standart_spl = load_file_from_path(spl_path)
standart_structure = load_file_from_path(structure_path)

sound = SoundSimulator(domain)

Expand Down

0 comments on commit 17fc1bc

Please sign in to comment.