diff --git a/src/View/Results/PlotHAdisTS.py b/src/View/Results/PlotCAdisTS.py similarity index 98% rename from src/View/Results/PlotHAdisTS.py rename to src/View/Results/PlotCAdisTS.py index 6f14d129dc1ee1159b0b35a3434359f9c8e2472e..c542c63d4afbaae224492193951fa3de807aaa09 100644 --- a/src/View/Results/PlotHAdisTS.py +++ b/src/View/Results/PlotCAdisTS.py @@ -1,4 +1,4 @@ -# PlotHAdisTS.py -- Pamhyr +# PlotCAdisTS.py -- Pamhyr # Copyright (C) 2023-2024 INRAE # # This program is free software: you can redistribute it and/or modify @@ -33,11 +33,11 @@ _translate = QCoreApplication.translate logger = logging.getLogger() -class PlotH(PamhyrPlot): +class PlotC(PamhyrPlot): def __init__(self, canvas=None, trad=None, toolbar=None, results=None, reach_id=0, profile_id=0, pol_id=0, parent=None): - super(PlotH, self).__init__( + super(PlotC, self).__init__( canvas=canvas, trad=trad, data=results, diff --git a/src/View/Results/PlotMAdisTS.py b/src/View/Results/PlotMAdisTS.py new file mode 100644 index 0000000000000000000000000000000000000000..2b9630c14d10beb3956481100967a1f77f0e7ea4 --- /dev/null +++ b/src/View/Results/PlotMAdisTS.py @@ -0,0 +1,168 @@ +# PlotMAdisTS.py -- Pamhyr +# Copyright (C) 2023-2024 INRAE +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +# -*- coding: utf-8 -*- + +import logging + +from functools import reduce +from datetime import datetime + +import numpy as np + +from tools import timer, trace +from View.Tools.PamhyrPlot import PamhyrPlot + +from PyQt5.QtCore import ( + QCoreApplication +) + +_translate = QCoreApplication.translate + +logger = logging.getLogger() + + +class PlotM(PamhyrPlot): + def __init__(self, canvas=None, trad=None, toolbar=None, + results=None, reach_id=0, profile_id=0, pol_id=0, + parent=None): + super(PlotM, self).__init__( + canvas=canvas, + trad=trad, + data=results, + toolbar=toolbar, + parent=parent + ) + + self._mode = "time" + + self._current_timestamp = max(results.get("timestamps")) + self._current_reach_id = reach_id + self._current_profile_id = profile_id + self._current_pol_id = pol_id + + self.label_x = _translate("Results", "Time (s)") + self.label_y = _translate("Results", "Discharge (m³/s)") + + self.label_discharge = _translate("Results", "Cross-section discharge") + self.label_discharge_max = _translate("Results", "Max discharge") + self.label_timestamp = _translate("Results", "Current timestamp") + + self._isometric_axis = False + + self._auto_relim_update = False + self._autoscale_update = False + + @property + def results(self): + return self.data + + @results.setter + def results(self, results): + self.data = results + self._current_timestamp = max(results.get("timestamps")) + + @timer + def draw(self, highlight=None): + self.init_axes() + + if self.results is None: + return + + reach = self.results.river.reach(self._current_reach_id) + profile = reach.profile(self._current_profile_id) + pollutant = self._current_pol_id + + if reach.geometry.number_profiles == 0: + self._init = False + return + + self.draw_data(reach, profile, pollutant) + + self.set_ticks_time_formater() + + self.enable_legend() + + self.idle() + self._init = True + + def draw_data(self, reach, profile, pollutant): + self.ts = list(self.results.get("timestamps")) + self.ts.sort() + + x = self.ts + #y = profile.get_key("Q") + #First 0 for pol and second 0 for phys var + y1 = list(map(lambda data_el: data_el[pollutant][1], profile.get_key("pols"))) + y2 = list(map(lambda data_el: data_el[pollutant][2], profile.get_key("pols"))) + y3 = list(map(lambda data_el: data_el[pollutant][3], profile.get_key("pols"))) + + y = (np.array(y1) + np.array(y2) + np.array(y3)).tolist() + + print("************//////////////////") + print("profile: ", self._current_profile_id) + print("reach: ", self._current_reach_id) + print("pollutant: ", pollutant) + + ###print("*****************draw data: ", len(x),len(y)) + ###print("x: ", x) + ###print("y: ", y) + ###print("reach: ", reach) + ###print("profile: ", profile) + ###print("pollutant: ", pollutant) + + self._line, = self.canvas.axes.plot( + x, y, + label=self.label_discharge, + color=self.color_plot, + **self.plot_default_kargs + ) + + def set_reach(self, reach_id): + self._current_reach_id = reach_id + self._current_profile_id = 0 + self.draw() + + def set_profile(self, profile_id): + self._current_profile_id = profile_id + self.update() + + def set_pollutant(self, pol_id): + self._current_pol_id = pol_id + self.update() + + def set_timestamp(self, timestamp): + self._current_timestamp = timestamp + self.update() + + def update(self): + if not self._init: + self.draw() + + self.update_data() + + self.update_idle() + + def update_data(self): + reach = self.results.river.reach(self._current_reach_id) + profile = reach.profile(self._current_profile_id) + pollutant = self._current_pol_id + + x = self.ts + #y = profile.get_key("Q") + y = list(map(lambda data_el: data_el[pollutant][0], profile.get_key("pols"))) + + self._line.set_data(x, y) diff --git a/src/View/Results/WindowAdisTS.py b/src/View/Results/WindowAdisTS.py index c9a01d8e1bc7dd246ab199b77b923c4a3164e8a4..0d90c935831e211d31d4db6070325ae792946c24 100644 --- a/src/View/Results/WindowAdisTS.py +++ b/src/View/Results/WindowAdisTS.py @@ -46,7 +46,8 @@ from PyQt5.QtWidgets import ( from View.Tools.Plot.PamhyrCanvas import MplCanvas from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar -from View.Results.PlotHAdisTS import PlotH +from View.Results.PlotCAdisTS import PlotC +from View.Results.PlotMAdisTS import PlotM from View.Results.CustomPlot.Plot import CustomPlot from View.Results.CustomPlot.CustomPlotValuesSelectionDialog import ( @@ -144,11 +145,11 @@ class ResultsWindowAdisTS(PamhyrWindow): ] ) self.plot_layout_4 = self.find( - QVBoxLayout, "verticalLayout_hydrograph") + QVBoxLayout, "verticalLayout_concentration") self.plot_layout_4.addWidget(self.toolbar_4) self.plot_layout_4.addWidget(self.canvas_4) - self.plot_h = PlotH( + self.plot_c = PlotC( canvas=self.canvas_4, results=self._results, reach_id=0, @@ -157,7 +158,31 @@ class ResultsWindowAdisTS(PamhyrWindow): trad=self._trad, toolbar=self.toolbar_4 ) - self.plot_h.draw() + self.plot_c.draw() + + self.canvas_3 = MplCanvas(width=5, height=4, dpi=100) + self.canvas_3.setObjectName("canvas_3") + self.toolbar_3 = PamhyrPlotToolbar( + self.canvas_3, self, items=[ + "home", "move", "zoom", "save", + "iso", "back/forward" + ] + ) + self.plot_layout_3 = self.find( + QVBoxLayout, "verticalLayout_mass") + self.plot_layout_3.addWidget(self.toolbar_3) + self.plot_layout_3.addWidget(self.canvas_3) + + self.plot_m = PlotM( + canvas=self.canvas_3, + results=self._results, + reach_id=0, + profile_id=0, + pol_id=0, + trad=self._trad, + toolbar=self.toolbar_3 + ) + self.plot_m.draw() def closeEvent(self, event): try: @@ -285,14 +310,16 @@ class ResultsWindowAdisTS(PamhyrWindow): def update(self, reach_id=None, profile_id=None, pol_id=None, timestamp=None): if reach_id is not None: - self.plot_h.set_reach(reach_id) + self.plot_c.set_reach(reach_id) + self.plot_m.set_reach(reach_id) self.update_table_selection_reach(reach_id) self.update_table_selection_profile(0) self.update_table_selection_pol(0) if profile_id is not None: - self.plot_h.set_profile(profile_id) + self.plot_c.set_profile(profile_id) + self.plot_m.set_profile(profile_id) self.update_table_selection_profile(profile_id) @@ -300,12 +327,14 @@ class ResultsWindowAdisTS(PamhyrWindow): if pol_id is not None: print("--**//++//**//** update pol_id: ", pol_id) - self.plot_h.set_pollutant(pol_id) + self.plot_c.set_pollutant(pol_id) + self.plot_m.set_pollutant(pol_id) self.update_table_selection_pol(pol_id) if timestamp is not None: - self.plot_h.set_timestamp(timestamp) + self.plot_c.set_timestamp(timestamp) + self.plot_m.set_timestamp(timestamp) self._table["raw_data"].timestamp = timestamp @@ -358,9 +387,11 @@ class ResultsWindowAdisTS(PamhyrWindow): self.update(timestamp=timestamp) def _reload_plots(self): - self.plot_h.results = self._results + self.plot_c.results = self._results + self.plot_m.results = self._results - self.plot_h.draw() + self.plot_c.draw() + self.plot_m.draw() def _reload_slider(self): self._slider_time = self.find(QSlider, f"horizontalSlider_time") diff --git a/src/View/ui/ResultsAdisTS.ui b/src/View/ui/ResultsAdisTS.ui index c499f085b5cce40c8777b5d2e821eaf8892cc04f..3edfe5f4de01450f062194941affada4c4d4b8f0 100644 --- a/src/View/ui/ResultsAdisTS.ui +++ b/src/View/ui/ResultsAdisTS.ui @@ -81,11 +81,31 @@ </widget> <widget class="QWidget" name="tab_2"> <attribute name="title"> - <string>Hydrograph</string> + <string>Concentration</string> </attribute> <layout class="QGridLayout" name="gridLayout_4"> <item row="0" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_hydrograph"/> + <layout class="QVBoxLayout" name="verticalLayout_concentration"/> + </item> + </layout> + </widget> + <widget class="QWidget" name="tab_3"> + <attribute name="title"> + <string>Mass</string> + </attribute> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <layout class="QVBoxLayout" name="verticalLayout_mass"/> + </item> + </layout> + </widget> + <widget class="QWidget" name="tab_5"> + <attribute name="title"> + <string>Total Sediments</string> + </attribute> + <layout class="QGridLayout" name="gridLayout_6"> + <item row="0" column="0"> + <layout class="QVBoxLayout" name="verticalLayout_total"/> </item> </layout> </widget>