From d4bf13acbf8ac32fd01c2b41369ae3bbd4c4d1ee Mon Sep 17 00:00:00 2001 From: mlauer154 Date: Mon, 12 Feb 2024 17:09:27 -0600 Subject: [PATCH] Re-implemented sampling visualization --- pymead/gui/input_dialog.py | 47 +++++++++++----------------- pymead/gui/sampling_visualization.py | 24 +++++++------- 2 files changed, 30 insertions(+), 41 deletions(-) diff --git a/pymead/gui/input_dialog.py b/pymead/gui/input_dialog.py index 9667ff05..3bfeff5d 100644 --- a/pymead/gui/input_dialog.py +++ b/pymead/gui/input_dialog.py @@ -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): @@ -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__() @@ -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) diff --git a/pymead/gui/sampling_visualization.py b/pymead/gui/sampling_visualization.py index e1406bb9..88751ac2 100644 --- a/pymead/gui/sampling_visualization.py +++ b/pymead/gui/sampling_visualization.py @@ -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)) @@ -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) @@ -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 @@ -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