add envelop in custom plots + optim + clean

compare_results
Theophile Terraz 2024-11-04 16:03:18 +01:00
parent e25a3ae98c
commit 5f043468ee
13 changed files with 414 additions and 75 deletions

View File

@ -52,7 +52,7 @@ class PlotRKZ(PamhyrPlot):
self.line_rk_zmin_zmax_highlight = None
self.label_x = self._trad["unit_rk"]
self.label_y = self._trad["unit_height"]
self.label_y = self._trad["unit_depth"]
self.before_plot_selected = None
self.plot_selected = None

View File

@ -104,15 +104,15 @@ class InitialConditionTableModel(PamhyrTableModel):
row = index.row()
column = index.column()
if self._headers[column] is "speed":
if self._headers[column] == "velocity":
z = self._lst.get(row)["elevation"]
q = self._lst.get(row)["discharge"]
profile = self._reach.reach.get_profiles_from_rk(
self._lst.get(row)["rk"]
)
if len(profile) >= 1:
speed = profile[0].speed(q, z)
return f"{speed:.4f}"
velocity = profile[0].speed(q, z)
return f"{velocity:.4f}"
return ""
elif self._headers[column] not in ["name", "comment"]:

View File

@ -39,7 +39,7 @@ class ICTranslate(MainTranslate):
"rk": self._dict["unit_rk"],
"discharge": self._dict["unit_discharge"],
"elevation": self._dict["unit_elevation"],
"height": self._dict["unit_height"],
"speed": self._dict["unit_speed"],
"height": self._dict["unit_depth"],
"velocity": self._dict["unit_velocity"],
# "comment": _translate("InitialCondition", "Comment"),
}

View File

