work on multiple results plot

This commit is contained in:
Theophile Terraz committed 2025-02-04 11:12:56 +01:00
1 parent 52c153fa84
commit fa8f07b97e
11 files changed
+155 -265

No files matched your search

+42 -42
View File
@@ -49,7 +49,7 @@ unit = {
class CustomPlot(PamhyrPlot):
def __init__(self, x, y, envelop, reach, profile, timestamp,
data=None, canvas=None, trad=None, res_id=0,
data=None, canvas=None, trad=None, res_id=[0],
toolbar=None, parent=None):
super(CustomPlot, self).__init__(
canvas=canvas,
@@ -65,7 +65,7 @@ class CustomPlot(PamhyrPlot):
self._reach = reach
self._profile = profile
self._timestamp = timestamp
self._current_res_id = res_id
self._current_res_id = res_id[0]
self._parent = parent
logger.debug(
@@ -133,7 +133,7 @@ class CustomPlot(PamhyrPlot):
"""
Get SL list for profile p at initial time (initial data)
"""
t0 = min(list(self.data[self._current_res_id].get("timestamps")))
t0 = min(list(self.data[self._current_res_id[0]].get("timestamps")))
return map(
lambda p: p.get_ts_key(t0, "sl")[0],
reach.profiles
@@ -148,8 +148,8 @@ class CustomPlot(PamhyrPlot):
reach.profiles
)
def get_ts_zmin(self, profile):
results = self.data[self._current_res_id]
def get_ts_zmin(self, profile, res_id):
results = self.data[res_id]
nt = len(list(results.get("timestamps")))
reach = results.river.reach(self._reach)
berdrock = self.sl_compute_bedrock(reach)
@@ -170,6 +170,7 @@ class CustomPlot(PamhyrPlot):
return ts_z_min
def _draw_rk(self):
#for res_id in self._current_res_id:
results = self.data[self._current_res_id]
reach = results.river.reach(self._reach)
if self._current_res_id == 2: # compare results
@@ -215,7 +216,7 @@ class CustomPlot(PamhyrPlot):
if "bed_elevation" in self._y:
ax = self._axes[unit["bed_elevation"]]
if self._current_res_id != 2:
if self._current_res_id < 2:
line = ax.plot(
rk, z_min,
color='grey', lw=1.,
@@ -242,13 +243,13 @@ class CustomPlot(PamhyrPlot):
if (self._envelop and
reach.has_sediment() and
self._current_res_id != 2):
self._current_res_id < 2):
ax = self._axes[unit["bed_elevation_envelop"]]
e = list(
map(
lambda p: max(self.get_ts_zmin(p)),
lambda p: max(self.get_ts_zmin(p, res_id)),
range(len(reach))
)
)
@@ -261,7 +262,7 @@ class CustomPlot(PamhyrPlot):
e = list(
map(
lambda p: min(self.get_ts_zmin(p)),
lambda p: min(self.get_ts_zmin(p, res_id)),
range(len(reach))
)
)
@@ -281,7 +282,7 @@ class CustomPlot(PamhyrPlot):
)
self.lines["water_elevation"] = line
if "bed_elevation" in self._y and self._current_res_id != 2:
if "bed_elevation" in self._y and self._current_res_id < 2:
self.fill = ax.fill_between(
rk, z_min, z,
color='blue', alpha=0.5, interpolate=True
@@ -398,7 +399,7 @@ class CustomPlot(PamhyrPlot):
if "depth" in self._y:
ax = self._axes[unit["depth"]]
if self._current_res_id != 2:
if self._current_res_id < 2:
d = list(
map(
lambda p: p.geometry.max_water_depth(
@@ -434,7 +435,7 @@ class CustomPlot(PamhyrPlot):
)
self.lines["depth"] = line
if self._envelop and self._current_res_id != 2:
if self._envelop and self._current_res_id < 2:
ax = self._axes[unit["depth_envelop"]]
@@ -467,7 +468,7 @@ class CustomPlot(PamhyrPlot):
if "mean_depth" in self._y:
ax = self._axes[unit["mean_depth"]]
if self._current_res_id != 2:
if self._current_res_id < 2:
d = list(
map(
lambda p: p.geometry.mean_water_depth(
@@ -506,7 +507,7 @@ class CustomPlot(PamhyrPlot):
if "froude" in self._y:
ax = self._axes[unit["froude"]]
if self._current_res_id != 2:
if self._current_res_id < 2:
fr = list(
map(
lambda p:
@@ -562,7 +563,7 @@ class CustomPlot(PamhyrPlot):
if "wet_area" in self._y:
ax = self._axes[unit["wet_area"]]
if self._current_res_id != 2:
if self._current_res_id < 2:
d = list(
map(
lambda p: p.geometry.wet_area(
@@ -640,7 +641,7 @@ class CustomPlot(PamhyrPlot):
)
)
if "bed_elevation" in self._y:
if self._current_res_id != 2:
if self._current_res_id < 2:
dz = z_min
else:
if reach.has_sediment():
@@ -660,7 +661,7 @@ class CustomPlot(PamhyrPlot):
if "water_elevation" in self._y:
self.lines["water_elevation"][0].set_ydata(z)
if "bed_elevation" in self._y and self._current_res_id != 2:
if "bed_elevation" in self._y and self._current_res_id < 2:
ax = self._axes[unit["water_elevation"]]
self.fill.remove()
self.fill = ax.fill_between(
@@ -675,7 +676,7 @@ class CustomPlot(PamhyrPlot):
self.lines["velocity"][0].set_ydata(v)
if "depth" in self._y:
if self._current_res_id != 2:
if self._current_res_id < 2:
d = list(
map(
lambda p: p.geometry.max_water_depth(
@@ -708,7 +709,7 @@ class CustomPlot(PamhyrPlot):
self.lines["depth"][0].set_ydata(d)
if "mean_depth" in self._y:
if self._current_res_id != 2:
if self._current_res_id < 2:
d = list(
map(
lambda p: p.geometry.mean_water_depth(
@@ -741,7 +742,7 @@ class CustomPlot(PamhyrPlot):
self.lines["mean_depth"][0].set_ydata(d)
if "froude" in self._y:
if self._current_res_id != 2:
if self._current_res_id < 2:
fr = list(
map(
lambda p:
@@ -792,7 +793,7 @@ class CustomPlot(PamhyrPlot):
self.lines["froude"][0].set_ydata(fr)
if "wet_area" in self._y:
if self._current_res_id != 2:
if self._current_res_id < 2:
d = list(
map(
lambda p: p.geometry.wet_area(
@@ -901,9 +902,9 @@ class CustomPlot(PamhyrPlot):
z = profile.get_key("Z")
v = profile.get_key("V")
z_min = profile.geometry.z_min()
if self._current_res_id != 2:
if self._current_res_id < 2:
if reach.has_sediment():
ts_z_min = self.get_ts_zmin(self._profile)
ts_z_min = self.get_ts_zmin(self._profile, res_id)
else:
ts_z_min = list(
map(
@@ -920,8 +921,8 @@ class CustomPlot(PamhyrPlot):
if self._current_res_id == 2:
if reach.has_sediment():
ts_z_min1 = self.get_ts_zmin(self._profile1)
ts_z_min2 = self.get_ts_zmin(self._profile2)
ts_z_min1 = self.get_ts_zmin(self._profile1, 0)
ts_z_min2 = self.get_ts_zmin(self._profile2, 1)
ts_z_min = list(
map(
lambda x, y: x - y,
@@ -953,7 +954,7 @@ class CustomPlot(PamhyrPlot):
)
self.lines["water_elevation"] = line
if "bed_elevation" in self._y and self._current_res_id != 2:
if "bed_elevation" in self._y and self._current_res_id < 2:
self.fill = ax.fill_between(
ts, ts_z_min, z,
@@ -982,7 +983,7 @@ class CustomPlot(PamhyrPlot):
if "depth" in self._y:
ax = self._axes[unit["depth"]]
if self._current_res_id != 2:
if self._current_res_id < 2:
d = list(
map(lambda z: profile.geometry.max_water_depth(z), z)
)
@@ -1009,7 +1010,7 @@ class CustomPlot(PamhyrPlot):
if "mean_depth" in self._y:
ax = self._axes[unit["mean_depth"]]
if self._current_res_id != 2:
if self._current_res_id < 2:
d = list(
map(lambda z: profile.geometry.mean_water_depth(z), z)
)
@@ -1036,7 +1037,7 @@ class CustomPlot(PamhyrPlot):
if "froude" in self._y:
ax = self._axes[unit["froude"]]
if self._current_res_id != 2:
if self._current_res_id < 2:
d = list(
map(lambda z, v:
v /
@@ -1077,7 +1078,7 @@ class CustomPlot(PamhyrPlot):
if "wet_area" in self._y:
ax = self._axes[unit["wet_area"]]
if self._current_res_id != 2:
if self._current_res_id < 2:
d = list(
map(lambda z: profile.geometry.wet_area(z), z)
)
@@ -1136,7 +1137,7 @@ class CustomPlot(PamhyrPlot):
q = profile.get_key("Q")
z = profile.get_key("Z")
v = profile.get_key("V")
if self._current_res_id != 2:
if self._current_res_id < 2:
if reach.has_sediment():
ts_z_min = self.get_ts_zmin(self._profile)
else:
@@ -1150,8 +1151,8 @@ class CustomPlot(PamhyrPlot):
if "bed_elevation" in self._y:
if self._current_res_id == 2:
if reach.has_sediment():
ts_z_min1 = self.get_ts_zmin(self._profile1)
ts_z_min2 = self.get_ts_zmin(self._profile2)
ts_z_min1 = self.get_ts_zmin(self._profile1, 0)
ts_z_min2 = self.get_ts_zmin(self._profile2, 1)
ts_z_min = list(
map(
lambda x, y: x - y,
@@ -1172,7 +1173,7 @@ class CustomPlot(PamhyrPlot):
if "water_elevation" in self._y:
self.lines["water_elevation"][0].set_ydata(z)
if "bed_elevation" in self._y and self._current_res_id != 2:
if "bed_elevation" in self._y and self._current_res_id < 2:
ax = self._axes[unit["bed_elevation"]]
self.fill.remove()
self.fill = ax.fill_between(
@@ -1187,7 +1188,7 @@ class CustomPlot(PamhyrPlot):
self.lines["velocity"][0].set_ydata(v)
if "depth" in self._y:
if self._current_res_id != 2:
if self._current_res_id < 2:
d = list(
map(lambda z: profile.geometry.max_water_depth(z), z)
)
@@ -1208,7 +1209,7 @@ class CustomPlot(PamhyrPlot):
self.lines["depth"][0].set_ydata(d)
if "mean_depth" in self._y:
if self._current_res_id != 2:
if self._current_res_id < 2:
d = list(
map(lambda z: profile.geometry.mean_water_depth(z), z)
)
@@ -1229,7 +1230,7 @@ class CustomPlot(PamhyrPlot):
self.lines["mean_depth"][0].set_ydata(d)
if "froude" in self._y:
if self._current_res_id != 2:
if self._current_res_id < 2:
d = list(
map(lambda z, v:
v /
@@ -1265,7 +1266,7 @@ class CustomPlot(PamhyrPlot):
self.lines["froude"][0].set_ydata(d)
if "wet_area" in self._y:
if self._current_res_id != 2:
if self._current_res_id < 2:
d = list(
map(lambda z: profile.geometry.wet_area(z), z)
)
@@ -1319,7 +1320,7 @@ class CustomPlot(PamhyrPlot):
color='black', fontsize=10
)
if self._current_res_id != 2:
if self._current_res_id < 2:
self.canvas.axes.set_ylabel(
self._trad[self._y_axes[0]],
color='black', fontsize=10
@@ -1334,14 +1335,13 @@ class CustomPlot(PamhyrPlot):
if len(self.lines) != 0:
self.lines.clear()
for axes in self._y_axes[1:]:
print("axes: ", axes)
if axes in self._axes.keys():
for ll in self._axes[axes].lines:
ll.remove()
else:
ax_new = self.canvas.axes.twinx()
self._axes[axes] = ax_new
if self._current_res_id != 2:
if self._current_res_id < 2:
self._axes[axes].set_ylabel(
self._trad[axes],
color='black', fontsize=10
@@ -1398,7 +1398,7 @@ class CustomPlot(PamhyrPlot):
self.draw_current()
def set_result(self, res_id):
self._current_res_id = res_id
self._current_res_id = res_id[0]
self.draw()
def set_timestamp(self, timestamp):
+2 -2
View File
@@ -41,7 +41,7 @@ class PlotAC(PamhyrPlot):
self._current_reach_id = reach_id
self._current_profile_id = profile_id
self._current_res_id = res_id
self._current_res_id = res_id[0]
self._timestamps = parent._timestamps
self._current_timestamp = max(self._timestamps)
@@ -144,7 +144,7 @@ class PlotAC(PamhyrPlot):
self.update()
def set_result(self, res_id):
self._current_res_id = res_id
self._current_res_id = res_id[0]
self.update()
def set_timestamp(self, timestamp):
+38 -18
View File
@@ -35,7 +35,7 @@ logger = logging.getLogger()
class PlotH(PamhyrPlot):
def __init__(self, canvas=None, trad=None, toolbar=None,
results=None, reach_id=0, profile_id=0, res_id=0,
results=None, reach_id=0, profile_id=0, res_id=[0],
parent=None):
super(PlotH, self).__init__(
canvas=canvas,
@@ -65,6 +65,9 @@ class PlotH(PamhyrPlot):
# self._auto_relim_update = False
# self._autoscale_update = False
self._line_max = []
self._line = []
@property
def results(self):
return self.data
@@ -82,19 +85,33 @@ class PlotH(PamhyrPlot):
if self.results is None:
return
if self.results[self._current_res_id] is None:
if len(self._current_res_id) < 1:
return
results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id)
for res_id in self._current_res_id:
if self.results[res_id] is None:
continue
if reach.geometry.number_profiles == 0:
self._init = False
return
results = self.results[res_id]
reach = results.river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id)
self.draw_max(reach)
self.draw_data(reach, profile)
if reach.geometry.number_profiles == 0:
self._init = False
return
self.draw_max(reach)
self.draw_data(reach, profile)
self.canvas.axes.set_xlabel(
self._trad["unit_time_s"],
color='black', fontsize=10
)
self.canvas.axes.set_ylabel(
self._trad["unit_discharge"],
color='black', fontsize=10
)
self.set_ticks_time_formater()
@@ -110,12 +127,13 @@ class PlotH(PamhyrPlot):
x = self._timestamps
y = profile.get_key("Q")
self._line, = self.canvas.axes.plot(
line, = self.canvas.axes.plot(
x, y,
label=self.label_discharge,
color=self.color_plot,
**self.plot_default_kargs
)
self._line.append(line)
def draw_current(self):
self._current, = self.canvas.axes.plot(
@@ -138,13 +156,14 @@ class PlotH(PamhyrPlot):
ts_y = max(ts_y, q)
y.append(ts_y)
self._line_max, = self.canvas.axes.plot(
m, = self.canvas.axes.plot(
x, y,
label=self.label_discharge_max,
color=self.color_plot_highlight,
linestyle='dotted',
**self.plot_default_kargs
)
self._line_max.append(m)
def set_reach(self, reach_id):
self._current_reach_id = reach_id
@@ -173,14 +192,15 @@ class PlotH(PamhyrPlot):
self.update_idle()
def update_data(self):
results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id)
for res, res_id in enumerate(self._current_res_id):
results = self.results[res_id]
reach = results.river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id)
x = self._timestamps
y = profile.get_key("Q")
x = self._timestamps
y = profile.get_key("Q")
self._line.set_data(x, y)
self._line[res].set_data(x, y)
def update_current(self):
y = self._current.get_ydata()
+2 -2
View File
@@ -44,7 +44,7 @@ class PlotRKC(PamhyrPlot):
self._current_reach_id = reach_id
self._current_profile_id = profile_id
self._current_res_id = res_id
self._current_res_id = res_id[0]
self._timestamps = parent._timestamps
self._current_timestamp = max(self._timestamps)
@@ -323,7 +323,7 @@ class PlotRKC(PamhyrPlot):
self.update_current()
def set_result(self, res_id):
self._current_res_id = res_id
self._current_res_id = res_id[0]
self.update()
def set_timestamp(self, timestamp):
+2 -2
View File
@@ -56,7 +56,7 @@ class PlotXY(PamhyrPlot):
self._current_timestamp = max(self._timestamps)
self._current_reach_id = reach_id
self._current_profile_id = profile_id
self._current_res_id = res_id
self._current_res_id = res_id[0]
self.label_x = _translate("Results", "X (m)")
self.label_y = _translate("Results", "Y (m)")
@@ -316,7 +316,7 @@ class PlotXY(PamhyrPlot):
self.update_idle()
def set_result(self, res_id):
self._current_res_id = res_id
self._current_res_id = res_id[0]
self.update()
def set_timestamp(self, timestamp):
+6 -7
View File
@@ -88,7 +88,7 @@ class ResultsWindow(PamhyrWindow):
results=None, parent=None, trad=None):
self._solvers = [r._solver for r in results]
self._results = results
self._current_results = 0
self._current_results = [0]
if trad is None:
trad = ResultsTranslate()
@@ -125,8 +125,9 @@ class ResultsWindow(PamhyrWindow):
return
self.update(reach_id=0,
profile_id=0,
solver_id=0)
profile_id=0)
self.update_table_selection_solver(0)
def setup_table(self):
self._table = {}
@@ -147,7 +148,7 @@ class ResultsWindow(PamhyrWindow):
table.hide()
def setup_slider(self):
default_reach = self._results[self._current_results].river.reach(0)
default_reach = self._results[self._current_results[0]].river.reach(0)
self._slider_time = self.find(QSlider, f"horizontalSlider_time")
self._slider_time.setMaximum(len(self._timestamps) - 1)
@@ -450,8 +451,6 @@ class ResultsWindow(PamhyrWindow):
for plot in self._additional_plot:
self._additional_plot[plot].set_result(solver_id)
self.update_table_selection_solver(solver_id)
if timestamp is not None:
self.plot_xy.set_timestamp(timestamp)
self.plot_ac.set_timestamp(timestamp)
@@ -512,7 +511,7 @@ class ResultsWindow(PamhyrWindow):
if len(indexes) == 0:
return
self.update(solver_id=indexes[0].row())
self.update(solver_id=[i.row() for i in indexes])
def _set_current_timestamp(self):
timestamp = self._timestamps[self._slider_time.value()]
+6 -10
View File
@@ -106,16 +106,13 @@ class UnitTranslate(CommonWordTranslate):
self._dict["unit_min_velocity"] = _translate(
"Unit", "Min Velocity (m/s)"
)
self._dict["unit_discharge"] = _translate("Unit", "Discharge (m³/s)")
self._dict["unit_discharge"] = _translate("Unit", "Discharge") + " (m³/s)"
self._dict["unit_discharge_envelop"] = _translate(
"Unit", "Discharge Envelop (m³/s)"
)
"Unit", "Discharge Envelop") + " (m³/s)"
self._dict["unit_max_discharge"] = _translate(
"Unit", "Max Discharge (m³/s)"
)
"Unit", "Max Discharge") + " (m³/s)"
self._dict["unit_min_discharge"] = _translate(
"Unit", "Min Discharge (m³/s)"
)
"Unit", "Min Discharge") + " (m³/s)"
self._dict["unit_area_he"] = _translate("Unit", "Area (hectare)")
self._dict["unit_time_s"] = _translate("Unit", "Time (sec)")
@@ -136,7 +133,7 @@ class UnitTranslate(CommonWordTranslate):
self._dict["unit_concentration"] = _translate(
"Unit", "Concentration (g/l)"
)
self._dict["unit_wet_area"] = _translate("Unit", "Wet Area (m²)")
self._dict["unit_wet_area"] = _translate("Unit", "Wet Area") + " (m²)"
self._dict["unit_wet_perimeter"] = _translate(
"Unit", "Wet Perimeter (m)"
)
@@ -146,8 +143,7 @@ class UnitTranslate(CommonWordTranslate):
self._dict["unit_froude"] = _translate("Unit", "Froude number")
self._dict["unit_mass"] = _translate("Unit", "Mass (kg)")
self._dict["unit_concentration"] = _translate(
"Unit", "Concentration (kg/m³)"
)
"Unit", "Concentration") + " (kg/m³)"
class MainTranslate(UnitTranslate):