export envelops to .csv

compare_results
Theophile Terraz 2024-11-04 17:44:30 +01:00
parent b21b6be9ca
commit 2896c604a5
5 changed files with 123 additions and 51 deletions

View File

@ -226,8 +226,9 @@ class CustomPlot(PamhyrPlot):
if self._envelop:
velocities = list(map(lambda p:
list(map(lambda q, z:
velocities = list(map(
lambda p: list(map(
lambda q, z:
p.geometry.speed(q, z),
p.get_key("Q"), p.get_key("Z")
)), reach.profiles
@ -272,8 +273,8 @@ class CustomPlot(PamhyrPlot):
ax = self._axes[unit["depth_envelop"]]
d = list(map(lambda p1, p2: p1 - p2,
map(
d = list(map(
lambda p1, p2: p1 - p2, map(
lambda p: max(p.get_key("Z")),
reach.profiles
), z_min)
@ -285,8 +286,8 @@ class CustomPlot(PamhyrPlot):
)
self.lines["depth_envelop"] = line1
d = list(map(lambda p1, p2: p1 - p2,
map(
d = list(map(
lambda p1, p2: p1 - p2, map(
lambda p: min(p.get_key("Z")),
reach.profiles
), z_min)
@ -781,10 +782,9 @@ class CustomPlot(PamhyrPlot):
@timer
def update(self):
if not self._init:
#self.draw_static()
self.draw_current()
#if not self._init:
self.draw_update()
self.draw_current()
return
def set_reach(self, reach_id):

View File

@ -36,7 +36,9 @@ class CustomPlotTranslate(ResultsTranslate):
self._dict['time'] = self._dict["unit_time_s"]
self._dict['rk'] = self._dict["unit_rk"]
self._dict['water_elevation'] = self._dict["unit_water_elevation"]
self._dict['water_elevation_envelop'] = self._dict["unit_water_elevation_envelop"]
self._dict['water_elevation_envelop'] = self._dict[
"unit_water_elevation_envelop"
]
self._dict['discharge'] = self._dict["unit_discharge"]
self._dict['discharge_envelop'] = self._dict["unit_discharge_envelop"]
self._dict['bed_elevation'] = self._dict["unit_bed_elevation"]

View File

@ -591,7 +591,7 @@ class ResultsWindow(PamhyrWindow):
dlg = CustomPlotValuesSelectionDialog(parent=self)
if dlg.exec():
x, y, = dlg.value
x, y, envelop = dlg.value
else:
return
@ -601,12 +601,12 @@ class ResultsWindow(PamhyrWindow):
)
self.file_dialog(
select_file="AnyFile",
callback=lambda f: self.export_to(f[0], x, y),
callback=lambda f: self.export_to(f[0], x, y, envelop),
default_suffix=".csv",
file_filter=["CSV (*.csv)"],
)
def export_to(self, filename, x, y):
def export_to(self, filename, x, y, envelop):
timestamps = sorted(self._results.get("timestamps"))
reach = self._results.river.reachs[self._get_current_reach()]
first_line = [f"Study: {self._results.study.name}",
@ -614,7 +614,7 @@ class ResultsWindow(PamhyrWindow):
if x == "rk":
timestamp = self._get_current_timestamp()
first_line.append(f"Time: {timestamp}s")
val_dict = self._export_rk(timestamp, y, filename)
val_dict = self._export_rk(timestamp, y, envelop, filename)
elif x == "time":
profile_id = self._get_current_profile()
profile = reach.profile(profile_id)
@ -626,15 +626,14 @@ class ResultsWindow(PamhyrWindow):
writer = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
dict_x = self._trad.get_dict("values_x")
dict_y = self._trad.get_dict("values_y")
header = [dict_x[x]]
header = []
writer.writerow(first_line)
for text in y:
header.append(dict_y[text])
for text in val_dict.keys():
header.append(text)
writer.writerow(header)
for row in range(len(val_dict[x])):
line = [val_dict[x][row]]
for var in y:
for row in range(len(val_dict[dict_x[x]])):
line = []
for var in val_dict.keys():
line.append(val_dict[var][row])
writer.writerow(line)
@ -676,28 +675,59 @@ class ResultsWindow(PamhyrWindow):
self._additional_plot.pop(tab_widget.tabText(index))
tab_widget.removeTab(index)
def _export_rk(self, timestamp, y, filename):
def _export_rk(self, timestamp, y, envelop, filename):
reach = self._results.river.reachs[self._get_current_reach()]
dict_x = self._trad.get_dict("values_x")
dict_y = self._trad.get_dict("values_y")
if envelop:
dict_y.update(self._trad.get_dict("values_y_envelop"))
my_dict = {}
my_dict["rk"] = reach.geometry.get_rk()
if "elevation" in y:
my_dict["elevation"] = reach.geometry.get_z_min()
my_dict[dict_x["rk"]] = reach.geometry.get_rk()
if "bed_elevation" in y:
my_dict[dict_y["bed_elevation"]] = reach.geometry.get_z_min()
if "discharge" in y:
my_dict["discharge"] = list(
my_dict[dict_y["discharge"]] = list(
map(
lambda p: p.get_ts_key(timestamp, "Q"),
reach.profiles
)
)
if envelop:
my_dict[dict_y["min_discharge"]] = list(
map(
lambda p: min(p.get_key("Q")),
reach.profiles
)
)
my_dict[dict_y["max_discharge"]] = list(
map(
lambda p: max(p.get_key("Q")),
reach.profiles
)
)
if "water_elevation" in y:
my_dict["water_elevation"] = list(
my_dict[dict_y["water_elevation"]] = list(
map(
lambda p: p.get_ts_key(timestamp, "Z"),
reach.profiles
)
)
if envelop:
my_dict[dict_y["min_water_elevation"]] = list(
map(
lambda p: min(p.get_key("Z")),
reach.profiles
)
)
my_dict[dict_y["max_water_elevation"]] = list(
map(
lambda p: max(p.get_key("Z")),
reach.profiles
)
)
if "velocity" in y:
my_dict["velocity"] = list(
my_dict[dict_y["velocity"]] = list(
map(
lambda p: p.geometry.speed(
p.get_ts_key(timestamp, "Q"),
@ -705,16 +735,44 @@ class ResultsWindow(PamhyrWindow):
reach.profiles
)
)
if envelop:
velocities = list(map(
lambda p: list(map(
lambda q, z:
p.geometry.speed(q, z),
p.get_key("Q"), p.get_key("Z")
)), reach.profiles
)
)
my_dict[dict_y["min_velocity"]] = [min(v) for v in velocities]
my_dict[dict_y["max_velocity"]] = [max(v) for v in velocities]
if "depth" in y:
my_dict["depth"] = list(
my_dict[dict_y["depth"]] = list(
map(
lambda p: p.geometry.max_water_depth(
p.get_ts_key(timestamp, "Z")),
reach.profiles
)
)
if envelop:
my_dict[dict_y["min_depth"]] = list(map(
lambda p1, p2: p1 - p2, map(
lambda p: min(p.get_key("Z")),
reach.profiles
), reach.geometry.get_z_min()
)
)
my_dict[dict_y["max_depth"]] = list(map(
lambda p1, p2: p1 - p2, map(
lambda p: max(p.get_key("Z")),
reach.profiles
), reach.geometry.get_z_min()
)
)
if "mean_depth" in y:
my_dict["mean_depth"] = list(
my_dict[dict_y["mean_depth"]] = list(
map(
lambda p: p.geometry.mean_water_depth(
p.get_ts_key(timestamp, "Z")),
@ -722,7 +780,7 @@ class ResultsWindow(PamhyrWindow):
)
)
if "froude" in y:
my_dict["froude"] = list(
my_dict[dict_y["froude"]] = list(
map(
lambda p:
p.geometry.speed(
@ -738,7 +796,7 @@ class ResultsWindow(PamhyrWindow):
)
)
if "wet_area" in y:
my_dict["wet_area"] = list(
my_dict[dict_y["wet_area"]] = list(
map(
lambda p: p.geometry.wet_area(
p.get_ts_key(timestamp, "Z")),
@ -753,33 +811,36 @@ class ResultsWindow(PamhyrWindow):
profile = reach.profile(profile)
ts = list(self._results.get("timestamps"))
ts.sort()
dict_x = self._trad.get_dict("values_x")
dict_y = self._trad.get_dict("values_y")
my_dict = {}
my_dict["time"] = ts
my_dict[dict_x["time"]] = ts
z = profile.get_key("Z")
q = profile.get_key("Q")
if "elevation" in y:
my_dict["elevation"] = [profile.geometry.z_min()] * len(ts)
if "bed_elevation" in y:
my_dict[dict_y["bed_elevation"]] = [
profile.geometry.z_min()] * len(ts)
if "discharge" in y:
my_dict["discharge"] = q
my_dict[dict_y["discharge"]] = q
if "water_elevation" in y:
my_dict["water_elevation"] = z
my_dict[dict_y["water_elevation"]] = z
if "velocity" in y:
my_dict["velocity"] = list(
my_dict[dict_y["velocity"]] = list(
map(
lambda q, z: profile.geometry.speed(q, z),
q, z
)
)
if "depth" in y:
my_dict["depth"] = list(
my_dict[dict_y["depth"]] = list(
map(lambda z: profile.geometry.max_water_depth(z), z)
)
if "mean_depth" in y:
my_dict["mean_depth"] = list(
my_dict[dict_y["mean_depth"]] = list(
map(lambda z: profile.geometry.mean_water_depth(z), z)
)
if "froude" in y:
my_dict["froude"] = list(
my_dict[dict_y["froude"]] = list(
map(lambda z, q:
profile.geometry.speed(q, z) /
sqrt(9.81 * (
@ -788,7 +849,7 @@ class ResultsWindow(PamhyrWindow):
), z, q)
)
if "wet_area" in y:
my_dict["wet_area"] = list(
my_dict[dict_y["wet_area"]] = list(
map(lambda z: profile.geometry.wet_area(z), z)
)

View File

@ -75,14 +75,21 @@ class ResultsTranslate(MainTranslate):
self._sub_dict["values_y"] = {
"bed_elevation": self._dict["unit_bed_elevation"],
"water_elevation": self._dict["unit_water_elevation"],
#"water_elevation_envelop": self._dict["unit_water_elevation_envelop"],
"discharge": self._dict["unit_discharge"],
#"discharge_envelop": self._dict["unit_discharge_envelop"],
"velocity": self._dict["unit_velocity"],
#"velocity_envelop": self._dict["unit_velocity_envelop"],
"depth": self._dict["unit_depth"],
#"depth_envelop": self._dict["unit_depth_envelop"],
"mean_depth": self._dict["unit_mean_depth"],
"froude": self._dict["unit_froude"],
"wet_area": self._dict["unit_wet_area"],
}
self._sub_dict["values_y_envelop"] = {
"min_water_elevation": self._dict["unit_min_water_elevation"],
"max_water_elevation": self._dict["unit_max_water_elevation"],
"min_discharge": self._dict["unit_min_discharge"],
"max_discharge": self._dict["unit_max_discharge"],
"min_velocity": self._dict["unit_min_velocity"],
"max_velocity": self._dict["unit_max_velocity"],
"min_depth": self._dict["unit_min_depth"],
"max_depth": self._dict["unit_max_depth"],
}

View File

@ -69,7 +69,9 @@ class UnitTranslate(CommonWordTranslate):
self._dict["unit_diameter"] = _translate("Unit", "Diameter (m)")
self._dict["unit_thickness"] = _translate("Unit", "Thickness (m)")
self._dict["unit_elevation"] = _translate("Unit", "Elevation (m)")
self._dict["unit_bed_elevation"] = _translate("Unit", "Bed Elevation (m)")
self._dict["unit_bed_elevation"] = _translate(
"Unit", "Bed Elevation (m)"
)
self._dict["unit_water_elevation"] = _translate(
"Unit", "Water Elevation (m)"
)