Compare commits

..
24 changed files with 710 additions and 116 deletions

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

+2 -1
View File
@@ -4,7 +4,7 @@ PyQt5-sip==12.18.0
PyQtWebEngine==5.15.6 PyQtWebEngine==5.15.6
QScintilla>=2.14.1 QScintilla>=2.14.1
pyqtgraph>=0.12.1 pyqtgraph>=0.12.1
matplotlib==3.8.3 matplotlib==3.10.8
numpy>=1.24.2 numpy>=1.24.2
colorama>=0.4.3 colorama>=0.4.3
pyinstaller>=5.11.0 pyinstaller>=5.11.0
@@ -14,3 +14,4 @@ platformdirs>=4.2.0
pyshp>=2.3.1 pyshp>=2.3.1
rasterio==1.3.11 rasterio==1.3.11
#fortranformat==2.0.3 #fortranformat==2.0.3
psutil>=7.2.2
+70 -4
View File
@@ -46,6 +46,8 @@ class Distribution(SQLSubModel):
self._script = script self._script = script
self._labels = [] self._labels = []
self._default_values = [] self._default_values = []
self._params_checkers = []
self._params_tips = []
@property @property
def name(self): def name(self):
@@ -145,13 +147,28 @@ class Distribution(SQLSubModel):
if predicate(self, data): if predicate(self, data):
modifier(self, data) modifier(self, data)
def is_valid_parameters(self, parameters):
valid = True
tips = []
for i, checker in enumerate(self._params_checkers):
ok = checker(parameters)
if not ok:
tips.append(self._params_tips[i])
valid = False
return (valid, tips)
def check_params(self, params):
return True
def random(self, r): def random(self, r):
raise NotImplementedMethodeError(cls, cls._load) raise NotImplementedMethodeError(cls, cls._load)
########################### ###############################
# DISTRIBUTION IMPLEMENTATION # # DISTRIBUTION IMPLEMENTATION #
########################### ###############################
class Uniform(Distribution): class Uniform(Distribution):
_sub_classes = [] _sub_classes = []
@@ -166,6 +183,11 @@ class Uniform(Distribution):
self._labels = ["low", "high"] self._labels = ["low", "high"]
self._default_values = [20.0, 40.0] self._default_values = [20.0, 40.0]
self._params_checkers = [self.check_params, self.check_params]
self._params_tips = ["uniform_low_tips", "uniform_high_tips"]
def check_params(self, params):
return (params[0] < params[1])
def random(self, params, nb): def random(self, params, nb):
lst = params.copy() lst = params.copy()
@@ -187,6 +209,11 @@ class Normal(Distribution):
self._labels = ["loc", "scale"] self._labels = ["loc", "scale"]
self._default_values = [30.0, 5.0] self._default_values = [30.0, 5.0]
self._params_checkers = [self.check_params, self.check_scale]
self._params_tips = ["normal_loc_tips", "normal_scale_tips"]
def check_scale(self, params):
return 0 <= params[1]
def random(self, params, nb): def random(self, params, nb):
lst = params.copy() lst = params.copy()
@@ -195,6 +222,37 @@ class Normal(Distribution):
return np.random.normal(*lst) return np.random.normal(*lst)
class Binomial(Distribution):
_sub_classes = []
def __init__(self, id: int = -1,
name: str = "binomial", script: str = "",
status=None):
super(Binomial, self).__init__(
id=id, status=status,
name=name, script=script
)
self._labels = ["binomial_n", "binomial_p"]
self._default_values = [100.0, 0.3]
self._params_checkers = [self.check_n, self.check_p]
self._params_tips = ["binomial_n_tips", "binomial_p_tips"]
def check_n(self, params):
n = params[0]
return (0 <= n) and (n == round(n))
def check_p(self, params):
p = params[1]
return 0 <= p <= 1
def random(self, params, nb):
lst = params.copy()
lst.append(nb)
return np.random.binomial(*lst)
class Poisson(Distribution): class Poisson(Distribution):
_sub_classes = [] _sub_classes = []
@@ -206,8 +264,14 @@ class Poisson(Distribution):
name=name, script=script name=name, script=script
) )
self._labels = ["lam"] self._labels = ["poisson_lam"]
self._default_values = [5.0] self._default_values = [5.0]
self._params_checkers = [self.check_lam]
self._params_tips = ["poisson_lam_tips"]
def check_lam(self, params):
lam = params[0]
return 0 <= lam
def random(self, params, nb): def random(self, params, nb):
lst = params.copy() lst = params.copy()
@@ -229,7 +293,9 @@ class Custom(Distribution):
self._labels = ["custom"] self._labels = ["custom"]
self._type = "custom" self._type = "custom"
self._default_values = "" self._default_values = [""]
self._params_checkers = [self.check_params]
self._params_tips = ["custom_params_tips"]
def random(self, params, nb): def random(self, params, nb):
try: try:
+5 -3
View File
@@ -30,10 +30,12 @@ class DistributionList(PamhyrModelList):
new = cls(status=data['status']) new = cls(status=data['status'])
# Default distributions # Default distributions
d = {"status": data['status']}
new._lst = [ new._lst = [
Uniform(status=data['status']), Uniform(**d),
Normal(status=data['status']), Normal(**d),
Poisson(status=data['status']), Binomial(**d),
Poisson(**d),
] ]
# DB custom distributions # DB custom distributions
+12 -3
View File
@@ -253,12 +253,21 @@ class Ensemble(SQLSubModel):
self._target_data = target_data self._target_data = target_data
self._status.modified() self._status.modified()
def get_data_dict(self): def get_data_dict(self, use_ids=False):
target_data = self.target_data
distribution = self.distribution
if use_ids:
if self.target_data:
target_data = self.target_data.pamhyr_id
if self.distribution:
distribution = self.distribution.name
return { return {
"name": self.name, "name": self.name,
"data_type": self.data_type, "data_type": self.data_type,
"target_data": self.target_data, "target_data": target_data,
"distribution": self.distribution, "distribution": distribution,
"params": self.params, "params": self.params,
} }
+9
View File
@@ -51,3 +51,12 @@ class EnsembleList(PamhyrModelList):
self._lst.insert(index, r) self._lst.insert(index, r)
self._status.modified() self._status.modified()
return r return r
def new_with_data(self, index, data):
r = Ensemble(status=self._status)
r.set_data_dict(data)
self._lst.insert(index, r)
self._status.modified()
return r
+1 -1
View File
@@ -707,7 +707,7 @@ class Study(SQLModel):
if switch: if switch:
self.status.scenario = new self.status.scenario = new
self.status.set_as_editable() self.status.set_as_read_only()
return new return new
@property @property
+64
View File
@@ -0,0 +1,64 @@
# Translate.py -- Pamhyr
# Copyright (C) 2023-2026 INRAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
from PyQt5.QtCore import QCoreApplication
from View.Ensembles.Translate import EnsemblesTranslate
_translate = QCoreApplication.translate
class EnsembleEditTranslate(EnsemblesTranslate):
def __init__(self):
super(EnsembleEditTranslate, self).__init__()
self._dict["binomial_n"] = _translate("Ensemble", "n")
self._dict["binomial_p"] = _translate("Ensemble", "p")
self._dict["poisson_lam"] = _translate("Ensemble", "Lam")
self._dict["checker_failed_title"] = _translate(
"Ensemble",
"Invalid parameter"
)
self._dict["checker_failed_text"] = _translate(
"Ensemble",
"This parameter is not valid for selected distribution: "
)
uniform = _translate(
"Ensemble", "(High - Low) must be non-negative."
)
self._dict["uniform_low_tips"] = uniform
self._dict["uniform_high_tips"] = uniform
self._dict["normal_scale_tips"] = _translate(
"Ensemble", "Scale must be non-negative."
)
self._dict["binomial_n_tips"] = _translate(
"Ensemble", "N must be non-negative and must be an integers."
)
self._dict["binomial_p_tips"] = _translate(
"Ensemble", "P must be >= 0 and <=1."
)
self._dict["poisson_lam_tips"] = _translate(
"Ensemble", "Lam must be >= 0."
)
+25 -4
View File
@@ -45,6 +45,8 @@ from PyQt5.QtWidgets import (
QGroupBox, QTreeWidget, QGroupBox, QTreeWidget,
) )
from View.Ensembles.Edit.Translate import EnsembleEditTranslate
logger = logging.getLogger() logger = logging.getLogger()
@@ -74,7 +76,9 @@ class EnsembleEditDialog(PamhyrDialog):
_pamhyr_name = "Parameters" _pamhyr_name = "Parameters"
def __init__(self, study=None, ensemble=None, def __init__(self, study=None, ensemble=None,
trad=None, parent=None): parent=None):
trad = EnsembleEditTranslate()
super(EnsembleEditDialog, self).__init__( super(EnsembleEditDialog, self).__init__(
title=trad[self._pamhyr_name], title=trad[self._pamhyr_name],
trad=trad, trad=trad,
@@ -209,13 +213,26 @@ class EnsembleEditDialog(PamhyrDialog):
), ),
None None
) )
parameters = self._params_widget.values
if distribution is not None:
ok, tips = distribution.is_valid_parameters(parameters)
if not ok:
self.message_box(
text=self._trad["checker_failed_text"],
informative_text="\n".join(
map(lambda t: " - " + self._trad[t], tips)
),
window_title=self._trad["checker_failed_title"],
)
return
self._values = { self._values = {
"name": self.get_line_edit_text("lineEdit_name"), "name": self.get_line_edit_text("lineEdit_name"),
"data_type": self._target_data[0], "data_type": self._target_data[0],
"target_data": self._target_data[1], "target_data": self._target_data[1],
"distribution": distribution, "distribution": distribution,
"params": self._params_widget.values, "params": parameters,
} }
super().accept() super().accept()
@@ -248,7 +265,9 @@ class Ensemble1ParamsWidget(PamhyrWidget):
def _init_default_values(self): def _init_default_values(self):
self._values = self._ensemble.params self._values = self._ensemble.params
if len(self._values) > 0: if len(self._values) != 1:
self._values = self._distribution.default_values.copy()
self.set_double_spin_box("doubleSpinBox_0", self._values[0]) self.set_double_spin_box("doubleSpinBox_0", self._values[0])
@property @property
@@ -285,7 +304,9 @@ class Ensemble2ParamsWidget(PamhyrWidget):
def _init_default_values(self): def _init_default_values(self):
self._values = self._ensemble.params self._values = self._ensemble.params
if len(self._values) > 0: if len(self._values) != 2:
self._values = self._distribution.default_values.copy()
self.set_double_spin_box("doubleSpinBox_0", self._values[0]) self.set_double_spin_box("doubleSpinBox_0", self._values[0])
self.set_double_spin_box("doubleSpinBox_1", self._values[1]) self.set_double_spin_box("doubleSpinBox_1", self._values[1])
+28
View File
@@ -115,6 +115,34 @@ class AddCommand(QUndoCommand):
self._ensembles.insert(self._index, self._new) self._ensembles.insert(self._index, self._new)
class ImportCommand(QUndoCommand):
def __init__(self, ensembles, data, index):
QUndoCommand.__init__(self)
self._ensembles = ensembles
self._index = index
self._data = data
self._news = None
def undo(self):
for new in self._news:
new.set_as_deleted()
def redo(self):
if self._news is None:
self._news = list(
map(
lambda d: self._ensembles.new_with_data(
self._index, d
),
self._data,
)
)
else:
for new in self._news:
new.set_as_not_deleted()
class DelCommand(QUndoCommand): class DelCommand(QUndoCommand):
def __init__(self, ensembles, rows): def __init__(self, ensembles, rows):
QUndoCommand.__init__(self) QUndoCommand.__init__(self)
+65 -75
View File
@@ -17,6 +17,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging import logging
import json
from tools import trace, timer, logger_exception from tools import trace, timer, logger_exception
@@ -47,7 +48,7 @@ from View.Ensembles.Table import (
EnsembleTableModel, ComboBoxDelegate EnsembleTableModel, ComboBoxDelegate
) )
from View.Ensembles.Translate import EnsemblesTranslate from View.Ensembles.Translate import EnsemblesTranslate
from View.Ensembles.UndoCommand import SetAllCommand from View.Ensembles.UndoCommand import SetAllCommand, ImportCommand
logger = logging.getLogger() logger = logging.getLogger()
@@ -140,6 +141,12 @@ class EnsemblesWindow(PamhyrWindow):
self.find(QAction, "action_add").triggered.connect(self.add) self.find(QAction, "action_add").triggered.connect(self.add)
self.find(QAction, "action_del").triggered.connect(self.delete) self.find(QAction, "action_del").triggered.connect(self.delete)
self.find(QAction, "action_edit").triggered.connect(self.edit) self.find(QAction, "action_edit").triggered.connect(self.edit)
self.find(QAction, "action_export").triggered.connect(
self.export_to_json
)
self.find(QAction, "action_import").triggered.connect(
self.import_from_json
)
table = self.find(QTableView, f"tableView") table = self.find(QTableView, f"tableView")
table.selectionModel()\ table.selectionModel()\
@@ -190,7 +197,6 @@ class EnsemblesWindow(PamhyrWindow):
dlg = EnsembleEditDialog( dlg = EnsembleEditDialog(
study=self._study, study=self._study,
ensemble=ens, ensemble=ens,
trad=self._trad,
parent=self parent=self
) )
@@ -204,87 +210,71 @@ class EnsemblesWindow(PamhyrWindow):
logger_exception(e) logger_exception(e)
return return
def export_to_json(self):
ens = []
for e in self._ensembles.lst:
ens.append(e.get_data_dict(use_ids=True))
class Ensemble1ParamsDialog(PamhyrDialog): data = {"ensembles": ens}
_pamhyr_ui = "Ensemble1ParamsDialog"
_pamhyr_name = "Parameters"
def __init__(self, ensemble=None, def aux(filename):
trad=None, parent=None): with open(filename[0], 'w') as f:
super(Ensemble1ParamsDialog, self).__init__( f.write(json.dumps(data))
title=trad[self._pamhyr_name],
trad=trad, self.file_dialog(
options=[], select_file=None,
parent=parent callback=aux,
default_suffix='.json',
file_filter=[self._trad["file_json"]]
) )
self._ensemble = ensemble def import_from_json(self):
self._labels = ensemble.distribution.labels def aux(filename):
with open(filename[0], 'r') as f:
return json.load(f)
self._init_default_labels() data = self.file_dialog(
self._init_default_values() select_file=None,
callback=aux,
def _init_default_labels(self): default_suffix='.json',
self.set_label_text("label_0", self._trad[self._labels[0]]) file_filter=[self._trad["file_json"]]
def _init_default_values(self):
self._values = self._ensemble.params
if len(self._values) > 0:
self.set_double_spin_box("doubleSpinBox_0", self._values[0])
@property
def values(self):
return self._values
def accept(self):
self._values = [
self.get_double_spin_box("doubleSpinBox_0"),
]
super().accept()
def reject(self):
self.close()
class Ensemble2ParamsDialog(PamhyrDialog):
_pamhyr_ui = "Ensemble2ParamsDialog"
_pamhyr_name = "Parameters"
def __init__(self, ensemble=None,
trad=None, parent=None):
super(Ensemble2ParamsDialog, self).__init__(
title=trad[self._pamhyr_name],
trad=trad,
options=[],
parent=parent
) )
self._ensemble = ensemble dtarget = dict(
self._labels = ensemble.distribution.labels map(
lambda s: (s.pamhyr_id, s),
self._study.river.stricklers.stricklers
)
)
self._init_default_labels() ddistr = dict(
self._init_default_values() map(
lambda d: (d.name, d),
self._study._ens_distributions.lst
)
)
def _init_default_labels(self): def update(d, values):
self.set_label_text("label_0", self._trad[self._labels[0]]) d.update(values)
self.set_label_text("label_1", self._trad[self._labels[1]]) return d
def _init_default_values(self): updated = list(
self._values = self._ensemble.params map(
if len(self._values) > 0: lambda d: update(
self.set_double_spin_box("doubleSpinBox_0", self._values[0]) d, {"target_data": dtarget[d["target_data"]]}
self.set_double_spin_box("doubleSpinBox_1", self._values[1]) ),
map(
lambda d: update(
d, {"distribution": ddistr[d["distribution"]]}
),
data["ensembles"]
)
)
)
@property self._undo_stack.push(
def values(self): ImportCommand(
return self._values self._ensembles, updated, 0
)
def accept(self): )
self._values = [ self._table.update()
self.get_double_spin_box("doubleSpinBox_0"),
self.get_double_spin_box("doubleSpinBox_1")
]
super().accept()
def reject(self):
self.close()
+21 -9
View File
@@ -26,10 +26,13 @@ from View.Results.translate import ResultsTranslate
class CustomExportDialog(PamhyrDialog): class CustomExportDialog(PamhyrDialog):
_pamhyr_ui = "CustomExportAdisDialog" _pamhyr_ui = "CustomExportDialog"
_pamhyr_name = "Custom Plot Selection" _pamhyr_name = "Custom Export"
def __init__(self, parent=None): def __init__(self,
tag_x="values_x",
tag_y="values_y",
parent=None):
trad = ResultsTranslate() trad = ResultsTranslate()
super(CustomExportDialog, self).__init__( super(CustomExportDialog, self).__init__(
title=trad[self._pamhyr_name], title=trad[self._pamhyr_name],
@@ -38,8 +41,8 @@ class CustomExportDialog(PamhyrDialog):
parent=parent parent=parent
) )
self._available_values_x = self._trad.get_dict("values_x") self._available_values_x = self._trad.get_dict(tag_x)
self._available_values_y = self._trad.get_dict("values_y") self._available_values_y = self._trad.get_dict(tag_y)
self.setup_radio_buttons_x() self.setup_radio_buttons_x()
self.setup_radio_buttons_res() self.setup_radio_buttons_res()
@@ -66,8 +69,8 @@ class CustomExportDialog(PamhyrDialog):
def setup_radio_buttons_res(self): def setup_radio_buttons_res(self):
self._radio2 = [] self._radio2 = []
layout = self.find(QVBoxLayout, "verticalLayout_pol") layout = self.find(QVBoxLayout, "verticalLayout_solv")
label = self.find(QLabel, "label_3") label = self.find(QLabel, "label_solv")
label.setText(self._trad["solver"]) label.setText(self._trad["solver"])
for solver in self.parent._solvers: for solver in self.parent._solvers:
@@ -89,7 +92,7 @@ class CustomExportDialog(PamhyrDialog):
layout.addStretch() layout.addStretch()
def setup_label(self): 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.setFrameStyle(QFrame.StyledPanel)
self._label.setStyleSheet('background-color: white') self._label.setStyleSheet('background-color: white')
self.set_label() self.set_label()
@@ -163,6 +166,15 @@ class CustomExportDialog(PamhyrDialog):
res = i res = i
break break
self.value = x, y, self._envelop.isChecked(), res self.value = (x, y, self._envelop.isChecked(), res)
super().accept() 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 ( from View.Results.CustomPlot.CustomPlotValuesSelectionDialog import (
CustomPlotValuesSelectionDialog, 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.Table import TableModel
from View.Results.translate import ( from View.Results.translate import (
@@ -786,34 +788,47 @@ class ResultsWindow(PamhyrWindow):
def export_to(self, filename, x, y, envelop, solver_id): def export_to(self, filename, x, y, envelop, solver_id):
results = self._results[solver_id] results = self._results[solver_id]
reach = results.river.reachs[self._get_current_reach()] reach = results.river.reachs[self._get_current_reach()]
first_line = [f"Study: {results.study.name}", first_line = [
f"Reach: {reach.name}"] f"Study: {results.study.name}",
f"Reach: {reach.name}"
]
if x == "rk": if x == "rk":
timestamp = self._get_current_timestamp() timestamp = self._get_current_timestamp()
first_line.append(f"Time: {timestamp}s") first_line.append(f"Time: {timestamp}s")
val_dict = self._export_rk(timestamp, y, envelop, solver_id) val_dict = self._export_rk(timestamp, y, envelop, solver_id)
elif x == "time": elif x == "time":
profile_id = self._get_current_profile() profile_id = self._get_current_profile()
profile = reach.profile(profile_id) profile = reach.profile(profile_id)
pname = profile.name if profile.name != "" else profile.rk pname = profile.name if profile.name != "" else profile.rk
first_line.append(f"Profile: {pname}") first_line.append(f"Profile: {pname}")
val_dict = self._export_time(profile_id, y, solver_id) val_dict = self._export_time(profile_id, y, solver_id)
try: try:
with open(filename, 'w', newline='') as csvfile: with open(filename, 'w', newline='') as csvfile:
writer = csv.writer(csvfile, delimiter=',', writer = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL) quotechar='|',
quoting=csv.QUOTE_MINIMAL)
dict_x = self._trad.get_dict("values_x") dict_x = self._trad.get_dict("values_x")
header = [] header = []
writer.writerow(first_line) writer.writerow(first_line)
for text in val_dict.keys(): for text in val_dict.keys():
header.append(text) header.append(text)
writer.writerow(header) writer.writerow(header)
for row in range(len(val_dict[dict_x[x]])): for row in range(len(val_dict[dict_x[x]])):
line = [] line = []
for var in val_dict.keys(): for var in val_dict.keys():
line.append(val_dict[var][row]) line.append(val_dict[var][row])
writer.writerow(line) writer.writerow(line)
self._timer.stop() self._timer.stop()
except Exception as e: except Exception as e:
self.message_box( self.message_box(
@@ -913,11 +928,11 @@ class ResultsWindow(PamhyrWindow):
# Translate dictionary keys # Translate dictionary keys
translated_dict = {} translated_dict = {}
translated_dict[dict_x["rk"]] = reach.geometry.get_rk()
for key in my_dict: for key in my_dict:
translated_dict[dict_y[key]] = my_dict[key] translated_dict[dict_y[key]] = my_dict[key]
translated_dict[dict_x["rk"]] = reach.geometry.get_rk()
return translated_dict return translated_dict
def _export_rk_compute_elevation(self, data): def _export_rk_compute_elevation(self, data):
@@ -1087,16 +1102,16 @@ class ResultsWindow(PamhyrWindow):
# Translate dictionary keys # Translate dictionary keys
translated_dict = {} translated_dict = {}
translated_dict[dict_x["time"]] = self._timestamps
for key in my_dict: for key in my_dict:
translated_dict[dict_y[key]] = my_dict[key] translated_dict[dict_y[key]] = my_dict[key]
translated_dict[dict_x["time"]] = self._timestamps
return translated_dict return translated_dict
def _export_time_compute_elevation(self, data): def _export_time_compute_elevation(self, data):
my_dict = data["my_dict"] my_dict = data["my_dict"]
reach = data["reach"] profile = data["profile"]
if reach.has_bedload(): if reach.has_bedload():
z_min = data["zfd"] z_min = data["zfd"]
@@ -1537,3 +1552,186 @@ class ResultsEnsembleWindow(ResultsWindow):
def update_table_selection_solver(self, ind): def update_table_selection_solver(self, ind):
return 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"]
+19
View File
@@ -130,6 +130,25 @@ class ResultsTranslate(MainTranslate):
"wet_area": self._dict["unit_wet_area"], "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: if self.pollutants is not None:
self._sub_dict["table_headers_raw_data"] = { self._sub_dict["table_headers_raw_data"] = {
"name": _translate("Results", "Profile"), "name": _translate("Results", "Profile"),
+1 -1
View File
@@ -107,7 +107,7 @@ class WindowToolKit(object):
dialog = QFileDialog(self, options=options) dialog = QFileDialog(self, options=options)
if select_file == "Existing_file": if select_file == "ExistingFile":
mode = QFileDialog.FileMode.ExistingFile mode = QFileDialog.FileMode.ExistingFile
elif select_file == "Directory": elif select_file == "Directory":
mode = QFileDialog.FileMode.Directory mode = QFileDialog.FileMode.Directory
+19 -3
View File
@@ -45,7 +45,6 @@ class CommonWordTranslate(PamhyrTranslate):
self._dict["loc"] = _translate("CommonWord", "Loc") self._dict["loc"] = _translate("CommonWord", "Loc")
self._dict["scale"] = _translate("CommonWord", "Scale") self._dict["scale"] = _translate("CommonWord", "Scale")
self._dict["lam"] = _translate("CommonWord", "Lam")
self._dict["reach"] = _translate("CommonWord", "Reach") self._dict["reach"] = _translate("CommonWord", "Reach")
self._dict["reaches"] = _translate("CommonWord", "Reaches") self._dict["reaches"] = _translate("CommonWord", "Reaches")
@@ -72,6 +71,9 @@ class CommonWordTranslate(PamhyrTranslate):
self._dict["file_csv"] = _translate( self._dict["file_csv"] = _translate(
"CommonWord", "CSV file (*.csv)" "CommonWord", "CSV file (*.csv)"
) )
self._dict["file_json"] = _translate(
"CommonWord", "JSON file (*.json)"
)
class UnitTranslate(CommonWordTranslate): class UnitTranslate(CommonWordTranslate):
@@ -110,6 +112,12 @@ class UnitTranslate(CommonWordTranslate):
self._dict["unit_water_elevation"] = _translate( self._dict["unit_water_elevation"] = _translate(
"Unit", "Water Elevation (m)" "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( self._dict["unit_water_elevation_envelop"] = _translate(
"Unit", "Water Elevation Envelop (m)" "Unit", "Water Elevation Envelop (m)"
) )
@@ -129,8 +137,16 @@ class UnitTranslate(CommonWordTranslate):
self._dict["unit_min_velocity"] = _translate( self._dict["unit_min_velocity"] = _translate(
"Unit", "Min Velocity (m/s)" "Unit", "Min Velocity (m/s)"
) )
self._dict["unit_discharge"] = _translate( self._dict["unit_discharge"] = (
"Unit", "Discharge") + f" (m³/s)" _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( self._dict["unit_discharge_envelop"] = _translate(
"Unit", "Discharge Envelop") + " (m³/s)" "Unit", "Discharge Envelop") + " (m³/s)"
self._dict["unit_max_discharge"] = _translate( 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>
+27
View File
@@ -33,6 +33,9 @@
<addaction name="action_add"/> <addaction name="action_add"/>
<addaction name="action_del"/> <addaction name="action_del"/>
<addaction name="action_edit"/> <addaction name="action_edit"/>
<addaction name="separator"/>
<addaction name="action_export"/>
<addaction name="action_import"/>
</widget> </widget>
<action name="action_add"> <action name="action_add">
<property name="icon"> <property name="icon">
@@ -79,6 +82,30 @@
<enum>QAction::NoRole</enum> <enum>QAction::NoRole</enum>
</property> </property>
</action> </action>
<action name="action_export">
<property name="icon">
<iconset>
<normaloff>ressources/export.png</normaloff>ressources/export.png</iconset>
</property>
<property name="text">
<string>Export</string>
</property>
<property name="toolTip">
<string>Export all ensemble configuration into json file</string>
</property>
</action>
<action name="action_import">
<property name="icon">
<iconset>
<normaloff>ressources/import.png</normaloff>ressources/import.png</iconset>
</property>
<property name="text">
<string>Import</string>
</property>
<property name="toolTip">
<string>Import ensemble configuration from json file</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>
+8 -1
View File
@@ -24,7 +24,14 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QDoubleSpinBox" name="doubleSpinBox_0"/> <widget class="QDoubleSpinBox" name="doubleSpinBox_0">
<property name="minimum">
<double>-10000000000.000000000000000</double>
</property>
<property name="maximum">
<double>10000000000.000000000000000</double>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>
+16 -2
View File
@@ -22,7 +22,14 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_0"/> <widget class="QDoubleSpinBox" name="doubleSpinBox_0">
<property name="minimum">
<double>-10000000000.000000000000000</double>
</property>
<property name="maximum">
<double>10000000000.000000000000000</double>
</property>
</widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_1"> <widget class="QLabel" name="label_1">
@@ -32,7 +39,14 @@
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_1"/> <widget class="QDoubleSpinBox" name="doubleSpinBox_1">
<property name="minimum">
<double>-10000000000.000000000000000</double>
</property>
<property name="maximum">
<double>10000000000.000000000000000</double>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
Binary file not shown.