adists_release
Theophile Terraz 2024-10-31 14:02:38 +01:00
commit 4f69553bd3
11 changed files with 292 additions and 81 deletions

View File

@ -1 +0,0 @@
$Clapet_001 clapet

Binary file not shown.

View File

@ -599,29 +599,50 @@ class Mage(CommandLineSolver):
if qlog is not None: if qlog is not None:
qlog.put("Export VAR file") qlog.put("Export VAR file")
with mage_file_open(os.path.join(repertory, f"{name}.VAR"), "w+") as f: nb_cv = 0
files.append(f"{name}.VAR") for hs in hydraulic_structures:
if hs.input_reach is None:
continue
for hs in hydraulic_structures: if not hs.input_reach.is_enable():
if hs.input_reach is None: continue
continue
if not hs.input_reach.is_enable(): if not hs.enabled:
continue continue
for bhs in hs.basic_structures: for bhs in hs.basic_structures:
if bhs.enabled:
logger.info(bhs._type) logger.info(bhs._type)
if bhs._type != "CV": if bhs._type == "CV":
nb_cv += 1
if nb_cv != 0:
with mage_file_open(os.path.join(
repertory, f"{name}.VAR"), "w+") as f:
files.append(f"{name}.VAR")
for hs in hydraulic_structures:
if hs.input_reach is None:
continue continue
name = bhs.name if not hs.input_reach.is_enable():
if name == "": continue
name = f"HS_{bhs.id:>3}".replace(" ", "0")
f.write( if not hs.enabled:
f"${name} clapet" continue
)
for bhs in hs.basic_structures:
logger.info(bhs._type)
if bhs._type != "CV":
continue
name = bhs.name
if name == "":
name = f"HS_{bhs.id:>3}".replace(" ", "0")
f.write(
f"${name} clapet"
)
return files return files
def _export_DEV(self, study, repertory, qlog, name="0"): def _export_DEV(self, study, repertory, qlog, name="0"):

View File

@ -365,40 +365,43 @@ class InitialConditionsWindow(PamhyrWindow):
self._update() self._update()
def generate_growing_constant_depth(self): def generate_growing_constant_depth(self):
dlg = DepthDialog(self.depth_value, if self._reach.reach.number_profiles > 0:
self.depth_option, dlg = DepthDialog(self.depth_value,
trad=self._trad, self.depth_option,
parent=self)
if dlg.exec():
self.depth_value = dlg.value
self.depth_option = dlg.option
self._table.generate("growing",
self.depth_value,
self.depth_option)
self._update()
def generate_discharge(self):
dlg = DischargeDialog(self.discharge_value,
self.discharge_option,
trad=self._trad, trad=self._trad,
parent=self) parent=self)
if dlg.exec(): if dlg.exec():
self.discharge_value = dlg.value self.depth_value = dlg.value
self.discharge_option = dlg.option self.depth_option = dlg.option
self._table.generate("discharge", self._table.generate("growing",
self.discharge_value, self.depth_value,
self.discharge_option) self.depth_option)
self._update() self._update()
def generate_discharge(self):
if self._reach.reach.number_profiles > 1:
dlg = DischargeDialog(self.discharge_value,
self.discharge_option,
trad=self._trad,
parent=self)
if dlg.exec():
self.discharge_value = dlg.value
self.discharge_option = dlg.option
self._table.generate("discharge",
self.discharge_value,
self.discharge_option)
self._update()
def generate_height(self): def generate_height(self):
dlg = HeightDialog(self.height_values, if self._reach.reach.number_profiles > 0:
self.height_option, dlg = HeightDialog(self.height_values,
trad=self._trad, self.height_option,
parent=self) trad=self._trad,
if dlg.exec(): parent=self)
self.height_values = dlg.values if dlg.exec():
self.height_option = dlg.option self.height_values = dlg.values
self._table.generate("height", self.height_option = dlg.option
self.height_values, self._table.generate("height",
self.height_option) self.height_values,
self._update() self.height_option)
self._update()

View File

