mirror of https://gitlab.com/pamhyr/pamhyr2
Results, Sediment: Add sediment results plots.
parent
596cd24cc3
commit
d7a8e5de20
|
|
@ -0,0 +1,130 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
|
from tools import timer
|
||||||
|
from View.Plot.APlot import APlot
|
||||||
|
|
||||||
|
from PyQt5.QtCore import (
|
||||||
|
QCoreApplication
|
||||||
|
)
|
||||||
|
|
||||||
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
class PlotSedProfile(APlot):
|
||||||
|
def __init__(self, canvas=None, study=None, results=None,
|
||||||
|
reach_id=0, profile_id=0,
|
||||||
|
toolbar=None):
|
||||||
|
super(PlotSedProfile, self).__init__(
|
||||||
|
canvas=canvas,
|
||||||
|
data=study,
|
||||||
|
toolbar=toolbar
|
||||||
|
)
|
||||||
|
|
||||||
|
self._results = results
|
||||||
|
|
||||||
|
self._current_timestamp = max(results.get("timestamps"))
|
||||||
|
self._current_reach_id = reach_id
|
||||||
|
self._current_profile_id = profile_id
|
||||||
|
|
||||||
|
@timer
|
||||||
|
def draw(self):
|
||||||
|
self.canvas.axes.cla()
|
||||||
|
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||||
|
|
||||||
|
if self.data is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
reach = self._results.river.reach(self._current_reach_id)
|
||||||
|
profile = reach.profile(self._current_profile_id)
|
||||||
|
if profile.geometry.number_points == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.canvas.axes.set_xlabel(
|
||||||
|
_translate("MainWindow_reach", "X (m)"),
|
||||||
|
color='green', fontsize=12
|
||||||
|
)
|
||||||
|
self.canvas.axes.set_ylabel(
|
||||||
|
_translate("MainWindow_reach", "Height (m)"),
|
||||||
|
color='green', fontsize=12
|
||||||
|
)
|
||||||
|
|
||||||
|
x = profile.geometry.get_station()
|
||||||
|
z = profile.geometry.z()
|
||||||
|
|
||||||
|
psl = list(
|
||||||
|
map(
|
||||||
|
lambda sl: sl[0],
|
||||||
|
profile.get_ts_key(self._current_timestamp, "sl")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
sl = []
|
||||||
|
for i in range(len(psl)):
|
||||||
|
cur = []
|
||||||
|
for p in range(profile.geometry.number_points):
|
||||||
|
cur.append(psl[i])
|
||||||
|
sl.append(cur)
|
||||||
|
|
||||||
|
# logger.info(sl)
|
||||||
|
|
||||||
|
self.canvas.axes.set_xlim(
|
||||||
|
left = min(x), right = max(x)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Compute sediment layer in function to point z
|
||||||
|
z_sl = reduce(
|
||||||
|
lambda acc, v: acc + [
|
||||||
|
list(
|
||||||
|
map(lambda x, y: y - x, v, acc[-1])
|
||||||
|
)
|
||||||
|
],
|
||||||
|
sl,
|
||||||
|
[z]
|
||||||
|
)
|
||||||
|
|
||||||
|
self.line_kp_sl = []
|
||||||
|
for i, zsl in enumerate(reversed(z_sl)):
|
||||||
|
self.line_kp_sl.append(None)
|
||||||
|
self.line_kp_sl[i], = self.canvas.axes.plot(
|
||||||
|
x, zsl,
|
||||||
|
linestyle="solid" if i == len(z_sl) - 1 else "--",
|
||||||
|
lw=1.8,
|
||||||
|
color='grey' if i == len(z_sl) - 1 else None
|
||||||
|
)
|
||||||
|
|
||||||
|
self.canvas.figure.tight_layout()
|
||||||
|
self.canvas.figure.canvas.draw_idle()
|
||||||
|
if self.toolbar is not None:
|
||||||
|
self.toolbar.update()
|
||||||
|
|
||||||
|
self._init = False
|
||||||
|
|
||||||
|
@timer
|
||||||
|
def update(self, ind=None):
|
||||||
|
if self._init == False:
|
||||||
|
self.draw()
|
||||||
|
return
|
||||||
|
|
||||||
|
if ind is None:
|
||||||
|
logger.info("TODO: Update")
|
||||||
|
|
||||||
|
self.canvas.axes.autoscale_view(True, True, True)
|
||||||
|
self.canvas.figure.canvas.draw_idle()
|
||||||
|
|
||||||
|
def set_reach(self, reach_id):
|
||||||
|
self._current_reach_id = reach_id
|
||||||
|
self._current_profile_id = 0
|
||||||
|
self.draw()
|
||||||
|
|
||||||
|
def set_profile(self, profile_id):
|
||||||
|
self._current_profile_id = profile_id
|
||||||
|
self.draw()
|
||||||
|
|
||||||
|
def set_timestamp(self, timestamp):
|
||||||
|
self._current_timestamp = timestamp
|
||||||
|
self.draw()
|
||||||
|
|
@ -0,0 +1,134 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
|
from tools import timer
|
||||||
|
from View.Plot.APlot import APlot
|
||||||
|
|
||||||
|
from PyQt5.QtCore import (
|
||||||
|
QCoreApplication
|
||||||
|
)
|
||||||
|
|
||||||
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
class PlotSedReach(APlot):
|
||||||
|
def __init__(self, canvas=None, study=None, results=None,
|
||||||
|
reach_id=0, profile_id=0,
|
||||||
|
toolbar=None):
|
||||||
|
super(PlotSedReach, self).__init__(
|
||||||
|
canvas=canvas,
|
||||||
|
data=study,
|
||||||
|
toolbar=toolbar
|
||||||
|
)
|
||||||
|
|
||||||
|
self._results = results
|
||||||
|
|
||||||
|
self._current_timestamp = max(results.get("timestamps"))
|
||||||
|
self._current_reach_id = reach_id
|
||||||
|
self._current_profile_id = profile_id
|
||||||
|
|
||||||
|
@timer
|
||||||
|
def draw(self):
|
||||||
|
self.canvas.axes.cla()
|
||||||
|
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||||
|
|
||||||
|
if self.data is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
reach = self._results.river.reach(self._current_reach_id)
|
||||||
|
if reach.geometry.number_profiles == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.canvas.axes.set_xlabel(
|
||||||
|
_translate("MainWindow_reach", "Kp (m)"),
|
||||||
|
color='green', fontsize=12
|
||||||
|
)
|
||||||
|
self.canvas.axes.set_ylabel(
|
||||||
|
_translate("MainWindow_reach", "Height (m)"),
|
||||||
|
color='green', fontsize=12
|
||||||
|
)
|
||||||
|
|
||||||
|
kp = reach.geometry.get_kp()
|
||||||
|
z_min = reach.geometry.get_z_min()
|
||||||
|
z_max = reach.geometry.get_z_max()
|
||||||
|
|
||||||
|
psl = list(
|
||||||
|
map(
|
||||||
|
# Get SL list for profile p
|
||||||
|
lambda p: p.get_ts_key(self._current_timestamp, "sl"),
|
||||||
|
reach.profiles
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
max_sl = reduce(
|
||||||
|
lambda acc, sl: max(acc, len(sl)),
|
||||||
|
psl,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
|
||||||
|
sl = []
|
||||||
|
for i in range(max_sl):
|
||||||
|
cur = []
|
||||||
|
for csl in psl:
|
||||||
|
if i < len(csl):
|
||||||
|
cur.append(csl[i][0])
|
||||||
|
else:
|
||||||
|
cur.append(0)
|
||||||
|
sl.append(cur)
|
||||||
|
|
||||||
|
# logger.info(f"sl = {sl}")
|
||||||
|
|
||||||
|
self.canvas.axes.set_xlim(
|
||||||
|
left = min(kp), right = max(kp)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Compute sediment layer in function to profile z_min
|
||||||
|
z_sl = reduce(
|
||||||
|
lambda acc, v: acc + [
|
||||||
|
list(
|
||||||
|
map(lambda x, y: y - x, v, acc[-1])
|
||||||
|
)
|
||||||
|
],
|
||||||
|
sl,
|
||||||
|
[z_min]
|
||||||
|
)
|
||||||
|
|
||||||
|
self.line_kp_sl = []
|
||||||
|
for i, z in enumerate(reversed(z_sl)):
|
||||||
|
self.line_kp_sl.append(None)
|
||||||
|
self.line_kp_sl[i], = self.canvas.axes.plot(
|
||||||
|
kp, z,
|
||||||
|
linestyle="solid" if i == len(z_sl) - 1 else "--",
|
||||||
|
lw=1.8,
|
||||||
|
color='grey' if i == len(z_sl) - 1 else None
|
||||||
|
)
|
||||||
|
|
||||||
|
self.canvas.figure.tight_layout()
|
||||||
|
self.canvas.figure.canvas.draw_idle()
|
||||||
|
if self.toolbar is not None:
|
||||||
|
self.toolbar.update()
|
||||||
|
|
||||||
|
self._init = False
|
||||||
|
|
||||||
|
@timer
|
||||||
|
def update(self, ind=None):
|
||||||
|
if self._init == False:
|
||||||
|
self.draw()
|
||||||
|
return
|
||||||
|
|
||||||
|
def set_reach(self, reach_id):
|
||||||
|
self._current_reach_id = reach_id
|
||||||
|
self._current_profile_id = 0
|
||||||
|
self.draw()
|
||||||
|
|
||||||
|
def set_profile(self, profile_id):
|
||||||
|
self._current_profile_id = profile_id
|
||||||
|
self.draw()
|
||||||
|
|
||||||
|
def set_timestamp(self, timestamp):
|
||||||
|
self._current_timestamp = timestamp
|
||||||
|
self.draw()
|
||||||
|
|
@ -46,6 +46,8 @@ from View.Results.PlotXY import PlotXY
|
||||||
from View.Results.PlotAC import PlotAC
|
from View.Results.PlotAC import PlotAC
|
||||||
from View.Results.PlotKPC import PlotKPC
|
from View.Results.PlotKPC import PlotKPC
|
||||||
from View.Results.PlotH import PlotH
|
from View.Results.PlotH import PlotH
|
||||||
|
from View.Results.PlotSedReach import PlotSedReach
|
||||||
|
from View.Results.PlotSedProfile import PlotSedProfile
|
||||||
|
|
||||||
from View.Results.Table import TableModel
|
from View.Results.Table import TableModel
|
||||||
from View.Results.translate import *
|
from View.Results.translate import *
|
||||||
|
|
@ -180,6 +182,37 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow):
|
||||||
)
|
)
|
||||||
self.plot_h.draw()
|
self.plot_h.draw()
|
||||||
|
|
||||||
|
|
||||||
|
self.canvas_5 = MplCanvas(width=5, height=4, dpi=100)
|
||||||
|
self.canvas_5.setObjectName("canvas_5")
|
||||||
|
self.plot_layout_5 = self.find(QVBoxLayout, "verticalLayout_sed_reach")
|
||||||
|
self.plot_layout_5.addWidget(self.canvas_5)
|
||||||
|
|
||||||
|
self.plot_sed_reach = PlotSedReach(
|
||||||
|
canvas = self.canvas_5,
|
||||||
|
results = self._results,
|
||||||
|
study = self._study,
|
||||||
|
reach_id = 0,
|
||||||
|
profile_id = 0,
|
||||||
|
toolbar = None
|
||||||
|
)
|
||||||
|
self.plot_sed_reach.draw()
|
||||||
|
|
||||||
|
self.canvas_6 = MplCanvas(width=5, height=4, dpi=100)
|
||||||
|
self.canvas_6.setObjectName("canvas_6")
|
||||||
|
self.plot_layout_6 = self.find(QVBoxLayout, "verticalLayout_sed_profile")
|
||||||
|
self.plot_layout_6.addWidget(self.canvas_6)
|
||||||
|
|
||||||
|
self.plot_sed_profile = PlotSedProfile(
|
||||||
|
canvas = self.canvas_6,
|
||||||
|
results = self._results,
|
||||||
|
study = self._study,
|
||||||
|
reach_id = 0,
|
||||||
|
profile_id = 0,
|
||||||
|
toolbar = None
|
||||||
|
)
|
||||||
|
self.plot_sed_profile.draw()
|
||||||
|
|
||||||
def setup_connections(self):
|
def setup_connections(self):
|
||||||
self.undo_sc.activated.connect(self.undo)
|
self.undo_sc.activated.connect(self.undo)
|
||||||
self.redo_sc.activated.connect(self.redo)
|
self.redo_sc.activated.connect(self.redo)
|
||||||
|
|
@ -210,21 +243,29 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow):
|
||||||
self.plot_ac.set_reach(reach_id)
|
self.plot_ac.set_reach(reach_id)
|
||||||
self.plot_kpc.set_reach(reach_id)
|
self.plot_kpc.set_reach(reach_id)
|
||||||
self.plot_h.set_reach(reach_id)
|
self.plot_h.set_reach(reach_id)
|
||||||
|
self.plot_sed_reach.set_reach(reach_id)
|
||||||
|
self.plot_sed_profile.set_reach(reach_id)
|
||||||
if profile_id is not None:
|
if profile_id is not None:
|
||||||
self.plot_xy.set_profile(profile_id)
|
self.plot_xy.set_profile(profile_id)
|
||||||
self.plot_ac.set_profile(profile_id)
|
self.plot_ac.set_profile(profile_id)
|
||||||
self.plot_kpc.set_profile(profile_id)
|
self.plot_kpc.set_profile(profile_id)
|
||||||
self.plot_h.set_profile(profile_id)
|
self.plot_h.set_profile(profile_id)
|
||||||
|
self.plot_sed_reach.set_profile(profile_id)
|
||||||
|
self.plot_sed_profile.set_profile(profile_id)
|
||||||
if timestamp is not None:
|
if timestamp is not None:
|
||||||
self.plot_xy.set_timestamp(timestamp)
|
self.plot_xy.set_timestamp(timestamp)
|
||||||
self.plot_ac.set_timestamp(timestamp)
|
self.plot_ac.set_timestamp(timestamp)
|
||||||
self.plot_kpc.set_timestamp(timestamp)
|
self.plot_kpc.set_timestamp(timestamp)
|
||||||
self.plot_h.set_timestamp(timestamp)
|
self.plot_h.set_timestamp(timestamp)
|
||||||
|
self.plot_sed_reach.set_timestamp(timestamp)
|
||||||
|
self.plot_sed_profile.set_timestamp(timestamp)
|
||||||
|
|
||||||
self.plot_xy.draw()
|
self.plot_xy.draw()
|
||||||
self.plot_ac.draw()
|
self.plot_ac.draw()
|
||||||
self.plot_kpc.draw()
|
self.plot_kpc.draw()
|
||||||
self.plot_h.draw()
|
self.plot_h.draw()
|
||||||
|
self.plot_sed_reach.draw()
|
||||||
|
self.plot_sed_profile.draw()
|
||||||
|
|
||||||
|
|
||||||
def _set_current_reach(self):
|
def _set_current_reach(self):
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
<widget class="QTableView" name="tableView_reach"/>
|
<widget class="QTableView" name="tableView_reach"/>
|
||||||
<widget class="QTableView" name="tableView_profile"/>
|
<widget class="QTableView" name="tableView_profile"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="">
|
<widget class="QWidget" name="layoutWidget">
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
|
|
@ -75,6 +75,32 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_3">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Sediment</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_5">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QSplitter" name="splitter_5">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="verticalLayoutWidget_4">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_sed_reach"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="verticalLayoutWidget_5">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_sed_profile"/>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue