Compare commits

...
11 Commits
Author SHA1 Message Date
Theophile Terraz 6f7a891a6d optimization + debug 2025-01-20 16:24:17 +01:00
Theophile Terraz e4224e6358 force Mage sulver type in open from file 2025-01-17 13:54:27 +01:00
Theophile Terraz aa8a9dccbf translation 2025-01-17 12:00:42 +01:00
Theophile Terraz 1732e30e58 debug 2025-01-17 09:31:37 +01:00
Theophile Terraz 9eedd1fff9 debug results 2025-01-17 09:20:01 +01:00
Theophile Terraz ac6e8a3704 debug Adis-TS files generation 2025-01-16 15:54:50 +01:00
Theophile Terraz c5f918c885 pep8 2025-01-16 15:08:24 +01:00
Theophile Terraz 230712c3ea debug Adis-TS 2025-01-16 15:03:52 +01:00
Theophile Terraz 2e2f054a4f debug Adis-TS 2025-01-16 14:16:24 +01:00
Theophile Terraz f75a25d010 debug 2025-01-15 14:26:31 +01:00
Theophile Terraz 9db90debeb translation 2024-12-20 17:13:44 +01:00
28 changed files with 1042 additions and 338 deletions

No files matched your search

+93 -13
View File
@@ -20,6 +20,7 @@ import logging
import numpy as np import numpy as np
from typing import List from typing import List
from functools import reduce from functools import reduce
from dataclasses import dataclass
from tools import timer from tools import timer
from shapely import geometry from shapely import geometry
@@ -33,6 +34,13 @@ from Model.Geometry.Vector_1d import Vector1d
logger = logging.getLogger() logger = logging.getLogger()
@dataclass
class Tabulation:
z: np.array([])
A: np.array([])
L: np.array([])
class ProfileXYZ(Profile, SQLSubModel): class ProfileXYZ(Profile, SQLSubModel):
_sub_classes = [ _sub_classes = [
PointXYZ, PointXYZ,
@@ -70,6 +78,14 @@ class ProfileXYZ(Profile, SQLSubModel):
status=status, status=status,
) )
self.tab = Tabulation([], [], [])
self.tab_up_to_date = False
self.time_z = 0.0
self.time_A = 0.0
self.time_l = 0.0
self._station = []
self.station_up_to_date = False
@classmethod @classmethod
def _db_create(cls, execute): def _db_create(cls, execute):
execute(""" execute("""
@@ -305,6 +321,8 @@ class ProfileXYZ(Profile, SQLSubModel):
pt = PointXYZ(*point, profile=self, status=self._status) pt = PointXYZ(*point, profile=self, status=self._status)
self.points.append(pt) self.points.append(pt)
self._status.modified() self._status.modified()
self.tab_up_to_date = False
self.station_up_to_date = False
def get_point_i(self, index: int) -> PointXYZ: def get_point_i(self, index: int) -> PointXYZ:
"""Get point at index. """Get point at index.
@@ -366,6 +384,8 @@ class ProfileXYZ(Profile, SQLSubModel):
point_xyz = PointXYZ(0., 0., 0., profile=self, status=self._status) point_xyz = PointXYZ(0., 0., 0., profile=self, status=self._status)
self.points.append(point_xyz) self.points.append(point_xyz)
self._status.modified() self._status.modified()
self.tab_up_to_date = False
self.station_up_to_date = False
def insert(self, index: int): def insert(self, index: int):
"""Insert a new point at index. """Insert a new point at index.
@@ -379,6 +399,8 @@ class ProfileXYZ(Profile, SQLSubModel):
point = PointXYZ(0., 0., 0., profile=self, status=self._status) point = PointXYZ(0., 0., 0., profile=self, status=self._status)
self.points.insert(index, point) self.points.insert(index, point)
self._status.modified() self._status.modified()
self.tab_up_to_date = False
self.station_up_to_date = False
return point return point
def filter_isnan(self, lst): def filter_isnan(self, lst):
@@ -410,7 +432,7 @@ class ProfileXYZ(Profile, SQLSubModel):
return abs(rg.dist(rd)) return abs(rg.dist(rd))
def wet_width(self, z): def compute_wet_width(self, z):
start, end = self.get_all_water_limits_ac(z) start, end = self.get_all_water_limits_ac(z)
if len(start) == 0: if len(start) == 0:
@@ -421,6 +443,17 @@ class ProfileXYZ(Profile, SQLSubModel):
length += abs(s - e) length += abs(s - e)
return length return length
def wet_width(self, z):
if self.tab_up_to_date:
if z > self.tab.z[-1]:
return self.tab.L[-1]
elif z < self.tab.z[0]:
return 0.0
else:
return np.interp(z, self.tab.z, self.tab.L)
else:
return self.compute_wet_width(z)
def wet_perimeter(self, z): def wet_perimeter(self, z):
lines = self.wet_lines(z) lines = self.wet_lines(z)
@@ -432,17 +465,46 @@ class ProfileXYZ(Profile, SQLSubModel):
length += line.length length += line.length
return length return length
def wet_area(self, z): def compute_wet_area(self, z):
lines = self.wet_lines(z)
if lines is None:
return 0
area = 0.0 area = 0.0
for line in lines: if len(self.tab.L) > 0:
if len(line.coords) > 2: if z < self.tab.z[0]:
poly = geometry.Polygon(line) return 0.0
area += poly.area i = np.searchsorted([z], self.tab.z, side='right')[0]
for j in range(i-1):
area += (self.tab.L[j] + self.tab.L[j+1]) * (
self.tab.z[j+1] - self.tab.z[j]) / 2.0
area += (self.tab.L[i-1] + self.wet_width(z))
else:
lines = self.wet_lines(z)
if lines is None:
return 0.0
for line in lines:
if len(line.coords) > 2:
poly = geometry.Polygon(line)
area += poly.area
return area
def wet_area(self, z):
if self.tab_up_to_date:
if z > self.tab.z[-1]:
return self.tab.A[-1] + self.tab.L[-1] * (z - self.tab.z[-1])
elif z < self.tab.z[0]:
return 0.0
else:
return np.interp(z, self.tab.z, self.tab.A)
else:
lines = self.wet_lines(z)
if lines is None:
return 0.0
area = 0.0
for line in lines:
if len(line.coords) > 2:
poly = geometry.Polygon(line)
area += poly.area
return area return area
def wet_radius(self, z): def wet_radius(self, z):
@@ -563,7 +625,7 @@ class ProfileXYZ(Profile, SQLSubModel):
return None return None
zz = list(map(lambda p: p.z, points)) zz = list(map(lambda p: p.z, points))
station = self._get_station(points) station = self.get_station()
start = [] start = []
if points[0].z <= z: if points[0].z <= z:
@@ -651,6 +713,19 @@ class ProfileXYZ(Profile, SQLSubModel):
return pt_left, pt_right return pt_left, pt_right
def compute_tabulation(self):
sorted_points = sorted(self._points, key=lambda p: p.z)
self.tab.z = np.array([p.z for p in sorted_points], np.float64)
self.tab.L = np.zeros(len(self.tab.z), np.float64)
self.tab.A = np.zeros(len(self.tab.z), np.float64)
for i in range(1, len(self.tab.z)):
self.tab.L[i] = self.compute_wet_width(self.tab.z[i])
dx = (self.tab.L[i] + self.tab.L[i-1])/2
dz = self.tab.z[i] - self.tab.z[i-1]
self.tab.A[i] = self.tab.A[i-1] + dz * dx
self.tab_up_to_date = True
def get_station(self): def get_station(self):
"""Projection of the points of the profile on a plane. """Projection of the points of the profile on a plane.
@@ -663,7 +738,12 @@ class ProfileXYZ(Profile, SQLSubModel):
if self.nb_points < 2: if self.nb_points < 2:
return [0.0] return [0.0]
else: else:
return self._get_station(self.points) if self.station_up_to_date:
return self._station
else:
self._station = self._get_station(self.points)
self.station_up_to_date = True
return self._station
@timer @timer
def _get_station(self, points): def _get_station(self, points):
+15 -1
View File
@@ -128,7 +128,7 @@ class Pollutants(SQLSubModel):
if table is not None: if table is not None:
for t in table: for t in table:
new_data = t[1:] new_data = t[1:-1]
new_pollutant._data.append(new_data) new_pollutant._data.append(new_data)
@@ -177,5 +177,19 @@ class Pollutants(SQLSubModel):
def is_define(self): def is_define(self):
return len(self._data) != 0 return len(self._data) != 0
def new_from_data(self, data):
print("from_data before : ", data)
try:
new = [int(data[0])]
new += [float(d) for d in data[1:]]
except Exception as e:
logger.error(e)
new = None
print("from_data after : ", new)
return new
def __len__(self): def __len__(self):
return len(self._data) return len(self._data)
+3
View File
@@ -46,6 +46,9 @@ class Results(object):
el.split("/")[-1][0:-4] el.split("/")[-1][0:-4]
for el in glob.glob(repertory_results + "/*.bin") for el in glob.glob(repertory_results + "/*.bin")
] ]
self._pollutants_list.insert(0, self._pollutants_list.pop(
self._pollutants_list.index("total_sediment"))
)
self._phys_var_list = ["C", "G", "M", "D", "L", "N", "R"] self._phys_var_list = ["C", "G", "M", "D", "L", "N", "R"]
+21 -11
View File
@@ -410,10 +410,16 @@ class AdisTSwc(AdisTS):
def _export_ICs_AdisTS_Spec(self, study, pol_ics_spec_data, def _export_ICs_AdisTS_Spec(self, study, pol_ics_spec_data,
f, qlog, name="0"): f, qlog, name="0"):
edges = study.river.enable_edges()
for ic_spec in pol_ics_spec_data: for ic_spec in pol_ics_spec_data:
id_reach = ic_spec.reach
reach = next((x for x in edges if x.id == id_reach), None)
if reach is None:
continue
f.write(" ".join((f"{ic_spec.name}", f.write(" ".join((f"{ic_spec.name}",
"=", "=",
f"{ic_spec.reach}", f"{study.river.get_edge_id(reach)+1}",
f"{ic_spec.start_rk}", f"{ic_spec.start_rk}",
f"{ic_spec.end_rk}", f"{ic_spec.end_rk}",
f"{ic_spec.concentration}", f"{ic_spec.concentration}",
@@ -429,7 +435,7 @@ class AdisTSwc(AdisTS):
list_characteristics = ["type", "diametre", "rho", "porosity", list_characteristics = ["type", "diametre", "rho", "porosity",
"cdc_riv", "cdc_cas", "apd", "ac", "bc"] "cdc_riv", "cdc_cas", "apd", "ac", "bc"]
if len(list_characteristics) == (len(pol_data[0])-1): if len(list_characteristics) <= (len(pol_data[0])):
for i in range(len(list_characteristics)): for i in range(len(list_characteristics)):
f.write(f"{list_characteristics[i]} = {pol_data[0][i]}\n") f.write(f"{list_characteristics[i]} = {pol_data[0][i]}\n")
@@ -470,13 +476,14 @@ class AdisTSwc(AdisTS):
id_edges = list(map(lambda x: x.id, edges)) id_edges = list(map(lambda x: x.id, edges))
id_reach = d90_spec.reach id_reach = d90_spec.reach
reach = next((x for x in edges if x.id == id_reach), None)
if id_reach not in id_edges: if reach is None:
return return
f.write(" ".join((f"{d90_spec.name}", f.write(" ".join((f"{d90_spec.name}",
"=", "=",
f"{id_reach}", f"{study.river.get_edge_id(reach)+1}",
f"{d90_spec.start_rk}", f"{d90_spec.start_rk}",
f"{d90_spec.end_rk}", f"{d90_spec.end_rk}",
f"{d90_spec.d90}\n"))) f"{d90_spec.d90}\n")))
@@ -526,23 +533,22 @@ class AdisTSwc(AdisTS):
edges = study.river.enable_edges() edges = study.river.enable_edges()
id_edges = list(map(lambda x: x.id, edges))
id_reach = dif_spec.reach id_reach = dif_spec.reach
reach = next((x for x in edges if x.id == id_reach), None)
if id_reach not in id_edges: if reach is None:
return return
if dif_spec.method != "generique": if dif_spec.method != "generique":
f.write(" ".join((f"{dif_spec.method}", f.write(" ".join((f"{dif_spec.method}",
"=", "=",
f"{id_reach}", f"{study.river.get_edge_id(reach)+1}",
f"{dif_spec.start_rk}", f"{dif_spec.start_rk}",
f"{dif_spec.end_rk}", f"{dif_spec.end_rk}",
f"{dif_spec.dif}\n"))) f"{dif_spec.dif}\n")))
else: else:
f.write(" ".join((f"{dif_spec.method}", f.write(" ".join((f"{dif_spec.method}",
f"=" f"{id_reach}", f"=" f"{study.river.get_edge_id(reach)+1}",
f"{dif_spec.start_rk}", f"{dif_spec.start_rk}",
f"{dif_spec.end_rk}", f"{dif_spec.end_rk}",
f"{dif_spec.dif}", f"{dif_spec.dif}",
@@ -602,13 +608,14 @@ class AdisTSwc(AdisTS):
id_edges = list(map(lambda x: x.id, edges)) id_edges = list(map(lambda x: x.id, edges))
id_reach = outputrk.reach id_reach = outputrk.reach
reach = next((x for x in edges if x.id == id_reach), None)
rk = outputrk.rk rk = outputrk.rk
title = outputrk.title title = outputrk.title
if id_reach not in id_edges: if reach is None:
return return
f.write(f"output = {id_reach} {rk} {title}\n") f.write(f"output = {study.river.get_edge_id(reach)+1} {rk} {title}\n")
@timer @timer
def read_bin(self, study, repertory, results, qlog=None, name="0"): def read_bin(self, study, repertory, results, qlog=None, name="0"):
@@ -616,6 +623,9 @@ class AdisTSwc(AdisTS):
files_bin_names = [el.split("/")[-1] files_bin_names = [el.split("/")[-1]
for el in glob.glob(repertory_results+"/*.bin")] for el in glob.glob(repertory_results+"/*.bin")]
files_bin_names.insert(0, files_bin_names.pop(
files_bin_names.index("total_sediment.bin"))
)
print("files names resultats: ", files_bin_names) print("files names resultats: ", files_bin_names)
ifilename = os.path.join(repertory_results, files_bin_names[0]) ifilename = os.path.join(repertory_results, files_bin_names[0])
+17 -4
View File
@@ -1001,7 +1001,6 @@ class Mage8(Mage):
# Add profile id correspondance to reach # Add profile id correspondance to reach
key = (i1, i2) key = (i1, i2)
print("mage keys reachs: ", key)
iprofiles[key] = r iprofiles[key] = r
# Profile ID offset # Profile ID offset
@@ -1034,8 +1033,6 @@ class Mage8(Mage):
] ]
def ip_to_ri(r, i): return i - reach_offset[r] def ip_to_ri(r, i): return i - reach_offset[r]
print("mage iprofiles: ", iprofiles)
ts = set() ts = set()
end = False end = False
while not end: while not end:
@@ -1071,7 +1068,23 @@ class Mage8(Mage):
logger.debug(reachs[0].profiles[0]._data) logger.debug(reachs[0].profiles[0]._data)
results.set("timestamps", ts) results.set("timestamps", ts)
print("set timestamps mage: ", ts) ts_list = sorted(ts)
logger.info(f"compute tab...")
for r in reachs:
for p in r.profiles:
if not p.geometry.tab_up_to_date:
p.geometry.compute_tabulation()
logger.info(f"compute velocily...")
for r in reachs:
for t in ts_list:
for i, p in enumerate(r.profiles):
v = p.geometry.speed(
p.get_ts_key(t, "Q"),
p.get_ts_key(t, "Z")
)
r.set(i, t, "V", v)
logger.info(f"read_bin: ... end with {len(ts)} timestamp read") logger.info(f"read_bin: ... end with {len(ts)} timestamp read")
@timer @timer
+1 -1
View File
@@ -55,7 +55,7 @@ class AboutWindow(PamhyrDialog):
label = self.get_label_text("label_version") label = self.get_label_text("label_version")
label = label.replace("@version", version) label = label.replace("@version", version)
label = label.replace("@codename", "(Tahiti)") label = label.replace("@codename", "(Adis-TS)")
self.set_label_text("label_version", label) self.set_label_text("label_version", label)
# Authors # Authors
@@ -88,13 +88,13 @@ class EditBoundaryConditionWindow(PamhyrWindow):
self.setup_connections() self.setup_connections()
def setup_table(self): def setup_table(self):
table_headers = self._trad.get_dict("table_headers")
if self._data.type == "Concentration": if self._data.type == "Concentration":
self._data.header = ["time", "concentration"] self._data.header = ["time", "concentration"]
else: else:
self._data.header = ["time", "rate"] self._data.header = ["time", "mass"]
headers = {} headers = {}
table_headers = self._trad.get_dict("table_headers")
for h in self._data.header: for h in self._data.header:
headers[h] = table_headers[h] headers[h] = table_headers[h]
@@ -30,13 +30,13 @@ class BCETranslate(BCTranslate):
super(BCETranslate, self).__init__() super(BCETranslate, self).__init__()
self._dict["Edit Boundary Conditions AdisTS"] = _translate( self._dict["Edit Boundary Conditions AdisTS"] = _translate(
"BoundaryConditionAdisTS", "Edit boundary conditions AdisTS" "BoundaryConditionsAdisTS", "Edit boundary conditions AdisTS"
) )
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"time": self._dict["time"], "time": self._dict["time"],
"date": self._dict["date"], "date": self._dict["date"],
"rate": _translate("BoundaryConditionAdisTS", "Rate"), "mass": _translate("BoundaryConditionsAdisTS", "Mass"),
"concentration": _translate("BoundaryConditionAdisTS", "concentration": _translate("BoundaryConditionsAdisTS",
"Concentration"), "Concentration"),
} }
+15 -7
View File
@@ -70,7 +70,7 @@ class ComboBoxDelegate(QItemDelegate):
self.editor = QComboBox(parent) self.editor = QComboBox(parent)
if self._mode == "type": if self._mode == "type":
lst = [self._trad["not_associated"], "Concentration", "Rate"] lst = [self._trad["not_associated"], "Concentration", "Mass"]
self.editor.addItems( self.editor.addItems(
lst lst
) )
@@ -181,13 +181,21 @@ class TableModel(PamhyrTableModel):
) )
) )
elif self._headers[column] == "pol": elif self._headers[column] == "pol":
pol = next(filter(lambda x: x.name == value, if value == self._trad["not_associated"]:
self._data._Pollutants.Pollutants_List)) self._undo.push(
self._undo.push( SetPolCommand(
SetPolCommand( self._lst, row, None
self._lst, row, pol.id )
)
else:
pol = next(filter(lambda x: x.name == value,
self._data._Pollutants.Pollutants_List)
)
self._undo.push(
SetPolCommand(
self._lst, row, pol.id
)
) )
)
except Exception as e: except Exception as e:
logger.info(e) logger.info(e)
logger.debug(traceback.format_exc()) logger.debug(traceback.format_exc())
@@ -68,9 +68,8 @@ class SetPolCommand(QUndoCommand):
self._bcs = bcs self._bcs = bcs
self._index = index self._index = index
self._pollutant = pollutant
self._old = self._bcs[self._index].pollutant self._old = self._bcs[self._index].pollutant
self._new = self._pollutant self._new = pollutant
def undo(self): def undo(self):
self._bcs[self._index].pollutant = self._old self._bcs[self._index].pollutant = self._old
+1 -6
View File
@@ -74,7 +74,6 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
) )
self._pollutants_lst = self._study._river._Pollutants self._pollutants_lst = self._study._river._Pollutants
self._bcs = self._study.river.boundary_conditions_adists self._bcs = self._study.river.boundary_conditions_adists
self.setup_graph() self.setup_graph()
@@ -157,11 +156,7 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
) )
def add(self): def add(self):
rows = self.index_selected_rows() self._table.add(len(self._bcs))
if len(self._bcs) == 0 or len(rows) == 0:
self._table.add(0)
else:
self._table.add(rows[0])
def delete(self): def delete(self):
rows = self.index_selected_rows() rows = self.index_selected_rows()
-1
View File
@@ -187,7 +187,6 @@ class DIFTableModel(PamhyrTableModel):
) )
) )
elif self._headers[column] == "reach": elif self._headers[column] == "reach":
print(self._river.edge(value).id)
self._undo.push( self._undo.push(
SetCommandSpec( SetCommandSpec(
self._lst, self._lst,
-2
View File
@@ -287,9 +287,7 @@ class DIFAdisTSWindow(PamhyrWindow):
self._table_spec.add(rows[0]) self._table_spec.add(rows[0])
def delete(self): def delete(self):
print("del")
rows = self.index_selected_rows() rows = self.index_selected_rows()
if len(rows) == 0: if len(rows) == 0:
print("len 0")
return return
self._table_spec.delete(rows) self._table_spec.delete(rows)
@@ -28,7 +28,7 @@ class LCTranslate(MainTranslate):
super(LCTranslate, self).__init__() super(LCTranslate, self).__init__()
self._dict["Lateral contribution AdisTS"] = _translate( self._dict["Lateral contribution AdisTS"] = _translate(
"LateralContribution1adisTS", "Lateral contribution AdisTS" "LateralContributionAdisTS", "Lateral contribution AdisTS"
) )
self._sub_dict["long_types"] = { self._sub_dict["long_types"] = {
+13 -6
View File
@@ -29,6 +29,7 @@ from numpy.core.multiarray import where
from platformdirs import user_cache_dir from platformdirs import user_cache_dir
from Solver.AdisTS import AdisTS from Solver.AdisTS import AdisTS
from Solver.Mage import Mage8
from tools import logger_exception from tools import logger_exception
from PyQt5 import QtGui from PyQt5 import QtGui
@@ -185,10 +186,10 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
title = "(dbg) " if self.conf.debug else "" title = "(dbg) " if self.conf.debug else ""
if self._study is not None: if self._study is not None:
title += f"Pamhyr2 (Tahiti 🌴) - {self._study.name}" title += f"Pamhyr2 - {self._study.name}"
self.setWindowTitle(title) self.setWindowTitle(title)
else: else:
title += "Pamhyr2 (Tahiti 🌴)" title += "Pamhyr2"
self.setWindowTitle(title) self.setWindowTitle(title)
def setup_tab(self): def setup_tab(self):
@@ -785,14 +786,16 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
dlg.setWindowTitle(self._trad["mb_last_open_title"]) dlg.setWindowTitle(self._trad["mb_last_open_title"])
dlg.setText(self._trad["mb_last_open_msg"]) dlg.setText(self._trad["mb_last_open_msg"])
opt = QMessageBox.Cancel | QMessageBox.Ok # | QMessageBox.Open opt = QMessageBox.No | QMessageBox.Yes # | QMessageBox.Open
dlg.setStandardButtons(opt) dlg.setStandardButtons(opt)
dlg.setIcon(QMessageBox.Question) dlg.setIcon(QMessageBox.Question)
dlg.button(QMessageBox.Yes).setText(self._trad["Yes"])
dlg.button(QMessageBox.No).setText(self._trad["No"])
res = dlg.exec() res = dlg.exec()
if res == QMessageBox.Ok: if res == QMessageBox.Yes:
old = self.conf.last_study old = self.conf.last_study
file = self.dialog_reopen_study_select_backup( file = self.dialog_reopen_study_select_backup(
self.conf.last_study self.conf.last_study
@@ -805,7 +808,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
elif res == QMessageBox.Open: elif res == QMessageBox.Open:
self.open_model() self.open_model()
return True return True
elif res == QMessageBox.Cancel: elif res == QMessageBox.No:
return False return False
def dialog_reopen_study_select_backup(self, filename): def dialog_reopen_study_select_backup(self, filename):
@@ -832,6 +835,10 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
dlg.setStandardButtons(opt) dlg.setStandardButtons(opt)
dlg.setIcon(QMessageBox.Warning) dlg.setIcon(QMessageBox.Warning)
dlg.button(QMessageBox.Save).setText(self._trad["Save"])
dlg.button(QMessageBox.Close).setText(self._trad["Close"])
if cancel:
dlg.button(QMessageBox.Cancel).setText(self._trad["Cancel"])
res = dlg.exec() res = dlg.exec()
@@ -1544,7 +1551,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
file_name = dialog.selectedFiles() file_name = dialog.selectedFiles()
logger.info(f"Select results: {file_name}") logger.info(f"Select results: {file_name}")
self.open_solver_results( self.open_solver_results(
self._last_solver, Mage8("Mage"),
results=file_name[0] results=file_name[0]
) )
+7 -10
View File
@@ -90,17 +90,14 @@ class TableModel(PamhyrTableModel):
self.layoutAboutToBeChanged.emit() self.layoutAboutToBeChanged.emit()
self._undo.push( self._undo.push(PasteCommand(self._data, row,
PasteCommand( list(
self._data, row, map(
list( lambda d: self._data.new_from_data(d),
map( data
lambda d: self._data.new_from_data(d), )
data )
)
)
) )
) )
self.layoutAboutToBeChanged.emit()
self.layoutChanged.emit() self.layoutChanged.emit()
+1 -1
View File
@@ -35,7 +35,7 @@ class EditPollutantTranslate(PollutantsTranslate):
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"type": self._dict["type"], "type": self._dict["type"],
"diametre": self._dict["unit_area"], "diameter": self._dict["unit_diameter"],
"rho": self._dict["unit_rho"], "rho": self._dict["unit_rho"],
"porosity": self._dict["unit_porosity"], "porosity": self._dict["unit_porosity"],
"cdc_riv": self._dict["unit_cdc_riv"], "cdc_riv": self._dict["unit_cdc_riv"],
+24 -25
View File
@@ -31,36 +31,35 @@ logger = logging.getLogger()
class SetDataCommand(QUndoCommand): class SetDataCommand(QUndoCommand):
def __init__(self, data, index, column, new_value): def __init__(self, data, row, column, new_value):
QUndoCommand.__init__(self)
self._data = data
self._index = index
self._column = column
self._old = self._data.data[self._index][self._column]
self._new = new_value
def undo(self):
self._data.data[self._index][self._column] = self._old
def redo(self):
self._data.data[self._index][self._column] = self._new
class PasteCommand(QUndoCommand):
def __init__(self, data, row, hs):
QUndoCommand.__init__(self) QUndoCommand.__init__(self)
self._data = data self._data = data
self._row = row self._row = row
self._h = hs self._column = column
self._h.reverse() self._old = self._data.data[self._row][self._column]
self._new = new_value
def undo(self): def undo(self):
self._data.delete_i( self._data.data[self._row][self._column] = self._old
range(self._row, self._row + len(self._h))
)
def redo(self): def redo(self):
for h in self._h: self._data.data[self._row][self._column] = self._new
self._data.insert(self._row, h)
class PasteCommand(QUndoCommand):
def __init__(self, data, row, new_data):
QUndoCommand.__init__(self)
self._data = data
self._row = row
self._new = [n for n in new_data[row]]
self._old = [o for o in self._data.data[row]]
def undo(self):
for i in range(9):
self._data.data[self._row][i] = self._old[i]
def redo(self):
for i in range(9):
self._data.data[self._row][i] = self._new[i]
+1 -1
View File
@@ -129,7 +129,7 @@ class EditPolluantWindow(PamhyrWindow):
def _paste(self): def _paste(self):
header, data = self.parseClipboardTable() header, data = self.parseClipboardTable()
logger.debug(f"paste: h:{header}, d:{data}") logger.debug(f"paste: header:{header}, data:{data}")
if len(data) == 0: if len(data) == 0:
return return
+1 -1
View File
@@ -103,7 +103,7 @@ class TableModel(PamhyrTableModel):
self._undo.push( self._undo.push(
DelCommand( DelCommand(
self._lst, rows, self._data.initial_conditions_adists self._lst, rows, self._data.ic_adists
) )
) )
+11 -12
View File
@@ -105,6 +105,7 @@ class PollutantsWindow(PamhyrWindow):
def setup_connections(self): def setup_connections(self):
self.find(QAction, "action_add").triggered.connect(self.add) self.find(QAction, "action_add").triggered.connect(self.add)
self.find(QAction, "action_delete").setEnabled(False)
self.find(QAction, "action_delete").triggered.connect(self.delete) self.find(QAction, "action_delete").triggered.connect(self.delete)
self.find(QAction, "action_edit").triggered.connect(self.edit) self.find(QAction, "action_edit").triggered.connect(self.edit)
self.find(QAction, "action_initial_conditions" self.find(QAction, "action_initial_conditions"
@@ -154,11 +155,7 @@ class PollutantsWindow(PamhyrWindow):
) )
def add(self): def add(self):
rows = self.index_selected_rows() self._table.add(len(self._pollutants_lst))
if len(self._pollutants_lst) == 0 or len(rows) == 0:
self._table.add(0)
else:
self._table.add(rows[-1])
def delete(self): def delete(self):
rows = self.index_selected_rows() rows = self.index_selected_rows()
@@ -181,6 +178,9 @@ class PollutantsWindow(PamhyrWindow):
def edit(self): def edit(self):
rows = self.index_selected_rows() rows = self.index_selected_rows()
if len(rows) == 0:
return
for row in rows: for row in rows:
data = self._pollutants_lst.get(row) data = self._pollutants_lst.get(row)
@@ -199,6 +199,8 @@ class PollutantsWindow(PamhyrWindow):
def initial_conditions(self): def initial_conditions(self):
rows = self.index_selected_rows() rows = self.index_selected_rows()
if len(rows) == 0:
return
for row in rows: for row in rows:
pollutant_id = self._pollutants_lst.get(row).id pollutant_id = self._pollutants_lst.get(row).id
@@ -219,11 +221,7 @@ class PollutantsWindow(PamhyrWindow):
) )
initial.show() initial.show()
def boundary_conditions(self, tab=0): def boundary_conditions(self):
rows = self.index_selected_rows()
for row in rows:
pollutant_id = self._pollutants_lst.get(row).id
if self.sub_window_exists( if self.sub_window_exists(
BoundaryConditionAdisTSWindow, BoundaryConditionAdisTSWindow,
@@ -242,9 +240,10 @@ class PollutantsWindow(PamhyrWindow):
def lateral_contrib(self): def lateral_contrib(self):
rows = self.index_selected_rows() rows = self.index_selected_rows()
if len(rows) == 0:
return
for row in rows: pollutant_id = self._pollutants_lst.get(rows[0]).id
pollutant_id = self._pollutants_lst.get(row).id
if self.sub_window_exists( if self.sub_window_exists(
LateralContributionAdisTSWindow, LateralContributionAdisTSWindow,
+27 -47
View File
@@ -187,6 +187,12 @@ class CustomPlot(PamhyrPlot):
reach.profiles reach.profiles
) )
) )
v = list(
map(
lambda p: p.get_ts_key(self._timestamp, "V"),
reach.profiles
)
)
shift = 0 shift = 0
compt = 0 compt = 0
@@ -327,14 +333,6 @@ class CustomPlot(PamhyrPlot):
if "velocity" in self._y: if "velocity" in self._y:
ax = self._axes[unit["velocity"]] ax = self._axes[unit["velocity"]]
v = list(
map(
lambda p: p.geometry.speed(
p.get_ts_key(self._timestamp, "Q"),
p.get_ts_key(self._timestamp, "Z")),
reach.profiles
)
)
line = ax.plot( line = ax.plot(
rk, v, lw=1., rk, v, lw=1.,
@@ -344,12 +342,10 @@ class CustomPlot(PamhyrPlot):
if self._envelop: if self._envelop:
velocities = list(map( velocities = list(
lambda p: list(map( map(
lambda q, z: lambda p: p.get_key("V"),
p.geometry.speed(q, z), reach.profiles
p.get_key("Q"), p.get_key("Z")
)), reach.profiles
) )
) )
@@ -440,9 +436,7 @@ class CustomPlot(PamhyrPlot):
fr = list( fr = list(
map( map(
lambda p: lambda p:
p.geometry.speed( p.get_ts_key(self._timestamp, "V") /
p.get_ts_key(self._timestamp, "Q"),
p.get_ts_key(self._timestamp, "Z")) /
sqrt(9.81 * ( sqrt(9.81 * (
p.geometry.wet_area( p.geometry.wet_area(
p.get_ts_key(self._timestamp, "Z")) / p.get_ts_key(self._timestamp, "Z")) /
@@ -506,6 +500,12 @@ class CustomPlot(PamhyrPlot):
reach.profiles reach.profiles
) )
) )
v = list(
map(
lambda p: p.get_ts_key(self._timestamp, "V"),
reach.profiles
)
)
if "bed_elevation" in self._y: if "bed_elevation" in self._y:
self.lines["bed_elevation"][0].set_ydata(z_min) self.lines["bed_elevation"][0].set_ydata(z_min)
@@ -524,15 +524,7 @@ class CustomPlot(PamhyrPlot):
self.lines["discharge"][0].set_ydata(q) self.lines["discharge"][0].set_ydata(q)
if "velocity" in self._y: if "velocity" in self._y:
v = list( self.lines["velocity"][0].set_ydata(v)
map(
lambda p: p.geometry.speed(
p.get_ts_key(self._timestamp, "Q"),
p.get_ts_key(self._timestamp, "Z")),
reach.profiles
)
)
self.lines["discharge"][0].set_ydata(v)
if "depth" in self._y: if "depth" in self._y:
d = list( d = list(
@@ -558,9 +550,7 @@ class CustomPlot(PamhyrPlot):
fr = list( fr = list(
map( map(
lambda p: lambda p:
p.geometry.speed( p.get_ts_key(self._timestamp, "V") /
p.get_ts_key(self._timestamp, "Q"),
p.get_ts_key(self._timestamp, "Z")) /
sqrt(9.81 * ( sqrt(9.81 * (
p.geometry.wet_area( p.geometry.wet_area(
p.get_ts_key(self._timestamp, "Z")) / p.get_ts_key(self._timestamp, "Z")) /
@@ -642,6 +632,7 @@ class CustomPlot(PamhyrPlot):
q = profile.get_key("Q") q = profile.get_key("Q")
z = profile.get_key("Z") z = profile.get_key("Z")
v = profile.get_key("V")
z_min = profile.geometry.z_min() z_min = profile.geometry.z_min()
if reach.has_sediment(): if reach.has_sediment():
ts_z_min = self.get_ts_zmin(self._profile) ts_z_min = self.get_ts_zmin(self._profile)
@@ -693,12 +684,6 @@ class CustomPlot(PamhyrPlot):
if "velocity" in self._y: if "velocity" in self._y:
ax = self._axes[unit["velocity"]] ax = self._axes[unit["velocity"]]
v = list(
map(
lambda q, z: profile.geometry.speed(q, z),
q, z
)
)
line = ax.plot( line = ax.plot(
ts, v, lw=1., ts, v, lw=1.,
@@ -736,12 +721,12 @@ class CustomPlot(PamhyrPlot):
ax = self._axes[unit["froude"]] ax = self._axes[unit["froude"]]
d = list( d = list(
map(lambda z, q: map(lambda z, v:
profile.geometry.speed(q, z) / v /
sqrt(9.81 * ( sqrt(9.81 * (
profile.geometry.wet_area(z) / profile.geometry.wet_area(z) /
profile.geometry.wet_width(z)) profile.geometry.wet_width(z))
), z, q) ), z, v)
) )
line = ax.plot( line = ax.plot(
@@ -782,6 +767,7 @@ class CustomPlot(PamhyrPlot):
q = profile.get_key("Q") q = profile.get_key("Q")
z = profile.get_key("Z") z = profile.get_key("Z")
v = profile.get_key("V")
if reach.has_sediment(): if reach.has_sediment():
ts_z_min = self.get_ts_zmin(self._profile) ts_z_min = self.get_ts_zmin(self._profile)
else: else:
@@ -810,12 +796,6 @@ class CustomPlot(PamhyrPlot):
self.lines["discharge"][0].set_ydata(q) self.lines["discharge"][0].set_ydata(q)
if "velocity" in self._y: if "velocity" in self._y:
v = list(
map(
lambda q, z: profile.geometry.speed(q, z),
q, z
)
)
self.lines["velocity"][0].set_ydata(v) self.lines["velocity"][0].set_ydata(v)
if "depth" in self._y: if "depth" in self._y:
@@ -832,12 +812,12 @@ class CustomPlot(PamhyrPlot):
if "froude" in self._y: if "froude" in self._y:
d = list( d = list(
map(lambda z, q: map(lambda z, v:
profile.geometry.speed(q, z) / v /
sqrt(9.81 * ( sqrt(9.81 * (
profile.geometry.wet_area(z) / profile.geometry.wet_area(z) /
profile.geometry.wet_width(z)) profile.geometry.wet_width(z))
), z, q) ), z, v)
) )
self.lines["froude"][0].set_ydata(d) self.lines["froude"][0].set_ydata(d)
+1
View File
@@ -309,6 +309,7 @@ class PlotAdis_dt(PlotAdis):
type_pol=type_pol, type_pol=type_pol,
parent=parent parent=parent
) )
self.label_x = self._trad["unit_time_s"]
def draw_data(self): def draw_data(self):
reach = self.results.river.reach(self._current_reach_id) reach = self.results.river.reach(self._current_reach_id)
+2 -6
View File
@@ -47,12 +47,8 @@ _translate = QCoreApplication.translate
class TableModel(PamhyrTableModel): class TableModel(PamhyrTableModel):
def _setup_lst(self): def _setup_lst(self):
_river = self._data.river _river = self._data.river
print("data: ", self._data)
print("river: ", _river)
print("reaches: ", _river.reachs)
if self._opt_data == "reach": if self._opt_data == "reach":
self._lst = _river.reachs self._lst = _river.reachs
print("optreach: ", self._lst)
elif self._opt_data == "profile": elif self._opt_data == "profile":
self._lst = _river.reach(0).profiles self._lst = _river.reach(0).profiles
elif self._opt_data == "raw_data": elif self._opt_data == "raw_data":
@@ -95,7 +91,7 @@ class TableModel(PamhyrTableModel):
elif self._headers[column] == "velocity": elif self._headers[column] == "velocity":
q = self._lst[row].get_ts_key(self._timestamp, "Q") q = self._lst[row].get_ts_key(self._timestamp, "Q")
z = self._lst[row].get_ts_key(self._timestamp, "Z") z = self._lst[row].get_ts_key(self._timestamp, "Z")
v = self._lst[row].geometry.speed(q, z) v = self._lst[row].get_ts_key(self._timestamp, "V")
return f"{v:.4f}" return f"{v:.4f}"
elif self._headers[column] == "width": elif self._headers[column] == "width":
z = self._lst[row].get_ts_key(self._timestamp, "Z") z = self._lst[row].get_ts_key(self._timestamp, "Z")
@@ -124,7 +120,7 @@ class TableModel(PamhyrTableModel):
elif self._headers[column] == "froude": elif self._headers[column] == "froude":
q = self._lst[row].get_ts_key(self._timestamp, "Q") q = self._lst[row].get_ts_key(self._timestamp, "Q")
z = self._lst[row].get_ts_key(self._timestamp, "Z") z = self._lst[row].get_ts_key(self._timestamp, "Z")
v = self._lst[row].geometry.speed(q, z) v = self._lst[row].get_ts_key(self._timestamp, "V")
a = self._lst[row].geometry.wet_area(z) a = self._lst[row].geometry.wet_area(z)
b = self._lst[row].geometry.wet_width(z) b = self._lst[row].geometry.wet_width(z)
froude = v / sqrt(9.81 * (a / b)) froude = v / sqrt(9.81 * (a / b))
+10 -22
View File
@@ -730,21 +730,16 @@ class ResultsWindow(PamhyrWindow):
if "velocity" in y: if "velocity" in y:
my_dict[dict_y["velocity"]] = list( my_dict[dict_y["velocity"]] = list(
map( map(
lambda p: p.geometry.speed( lambda p: p.get_ts_key(timestamp, "V"),
p.get_ts_key(timestamp, "Q"),
p.get_ts_key(timestamp, "Z")),
reach.profiles reach.profiles
) )
) )
if envelop: if envelop:
velocities = list(map( velocities = list(map(
lambda p: list(map( lambda p: p.get_key("V"),
lambda q, z: reach.profiles
p.geometry.speed(q, z), )
p.get_key("Q"), p.get_key("Z")
)), reach.profiles
) )
)
my_dict[dict_y["min_velocity"]] = [min(v) for v in velocities] my_dict[dict_y["min_velocity"]] = [min(v) for v in velocities]
my_dict[dict_y["max_velocity"]] = [max(v) for v in velocities] my_dict[dict_y["max_velocity"]] = [max(v) for v in velocities]
@@ -784,9 +779,7 @@ class ResultsWindow(PamhyrWindow):
my_dict[dict_y["froude"]] = list( my_dict[dict_y["froude"]] = list(
map( map(
lambda p: lambda p:
p.geometry.speed( p.get_ts_key(timestamp, "V") /
p.get_ts_key(timestamp, "Q"),
p.get_ts_key(timestamp, "Z")) /
sqrt(9.81 * ( sqrt(9.81 * (
p.geometry.wet_area( p.geometry.wet_area(
p.get_ts_key(timestamp, "Z")) / p.get_ts_key(timestamp, "Z")) /
@@ -818,6 +811,7 @@ class ResultsWindow(PamhyrWindow):
my_dict[dict_x["time"]] = ts my_dict[dict_x["time"]] = ts
z = profile.get_key("Z") z = profile.get_key("Z")
q = profile.get_key("Q") q = profile.get_key("Q")
v = profile.get_key("V")
if "bed_elevation" in y: if "bed_elevation" in y:
my_dict[dict_y["bed_elevation"]] = [ my_dict[dict_y["bed_elevation"]] = [
profile.geometry.z_min()] * len(ts) profile.geometry.z_min()] * len(ts)
@@ -826,12 +820,7 @@ class ResultsWindow(PamhyrWindow):
if "water_elevation" in y: if "water_elevation" in y:
my_dict[dict_y["water_elevation"]] = z my_dict[dict_y["water_elevation"]] = z
if "velocity" in y: if "velocity" in y:
my_dict[dict_y["velocity"]] = list( my_dict[dict_y["velocity"]] = v
map(
lambda q, z: profile.geometry.speed(q, z),
q, z
)
)
if "depth" in y: if "depth" in y:
my_dict[dict_y["depth"]] = list( my_dict[dict_y["depth"]] = list(
map(lambda z: profile.geometry.max_water_depth(z), z) map(lambda z: profile.geometry.max_water_depth(z), z)
@@ -842,12 +831,11 @@ class ResultsWindow(PamhyrWindow):
) )
if "froude" in y: if "froude" in y:
my_dict[dict_y["froude"]] = list( my_dict[dict_y["froude"]] = list(
map(lambda z, q: map(lambda z, v:
profile.geometry.speed(q, z) / v / sqrt(9.81 * (
sqrt(9.81 * (
profile.geometry.wet_area(z) / profile.geometry.wet_area(z) /
profile.geometry.wet_width(z)) profile.geometry.wet_width(z))
), z, q) ), z, v)
) )
if "wet_area" in y: if "wet_area" in y:
my_dict[dict_y["wet_area"]] = list( my_dict[dict_y["wet_area"]] = list(
+7 -5
View File
@@ -78,6 +78,7 @@ class ResultsWindowAdisTS(PamhyrWindow):
parent=None): parent=None):
self._solver = solver self._solver = solver
self._results = results self._results = results
self.pollutant_label = ["None"]
pollutants_headers = self._results.pollutants_list.copy() pollutants_headers = self._results.pollutants_list.copy()
@@ -374,14 +375,15 @@ class ResultsWindowAdisTS(PamhyrWindow):
# Pollutant # Pollutant
table = self.find(QTableView, f"tableView_pollutants") table = self.find(QTableView, f"tableView_pollutants")
indexes = table.selectedIndexes() indexes = table.selectedIndexes()
if len(indexes) == 0: if len(indexes) != 0:
pollutant = self._results.pollutants_list[0] self.pollutant_label = [
else: self._results.pollutants_list[i.row()+1] for i in indexes
pollutant = self._results.pollutants_list[indexes[0].row()] ]
return (f"Reach: {reach.name} | " + return (f"Reach: {reach.name} | " +
f"Profile: {pname} | " + f"Profile: {pname} | " +
f"Pollutant: {pollutant}") f"Pollutant: {', '.join(self.pollutant_label)} | " +
f"{self._trad['unit_time_s']} : {fts} ({ts} sec)")
def setup_statusbar(self): def setup_statusbar(self):
txt = self._compute_status_label() txt = self._compute_status_label()
+5
View File
@@ -201,3 +201,8 @@ class MainTranslate(UnitTranslate):
) )
self._dict["x"] = _translate("MainWindow", "X (m)") self._dict["x"] = _translate("MainWindow", "X (m)")
self._dict["y"] = _translate("MainWindow", "Y (m)") self._dict["y"] = _translate("MainWindow", "Y (m)")
self._dict["Yes"] = _translate("MainWindow", "Yes")
self._dict["No"] = _translate("MainWindow", "No")
self._dict["Cancel"] = _translate("MainWindow", "Cancel")
self._dict["Save"] = _translate("MainWindow", "Save")
self._dict["Close"] = _translate("MainWindow", "Close")
+759 -148
View File
File diff suppressed because it is too large. Load diff