From 6c4f863b96de6b9af2ec1208d05d66673093dbbc Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Wed, 1 Jul 2026 15:39:52 +0200 Subject: [PATCH] Results: Export: Use np table. --- src/View/Results/Window.py | 202 ++++++++++++++++++++++--------------- 1 file changed, 119 insertions(+), 83 deletions(-) diff --git a/src/View/Results/Window.py b/src/View/Results/Window.py index c67df06e..53b85b31 100644 --- a/src/View/Results/Window.py +++ b/src/View/Results/Window.py @@ -872,14 +872,25 @@ class ResultsWindow(PamhyrWindow): reach = results.river.reachs[self._get_current_reach()] dict_x = self._trad.get_dict("values_x") dict_y = self._trad.get_dict("values_y") + if self._current_results == 2: envelop = False reach1 = results[0].river.reachs[self._get_current_reach()] reach2 = results[1].river.reachs[self._get_current_reach()] + if envelop: dict_y.update(self._trad.get_dict("values_y_envelop")) + my_dict = {} my_dict[dict_x["rk"]] = reach.geometry.get_rk() + + table = results.get("table") + id_ts = results.get_timestamp_id(timestamp) + + z = table["Z"] + q = table["Q"] + v = table["V"] + if "bed_elevation" in y: if reach.has_bedload(): zmin = list( @@ -897,40 +908,40 @@ class ResultsWindow(PamhyrWindow): if "discharge" in y: my_dict[dict_y["discharge"]] = list( map( - lambda p: p.get_ts_key(timestamp, "Q"), + lambda p: q[id_ts, p.global_index], reach.profiles ) ) if envelop: my_dict[dict_y["min_discharge"]] = list( map( - lambda p: min(p.get_key("Q")), + lambda p: min(q[:, p.global_index]), reach.profiles ) ) my_dict[dict_y["max_discharge"]] = list( map( - lambda p: max(p.get_key("Q")), + lambda p: max(q[:, p.global_index]), reach.profiles ) ) if "water_elevation" in y: my_dict[dict_y["water_elevation"]] = list( map( - lambda p: p.get_ts_key(timestamp, "Z"), + lambda p: z[id_ts, p.global_index], reach.profiles ) ) if envelop: my_dict[dict_y["min_water_elevation"]] = list( map( - lambda p: min(p.get_key("Z")), + lambda p: min(z[:, p.global_index]), reach.profiles ) ) my_dict[dict_y["max_water_elevation"]] = list( map( - lambda p: max(p.get_key("Z")), + lambda p: max(z[:, p.global_index]), reach.profiles ) ) @@ -938,16 +949,15 @@ class ResultsWindow(PamhyrWindow): if "velocity" in y: my_dict[dict_y["velocity"]] = list( map( - lambda p: p.get_ts_key(timestamp, "V"), + lambda p: v[id_ts, p.global_index], reach.profiles ) ) if envelop: velocities = list(map( - lambda p: p.get_key("V"), - reach.profiles - ) - ) + lambda p: v[:, p.global_index], + reach.profiles + )) my_dict[dict_y["min_velocity"]] = [min(v) for v in velocities] my_dict[dict_y["max_velocity"]] = [max(v) for v in velocities] @@ -956,7 +966,8 @@ class ResultsWindow(PamhyrWindow): d = my_dict[dict_y["depth"]] = list( map( lambda p: p.geometry.max_water_depth( - p.get_ts_key(timestamp, "Z")), + z[id_ts, p.global_index] + ), reach.profiles ) ) @@ -964,14 +975,16 @@ class ResultsWindow(PamhyrWindow): d1 = list( map( lambda p: p.geometry.max_water_depth( - p.get_ts_key(timestamp, "Z")), + z[id_ts, p.global_index] + ), reach1.profiles ) ) d2 = list( map( lambda p: p.geometry.max_water_depth( - p.get_ts_key(timestamp, "Z")), + z[id_ts, p.global_index] + ), reach2.profiles ) ) @@ -985,14 +998,14 @@ class ResultsWindow(PamhyrWindow): if envelop: my_dict[dict_y["min_depth"]] = list(map( lambda p1, p2: p1 - p2, map( - lambda p: min(p.get_key("Z")), + lambda p: min(z[:, p.global_index]), reach.profiles ), reach.geometry.get_z_min() ) ) my_dict[dict_y["max_depth"]] = list(map( lambda p1, p2: p1 - p2, map( - lambda p: max(p.get_key("Z")), + lambda p: max(z[:, p.global_index]), reach.profiles ), reach.geometry.get_z_min() ) @@ -1003,7 +1016,8 @@ class ResultsWindow(PamhyrWindow): d = list( map( lambda p: p.geometry.mean_water_depth( - p.get_ts_key(timestamp, "Z")), + z[id_ts, p.global_index] + ), reach.profiles ) ) @@ -1011,14 +1025,16 @@ class ResultsWindow(PamhyrWindow): d1 = list( map( lambda p: p.geometry.mean_water_depth( - p.get_ts_key(timestamp, "Z")), + z[id_ts, p.global_index] + ), reach1.profiles ) ) d2 = list( map( lambda p: p.geometry.mean_water_depth( - p.get_ts_key(timestamp, "Z")), + z[id_ts, p.global_index] + ), reach2.profiles ) ) @@ -1033,57 +1049,65 @@ class ResultsWindow(PamhyrWindow): if self._current_results != 2: fr = my_dict[dict_y["froude"]] = list( map( - lambda p: - p.get_ts_key(timestamp, "V") / + lambda p: ( + v[id_ts, p.global_index] / sqrt(9.81 * ( p.geometry.wet_area( - p.get_ts_key(timestamp, "Z")) / + z[id_ts, p.global_index] + ) / p.geometry.wet_width( - p.get_ts_key(timestamp, "Z")) - )), + z[id_ts, p.global_index] + ) + )) + ), reach.profiles ) ) else: fr1 = list( map( - lambda p: - p.get_ts_key(timestamp, "V") / + lambda p: ( + v[id_ts, p.global_index] / sqrt(9.81 * ( p.geometry.wet_area( - p.get_ts_key(timestamp, "Z")) / + z[id_ts, p.global_index] + ) / p.geometry.wet_width( - p.get_ts_key(timestamp, "Z")) - )), + z[id_ts, p.global_index] + ) + )) + ), reach1.profiles ) ) fr2 = list( map( - lambda p: - p.get_ts_key(timestamp, "V") / + lambda p: ( + v[id_ts, p.global_index] / sqrt(9.81 * ( p.geometry.wet_area( - p.get_ts_key(timestamp, "Z")) / + z[id_ts, p.global_index] + ) / p.geometry.wet_width( - p.get_ts_key(timestamp, "Z")) - )), + z[id_ts, p.global_index] + ) + )) + ), reach2.profiles ) ) - fr = list( - map( - lambda x, y: x - y, - fr1, fr2 - ) - ) + fr = list(map( + lambda x, y: x - y, + fr1, fr2 + )) my_dict[dict_y["froude"]] = fr if "wet_area" in y: if self._current_results != 2: wa = list( map( lambda p: p.geometry.wet_area( - p.get_ts_key(timestamp, "Z")), + z[id_ts, p.global_index] + ), reach.profiles ) ) @@ -1091,23 +1115,24 @@ class ResultsWindow(PamhyrWindow): wa1 = list( map( lambda p: p.geometry.wet_area( - p.get_ts_key(timestamp, "Z")), + z[id_ts, p.global_index] + ), reach1.profiles ) ) wa2 = list( map( lambda p: p.geometry.wet_area( - p.get_ts_key(timestamp, "Z")), + z[id_ts, p.global_index] + ), reach2.profiles ) ) - wa = list( - map( - lambda x, y: x - y, - wa1, wa2 - ) - ) + wa = list(map( + lambda x, y: x - y, + wa1, wa2 + )) + my_dict[dict_y["wet_area"]] = wa return my_dict @@ -1118,24 +1143,38 @@ class ResultsWindow(PamhyrWindow): profile = reach.profile(profile) dict_x = self._trad.get_dict("values_x") dict_y = self._trad.get_dict("values_y") + my_dict = {} my_dict[dict_x["time"]] = self._timestamps - z = profile.get_key("Z") - q = profile.get_key("Q") - v = profile.get_key("V") + + table = results.get("table") + + z = table["Z"][:, profile.global_index] + q = table["Q"][:, profile.global_index] + v = table["V"][:, profile.global_index] + if self._current_results == 2: reach1 = self._results[0].river.reach(self._reach) reach2 = self._results[1].river.reach(self._reach) reach3 = self._results[2].river.reach(self._reach) profile1 = reach1.profile(self._profile) profile2 = reach2.profile(self._profile) - profile3 = reach3.profile(self._profile) + # profile3 = reach3.profile(self._profile) + + z1 = table["Z"][:, profile1.global_index] + q1 = table["Q"][:, profile1.global_index] + v1 = table["V"][:, profile1.global_index] + + z2 = table["Z"][:, profile2.global_index] + q2 = table["Q"][:, profile2.global_index] + v2 = table["V"][:, profile2.global_index] if "bed_elevation" in y: if reach.has_bedload(): z_min = profile.get_key("zfd") else: z_min = [profile.geometry.z_min()] * len(self._timestamps) + my_dict[dict_y["bed_elevation"]] = z_min if "discharge" in y: my_dict[dict_y["discharge"]] = q @@ -1146,14 +1185,14 @@ class ResultsWindow(PamhyrWindow): if "depth" in y: if self._current_results != 2: d = list( - map(lambda z: profile.geometry.max_water_depth(z), z) + map(lambda x: profile.geometry.max_water_depth(x), z) ) else: d1 = list( - map(lambda z: profile1.geometry.max_water_depth(z), z1) + map(lambda x: profile1.geometry.max_water_depth(x), z1) ) d2 = list( - map(lambda z: profile2.geometry.max_water_depth(z), z2) + map(lambda x: profile2.geometry.max_water_depth(x), z2) ) d = list( map( @@ -1165,21 +1204,19 @@ class ResultsWindow(PamhyrWindow): if "mean_depth" in y: if self._current_results != 2: d = list( - map(lambda z: profile.geometry.mean_water_depth(z), z) + map(lambda x: profile.geometry.mean_water_depth(x), z) ) else: d1 = list( - map(lambda z: profile1.geometry.mean_water_depth(z), z1) + map(lambda x: profile1.geometry.mean_water_depth(x), z1) ) d2 = list( - map(lambda z: profile2.geometry.mean_water_depth(z), z2) + map(lambda x: profile2.geometry.mean_water_depth(x), z2) ) - d = list( - map( - lambda x, y: x - y, - d1, d2 - ) - ) + d = list(map( + lambda x, y: x - y, + d1, d2 + )) my_dict[dict_y["mean_depth"]] = d if "froude" in y: if self._current_results != 2: @@ -1188,7 +1225,8 @@ class ResultsWindow(PamhyrWindow): v / sqrt(9.81 * ( profile.geometry.wet_area(z) / profile.geometry.wet_width(z)) - ), z, v) + ), + z, v) ) else: fr1 = list( @@ -1197,7 +1235,8 @@ class ResultsWindow(PamhyrWindow): sqrt(9.81 * ( profile1.geometry.wet_area(z) / profile1.geometry.wet_width(z)) - ), z1, v1) + ), + z1, v1) ) fr2 = list( map(lambda z, v: @@ -1205,33 +1244,30 @@ class ResultsWindow(PamhyrWindow): sqrt(9.81 * ( profile2.geometry.wet_area(z) / profile2.geometry.wet_width(z)) - ), z2, v2) - ) - fr = list( - map( - lambda x, y: x - y, - fr1, fr2 - ) + ), + z2, v2) ) + fr = list(map( + lambda x, y: x - y, + fr1, fr2 + )) my_dict[dict_y["froude"]] = fr if "wet_area" in y: if self._current_results != 2: wa = list( - map(lambda z: profile.geometry.wet_area(z), z) + map(lambda x: profile.geometry.wet_area(x), z) ) else: wa1 = list( - map(lambda z: profile1.geometry.wet_area(z), z1) + map(lambda x: profile1.geometry.wet_area(x), z1) ) wa2 = list( - map(lambda z: profile2.geometry.wet_area(z), z2) + map(lambda x: profile2.geometry.wet_area(x), z2) ) - wa = list( - map( - lambda x, y: x - y, - wa1, wa2 - ) - ) + wa = list(map( + lambda x, y: x - y, + wa1, wa2 + )) my_dict[dict_y["wet_area"]] = wa return my_dict