@ -20,8 +20,13 @@ import logging
from tools import timer, trace from tools import timer, trace
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
from View.Tools.Plot.PamhyrCanvas import MplCanvas
from View.PlotXY import PlotXY
from View.Tools.PamhyrWidget import PamhyrWidget from View.Tools.PamhyrWidget import PamhyrWidget
from PyQt5.QtWidgets import QVBoxLayout
logger = logging.getLogger() logger = logging.getLogger()
@ -38,7 +43,9 @@ class WidgetInfo(PamhyrWidget):
parent=parent parent=parent
) )
self.parent = parent
self.set_initial_values() self.set_initial_values()
self.setup_graph()
@property @property
def study(self): def study(self):
@ -64,6 +71,25 @@ class WidgetInfo(PamhyrWidget):
self.set_label_text("label_lc", "-") self.set_label_text("label_lc", "-")
self.set_label_text("label_hs", "-") self.set_label_text("label_hs", "-")
def setup_graph(self):
self.canvas = MplCanvas(width=5, height=4, dpi=100)
self.canvas.setObjectName("canvas")
self.plot_layout_xy = self.find(QVBoxLayout, "verticalLayout")
self._toolbar_xy = PamhyrPlotToolbar(
self.canvas, self,
items=["home", "zoom", "save", "iso", "back/forward", "move"]
)
self.plot_layout_xy.addWidget(self._toolbar_xy)
self.plot_layout_xy.addWidget(self.canvas)
self.plot = PlotXY(
canvas=self.canvas,
data=None,
trad=self.parent._trad,
toolbar=self._toolbar_xy,
parent=self
)
def update(self): def update(self):
if self._study is None: if self._study is None:
self.set_initial_values() self.set_initial_values()
@ -75,6 +101,15 @@ class WidgetInfo(PamhyrWidget):
self.set_network_values() self.set_network_values()
self.set_geometry_values() self.set_geometry_values()
self.plot = PlotXY(
canvas=self.canvas,
data=self._study.river.enable_edges(),
trad=self.parent._trad,
toolbar=self._toolbar_xy,
parent=self
)
self.plot.update()
def set_network_values(self): def set_network_values(self):
river = self._study.river river = self._study.river

119
src/View/PlotXY.py Normal file
View File

@ -0,0 +1,119 @@
# PlotXY.py -- Pamhyr
# Copyright (C) 2023-2024 INRAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
from tools import timer, trace
from View.Tools.PamhyrPlot import PamhyrPlot
from matplotlib import collections
import numpy as np
from PyQt5.QtCore import (
QCoreApplication, Qt, QItemSelectionModel,
QItemSelection, QItemSelectionRange,
)
from PyQt5.QtWidgets import QApplication, QTableView
_translate = QCoreApplication.translate
class PlotXY(PamhyrPlot):
def __init__(self, canvas=None, trad=None, data=None, toolbar=None,
table=None, parent=None):
super(PlotXY, self).__init__(
canvas=canvas,
trad=trad,
data=data,
toolbar=toolbar,
table=table,
parent=parent
)
self._data = data
self.label_x = self._trad["x"]
self.label_y = self._trad["y"]
self.parent = parent
self._isometric_axis = True
self._auto_relim_update = True
self._autoscale_update = True
@timer
def draw(self):
self.init_axes()
if self._data is None:
self.idle()
return
if len(self._data) < 1:
self.idle()
return
self.line_lr = []
for data in self._data:
if data.reach.number_profiles != 0:
self.draw_xy(data.reach)
self.draw_lr(data.reach)
self.idle()
return
def draw_xy(self, reach):
line_xy = []
for xy in zip(reach.get_x(), reach.get_y()):
line_xy.append(np.column_stack(xy))
line_xy_collection = collections.LineCollection(
line_xy,
colors=self.color_plot_river_bottom
)
self.canvas.axes.add_collection(line_xy_collection)
def draw_lr(self, reach):
lx = []
ly = []
rx = []
ry = []
for x, y in zip(reach.get_x(),
reach.get_y()):
lx.append(x[0])
ly.append(y[0])
rx.append(x[-1])
ry.append(y[-1])
line = self.canvas.axes.plot(
lx, ly,
color=self.color_plot_river_bottom,
linestyle="dotted",
lw=1.,
)
self.line_lr.append(line)
line = self.canvas.axes.plot(
rx, ry,
color=self.color_plot_river_bottom,
linestyle="dotted",
lw=1.,
)
self.line_lr.append(line)
@timer
def update(self):
self.draw()
self.update_idle()

View File