@ -30,11 +30,15 @@ from View.Results.CustomPlot.Translate import CustomPlotTranslate
logger = logging.getLogger()
unit = {
"elevation": "0-meter",
"bed_elevation": "0-meter",
"water_elevation": "0-meter",
"water_elevation_envelop": "0-meter",
"discharge": "1-m3s",
"discharge_envelop": "1-m3s",
"velocity": "2-ms",
"max_depth": "3-meter",
"velocity_envelop": "2-ms",
"depth": "3-meter",
"depth_envelop": "3-meter",
"mean_depth": "3-meter",
"froude": "4-dimensionless",
"wet_area": "5-m2",
@ -105,15 +109,15 @@ class CustomPlot(PamhyrPlot):
self._axes[ax].spines['right'].set_position(('outward', shift))
shift += 60
lines = {}
if "elevation" in self._y:
self.lines = {}
if "bed_elevation" in self._y:
ax = self._axes[unit["elevation"]]
ax = self._axes[unit["bed_elevation"]]
line = ax.plot(
rk, z_min,
color='grey', lw=1.,
)
lines["elevation"] = line
self.lines["bed_elevation"] = line
if "water_elevation" in self._y:
@ -122,14 +126,46 @@ class CustomPlot(PamhyrPlot):
rk, z, lw=1.,
color='blue',
)
lines["water_elevation"] = line
self.lines["water_elevation"] = line
if "elevation" in self._y:
ax.fill_between(
if "bed_elevation" in self._y:
self.fill = ax.fill_between(
rk, z_min, z,
color='blue', alpha=0.5, interpolate=True
)
#if "water_elevation_envelop" in self._y:
ax = self._axes[unit["water_elevation_envelop"]]
d = list(
map(
lambda p: max(p.get_key("Z")),
reach.profiles
)
)
line1 = ax.plot(
rk, d, lw=1.,
color='blue',
linestyle='dotted',
)
self.lines["water_elevation_envelop"] = line1
d = list(
map(
lambda p: min(p.get_key("Z")),
reach.profiles
)
)
line2 = ax.plot(
rk, d, lw=1.,
color='blue',
linestyle='dotted',
)
#self.lines["water_elevation_envelop2"] = line2
if "discharge" in self._y:
ax = self._axes[unit["discharge"]]
@ -137,7 +173,37 @@ class CustomPlot(PamhyrPlot):
rk, q, lw=1.,
color='r',
)
lines["discharge"] = line
self.lines["discharge"] = line
#if "discharge_envelop" in self._y:
ax = self._axes[unit["discharge_envelop"]]
q1 = list(
map(
lambda p: max(p.get_key("Q")),
reach.profiles
)
)
line1 = ax.plot(
rk, q1, lw=1.,
color='r',
linestyle='dotted',
)
self.lines["discharge_envelop"] = line1
q2 = list(
map(
lambda p: min(p.get_key("Q")),
reach.profiles
)
)
line2 = ax.plot(
rk, q2, lw=1.,
color='r',
linestyle='dotted',
)
#self.lines["discharge_envelop2"] = line2
if "velocity" in self._y:
@ -155,11 +221,39 @@ class CustomPlot(PamhyrPlot):
rk, v, lw=1.,
color='g',
)
lines["velocity"] = line
self.lines["velocity"] = line
if "max_depth" in self._y:
#if "velocity_envelop" in self._y:
ax = self._axes[unit["max_depth"]]
velocities = list(map(lambda p:
list(map(lambda q, z:
p.geometry.speed(q, z),
p.get_key("Q"), p.get_key("Z")
)), reach.profiles
)
)
ax = self._axes[unit["velocity_envelop"]]
vmax = [max(v) for v in velocities]
line1 = ax.plot(
rk, vmax, lw=1.,
color='g',
linestyle='dotted',
)
self.lines["velocity_envelop"] = line1
vmin = [min(v) for v in velocities]
line2 = ax.plot(
rk, vmin, lw=1.,
color='g',
linestyle='dotted',
)
#self.lines["velocity_envelop2"] = line2
if "depth" in self._y:
ax = self._axes[unit["depth"]]
d = list(
map(
lambda p: p.geometry.max_water_depth(
@ -171,7 +265,37 @@ class CustomPlot(PamhyrPlot):
rk, d,
color='brown', lw=1.,
)
lines["max_depth"] = line
self.lines["depth"] = line
#if "depth_envelop" in self._y:
ax = self._axes[unit["depth_envelop"]]
d = list(map(lambda p1, p2: p1 - p2,
map(
lambda p: max(p.get_key("Z")),
reach.profiles
), z_min)
)
line1 = ax.plot(
rk, d,
color='brown', lw=1.,
linestyle='dotted',
)
self.lines["depth_envelop"] = line1
d = list(map(lambda p1, p2: p1 - p2,
map(
lambda p: min(p.get_key("Z")),
reach.profiles
), z_min)
)
line2 = ax.plot(
rk, d,
color='brown', lw=1.,
linestyle='dotted',
)
#self.lines["depth_envelop2"] = line2
if "mean_depth" in self._y:
@ -188,7 +312,7 @@ class CustomPlot(PamhyrPlot):
rk, d,
color='orange', lw=1.,
)
lines["mean_depth"] = line
self.lines["mean_depth"] = line
if "froude" in self._y:
@ -212,7 +336,7 @@ class CustomPlot(PamhyrPlot):
line = ax.plot(
rk, fr, color='black', linestyle='--', lw=1.,
)
lines["froude"] = line
self.lines["froude"] = line
if "wet_area" in self._y:
@ -229,17 +353,110 @@ class CustomPlot(PamhyrPlot):
rk, d,
color='blue', linestyle='--', lw=1.,
)
lines["wet_area"] = line
self.lines["wet_area"] = line
# Legend
lns = reduce(
lambda acc, line: acc + line,
map(lambda line: lines[line], lines),
map(lambda line: self.lines[line], self.lines),
[]
)
labs = list(map(lambda line: self._trad[line], lines))
labs = list(map(lambda line: self._trad[line], self.lines))
self.canvas.axes.legend(lns, labs, loc="best")
def _redraw_rk(self):
results = self.data
reach = results.river.reach(self._reach)
rk = reach.geometry.get_rk()
z_min = reach.geometry.get_z_min()
q = list(
map(
lambda p: p.get_ts_key(self._timestamp, "Q"),
reach.profiles
)
)
z = list(
map(
lambda p: p.get_ts_key(self._timestamp, "Z"),
reach.profiles
)
)
if "bed_elevation" in self._y:
self.lines["bed_elevation"][0].set_ydata(z_min)
if "water_elevation" in self._y:
self.lines["water_elevation"][0].set_ydata(z)
if "bed_elevation" in self._y:
ax = self._axes[unit["water_elevation"]]
self.fill.remove()
self.fill = ax.fill_between(
rk, z_min, z,
color='blue', alpha=0.5, interpolate=True
)
if "discharge" in self._y:
self.lines["discharge"][0].set_ydata(q)
if "velocity" in self._y:
v = list(
map(
lambda p: p.geometry.speed(
p.get_ts_key(self._timestamp, "Q"),
p.get_ts_key(self._timestamp, "Z")),
reach.profiles
)
)
self.lines["discharge"][0].set_ydata(v)
if "depth" in self._y:
d = list(
map(
lambda p: p.geometry.max_water_depth(
p.get_ts_key(self._timestamp, "Z")),
reach.profiles
)
)
self.lines["depth"][0].set_ydata(d)
if "mean_depth" in self._y:
d = list(
map(
lambda p: p.geometry.mean_water_depth(
p.get_ts_key(self._timestamp, "Z")),
reach.profiles
)
)
self.lines["mean_depth"][0].set_ydata(d)
if "froude" in self._y:
fr = list(
map(
lambda p:
p.geometry.speed(
p.get_ts_key(self._timestamp, "Q"),
p.get_ts_key(self._timestamp, "Z")) /
sqrt(9.81 * (
p.geometry.wet_area(
p.get_ts_key(self._timestamp, "Z")) /
p.geometry.wet_width(
p.get_ts_key(self._timestamp, "Z"))
)),
reach.profiles
)
)
self.lines["froude"][0].set_ydata(fr)
if "wet_area" in self._y:
d = list(
map(
lambda p: p.geometry.wet_area(
p.get_ts_key(self._timestamp, "Z")),
reach.profiles
)
)
self.lines["wet_area"][0].set_ydata(d)
def _customize_x_axes_time(self, ts, mode="time"):
# Custom time display
nb = len(ts)
@ -308,17 +525,17 @@ class CustomPlot(PamhyrPlot):
)
)
lines = {}
if "elevation" in self._y:
self.lines = {}
if "bed_elevation" in self._y:
# Z min is constant in time
ax = self._axes[unit["elevation"]]
ax = self._axes[unit["bed_elevation"]]
line = ax.plot(
ts, ts_z_min,
color='grey', lw=1.
)
lines["elevation"] = line
self.lines["bed_elevation"] = line
if "water_elevation" in self._y:
@ -327,11 +544,11 @@ class CustomPlot(PamhyrPlot):
ts, z, lw=1.,
color='b',
)
lines["water_elevation"] = line
self.lines["water_elevation"] = line
if "elevation" in self._y:
if "bed_elevation" in self._y:
ax.fill_between(
self.fill = ax.fill_between(
ts, ts_z_min, z,
color='blue', alpha=0.5, interpolate=True
)
@ -343,7 +560,7 @@ class CustomPlot(PamhyrPlot):
ts, q, lw=1.,
color='r',
)
lines["discharge"] = line
self.lines["discharge"] = line
if "velocity" in self._y:
@ -359,11 +576,11 @@ class CustomPlot(PamhyrPlot):
ts, v, lw=1.,
color='g',
)
lines["velocity"] = line
self.lines["velocity"] = line
if "max_depth" in self._y:
if "depth" in self._y:
ax = self._axes[unit["max_depth"]]
ax = self._axes[unit["depth"]]
d = list(
map(lambda z: profile.geometry.max_water_depth(z), z)
)
@ -372,7 +589,7 @@ class CustomPlot(PamhyrPlot):
ts, d,
color='brown', lw=1.,
)
lines["max_depth"] = line
self.lines["depth"] = line
if "mean_depth" in self._y:
@ -385,7 +602,7 @@ class CustomPlot(PamhyrPlot):
ts, d,
color='orange', lw=1.,
)
lines["mean_depth"] = line
self.lines["mean_depth"] = line
if "froude" in self._y:
@ -402,7 +619,7 @@ class CustomPlot(PamhyrPlot):
line = ax.plot(
ts, d, color='black', linestyle='--', lw=1.,
)
lines["froude"] = line
self.lines["froude"] = line
if "wet_area" in self._y:
@ -414,21 +631,100 @@ class CustomPlot(PamhyrPlot):
line = ax.plot(
ts, d, color='blue', linestyle='--', lw=1.,
)
lines["wet_area"] = line
self.lines["wet_area"] = line
self._customize_x_axes_time(ts)
# Legend
lns = reduce(
lambda acc, line: acc + line,
map(lambda line: lines[line], lines),
map(lambda line: self.lines[line], self.lines),
[]
)
labs = list(map(lambda line: self._trad[line], lines))
labs = list(map(lambda line: self._trad[line], self.lines))
self.canvas.axes.legend(lns, labs, loc="best")
@timer
def _redraw_time(self):
results = self.data
reach = results.river.reach(self._reach)
profile = reach.profile(self._profile)
ts = list(results.get("timestamps"))
ts.sort()
q = profile.get_key("Q")
z = profile.get_key("Z")
z_min = profile.geometry.z_min()
ts_z_min = list(
map(
lambda ts: z_min,
ts
)
)
if "water_elevation" in self._y:
self.lines["water_elevation"][0].set_ydata(z)
if "bed_elevation" in self._y:
ax = self._axes[unit["bed_elevation"]]
self.fill.remove()
self.fill = ax.fill_between(
ts, ts_z_min, z,
color='blue', alpha=0.5, interpolate=True
)
if "discharge" in self._y:
self.lines["discharge"][0].set_ydata(q)
if "velocity" in self._y:
v = list(
map(
lambda q, z: profile.geometry.speed(q, z),
q, z
)
)
self.lines["velocity"][0].set_ydata(v)
if "depth" in self._y:
d = list(
map(lambda z: profile.geometry.max_water_depth(z), z)
)
self.lines["depth"][0].set_ydata(d)
if "mean_depth" in self._y:
d = list(
map(lambda z: profile.geometry.mean_water_depth(z), z)
)
self.lines["mean_depth"][0].set_ydata(d)
if "froude" in self._y:
d = list(
map(lambda z, q:
profile.geometry.speed(q, z) /
sqrt(9.81 * (
profile.geometry.wet_area(z) /
profile.geometry.wet_width(z))
), z, q)
)
self.lines["froude"][0].set_ydata(d)
if "wet_area" in self._y:
d = list(
map(lambda z: profile.geometry.wet_area(z), z)
)
self.lines["wet_area"][0].set_ydata(d)
def draw(self):
self.draw_static()
def draw_update(self):
if self._x == "rk":
self._redraw_rk()
elif self._x == "time":
self._redraw_time()
@timer
def draw_static(self):
self.canvas.axes.cla()
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
@ -485,9 +781,10 @@ class CustomPlot(PamhyrPlot):
@timer
def update(self):
if not self._init:
self.draw()
#self.draw_static()
self.draw_current()
return
self.draw_update()
return
def set_reach(self, reach_id):
self._reach = reach_id

