From f1d6eb8990c567e847d0ca32712fae5076e2e98f Mon Sep 17 00:00:00 2001 From: Theophile Terraz Date: Thu, 5 Dec 2024 16:03:40 +0100 Subject: [PATCH] more work on adists results --- src/View/Results/PlotSedAdisDt.py | 1 + src/View/Results/PlotSedAdisDx.py | 49 +++++++++++++------ src/View/Results/TableAdisTS.py | 11 ++--- src/View/Results/WindowAdisTS.py | 79 ++++++++++++++++++++++++++++--- src/View/Results/translate.py | 1 + src/View/ui/ResultsAdisTS.ui | 62 +----------------------- 6 files changed, 114 insertions(+), 89 deletions(-) diff --git a/src/View/Results/PlotSedAdisDt.py b/src/View/Results/PlotSedAdisDt.py index 7ac68449..86265b2b 100644 --- a/src/View/Results/PlotSedAdisDt.py +++ b/src/View/Results/PlotSedAdisDt.py @@ -240,3 +240,4 @@ class PlotAdis_dt(PamhyrPlot): self._type_pol = type_pol self._current_pol_id = pol_id self.update() + self.update_current() diff --git a/src/View/Results/PlotSedAdisDx.py b/src/View/Results/PlotSedAdisDx.py index 9ca91058..c831aa74 100644 --- a/src/View/Results/PlotSedAdisDx.py +++ b/src/View/Results/PlotSedAdisDx.py @@ -53,22 +53,31 @@ class PlotAdis_dx(PamhyrPlot): self._key = key self._type_pol = type_pol - self.label_x = self._trad["unit_pk"] + self.label_x = self._trad["unit_rk"] self._available_values_y = self._trad.get_dict("values_y_pol") self.label = {} - self.label["C"] = _translate("Results", "Concentration") - self.label["M"] = _translate("Results", "Mass") self.label_max = {} + self.label_min = {} + self.label["C"] = _translate("Results", "Concentration") self.label_max["C"] = _translate("Results", "Max Concentration") - self.label_max["M"] = _translate("Results", "Max Mass") + self.label_min["C"] = _translate("Results", "Min Concentration") + if self._type_pol == -1: # Total + self.label["M"] = _translate("Results", "Thickness") + self.label_max["M"] = _translate("Results", "Max Thickness") + self.label_min["M"] = _translate("Results", "Min Thickness") + self.label_y = self._available_values_y["unit_thickness"] + else: + self.label["M"] = _translate("Results", "Mass") + self.label_max["M"] = _translate("Results", "Max Mass") + self.label_min["M"] = _translate("Results", "Min Mass") + self.label_y = self._available_values_y["unit_"+self._key] 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] self._isometric_axis = False @@ -95,15 +104,13 @@ class PlotAdis_dx(PamhyrPlot): self._init = False return - self.draw_max(reach) + self.draw_min_and_max(reach) self.draw_data(reach, profile) self.draw_current(reach) self.draw_profiles_hs(reach) self.enable_legend() - self.set_y_lim() - self.idle() self.update_current() self._init = True @@ -151,8 +158,6 @@ class PlotAdis_dx(PamhyrPlot): reach.profiles )) - self.set_y_lim() - self._line, = self.canvas.axes.plot( x, y, label=self.label[self._key], @@ -160,6 +165,8 @@ class PlotAdis_dx(PamhyrPlot): **self.plot_default_kargs ) + self.set_y_lim() + def draw_current(self, reach): rk = reach.geometry.get_rk() @@ -171,7 +178,7 @@ class PlotAdis_dx(PamhyrPlot): lw=1. ) - def draw_max(self, reach): + def draw_min_and_max(self, reach): profile = reach.profile(self._current_profile_id) x = reach.geometry.get_rk() @@ -179,11 +186,13 @@ class PlotAdis_dx(PamhyrPlot): y=[0.0]*len(x) else: y = [] + z = [] 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)) + z.append(np.min(rk_y)) self._line_max, = self.canvas.axes.plot( x, y, @@ -194,6 +203,15 @@ class PlotAdis_dx(PamhyrPlot): markersize=0 ) + self._line_min, = self.canvas.axes.plot( + x, y, + label=self.label_min[self._key], + color='g', + linestyle='dotted', + lw=1., + markersize=0 + ) + def set_reach(self, reach_id): self._current_reach_id = reach_id self._current_profile_id = 0 @@ -212,12 +230,12 @@ class PlotAdis_dx(PamhyrPlot): if not self._init: self.draw() - self.update_max() + self.update_min_and_max() self.update_data() self.set_y_lim self.update_idle() - def update_max(self): + def update_min_and_max(self): reach = self.results.river.reach(self._current_reach_id) profile = reach.profile(self._current_profile_id) x = reach.geometry.get_rk() @@ -226,13 +244,16 @@ class PlotAdis_dx(PamhyrPlot): y=[0.0]*len(x) else: y = [] + z = [] 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)) + z.append(np.min(rk_y)) self._line_max.set_data(x, y) + self._line_min.set_data(x, z) def update_data(self): reach = self.results.river.reach(self._current_reach_id) @@ -297,7 +318,7 @@ class PlotAdis_dx(PamhyrPlot): self.y_max = np.max(y) self.y_min = np.min(y) - if self.y_max - self.y_min < 1: + if self.y_max - self.y_min < 0.000001: self.y_min = (self.y_max + self.y_min)/2 - 0.5 self.y_max = (self.y_max + self.y_min)/2 + 0.5 diff --git a/src/View/Results/TableAdisTS.py b/src/View/Results/TableAdisTS.py index fef91191..b2937362 100644 --- a/src/View/Results/TableAdisTS.py +++ b/src/View/Results/TableAdisTS.py @@ -59,6 +59,7 @@ class TableModel(PamhyrTableModel): elif self._opt_data == "pollutants": tmp_list = self._data.pollutants_list.copy() ###print(type(tmp_list)) + tmp_list.remove("total_sediment") #tmp_list.insert(len(tmp_list), "total_sediment") self._lst = tmp_list ###print("=====table pollutants: ", self._lst) @@ -101,17 +102,12 @@ class TableModel(PamhyrTableModel): tmp_list.remove("total_sediment") tmp_list2 = self._data.pollutants_list.copy() for pol in tmp_list: - print('head name: ', self._headers[column]) - print("pols: ", tmp_list, pol) pol_index = tmp_list2.index(pol) header_name = pol + " Concentration" - #print(f"_lst({row}): {len(self._lst[row])}") - #print(f"longueur : {len(self._lst[row].get_ts_key(self._timestamp, 'pols')[pol_index])}") if self._headers[column] == header_name: v = self._lst[row].get_ts_key(self._timestamp, "pols")[pol_index][0] return f"{v:.4f}" - if self._headers[column] == pol + " Mass" and self._type_pol==7: ##### - print(self._lst[row].get_ts_key(self._timestamp, "pols")[pol_index]) + if self._headers[column] == pol + " Mass" and self._type_pol[pol_index]==7: m1 = self._lst[row].get_ts_key(self._timestamp, "pols")[pol_index][1] m2 = self._lst[row].get_ts_key(self._timestamp, "pols")[pol_index][2] m3 = self._lst[row].get_ts_key(self._timestamp, "pols")[pol_index][3] @@ -134,7 +130,6 @@ class TableModel(PamhyrTableModel): def timestamp(self): return self._timestamp - @timestamp.setter - def timestamp(self, timestamp): + def set_timestamp(self, timestamp): self._timestamp = timestamp self.layoutChanged.emit() diff --git a/src/View/Results/WindowAdisTS.py b/src/View/Results/WindowAdisTS.py index e54bb67e..30fa5693 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 = 0 + self._pol_id = 1 self._reach_id = 0 self._profile_id = 0 @@ -122,7 +122,7 @@ class ResultsWindowAdisTS(PamhyrWindow): self.setup_connections() self.update_table_selection_reach(self._reach_id) self.update_table_selection_profile(self._profile_id) - self.update_table_selection_pol(self._pol_id) + self.update_table_selection_pol(self._pol_id-1) except Exception as e: logger_exception(e) return @@ -130,7 +130,6 @@ class ResultsWindowAdisTS(PamhyrWindow): def set_type_pol(self): self._type_pol = [] tmp_list = self._results.river.reach(0).profiles - print(self._results.pollutants_list) for pol_index in range(self._results.nb_pollutants): if self._results.pollutants_list[pol_index] == "total_sediment": self._type_pol.append(-1) @@ -291,6 +290,62 @@ class ResultsWindowAdisTS(PamhyrWindow): if self._type_pol[self._pol_id] != 7: self.find(QTabWidget, "tabWidget").setTabVisible(2, False) + # Thickness + + self.canvas_tdx = MplCanvas(width=5, height=4, dpi=100) + self.canvas_tdx.setObjectName("canvas_tdx") + self.toolbar_tdx = PamhyrPlotToolbar( + self.canvas_tdx, self, items=[ + "home", "move", "zoom", "save", + "iso", "back/forward" + ] + ) + self.plot_layout_tdx = self.find( + QVBoxLayout, "verticalLayout_tdx") + self.plot_layout_tdx.addWidget(self.toolbar_tdx) + self.plot_layout_tdx.addWidget(self.canvas_tdx) + + self.plot_tdx = PlotAdis_dx( + canvas=self.canvas_tdx, + results=self._results, + reach_id=self._reach_id, + profile_id=self._profile_id, + pol_id=0, + key="M", + type_pol = self._type_pol[0], + trad=self._trad, + toolbar=self.toolbar_tdx + ) + + self.plot_tdx.draw() + + self.canvas_tdt = MplCanvas(width=5, height=4, dpi=100) + self.canvas_tdt.setObjectName("canvas_tdt") + self.toolbar_tdt = PamhyrPlotToolbar( + self.canvas_tdt, self, items=[ + "home", "move", "zoom", "save", + "iso", "back/forward" + ] + ) + self.plot_layout_tdt = self.find( + QVBoxLayout, "verticalLayout_tdt") + self.plot_layout_tdt.addWidget(self.toolbar_tdt) + self.plot_layout_tdt.addWidget(self.canvas_tdt) + + self.plot_tdt = PlotAdis_dt( + canvas=self.canvas_tdt, + results=self._results, + reach_id=self._reach_id, + profile_id=self._profile_id, + pol_id=0, + key="M", + type_pol = self._type_pol[0], + trad=self._trad, + toolbar=self.toolbar_tdt + ) + + self.plot_tdt.draw() + def closeEvent(self, event): try: self._timer.stop() @@ -402,7 +457,7 @@ class ResultsWindowAdisTS(PamhyrWindow): table.scrollTo(index) self._table["profile"].update(ind) - ###self._table["raw_data"].update(ind) + self._table["raw_data"].update(ind) def update_table_selection_profile(self, ind): for t in ["profile"]:###, "raw_data"]: @@ -439,6 +494,8 @@ class ResultsWindowAdisTS(PamhyrWindow): if self._type_pol[self._pol_id] != 1: self.plot_mdx.set_reach(reach_id) self.plot_mdt.set_reach(reach_id) + self.plot_tdt.set_reach(reach_id) + self.plot_tdx.set_reach(reach_id) self.update_table_selection_reach(reach_id) self.update_table_selection_profile(0) @@ -449,11 +506,13 @@ class ResultsWindowAdisTS(PamhyrWindow): if self._type_pol[self._pol_id] != 1: self.plot_mdx.set_profile(profile_id) self.plot_mdt.set_profile(profile_id) + self.plot_tdt.set_profile(profile_id) + self.plot_tdx.set_profile(profile_id) self.update_table_selection_profile(profile_id) if pol_id is not None: - self._pol_id = pol_id + self._pol_id = pol_id+1 self.plot_cdt.set_pollutant(self._pol_id, self._type_pol[self._pol_id]) self.plot_cdx.set_pollutant(self._pol_id, @@ -467,7 +526,7 @@ class ResultsWindowAdisTS(PamhyrWindow): else: self.find(QTabWidget, "tabWidget").setTabVisible(2, False) - self.update_table_selection_pol(self._pol_id) + self.update_table_selection_pol(self._pol_id-1) if timestamp is not None: self.plot_cdt.set_timestamp(timestamp) @@ -475,8 +534,10 @@ class ResultsWindowAdisTS(PamhyrWindow): if self._type_pol[self._pol_id] != 1: self.plot_mdx.set_timestamp(timestamp) self.plot_mdt.set_timestamp(timestamp) + self.plot_tdt.set_timestamp(timestamp) + self.plot_tdx.set_timestamp(timestamp) - self._table["raw_data"].timestamp = timestamp + self._table["raw_data"].set_timestamp(timestamp) self.update_statusbar() @@ -529,12 +590,16 @@ 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_tdt.results = self._results + self.plot_tdx.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_tdt.draw() + self.plot_tdx.draw() def _reload_slider(self): self._slider_time = self.find(QSlider, f"horizontalSlider_time") diff --git a/src/View/Results/translate.py b/src/View/Results/translate.py index f74fc2d1..515ac420 100644 --- a/src/View/Results/translate.py +++ b/src/View/Results/translate.py @@ -129,5 +129,6 @@ class ResultsTranslate(MainTranslate): self._sub_dict["values_y_pol"] = { "unit_C": self._dict["unit_concentration"], "unit_M": self._dict["unit_mass"], + "unit_thickness": self._dict["unit_thickness"], } diff --git a/src/View/ui/ResultsAdisTS.ui b/src/View/ui/ResultsAdisTS.ui index 8ed94324..52534ef5 100644 --- a/src/View/ui/ResultsAdisTS.ui +++ b/src/View/ui/ResultsAdisTS.ui @@ -293,64 +293,6 @@ - - - Total Sediments - - - - - - - - 0 - - - - Concentration - - - - - - - - - - Left thickness - - - - - - - - - - Minor thickness - - - - - - - - - - Right thickness - - - - - - - - - - - - - Thickness @@ -419,7 +361,7 @@ - + @@ -429,7 +371,7 @@ - +