mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
135 lines
3.4 KiB
Python
135 lines
3.4 KiB
Python
# -*- 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()
|