View File

@ -36,14 +36,16 @@ class CustomPlotTranslate(ResultsTranslate):
self._dict['time'] = self._dict["unit_time_s"]
self._dict['rk'] = self._dict["unit_rk"]
self._dict['water_elevation'] = self._dict["unit_water_elevation"]
self._dict['water_elevation_envelop'] = self._dict["unit_water_elevation_envelop"]
self._dict['discharge'] = self._dict["unit_discharge"]
self._dict['elevation'] = _translate(
"CustomPlot", "Bed elevation (m)"
)
self._dict['velocity'] = self._dict["unit_speed"]
self._dict['discharge_envelop'] = self._dict["unit_discharge_envelop"]
self._dict['bed_elevation'] = self._dict["unit_bed_elevation"]
self._dict['velocity'] = self._dict["unit_velocity"]
self._dict['width'] = self._dict["unit_width"]
self._dict['max_depth'] = self._dict["unit_max_height"]
self._dict['mean_depth'] = self._dict["unit_mean_height"]
self._dict['velocity_envelop'] = self._dict["unit_velocity_envelop"]
self._dict['depth'] = self._dict["unit_depth"]
self._dict['depth_envelop'] = self._dict["unit_depth_envelop"]
self._dict['mean_depth'] = self._dict["unit_mean_depth"]
self._dict['wet_area'] = self._dict["unit_wet_area"]
self._dict['wet_perimeter'] = self._dict["unit_wet_perimeter"]
self._dict['hydraulic_radius'] = self._dict["unit_hydraulic_radius"]
@ -55,7 +57,7 @@ class CustomPlotTranslate(ResultsTranslate):
"CustomPlot", "Elevation (m)"
)
self._dict['1-m3s'] = self._dict["unit_discharge"]
self._dict['2-ms'] = self._dict["unit_speed"]
self._dict['3-meter'] = self._dict["unit_height"]
self._dict['2-ms'] = self._dict["unit_velocity"]
self._dict['3-meter'] = self._dict["unit_depth"]
self._dict['4-dimensionless'] = self._dict["unit_froude"]
self._dict['5-m2'] = self._dict["wet_area"]

