From fb62298bd2ba0fcdb78aa8e108e973f90126ee7d Mon Sep 17 00:00:00 2001
From: Theophile Terraz <theophile.terraz@inrae.fr>
Date: Wed, 7 Aug 2024 11:33:41 +0200
Subject: [PATCH] more custom plots

---
 src/View/Results/CustomPlot/Plot.py      | 82 ++++++++++++++++++++----
 src/View/Results/CustomPlot/Translate.py | 15 +++--
 src/lang/fr.ts                           |  2 +-
 3 files changed, 78 insertions(+), 21 deletions(-)

diff --git a/src/View/Results/CustomPlot/Plot.py b/src/View/Results/CustomPlot/Plot.py
index e8a21d95..f9ebdfcf 100644
--- a/src/View/Results/CustomPlot/Plot.py
+++ b/src/View/Results/CustomPlot/Plot.py
@@ -33,6 +33,8 @@ unit = {
     "water_elevation": "0-meter",
     "discharge": "1-m3s",
     "velocity": "2-ms",
+    "depth": "3-meter",
+    "mean_depth": "3-meter",
 }
 
 
@@ -152,6 +154,39 @@ class CustomPlot(PamhyrPlot):
             )
             lines["velocity"] = line
 
+        if "depth" in self._y:
+
+            ax = self._axes[unit["depth"]]
+            d = list(
+                map(
+                    lambda p: p.geometry.max_water_depth(
+                        p.get_ts_key(self._timestamp, "Z")),
+                    reach.profiles
+                )
+            )
+            line = ax.plot(
+                rk, d,
+                color='brown', lw=1.,
+            )
+            lines["depth"] = line
+
+        if "mean_depth" in self._y:
+
+            ax = self._axes[unit["depth"]]
+            d = list(
+                map(
+                    lambda p: p.geometry.mean_water_depth(
+                        p.get_ts_key(self._timestamp, "Z")),
+                    reach.profiles
+                )
+            )
+
+            line = ax.plot(
+                rk, d,
+                color='orange', lw=1.,
+            )
+            lines["depth"] = line
+
         # Legend
         lns = reduce(
             lambda acc, line: acc + line,
@@ -221,19 +256,19 @@ class CustomPlot(PamhyrPlot):
 
         q = profile.get_key("Q")
         z = profile.get_key("Z")
+        z_min = profile.geometry.z_min()
+        ts_z_min = list(
+            map(
+                lambda ts:  z_min,
+                ts
+            )
+        )
 
         lines = {}
         if "elevation" in self._y:
             # Z min is constant in time
 
             ax = self._axes[unit["elevation"]]
-            z_min = profile.geometry.z_min()
-            ts_z_min = list(
-                map(
-                    lambda ts:  z_min,
-                    ts
-                )
-            )
 
             line = ax.plot(
                 ts, ts_z_min,
@@ -251,13 +286,6 @@ class CustomPlot(PamhyrPlot):
             lines["water_elevation"] = line
 
             if "elevation" in self._y:
-                z_min = profile.geometry.z_min()
-                ts_z_min = list(
-                    map(
-                        lambda ts:  z_min,
-                        ts
-                    )
-                )
 
                 ax.fill_between(
                     ts, ts_z_min, z,
@@ -289,6 +317,32 @@ class CustomPlot(PamhyrPlot):
             )
             lines["velocity"] = line
 
+        if "depth" in self._y:
+
+            ax = self._axes[unit["depth"]]
+            d = list(
+                map(lambda z: profile.geometry.max_water_depth(z), z)
+            )
+
+            line = ax.plot(
+                ts, d,
+                color='brown', lw=1.,
+            )
+            lines["depth"] = line
+
+        if "mean_depth" in self._y:
+
+            ax = self._axes[unit["depth"]]
+            d = list(
+                map(lambda z: profile.geometry.mean_water_depth(z), z)
+            )
+
+            line = ax.plot(
+                ts, d,
+                color='orange', lw=1.,
+            )
+            lines["depth"] = line
+
         self._customize_x_axes_time(ts)
 
         # Legend
diff --git a/src/View/Results/CustomPlot/Translate.py b/src/View/Results/CustomPlot/Translate.py
index 5e9944c7..df4ad75b 100644
--- a/src/View/Results/CustomPlot/Translate.py
+++ b/src/View/Results/CustomPlot/Translate.py
@@ -41,12 +41,12 @@ class CustomPlotTranslate(ResultsTranslate):
             "CustomPlot", "Bed elevation (m)"
         )
         self._dict['velocity'] = self._dict["unit_speed"]
-        self._dict['width'] = self._dict["unit_width"],
-        self._dict['max_depth'] = self._dict["unit_max_height"],
-        self._dict['mean_depth'] = self._dict["unit_mean_height"],
-        self._dict['wet_area'] = self._dict["unit_wet_area"],
-        self._dict['wet_perimeter'] = self._dict["unit_wet_perimeter"],
-        self._dict['hydraulic_radius'] = self._dict["unit_hydraulic_radius"],
+        self._dict['width'] = self._dict["unit_width"]
+        self._dict['max_depth'] = self._dict["unit_max_height"]
+        self._dict['mean_depth'] = self._dict["unit_mean_height"]
+        self._dict['wet_area'] = self._dict["unit_wet_area"]
+        self._dict['wet_perimeter'] = self._dict["unit_wet_perimeter"]
+        self._dict['hydraulic_radius'] = self._dict["unit_hydraulic_radius"]
 
         # Unit corresponding long name (plot axes display)
 
@@ -55,6 +55,7 @@ class CustomPlotTranslate(ResultsTranslate):
         )
         self._dict['1-m3s'] = self._dict["unit_discharge"]
         self._dict['2-ms'] = self._dict["unit_speed"]
+        self._dict['3-meter'] = self._dict["unit_height"]
 
         # SubDict
 
@@ -67,4 +68,6 @@ class CustomPlotTranslate(ResultsTranslate):
             "water_elevation": self._dict["water_elevation"],
             "discharge": self._dict["discharge"],
             "velocity": self._dict["velocity"],
+            "depth": self._dict["max_depth"],
+            "mean_depth": self._dict["mean_depth"],
         }
diff --git a/src/lang/fr.ts b/src/lang/fr.ts
index 7ae74e51..dc68faec 100644
--- a/src/lang/fr.ts
+++ b/src/lang/fr.ts
@@ -3057,7 +3057,7 @@
     </message>
     <message>
         <location filename="../View/Translate.py" line="57"/>
-        <source>Height (m)</source>
+        <source>Depth (m)</source>
         <translation>Hauteur (m)</translation>
     </message>
     <message>
-- 
GitLab