Ensemble: Results: Setup export methods.

This commit is contained in:
parouby committed 2026-09-24 15:14:35 +02:00
1 parent f93e6a7d7c
commit 7124b2b61c
5 files changed
+375 -21

No files matched your search

+21 -9
View File
@@ -26,10 +26,13 @@ from View.Results.translate import ResultsTranslate
class CustomExportDialog(PamhyrDialog):
_pamhyr_ui = "CustomExportAdisDialog"
_pamhyr_name = "Custom Plot Selection"
_pamhyr_ui = "CustomExportDialog"
_pamhyr_name = "Custom Export"
def __init__(self, parent=None):
def __init__(self,
tag_x="values_x",
tag_y="values_y",
parent=None):
trad = ResultsTranslate()
super(CustomExportDialog, self).__init__(
title=trad[self._pamhyr_name],
@@ -38,8 +41,8 @@ class CustomExportDialog(PamhyrDialog):
parent=parent
)
self._available_values_x = self._trad.get_dict("values_x")
self._available_values_y = self._trad.get_dict("values_y")
self._available_values_x = self._trad.get_dict(tag_x)
self._available_values_y = self._trad.get_dict(tag_y)
self.setup_radio_buttons_x()
self.setup_radio_buttons_res()
@@ -66,8 +69,8 @@ class CustomExportDialog(PamhyrDialog):
def setup_radio_buttons_res(self):
self._radio2 = []
layout = self.find(QVBoxLayout, "verticalLayout_pol")
label = self.find(QLabel, "label_3")
layout = self.find(QVBoxLayout, "verticalLayout_solv")
label = self.find(QLabel, "label_solv")
label.setText(self._trad["solver"])
for solver in self.parent._solvers:
@@ -89,7 +92,7 @@ class CustomExportDialog(PamhyrDialog):
layout.addStretch()
def setup_label(self):
self._label = self.find(QLabel, "label_4")
self._label = self.find(QLabel, "label_data")
self._label.setFrameStyle(QFrame.StyledPanel)
self._label.setStyleSheet('background-color: white')
self.set_label()
@@ -163,6 +166,15 @@ class CustomExportDialog(PamhyrDialog):
res = i
break
self.value = x, y, self._envelop.isChecked(), res
self.value = (x, y, self._envelop.isChecked(), res)
super().accept()
class CustomExportEnsembleDialog(CustomExportDialog):
def __init__(self, parent=None):
super(CustomExportEnsembleDialog, self).__init__(
tag_x="values_x_ens",
tag_y="values_y_ens",
parent=parent
)
+207 -9
View File
@@ -79,7 +79,9 @@ from View.Results.CustomPlot.Plot import CustomPlot
from View.Results.CustomPlot.CustomPlotValuesSelectionDialog import (
CustomPlotValuesSelectionDialog,
)
from View.Results.CustomExport.CustomExport import CustomExportDialog
from View.Results.CustomExport.CustomExport import (
CustomExportDialog, CustomExportEnsembleDialog,
)
from View.Results.Table import TableModel
from View.Results.translate import (
@@ -786,34 +788,47 @@ class ResultsWindow(PamhyrWindow):
def export_to(self, filename, x, y, envelop, solver_id):
results = self._results[solver_id]
reach = results.river.reachs[self._get_current_reach()]
first_line = [f"Study: {results.study.name}",
f"Reach: {reach.name}"]
first_line = [
f"Study: {results.study.name}",
f"Reach: {reach.name}"
]
if x == "rk":
timestamp = self._get_current_timestamp()
first_line.append(f"Time: {timestamp}s")
val_dict = self._export_rk(timestamp, y, envelop, solver_id)
elif x == "time":
profile_id = self._get_current_profile()
profile = reach.profile(profile_id)
pname = profile.name if profile.name != "" else profile.rk
first_line.append(f"Profile: {pname}")
val_dict = self._export_time(profile_id, y, solver_id)
try:
with open(filename, 'w', newline='') as csvfile:
writer = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
quotechar='|',
quoting=csv.QUOTE_MINIMAL)
dict_x = self._trad.get_dict("values_x")
header = []
writer.writerow(first_line)
for text in val_dict.keys():
header.append(text)
writer.writerow(header)
for row in range(len(val_dict[dict_x[x]])):
line = []
for var in val_dict.keys():
line.append(val_dict[var][row])
writer.writerow(line)
self._timer.stop()
except Exception as e:
self.message_box(
@@ -913,11 +928,11 @@ class ResultsWindow(PamhyrWindow):
# Translate dictionary keys
translated_dict = {}
translated_dict[dict_x["rk"]] = reach.geometry.get_rk()
for key in my_dict:
translated_dict[dict_y[key]] = my_dict[key]
translated_dict[dict_x["rk"]] = reach.geometry.get_rk()
return translated_dict
def _export_rk_compute_elevation(self, data):
@@ -1087,16 +1102,16 @@ class ResultsWindow(PamhyrWindow):
# Translate dictionary keys
translated_dict = {}
translated_dict[dict_x["time"]] = self._timestamps
for key in my_dict:
translated_dict[dict_y[key]] = my_dict[key]
translated_dict[dict_x["time"]] = self._timestamps
return translated_dict
def _export_time_compute_elevation(self, data):
my_dict = data["my_dict"]
reach = data["reach"]
profile = data["profile"]
if reach.has_bedload():
z_min = data["zfd"]
@@ -1537,3 +1552,186 @@ class ResultsEnsembleWindow(ResultsWindow):
def update_table_selection_solver(self, ind):
return
def _export(self):
profile_id = self._get_current_profile()
self.update_table_selection_profile(profile_id)
dlg = CustomExportEnsembleDialog(parent=self)
if dlg.exec():
x, y, envelop, solver_id = dlg.value
else:
return
logger.debug(
"Export custom plot for: " +
f"{x} -> {','.join(y)}"
)
self.file_dialog(
select_file="AnyFile",
callback=lambda f: self.export_to(f[0], x, y, envelop, solver_id),
default_suffix=".csv",
file_filter=[self._trad["file_csv"]],
)
def _export_rk(self, timestamp, y, envelop, solver_id):
results = self._results[solver_id]
reach = results.river.reachs[self._get_current_reach()]
dict_x = self._trad.get_dict("values_x_ens")
dict_y = self._trad.get_dict("values_y_ens")
if envelop:
dict_y.update(self._trad.get_dict("values_y_envelop_ens"))
table = results.get("table")
id_ts = results.get_timestamp_id(timestamp)
ind = reach.global_index
my_dict = {}
data = {
"z_min": table["z_min"][:, ind[0]:ind[1]+1],
"q_min": table["q_min"][:, ind[0]:ind[1]+1],
"z": table["z_mean"][:, ind[0]:ind[1]+1],
"q": table["q_mean"][:, ind[0]:ind[1]+1],
"z_max": table["z_max"][:, ind[0]:ind[1]+1],
"q_max": table["q_max"][:, ind[0]:ind[1]+1],
"z_std_deriv": table["z_std_derivation"][:, ind[0]:ind[1]+1],
"q_std_deriv": table["q_std_derivation"][:, ind[0]:ind[1]+1],
"reach": reach,
"id_ts": id_ts, "envelop": envelop,
"my_dict": my_dict,
}
func = {
"z_mean": self._export_rk_z,
"q_mean": self._export_rk_q,
"z_standard_derivation": self._export_rk_z_std_deriv,
"q_standard_derivation": self._export_rk_q_std_deriv,
}
# Compute values
for key in y:
func[key](data)
# Translate dictionary keys
translated_dict = {}
translated_dict[dict_x["rk"]] = reach.geometry.get_rk()
for key in my_dict:
translated_dict[dict_y[key]] = my_dict[key]
return translated_dict
def _export_rk_z(self, data):
my_dict = data["my_dict"]
envelop = data["envelop"]
reach = data["reach"]
id_ts = data["id_ts"]
my_dict["z_mean"] = data["z"][id_ts, :]
if envelop:
my_dict["z_min"] = data["z_min"][id_ts, :]
my_dict["z_max"] = data["z_max"][id_ts, :]
def _export_rk_z_std_deriv(self, data):
my_dict = data["my_dict"]
envelop = data["envelop"]
reach = data["reach"]
id_ts = data["id_ts"]
my_dict["z_standard_derivation"] = data["z_std_deriv"][id_ts, :]
def _export_rk_q(self, data):
my_dict = data["my_dict"]
envelop = data["envelop"]
reach = data["reach"]
id_ts = data["id_ts"]
my_dict["q_mean"] = data["q"][id_ts, :]
if envelop:
my_dict["q_min"] = data["q_min"][id_ts, :]
my_dict["q_max"] = data["q_max"][id_ts, :]
def _export_rk_q_std_deriv(self, data):
my_dict = data["my_dict"]
envelop = data["envelop"]
reach = data["reach"]
id_ts = data["id_ts"]
my_dict["q_standard_derivation"] = data["q_std_deriv"][id_ts, :]
def _export_time(self, profile, y, solver_id):
results = self._results[solver_id]
reach = results.river.reachs[self._get_current_reach()]
profile = reach.profile(profile)
dict_x = self._trad.get_dict("values_x")
dict_y = self._trad.get_dict("values_y")
table = results.get("table")
ind = profile.global_index
my_dict = {}
data = {
"z_min": table["z_min"][:, ind],
"q_min": table["q_min"][:, ind],
"z": table["z_mean"][:, ind],
"q": table["q_mean"][:, ind],
"z_max": table["z_max"][:, ind],
"q_max": table["q_max"][:, ind],
"z": table["z_std_derivation"][:, ind],
"q": table["q_std_derivation"][:, ind],
"reach": reach,
"profile": profile,
"my_dict": my_dict,
}
func = {
"z_mean": self._export_time_z,
"q_mean": self._export_time_q,
"z_standard_derivation": self._export_time_z_std_deriv,
"q_standard_derivation": self._export_time_q_std_deriv,
}
# Compute values
for key in y:
func[key](data)
# Translate dictionary keys
translated_dict = {}
translated_dict[dict_x["time"]] = self._timestamps
for key in my_dict:
translated_dict[dict_y[key]] = my_dict[key]
return translated_dict
def _export_time_z(self, data):
my_dict = data["my_dict"]
my_dict["z_mean"] = data["z"]
my_dict["z_min"] = data["z_min"]
my_dict["z_max"] = data["z_max"]
def _export_time_z_std_deriv(self, data):
my_dict = data["my_dict"]
my_dict["z_standard_derivation"] = data["z_std_deriv"]
def _export_time_q(self, data):
my_dict = data["my_dict"]
my_dict["q_mean"] = data["q"]
my_dict["q_min"] = data["q_min"]
my_dict["q_max"] = data["q_max"]
def _export_time_q_std_deriv(self, data):
my_dict = data["my_dict"]
my_dict["q_standard_derivation"] = data["q_std_deriv"]
+20 -1
View File
@@ -130,6 +130,25 @@ class ResultsTranslate(MainTranslate):
"wet_area": self._dict["unit_wet_area"],
}
self._sub_dict["values_x_ens"] = {
"rk": self._dict["unit_rk"],
"time": self._dict["unit_time_s"],
}
self._sub_dict["values_y_ens"] = {
"z_mean": self._dict["unit_mean_water_elevation"],
"q_mean": self._dict["unit_mean_discharge"],
"z_standard_derivation": self._dict["unit_std_deriv_elevation"],
"q_standard_derivation": self._dict["unit_std_deriv_discharge"],
}
self._sub_dict["values_y_envelop_ens"] = {
"z_min": self._dict["unit_min_water_elevation"],
"z_max": self._dict["unit_max_water_elevation"],
"q_min": self._dict["unit_min_discharge"],
"q_max": self._dict["unit_max_discharge"],
}
if self.pollutants is not None:
self._sub_dict["table_headers_raw_data"] = {
"name": _translate("Results", "Profile"),
@@ -157,7 +176,7 @@ class ResultsTranslate(MainTranslate):
"max_velocity": self._dict["unit_max_velocity"],
"min_depth": self._dict["unit_min_depth"],
"max_depth": self._dict["unit_max_depth"],
}
}
self._sub_dict["values_y_pol"] = {
"unit_C": self._dict["unit_concentration"],
+16 -2
View File
@@ -110,6 +110,12 @@ class UnitTranslate(CommonWordTranslate):
self._dict["unit_water_elevation"] = _translate(
"Unit", "Water Elevation (m)"
)
self._dict["unit_mean_water_elevation"] = _translate(
"Unit", "Mean water elevation (m)"
)
self._dict["unit_std_deriv_elevation"] = _translate(
"Unit", "Elevation standard derivation (m)"
)
self._dict["unit_water_elevation_envelop"] = _translate(
"Unit", "Water Elevation Envelop (m)"
)
@@ -129,8 +135,16 @@ class UnitTranslate(CommonWordTranslate):
self._dict["unit_min_velocity"] = _translate(
"Unit", "Min Velocity (m/s)"
)
self._dict["unit_discharge"] = _translate(
"Unit", "Discharge") + f" (m³/s)"
self._dict["unit_discharge"] = (
_translate("Unit", "Discharge") + f" (m³/s)"
)
self._dict["unit_mean_discharge"] = (
_translate("Unit", "Mean discharge") + f" (m³/s)"
)
self._dict["unit_std_deriv_discharge"] = (
_translate("Unit", "Discharge standard derivation")
+ f" (m³/s)"
)
self._dict["unit_discharge_envelop"] = _translate(
"Unit", "Discharge Envelop") + " (m³/s)"
self._dict["unit_max_discharge"] = _translate(
+111
View File
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>418</width>
<height>220</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="verticalLayoutWidget">
<layout class="QVBoxLayout" name="verticalLayout_x">
<item>
<widget class="QLabel" name="label_x">
<property name="text">
<string>X axis:</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="verticalLayoutWidget_2">
<layout class="QVBoxLayout" name="verticalLayout_y">
<item>
<widget class="QLabel" name="label_y">
<property name="text">
<string>Y axis:</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="verticalLayoutWidget_3">
<layout class="QVBoxLayout" name="verticalLayout_solv">
<item>
<widget class="QLabel" name="label_solv">
<property name="text">
<string>Solver:</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="5" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_data">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>