View File

@ -97,7 +97,7 @@ class TableModel(PamhyrTableModel):
z = self._lst[row].get_ts_key(self._timestamp, "Z")
v = self._lst[row].geometry.wet_width(z)
return f"{v:.4f}"
elif self._headers[column] == "max_depth":
elif self._headers[column] == "depth":
z = self._lst[row].get_ts_key(self._timestamp, "Z")
v = self._lst[row].geometry.max_water_depth(z)
return f"{v:.4f}"

View File

@ -703,8 +703,8 @@ class ResultsWindow(PamhyrWindow):
reach.profiles
)
)
if "max_depth" in y:
my_dict["max_depth"] = list(
if "depth" in y:
my_dict["depth"] = list(
map(
lambda p: p.geometry.max_water_depth(
p.get_ts_key(timestamp, "Z")),
@ -768,8 +768,8 @@ class ResultsWindow(PamhyrWindow):
q, z
)
)
if "max_depth" in y:
my_dict["max_depth"] = list(
if "depth" in y:
my_dict["depth"] = list(
map(lambda z: profile.geometry.max_water_depth(z), z)
)
if "mean_depth" in y:

View File

@ -57,10 +57,10 @@ class ResultsTranslate(MainTranslate):
"name": _translate("Results", "Profile"),
"water_elevation": self._dict["unit_water_elevation"],
"discharge": self._dict["unit_discharge"],
"velocity": self._dict["unit_speed"],
"velocity": self._dict["unit_velocity"],
"width": self._dict["unit_width"],
"max_depth": self._dict["unit_max_height"],
"mean_depth": self._dict["unit_mean_height"],
"depth": self._dict["unit_depth"],
"mean_depth": self._dict["unit_mean_depth"],
"wet_area": self._dict["unit_wet_area"],
"wet_perimeter": self._dict["unit_wet_perimeter"],
"hydraulic_radius": self._dict["unit_hydraulic_radius"],
@ -73,12 +73,16 @@ class ResultsTranslate(MainTranslate):
}
self._sub_dict["values_y"] = {
"elevation": self._dict["unit_elevation"],
"bed_elevation": self._dict["unit_bed_elevation"],
"water_elevation": self._dict["unit_water_elevation"],
#"water_elevation_envelop": self._dict["unit_water_elevation_envelop"],
"discharge": self._dict["unit_discharge"],
"velocity": self._dict["unit_speed"],
"max_depth": self._dict["unit_max_height"],
"mean_depth": self._dict["unit_mean_height"],
#"discharge_envelop": self._dict["unit_discharge_envelop"],
"velocity": self._dict["unit_velocity"],
#"velocity_envelop": self._dict["unit_velocity_envelop"],
"depth": self._dict["unit_depth"],
#"depth_envelop": self._dict["unit_depth_envelop"],
"mean_depth": self._dict["unit_mean_depth"],
"froude": self._dict["unit_froude"],
"wet_area": self._dict["unit_wet_area"],
}

View File

@ -44,7 +44,7 @@ class Plot(PamhyrPlot):
)
self.label_x = self._trad["rk"]
self.label_y = self._trad["height"]
self.label_y = self._trad["elevation"]
self.line_rk_zmin = None
self.line_rk_sl = []

