Skip to content

Commit

Permalink
Re-implemented sampling visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
mlauer154 committed Feb 12, 2024
1 parent 86f641d commit d4bf13a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 41 deletions.
47 changes: 19 additions & 28 deletions pymead/gui/input_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1923,16 +1923,18 @@ def visualize_sampling(self, ws_widget, _):
general_settings = self.parent().findChild(GAGeneralSettingsDialogWidget).valuesFromWidgets()
starting_value = ws_widget.value()
use_current_mea = bool(general_settings["use_current_mea"])
mea_file = general_settings["mea_file"]
jmea_file = general_settings["mea_file"]
gui_obj = get_parent(self, depth=4)
background_color = gui_obj.themes[gui_obj.current_theme]["graph-background-color"]
if use_current_mea or len(mea_file) == 0 or not os.path.exists(mea_file):
jmea_dict = gui_obj.mea.copy_as_param_dict(deactivate_airfoil_graphs=True)
theme = gui_obj.themes[gui_obj.current_theme]
if use_current_mea or len(jmea_file) == 0 or not os.path.exists(jmea_file):
geo_col_dict = gui_obj.geo_col.get_dict_rep()
else:
jmea_dict = load_data(mea_file)
geo_col_dict = load_data(jmea_file)

dialog = SamplingVisualizationDialog(jmea_dict=jmea_dict, initial_sampling_width=starting_value,
initial_n_samples=20, background_color=background_color, parent=self)
dialog = SamplingVisualizationDialog(geo_col_dict=geo_col_dict, initial_sampling_width=starting_value,
initial_n_samples=20, background_color=background_color, theme=theme,
parent=self)
dialog.exec_()

def select_directory(self, line_edit: QLineEdit):
Expand Down Expand Up @@ -2005,28 +2007,6 @@ def convert_text_array_to_dict(multi_line_text: str):
return data_dict


class SamplingVisualizationDialog(QDialog):
def __init__(self, jmea_dict: dict, initial_sampling_width: float, initial_n_samples: int, background_color: str,
parent=None):
super().__init__(parent=parent)
self.setWindowTitle("Visualize Sampling")
self.setFont(self.parent().font())
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self)
layout = QFormLayout(self)

self.sampling_widget = SamplingVisualizationWidget(self, jmea_dict,
initial_sampling_width=initial_sampling_width,
initial_n_samples=initial_n_samples,
background_color=background_color)

layout.addWidget(self.sampling_widget)

layout.addWidget(buttonBox)

buttonBox.accepted.connect(self.accept)
buttonBox.rejected.connect(self.reject)


class PymeadDialogVTabWidget(VerticalTabWidget):
def __init__(self, parent, widgets: dict, settings_override: dict = None):
super().__init__()
Expand Down Expand Up @@ -2308,6 +2288,17 @@ def event(self, event):
return super().event(event)


class SamplingVisualizationDialog(PymeadDialog):
def __init__(self, geo_col_dict: dict, initial_sampling_width: float, initial_n_samples: int, background_color: str,
theme: dict, parent=None):
self.sampling_widget = SamplingVisualizationWidget(None, geo_col_dict,
initial_sampling_width=initial_sampling_width,
initial_n_samples=initial_n_samples,
background_color=background_color)

super().__init__(parent=parent, window_title="Sampling Visualization", widget=self.sampling_widget, theme=theme)


class LoadDialog(QFileDialog):
def __init__(self, parent, settings_var: str, file_filter: str = "JMEA Files (*.jmea)"):
super().__init__(parent=parent)
Expand Down
24 changes: 11 additions & 13 deletions pymead/gui/sampling_visualization.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
from copy import deepcopy

import pyqtgraph as pg
import numpy as np
from PyQt5.QtWidgets import QWidget, QDoubleSpinBox, QSpinBox, QLabel
from PyQt5.QtWidgets import QGridLayout

# from pymead.core.mea import MEA
from pymead.core.geometry_collection import GeometryCollection
from pymead.optimization.sampling import ConstrictedRandomSampling


class SamplingVisualizationWidget(QWidget):
def __init__(self, parent, jmea_dict: dict, initial_sampling_width: float, initial_n_samples: int,
def __init__(self, parent, geo_col_dict: dict, initial_sampling_width: float, initial_n_samples: int,
background_color: str):
super().__init__(parent=parent)

self.jmea_dict = deepcopy(jmea_dict)
self.jmea_dict["airfoil_graphs_active"] = False
self.mea = MEA.generate_from_param_dict(self.jmea_dict)
norm_param_list, _ = self.mea.extract_parameters()
self.geo_col_dict = deepcopy(geo_col_dict)
self.geo_col_dict["airfoil_graphs_active"] = False
self.geo_col = GeometryCollection.set_from_dict_rep(self.geo_col_dict)
norm_param_list = self.geo_col.extract_design_variable_values(bounds_normalized=True)
self.norm_param_list = deepcopy(norm_param_list)

self.w = pg.GraphicsLayoutWidget(show=True, size=(800, 300))
Expand All @@ -27,6 +26,7 @@ def __init__(self, parent, jmea_dict: dict, initial_sampling_width: float, initi
self.v = self.w.addPlot()
self.v.setLabel(axis="bottom", text="x")
self.v.setLabel(axis="left", text="y")
self.v.setAspectLocked(True)

layout = QGridLayout(self)
layout.addWidget(self.w, 0, 0, 1, 4)
Expand Down Expand Up @@ -60,6 +60,7 @@ def __init__(self, parent, jmea_dict: dict, initial_sampling_width: float, initi
self.current_ns = initial_n_samples

self.setLayout(layout)
self.setMinimumSize(800, 300)

def spinbox_ws_value_changed(self, new_ws):
self.current_ws = new_ws
Expand All @@ -75,11 +76,8 @@ def update_plots(self, sampling_width: float, n_samples: int):
max_sampling_width=sampling_width)
X_list = sampling.sample()
for idx, individual in enumerate(X_list):
self.mea.update_parameters(individual)
# extra_get_coords_kwargs = dict(downsample=2, ds_max_points=100, ds_curve_exp=2.0)
extra_get_coords_kwargs = {}
for a in self.mea.airfoils.values():
coords = np.array(a.get_coords(body_fixed_csys=False, **extra_get_coords_kwargs))
self.geo_col.assign_design_variable_values(individual, bounds_normalized=True)
for a in self.geo_col.container()["airfoils"].values():
coords = a.get_coords_selig_format()
plot_handle = self.v.plot(pen=pg.mkPen(color="cornflowerblue"))
plot_handle.setData(coords[:, 0], coords[:, 1])
pass

0 comments on commit d4bf13a

Please sign in to comment.