From b72ffe03c30038e2611b08d5fd45063df384b1ec Mon Sep 17 00:00:00 2001 From: Theophile Terraz Date: Wed, 4 Dec 2024 16:09:33 +0100 Subject: [PATCH] more work on adis results --- src/View/Results/PlotSedAdisDt.py | 66 ++++++++---- src/View/Results/PlotSedAdisDx.py | 87 +++++++++++----- src/View/Results/WindowAdisTS.py | 147 ++++----------------------- src/View/ui/ResultsAdisTS.ui | 162 ++++++++++++++++++++++++++++-- 4 files changed, 282 insertions(+), 180 deletions(-) diff --git a/src/View/Results/PlotSedAdisDt.py b/src/View/Results/PlotSedAdisDt.py index 83a0e906..7ac68449 100644 --- a/src/View/Results/PlotSedAdisDt.py +++ b/src/View/Results/PlotSedAdisDt.py @@ -37,7 +37,7 @@ logger = logging.getLogger() class PlotAdis_dt(PamhyrPlot): def __init__(self, canvas=None, trad=None, toolbar=None, results=None, reach_id=0, profile_id=0, - pol_id=0, key="C", parent=None): + pol_id=0, key="C", type_pol=7, parent=None): super(PlotAdis_dt, self).__init__( canvas=canvas, trad=trad, @@ -51,6 +51,7 @@ class PlotAdis_dt(PamhyrPlot): self._current_profile_id = profile_id self._current_pol_id = pol_id self._key = key + self._type_pol = type_pol self.label_x = self._trad["unit_time_s"] self._available_values_y = self._trad.get_dict("values_y_pol") @@ -61,9 +62,11 @@ class PlotAdis_dt(PamhyrPlot): self.label_max = {} self.label_max["C"] = _translate("Results", "Max Concentration") self.label_max["M"] = _translate("Results", "Max Mass") - self.sed_id = {} - self.sed_id["C"] = 0 - self.sed_id["M"] = 1 + self.val_id = {} + self.val_id["C"] = 0 + self.val_id["G"] = 1 + self.val_id["M"] = 2 + self.val_id["D"] = 3 self.label_y = self._available_values_y["unit_"+self._key] @@ -109,9 +112,12 @@ class PlotAdis_dt(PamhyrPlot): self.ts.sort() x = self.ts - y = list(map(lambda data_el: data_el[self._current_pol_id][self.sed_id[self._key]], - profile.get_key("pols") - )) + if self.val_id[self._key] > 0 and self._type_pol == 1: + y=[0.0]*len(x) + else: + y = list(map(lambda data_el: data_el[self._current_pol_id][self.val_id[self._key]], + profile.get_key("pols") + )) self._line, = self.canvas.axes.plot( x, y, @@ -134,12 +140,15 @@ class PlotAdis_dt(PamhyrPlot): self.ts.sort() x = self.ts - y = [] - for ts in x: - ts_y = list(map( - lambda p: p.get_ts_key(ts, "pols")[self._current_pol_id][self.sed_id[self._key]], - reach.profiles)) - y.append(np.max(ts_y)) + if self.val_id[self._key] > 0 and self._type_pol == 1: + y=[0.0]*len(x) + else: + y = [] + for ts in x: + ts_y = list(map( + lambda p: p.get_ts_key(ts, "pols")[self._current_pol_id][self.val_id[self._key]], + reach.profiles)) + y.append(np.max(ts_y)) self._line_max, = self.canvas.axes.plot( x, y, @@ -168,17 +177,39 @@ class PlotAdis_dt(PamhyrPlot): if not self._init: self.draw() + self.update_max() self.update_data() self.update_idle() + def update_max(self): + reach = self.results.river.reach(self._current_reach_id) + self.ts = list(self.results.get("timestamps")) + self.ts.sort() + + x = self.ts + if self.val_id[self._key] > 0 and self._type_pol == 1: + y=[0.0]*len(x) + else: + y = [] + for ts in x: + ts_y = list(map( + lambda p: p.get_ts_key(ts, "pols")[self._current_pol_id][self.val_id[self._key]], + reach.profiles)) + y.append(np.max(ts_y)) + + self._line_max.set_data(x, y) + def update_data(self): reach = self.results.river.reach(self._current_reach_id) profile = reach.profile(self._current_profile_id) x = self.ts - y = list(map(lambda data_el: data_el[self._current_pol_id][self.sed_id[self._key]], - profile.get_key("pols") - )) + if self.val_id[self._key] > 0 and self._type_pol == 1: + y=[0.0]*len(x) + else: + y = list(map(lambda data_el: data_el[self._current_pol_id][self.val_id[self._key]], + profile.get_key("pols") + )) self._line.set_data(x, y) @@ -204,7 +235,8 @@ class PlotAdis_dt(PamhyrPlot): def show_current(self): self._current.set_visible(True) - def set_pollutant(self, pol_id): + def set_pollutant(self, pol_id, type_pol): if pol_id != self._current_pol_id: + self._type_pol = type_pol self._current_pol_id = pol_id self.update() diff --git a/src/View/Results/PlotSedAdisDx.py b/src/View/Results/PlotSedAdisDx.py index 7ec8cadc..9ca91058 100644 --- a/src/View/Results/PlotSedAdisDx.py +++ b/src/View/Results/PlotSedAdisDx.py @@ -37,7 +37,7 @@ logger = logging.getLogger() class PlotAdis_dx(PamhyrPlot): def __init__(self, canvas=None, trad=None, toolbar=None, results=None, reach_id=0, profile_id=0, - pol_id=0, key="C", parent=None): + pol_id=0, key="C", type_pol=7, parent=None): super(PlotAdis_dx, self).__init__( canvas=canvas, trad=trad, @@ -51,6 +51,7 @@ class PlotAdis_dx(PamhyrPlot): self._current_profile_id = profile_id self._current_pol_id = pol_id self._key = key + self._type_pol = type_pol self.label_x = self._trad["unit_pk"] self._available_values_y = self._trad.get_dict("values_y_pol") @@ -61,9 +62,11 @@ class PlotAdis_dx(PamhyrPlot): self.label_max = {} self.label_max["C"] = _translate("Results", "Max Concentration") self.label_max["M"] = _translate("Results", "Max Mass") - self.sed_id = {} - self.sed_id["C"] = 0 - self.sed_id["M"] = 1 + self.val_id = {} + self.val_id["C"] = 0 + self.val_id["G"] = 1 + self.val_id["M"] = 2 + self.val_id["D"] = 3 self.label_y = self._available_values_y["unit_"+self._key] @@ -140,10 +143,13 @@ class PlotAdis_dx(PamhyrPlot): profile = reach.profile(self._current_profile_id) x = reach.geometry.get_rk() - y = list(map( - lambda p: p.get_ts_key(self._current_timestamp, "pols")[self._current_pol_id][self.sed_id[self._key]], - reach.profiles - )) + if self.val_id[self._key] > 0 and self._type_pol == 1: + y=[0.0]*len(x) + else: + y = list(map( + lambda p: p.get_ts_key(self._current_timestamp, "pols")[self._current_pol_id][self.val_id[self._key]], + reach.profiles + )) self.set_y_lim() @@ -169,12 +175,15 @@ class PlotAdis_dx(PamhyrPlot): profile = reach.profile(self._current_profile_id) x = reach.geometry.get_rk() - y = [] - for p in reach.profiles: - rk_y = list(map(lambda data_el: data_el[self._current_pol_id][self.sed_id[self._key]], - p.get_key("pols") - )) - y.append(np.max(rk_y)) + if self.val_id[self._key] > 0 and self._type_pol == 1: + y=[0.0]*len(x) + else: + y = [] + for p in reach.profiles: + rk_y = list(map(lambda data_el: data_el[self._current_pol_id][self.val_id[self._key]], + p.get_key("pols") + )) + y.append(np.max(rk_y)) self._line_max, = self.canvas.axes.plot( x, y, @@ -203,19 +212,41 @@ class PlotAdis_dx(PamhyrPlot): if not self._init: self.draw() + self.update_max() self.update_data() + self.set_y_lim self.update_idle() + def update_max(self): + reach = self.results.river.reach(self._current_reach_id) + profile = reach.profile(self._current_profile_id) + x = reach.geometry.get_rk() + + if self.val_id[self._key] > 0 and self._type_pol == 1: + y=[0.0]*len(x) + else: + y = [] + for p in reach.profiles: + rk_y = list(map(lambda data_el: data_el[self._current_pol_id][self.val_id[self._key]], + p.get_key("pols") + )) + y.append(np.max(rk_y)) + + self._line_max.set_data(x, y) + def update_data(self): reach = self.results.river.reach(self._current_reach_id) profile = reach.profile(self._current_profile_id) x = reach.geometry.get_rk() - y = list(map( - lambda p: p.get_ts_key(self._current_timestamp, "pols")[self._current_pol_id][self.sed_id[self._key]], - reach.profiles - )) + if self.val_id[self._key] > 0 and self._type_pol == 1: + y=[0.0]*len(x) + else: + y = list(map( + lambda p: p.get_ts_key(self._current_timestamp, "pols")[self._current_pol_id][self.val_id[self._key]], + reach.profiles + )) self._line.set_data(x, y) @@ -243,22 +274,26 @@ class PlotAdis_dx(PamhyrPlot): def show_current(self): self._current.set_visible(True) - def set_pollutant(self, pol_id): + def set_pollutant(self, pol_id, type_pol): if pol_id != self._current_pol_id: + self._type_pol = type_pol self._current_pol_id = pol_id self.update() def set_y_lim(self): reach = self.results.river.reach(self._current_reach_id) - y = list( - map(lambda p: - list(map(lambda data_el: data_el[self._current_pol_id][self.sed_id[self._key]], - p.get_key("pols")) - ), - reach.profiles - ) + if self.val_id[self._key] > 0 and self._type_pol == 1: + y=[0.0] + else: + y = list( + map(lambda p: + list(map(lambda data_el: data_el[self._current_pol_id][self.val_id[self._key]], + p.get_key("pols")) + ), + reach.profiles ) + ) self.y_max = np.max(y) self.y_min = np.min(y) diff --git a/src/View/Results/WindowAdisTS.py b/src/View/Results/WindowAdisTS.py index f4647115..e54bb67e 100644 --- a/src/View/Results/WindowAdisTS.py +++ b/src/View/Results/WindowAdisTS.py @@ -107,7 +107,7 @@ class ResultsWindowAdisTS(PamhyrWindow): self._hash_data.append(self._results) self._additional_plot = {} - self._pol_id = 1 + self._pol_id = 0 self._reach_id = 0 self._profile_id = 0 @@ -200,6 +200,7 @@ class ResultsWindowAdisTS(PamhyrWindow): profile_id=self._profile_id, pol_id=self._pol_id, key="C", + type_pol = self._type_pol[self._pol_id], trad=self._trad, toolbar=self.toolbar_cdt ) @@ -227,6 +228,7 @@ class ResultsWindowAdisTS(PamhyrWindow): profile_id=self._profile_id, pol_id=self._pol_id, key="C", + type_pol = self._type_pol[self._pol_id], trad=self._trad, toolbar=self.toolbar_cdx ) @@ -252,6 +254,7 @@ class ResultsWindowAdisTS(PamhyrWindow): profile_id=self._profile_id, pol_id=self._pol_id, key="M", + type_pol = self._type_pol[self._pol_id], trad=self._trad, toolbar=self.toolbar_mdx ) @@ -278,6 +281,7 @@ class ResultsWindowAdisTS(PamhyrWindow): profile_id=self._profile_id, pol_id=self._pol_id, key="M", + type_pol = self._type_pol[self._pol_id], trad=self._trad, toolbar=self.toolbar_mdt ) @@ -287,106 +291,6 @@ class ResultsWindowAdisTS(PamhyrWindow): if self._type_pol[self._pol_id] != 7: self.find(QTabWidget, "tabWidget").setTabVisible(2, False) - self.canvas_2 = MplCanvas(width=5, height=4, dpi=100) - self.canvas_2.setObjectName("canvas_2") - self.toolbar_2 = PamhyrPlotToolbar( - self.canvas_2, self, items=[ - "home", "move", "zoom", "save", - "iso", "back/forward" - ] - ) - self.plot_layout_2 = self.find( - QVBoxLayout, "verticalLayout_tot_c") - self.plot_layout_2.addWidget(self.toolbar_2) - self.plot_layout_2.addWidget(self.canvas_2) - - self.plot_tot_c = PlotTotSedC( - canvas=self.canvas_2, - results=self._results, - reach_id=self._reach_id, - profile_id=self._profile_id, - pol_id=self._results.pollutants_list.index("total_sediment"), - trad=self._trad, - 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=self._reach_id, - profile_id=self._profile_id, - 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=self._reach_id, - profile_id=self._profile_id, - 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=self._reach_id, - profile_id=self._profile_id, - pol_id=self._results.pollutants_list.index("total_sediment"), - trad=self._trad, - toolbar=self.toolbar_5 - ) - - self.plot_tot_ed.draw() - def closeEvent(self, event): try: self._timer.stop() @@ -532,39 +436,34 @@ class ResultsWindowAdisTS(PamhyrWindow): if reach_id is not None: self.plot_cdt.set_reach(reach_id) self.plot_cdx.set_reach(reach_id) - if self._type_pol[self._pol_id] == 7: + if self._type_pol[self._pol_id] != 1: self.plot_mdx.set_reach(reach_id) self.plot_mdt.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) - self.update_table_selection_pol(0) if profile_id is not None: self.plot_cdt.set_profile(profile_id) self.plot_cdx.set_profile(profile_id) - if self._type_pol[self._pol_id] == 7: + if self._type_pol[self._pol_id] != 1: self.plot_mdx.set_profile(profile_id) self.plot_mdt.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) if pol_id is not None: self._pol_id = pol_id - self.plot_cdt.set_pollutant(self._pol_id) - self.plot_cdx.set_pollutant(self._pol_id) - if self._type_pol[self._pol_id] == 7: + self.plot_cdt.set_pollutant(self._pol_id, + self._type_pol[self._pol_id]) + self.plot_cdx.set_pollutant(self._pol_id, + self._type_pol[self._pol_id]) + if self._type_pol[self._pol_id] != 1: self.find(QTabWidget, "tabWidget").setTabVisible(2, True) - self.plot_mdx.set_pollutant(self._pol_id) - self.plot_mdt.set_pollutant(self._pol_id) + self.plot_mdx.set_pollutant(self._pol_id, + self._type_pol[self._pol_id]) + self.plot_mdt.set_pollutant(self._pol_id, + self._type_pol[self._pol_id]) else: self.find(QTabWidget, "tabWidget").setTabVisible(2, False) @@ -573,13 +472,9 @@ class ResultsWindowAdisTS(PamhyrWindow): if timestamp is not None: self.plot_cdt.set_timestamp(timestamp) self.plot_cdx.set_timestamp(timestamp) - if self._type_pol[self._pol_id] == 7: + if self._type_pol[self._pol_id] != 1: self.plot_mdx.set_timestamp(timestamp) self.plot_mdt.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 @@ -634,20 +529,12 @@ class ResultsWindowAdisTS(PamhyrWindow): if self._type_pol[self._pol_id] == 7: self.plot_mdx.results = self._results self.plot_mdt.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_cdt.draw() self.plot_cdx.draw() if self._type_pol[self._pol_id] == 7: self.plot_mdx.draw() self.plot_mdt.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 08dd7eb3..8ed94324 100644 --- a/src/View/ui/ResultsAdisTS.ui +++ b/src/View/ui/ResultsAdisTS.ui @@ -24,7 +24,7 @@ - + Qt::Horizontal @@ -133,7 +133,7 @@ true - 2 + 0 @@ -198,12 +198,68 @@ true - Mass + Linear mass density - - + + + + + QLayout::SetDefaultConstraint + + + 0 + + + + + Left bed + + + buttonGroup + + + + + + + Minor bed + + + true + + + buttonGroup + + + + + + + Right bed + + + buttonGroup + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + true @@ -213,7 +269,7 @@ - Mass dx + Linear mass density dx @@ -223,7 +279,7 @@ - Mass dt + Linear mass density dt @@ -295,6 +351,94 @@ + + + Thickness + + + + + + + + + + Left bed + + + buttonGroup_2 + + + + + + + Minor bed + + + true + + + buttonGroup_2 + + + + + + + Right bed + + + buttonGroup_2 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 0 + + + + Thickness dx + + + + + + + + + + Thickness dt + + + + + + + + + + + + + @@ -370,4 +514,8 @@ + + + +