From 6b64e5cc99c3f1cf5414fe4d000e2d0998e1139d Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Tue, 22 Aug 2023 15:33:32 +0200 Subject: [PATCH] Results, Sediment: Change sediment display algorithme. --- src/View/Results/PlotSedProfile.py | 41 ++++++++++++++++++----- src/View/Results/PlotSedReach.py | 54 +++++++++++++++++++++--------- 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/src/View/Results/PlotSedProfile.py b/src/View/Results/PlotSedProfile.py index 5b34bb1e..8f77ee3b 100644 --- a/src/View/Results/PlotSedProfile.py +++ b/src/View/Results/PlotSedProfile.py @@ -56,7 +56,7 @@ class PlotSedProfile(APlot): x = profile.geometry.get_station() z = profile.geometry.z() - psl = list( + profiles_sl = list( map( lambda sl: sl[0], profile.get_ts_key(self._current_timestamp, "sl") @@ -64,10 +64,10 @@ class PlotSedProfile(APlot): ) sl = [] - for i in range(len(psl)): + for i in range(len(profiles_sl)): cur = [] for p in range(profile.geometry.number_points): - cur.append(psl[i]) + cur.append(profiles_sl[i]) sl.append(cur) # logger.info(sl) @@ -76,19 +76,44 @@ class PlotSedProfile(APlot): left = min(x), right = max(x) ) - # Compute sediment layer in function to point z + # Dummy layer with height = 0 + f = list(map(lambda p: 0, range(profile.geometry.number_points))) + + # We compute Z sediment layer in reverse order, from last layer to + # fake river bottom + r_sl = list(reversed(sl)) z_sl = reduce( lambda acc, v: acc + [ list( - map(lambda x, y: y - x, v, acc[-1]) + map(lambda x, y: y + x, v, acc[-1]) ) ], - sl, - [z] + r_sl, + [f] + ) + + # We normalize Z coordinate to 0 (the maximum must be 0) + f_z_max = max(z_sl[-1]) + z_sl = list( + map( + lambda p: list(map(lambda z: z - f_z_max, p)), + z_sl + ) + ) + + # We apply the river geometry bottom height at each layers to + # fond the new river geometry + z_sl = list( + map( + lambda sl: list( + map(lambda pz, m: pz + m, sl, z) + ), + z_sl + ) ) self.line_kp_sl = [] - for i, zsl in enumerate(reversed(z_sl)): + for i, zsl in enumerate(z_sl): self.line_kp_sl.append(None) self.line_kp_sl[i], = self.canvas.axes.plot( x, zsl, diff --git a/src/View/Results/PlotSedReach.py b/src/View/Results/PlotSedReach.py index 892120c6..d88e26df 100644 --- a/src/View/Results/PlotSedReach.py +++ b/src/View/Results/PlotSedReach.py @@ -56,7 +56,7 @@ class PlotSedReach(APlot): z_min = reach.geometry.get_z_min() z_max = reach.geometry.get_z_max() - psl = list( + profiles_sl = list( map( # Get SL list for profile p lambda p: p.get_ts_key(self._current_timestamp, "sl"), @@ -64,41 +64,65 @@ class PlotSedReach(APlot): ) ) - max_sl = reduce( + max_sl_num = reduce( lambda acc, sl: max(acc, len(sl)), - psl, + profiles_sl, 0 ) sl = [] - for i in range(max_sl): + for i in range(max_sl_num): cur = [] - for csl in psl: - if i < len(csl): - cur.append(csl[i][0]) + for profile_sl in profiles_sl: + if i < len(profile_sl): + cur.append(profile_sl[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) + left = min(kp) - 10, right = max(kp) + 10 ) - # Compute sediment layer in function to profile z_min + # Dummy layer with height = 0 + f = list(map(lambda p: 0, reach.profiles)) + + # We compute Z sediment layer in reverse order, from last layer to + # fake river bottom + r_sl = list(reversed(sl)) z_sl = reduce( lambda acc, v: acc + [ list( - map(lambda x, y: y - x, v, acc[-1]) + map(lambda x, y: y + x, v, acc[-1]) ) ], - sl, - [z_min] + r_sl, + [f] + ) + + # We normalize Z coordinate to 0 (the maximum must be 0) + f_z_max = max(z_sl[-1]) + z_sl = list( + map( + lambda p: list(map(lambda z: z - f_z_max, p)), + z_sl + ) + ) + + # We apply the river geometry bottom height at each layers to + # fond the new river geometry + z_sl = list( + map( + lambda sl: list( + map(lambda z, m: z + m, sl, z_min) + ), + z_sl + ) ) + # Draw self.line_kp_sl = [] - for i, z in enumerate(reversed(z_sl)): + for i, z in enumerate(z_sl): self.line_kp_sl.append(None) self.line_kp_sl[i], = self.canvas.axes.plot( kp, z, -- GitLab