Compare commits

...

7 Commits

Author SHA1 Message Date
Theophile Terraz 7640123299 merge 2025-10-24 16:41:34 +02:00
Theophile Terraz e6dd983f97 more work on compare results 2025-10-24 16:36:06 +02:00
Theophile Terraz 84486c03ed more work on import data results 2025-10-24 15:11:11 +02:00
Theophile Terraz 68b62a5630 debug water limits 2025-10-23 15:30:41 +02:00
Theophile Terraz 990d44dd07 again 2025-10-23 14:50:06 +02:00
Theophile Terraz bf95b7f7e6 work on import data in result window 2025-10-22 16:22:59 +02:00
Theophile Terraz 57a80d00aa work on import data in results 2025-10-21 15:01:16 +02:00
7 changed files with 147 additions and 52 deletions

View File

@ -749,8 +749,8 @@ class ProfileXYZ(Profile, SQLSubModel):
if zz[i] >= z and zz[i+1] < z: if zz[i] >= z and zz[i+1] < z:
y = np.interp( y = np.interp(
z, z,
[zz[i], zz[i+1]], [zz[i+1], zz[i]],
[station[i], station[i+1]] [station[i+1], station[i]]
) )
line.append([y, z]) line.append([y, z])
@ -839,11 +839,8 @@ class ProfileXYZ(Profile, SQLSubModel):
for i in range(self.number_points-1): for i in range(self.number_points-1):
if zz[i] > z and zz[i+1] <= z: if zz[i] > z and zz[i+1] <= z:
y = np.interp( fact = (z - zz[i]) / (zz[i+1] - zz[i])
z, y = station[i] + fact * (station[i+1] - station[i])
[zz[i], zz[i+1]],
[station[i], station[i+1]]
)
start.append(y) start.append(y)
end = [] end = []
@ -852,11 +849,8 @@ class ProfileXYZ(Profile, SQLSubModel):
for i in reversed(range(self.number_points-1)): for i in reversed(range(self.number_points-1)):
if zz[i] <= z and zz[i+1] > z: if zz[i] <= z and zz[i+1] > z:
y = np.interp( fact = (z - zz[i]) / (zz[i+1] - zz[i])
z, y = station[i] + fact * (station[i+1] - station[i])
[zz[i], zz[i+1]],
[station[i], station[i+1]]
)
end.append(y) end.append(y)
if len(start) != len(end): if len(start) != len(end):
@ -887,33 +881,25 @@ class ProfileXYZ(Profile, SQLSubModel):
# Interpolate points at river left side # Interpolate points at river left side
if (i_left > 0): if (i_left > 0):
x = np.interp( fact = (z - self.point(i_left).z) / (self.point(i_left - 1).z
z, - self.point(i_left).z)
[self.point(i_left).z, self.point(i_left - 1).z], x = self.point(i_left).x + fact * (self.point(i_left - 1).x
[self.point(i_left).x, self.point(i_left - 1).x] - self.point(i_left).x)
) y = self.point(i_left).y + fact * (self.point(i_left - 1).y
y = np.interp( - self.point(i_left).y)
z, pt_left = PointXYZ(x=x, y=y, z=z, name="wl_left")
[self.point(i_left).z, self.point(i_left - 1).z],
[self.point(i_left).y, self.point(i_left - 1).y]
)
pt_left = PointXYZ(x, y, z, name="wl_left")
else: else:
pt_left = self.point(0) pt_left = self.point(0)
# Interpolate points at river right side # Interpolate points at river right side
if (i_right < self.number_points - 1): if (i_right < self.number_points - 1):
x = np.interp( fact = (z - self.point(i_right).z) / (self.point(i_right + 1).z -
z, self.point(i_right).z)
[self.point(i_right).z, self.point(i_right + 1).z], x = self.point(i_right).x + fact * (self.point(i_right + 1).x -
[self.point(i_right).x, self.point(i_right + 1).x] self.point(i_right).x)
) y = self.point(i_right).y + fact * (self.point(i_right + 1).y -
y = np.interp( self.point(i_right).y)
z, pt_right = PointXYZ(x=x, y=y, z=z, name="wl_right")
[self.point(i_right).z, self.point(i_right + 1).z],
[self.point(i_right).y, self.point(i_right + 1).y]
)
pt_right = PointXYZ(x, y, z, name="wl_right")
else: else:
pt_right = self.point(self.number_points - 1) pt_right = self.point(self.number_points - 1)

View File

@ -599,13 +599,7 @@ class CustomPlot(PamhyrPlot):
self.lines["wet_area"] = line self.lines["wet_area"] = line
# Legend # Legend
lns = reduce( self.update_legend()
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 _redraw_rk(self): def _redraw_rk(self):
results = self.data[self._current_res_id] results = self.data[self._current_res_id]
@ -1103,13 +1097,7 @@ class CustomPlot(PamhyrPlot):
self._customize_x_axes_time(ts) self._customize_x_axes_time(ts)
# Legend # Legend
lns = reduce( self.update_legend()
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 _redraw_time(self): def _redraw_time(self):
@ -1419,3 +1407,25 @@ class CustomPlot(PamhyrPlot):
x = self._timestamp x = self._timestamp
self._current.set_data([x, x], self.canvas.axes.get_ylim()) self._current.set_data([x, x], self.canvas.axes.get_ylim())
self.canvas.draw_idle() 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()

View File

@ -55,6 +55,9 @@ class CustomPlotTranslate(ResultsTranslate):
self._dict['wet_perimeter'] = self._dict["unit_wet_perimeter"] self._dict['wet_perimeter'] = self._dict["unit_wet_perimeter"]
self._dict['hydraulic_radius'] = self._dict["unit_hydraulic_radius"] self._dict['hydraulic_radius'] = self._dict["unit_hydraulic_radius"]
self._dict['froude'] = self._dict["unit_froude"] self._dict['froude'] = self._dict["unit_froude"]
self._dict['user_imported'] = _translate(
"CustomPlot", "user_imported"
)
# Unit corresponding long name (plot axes display) # Unit corresponding long name (plot axes display)

View File

@ -160,8 +160,6 @@ class TableModel(PamhyrTableModel):
self._lst = _river.reachs self._lst = _river.reachs
elif self._opt_data == "profile" or self._opt_data == "raw_data": elif self._opt_data == "profile" or self._opt_data == "raw_data":
self._lst = _river.reach(reach).profiles self._lst = _river.reach(reach).profiles
# self._lst = list(compress(_river.reach(reach).profiles,
# _river.reach(reach).profile_mask))
elif self._opt_data == "solver": elif self._opt_data == "solver":
self._lst = self._parent._solvers self._lst = self._parent._solvers

View File

@ -31,6 +31,8 @@ except Exception as e:
print(f"Module 'rasterio' is not available: {e}") print(f"Module 'rasterio' is not available: {e}")
_rasterio_loaded = False _rasterio_loaded = False
from functools import reduce
from numpy import sqrt from numpy import sqrt
from datetime import datetime from datetime import datetime
@ -54,7 +56,7 @@ from PyQt5.QtWidgets import (
QFileDialog, QTableView, QAbstractItemView, QFileDialog, QTableView, QAbstractItemView,
QUndoStack, QShortcut, QAction, QItemDelegate, QUndoStack, QShortcut, QAction, QItemDelegate,
QComboBox, QVBoxLayout, QHeaderView, QTabWidget, QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
QSlider, QLabel, QWidget, QGridLayout, QTabBar QSlider, QLabel, QWidget, QGridLayout, QTabBar, QInputDialog
) )
from View.Tools.Plot.PamhyrCanvas import MplCanvas from View.Tools.Plot.PamhyrCanvas import MplCanvas
@ -347,6 +349,7 @@ class ResultsWindow(PamhyrWindow):
"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, # "action_export": self.export_current,
"action_import_data": self.import_data
} }
if _rasterio_loaded: if _rasterio_loaded:
actions["action_Geo_tiff"] = self.import_geotiff actions["action_Geo_tiff"] = self.import_geotiff
@ -715,7 +718,7 @@ class ResultsWindow(PamhyrWindow):
select_file="AnyFile", select_file="AnyFile",
callback=lambda f: self.export_to(f[0], x, y, envelop, solver_id), callback=lambda f: self.export_to(f[0], x, y, envelop, solver_id),
default_suffix=".csv", default_suffix=".csv",
file_filter=["CSV (*.csv)"], file_filter=[self._dict["file_csv"]],
) )
def export_to(self, filename, x, y, envelop, solver_id): def export_to(self, filename, x, y, envelop, solver_id):
@ -1225,3 +1228,83 @@ class ResultsWindow(PamhyrWindow):
self.plot_xy.idle() self.plot_xy.idle()
self.canvas.axes.set_xlim(xlim) self.canvas.axes.set_xlim(xlim)
self.canvas.axes.set_ylim(ylim) 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)

View File

@ -56,6 +56,8 @@ class ResultsTranslate(MainTranslate):
self._dict["file_all"] = _translate("Results", "All files (*)") self._dict["file_all"] = _translate("Results", "All files (*)")
self._dict["file_geotiff"] = _translate( self._dict["file_geotiff"] = _translate(
"Results", "GeoTIFF file (*.tiff *.tif)") "Results", "GeoTIFF file (*.tiff *.tif)")
self._dict["file_csv"] = _translate(
"Results", "CSV file (*.csv)")
self._dict["ImageCoordinates"] = _translate( self._dict["ImageCoordinates"] = _translate(
"Results", "Image coordinates" "Results", "Image coordinates"
) )

View File

@ -239,6 +239,7 @@
<addaction name="action_export"/> <addaction name="action_export"/>
<addaction name="action_reload"/> <addaction name="action_reload"/>
<addaction name="action_Geo_tiff"/> <addaction name="action_Geo_tiff"/>
<addaction name="action_import_data"/>
</widget> </widget>
<action name="action_add"> <action name="action_add">
<property name="icon"> <property name="icon">
@ -288,6 +289,18 @@
<string>Import background image</string> <string>Import background image</string>
</property> </property>
</action> </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> </widget>
<resources/> <resources/>
<connections/> <connections/>