diff --git a/src/View/Results/PlotTotSedEDAdisTS.py b/src/View/Results/PlotTotSedEDAdisTS.py new file mode 100644 index 0000000000000000000000000000000000000000..007b5038e649c63a2a6c42848d0456c3ea319338 --- /dev/null +++ b/src/View/Results/PlotTotSedEDAdisTS.py @@ -0,0 +1,160 @@ +# PlotTotSedEDAdisTS.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 PlotTotSedED(PamhyrPlot): + def __init__(self, canvas=None, trad=None, toolbar=None, + results=None, reach_id=0, profile_id=0, pol_id=0, + parent=None): + super(PlotTotSedED, 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 + y = list(map(lambda data_el: data_el[pollutant][3], profile.get_key("pols"))) + + print("Total Sed ED ************//////////////////") + 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_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][3], profile.get_key("pols"))) + + self._line.set_data(x, y) diff --git a/src/View/Results/PlotTotSedEGAdisTS.py b/src/View/Results/PlotTotSedEGAdisTS.py new file mode 100644 index 0000000000000000000000000000000000000000..ba1f5a75e39f32dc2cf5d8b58caeb97dc8c0bbed --- /dev/null +++ b/src/View/Results/PlotTotSedEGAdisTS.py @@ -0,0 +1,160 @@ +# PlotTotSedEGAdisTS.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 PlotTotSedEG(PamhyrPlot): + def __init__(self, canvas=None, trad=None, toolbar=None, + results=None, reach_id=0, profile_id=0, pol_id=0, + parent=None): + super(PlotTotSedEG, 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 + y = list(map(lambda data_el: data_el[pollutant][1], profile.get_key("pols"))) + + print("Total Sed EG ************//////////////////") + 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_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][1], profile.get_key("pols"))) + + self._line.set_data(x, y) diff --git a/src/View/Results/PlotTotSedEMAdisTS.py b/src/View/Results/PlotTotSedEMAdisTS.py new file mode 100644 index 0000000000000000000000000000000000000000..36387d8343592007156a9d3dd1c49c2d30561732 --- /dev/null +++ b/src/View/Results/PlotTotSedEMAdisTS.py @@ -0,0 +1,160 @@ +# PlotTotSedEMAdisTS.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 PlotTotSedEM(PamhyrPlot): + def __init__(self, canvas=None, trad=None, toolbar=None, + results=None, reach_id=0, profile_id=0, pol_id=0, + parent=None): + super(PlotTotSedEM, 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 + y = list(map(lambda data_el: data_el[pollutant][2], profile.get_key("pols"))) + + print("Total Sed EM ************//////////////////") + 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_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][2], 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 12f4aaf5546dcf12c1656e4c1db5f0d988e1579b..f68af07bc8d41dd763f96f23a3ca839722df0aad 100644 --- a/src/View/Results/WindowAdisTS.py +++ b/src/View/Results/WindowAdisTS.py @@ -49,6 +49,9 @@ from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar from View.Results.PlotCAdisTS import PlotC from View.Results.PlotMAdisTS import PlotM from View.Results.PlotTotSedCAdisTS import PlotTotSedC +from View.Results.PlotTotSedEGAdisTS import PlotTotSedEG +from View.Results.PlotTotSedEMAdisTS import PlotTotSedEM +from View.Results.PlotTotSedEDAdisTS import PlotTotSedED from View.Results.CustomPlot.Plot import CustomPlot from View.Results.CustomPlot.CustomPlotValuesSelectionDialog import ( @@ -110,8 +113,11 @@ class ResultsWindowAdisTS(PamhyrWindow): self.setup_table() self.setup_plots() self.setup_slider() + print("///setup slider correct") self.setup_statusbar() + print("///setup status bar correct") self.setup_connections() + print("///setup connections correct") except Exception as e: logger_exception(e) return @@ -161,6 +167,8 @@ class ResultsWindowAdisTS(PamhyrWindow): ) self.plot_c.draw() + print("///plot c adists correct") + self.canvas_3 = MplCanvas(width=5, height=4, dpi=100) self.canvas_3.setObjectName("canvas_3") self.toolbar_3 = PamhyrPlotToolbar( @@ -185,6 +193,8 @@ class ResultsWindowAdisTS(PamhyrWindow): ) self.plot_m.draw() + print("///plot m adists correct") + self.canvas_2 = MplCanvas(width=5, height=4, dpi=100) self.canvas_2.setObjectName("canvas_2") self.toolbar_2 = PamhyrPlotToolbar( @@ -195,7 +205,7 @@ class ResultsWindowAdisTS(PamhyrWindow): ) self.plot_layout_2 = self.find( QVBoxLayout, "verticalLayout_tot_c") - self.plot_layout_2.addWidget(self.toolbar_2) + #self.plot_layout_2.addWidget(self.toolbar_2) self.plot_layout_2.addWidget(self.canvas_2) self.plot_tot_c = PlotTotSedC( @@ -205,10 +215,86 @@ class ResultsWindowAdisTS(PamhyrWindow): profile_id=0, pol_id=self._results.pollutants_list.index("total_sediment"), trad=self._trad, - toolbar=self.toolbar_2 + #toolbar=self.toolbar_2 ) + self.plot_tot_c.draw() + self.canvas_1 = MplCanvas(width=5, height=4, dpi=100) + self.canvas_1.setObjectName("canvas_1") + self.toolbar_1 = PamhyrPlotToolbar( + self.canvas_1, self, items=[ + "home", "move", "zoom", "save", + "iso", "back/forward" + ] + ) + self.plot_layout_1 = self.find( + QVBoxLayout, "verticalLayout_tot_left_2") + # self.plot_layout_1.addWidget(self.toolbar_1) + self.plot_layout_1.addWidget(self.canvas_1) + + self.plot_tot_eg = PlotTotSedEG( + canvas=self.canvas_1, + results=self._results, + reach_id=0, + profile_id=0, + pol_id=self._results.pollutants_list.index("total_sediment"), + trad=self._trad, + #toolbar=self.toolbar_1 + ) + + self.plot_tot_eg.draw() + + self.canvas_0 = MplCanvas(width=5, height=4, dpi=100) + self.canvas_0.setObjectName("canvas_0") + self.toolbar_0 = PamhyrPlotToolbar( + self.canvas_0, self, items=[ + "home", "move", "zoom", "save", + "iso", "back/forward" + ] + ) + self.plot_layout_0 = self.find( + QVBoxLayout, "verticalLayout_tot_minor") + # self.plot_layout_0.addWidget(self.toolbar_0) + self.plot_layout_0.addWidget(self.canvas_0) + + self.plot_tot_em = PlotTotSedEM( + canvas=self.canvas_0, + results=self._results, + reach_id=0, + profile_id=0, + pol_id=self._results.pollutants_list.index("total_sediment"), + trad=self._trad, + # toolbar=self.toolbar_0 + ) + + self.plot_tot_em.draw() + + self.canvas_5 = MplCanvas(width=5, height=4, dpi=100) + self.canvas_5.setObjectName("canvas_5") + self.toolbar_5 = PamhyrPlotToolbar( + self.canvas_5, self, items=[ + "home", "move", "zoom", "save", + "iso", "back/forward" + ] + ) + self.plot_layout_5 = self.find( + QVBoxLayout, "verticalLayout_tot_right") + # self.plot_layout_5.addWidget(self.toolbar_5) + self.plot_layout_5.addWidget(self.canvas_5) + + self.plot_tot_ed = PlotTotSedED( + canvas=self.canvas_5, + results=self._results, + reach_id=0, + profile_id=0, + pol_id=self._results.pollutants_list.index("total_sediment"), + trad=self._trad, + # toolbar=self.toolbar_0 + ) + + self.plot_tot_ed.draw() + def closeEvent(self, event): try: self._timer.stop() @@ -338,6 +424,9 @@ class ResultsWindowAdisTS(PamhyrWindow): self.plot_c.set_reach(reach_id) self.plot_m.set_reach(reach_id) self.plot_tot_c.set_reach(reach_id) + self.plot_tot_eg.set_reach(reach_id) + self.plot_tot_em.set_reach(reach_id) + self.plot_tot_ed.set_reach(reach_id) self.update_table_selection_reach(reach_id) self.update_table_selection_profile(0) @@ -347,6 +436,9 @@ class ResultsWindowAdisTS(PamhyrWindow): self.plot_c.set_profile(profile_id) self.plot_m.set_profile(profile_id) self.plot_tot_c.set_profile(profile_id) + self.plot_tot_eg.set_profile(profile_id) + self.plot_tot_em.set_profile(profile_id) + self.plot_tot_ed.set_profile(profile_id) self.update_table_selection_profile(profile_id) @@ -363,6 +455,9 @@ class ResultsWindowAdisTS(PamhyrWindow): self.plot_c.set_timestamp(timestamp) self.plot_m.set_timestamp(timestamp) self.plot_tot_c.set_timestamp(timestamp) + self.plot_tot_eg.set_timestamp(timestamp) + self.plot_tot_em.set_timestamp(timestamp) + self.plot_tot_ed.set_timestamp(timestamp) self._table["raw_data"].timestamp = timestamp @@ -418,10 +513,16 @@ class ResultsWindowAdisTS(PamhyrWindow): self.plot_c.results = self._results self.plot_m.results = self._results self.plot_tot_c.results = self._results + self.plot_tot_eg.results = self._results + self.plot_tot_em.results = self._results + self.plot_tot_ed.results = self._results self.plot_c.draw() self.plot_m.draw() self.plot_tot_c.draw() + self.plot_tot_eg.draw() + self.plot_tot_em.draw() + self.plot_tot_ed.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 13701936f2ded3b394d4af5bb518dd8b2fd394fc..ddc694e1f3d7c03d9dd7a795d84be4643d207af5 100644 --- a/src/View/ui/ResultsAdisTS.ui +++ b/src/View/ui/ResultsAdisTS.ui @@ -24,7 +24,7 @@ </size> </property> <layout class="QGridLayout" name="gridLayout_3"> - <item row="0" column="1"> + <item row="0" column="0"> <widget class="QSplitter" name="splitter_4"> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -112,7 +112,7 @@ <item> <widget class="QTabWidget" name="tabWidget_2"> <property name="currentIndex"> - <number>0</number> + <number>1</number> </property> <widget class="QWidget" name="tab"> <attribute name="title">