Skip to content

Commit

Permalink
Add DesignMatrixPanel to show DataFrame parameters in a table
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Oct 8, 2024
1 parent 1a42df2 commit b47bd57
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/ert/gui/simulation/ensemble_experiment_panel.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from dataclasses import dataclass

import pandas as pd
from qtpy import QtCore
from qtpy.QtCore import Slot
from qtpy.QtWidgets import QFormLayout, QLabel
from qtpy.QtWidgets import QFormLayout, QLabel, QPushButton

from ert.gui.ertnotifier import ErtNotifier
from ert.gui.ertwidgets import (
Expand All @@ -11,13 +12,11 @@
StringBox,
TextModel,
)
from ert.gui.tools.design_matrix.design_matrix_panel import DesignMatrixPanel
from ert.mode_definitions import ENSEMBLE_EXPERIMENT_MODE
from ert.run_models import EnsembleExperiment
from ert.validation import RangeStringArgument
from ert.validation.proper_name_argument import (
ExperimentValidation,
ProperNameArgument,
)
from ert.validation.proper_name_argument import ExperimentValidation, ProperNameArgument

from .experiment_config_panel import ExperimentConfigPanel

Expand Down Expand Up @@ -78,6 +77,10 @@ def __init__(self, ensemble_size: int, run_path: str, notifier: ErtNotifier):
)
layout.addRow("Active realizations", self._active_realizations_field)

dm_param_button = QPushButton("Show DM parameters")
dm_param_button.clicked.connect(self.on_dm_params_clicked)
layout.addRow("Show DM parameters", dm_param_button)

self.setLayout(layout)

self._active_realizations_field.getValidationSupport().validationChanged.connect(
Expand All @@ -92,6 +95,11 @@ def __init__(self, ensemble_size: int, run_path: str, notifier: ErtNotifier):

self.notifier.ertChanged.connect(self._update_experiment_name_placeholder)

def on_dm_params_clicked(self):

Check failure on line 98 in src/ert/gui/simulation/ensemble_experiment_panel.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Function is missing a return type annotation
df_sample = pd.DataFrame({"Column1": [1, 2, 3], "Column2": ["A", "B", "C"]})
viewer = DesignMatrixPanel(df_sample)
viewer.exec_()

@Slot(ExperimentConfigPanel)
def experimentTypeChanged(self, w: ExperimentConfigPanel) -> None:
if isinstance(w, EnsembleExperimentPanel):
Expand Down
36 changes: 36 additions & 0 deletions src/ert/gui/tools/design_matrix/design_matrix_panel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pandas as pd
from qtpy.QtGui import QStandardItem, QStandardItemModel
from qtpy.QtWidgets import QDialog, QTableView, QVBoxLayout


class DesignMatrixPanel(QDialog):
def __init__(self, design_matrix_df: pd.DataFrame, parent=None):

Check failure on line 7 in src/ert/gui/tools/design_matrix/design_matrix_panel.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Function is missing a type annotation for one or more arguments
super().__init__(parent)

self.setWindowTitle("Design matrix parameters viewer")

self.table_view = QTableView(self)
self.table_view.setEditTriggers(QTableView.NoEditTriggers)

self.model = self.create_model(design_matrix_df)
self.table_view.setModel(self.model)

# Layout to hold the table view
layout = QVBoxLayout()
layout.addWidget(self.table_view)
self.setLayout(layout)

@staticmethod
def create_model(design_matrix_df: pd.DataFrame):

Check failure on line 24 in src/ert/gui/tools/design_matrix/design_matrix_panel.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Function is missing a return type annotation
# Create a model
model = QStandardItemModel()
model.setHorizontalHeaderLabels(design_matrix_df.columns.astype(str).tolist())

# Populate the model with data
for index, _ in design_matrix_df.iterrows():
items = [
QStandardItem(str(design_matrix_df.at[index, col]))
for col in design_matrix_df.columns
]
model.appendRow(items)
return model

0 comments on commit b47bd57

Please sign in to comment.