mirror of https://gitlab.com/pamhyr/pamhyr2
SL: Apply new PamhyrPlot features.
parent
d1d63c8c29
commit
9302d1fabc
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from functools import reduce
|
||||
|
||||
from tools import trace, timer
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
|
|
@ -362,3 +364,29 @@ class SedimentLayer(SQLSubModel):
|
|||
lst[index], lst[prev] = lst[prev], lst[index]
|
||||
|
||||
self._status.modified()
|
||||
|
||||
def compute_height_from_bottom(self, bottom_elevation: list):
|
||||
sl_height = self.height()
|
||||
|
||||
sl_height_by_profile = []
|
||||
for i in range(len(sl_height)):
|
||||
cur_profile = []
|
||||
for _ in bottom_elevation:
|
||||
cur_profile.append(sl_height[i])
|
||||
|
||||
sl_height_by_profile.append(cur_profile)
|
||||
|
||||
z_sl = reduce(
|
||||
lambda acc, current_sl: acc + [
|
||||
list(
|
||||
map(
|
||||
lambda cur_sl_h, prev_sl_h: prev_sl_h - cur_sl_h,
|
||||
current_sl, acc[-1]
|
||||
)
|
||||
)
|
||||
],
|
||||
sl_height_by_profile,
|
||||
[bottom_elevation]
|
||||
)
|
||||
|
||||
return z_sl
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@ logger = logging.getLogger()
|
|||
|
||||
class Plot(PamhyrPlot):
|
||||
def __init__(self, canvas=None, trad=None, data=None,
|
||||
toolbar=None, display_current=True,
|
||||
parent=None):
|
||||
toolbar=None, parent=None):
|
||||
super(Plot, self).__init__(
|
||||
canvas=canvas,
|
||||
trad=trad,
|
||||
|
|
@ -38,51 +37,40 @@ class Plot(PamhyrPlot):
|
|||
parent=parent
|
||||
)
|
||||
|
||||
self._display_current = display_current
|
||||
self.label_x = ""
|
||||
self.canvas.axes.axes.get_xaxis().set_visible(False)
|
||||
|
||||
self.label_y = self._trad["height"]
|
||||
|
||||
self.line_kp_zmin = None
|
||||
self.line_kp_sl = []
|
||||
|
||||
self._isometric_axis = False
|
||||
|
||||
self._auto_relim = False
|
||||
self._auto_relim_update = False
|
||||
self._autoscale_update = True
|
||||
|
||||
@timer
|
||||
def draw(self):
|
||||
self.canvas.axes.cla()
|
||||
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||
|
||||
self.canvas.axes.axes.get_xaxis().set_visible(False)
|
||||
self.canvas.axes.set_ylabel(
|
||||
self._trad["height"],
|
||||
color='black', fontsize=10
|
||||
)
|
||||
self.init_axes()
|
||||
|
||||
if self.data is None:
|
||||
return
|
||||
|
||||
self.draw_data()
|
||||
|
||||
self.idle()
|
||||
self._init = True
|
||||
|
||||
def draw_data(self):
|
||||
x = [0, 1]
|
||||
z = [0, 0]
|
||||
sl = self.data.height()
|
||||
|
||||
z_sl = self.data.compute_height_from_bottom(z)
|
||||
names = ["bottom"] + self.data.names()
|
||||
|
||||
self.canvas.axes.set_xlim(
|
||||
left=min(x), right=max(x)
|
||||
)
|
||||
|
||||
lsl = []
|
||||
for i in range(len(sl)):
|
||||
cur = []
|
||||
for _ in x:
|
||||
cur.append(sl[i])
|
||||
lsl.append(cur)
|
||||
|
||||
# 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])
|
||||
)
|
||||
],
|
||||
lsl,
|
||||
[z]
|
||||
)
|
||||
self.canvas.axes.set_xlim(*x)
|
||||
|
||||
for i, zsl in enumerate(reversed(z_sl)):
|
||||
self.line_kp_sl.append(None)
|
||||
|
|
@ -90,27 +78,14 @@ class Plot(PamhyrPlot):
|
|||
x, zsl,
|
||||
label=names[-(i+1)],
|
||||
linestyle="solid" if i == len(names) - 1 else "--",
|
||||
lw=1.8,
|
||||
lw=1.5,
|
||||
color='grey' if i == len(names) - 1 else None
|
||||
)
|
||||
self.canvas.axes.text(
|
||||
x[0] + 0.01, zsl[0] + 0.01, f'{names[-(i+1)]}')
|
||||
|
||||
self.canvas.figure.tight_layout()
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
if self.toolbar is not None:
|
||||
self.toolbar.update()
|
||||
|
||||
self._init = True
|
||||
x[0] + 0.01, zsl[0] + 0.01,
|
||||
f'{names[-(i+1)]}'
|
||||
)
|
||||
|
||||
@timer
|
||||
def update(self, ind=None):
|
||||
if not self._init:
|
||||
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 update(self):
|
||||
self.draw()
|
||||
|
|
|
|||
|
|
@ -114,7 +114,6 @@ class EditSedimentLayersWindow(PamhyrWindow):
|
|||
data=self._sl,
|
||||
toolbar=self.toolbar,
|
||||
trad=self._trad,
|
||||
display_current=False
|
||||
)
|
||||
self.plot.draw()
|
||||
|
||||
|
|
|
|||
|
|
@ -33,9 +33,8 @@ logger = logging.getLogger()
|
|||
|
||||
|
||||
class Plot(PamhyrPlot):
|
||||
def __init__(self, data=None, display_current=True,
|
||||
canvas=None, trad=None, toolbar=None,
|
||||
parent=None):
|
||||
def __init__(self, data=None, canvas=None, trad=None,
|
||||
toolbar=None, parent=None):
|
||||
super(Plot, self).__init__(
|
||||
canvas=canvas,
|
||||
trad=trad,
|
||||
|
|
@ -44,15 +43,21 @@ class Plot(PamhyrPlot):
|
|||
parent=parent
|
||||
)
|
||||
|
||||
self._display_current = display_current
|
||||
self.label_x = self._trad["kp"]
|
||||
self.label_y = self._trad["height"]
|
||||
|
||||
self.line_kp_zmin = None
|
||||
self.line_kp_sl = []
|
||||
|
||||
self._isometric_axis = False
|
||||
|
||||
self._auto_relim = False
|
||||
self._auto_relim_update = False
|
||||
self._autoscale_update = True
|
||||
|
||||
@timer
|
||||
def draw(self):
|
||||
self.canvas.axes.cla()
|
||||
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||
self.init_axes()
|
||||
|
||||
if self.data is None:
|
||||
return
|
||||
|
|
@ -60,29 +65,27 @@ class Plot(PamhyrPlot):
|
|||
if self.data.number_profiles == 0:
|
||||
return
|
||||
|
||||
self.canvas.axes.set_xlabel(
|
||||
self._trad["kp"],
|
||||
color='black', fontsize=10
|
||||
)
|
||||
self.canvas.axes.set_ylabel(
|
||||
self._trad["height"],
|
||||
color='black', fontsize=10
|
||||
)
|
||||
self.draw_data()
|
||||
|
||||
self.idle()
|
||||
self._init = True
|
||||
|
||||
def draw_data(self):
|
||||
kp = self.data.get_kp()
|
||||
sl = self.data.get_sl()
|
||||
z_min = self.data.get_z_min()
|
||||
z_max = self.data.get_z_max()
|
||||
|
||||
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 + [
|
||||
lambda acc, current_sl: acc + [
|
||||
list(
|
||||
map(lambda x, y: y - x, v, acc[-1])
|
||||
map(
|
||||
lambda cur_sl_h, prev_sl_h: prev_sl_h - cur_sl_h,
|
||||
current_sl, acc[-1]
|
||||
)
|
||||
)
|
||||
],
|
||||
sl,
|
||||
|
|
@ -94,29 +97,10 @@ class Plot(PamhyrPlot):
|
|||
self.line_kp_sl[i], = self.canvas.axes.plot(
|
||||
kp, z,
|
||||
linestyle="solid" if i == len(z_sl) - 1 else "--",
|
||||
lw=1.8,
|
||||
lw=1.5,
|
||||
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 = True
|
||||
|
||||
@timer
|
||||
def update(self, ind=None):
|
||||
if not self._init:
|
||||
self.draw()
|
||||
return
|
||||
|
||||
if ind is None:
|
||||
kp = self.data.get_kp()
|
||||
z_min = self.data.get_z_min()
|
||||
z_max = self.data.get_z_max()
|
||||
|
||||
self.line_kp_zmin.set_data(kp, z_min)
|
||||
|
||||
self.canvas.axes.autoscale_view(True, True, True)
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
def update(self):
|
||||
self.draw()
|
||||
|
|
|
|||
|
|
@ -33,9 +33,8 @@ logger = logging.getLogger()
|
|||
|
||||
|
||||
class Plot(PamhyrPlot):
|
||||
def __init__(self, data=None, display_current=True,
|
||||
canvas=None, trad=None, toolbar=None,
|
||||
parent=None):
|
||||
def __init__(self, data=None, canvas=None, trad=None,
|
||||
toolbar=None, parent=None):
|
||||
super(Plot, self).__init__(
|
||||
canvas=canvas,
|
||||
trad=trad,
|
||||
|
|
@ -44,15 +43,21 @@ class Plot(PamhyrPlot):
|
|||
parent=parent
|
||||
)
|
||||
|
||||
self._display_current = display_current
|
||||
self.label_x = self._trad["x"]
|
||||
self.label_y = self._trad["height"]
|
||||
|
||||
self.line_kp_zmin = None
|
||||
self.line_kp_sl = []
|
||||
|
||||
self._isometric_axis = False
|
||||
|
||||
self._auto_relim = False
|
||||
self._auto_relim_update = False
|
||||
self._autoscale_update = True
|
||||
|
||||
@timer
|
||||
def draw(self):
|
||||
self.canvas.axes.cla()
|
||||
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||
self.init_axes()
|
||||
|
||||
if self.data is None:
|
||||
return
|
||||
|
|
@ -60,24 +65,16 @@ class Plot(PamhyrPlot):
|
|||
if self.data.number_points == 0:
|
||||
return
|
||||
|
||||
self.canvas.axes.set_xlabel(
|
||||
_translate("MainWindow_reach", "X (m)"),
|
||||
color='black', fontsize=10
|
||||
)
|
||||
self.canvas.axes.set_ylabel(
|
||||
_translate("MainWindow_reach", "Height (m)"),
|
||||
color='black', fontsize=10
|
||||
)
|
||||
self.draw_data()
|
||||
|
||||
self.idle()
|
||||
self._init = True
|
||||
|
||||
def draw_data(self):
|
||||
x = self.data.get_station()
|
||||
z = self.data.z()
|
||||
sl = self.data.get_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(
|
||||
|
|
@ -97,21 +94,6 @@ class Plot(PamhyrPlot):
|
|||
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 = True
|
||||
|
||||
@timer
|
||||
def update(self, ind=None):
|
||||
if not self._init:
|
||||
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 update(self):
|
||||
self.draw()
|
||||
|
|
|
|||
|
|
@ -140,8 +140,8 @@ class ProfileSedimentLayersWindow(PamhyrWindow):
|
|||
self.plot = Plot(
|
||||
canvas=self.canvas,
|
||||
data=self._profile,
|
||||
trad=self._trad,
|
||||
toolbar=self.toolbar,
|
||||
display_current=False
|
||||
)
|
||||
self.plot.draw()
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,14 @@ class SedimentProfileTranslate(SedimentReachTranslate):
|
|||
def __init__(self):
|
||||
super(SedimentProfileTranslate, self).__init__()
|
||||
|
||||
self._dict["x"] = _translate(
|
||||
"SedimentLayers", "X (m)"
|
||||
)
|
||||
self._dict["height"] = _translate(
|
||||
"SedimentLayers", "Height (m)"
|
||||
)
|
||||
|
||||
|
||||
self._dict["Profile sediment layers"] = _translate(
|
||||
"SedimentLayers", "Profile sediment layers"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -134,7 +134,6 @@ class ReachSedimentLayersWindow(PamhyrWindow):
|
|||
data=self._reach,
|
||||
toolbar=self.toolbar,
|
||||
trad=self._trad,
|
||||
display_current=False
|
||||
)
|
||||
self.plot.draw()
|
||||
|
||||
|
|
|
|||
|
|
@ -122,7 +122,6 @@ class SedimentLayersWindow(PamhyrWindow):
|
|||
data=self._sediment_layers.get(rows[0]),
|
||||
trad=self._trad,
|
||||
toolbar=None,
|
||||
display_current=False
|
||||
)
|
||||
self.plot.draw()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue