mirror of https://gitlab.com/pamhyr/pamhyr2
add zfd in results
parent
242df7f648
commit
5b497d61f0
|
|
@ -77,9 +77,12 @@ class Profile(SQLSubModel):
|
|||
return self._data[timestamp][key]
|
||||
return None
|
||||
|
||||
def has_sediment(self):
|
||||
def has_sediment_layers(self):
|
||||
return any(map(lambda ts: "sl" in self._data[ts], self._data))
|
||||
|
||||
def has_bedload(self):
|
||||
return any(map(lambda ts: "zfd" in self._data[ts], self._data))
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
|
|
@ -308,7 +311,11 @@ class Reach(SQLSubModel):
|
|||
self._profiles[profile_id].set(timestamp, key, data)
|
||||
|
||||
def has_sediment(self):
|
||||
return any(map(lambda profile: profile.has_sediment(), self._profiles))
|
||||
return any(map(lambda profile: profile.has_sediment_layers(),
|
||||
self._profiles))
|
||||
|
||||
def has_bedload(self):
|
||||
return any(map(lambda profile: profile.has_bedload(), self._profiles))
|
||||
|
||||
def bufferize(self, timestamps, key):
|
||||
self._buffers[key] = np.zeros((len(timestamps), len(self)))
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
import os
|
||||
import logging
|
||||
import numpy as np
|
||||
from functools import reduce
|
||||
|
||||
from itertools import chain
|
||||
from tools import timer, trace, logger_exception
|
||||
|
|
@ -1366,6 +1367,40 @@ class Mage8(Mage):
|
|||
)
|
||||
end = newline().size <= 0
|
||||
|
||||
ts_list = sorted(ts)
|
||||
|
||||
logger.info(f"compute river bed elevation...")
|
||||
|
||||
for r in reachs:
|
||||
z_min = reach.geometry.get_z_min()
|
||||
sls = list(map(
|
||||
lambda p: p.get_ts_key(ts_list[0], "sl")[0],
|
||||
r.profiles
|
||||
))
|
||||
z_br = list(map(
|
||||
lambda z, sl: reduce(
|
||||
lambda z, h: z - h[0],
|
||||
sl, z
|
||||
),
|
||||
z_min, # Original geometry
|
||||
sls # Original sediment layers
|
||||
))
|
||||
for t in ts_list:
|
||||
sls = list(map(
|
||||
lambda p: p.get_ts_key(t, "sl")[0],
|
||||
r.profiles
|
||||
))
|
||||
zfd = list(map(
|
||||
lambda z, sl: reduce(
|
||||
lambda z, h: z + h[0],
|
||||
sl, z
|
||||
),
|
||||
z_br, # bedrock
|
||||
sls # Original sediment layers
|
||||
))
|
||||
for i, p in enumerate(r.profiles):
|
||||
r.set(i, t, "zfd", zfd[i])
|
||||
|
||||
results.set("sediment_timestamps", ts)
|
||||
logger.info(f"read_gra: ... end with {len(ts)} timestamp read")
|
||||
|
||||
|
|
|
|||
|
|
@ -1934,17 +1934,23 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
)
|
||||
)
|
||||
|
||||
result3 = Results(self._study, solver3)
|
||||
result4 = Results(self._study, solver1)
|
||||
result5 = Results(self._study, solver2)
|
||||
|
||||
result3.set("nb_reach", result1.get("nb_reach"))
|
||||
result3.set("nb_profile", result1.get("nb_profile"))
|
||||
result3.set("timestamps", ts)
|
||||
result4.set("timestamps", ts)
|
||||
result5.set("timestamps", ts)
|
||||
|
||||
for i in range(int(result1.get("nb_reach"))):
|
||||
r = result3.river.add(i)
|
||||
|
||||
for timestamp in result3.get("timestamps"):
|
||||
for timestamp in ts:
|
||||
for r in range(int(result1.get("nb_reach"))):
|
||||
reach1 = result1.river.reach(r)
|
||||
reach2 = result2.river.reach(r)
|
||||
reach1 = result4.river.reach(r)
|
||||
reach2 = result5.river.reach(r)
|
||||
reach3 = result3.river.reach(r)
|
||||
|
||||
for profile1, profile2, profile3 in zip(
|
||||
|
|
@ -1954,17 +1960,41 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
for key in ["Z", "Q", "V"]:
|
||||
d1 = profile1.get_ts_key(timestamp, key)
|
||||
d2 = profile2.get_ts_key(timestamp, key)
|
||||
d = d1 - d2
|
||||
d = d1-d2
|
||||
reach3.set(p, timestamp, key, d)
|
||||
reach4.set(p, timestamp, key, d1)
|
||||
reach5.set(p, timestamp, key, d2)
|
||||
if reach1.has_bedload():
|
||||
d1 = profile1.get_ts_key(timestamp, 'zfd')
|
||||
reach4.set(p, timestamp, 'zfd', d1)
|
||||
if reach2.has_bedload():
|
||||
d2 = profile2.get_ts_key(timestamp, 'zfd')
|
||||
reach5.set(p, timestamp, 'zfd', d2)
|
||||
if reach1.has_bedload():
|
||||
d3 = d1-d2
|
||||
reach3.set(p, timestamp, 'zfd', d3)
|
||||
|
||||
profile3.set(timestamp, key, d)
|
||||
limits = reach3.profile(p).geometry.get_water_limits(
|
||||
reach3.profile(p).get_ts_key(timestamp, "Z")
|
||||
)
|
||||
reach3.set(
|
||||
p, timestamp,
|
||||
"water_limits",
|
||||
limits
|
||||
)
|
||||
limits = profile1.get_ts_key(timestamp, "water_limits")
|
||||
reach4.set(p, timestamp, "water_limits", limits)
|
||||
limits = profile2.get_ts_key(timestamp, "water_limits")
|
||||
reach5.set(p, timestamp, "water_limits", limits)
|
||||
|
||||
limits = profile3.geometry\
|
||||
.get_water_limits(
|
||||
profile3.get_ts_key(timestamp, "Z")
|
||||
)
|
||||
profile3.set(timestamp, "water_limits", limits)
|
||||
for res in (result3, result4, result5):
|
||||
for r in range(int(res.get("nb_reach"))):
|
||||
for key in ["Z", "Q", "V"]:
|
||||
res.river.reach(r).bufferize(ts, key)
|
||||
if res.river.reach(r).has_bedload():
|
||||
res.river.reach(r).bufferize(ts, "zfd")
|
||||
|
||||
return [result1, result2, result3]
|
||||
return [result4, result5, result3]
|
||||
|
||||
def open_results_adists(self):
|
||||
if self._study is None:
|
||||
|
|
|
|||
|
|
@ -96,24 +96,33 @@ class PlotRKC(PamhyrPlot):
|
|||
self._init = True
|
||||
|
||||
def draw_bottom(self, reach):
|
||||
if reach.has_sediment():
|
||||
if reach.has_bedload():
|
||||
self.draw_bottom_with_bedload(reach)
|
||||
else:
|
||||
self.draw_bottom_geometry(reach)
|
||||
|
||||
def draw_bottom_with_bedload(self, reach):
|
||||
self._bedrock = self.sl_compute_bedrock(reach)
|
||||
# self._bedrock = self.sl_compute_bedrock(reach)
|
||||
|
||||
rk = reach.geometry.get_rk()
|
||||
z = self.sl_compute_current_z(reach)
|
||||
# z = self.sl_compute_current_z(reach)
|
||||
|
||||
zfd = list(
|
||||
map(
|
||||
lambda p: p.get_ts_key(
|
||||
self._current_timestamp, "zfd"
|
||||
),
|
||||
reach.profiles
|
||||
)
|
||||
)
|
||||
|
||||
self.line_bottom, = self.canvas.axes.plot(
|
||||
rk, z,
|
||||
rk, zfd,
|
||||
linestyle="solid", lw=1.,
|
||||
color=self.color_plot_river_bottom,
|
||||
)
|
||||
|
||||
self._river_bottom = z
|
||||
self._river_bottom = zfd
|
||||
|
||||
def draw_profiles_hs(self, reach):
|
||||
results = self.results[self._current_res_id]
|
||||
|
|
@ -147,58 +156,6 @@ class PlotRKC(PamhyrPlot):
|
|||
fontsize=9, color=self.color_plot_previous,
|
||||
)
|
||||
|
||||
def sl_compute_bedrock(self, reach):
|
||||
z_min = reach.geometry.get_z_min()
|
||||
sl = self.sl_compute_initial(reach)
|
||||
|
||||
z = list(
|
||||
map(
|
||||
lambda z, sl: reduce(
|
||||
lambda z, h: z - h[0],
|
||||
sl, z
|
||||
),
|
||||
z_min, # Original geometry
|
||||
sl # Original sediment layers
|
||||
)
|
||||
)
|
||||
|
||||
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 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 map(
|
||||
lambda p: p.get_ts_key(self._current_timestamp, "sl")[0],
|
||||
reach.profiles
|
||||
)
|
||||
|
||||
def draw_bottom_geometry(self, reach):
|
||||
rk = reach.geometry.get_rk()
|
||||
z_min = reach.geometry.get_z_min()
|
||||
|
|
@ -337,7 +294,7 @@ class PlotRKC(PamhyrPlot):
|
|||
|
||||
results = self.results[self._current_res_id]
|
||||
reach = results.river.reach(self._current_reach_id)
|
||||
if reach.has_sediment():
|
||||
if reach.has_bedload():
|
||||
self.update_bottom_with_bedload()
|
||||
|
||||
self.update_water_elevation()
|
||||
|
|
@ -397,14 +354,23 @@ class PlotRKC(PamhyrPlot):
|
|||
results = self.results[self._current_res_id]
|
||||
reach = results.river.reach(self._current_reach_id)
|
||||
rk = reach.geometry.get_rk()
|
||||
z = self.sl_compute_current_z(reach)
|
||||
# z = self.sl_compute_current_z(reach)
|
||||
|
||||
zfd = list(
|
||||
map(
|
||||
lambda p: p.get_ts_key(
|
||||
self._current_timestamp, "zfd"
|
||||
),
|
||||
reach.profiles
|
||||
)
|
||||
)
|
||||
|
||||
self.line_bottom.remove()
|
||||
|
||||
self.line_bottom, = self.canvas.axes.plot(
|
||||
rk, z,
|
||||
rk, zfd,
|
||||
linestyle="solid", lw=1.,
|
||||
color=self.color_plot_river_bottom,
|
||||
)
|
||||
|
||||
self._river_bottom = z
|
||||
self._river_bottom = zfd
|
||||
|
|
|
|||
|
|
@ -558,7 +558,7 @@ class ResultsWindow(PamhyrWindow):
|
|||
table = self.find(QTableView, f"tableView_solver")
|
||||
indexes = table.selectedIndexes()
|
||||
if len(indexes) == 0:
|
||||
return
|
||||
return []
|
||||
|
||||
return [i.row() for i in indexes]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue