Commit 2896c604 authored by Theophile Terraz's avatar Theophile Terraz
Browse files

export envelops to .csv

No related merge requests found
Pipeline #60139 passed with stages
in 4 minutes and 9 seconds
Showing with 123 additions and 51 deletions
+123 -51
...@@ -165,7 +165,7 @@ class CustomPlot(PamhyrPlot): ...@@ -165,7 +165,7 @@ class CustomPlot(PamhyrPlot):
color='blue', color='blue',
linestyle='dotted', linestyle='dotted',
) )
#self.lines["water_elevation_envelop2"] = line2 # self.lines["water_elevation_envelop2"] = line2
if "discharge" in self._y: if "discharge" in self._y:
...@@ -204,7 +204,7 @@ class CustomPlot(PamhyrPlot): ...@@ -204,7 +204,7 @@ class CustomPlot(PamhyrPlot):
color='r', color='r',
linestyle='dotted', linestyle='dotted',
) )
#self.lines["discharge_envelop2"] = line2 # self.lines["discharge_envelop2"] = line2
if "velocity" in self._y: if "velocity" in self._y:
...@@ -226,8 +226,9 @@ class CustomPlot(PamhyrPlot): ...@@ -226,8 +226,9 @@ class CustomPlot(PamhyrPlot):
if self._envelop: if self._envelop:
velocities = list(map(lambda p: velocities = list(map(
list(map(lambda q, z: lambda p: list(map(
lambda q, z:
p.geometry.speed(q, z), p.geometry.speed(q, z),
p.get_key("Q"), p.get_key("Z") p.get_key("Q"), p.get_key("Z")
)), reach.profiles )), reach.profiles
...@@ -250,7 +251,7 @@ class CustomPlot(PamhyrPlot): ...@@ -250,7 +251,7 @@ class CustomPlot(PamhyrPlot):
color='g', color='g',
linestyle='dotted', linestyle='dotted',
) )
#self.lines["velocity_envelop2"] = line2 # self.lines["velocity_envelop2"] = line2
if "depth" in self._y: if "depth" in self._y:
...@@ -272,8 +273,8 @@ class CustomPlot(PamhyrPlot): ...@@ -272,8 +273,8 @@ class CustomPlot(PamhyrPlot):
ax = self._axes[unit["depth_envelop"]] ax = self._axes[unit["depth_envelop"]]
d = list(map(lambda p1, p2: p1 - p2, d = list(map(
map( lambda p1, p2: p1 - p2, map(
lambda p: max(p.get_key("Z")), lambda p: max(p.get_key("Z")),
reach.profiles reach.profiles
), z_min) ), z_min)
...@@ -285,8 +286,8 @@ class CustomPlot(PamhyrPlot): ...@@ -285,8 +286,8 @@ class CustomPlot(PamhyrPlot):
) )
self.lines["depth_envelop"] = line1 self.lines["depth_envelop"] = line1
d = list(map(lambda p1, p2: p1 - p2, d = list(map(
map( lambda p1, p2: p1 - p2, map(
lambda p: min(p.get_key("Z")), lambda p: min(p.get_key("Z")),
reach.profiles reach.profiles
), z_min) ), z_min)
...@@ -296,7 +297,7 @@ class CustomPlot(PamhyrPlot): ...@@ -296,7 +297,7 @@ class CustomPlot(PamhyrPlot):
color='brown', lw=1., color='brown', lw=1.,
linestyle='dotted', linestyle='dotted',
) )
#self.lines["depth_envelop2"] = line2 # self.lines["depth_envelop2"] = line2
if "mean_depth" in self._y: if "mean_depth" in self._y:
...@@ -781,10 +782,9 @@ class CustomPlot(PamhyrPlot): ...@@ -781,10 +782,9 @@ class CustomPlot(PamhyrPlot):
@timer @timer
def update(self): def update(self):
if not self._init: #if not self._init:
#self.draw_static()
self.draw_current()
self.draw_update() self.draw_update()
self.draw_current()
return return
def set_reach(self, reach_id): def set_reach(self, reach_id):
......
...@@ -36,7 +36,9 @@ class CustomPlotTranslate(ResultsTranslate): ...@@ -36,7 +36,9 @@ class CustomPlotTranslate(ResultsTranslate):
self._dict['time'] = self._dict["unit_time_s"] self._dict['time'] = self._dict["unit_time_s"]
self._dict['rk'] = self._dict["unit_rk"] self._dict['rk'] = self._dict["unit_rk"]
self._dict['water_elevation'] = self._dict["unit_water_elevation"] 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'] = self._dict["unit_discharge"]
self._dict['discharge_envelop'] = self._dict["unit_discharge_envelop"] self._dict['discharge_envelop'] = self._dict["unit_discharge_envelop"]
self._dict['bed_elevation'] = self._dict["unit_bed_elevation"] self._dict['bed_elevation'] = self._dict["unit_bed_elevation"]
......
...@@ -591,7 +591,7 @@ class ResultsWindow(PamhyrWindow): ...@@ -591,7 +591,7 @@ class ResultsWindow(PamhyrWindow):
dlg = CustomPlotValuesSelectionDialog(parent=self) dlg = CustomPlotValuesSelectionDialog(parent=self)
if dlg.exec(): if dlg.exec():
x, y, = dlg.value x, y, envelop = dlg.value
else: else:
return return
...@@ -601,12 +601,12 @@ class ResultsWindow(PamhyrWindow): ...@@ -601,12 +601,12 @@ class ResultsWindow(PamhyrWindow):
) )
self.file_dialog( self.file_dialog(
select_file="AnyFile", 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", default_suffix=".csv",
file_filter=["CSV (*.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")) timestamps = sorted(self._results.get("timestamps"))
reach = self._results.river.reachs[self._get_current_reach()] reach = self._results.river.reachs[self._get_current_reach()]
first_line = [f"Study: {self._results.study.name}", first_line = [f"Study: {self._results.study.name}",
...@@ -614,7 +614,7 @@ class ResultsWindow(PamhyrWindow): ...@@ -614,7 +614,7 @@ class ResultsWindow(PamhyrWindow):
if x == "rk": if x == "rk":
timestamp = self._get_current_timestamp() timestamp = self._get_current_timestamp()
first_line.append(f"Time: {timestamp}s") 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": elif x == "time":
profile_id = self._get_current_profile() profile_id = self._get_current_profile()
profile = reach.profile(profile_id) profile = reach.profile(profile_id)
...@@ -626,15 +626,14 @@ class ResultsWindow(PamhyrWindow): ...@@ -626,15 +626,14 @@ class ResultsWindow(PamhyrWindow):
writer = csv.writer(csvfile, delimiter=',', writer = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL) quotechar='|', quoting=csv.QUOTE_MINIMAL)
dict_x = self._trad.get_dict("values_x") dict_x = self._trad.get_dict("values_x")
dict_y = self._trad.get_dict("values_y") header = []
header = [dict_x[x]]
writer.writerow(first_line) writer.writerow(first_line)
for text in y: for text in val_dict.keys():
header.append(dict_y[text]) header.append(text)
writer.writerow(header) writer.writerow(header)
for row in range(len(val_dict[x])): for row in range(len(val_dict[dict_x[x]])):
line = [val_dict[x][row]] line = []
for var in y: for var in val_dict.keys():
line.append(val_dict[var][row]) line.append(val_dict[var][row])
writer.writerow(line) writer.writerow(line)
...@@ -676,28 +675,59 @@ class ResultsWindow(PamhyrWindow): ...@@ -676,28 +675,59 @@ class ResultsWindow(PamhyrWindow):
self._additional_plot.pop(tab_widget.tabText(index)) self._additional_plot.pop(tab_widget.tabText(index))
tab_widget.removeTab(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()] 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 = {}
my_dict["rk"] = reach.geometry.get_rk() my_dict[dict_x["rk"]] = reach.geometry.get_rk()
if "elevation" in y: if "bed_elevation" in y:
my_dict["elevation"] = reach.geometry.get_z_min() my_dict[dict_y["bed_elevation"]] = reach.geometry.get_z_min()
if "discharge" in y: if "discharge" in y:
my_dict["discharge"] = list( my_dict[dict_y["discharge"]] = list(
map( map(
lambda p: p.get_ts_key(timestamp, "Q"), lambda p: p.get_ts_key(timestamp, "Q"),
reach.profiles 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: if "water_elevation" in y:
my_dict["water_elevation"] = list( my_dict[dict_y["water_elevation"]] = list(
map( map(
lambda p: p.get_ts_key(timestamp, "Z"), lambda p: p.get_ts_key(timestamp, "Z"),
reach.profiles 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: if "velocity" in y:
my_dict["velocity"] = list( my_dict[dict_y["velocity"]] = list(
map( map(
lambda p: p.geometry.speed( lambda p: p.geometry.speed(
p.get_ts_key(timestamp, "Q"), p.get_ts_key(timestamp, "Q"),
...@@ -705,16 +735,44 @@ class ResultsWindow(PamhyrWindow): ...@@ -705,16 +735,44 @@ class ResultsWindow(PamhyrWindow):
reach.profiles 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: if "depth" in y:
my_dict["depth"] = list( my_dict[dict_y["depth"]] = list(
map( map(
lambda p: p.geometry.max_water_depth( lambda p: p.geometry.max_water_depth(
p.get_ts_key(timestamp, "Z")), p.get_ts_key(timestamp, "Z")),
reach.profiles 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: if "mean_depth" in y:
my_dict["mean_depth"] = list( my_dict[dict_y["mean_depth"]] = list(
map( map(
lambda p: p.geometry.mean_water_depth( lambda p: p.geometry.mean_water_depth(
p.get_ts_key(timestamp, "Z")), p.get_ts_key(timestamp, "Z")),
...@@ -722,7 +780,7 @@ class ResultsWindow(PamhyrWindow): ...@@ -722,7 +780,7 @@ class ResultsWindow(PamhyrWindow):
) )
) )
if "froude" in y: if "froude" in y:
my_dict["froude"] = list( my_dict[dict_y["froude"]] = list(
map( map(
lambda p: lambda p:
p.geometry.speed( p.geometry.speed(
...@@ -738,7 +796,7 @@ class ResultsWindow(PamhyrWindow): ...@@ -738,7 +796,7 @@ class ResultsWindow(PamhyrWindow):
) )
) )
if "wet_area" in y: if "wet_area" in y:
my_dict["wet_area"] = list( my_dict[dict_y["wet_area"]] = list(
map( map(
lambda p: p.geometry.wet_area( lambda p: p.geometry.wet_area(
p.get_ts_key(timestamp, "Z")), p.get_ts_key(timestamp, "Z")),
...@@ -753,33 +811,36 @@ class ResultsWindow(PamhyrWindow): ...@@ -753,33 +811,36 @@ class ResultsWindow(PamhyrWindow):
profile = reach.profile(profile) profile = reach.profile(profile)
ts = list(self._results.get("timestamps")) ts = list(self._results.get("timestamps"))
ts.sort() ts.sort()
dict_x = self._trad.get_dict("values_x")
dict_y = self._trad.get_dict("values_y")
my_dict = {} my_dict = {}
my_dict["time"] = ts my_dict[dict_x["time"]] = ts
z = profile.get_key("Z") z = profile.get_key("Z")
q = profile.get_key("Q") q = profile.get_key("Q")
if "elevation" in y: if "bed_elevation" in y:
my_dict["elevation"] = [profile.geometry.z_min()] * len(ts) my_dict[dict_y["bed_elevation"]] = [
profile.geometry.z_min()] * len(ts)
if "discharge" in y: if "discharge" in y:
my_dict["discharge"] = q my_dict[dict_y["discharge"]] = q
if "water_elevation" in y: if "water_elevation" in y:
my_dict["water_elevation"] = z my_dict[dict_y["water_elevation"]] = z
if "velocity" in y: if "velocity" in y:
my_dict["velocity"] = list( my_dict[dict_y["velocity"]] = list(
map( map(
lambda q, z: profile.geometry.speed(q, z), lambda q, z: profile.geometry.speed(q, z),
q, z q, z
) )
) )
if "depth" in y: if "depth" in y:
my_dict["depth"] = list( my_dict[dict_y["depth"]] = list(
map(lambda z: profile.geometry.max_water_depth(z), z) map(lambda z: profile.geometry.max_water_depth(z), z)
) )
if "mean_depth" in y: 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) map(lambda z: profile.geometry.mean_water_depth(z), z)
) )
if "froude" in y: if "froude" in y:
my_dict["froude"] = list( my_dict[dict_y["froude"]] = list(
map(lambda z, q: map(lambda z, q:
profile.geometry.speed(q, z) / profile.geometry.speed(q, z) /
sqrt(9.81 * ( sqrt(9.81 * (
...@@ -788,7 +849,7 @@ class ResultsWindow(PamhyrWindow): ...@@ -788,7 +849,7 @@ class ResultsWindow(PamhyrWindow):
), z, q) ), z, q)
) )
if "wet_area" in y: 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) map(lambda z: profile.geometry.wet_area(z), z)
) )
......
...@@ -75,14 +75,21 @@ class ResultsTranslate(MainTranslate): ...@@ -75,14 +75,21 @@ class ResultsTranslate(MainTranslate):
self._sub_dict["values_y"] = { self._sub_dict["values_y"] = {
"bed_elevation": self._dict["unit_bed_elevation"], "bed_elevation": self._dict["unit_bed_elevation"],
"water_elevation": self._dict["unit_water_elevation"], "water_elevation": self._dict["unit_water_elevation"],
#"water_elevation_envelop": self._dict["unit_water_elevation_envelop"],
"discharge": self._dict["unit_discharge"], "discharge": self._dict["unit_discharge"],
#"discharge_envelop": self._dict["unit_discharge_envelop"],
"velocity": self._dict["unit_velocity"], "velocity": self._dict["unit_velocity"],
#"velocity_envelop": self._dict["unit_velocity_envelop"],
"depth": self._dict["unit_depth"], "depth": self._dict["unit_depth"],
#"depth_envelop": self._dict["unit_depth_envelop"],
"mean_depth": self._dict["unit_mean_depth"], "mean_depth": self._dict["unit_mean_depth"],
"froude": self._dict["unit_froude"], "froude": self._dict["unit_froude"],
"wet_area": self._dict["unit_wet_area"], "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"],
}
...@@ -69,7 +69,9 @@ class UnitTranslate(CommonWordTranslate): ...@@ -69,7 +69,9 @@ class UnitTranslate(CommonWordTranslate):
self._dict["unit_diameter"] = _translate("Unit", "Diameter (m)") self._dict["unit_diameter"] = _translate("Unit", "Diameter (m)")
self._dict["unit_thickness"] = _translate("Unit", "Thickness (m)") self._dict["unit_thickness"] = _translate("Unit", "Thickness (m)")
self._dict["unit_elevation"] = _translate("Unit", "Elevation (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( self._dict["unit_water_elevation"] = _translate(
"Unit", "Water Elevation (m)" "Unit", "Water Elevation (m)"
) )
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment