mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
merge
This commit is contained in:
commit
7640123299
7 files changed
+147
-52
No files matched your search
@@ -599,13 +599,7 @@ class CustomPlot(PamhyrPlot):
|
||||
self.lines["wet_area"] = line
|
||||
|
||||
# Legend
|
||||
lns = reduce(
|
||||
lambda acc, line: acc + line,
|
||||
map(lambda line: self.lines[line], self.lines),
|
||||
[]
|
||||
)
|
||||
labs = list(map(lambda line: self._trad[line], self.lines))
|
||||
self.canvas.axes.legend(lns, labs, loc="best")
|
||||
self.update_legend()
|
||||
|
||||
def _redraw_rk(self):
|
||||
results = self.data[self._current_res_id]
|
||||
@@ -1103,13 +1097,7 @@ class CustomPlot(PamhyrPlot):
|
||||
self._customize_x_axes_time(ts)
|
||||
|
||||
# Legend
|
||||
lns = reduce(
|
||||
lambda acc, line: acc + line,
|
||||
map(lambda line: self.lines[line], self.lines),
|
||||
[]
|
||||
)
|
||||
labs = list(map(lambda line: self._trad[line], self.lines))
|
||||
self.canvas.axes.legend(lns, labs, loc="best")
|
||||
self.update_legend()
|
||||
|
||||
def _redraw_time(self):
|
||||
|
||||
@@ -1419,3 +1407,25 @@ class CustomPlot(PamhyrPlot):
|
||||
x = self._timestamp
|
||||
self._current.set_data([x, x], self.canvas.axes.get_ylim())
|
||||
self.canvas.draw_idle()
|
||||
|
||||
def update_legend(self):
|
||||
lns = reduce(
|
||||
lambda acc, line: acc + line,
|
||||
map(lambda line: self.lines[line], self.lines),
|
||||
[]
|
||||
)
|
||||
labs = list(map(lambda line: self._trad[line], self.lines))
|
||||
self.canvas.axes.legend(lns, labs, loc="best")
|
||||
|
||||
def add_imported_plot(self, data):
|
||||
if (data["type_x"] == self._x and
|
||||
data["type_y"] in self._y):
|
||||
while data["legend"] in self.lines:
|
||||
data["legend"] += '*'
|
||||
self._trad._dict[data["legend"]] = data["legend"] + data["unit"]
|
||||
self.lines[data["legend"]] = self.canvas.axes.plot(data["x"],
|
||||
data["y"],
|
||||
marker="+",
|
||||
linestyle="--")
|
||||
self.update_legend()
|
||||
self.idle()
|
||||
@@ -55,6 +55,9 @@ class CustomPlotTranslate(ResultsTranslate):
|
||||
self._dict['wet_perimeter'] = self._dict["unit_wet_perimeter"]
|
||||
self._dict['hydraulic_radius'] = self._dict["unit_hydraulic_radius"]
|
||||
self._dict['froude'] = self._dict["unit_froude"]
|
||||
self._dict['user_imported'] = _translate(
|
||||
"CustomPlot", "user_imported"
|
||||
)
|
||||
|
||||
# Unit corresponding long name (plot axes display)
|
||||
|
||||
|
||||
@@ -160,8 +160,6 @@ class TableModel(PamhyrTableModel):
|
||||
self._lst = _river.reachs
|
||||
elif self._opt_data == "profile" or self._opt_data == "raw_data":
|
||||
self._lst = _river.reach(reach).profiles
|
||||
# self._lst = list(compress(_river.reach(reach).profiles,
|
||||
# _river.reach(reach).profile_mask))
|
||||
elif self._opt_data == "solver":
|
||||
self._lst = self._parent._solvers
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ except Exception as e:
|
||||
print(f"Module 'rasterio' is not available: {e}")
|
||||
_rasterio_loaded = False
|
||||
|
||||
from functools import reduce
|
||||
|
||||
from numpy import sqrt
|
||||
|
||||
from datetime import datetime
|
||||
@@ -54,7 +56,7 @@ from PyQt5.QtWidgets import (
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
|
||||
QSlider, QLabel, QWidget, QGridLayout, QTabBar
|
||||
QSlider, QLabel, QWidget, QGridLayout, QTabBar, QInputDialog
|
||||
)
|
||||
|
||||
from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
||||
@@ -347,6 +349,7 @@ class ResultsWindow(PamhyrWindow):
|
||||
"action_add": self._add_custom_plot,
|
||||
"action_export": self._export,
|
||||
# "action_export": self.export_current,
|
||||
"action_import_data": self.import_data
|
||||
}
|
||||
if _rasterio_loaded:
|
||||
actions["action_Geo_tiff"] = self.import_geotiff
|
||||
@@ -715,7 +718,7 @@ class ResultsWindow(PamhyrWindow):
|
||||
select_file="AnyFile",
|
||||
callback=lambda f: self.export_to(f[0], x, y, envelop, solver_id),
|
||||
default_suffix=".csv",
|
||||
file_filter=["CSV (*.csv)"],
|
||||
file_filter=[self._dict["file_csv"]],
|
||||
)
|
||||
|
||||
def export_to(self, filename, x, y, envelop, solver_id):
|
||||
@@ -1225,3 +1228,83 @@ class ResultsWindow(PamhyrWindow):
|
||||
self.plot_xy.idle()
|
||||
self.canvas.axes.set_xlim(xlim)
|
||||
self.canvas.axes.set_ylim(ylim)
|
||||
return
|
||||
|
||||
def import_data(self):
|
||||
|
||||
file_types = [
|
||||
self._trad["file_csv"],
|
||||
self._trad["file_all"],
|
||||
]
|
||||
|
||||
self.file_dialog(
|
||||
select_file="Existing_file",
|
||||
callback=lambda f: self.read_csv_file(f[0]),
|
||||
default_suffix=".csv",
|
||||
file_filter=file_types,
|
||||
)
|
||||
|
||||
def read_csv_file(self, filename):
|
||||
if filename == "":
|
||||
return
|
||||
|
||||
sep = " "
|
||||
with open(filename, 'r', newline='') as f:
|
||||
lines = f.readlines()
|
||||
x = []
|
||||
y = []
|
||||
for line in lines:
|
||||
if line[0] != "*" and line[0] != "#" and line[0] != "$":
|
||||
row = line.split(sep)
|
||||
if len(row) >= 2:
|
||||
try:
|
||||
x.append(float(row[0]))
|
||||
y.append(float(row[1]))
|
||||
except:
|
||||
pass
|
||||
|
||||
data_type_lst = ['Q(t)', 'Z(t)', 'Z(x)']
|
||||
data_type, ok = QInputDialog.getItem(
|
||||
self, 'Data type', 'Chose the type of data:', data_type_lst)
|
||||
|
||||
if not ok:
|
||||
return
|
||||
|
||||
legend, ok = QInputDialog.getText(self, 'Legend', 'Legend:')
|
||||
|
||||
if not ok:
|
||||
return
|
||||
|
||||
if legend.strip() == '':
|
||||
legend = '*'
|
||||
|
||||
tmp_dict = {'Z': 'water_elevation',
|
||||
'Q': 'discharge',
|
||||
'x': 'rk',
|
||||
't': 'time'}
|
||||
|
||||
tmp_unit = {'Z': ' (m)',
|
||||
'Q': ' (m³/s)'}
|
||||
|
||||
data = {'type_x': tmp_dict[data_type[2]],
|
||||
'type_y': tmp_dict[data_type[0]],
|
||||
'legend': legend,
|
||||
'unit': tmp_unit[data_type[0]],
|
||||
'x': x,
|
||||
'y': y}
|
||||
|
||||
if data_type == 'Z(x)':
|
||||
line = self.canvas_2.axes.plot(x, y, marker="+",
|
||||
label=legend + ' (m)')
|
||||
self.plot_rkc.canvas.draw_idle()
|
||||
self.plot_rkc.update_idle()
|
||||
if data_type == 'Q(t)':
|
||||
line = self.canvas_4.axes.plot(x, y, marker="+",
|
||||
label=legend + ' (m³/s)')
|
||||
self.plot_h._line.append(line)
|
||||
self.plot_h.enable_legend()
|
||||
self.plot_h.canvas.draw_idle()
|
||||
self.plot_h.update_idle
|
||||
|
||||
for p in self._additional_plot:
|
||||
self._additional_plot[p].add_imported_plot(data)
|
||||
@@ -56,6 +56,8 @@ class ResultsTranslate(MainTranslate):
|
||||
self._dict["file_all"] = _translate("Results", "All files (*)")
|
||||
self._dict["file_geotiff"] = _translate(
|
||||
"Results", "GeoTIFF file (*.tiff *.tif)")
|
||||
self._dict["file_csv"] = _translate(
|
||||
"Results", "CSV file (*.csv)")
|
||||
self._dict["ImageCoordinates"] = _translate(
|
||||
"Results", "Image coordinates"
|
||||
)
|
||||
|
||||
@@ -239,6 +239,7 @@
|
||||
<addaction name="action_export"/>
|
||||
<addaction name="action_reload"/>
|
||||
<addaction name="action_Geo_tiff"/>
|
||||
<addaction name="action_import_data"/>
|
||||
</widget>
|
||||
<action name="action_add">
|
||||
<property name="icon">
|
||||
@@ -288,6 +289,18 @@
|
||||
<string>Import background image</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_import_data">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>ressources/import.png</normaloff>ressources/import.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Import data</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Import data from SCV file</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
Reference in new issue
Block a user