mirror of https://gitlab.com/pamhyr/pamhyr2
Results: Simplify and fix river bottom display.
parent
6e94d7a707
commit
f4bf8d3766
|
|
@ -92,130 +92,69 @@ class PlotKPC(PamhyrPlot):
|
|||
self.draw_bottom_geometry(reach)
|
||||
|
||||
def draw_bottom_with_bedload(self, reach):
|
||||
self._bedrock = self.sl_compute_bedrock(reach)
|
||||
|
||||
kp = reach.geometry.get_kp()
|
||||
z = self.sl_compute_current_z(reach)
|
||||
|
||||
self.line_bottom, = self.canvas.axes.plot(
|
||||
kp, z,
|
||||
linestyle="solid", lw=1.,
|
||||
color=self.color_plot_river_bottom,
|
||||
)
|
||||
|
||||
self._river_bottom = z
|
||||
|
||||
def sl_compute_bedrock(self, reach):
|
||||
z_min = reach.geometry.get_z_min()
|
||||
z_max = reach.geometry.get_z_max()
|
||||
sl = self.sl_compute_initial(reach)
|
||||
|
||||
initial_sl = self.sl_compute_initial(reach)
|
||||
current_sl = self.sl_compute_current(reach)
|
||||
|
||||
max_sl_num = reduce(
|
||||
lambda acc, sl: max(acc, len(sl)),
|
||||
current_sl, 0
|
||||
)
|
||||
|
||||
sl_init, sl = self.sl_completed_layers(
|
||||
initial_sl, current_sl, max_sl_num
|
||||
)
|
||||
|
||||
z_sl = self.sl_apply_z_min_to_initial(sl_init, z_min)
|
||||
d_sl = self.sl_compute_diff(sl_init, sl)
|
||||
|
||||
final_z_sl = self.sl_apply_diff(reach, z_sl, d_sl)
|
||||
final_z_sl = list(reversed(final_z_sl))
|
||||
|
||||
self.line_kp_sl = []
|
||||
for i, z in enumerate(final_z_sl):
|
||||
self.line_kp_sl.append(None)
|
||||
self.line_kp_sl[i], = self.canvas.axes.plot(
|
||||
kp, z,
|
||||
linestyle=(
|
||||
"solid" if i == len(final_z_sl) - 1
|
||||
else self.linestyle[1:][i // len(self.colors)]
|
||||
z = list(
|
||||
map(
|
||||
lambda z, sl: reduce(
|
||||
lambda z, h: z - h[0],
|
||||
sl, z
|
||||
),
|
||||
lw=1.,
|
||||
color=(
|
||||
self.color_plot_river_bottom if i == len(final_z_sl) - 1
|
||||
else self.colors[i % len(self.colors)]
|
||||
)
|
||||
z_min, # Original geometry
|
||||
sl # Original sediment layers
|
||||
)
|
||||
)
|
||||
|
||||
self._initial_sl = initial_sl
|
||||
self._river_bottom = final_z_sl[-1]
|
||||
return z
|
||||
|
||||
def sl_compute_current_z(self, reach):
|
||||
z_br = self._bedrock
|
||||
sl = self.sl_compute_current(reach)
|
||||
|
||||
z = list(
|
||||
map(
|
||||
lambda z, sl: reduce(
|
||||
lambda z, h: z + h[0],
|
||||
sl, z
|
||||
),
|
||||
z_br, # Bedrock elevation
|
||||
sl # Current sediment layers
|
||||
)
|
||||
)
|
||||
|
||||
return z
|
||||
|
||||
def sl_compute_initial(self, reach):
|
||||
"""
|
||||
Get SL list for profile p at initial time (initial data)
|
||||
"""
|
||||
return list(
|
||||
map(
|
||||
lambda p: p.get_ts_key(min(self._timestamps), "sl")[0],
|
||||
reach.profiles
|
||||
)
|
||||
return map(
|
||||
lambda p: p.get_ts_key(min(self._timestamps), "sl")[0],
|
||||
reach.profiles
|
||||
)
|
||||
|
||||
def sl_compute_current(self, reach):
|
||||
"""
|
||||
Get SL list for profile p at current time
|
||||
"""
|
||||
return list(
|
||||
map(
|
||||
lambda p: p.get_ts_key(self._current_timestamp, "sl")[0],
|
||||
reach.profiles
|
||||
)
|
||||
)
|
||||
|
||||
def sl_completed_layers(self, initial_sl, current_sl, max_sl_num):
|
||||
sl = []
|
||||
sl_init = []
|
||||
for i in range(max_sl_num):
|
||||
cur = []
|
||||
cur_init = []
|
||||
for current, initial in zip(current_sl, initial_sl):
|
||||
if i < len(initial_sl):
|
||||
cur.append(current[i][0])
|
||||
cur_init.append(initial[i][0])
|
||||
else:
|
||||
cur.append(0)
|
||||
cur_init.append(0)
|
||||
sl.append(cur)
|
||||
sl_init.append(cur_init)
|
||||
|
||||
return sl_init, sl
|
||||
|
||||
def sl_apply_z_min_to_initial(self, sl_init, z_min):
|
||||
"""
|
||||
Compute sediment layer from initial data in function to profile
|
||||
z_min
|
||||
"""
|
||||
return reduce(
|
||||
lambda acc, v: acc + [
|
||||
list(
|
||||
map(
|
||||
lambda x, y: y - x,
|
||||
v, acc[-1]
|
||||
)
|
||||
)
|
||||
],
|
||||
sl_init, [z_min]
|
||||
)
|
||||
|
||||
def sl_compute_diff(self, sl_init, sl):
|
||||
return list(
|
||||
map(
|
||||
lambda ln0, lni: list(
|
||||
map(
|
||||
lambda z0, zi: z0 - zi,
|
||||
ln0, lni
|
||||
)
|
||||
),
|
||||
sl_init, sl
|
||||
)
|
||||
)
|
||||
|
||||
def sl_apply_diff(self, reach, z_sl, d_sl):
|
||||
f = list(map(lambda p: 0, reach.profiles))
|
||||
|
||||
return list(
|
||||
map(
|
||||
lambda z, d: list(
|
||||
map(
|
||||
lambda zn, dn: zn - dn,
|
||||
z, d
|
||||
)
|
||||
),
|
||||
z_sl, d_sl + [f] # HACK: Add dummy data for last layer
|
||||
)
|
||||
return map(
|
||||
lambda p: p.get_ts_key(self._current_timestamp, "sl")[0],
|
||||
reach.profiles
|
||||
)
|
||||
|
||||
def draw_bottom_geometry(self, reach):
|
||||
|
|
@ -398,27 +337,14 @@ class PlotKPC(PamhyrPlot):
|
|||
def update_bottom_with_bedload(self):
|
||||
reach = self.results.river.reach(self._current_reach_id)
|
||||
kp = reach.geometry.get_kp()
|
||||
z_min = reach.geometry.get_z_min()
|
||||
z = self.sl_compute_current_z(reach)
|
||||
|
||||
initial_sl = self._initial_sl
|
||||
current_sl = self.sl_compute_current(reach)
|
||||
self.line_bottom.remove()
|
||||
|
||||
max_sl_num = reduce(
|
||||
lambda acc, sl: max(acc, len(sl)),
|
||||
current_sl, 0
|
||||
self.line_bottom, = self.canvas.axes.plot(
|
||||
kp, z,
|
||||
linestyle="solid", lw=1.,
|
||||
color=self.color_plot_river_bottom,
|
||||
)
|
||||
|
||||
sl_init, sl = self.sl_completed_layers(
|
||||
initial_sl, current_sl, max_sl_num
|
||||
)
|
||||
|
||||
z_sl = self.sl_apply_z_min_to_initial(sl_init, z_min)
|
||||
d_sl = self.sl_compute_diff(sl_init, sl)
|
||||
|
||||
final_z_sl = self.sl_apply_diff(reach, z_sl, d_sl)
|
||||
final_z_sl = list(reversed(final_z_sl))
|
||||
|
||||
for i, z in enumerate(final_z_sl):
|
||||
self.line_kp_sl[i].set_data(kp, z)
|
||||
|
||||
self._river_bottom = final_z_sl[-1]
|
||||
self._river_bottom = z
|
||||
|
|
|
|||
Loading…
Reference in New Issue