Compare commits

..

No commits in common. "421e6797f69bd6ece678973549a31036a7c35001" and "ad5cc831a3382911e86e0c07d35f00cce72f85f8" have entirely different histories.

7 changed files with 182 additions and 167 deletions

View File

@ -69,8 +69,3 @@ class Results(object):
self._repertory,
qlog=None,
)
def bufferize(self, key):
if self.is_valid:
for reach in self._river._reachs:
reach.bufferize(self._meta_data["timestamps"], key)

View File

@ -15,7 +15,6 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import logging
import numpy as np
from datetime import datetime
@ -63,12 +62,9 @@ class Profile(object):
return self._data[timestamp][key]
return None
def has_sediment_layers(self):
def has_sediment(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))
class Reach(object):
def __init__(self, reach, study):
@ -86,7 +82,6 @@ class Reach(object):
lambda p: p.name[0:8] != 'interpol', self._profiles
)
)
self._buffers = {}
def __len__(self):
return len(self._profiles)
@ -107,10 +102,6 @@ class Reach(object):
def profile_mask(self):
return self._profile_mask
@property
def buffers(self):
return self._buffers
def profile(self, id):
return self._profiles[id]
@ -118,16 +109,7 @@ class Reach(object):
self._profiles[profile_id].set(timestamp, key, data)
def has_sediment(self):
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)))
for i, p in enumerate(self._profiles):
self._buffers[key][:, i] = p.get_key(key)
return any(map(lambda profile: profile.has_sediment(), self._profiles))
class River(object):

View File

@ -19,7 +19,6 @@
import os
import logging
import numpy as np
from functools import reduce
from tools import timer, trace, logger_exception
@ -1107,10 +1106,6 @@ class Mage8(Mage):
r.set(i, t, "V", v)
logger.info(f"read_bin: ... end with {len(ts)} timestamp read")
results.bufferize("Z")
results.bufferize("Q")
results.bufferize("V")
@timer
def read_gra(self, study, repertory, results, qlog=None, name="0"):
if not study.river.has_sediment():
@ -1277,40 +1272,6 @@ 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")

View File

