mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-29 19:10:42 +01:00
Results: Refactoring '_export_time' method.
This commit is contained in:
1 parent
5d46401b85
commit
f93e6a7d7c
2 files changed
+101
-123
No files matched your search
@@ -826,7 +826,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
|
||||
return n_zones
|
||||
|
||||
def froude(self, v, z):
|
||||
def froude(self, z, v):
|
||||
return v / np.sqrt(
|
||||
9.81 * (
|
||||
self.wet_area(z) / self.wet_width(z)
|
||||
|
||||
+100
-122
@@ -937,6 +937,7 @@ class ResultsWindow(PamhyrWindow):
|
||||
my_dict = data["my_dict"]
|
||||
envelop = data["envelop"]
|
||||
id_ts = data["id_ts"]
|
||||
|
||||
q = data["q"]
|
||||
|
||||
my_dict["discharge"] = q[id_ts, :]
|
||||
@@ -949,6 +950,7 @@ class ResultsWindow(PamhyrWindow):
|
||||
my_dict = data["my_dict"]
|
||||
envelop = data["envelop"]
|
||||
id_ts = data["id_ts"]
|
||||
|
||||
z = data["z"]
|
||||
|
||||
my_dict["water_elevation"] = z[id_ts, :]
|
||||
@@ -961,6 +963,7 @@ class ResultsWindow(PamhyrWindow):
|
||||
my_dict = data["my_dict"]
|
||||
envelop = data["envelop"]
|
||||
id_ts = data["id_ts"]
|
||||
|
||||
v = data["v"]
|
||||
|
||||
my_dict["velocity"] = v[id_ts, :]
|
||||
@@ -974,6 +977,7 @@ class ResultsWindow(PamhyrWindow):
|
||||
envelop = data["envelop"]
|
||||
reach = data["reach"]
|
||||
id_ts = data["id_ts"]
|
||||
|
||||
z = data["z"]
|
||||
|
||||
my_dict["depth"] = list(
|
||||
@@ -995,6 +999,7 @@ class ResultsWindow(PamhyrWindow):
|
||||
my_dict = data["my_dict"]
|
||||
reach = data["reach"]
|
||||
id_ts = data["id_ts"]
|
||||
|
||||
z = data["z"]
|
||||
|
||||
my_dict["mean_depth"] = list(
|
||||
@@ -1010,14 +1015,15 @@ class ResultsWindow(PamhyrWindow):
|
||||
my_dict = data["my_dict"]
|
||||
reach = data["reach"]
|
||||
id_ts = data["id_ts"]
|
||||
|
||||
z = data["z"]
|
||||
v = data["v"]
|
||||
|
||||
my_dict["froude"] = list(
|
||||
map(
|
||||
lambda p: p.geometry.froude(
|
||||
v[id_ts, p.global_index],
|
||||
z[id_ts, p.global_index]
|
||||
z[id_ts, p.global_index],
|
||||
v[id_ts, p.global_index]
|
||||
),
|
||||
reach.profiles
|
||||
)
|
||||
@@ -1027,6 +1033,7 @@ class ResultsWindow(PamhyrWindow):
|
||||
my_dict = data["my_dict"]
|
||||
reach = data["reach"]
|
||||
id_ts = data["id_ts"]
|
||||
|
||||
z = data["z"]
|
||||
|
||||
my_dict["wet_area"] = list(
|
||||
@@ -1045,134 +1052,105 @@ class ResultsWindow(PamhyrWindow):
|
||||
dict_x = self._trad.get_dict("values_x")
|
||||
dict_y = self._trad.get_dict("values_y")
|
||||
|
||||
my_dict = {}
|
||||
my_dict[dict_x["time"]] = self._timestamps
|
||||
|
||||
table = results.get("table")
|
||||
ind = profile.global_index
|
||||
|
||||
z = table["Z"][:, profile.global_index]
|
||||
q = table["Q"][:, profile.global_index]
|
||||
v = table["V"][:, profile.global_index]
|
||||
zfd = table["zfd"][:, profile.global_index]
|
||||
my_dict = {}
|
||||
data = {
|
||||
"z": table["Z"][:, ind],
|
||||
"q": table["Q"][:, ind],
|
||||
"v": table["V"][:, ind],
|
||||
"zfd": table["zfd"][:, ind],
|
||||
|
||||
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)
|
||||
"reach": reach,
|
||||
"profile": profile,
|
||||
"my_dict": my_dict,
|
||||
}
|
||||
|
||||
z1 = table["Z"][:, profile1.global_index]
|
||||
q1 = table["Q"][:, profile1.global_index]
|
||||
v1 = table["V"][:, profile1.global_index]
|
||||
def set_dict(k, v):
|
||||
my_dict[k] = v
|
||||
|
||||
z2 = table["Z"][:, profile2.global_index]
|
||||
q2 = table["Q"][:, profile2.global_index]
|
||||
v2 = table["V"][:, profile2.global_index]
|
||||
func = {
|
||||
"bed_elevation": self._export_time_compute_elevation,
|
||||
"discharge": lambda d: set_dict("discharge", d["q"]),
|
||||
"water_elevation": lambda d: set_dict("water_elevation", d["z"]),
|
||||
"velocity": lambda d: set_dict("velocity", d["v"]),
|
||||
"depth": self._export_time_compute_depth,
|
||||
"mean_depth": self._export_time_compute_mean_depth,
|
||||
"froude": self._export_time_compute_froude,
|
||||
"wet_area": self._export_time_compute_wet_area,
|
||||
}
|
||||
|
||||
if "bed_elevation" in y:
|
||||
if reach.has_bedload():
|
||||
z_min = zfd
|
||||
else:
|
||||
z_min = [profile.geometry.z_min()] * len(self._timestamps)
|
||||
# Compute values
|
||||
for key in y:
|
||||
func[key](data)
|
||||
|
||||
my_dict[dict_y["bed_elevation"]] = z_min
|
||||
if "discharge" in y:
|
||||
my_dict[dict_y["discharge"]] = q
|
||||
if "water_elevation" in y:
|
||||
my_dict[dict_y["water_elevation"]] = z
|
||||
if "velocity" in y:
|
||||
my_dict[dict_y["velocity"]] = v
|
||||
if "depth" in y:
|
||||
if self._current_results != 2:
|
||||
d = list(
|
||||
map(lambda x: profile.geometry.max_water_depth(x), z)
|
||||
)
|
||||
else:
|
||||
d1 = list(
|
||||
map(lambda x: profile1.geometry.max_water_depth(x), z1)
|
||||
)
|
||||
d2 = list(
|
||||
map(lambda x: profile2.geometry.max_water_depth(x), z2)
|
||||
)
|
||||
d = list(
|
||||
map(
|
||||
lambda x, y: x - y,
|
||||
d1, d2
|
||||
)
|
||||
)
|
||||
my_dict[dict_y["depth"]] = d
|
||||
if "mean_depth" in y:
|
||||
if self._current_results != 2:
|
||||
d = list(
|
||||
map(lambda x: profile.geometry.mean_water_depth(x), z)
|
||||
)
|
||||
else:
|
||||
d1 = list(
|
||||
map(lambda x: profile1.geometry.mean_water_depth(x), z1)
|
||||
)
|
||||
d2 = list(
|
||||
map(lambda x: profile2.geometry.mean_water_depth(x), z2)
|
||||
)
|
||||
d = list(map(
|
||||
lambda x, y: x - y,
|
||||
d1, d2
|
||||
))
|
||||
my_dict[dict_y["mean_depth"]] = d
|
||||
if "froude" in y:
|
||||
if self._current_results != 2:
|
||||
fr = my_dict[dict_y["froude"]] = list(
|
||||
map(lambda z, v:
|
||||
v / sqrt(9.81 * (
|
||||
profile.geometry.wet_area(z) /
|
||||
profile.geometry.wet_width(z))
|
||||
),
|
||||
z, v)
|
||||
)
|
||||
else:
|
||||
fr1 = list(
|
||||
map(lambda z, v:
|
||||
v /
|
||||
sqrt(9.81 * (
|
||||
profile1.geometry.wet_area(z) /
|
||||
profile1.geometry.wet_width(z))
|
||||
),
|
||||
z1, v1)
|
||||
)
|
||||
fr2 = list(
|
||||
map(lambda z, v:
|
||||
v /
|
||||
sqrt(9.81 * (
|
||||
profile2.geometry.wet_area(z) /
|
||||
profile2.geometry.wet_width(z))
|
||||
),
|
||||
z2, v2)
|
||||
)
|
||||
fr = list(map(
|
||||
lambda x, y: x - y,
|
||||
fr1, fr2
|
||||
))
|
||||
my_dict[dict_y["froude"]] = fr
|
||||
if "wet_area" in y:
|
||||
if self._current_results != 2:
|
||||
wa = list(
|
||||
map(lambda x: profile.geometry.wet_area(x), z)
|
||||
)
|
||||
else:
|
||||
wa1 = list(
|
||||
map(lambda x: profile1.geometry.wet_area(x), z1)
|
||||
)
|
||||
wa2 = list(
|
||||
map(lambda x: profile2.geometry.wet_area(x), z2)
|
||||
)
|
||||
wa = list(map(
|
||||
lambda x, y: x - y,
|
||||
wa1, wa2
|
||||
))
|
||||
my_dict[dict_y["wet_area"]] = wa
|
||||
# Translate dictionary keys
|
||||
translated_dict = {}
|
||||
for key in my_dict:
|
||||
translated_dict[dict_y[key]] = my_dict[key]
|
||||
|
||||
return my_dict
|
||||
translated_dict[dict_x["time"]] = self._timestamps
|
||||
|
||||
return translated_dict
|
||||
|
||||
def _export_time_compute_elevation(self, data):
|
||||
my_dict = data["my_dict"]
|
||||
reach = data["reach"]
|
||||
|
||||
if reach.has_bedload():
|
||||
z_min = data["zfd"]
|
||||
else:
|
||||
z_min = [profile.geometry.z_min()] * len(self._timestamps)
|
||||
|
||||
my_dict["bed_elevation"] = z_min
|
||||
|
||||
def _export_time_compute_depth(self, data):
|
||||
my_dict = data["my_dict"]
|
||||
profile = data["profile"]
|
||||
|
||||
z = data["z"]
|
||||
|
||||
my_dict["depth"] = list(
|
||||
map(lambda x: profile.geometry.max_water_depth(x), z)
|
||||
)
|
||||
|
||||
def _export_time_compute_mean_depth(self, data):
|
||||
my_dict = data["my_dict"]
|
||||
profile = data["profile"]
|
||||
|
||||
z = data["z"]
|
||||
|
||||
my_dict["mean_depth"] = list(
|
||||
map(lambda x: profile.geometry.mean_water_depth(x), z)
|
||||
)
|
||||
|
||||
def _export_time_compute_froude(self, data):
|
||||
my_dict = data["my_dict"]
|
||||
profile = data["profile"]
|
||||
|
||||
z = data["z"]
|
||||
v = data["v"]
|
||||
|
||||
my_dict["froude"] = list(
|
||||
map(
|
||||
lambda z, v: profile.geometry.froude(z, v),
|
||||
z, v
|
||||
)
|
||||
)
|
||||
|
||||
def _export_time_compute_wet_area(self, data):
|
||||
my_dict = data["my_dict"]
|
||||
profile = data["profile"]
|
||||
|
||||
z = data["z"]
|
||||
|
||||
my_dict["wet_area"] = list(
|
||||
map(
|
||||
lambda x: profile.geometry.wet_area(x),
|
||||
z
|
||||
)
|
||||
)
|
||||
|
||||
def get_timestamps(self):
|
||||
self._timestamps = sorted(list(self._results[0].get("timestamps")))
|
||||
|
||||
Reference in new issue
Block a user