@ -49,8 +49,8 @@ class Plot(PamhyrPlot):
self._mode = mode self._mode = mode
self._table_headers = self._trad.get_dict("table_headers") self._table_headers = self._trad.get_dict("table_headers")
self.label_x = self._table_headers["z"] self.label_x = self._table_headers["area"]
self.label_y = self._table_headers["area"] self.label_y = self._table_headers["z"]
self._isometric_axis = False self._isometric_axis = False
@ -71,8 +71,8 @@ class Plot(PamhyrPlot):
self._init = True self._init = True
def draw_data(self): def draw_data(self):
x = list(map(lambda v: v[0], self.data.data)) x = list(map(lambda v: v[1], self.data.data))
y = list(map(lambda v: v[1], self.data.data)) y = list(map(lambda v: v[0], self.data.data))
self._line, = self.canvas.axes.plot( self._line, = self.canvas.axes.plot(
x, y, x, y,
color=self.color_plot, color=self.color_plot,
@ -89,7 +89,7 @@ class Plot(PamhyrPlot):
self.update_idle() self.update_idle()
def update_data(self): def update_data(self):
x = list(map(lambda v: v[0], self.data.data)) x = list(map(lambda v: v[1], self.data.data))
y = list(map(lambda v: v[1], self.data.data)) y = list(map(lambda v: v[0], self.data.data))
self._line.set_data(x, y) self._line.set_data(x, y)

View File

@ -146,8 +146,9 @@ class PlotXY(PamhyrPlot):
return return
reach = self.results.river.reach(self._current_reach_id) reach = self.results.river.reach(self._current_reach_id)
reaches = self.results.river.reachs
self.draw_profiles(reach) self.draw_profiles(reach, reaches)
self.draw_water_elevation(reach) self.draw_water_elevation(reach)
self.draw_water_elevation_max(reach) self.draw_water_elevation_max(reach)
self.draw_guide_lines(reach) self.draw_guide_lines(reach)
@ -156,12 +157,12 @@ class PlotXY(PamhyrPlot):
self.idle() self.idle()
self._init = True self._init = True
def draw_profiles(self, reach): def draw_profiles(self, reach, reaches):
if reach.geometry.number_profiles == 0: if reach.geometry.number_profiles == 0:
self._init = False self._init = False
return return
# TODO uncomment to draw all the reaches
self.line_xy = [] # self.draw_other_profiles(reaches)
for xy in zip(reach.geometry.get_x(), for xy in zip(reach.geometry.get_x(),
reach.geometry.get_y()): reach.geometry.get_y()):
self.line_xy.append(np.column_stack(xy)) self.line_xy.append(np.column_stack(xy))
@ -176,6 +177,19 @@ class PlotXY(PamhyrPlot):
) )
self.canvas.axes.add_collection(self.line_xy_collection) self.canvas.axes.add_collection(self.line_xy_collection)
def draw_other_profiles(self, reaches):
for reach in reaches:
for xy in zip(reach.geometry.get_x(),
reach.geometry.get_y()):
self.line_xy.append(np.column_stack(xy))
self.line_xy_collection = collections.LineCollection(
self.line_xy,
colors=self.color_plot_river_bottom,
)
self.canvas.axes.add_collection(self.line_xy_collection)
def draw_guide_lines(self, reach): def draw_guide_lines(self, reach):
x_complete = reach.geometry.get_guidelines_x() x_complete = reach.geometry.get_guidelines_x()
y_complete = reach.geometry.get_guidelines_y() y_complete = reach.geometry.get_guidelines_y()

View File

@ -606,11 +606,17 @@ class ResultsWindow(PamhyrWindow):
def export_to(self, filename, x, y): def export_to(self, filename, x, y):
timestamps = sorted(self._results.get("timestamps")) timestamps = sorted(self._results.get("timestamps"))
reach = self._results.river.reachs[self._get_current_reach()]
first_line = [f"Study: {self._results.study.name}",
f"Reach: {reach.name}"]
if x == "rk": if x == "rk":
timestamp = self._get_current_timestamp() timestamp = self._get_current_timestamp()
first_line.append(f"Time: {timestamp}s")
val_dict = self._export_rk(timestamp, y, filename) val_dict = self._export_rk(timestamp, y, filename)
elif x == "time": elif x == "time":
profile = self._get_current_profile() profile = self._get_current_profile()
pname = profile.name if profile.name != "" else profile.rk
first_line.append(f"Profile: {pname}")
val_dict = self._export_time(profile, y, filename) val_dict = self._export_time(profile, y, filename)
with open(filename, 'w', newline='') as csvfile: with open(filename, 'w', newline='') as csvfile:
@ -619,6 +625,7 @@ class ResultsWindow(PamhyrWindow):
dict_x = self._trad.get_dict("values_x") dict_x = self._trad.get_dict("values_x")
dict_y = self._trad.get_dict("values_y") dict_y = self._trad.get_dict("values_y")
header = [dict_x[x]] header = [dict_x[x]]
writer.writerow(first_line)
for text in y: for text in y:
header.append(dict_y[text]) header.append(dict_y[text])
writer.writerow(header) writer.writerow(header)

View File

