From b04e325ab5d2a4fb4394fb1c55445e8e53dd16f8 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Wed, 9 Aug 2023 11:00:07 +0200 Subject: [PATCH] Results: PlotXY: Add water level. --- src/Model/Results/River/River.py | 2 +- src/Solver/Mage.py | 1 + src/View/Results/PlotXY.py | 32 +++++++++++++++++++++++++++++++- src/View/Results/Window.py | 11 +++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/Model/Results/River/River.py b/src/Model/Results/River/River.py index ae8b33c0..5ae1e90f 100644 --- a/src/Model/Results/River/River.py +++ b/src/Model/Results/River/River.py @@ -47,7 +47,7 @@ class Profile(object): def get_ts(self, timestamp): return self._data[timestamp] - def get_key(self, timestamp): + def get_key(self, key): return list( map(lambda ts: self._data[ts][key], self._data) ) diff --git a/src/Solver/Mage.py b/src/Solver/Mage.py index cc695556..6c129f88 100644 --- a/src/Solver/Mage.py +++ b/src/Solver/Mage.py @@ -595,4 +595,5 @@ class Mage8(Mage): end = newline().size <= 0 logger.debug(reachs[0].profiles[0]._data) + results.set("timestamps", ts) logger.info(f"read_bin: ... end with {len(ts)} timestamp read") diff --git a/src/View/Results/PlotXY.py b/src/View/Results/PlotXY.py index 43934073..a0af6a2d 100644 --- a/src/View/Results/PlotXY.py +++ b/src/View/Results/PlotXY.py @@ -16,6 +16,8 @@ # -*- coding: utf-8 -*- +from functools import reduce + from tools import timer, trace from View.Plot.APlot import APlot @@ -40,6 +42,7 @@ class PlotXY(APlot): self.line_xy = [] self.line_gl = [] + self._current_timestamp = max(results.get("timestamps")) self._current_reach_id = reach_id self._current_profile_id = profile_id @@ -106,9 +109,32 @@ class PlotXY(APlot): for x, y in zip(x_complete, y_complete) ] + # Display point under water + for profile in reach.profiles: + water_z = profile.get_ts_key( + self._current_timestamp, "Z" + ) + pgeo = profile.geometry + + x, y = reduce( + lambda acc, pts: (acc[0] + [pts.x], acc[1] + [pts.y]), + filter( + lambda pts: pts.z < water_z, + pgeo.points + ), + ([], []) + ) + + self.canvas.axes.plot( + x, y, lw=1., + color='b', + markersize=4, + marker='o' + ) + if self.display_current: # Current profile - profile = reach.geometry.profile(self._current_profile_id) + profile = reach.profile(self._current_profile_id).geometry self.plot_selected, = self.canvas.axes.plot( profile.x(), @@ -134,5 +160,9 @@ class PlotXY(APlot): self._current_profile_id = profile_id self.draw() + def set_timestamp(self, timestamp): + self._current_timestamp = timestamp + self.draw() + def update(self): self.draw() diff --git a/src/View/Results/Window.py b/src/View/Results/Window.py index e2d3f8b3..66845431 100644 --- a/src/View/Results/Window.py +++ b/src/View/Results/Window.py @@ -158,6 +158,17 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow): self._table[t].dataChanged.connect(fun[t]) + def plotXY(self, reach_id = None, profile_id = None, timestamp = None): + if reach_id is not None: + self.plot_xy.set_reach(reach_id) + if profile_id is not None: + self.plot_xy.set_profile(profile_id) + if timestamp is not None: + self.plot_xy.set_timestamp(timestamp) + + self.plot_xy.draw() + + def _set_current_reach(self): return -- GitLab