View File

@ -44,7 +44,7 @@ class Plot(PamhyrPlot):
)
self.label_x = self._trad["x"]
self.label_y = self._trad["height"]
self.label_y = self._trad["elevation"]
self.line_rk_zmin = None
self.line_rk_sl = []

View File

@ -30,7 +30,7 @@ class SedimentProfileTranslate(SedimentReachTranslate):
self._dict["x"] = _translate(
"SedimentLayers", "X (m)"
)
self._dict["height"] = self._dict["unit_height"]
self._dict["elevation"] = self._dict["unit_elevation"]
self._dict["Profile sediment layers"] = _translate(
"SedimentLayers", "Profile sediment layers"

View File

@ -35,7 +35,7 @@ class SedimentReachTranslate(SedimentTranslate):
)
self._dict["rk"] = self._dict["unit_rk"]
self._dict["height"] = self._dict["unit_height"]
self._dict["elevation"] = self._dict["unit_elevation"]
self._sub_dict["table_headers"] = {
"name": self._dict["name"],

View File

@ -54,18 +54,54 @@ class UnitTranslate(CommonWordTranslate):
self._dict["unit_rk"] = _translate("Unit", "River Kilometer (m)")
self._dict["unit_width"] = _translate("Unit", "Width (m)")
self._dict["unit_height"] = _translate("Unit", "Depth (m)")
self._dict["unit_max_height"] = _translate("Unit", "Max Depth (m)")
self._dict["unit_mean_height"] = _translate("Unit", "Mean Depth (m)")
self._dict["unit_width_envelop"] = _translate(
"Unit", "Width Envelop (m)"
)
self._dict["unit_max_width"] = _translate("Unit", "Max Width (m)")
self._dict["unit_min_width"] = _translate("Unit", "Min Width (m)")
self._dict["unit_depth"] = _translate("Unit", "Depth (m)")
self._dict["unit_max_depth"] = _translate("Unit", "Max Depth (m)")
self._dict["unit_min_depth"] = _translate("Unit", "Min Depth (m)")
self._dict["unit_depth_envelop"] = _translate(
"Unit", "Depth Envelop (m)"
)
self._dict["unit_mean_depth"] = _translate("Unit", "Mean Depth (m)")
self._dict["unit_diameter"] = _translate("Unit", "Diameter (m)")
self._dict["unit_thickness"] = _translate("Unit", "Thickness (m)")
self._dict["unit_elevation"] = _translate("Unit", "Elevation (m)")
self._dict["unit_bed_elevation"] = _translate("Unit", "Bed Elevation (m)")
self._dict["unit_water_elevation"] = _translate(
"Unit", "Water elevation (m)"
"Unit", "Water Elevation (m)"
)
self._dict["unit_water_elevation_envelop"] = _translate(
"Unit", "Water Elevation Envelop (m)"
)
self._dict["unit_max_water_elevation"] = _translate(
"Unit", "Max Water Elevation (m)"
)
self._dict["unit_min_water_elevation"] = _translate(
"Unit", "Min Water Elevation (m)"
)
self._dict["unit_velocity"] = _translate("Unit", "Velocity (m/s)")
self._dict["unit_velocity_envelop"] = _translate(
"Unit", "Velocity Envelop (m/s)"
)
self._dict["unit_max_velocity"] = _translate(
"Unit", "Max Velocity (m/s)"
)
self._dict["unit_min_velocity"] = _translate(
"Unit", "Min Velocity (m/s)"
)
self._dict["unit_speed"] = _translate("Unit", "Velocity (m/s)")
self._dict["unit_discharge"] = _translate("Unit", "Discharge (m^3/s)")
self._dict["unit_discharge_envelop"] = _translate(
"Unit", "Discharge Envelop (m^3/s)"
)
self._dict["unit_max_discharge"] = _translate(
"Unit", "Max Discharge (m^3/s)"
)
self._dict["unit_min_discharge"] = _translate(
"Unit", "Min Discharge (m^3/s)"
)
self._dict["unit_area"] = _translate("Unit", "Area (hectare)")
self._dict["unit_time_s"] = _translate("Unit", "Time (sec)")