@ -146,3 +146,5 @@ class MainTranslate(UnitTranslate):
"MainWindow", "MainWindow",
"Do you want to save current study before closing it?" "Do you want to save current study before closing it?"
) )
self._dict["x"] = _translate("MainWindow", "X (m)")
self._dict["y"] = _translate("MainWindow", "Y (m)")

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="2.0" language="fr_FR" sourcelanguage="en_150"> <!DOCTYPE TS>
<TS version="2.1" language="fr_FR" sourcelanguage="en_150">
<context> <context>
<name>About</name> <name>About</name>
<message> <message>
@ -1167,7 +1168,7 @@ Cette fonctionnalité nécessite un bief muni d&apos;une géométrie.</translati
</message> </message>
<message> <message>
<location filename="../View/ui/about.ui" line="94"/> <location filename="../View/ui/about.ui" line="94"/>
<source>Copyright &#xa9; 2022-2024 INRAE</source> <source>Copyright © 2022-2024 INRAE</source>
<translation type="obsolete">Copyright © 2022-2024 INRAE</translation> <translation type="obsolete">Copyright © 2022-2024 INRAE</translation>
</message> </message>
<message> <message>
@ -1175,11 +1176,6 @@ Cette fonctionnalité nécessite un bief muni d&apos;une géométrie.</translati
<source>Version: @version @codename</source> <source>Version: @version @codename</source>
<translation>Version : @version @codename</translation> <translation>Version : @version @codename</translation>
</message> </message>
<message encoding="UTF-8">
<location filename="../View/ui/about.ui" line="94"/>
<source>Copyright © 2022-2024 INRAE</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>Frictions</name> <name>Frictions</name>
@ -1456,17 +1452,17 @@ Cette fonctionnalité nécessite un bief muni d&apos;une géométrie.</translati
<context> <context>
<name>MainWindow</name> <name>MainWindow</name>
<message> <message>
<location filename="../View/Translate.py" line="98"/> <location filename="../View/Translate.py" line="97"/>
<source>Open debug window</source> <source>Open debug window</source>
<translation>Ouvrir la fenêtre de débogage</translation> <translation>Ouvrir la fenêtre de débogage</translation>
</message> </message>
<message> <message>
<location filename="../View/Translate.py" line="101"/> <location filename="../View/Translate.py" line="100"/>
<source>Open SQLite debuging tool (&apos;sqlitebrowser&apos;)</source> <source>Open SQLite debuging tool (&apos;sqlitebrowser&apos;)</source>
<translation>Ouvrir l&apos;outil de débogage SQLite (&apos;sqlitebrowser&apos;)</translation> <translation>Ouvrir l&apos;outil de débogage SQLite (&apos;sqlitebrowser&apos;)</translation>
</message> </message>
<message> <message>
<location filename="../View/Translate.py" line="104"/> <location filename="../View/Translate.py" line="103"/>
<source>Enable this window</source> <source>Enable this window</source>
<translation>Activer cette fenêtre</translation> <translation>Activer cette fenêtre</translation>
</message> </message>
@ -2311,12 +2307,12 @@ Cette fonctionnalité nécessite un bief muni d&apos;une géométrie.</translati
<translation>Maillage</translation> <translation>Maillage</translation>
</message> </message>
<message> <message>
<location filename="../View/Translate.py" line="91"/> <location filename="../View/Translate.py" line="90"/>
<source>Summary</source> <source>Summary</source>
<translation>Résumé</translation> <translation>Résumé</translation>
</message> </message>
<message> <message>
<location filename="../View/Translate.py" line="94"/> <location filename="../View/Translate.py" line="93"/>
<source>Checks</source> <source>Checks</source>
<translation>Vérifications</translation> <translation>Vérifications</translation>
</message> </message>
@ -2536,7 +2532,7 @@ Cette fonctionnalité nécessite un bief muni d&apos;une géométrie.</translati
<translation>Données</translation> <translation>Données</translation>
</message> </message>
<message> <message>
<location filename="../View/Translate.py" line="112"/> <location filename="../View/Translate.py" line="111"/>
<source>Please select a reach</source> <source>Please select a reach</source>
<translation>Veuillez sélectionner un bief</translation> <translation>Veuillez sélectionner un bief</translation>
</message> </message>
@ -2546,35 +2542,45 @@ Cette fonctionnalité nécessite un bief muni d&apos;une géométrie.</translati
<translation type="obsolete">L&apos;édition de la géométrie nécessite un bief sélectionné dans le réseau fluvial pour pouvoir travailler dessus</translation> <translation type="obsolete">L&apos;édition de la géométrie nécessite un bief sélectionné dans le réseau fluvial pour pouvoir travailler dessus</translation>
</message> </message>
<message> <message>
<location filename="../View/Translate.py" line="121"/> <location filename="../View/Translate.py" line="120"/>
<source>Last open study</source> <source>Last open study</source>
<translation>Dernière étude ouverte</translation> <translation>Dernière étude ouverte</translation>
</message> </message>
<message> <message>
<location filename="../View/Translate.py" line="124"/> <location filename="../View/Translate.py" line="123"/>
<source>Do you want to open again the last open study?</source> <source>Do you want to open again the last open study?</source>
<translation>Voulez-vous rouvrir la dernière étude ?</translation> <translation>Voulez-vous rouvrir la dernière étude ?</translation>
</message> </message>
<message> <message>
<location filename="../View/Translate.py" line="115"/> <location filename="../View/Translate.py" line="114"/>
<source>This edition window need a reach selected into the river network to work on it</source> <source>This edition window need a reach selected into the river network to work on it</source>
<translation>Cette fenêtre d&apos;édition a besoin d&apos;un bief sélectionné dans le réseau pour travailler dessus</translation> <translation>Cette fenêtre d&apos;édition a besoin d&apos;un bief sélectionné dans le réseau pour travailler dessus</translation>
</message> </message>
<message> <message>
<location filename="../View/Translate.py" line="129"/> <location filename="../View/Translate.py" line="128"/>
<source>Close without saving study</source> <source>Close without saving study</source>
<translation>Fermer sans sauvegarder l&apos;étude</translation> <translation>Fermer sans sauvegarder l&apos;étude</translation>
</message> </message>
<message> <message>
<location filename="../View/Translate.py" line="132"/> <location filename="../View/Translate.py" line="131"/>
<source>Do you want to save current study before closing it?</source> <source>Do you want to save current study before closing it?</source>
<translation>Souhaitez-vous sauvegarder l&apos;étude en cours avant de la fermer ?</translation> <translation>Souhaitez-vous sauvegarder l&apos;étude en cours avant de la fermer ?</translation>
</message> </message>
<message> <message>
<location filename="../View/Translate.py" line="109"/> <location filename="../View/Translate.py" line="108"/>
<source>Warning</source> <source>Warning</source>
<translation>Avertissement</translation> <translation>Avertissement</translation>
</message> </message>
<message>
<location filename="../View/Translate.py" line="135"/>
<source>X (m)</source>
<translation>X (m)</translation>
</message>
<message>
<location filename="../View/Translate.py" line="136"/>
<source>Y (m)</source>
<translation>Y (m)</translation>
</message>
</context> </context>
<context> <context>
<name>MainWindow_reach</name> <name>MainWindow_reach</name>
@ -3255,17 +3261,17 @@ Cette fonctionnalité nécessite un bief muni d&apos;une géométrie.</translati
<translation>Vitesse (m/s)</translation> <translation>Vitesse (m/s)</translation>
</message> </message>
<message> <message>
<location filename="../View/Translate.py" line="78"/> <location filename="../View/Translate.py" line="77"/>
<source>Wet Perimeter (m)</source> <source>Wet Perimeter (m)</source>
<translation>Périmètre mouillé (m)</translation> <translation>Périmètre mouillé (m)</translation>
</message> </message>
<message> <message>
<location filename="../View/Translate.py" line="81"/> <location filename="../View/Translate.py" line="80"/>
<source>Hydraulic Radius (m)</source> <source>Hydraulic Radius (m)</source>
<translation>Rayon hydraulique (m)</translation> <translation>Rayon hydraulique (m)</translation>
</message> </message>
<message> <message>
<location filename="../View/Translate.py" line="84"/> <location filename="../View/Translate.py" line="83"/>
<source>Froude number</source> <source>Froude number</source>
<translation>Nombre de Froude</translation> <translation>Nombre de Froude</translation>
</message> </message>
@ -3277,6 +3283,11 @@ Cette fonctionnalité nécessite un bief muni d&apos;une géométrie.</translati
<message> <message>
<location filename="../View/Translate.py" line="77"/> <location filename="../View/Translate.py" line="77"/>
<source>Wet Area (m^2)</source> <source>Wet Area (m^2)</source>
<translation type="obsolete">Aire mouillée (m²)</translation>
</message>
<message>
<location filename="../View/Translate.py" line="76"/>
<source>Wet Area (m²)</source>
<translation>Aire mouillée (m²)</translation> <translation>Aire mouillée (m²)</translation>
</message> </message>
</context> </context>