mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97867080d9 | ||
|
|
93a4b44143 | ||
|
|
5e3e5628d2 |
No files matched your search
@@ -252,3 +252,19 @@ class Ensemble(SQLSubModel):
|
||||
def target_data(self, target_data):
|
||||
self._target_data = target_data
|
||||
self._status.modified()
|
||||
|
||||
def get_data_dict(self):
|
||||
return {
|
||||
"name": self.name,
|
||||
"data_type": self.data_type,
|
||||
"target_data": self.target_data,
|
||||
"distribution": self.distribution,
|
||||
"params": self.params,
|
||||
}
|
||||
|
||||
def set_data_dict(self, data):
|
||||
self.name = data["name"]
|
||||
self.data_type = data["data_type"]
|
||||
self.target_data = data["target_data"]
|
||||
self.distribution = data["distribution"]
|
||||
self.params = data["params"]
|
||||
@@ -393,7 +393,7 @@ class Reach(SQLSubModel):
|
||||
class River(SQLSubModel):
|
||||
_sub_classes = [Reach]
|
||||
|
||||
def __init__(self, study, parent):
|
||||
def __init__(self, study, parent, init=True):
|
||||
super(River, self).__init__(
|
||||
id=-1, status=study.status,
|
||||
owner_scenario=study.status.scenario.id
|
||||
@@ -404,8 +404,9 @@ class River(SQLSubModel):
|
||||
|
||||
# Dict with timestamps as key
|
||||
self._reachs = []
|
||||
for i, _ in enumerate(self._study.river.enable_edges()):
|
||||
self.add(i)
|
||||
if init:
|
||||
for i, _ in enumerate(self._study.river.enable_edges()):
|
||||
self.add(i)
|
||||
|
||||
def __len__(self):
|
||||
return len(self._reachs)
|
||||
@@ -458,7 +459,7 @@ class River(SQLSubModel):
|
||||
study = data["study"]
|
||||
parent = data["parent"]
|
||||
|
||||
new_river = cls(study, parent)
|
||||
new_river = cls(study, parent, init=False)
|
||||
|
||||
for reach in study.river.reachs():
|
||||
data["reach"] = reach.reach
|
||||
|
||||
@@ -201,19 +201,22 @@ class EnsembleEditDialog(PamhyrDialog):
|
||||
return self._values
|
||||
|
||||
def accept(self):
|
||||
self._ensemble.name = self.get_line_edit_text("lineEdit_name")
|
||||
self._ensemble.data_type = self._target_data[0]
|
||||
self._ensemble.target_data = self._target_data[1]
|
||||
|
||||
txt = self.get_combobox_text("comboBox_distribution")
|
||||
self._ensemble.distribution = next(
|
||||
distribution = next(
|
||||
filter(
|
||||
lambda d: d.name == txt,
|
||||
self._study._ens_distributions.lst
|
||||
),
|
||||
None
|
||||
)
|
||||
self._ensemble.params = self._params_widget.values
|
||||
|
||||
self._values = {
|
||||
"name": self.get_line_edit_text("lineEdit_name"),
|
||||
"data_type": self._target_data[0],
|
||||
"target_data": self._target_data[1],
|
||||
"distribution": distribution,
|
||||
"params": self._params_widget.values,
|
||||
}
|
||||
|
||||
super().accept()
|
||||
|
||||
|
||||
@@ -133,3 +133,18 @@ class DelCommand(QUndoCommand):
|
||||
|
||||
def redo(self):
|
||||
self._ensembles.delete_i(self._rows)
|
||||
|
||||
|
||||
class SetAllCommand(QUndoCommand):
|
||||
def __init__(self, ensemble, data):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ensemble = ensemble
|
||||
self._old = self._ensemble.get_data_dict()
|
||||
self._new = data
|
||||
|
||||
def undo(self):
|
||||
self._ensemble.set_data_dict(self._old)
|
||||
|
||||
def redo(self):
|
||||
self._ensemble.set_data_dict(self._new)
|
||||
@@ -47,6 +47,7 @@ from View.Ensembles.Table import (
|
||||
EnsembleTableModel, ComboBoxDelegate
|
||||
)
|
||||
from View.Ensembles.Translate import EnsemblesTranslate
|
||||
from View.Ensembles.UndoCommand import SetAllCommand
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
@@ -194,7 +195,11 @@ class EnsemblesWindow(PamhyrWindow):
|
||||
)
|
||||
|
||||
if dlg.exec():
|
||||
return
|
||||
self._undo_stack.push(
|
||||
SetAllCommand(
|
||||
ens, dlg.values
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
return
|
||||
|
||||
@@ -102,6 +102,7 @@ class PlotHEnsemble(PamhyrPlot):
|
||||
return
|
||||
|
||||
self.draw_data(res_id)
|
||||
self.draw_data_std_derivation(res_id)
|
||||
|
||||
self.canvas.axes.set_xlabel(
|
||||
self._trad["unit_time_s"],
|
||||
@@ -159,6 +160,29 @@ class PlotHEnsemble(PamhyrPlot):
|
||||
|
||||
self._line.append(line)
|
||||
|
||||
@timer
|
||||
def draw_data_std_derivation(self, res_id):
|
||||
results = self.results[res_id]
|
||||
reach = results.river.reach(self._current_reach_id)
|
||||
|
||||
q = results.get("table")["q_mean"]
|
||||
std_deriv = results.get("table")["q_std_derivation"]
|
||||
profile = reach.profile(self._current_profile_id[0])
|
||||
|
||||
x = self._timestamps
|
||||
y = q[:, profile.global_index]
|
||||
std = std_deriv[:, profile.global_index]
|
||||
|
||||
y_b = y - std
|
||||
y_t = y + std
|
||||
|
||||
plot = self.canvas.axes.fill_between(
|
||||
x, y_b, y_t,
|
||||
label=f"Standard derivation {profile.name}",
|
||||
color=self.color_plot_ensemble_std_deriv,
|
||||
alpha=0.3,
|
||||
)
|
||||
|
||||
def draw_additional_data(self, res_id):
|
||||
results = self.results[res_id]
|
||||
|
||||
|
||||
Reference in new issue
Block a user