mirror of https://gitlab.com/pamhyr/pamhyr2
Results: Add export function.
parent
aec31df520
commit
d2f275c49f
|
|
@ -17,6 +17,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import csv
|
||||
import logging
|
||||
|
||||
from datetime import datetime
|
||||
|
|
@ -284,7 +285,8 @@ class ResultsWindow(PamhyrWindow):
|
|||
# Action
|
||||
actions = {
|
||||
"action_reload": self._reload,
|
||||
"action_add": self._add_custom_plot
|
||||
"action_add": self._add_custom_plot,
|
||||
"action_export": self.export,
|
||||
}
|
||||
|
||||
for action in actions:
|
||||
|
|
@ -564,3 +566,56 @@ class ResultsWindow(PamhyrWindow):
|
|||
self._button_first.setEnabled(True)
|
||||
self._button_last.setEnabled(True)
|
||||
self._button_play.setIcon(self._icon_start)
|
||||
|
||||
def export(self):
|
||||
self.file_dialog(
|
||||
select_file=False,
|
||||
callback=lambda d: self.export_to(d[0])
|
||||
)
|
||||
|
||||
def export_to(self, directory):
|
||||
for reach in self._results.river.reachs:
|
||||
self.export_reach(reach, directory)
|
||||
|
||||
def export_reach(self, reach, directory):
|
||||
name = reach.name
|
||||
name = name.replace(" ", "-")
|
||||
|
||||
file_name = os.path.join(
|
||||
directory,
|
||||
f"reach_{name}.csv"
|
||||
)
|
||||
|
||||
with open(file_name, 'w', newline='') as csvfile:
|
||||
writer = csv.writer(csvfile, delimiter=',',
|
||||
quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||
writer.writerow(["name", "kp", "data-file"])
|
||||
for profile in reach.profiles:
|
||||
p_file_name = os.path.join(
|
||||
directory,
|
||||
f"cs_{profile.geometry.id}.csv"
|
||||
)
|
||||
|
||||
writer.writerow([
|
||||
profile.name,
|
||||
profile.kp,
|
||||
p_file_name
|
||||
])
|
||||
|
||||
self.export_profile(reach, profile, p_file_name)
|
||||
|
||||
def export_profile(self, reach, profile, file_name):
|
||||
with open(file_name, 'w', newline='') as csvfile:
|
||||
writer = csv.writer(csvfile, delimiter=',',
|
||||
quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||
|
||||
writer.writerow(["timestamp", "z", "q"])
|
||||
for profile in reach.profiles:
|
||||
timestamps = self._results.get("timestamps")
|
||||
|
||||
for ts in timestamps:
|
||||
writer.writerow([
|
||||
ts,
|
||||
profile.get_ts_key(ts, "Z"),
|
||||
profile.get_ts_key(ts, "Q"),
|
||||
])
|
||||
|
|
|
|||
Loading…
Reference in New Issue