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_reach_id = reach_id
self._current_profile_id = profile_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 @property
def results(self): def results(self):
return self.data return self.data
@ -62,8 +70,7 @@ class PlotH(PamhyrPlot):
@timer @timer
def draw(self, highlight=None): def draw(self, highlight=None):
self.canvas.axes.cla() self.init_axes()
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
if self.results is None: if self.results is None:
return return
@ -75,87 +82,60 @@ class PlotH(PamhyrPlot):
self._init = False self._init = False
return return
kp_min, kp_max = (-1, -1) self.draw_max(reach)
if highlight is not None: self.draw_data(reach, profile)
kp_min, kp_max = highlight self.draw_current(reach, profile)
# Axes self.set_ticks_time_formater()
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.idle()
self._init = True
def draw_data(self, reach, profile):
self.ts = list(self.results.get("timestamps")) self.ts = list(self.results.get("timestamps"))
self.ts.sort() self.ts.sort()
# Draw discharge for each timestamp
x = self.ts x = self.ts
y = profile.get_key("Q") y = profile.get_key("Q")
self._line, = self.canvas.axes.plot( self._line, = self.canvas.axes.plot(
x, y, lw=1., x, y,
color='r', color=self.color_plot,
markersize=3, marker='+' **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, = self.canvas.axes.plot(
self._current_timestamp, self._current_timestamp,
y[self.ts.index(self._current_timestamp)], y[self.ts.index(self._current_timestamp)],
lw=1., color='b', color=self.color_plot_current,
markersize=3, marker='+' **kargs
) )
self.canvas.axes.relim() def draw_max(self, reach):
self.ts = list(self.results.get("timestamps"))
self.ts.sort()
# Custom time display x = self.ts
nb = len(x) y = []
mod = int(nb / 5) for ts in x:
mod = mod if mod > 0 else nb 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( self._line_max, = self.canvas.axes.plot(
map( x, y,
lambda x: x[1], color=self.color_plot_highlight,
filter( linestyle='dotted',
lambda x: x[0] % mod == 0, **self.plot_default_kargs
enumerate(x)
)
)
) )
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): def set_reach(self, reach_id):
self._current_reach_id = reach_id self._current_reach_id = reach_id

View File

@ -335,7 +335,7 @@ class ResultsWindow(PamhyrWindow):
fun = { fun = {
"reach": self._set_current_reach, "reach": self._set_current_reach,
"profile": self._set_current_profile, "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"]: for t in ["reach", "profile", "raw_data"]:
@ -375,7 +375,8 @@ class ResultsWindow(PamhyrWindow):
self._table["raw_data"].update(ind) self._table["raw_data"].update(ind)
def update_table_selection_profile(self, ind): def update_table_selection_profile(self, ind):
table = self.find(QTableView, f"tableView_profile") for t in ["profile", "raw_data"]:
table = self.find(QTableView, f"tableView_{t}")
selectionModel = table.selectionModel() selectionModel = table.selectionModel()
index = table.model().index(ind, 0) index = table.model().index(ind, 0)
@ -475,6 +476,16 @@ class ResultsWindow(PamhyrWindow):
self.update(profile_id=ind) self.update(profile_id=ind)
self._slider_profile.setValue(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): def _set_current_profile_slider(self):
pid = self._slider_profile.value() pid = self._slider_profile.value()
self.update(profile_id=pid) self.update(profile_id=pid)

View File

@ -145,17 +145,24 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tab_4"> <widget class="QWidget" name="tab_4">
<attribute name="title"> <attribute name="title">
<string>Raw data</string> <string>Raw data</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_5"> <layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0"> <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"/> <widget class="QTableView" name="tableView_raw_data"/>
</item> </item>
</layout> </layout>
</item>
</layout>
</widget> </widget>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
@ -232,6 +239,7 @@
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<addaction name="action_add"/> <addaction name="action_add"/>
<addaction name="action_export"/>
<addaction name="action_reload"/> <addaction name="action_reload"/>
</widget> </widget>
<action name="action_add"> <action name="action_add">
@ -251,6 +259,17 @@
<string>Reload</string> <string>Reload</string>
</property> </property>
</action> </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> </widget>
<resources/> <resources/>
<connections/> <connections/>