diff --git a/src/Model/SedimentLayer/SedimentLayer.py b/src/Model/SedimentLayer/SedimentLayer.py index 44838baab65d0bc9622a76e14f8bf959d7875028..b31238cdc503442186e8287db057c456d7a2b1f6 100644 --- a/src/Model/SedimentLayer/SedimentLayer.py +++ b/src/Model/SedimentLayer/SedimentLayer.py @@ -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 diff --git a/src/View/SedimentLayers/Edit/Plot.py b/src/View/SedimentLayers/Edit/Plot.py index 0a0487d23cb2632c909d25aafc21036a22dc2aad..72f7cfb45a73d7b704ad3be86a6a2772171760cc 100644 --- a/src/View/SedimentLayers/Edit/Plot.py +++ b/src/View/SedimentLayers/Edit/Plot.py @@ -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() - names = ["bottom"] + self.data.names() - self.canvas.axes.set_xlim( - left=min(x), right=max(x) - ) + z_sl = self.data.compute_height_from_bottom(z) + names = ["bottom"] + self.data.names() - 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() diff --git a/src/View/SedimentLayers/Edit/Window.py b/src/View/SedimentLayers/Edit/Window.py index 2c19c0e15968198bbd1f73052109fe7f1c6a7454..4ae43ba63be2724ba6b5049d716f2b1dbb1e20f8 100644 --- a/src/View/SedimentLayers/Edit/Window.py +++ b/src/View/SedimentLayers/Edit/Window.py @@ -114,7 +114,6 @@ class EditSedimentLayersWindow(PamhyrWindow): data=self._sl, toolbar=self.toolbar, trad=self._trad, - display_current=False ) self.plot.draw() diff --git a/src/View/SedimentLayers/Reach/Plot.py b/src/View/SedimentLayers/Reach/Plot.py index ef354b778a192117203a783727fc261a597ffcc9..5198128aaa521218e15b1a0bff5bc75141df87e9 100644 --- a/src/View/SedimentLayers/Reach/Plot.py +++ b/src/View/SedimentLayers/Reach/Plot.py @@ -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() diff --git a/src/View/SedimentLayers/Reach/Profile/Plot.py b/src/View/SedimentLayers/Reach/Profile/Plot.py index 00ab9efee5d4da62db7bf60d8c4f1e2355893f2a..fe92bf760cad2a7e34315591ea4a5ab49fcf78a0 100644 --- a/src/View/SedimentLayers/Reach/Profile/Plot.py +++ b/src/View/SedimentLayers/Reach/Profile/Plot.py @@ -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() diff --git a/src/View/SedimentLayers/Reach/Profile/Window.py b/src/View/SedimentLayers/Reach/Profile/Window.py index b7bdec221d575cef84ec0fffd7c04e34163963bd..63be359db626e5d285070bf364dc6c946eff989a 100644 --- a/src/View/SedimentLayers/Reach/Profile/Window.py +++ b/src/View/SedimentLayers/Reach/Profile/Window.py @@ -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() diff --git a/src/View/SedimentLayers/Reach/Profile/translate.py b/src/View/SedimentLayers/Reach/Profile/translate.py index c811b18873c4b02f3e0266d3a292c35054716265..ab1b177c7237a28cc77a66c9c45d74d951e637ba 100644 --- a/src/View/SedimentLayers/Reach/Profile/translate.py +++ b/src/View/SedimentLayers/Reach/Profile/translate.py @@ -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" ) diff --git a/src/View/SedimentLayers/Reach/Window.py b/src/View/SedimentLayers/Reach/Window.py index 0d8fefdc109f642acd8e46e14bad4c8cbdf38059..51d8dc4157be0dc212c91532b54c9e1ecb53e166 100644 --- a/src/View/SedimentLayers/Reach/Window.py +++ b/src/View/SedimentLayers/Reach/Window.py @@ -134,7 +134,6 @@ class ReachSedimentLayersWindow(PamhyrWindow): data=self._reach, toolbar=self.toolbar, trad=self._trad, - display_current=False ) self.plot.draw() diff --git a/src/View/SedimentLayers/Window.py b/src/View/SedimentLayers/Window.py index 758c6874a2840dfe222a56f5dc75183047ad102f..66188298340767f8eec1f711af5c7efab053444b 100644 --- a/src/View/SedimentLayers/Window.py +++ b/src/View/SedimentLayers/Window.py @@ -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()