@ -1630,7 +1630,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
)
if result1 is None:
logger.warning(f"diff_results: result1 is None")
# TODO message
return None
result2 = solver2.results(
@ -1639,17 +1639,19 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
)
if result2 is None:
logger.warning(f"diff_results: result2 is None")
# TODO message
return None
if result2.get("nb_reach") != result1.get("nb_reach"):
logger.warning(f"diff_results: nb_reach missmatch")
# TODO message
return None
if result2.get("nb_profile") != result1.get("nb_profile"):
logger.warning(f"diff_results: nb_profile missmatch")
# TODO message
return None
# return [result1, result2]
result3 = Results(self._study, solver3)
result4 = Results(self._study, solver1)
result5 = Results(self._study, solver2)
@ -1671,7 +1673,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
r = result4.river.add(i)
r = result5.river.add(i)
for timestamp in ts:
for timestamp in result3.get("timestamps"):
for r in range(int(result1.get("nb_reach"))):
reach1 = result1.river.reach(r)
reach2 = result2.river.reach(r)
@ -1687,16 +1689,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
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)
limits = reach3.profile(p).geometry.get_water_limits(
reach3.profile(p).get_ts_key(timestamp, "Z")
)
@ -1710,13 +1702,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
limits = profile2.get_ts_key(timestamp, "water_limits")
reach5.set(p, 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 [result4, result5, result3]
def open_results_adists(self):

View File

@ -88,24 +88,86 @@ class CustomPlot(PamhyrPlot):
self.lines = {}
def draw_bottom_with_bedload(self, reach):
self._bedrock = self.sl_compute_bedrock(reach)
rk = reach.geometry.get_rk()
z = self.sl_compute_current_z(reach)
return z
def sl_compute_current_z(self, reach):
z_br = self._bedrock
sl = self.sl_compute_current_rk(reach)
z = list(
map(
lambda p: p.get_ts_key(
self._current_timestamp, "zfd"
lambda z, sl: reduce(
lambda z, h: z + h[0],
sl, z
),
reach.profiles
z_br, # Bedrock elevation
sl # Current sediment layers
)
)
return z
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_initial(self, reach):
"""
Get SL list for profile p at initial time (initial data)
"""
t0 = min(list(self.data[self._current_res_id].get("timestamps")))
return map(
lambda p: p.get_ts_key(t0, "sl")[0],
reach.profiles
)
def sl_compute_current_rk(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 get_ts_zmin(self, profile, res_id):
results = self.data[res_id]
nt = len(list(results.get("timestamps")))
reach = results.river.reach(self._current_reach)
zfd = reach.profile(profile).get_key("zfd")
return zfd
berdrock = self.sl_compute_bedrock(reach)
sl = reach.profile(profile).get_key("sl")
ts_z_bedrock = [berdrock[profile]]*nt
ts_z_min = list(
map(
lambda z, sl: reduce(
lambda z, h: z + h,
sl, z
),
ts_z_bedrock, # Bedrock elevations
asarray(sl)[:, 0, :, 0] # Sediment layers
)
)
return ts_z_min
def _draw_rk(self):
results = self.data[self._current_res_id]
@ -114,7 +176,7 @@ class CustomPlot(PamhyrPlot):
reach1 = self.data[0].river.reach(self._current_reach)
reach2 = self.data[1].river.reach(self._current_reach)
rk = reach.geometry.get_rk()
if reach.has_bedload():
if reach.has_sediment():
z_min = self.draw_bottom_with_bedload(reach)
else:
z_min = reach.geometry.get_z_min()
@ -154,32 +216,14 @@ class CustomPlot(PamhyrPlot):
ax = self._axes[unit["bed_elevation"]]
if self._current_res_id < 2:
if reach.has_bedload():
dz = self.draw_bottom_with_bedload(reach)
else:
dz = z_min
line = ax.plot(
rk, dz,
rk, z_min,
color='grey', lw=1.,
)
else:
if reach.has_bedload():
z_min1 = list(
map(
lambda p: p.get_ts_key(
self._current_timestamp, "zfd"
),
reach1.profiles
)
)
z_min2 = list(
map(
lambda p: p.get_ts_key(
self._current_timestamp, "zfd"
),
reach2.profiles
)
)
if reach.has_sediment():
z_min1 = self.draw_bottom_with_bedload(reach1)
z_min2 = self.draw_bottom_with_bedload(reach2)
else:
z_min1 = reach1.geometry.get_z_min()
z_min2 = reach2.geometry.get_z_min()
@ -197,7 +241,7 @@ class CustomPlot(PamhyrPlot):
self.lines["bed_elevation"] = line
if (self._envelop and
reach.has_bedload() and
reach.has_sediment() and
self._current_res_id < 2):
ax = self._axes[unit["bed_elevation_envelop"]]
@ -574,7 +618,7 @@ class CustomPlot(PamhyrPlot):
rk = reach.geometry.get_rk()
z_min = reach.geometry.get_z_min()
if reach.has_bedload():
if reach.has_sediment():
z_min = self.draw_bottom_with_bedload(reach)
else:
z_min = reach.geometry.get_z_min()
@ -599,12 +643,9 @@ class CustomPlot(PamhyrPlot):
)
if "bed_elevation" in self._y:
if self._current_res_id < 2:
if reach.has_bedload():
dz = self.draw_bottom_with_bedload(reach)
else:
dz = z_min
dz = z_min
else:
if reach.has_bedload():
if reach.has_sediment():
z_min1 = self.draw_bottom_with_bedload(reach1)
z_min2 = self.draw_bottom_with_bedload(reach2)
else:
@ -863,7 +904,7 @@ class CustomPlot(PamhyrPlot):
v = profile.get_key("V")
z_min = profile.geometry.z_min()
if self._current_res_id < 2:
if reach.has_bedload():
if reach.has_sediment():
ts_z_min = self.get_ts_zmin(
self._current_profile_id, self._current_res_id)
else:
@ -881,9 +922,9 @@ class CustomPlot(PamhyrPlot):
ax = self._axes[unit["bed_elevation"]]
if self._current_res_id == 2:
if reach.has_bedload():
ts_z_min1 = self.get_ts_zmin(self._current_profile_id, 0)
ts_z_min2 = self.get_ts_zmin(self._current_profile_id, 1)
if reach.has_sediment():
ts_z_min1 = self.get_ts_zmin(self._current_profile_id1, 0)
ts_z_min2 = self.get_ts_zmin(self._current_profile_id2, 1)
ts_z_min = list(
map(
lambda x, y: x - y,
@ -1099,7 +1140,7 @@ class CustomPlot(PamhyrPlot):
z = profile.get_key("Z")
v = profile.get_key("V")
if self._current_res_id < 2:
if reach.has_bedload():
if reach.has_sediment():
ts_z_min = self.get_ts_zmin(
self._current_profile_id, self._current_res_id)
else:
@ -1112,9 +1153,9 @@ class CustomPlot(PamhyrPlot):
)
if "bed_elevation" in self._y:
if self._current_res_id == 2:
if reach.has_bedload():
ts_z_min1 = self.get_ts_zmin(self._current_profile_id, 0)
ts_z_min2 = self.get_ts_zmin(self._current_profile_id, 1)
if reach.has_sediment():
ts_z_min1 = self.get_ts_zmin(self._current_profile_id1, 0)
ts_z_min2 = self.get_ts_zmin(self._current_profile_id2, 1)
ts_z_min = list(
map(
lambda x, y: x - y,

View File

@ -96,29 +96,24 @@ class PlotRKC(PamhyrPlot):
self._init = True
def draw_bottom(self, reach):
if reach.has_bedload():
if reach.has_sediment():
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)
rk = reach.geometry.get_rk()
zfd = list(
map(
lambda p: p.get_ts_key(
self._current_timestamp, "zfd"
),
reach.profiles
)
)
z = self.sl_compute_current_z(reach)
self.line_bottom, = self.canvas.axes.plot(
rk, zfd,
rk, z,
linestyle="solid", lw=1.,
color=self.color_plot_river_bottom,
)
self._river_bottom = zfd
self._river_bottom = z
def draw_profiles_hs(self, reach):
results = self.results[self._current_res_id]
@ -152,6 +147,58 @@ 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()
@ -290,7 +337,7 @@ class PlotRKC(PamhyrPlot):
results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
if reach.has_bedload():
if reach.has_sediment():
self.update_bottom_with_bedload()
self.update_water_elevation()
@ -350,23 +397,14 @@ 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)
zfd = list(
map(
lambda p: p.get_ts_key(
self._current_timestamp, "zfd"
),
reach.profiles
)
)
z = self.sl_compute_current_z(reach)
self.line_bottom.remove()
self.line_bottom, = self.canvas.axes.plot(
rk, zfd,
rk, z,
linestyle="solid", lw=1.,
color=self.color_plot_river_bottom,
)
self._river_bottom = zfd
self._river_bottom = z

View File

@ -546,7 +546,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]
@ -851,17 +851,17 @@ class ResultsWindow(PamhyrWindow):
my_dict = {}
my_dict[dict_x["rk"]] = reach.geometry.get_rk()
if "bed_elevation" in y:
if reach.has_bedload():
if self._current_results != 2:
zmin = reach.geometry.get_z_min()
else:
z_min1 = reach1.geometry.get_z_min()
z_min2 = reach2.geometry.get_z_min()
zmin = list(
map(
lambda p: p.get_ts_key(
timestamp, "zfd"
),
reach.profiles
map(
lambda x, y: x - y,
z_min2, z_min2
)
)
else:
zmin = reach.geometry.get_z_min()
my_dict[dict_y["bed_elevation"]] = zmin
# if envelop and reach.has_sediment():
if "discharge" in y:
@ -1096,16 +1096,29 @@ class ResultsWindow(PamhyrWindow):
if self._current_results == 2:
reach1 = self._results[0].river.reach(self._reach)
reach2 = self._results[1].river.reach(self._reach)
reach3 = self._results[2].river.reach(self._reach)
profile1 = reach1.profile(self._profile)
profile2 = reach2.profile(self._profile)
profile3 = reach3.profile(self._profile)
q1 = profile1.get_key("Q")
z1 = profile1.get_key("Z")
v1 = profile1.get_key("V")
q2 = profile2.get_key("Q")
z2 = profile2.get_key("Z")
v2 = profile2.get_key("V")
if "bed_elevation" in y:
if reach.has_bedload():
z_min = profile.get_key("zfd")
else:
if self._current_results != 2:
z_min = [profile.geometry.z_min()] * len(self._timestamps)
else:
z_min1 = profile1.geometry.z_min()
z_min2 = profile2.geometry.z_min()
z_min = list(
map(
lambda ts: z_min1 - z_min2,
self._timestamps
)
)
my_dict[dict_y["bed_elevation"]] = z_min
if "discharge" in y:
my_dict[dict_y["discharge"]] = q