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