mirror of https://gitlab.com/pamhyr/pamhyr2
Results: Update plot XY and add overflow on this plot.
parent
6055065e27
commit
aeae8fb710
|
|
@ -489,46 +489,52 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
# niveau d'eau pour lequel on a obtenu irg, ird, ptX et ptY
|
# niveau d'eau pour lequel on a obtenu irg, ird, ptX et ptY
|
||||||
# ====================================================================
|
# ====================================================================
|
||||||
|
|
||||||
# initialisation
|
|
||||||
irg = -1
|
# Get the index of last point with elevation lesser than water
|
||||||
ird = -1
|
# level (for the right and left river side)
|
||||||
|
i_left = -1
|
||||||
|
i_right = -1
|
||||||
|
|
||||||
for i in range(self.number_points):
|
for i in range(self.number_points):
|
||||||
if self.point(i).z <= z:
|
if self.point(i).z <= z:
|
||||||
irg = i
|
i_left = i
|
||||||
|
break
|
||||||
|
|
||||||
for i in reversed(range(self.number_points)):
|
for i in reversed(range(self.number_points)):
|
||||||
if self.point(i).z <= z:
|
if self.point(i).z <= z:
|
||||||
ird = i
|
i_right = i
|
||||||
|
break
|
||||||
|
|
||||||
# interpolation des points ptX et ptY
|
# Interpolate points at river left side
|
||||||
if (irg < self.number_points - 1):
|
if (i_left > 0):
|
||||||
x = np.interp(
|
x = np.interp(
|
||||||
z,
|
z,
|
||||||
[self.point(irg).z, self.point(irg + 1).z],
|
[self.point(i_left).z, self.point(i_left - 1).z],
|
||||||
[self.point(irg).x, self.point(irg + 1).x]
|
[self.point(i_left).x, self.point(i_left - 1).x]
|
||||||
)
|
)
|
||||||
y = np.interp(
|
y = np.interp(
|
||||||
z,
|
z,
|
||||||
[self.point(irg).z, self.point(irg + 1).z],
|
[self.point(i_left).z, self.point(i_left - 1).z],
|
||||||
[self.point(irg).y, self.point(irg + 1).y]
|
[self.point(i_left).y, self.point(i_left - 1).y]
|
||||||
)
|
)
|
||||||
ptX = PointXYZ(x, y, z)
|
pt_left = PointXYZ(x, y, z)
|
||||||
else:
|
else:
|
||||||
ptX = self.point(0)
|
pt_left = self.point(0)
|
||||||
if (ird > 0):
|
|
||||||
|
# Interpolate points at river right side
|
||||||
|
if (i_right < self.number_points - 1):
|
||||||
x = np.interp(
|
x = np.interp(
|
||||||
z,
|
z,
|
||||||
[self.point(ird-1).z, self.point(ird).z],
|
[self.point(i_right).z, self.point(i_right + 1).z],
|
||||||
[self.point(ird-1).x, self.point(ird).x]
|
[self.point(i_right).x, self.point(i_right + 1).x]
|
||||||
)
|
)
|
||||||
y = np.interp(
|
y = np.interp(
|
||||||
z,
|
z,
|
||||||
[self.point(ird).z, self.point(ird - 1).z],
|
[self.point(i_right).z, self.point(i_right + 1).z],
|
||||||
[self.point(ird).y, self.point(ird - 1).y]
|
[self.point(i_right).y, self.point(i_right + 1).y]
|
||||||
)
|
)
|
||||||
ptY = PointXYZ(x, y, z)
|
pt_right = PointXYZ(x, y, z)
|
||||||
else:
|
else:
|
||||||
ptY = self.point(self.number_points - 1)
|
pt_right = self.point(self.number_points - 1)
|
||||||
|
|
||||||
return ptX, ptY
|
return pt_left, pt_right
|
||||||
|
|
|
||||||
|
|
@ -1023,9 +1023,12 @@ class Mage8(Mage):
|
||||||
reach.set(ri, timestamp, key, d)
|
reach.set(ri, timestamp, key, d)
|
||||||
if key == "Z":
|
if key == "Z":
|
||||||
profile = reach.profile(ri)
|
profile = reach.profile(ri)
|
||||||
ptX, ptY = profile.geometry.get_water_limits(d)
|
limits = profile.geometry.get_water_limits(d)
|
||||||
reach.set(ri, timestamp, "ptX", ptX)
|
reach.set(
|
||||||
reach.set(ri, timestamp, "ptY", ptY)
|
ri, timestamp,
|
||||||
|
"water_limits",
|
||||||
|
limits
|
||||||
|
)
|
||||||
|
|
||||||
endline()
|
endline()
|
||||||
end = newline().size <= 0
|
end = newline().size <= 0
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,6 @@ class PlotKPC(PamhyrPlot):
|
||||||
|
|
||||||
reach = self.results.river.reach(self._current_reach_id)
|
reach = self.results.river.reach(self._current_reach_id)
|
||||||
|
|
||||||
|
|
||||||
self.draw_bottom(reach)
|
self.draw_bottom(reach)
|
||||||
self.draw_water_elevation(reach)
|
self.draw_water_elevation(reach)
|
||||||
self.draw_water_elevation_max(reach)
|
self.draw_water_elevation_max(reach)
|
||||||
|
|
|
||||||
|
|
@ -44,15 +44,20 @@ class PlotXY(PamhyrPlot):
|
||||||
parent=parent
|
parent=parent
|
||||||
)
|
)
|
||||||
|
|
||||||
self.display_current = display_current
|
|
||||||
|
|
||||||
self.line_xy = []
|
self.line_xy = []
|
||||||
self.line_gl = []
|
self.line_gl = []
|
||||||
|
self.overflow = []
|
||||||
|
|
||||||
self._current_timestamp = max(results.get("timestamps"))
|
self._timestamps = results.get("timestamps")
|
||||||
|
self._current_timestamp = max(self._timestamps)
|
||||||
self._current_reach_id = reach_id
|
self._current_reach_id = reach_id
|
||||||
self._current_profile_id = profile_id
|
self._current_profile_id = profile_id
|
||||||
|
|
||||||
|
self.label_x = _translate("Results", "X (m)")
|
||||||
|
self.label_y = _translate("Results", "Y (m)")
|
||||||
|
|
||||||
|
self._isometric_axis = True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def results(self):
|
def results(self):
|
||||||
return self.data
|
return self.data
|
||||||
|
|
@ -64,53 +69,41 @@ class PlotXY(PamhyrPlot):
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def draw(self, highlight=None):
|
def draw(self, highlight=None):
|
||||||
self.canvas.axes.cla()
|
self.init_axes()
|
||||||
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
|
||||||
|
|
||||||
if self.results is None:
|
if self.results is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
reach = self.results.river.reach(self._current_reach_id)
|
reach = self.results.river.reach(self._current_reach_id)
|
||||||
|
|
||||||
|
self.draw_profiles(reach)
|
||||||
|
self.draw_water_elevation(reach)
|
||||||
|
self.draw_water_elevation_max(reach)
|
||||||
|
self.draw_guide_lines(reach)
|
||||||
|
self.draw_current(reach)
|
||||||
|
|
||||||
|
self.idle()
|
||||||
|
self._init = True
|
||||||
|
|
||||||
|
def draw_profiles(self, reach):
|
||||||
if reach.geometry.number_profiles == 0:
|
if reach.geometry.number_profiles == 0:
|
||||||
self._init = False
|
self._init = False
|
||||||
return
|
return
|
||||||
|
|
||||||
kp_min, kp_max = (-1, -1)
|
|
||||||
if highlight is not None:
|
|
||||||
kp_min, kp_max = highlight
|
|
||||||
|
|
||||||
# Axes
|
|
||||||
self.canvas.axes.set_xlabel(
|
|
||||||
_translate("Results", "X (m)"),
|
|
||||||
color='black', fontsize=10
|
|
||||||
)
|
|
||||||
self.canvas.axes.set_ylabel(
|
|
||||||
_translate("Results", "Y (m)"),
|
|
||||||
color='black', fontsize=10
|
|
||||||
)
|
|
||||||
self.canvas.axes.axis("equal")
|
|
||||||
|
|
||||||
kp = reach.geometry.get_kp()
|
|
||||||
self.canvas.axes.set_xlim(
|
|
||||||
left=min(kp), right=max(kp)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Draw line for each profile
|
|
||||||
self.line_xy = [
|
self.line_xy = [
|
||||||
self.canvas.axes.plot(
|
self.canvas.axes.plot(
|
||||||
x, y, lw=1.,
|
x, y,
|
||||||
color='b' if kp_min <= kp <= kp_max else 'grey',
|
color=self.color_plot_river_bottom,
|
||||||
markersize=3, marker='+'
|
**self.plot_default_kargs
|
||||||
)
|
)
|
||||||
for x, y, kp in zip(
|
for x, y, kp in zip(
|
||||||
reach.geometry.get_x(),
|
reach.geometry.get_x(),
|
||||||
reach.geometry.get_y(),
|
reach.geometry.get_y(),
|
||||||
kp
|
reach.geometry.get_kp()
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
# Guide lines
|
def draw_guide_lines(self, reach):
|
||||||
x_complete = reach.geometry.get_guidelines_x()
|
x_complete = reach.geometry.get_guidelines_x()
|
||||||
y_complete = reach.geometry.get_guidelines_y()
|
y_complete = reach.geometry.get_guidelines_y()
|
||||||
|
|
||||||
|
|
@ -121,34 +114,105 @@ class PlotXY(PamhyrPlot):
|
||||||
for x, y in zip(x_complete, y_complete)
|
for x, y in zip(x_complete, y_complete)
|
||||||
]
|
]
|
||||||
|
|
||||||
if self.display_current:
|
def draw_current(self, reach):
|
||||||
# Current profile
|
profile = reach.profile(self._current_profile_id)
|
||||||
profile = reach.profile(self._current_profile_id).geometry
|
|
||||||
|
|
||||||
self.plot_selected, = self.canvas.axes.plot(
|
self.plot_selected, = self.canvas.axes.plot(
|
||||||
profile.x(),
|
profile.geometry.x(),
|
||||||
profile.y(),
|
profile.geometry.y(),
|
||||||
lw=1., markersize=3,
|
color=self.color_plot,
|
||||||
color="r", marker='+'
|
**self.plot_default_kargs
|
||||||
)
|
|
||||||
self.plot_selected.set_visible(True)
|
|
||||||
|
|
||||||
poly_x = [0]
|
|
||||||
poly_y = [0]
|
|
||||||
|
|
||||||
self.fill = self.canvas.axes.fill(
|
|
||||||
poly_x, poly_y,
|
|
||||||
color='skyblue',
|
|
||||||
alpha=0.7
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# self.canvas.axes.autoscale_view(True, True, True)
|
|
||||||
# self.canvas.axes.autoscale()
|
def draw_water_elevation_max(self, reach):
|
||||||
self.canvas.figure.tight_layout()
|
l_x, l_y, r_x, r_y = [], [], [], []
|
||||||
self.canvas.figure.canvas.draw_idle()
|
overflow = []
|
||||||
if self.toolbar is not None:
|
|
||||||
self.toolbar.update()
|
for profile in reach.profiles:
|
||||||
self.update()
|
z_max = max(profile.get_key("Z"))
|
||||||
|
z_max_ts = 0
|
||||||
|
for ts in self._timestamps:
|
||||||
|
z = profile.get_ts_key(ts, "Z")
|
||||||
|
if z == z_max:
|
||||||
|
z_max_ts = ts
|
||||||
|
break
|
||||||
|
|
||||||
|
pt_left, pt_right = profile.get_ts_key(z_max_ts, "water_limits")
|
||||||
|
|
||||||
|
l_x.append(pt_left.x)
|
||||||
|
l_y.append(pt_left.y)
|
||||||
|
r_x.append(pt_right.x)
|
||||||
|
r_y.append(pt_right.y)
|
||||||
|
|
||||||
|
if self.is_overflow_point(profile, pt_left):
|
||||||
|
overflow.append(pt_left)
|
||||||
|
|
||||||
|
if self.is_overflow_point(profile, pt_right):
|
||||||
|
overflow.append(pt_right)
|
||||||
|
|
||||||
|
self.water_max_left = self.canvas.axes.plot(
|
||||||
|
l_x, l_y,
|
||||||
|
color=self.color_plot_river_water,
|
||||||
|
linestyle='dotted',
|
||||||
|
lw=1.,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.water_max_right = self.canvas.axes.plot(
|
||||||
|
r_x, r_y,
|
||||||
|
color=self.color_plot_river_water,
|
||||||
|
linestyle='dotted',
|
||||||
|
lw=1.,
|
||||||
|
)
|
||||||
|
|
||||||
|
for p in overflow:
|
||||||
|
self.canvas.axes.plot(
|
||||||
|
p.x, p.y,
|
||||||
|
lw=1.,
|
||||||
|
color=self.color_plot,
|
||||||
|
markersize=3,
|
||||||
|
marker='x'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def is_overflow_point(self, profile, point):
|
||||||
|
left_limit = profile.geometry.point(0)
|
||||||
|
right_limit = profile.geometry.point(
|
||||||
|
profile.geometry.number_points - 1
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
point == left_limit
|
||||||
|
or point == right_limit
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def draw_water_elevation(self, reach):
|
||||||
|
reach = self.results.river.reach(self._current_reach_id)
|
||||||
|
poly_l_x, poly_l_y, poly_r_x, poly_r_y = [], [], [], []
|
||||||
|
|
||||||
|
for profile in reach.profiles:
|
||||||
|
water_z = profile.get_ts_key(
|
||||||
|
self._current_timestamp, "Z"
|
||||||
|
)
|
||||||
|
pt_left, pt_right = profile.get_ts_key(
|
||||||
|
self._current_timestamp,
|
||||||
|
"water_limits"
|
||||||
|
)
|
||||||
|
|
||||||
|
poly_l_x.append(pt_left.x)
|
||||||
|
poly_l_y.append(pt_left.y)
|
||||||
|
poly_r_x.append(pt_right.x)
|
||||||
|
poly_r_y.append(pt_right.y)
|
||||||
|
|
||||||
|
poly_x = poly_l_x + list(reversed(poly_r_x))
|
||||||
|
poly_y = poly_l_y + list(reversed(poly_r_y))
|
||||||
|
|
||||||
|
self.water_fill = self.canvas.axes.fill(
|
||||||
|
poly_x, poly_y,
|
||||||
|
color=self.color_plot_river_water_zone,
|
||||||
|
alpha=0.7
|
||||||
|
)
|
||||||
|
|
||||||
def set_reach(self, reach_id):
|
def set_reach(self, reach_id):
|
||||||
self._current_reach_id = reach_id
|
self._current_reach_id = reach_id
|
||||||
|
|
@ -158,63 +222,91 @@ class PlotXY(PamhyrPlot):
|
||||||
def set_profile(self, profile_id):
|
def set_profile(self, profile_id):
|
||||||
self._current_profile_id = profile_id
|
self._current_profile_id = profile_id
|
||||||
self.update_profile()
|
self.update_profile()
|
||||||
|
self.update_idle()
|
||||||
|
|
||||||
def set_timestamp(self, timestamp):
|
def set_timestamp(self, timestamp):
|
||||||
self._current_timestamp = timestamp
|
self._current_timestamp = timestamp
|
||||||
self.update_poly()
|
self.update()
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
if not self._init:
|
||||||
|
self.draw()
|
||||||
|
|
||||||
|
self.update_water_elevation()
|
||||||
|
self.update_water_elevation_overflow()
|
||||||
|
|
||||||
|
self.update_idle()
|
||||||
|
|
||||||
def update_profile(self):
|
def update_profile(self):
|
||||||
|
|
||||||
reach = self.results.river.reach(self._current_reach_id)
|
reach = self.results.river.reach(self._current_reach_id)
|
||||||
if self.display_current:
|
profile = reach.profile(self._current_profile_id)
|
||||||
# Current profile
|
|
||||||
profile = reach.profile(self._current_profile_id).geometry
|
|
||||||
|
|
||||||
self.plot_selected.set_data(profile.x(), profile.y())
|
self.plot_selected.set_data(
|
||||||
self.plot_selected.set_visible(True)
|
profile.geometry.x(),
|
||||||
self.canvas.draw_idle()
|
profile.geometry.y()
|
||||||
|
)
|
||||||
def update_poly(self):
|
|
||||||
|
|
||||||
|
def update_water_elevation(self):
|
||||||
reach = self.results.river.reach(self._current_reach_id)
|
reach = self.results.river.reach(self._current_reach_id)
|
||||||
profile = reach.profile(self._current_profile_id).geometry
|
poly_l_x, poly_l_y, poly_r_x, poly_r_y = [], [], [], []
|
||||||
|
|
||||||
# Display water
|
|
||||||
poly_l_x = []
|
|
||||||
poly_l_y = []
|
|
||||||
poly_r_x = []
|
|
||||||
poly_r_y = []
|
|
||||||
for profile in reach.profiles:
|
for profile in reach.profiles:
|
||||||
water_z = profile.get_ts_key(
|
water_z = profile.get_ts_key(
|
||||||
self._current_timestamp, "Z"
|
self._current_timestamp, "Z"
|
||||||
)
|
)
|
||||||
ptX = profile.get_ts_key(
|
pt_left, pt_right = profile.get_ts_key(
|
||||||
self._current_timestamp, "ptX"
|
self._current_timestamp,
|
||||||
)
|
"water_limits"
|
||||||
ptY = profile.get_ts_key(
|
|
||||||
self._current_timestamp, "ptY"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
poly_l_x.append(ptX.x)
|
poly_l_x.append(pt_left.x)
|
||||||
poly_l_y.append(ptX.y)
|
poly_l_y.append(pt_left.y)
|
||||||
poly_r_x.append(ptY.x)
|
poly_r_x.append(pt_right.x)
|
||||||
poly_r_y.append(ptY.y)
|
poly_r_y.append(pt_right.y)
|
||||||
|
|
||||||
# self.canvas.axes.plot(
|
|
||||||
# x, y, lw=1.,
|
|
||||||
# color='b',
|
|
||||||
# markersize=1,
|
|
||||||
# marker='o'
|
|
||||||
# )
|
|
||||||
|
|
||||||
poly_x = poly_l_x + list(reversed(poly_r_x))
|
poly_x = poly_l_x + list(reversed(poly_r_x))
|
||||||
poly_y = poly_l_y + list(reversed(poly_r_y))
|
poly_y = poly_l_y + list(reversed(poly_r_y))
|
||||||
|
|
||||||
poly = []
|
poly = []
|
||||||
for i in range(len(poly_x)):
|
for i in range(len(poly_x)):
|
||||||
poly.append([poly_x[i], poly_y[i]])
|
poly.append([poly_x[i], poly_y[i]])
|
||||||
self.fill[0].set_xy(poly)
|
|
||||||
self.canvas.draw_idle()
|
|
||||||
|
|
||||||
def update(self):
|
self.water_fill[0].set_xy(poly)
|
||||||
self.update_profile()
|
|
||||||
self.update_poly()
|
def update_water_elevation_overflow(self):
|
||||||
|
reach = self.results.river.reach(self._current_reach_id)
|
||||||
|
profile = reach.profile(self._current_profile_id)
|
||||||
|
|
||||||
|
overflow = []
|
||||||
|
|
||||||
|
for profile in reach.profiles:
|
||||||
|
pt_left, pt_right = profile.get_ts_key(
|
||||||
|
self._current_timestamp,
|
||||||
|
"water_limits"
|
||||||
|
)
|
||||||
|
|
||||||
|
left_limit = profile.geometry.point(0)
|
||||||
|
right_limit = profile.geometry.point(
|
||||||
|
profile.geometry.number_points - 1
|
||||||
|
)
|
||||||
|
|
||||||
|
if pt_left == left_limit:
|
||||||
|
overflow.append(pt_left)
|
||||||
|
|
||||||
|
if pt_right == right_limit:
|
||||||
|
overflow.append(pt_right)
|
||||||
|
|
||||||
|
for plot in self.overflow:
|
||||||
|
plot[0].remove()
|
||||||
|
del plot[0]
|
||||||
|
self.overflow = []
|
||||||
|
|
||||||
|
for p in overflow:
|
||||||
|
plot = self.canvas.axes.plot(
|
||||||
|
p.x, p.y,
|
||||||
|
lw=1.,
|
||||||
|
color=self.color_plot,
|
||||||
|
markersize=3,
|
||||||
|
marker='o'
|
||||||
|
)
|
||||||
|
self.overflow.append(plot)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue