mirror of https://gitlab.com/pamhyr/pamhyr2
lighter data export
parent
80a463a91e
commit
5e018fc8f0
|
|
@ -303,7 +303,8 @@ class ResultsWindow(PamhyrWindow):
|
||||||
actions = {
|
actions = {
|
||||||
"action_reload": self._reload,
|
"action_reload": self._reload,
|
||||||
"action_add": self._add_custom_plot,
|
"action_add": self._add_custom_plot,
|
||||||
"action_export": self.export,
|
# "action_export": self.export,
|
||||||
|
"action_export": self.export_current,
|
||||||
}
|
}
|
||||||
|
|
||||||
for action in actions:
|
for action in actions:
|
||||||
|
|
@ -591,12 +592,15 @@ class ResultsWindow(PamhyrWindow):
|
||||||
)
|
)
|
||||||
|
|
||||||
def export_to(self, directory):
|
def export_to(self, directory):
|
||||||
|
timestamps = sorted(self._results.get("timestamps"))
|
||||||
for reach in self._results.river.reachs:
|
for reach in self._results.river.reachs:
|
||||||
self.export_reach(reach, directory)
|
self.export_reach(reach, directory, timestamps)
|
||||||
|
|
||||||
def export_reach(self, reach, directory):
|
def export_reach(self, reach, directory, timestamps):
|
||||||
name = reach.name
|
name = reach.name
|
||||||
name = name.replace(" ", "-")
|
name = name.replace(" ", "-")
|
||||||
|
if len(timestamps) == 1:
|
||||||
|
name = f"{name}_t{timestamps[0]}"
|
||||||
|
|
||||||
file_name = os.path.join(
|
file_name = os.path.join(
|
||||||
directory,
|
directory,
|
||||||
|
|
@ -606,28 +610,40 @@ class ResultsWindow(PamhyrWindow):
|
||||||
with open(file_name, 'w', newline='') as csvfile:
|
with open(file_name, 'w', newline='') as csvfile:
|
||||||
writer = csv.writer(csvfile, delimiter=',',
|
writer = csv.writer(csvfile, delimiter=',',
|
||||||
quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||||
writer.writerow(["name", "rk", "data-file"])
|
if len(timestamps) > 1:
|
||||||
for profile in reach.profiles:
|
writer.writerow(["name", "rk", "data-file"])
|
||||||
p_file_name = os.path.join(
|
for profile in reach.profiles:
|
||||||
directory,
|
p_file_name = os.path.join(
|
||||||
f"cs_{profile.geometry.id}.csv"
|
directory,
|
||||||
)
|
f"cs_{profile.geometry.id}.csv"
|
||||||
|
)
|
||||||
|
|
||||||
writer.writerow([
|
writer.writerow([
|
||||||
profile.name,
|
profile.name,
|
||||||
profile.rk,
|
profile.rk,
|
||||||
p_file_name
|
p_file_name
|
||||||
])
|
])
|
||||||
|
|
||||||
self.export_profile(reach, profile, p_file_name)
|
self.export_profile(reach,
|
||||||
|
profile,
|
||||||
|
p_file_name,
|
||||||
|
timestamps)
|
||||||
|
else:
|
||||||
|
ts = timestamps[0]
|
||||||
|
writer.writerow(self._table["raw_data"]._headers)
|
||||||
|
for row in range(self._table["raw_data"].rowCount()):
|
||||||
|
line = []
|
||||||
|
for column in range(self._table["raw_data"].columnCount()):
|
||||||
|
index = self._table["raw_data"].index(row, column)
|
||||||
|
line.append(self._table["raw_data"].data(index))
|
||||||
|
writer.writerow(line)
|
||||||
|
|
||||||
def export_profile(self, reach, profile, file_name):
|
def export_profile(self, reach, profile, file_name, timestamps):
|
||||||
with open(file_name, 'w', newline='') as csvfile:
|
with open(file_name, 'w', newline='') as csvfile:
|
||||||
writer = csv.writer(csvfile, delimiter=',',
|
writer = csv.writer(csvfile, delimiter=',',
|
||||||
quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||||
|
|
||||||
writer.writerow(["timestamp", "z", "q"])
|
writer.writerow(["timestamp", "z", "q"])
|
||||||
timestamps = sorted(self._results.get("timestamps"))
|
|
||||||
|
|
||||||
for ts in timestamps:
|
for ts in timestamps:
|
||||||
writer.writerow([
|
writer.writerow([
|
||||||
|
|
@ -635,3 +651,13 @@ class ResultsWindow(PamhyrWindow):
|
||||||
profile.get_ts_key(ts, "Z"),
|
profile.get_ts_key(ts, "Z"),
|
||||||
profile.get_ts_key(ts, "Q"),
|
profile.get_ts_key(ts, "Q"),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def export_current(self):
|
||||||
|
self.file_dialog(
|
||||||
|
select_file=False,
|
||||||
|
callback=lambda d: self.export_current_to(d[0])
|
||||||
|
)
|
||||||
|
|
||||||
|
def export_current_to(self, directory):
|
||||||
|
reach = self._results.river.reachs[self._get_current_reach()]
|
||||||
|
self.export_reach(reach, directory, [self._get_current_timestamp()])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue