Results: Renew hydrograph.

setup.py
Pierre-Antoine Rouby 2024-02-16 16:56:46 +01:00
parent 065d94eb4a
commit 62fcafa982
3 changed files with 87 additions and 77 deletions

View File

@ -51,6 +51,14 @@ class PlotH(PamhyrPlot):
self._current_reach_id = reach_id
self._current_profile_id = profile_id
self.label_x = _translate("Results", "Time (s)")
self.label_y = _translate("Results", "Discharge (m³/s)")
self._isometric_axis = False
self._auto_relim_update = True
self._autoscale_update = True
@property
def results(self):
return self.data
@ -62,8 +70,7 @@ class PlotH(PamhyrPlot):
@timer
def draw(self, highlight=None):
self.canvas.axes.cla()
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
self.init_axes()
if self.results is None:
return
@ -75,87 +82,60 @@ class PlotH(PamhyrPlot):
self._init = False
return
kp_min, kp_max = (-1, -1)
if highlight is not None:
kp_min, kp_max = highlight
self.draw_max(reach)
self.draw_data(reach, profile)
self.draw_current(reach, profile)
# Axes
self.canvas.axes.set_xlabel(
_translate("Results", "Time (s)"),
color='black', fontsize=10
)
self.canvas.axes.set_ylabel(
_translate("Results", "Discharge (m³/s)"),
color='black', fontsize=10
)
self.set_ticks_time_formater()
self.idle()
self._init = True
def draw_data(self, reach, profile):
self.ts = list(self.results.get("timestamps"))
self.ts.sort()
# Draw discharge for each timestamp
x = self.ts
y = profile.get_key("Q")
self._line, = self.canvas.axes.plot(
x, y, lw=1.,
color='r',
markersize=3, marker='+'
x, y,
color=self.color_plot,
**self.plot_default_kargs
)
def draw_current(self, reach, profile):
y = profile.get_key("Q")
kargs = self.plot_default_kargs.copy()
kargs["marker"] = "o"
self._current, = self.canvas.axes.plot(
self._current_timestamp,
y[self.ts.index(self._current_timestamp)],
lw=1., color='b',
markersize=3, marker='+'
color=self.color_plot_current,
**kargs
)
self.canvas.axes.relim()
def draw_max(self, reach):
self.ts = list(self.results.get("timestamps"))
self.ts.sort()
# Custom time display
nb = len(x)
mod = int(nb / 5)
mod = mod if mod > 0 else nb
x = self.ts
y = []
for ts in x:
ts_y = -9999
for profile in reach.profiles:
q = profile.get_ts_key(ts, "Q")
ts_y = max(ts_y, q)
y.append(ts_y)
fx = list(
map(
lambda x: x[1],
filter(
lambda x: x[0] % mod == 0,
enumerate(x)
)
)
self._line_max, = self.canvas.axes.plot(
x, y,
color=self.color_plot_highlight,
linestyle='dotted',
**self.plot_default_kargs
)
if self._mode == "time":
t0 = datetime.fromtimestamp(0)
xt = list(
map(
lambda v: (
str(
datetime.fromtimestamp(v) - t0
).split(",")[0]
.replace("days", _translate("Results", "days"))
.replace("day", _translate("Results", "day"))
),
fx
)
)
else:
xt = list(
map(
lambda v: str(datetime.fromtimestamp(v).date()),
fx
)
)
self.canvas.axes.set_xticks(ticks=fx, labels=xt, rotation=45)
# self.canvas.axes.autoscale_view(True, True, True)
# self.canvas.axes.autoscale()
self.canvas.figure.tight_layout()
self.canvas.figure.canvas.draw_idle()
if self.toolbar is not None:
self.toolbar.update()
def set_reach(self, reach_id):
self._current_reach_id = reach_id

View File

@ -335,7 +335,7 @@ class ResultsWindow(PamhyrWindow):
fun = {
"reach": self._set_current_reach,
"profile": self._set_current_profile,
"raw_data": self._set_current_profile,
"raw_data": self._set_current_profile_raw_data,
}
for t in ["reach", "profile", "raw_data"]:
@ -375,17 +375,18 @@ class ResultsWindow(PamhyrWindow):
self._table["raw_data"].update(ind)
def update_table_selection_profile(self, ind):
table = self.find(QTableView, f"tableView_profile")
selectionModel = table.selectionModel()
index = table.model().index(ind, 0)
for t in ["profile", "raw_data"]:
table = self.find(QTableView, f"tableView_{t}")
selectionModel = table.selectionModel()
index = table.model().index(ind, 0)
selectionModel.select(
index,
QItemSelectionModel.Rows |
QItemSelectionModel.ClearAndSelect |
QItemSelectionModel.Select
)
table.scrollTo(index)
selectionModel.select(
index,
QItemSelectionModel.Rows |
QItemSelectionModel.ClearAndSelect |
QItemSelectionModel.Select
)
table.scrollTo(index)
def update(self, reach_id=None, profile_id=None, timestamp=None):
if reach_id is not None:
@ -475,6 +476,16 @@ class ResultsWindow(PamhyrWindow):
self.update(profile_id=ind)
self._slider_profile.setValue(ind)
def _set_current_profile_raw_data(self):
table = self.find(QTableView, f"tableView_raw_data")
indexes = table.selectedIndexes()
if len(indexes) == 0:
return
ind = indexes[0].row()
self.update(profile_id=ind)
self._slider_profile.setValue(ind)
def _set_current_profile_slider(self):
pid = self._slider_profile.value()
self.update(profile_id=pid)

View File

@ -145,15 +145,22 @@
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab_4">
<attribute name="title">
<string>Raw data</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QTableView" name="tableView_raw_data"/>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4"/>
</item>
<item>
<widget class="QTableView" name="tableView_raw_data"/>
</item>
</layout>
</item>
</layout>
</widget>
@ -232,6 +239,7 @@
<bool>false</bool>
</attribute>
<addaction name="action_add"/>
<addaction name="action_export"/>
<addaction name="action_reload"/>
</widget>
<action name="action_add">
@ -251,6 +259,17 @@
<string>Reload</string>
</property>
</action>
<action name="action_export">
<property name="text">
<string>Export</string>
</property>
<property name="toolTip">
<string>Export raw data</string>
</property>
<property name="shortcut">
<string>Ctrl+E</string>
</property>
</action>
</widget>
<resources/>
<connections/>