mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71914fdf57 | ||
|
|
2d7409debb | ||
|
|
92fb653676 |
No files matched your search
@@ -1,5 +1,5 @@
|
||||
# translate.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
# Adists.py -- Pamhyr study checkers
|
||||
# Copyright (C) 2023-2026 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
|
||||
@@ -16,25 +16,37 @@
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import time
|
||||
import logging
|
||||
from functools import reduce
|
||||
|
||||
from PyQt5.QtCore import QCoreApplication
|
||||
|
||||
from View.Translate import MainTranslate
|
||||
from Modules import Modules
|
||||
from Checker.Checker import AbstractModelChecker, STATUS
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
class BCTemperatureTranslate(MainTranslate):
|
||||
|
||||
class AdistsOutputRKChecker(AbstractModelChecker):
|
||||
def __init__(self):
|
||||
super(BCTemperatureTranslate, self).__init__()
|
||||
super(AdistsOutputRKChecker, self).__init__()
|
||||
|
||||
self._dict["Boundary conditions temperature"] = _translate(
|
||||
"BoundaryConditionsTemperature", "Boundary conditions temperature"
|
||||
)
|
||||
self._dict["default"] = _translate(
|
||||
"BoundaryConditionsTemperature", "default"
|
||||
self._name = _translate("Checker", "AdisTS output RK checker")
|
||||
self._description = _translate(
|
||||
"Checker", "Check output RK"
|
||||
)
|
||||
self._modules = Modules.OUTPUT_RK
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
"name": self._dict["name"],
|
||||
"node": _translate("BoundaryCondition", "Node"),
|
||||
}
|
||||
def run(self, study):
|
||||
ok = True
|
||||
nerror = 0
|
||||
self._summary = "ok"
|
||||
self._status = STATUS.OK
|
||||
|
||||
if not self.basic_check(study):
|
||||
return False
|
||||
|
||||
return ok
|
||||
+2
-5
@@ -229,11 +229,7 @@ for each reach"
|
||||
gls = []
|
||||
|
||||
for edge in edges:
|
||||
profiles = edge.reach.enabled_profiles
|
||||
comp, incomp = edge.reach.compute_guidelines(
|
||||
profiles=profiles,
|
||||
update_cache=False
|
||||
)
|
||||
comp, incomp = edge.reach.compute_guidelines()
|
||||
if len(incomp) != 0:
|
||||
self._status = STATUS.WARNING
|
||||
self._summary = "incomplete_guideline"
|
||||
@@ -241,6 +237,7 @@ for each reach"
|
||||
|
||||
gls.append(comp)
|
||||
|
||||
profiles = edge.reach.profiles
|
||||
for profile in profiles:
|
||||
if not profile.has_standard_named_points():
|
||||
self._status = STATUS.WARNING
|
||||
|
||||
@@ -87,7 +87,7 @@ class StudyGeometryChecker(AbstractModelChecker):
|
||||
return False
|
||||
|
||||
for edge in edges:
|
||||
if len(edge.reach.enabled_profiles) < 2:
|
||||
if len(edge.reach.profiles) < 2:
|
||||
summary = "no_geometry_defined"
|
||||
status = STATUS.ERROR
|
||||
ok = False
|
||||
@@ -132,12 +132,8 @@ class StudyInitialConditionsChecker(AbstractModelChecker):
|
||||
return ok
|
||||
|
||||
ic = river.initial_conditions[reach]
|
||||
enabled_profiles = set(reach.enabled_profiles)
|
||||
len_ic = sum(
|
||||
data["section"] in enabled_profiles
|
||||
for data in ic.data
|
||||
)
|
||||
len_reach = len(enabled_profiles)
|
||||
len_ic = len(ic)
|
||||
len_reach = len(reach)
|
||||
|
||||
if len_ic < len_reach:
|
||||
self._summary = "initial_condition_missing_profile"
|
||||
|
||||
@@ -1,478 +0,0 @@
|
||||
# BoundaryConditionsTemperature.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from tools import (
|
||||
trace, timer,
|
||||
old_pamhyr_date_to_timestamp,
|
||||
date_iso_to_timestamp,
|
||||
date_dmy_to_timestamp,
|
||||
)
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Data(SQLSubModel):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self,
|
||||
data0, data1,
|
||||
id: int = -1,
|
||||
types=[float, float],
|
||||
status=None,
|
||||
owner_scenario=-1):
|
||||
super(Data, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._types = types
|
||||
self._data = [data0, data1]
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE boundary_condition_data_temperature{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
data0 TEXT NOT NULL,
|
||||
data1 TEXT NOT NULL,
|
||||
bca INTEGER,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(bca)
|
||||
REFERENCES boundary_condition_temperature(pamhyr_id)
|
||||
)
|
||||
""")
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
if major == "0" and minor == "0":
|
||||
if int(release) < 11:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if major == "0" and (int(minor) < 2 or
|
||||
(int(minor) == 2 and int(release) < 7)):
|
||||
if not cls.is_table_exists(execute,
|
||||
"boundary_condition_data_temperature"):
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if not created:
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
bca = data["bca"]
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, data0, data1, scenario FROM " +
|
||||
"boundary_condition_data_temperature " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
# f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
|
||||
f"AND bca = {bca.id}"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
deleted = (next(it) == 1)
|
||||
data0 = next(it)
|
||||
data1 = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
bc = cls(
|
||||
data0, data1,
|
||||
id=pid,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
bc.set_as_deleted()
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(bc)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
bca = data["bca"]
|
||||
|
||||
data0 = self._db_format(self._data[0])
|
||||
data1 = self._db_format(self._data[1])
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"boundary_condition_data_temperature(" +
|
||||
"pamhyr_id, deleted, data0, data1, bca, scenario) " +
|
||||
f"VALUES ({self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"'{data0}', {data1}, {bca.id}, " +
|
||||
f"{self._status.scenario_id})"
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self._types[key](self._data[key])
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
self._data[key] = self._types[key](value)
|
||||
|
||||
|
||||
class BoundaryConditionTemperature(SQLSubModel):
|
||||
_sub_classes = [Data]
|
||||
|
||||
def __init__(self, id: int = -1, status=None, owner_scenario=-1):
|
||||
super(BoundaryConditionTemperature, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._status = status
|
||||
|
||||
self._name = ""
|
||||
self._node = None
|
||||
self._data = []
|
||||
self._header = []
|
||||
self._types = [self.time_convert, float]
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE boundary_condition_temperature{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
name TEXT NOT NULL,
|
||||
node INTEGER,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(node) REFERENCES river_node(pamhyr_id)
|
||||
)
|
||||
""")
|
||||
|
||||
if ext != "":
|
||||
return True
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and (int(minor) < 2 or (
|
||||
int(minor) == 2 and int(release) < 7)):
|
||||
if not cls.is_table_exists(execute,
|
||||
"boundary_condition_temperature"):
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if not created:
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
nodes = data['nodes']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
sql = (
|
||||
"SELECT pamhyr_id, deleted, name, node, scenario "
|
||||
"FROM boundary_condition_temperature " +
|
||||
f"WHERE scenario = {scenario.id} "
|
||||
)
|
||||
|
||||
table = execute(sql)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
deleted = (next(it) == 1)
|
||||
bc_name = next(it)
|
||||
node = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
bc = cls(
|
||||
id=pid,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
bc.set_as_deleted()
|
||||
|
||||
bc.name = bc_name
|
||||
|
||||
bc.node = None
|
||||
if node != -1:
|
||||
tmp = next(
|
||||
filter(
|
||||
lambda n: n.id == node, nodes
|
||||
),
|
||||
None
|
||||
)
|
||||
if tmp is not None:
|
||||
bc.node = tmp.id
|
||||
else:
|
||||
bc.node = -1
|
||||
|
||||
data["bca"] = bc
|
||||
bc._data = Data._db_load(execute, data=data)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(bc)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"DELETE FROM boundary_condition_temperature " +
|
||||
f"WHERE pamhyr_id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
)
|
||||
execute(
|
||||
"DELETE FROM boundary_condition_data_temperature " +
|
||||
f"WHERE bca = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
)
|
||||
|
||||
node = -1
|
||||
if self._node is not None:
|
||||
node = self._node
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"boundary_condition_temperature(" +
|
||||
"pamhyr_id, deleted, name, " +
|
||||
"node, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"'{self._db_format(self._name)}', {node}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
data["bca"] = self
|
||||
|
||||
ind = 0
|
||||
for d in self._data:
|
||||
data["ind"] = ind
|
||||
|
||||
d._db_save(execute, data)
|
||||
|
||||
ind += 1
|
||||
|
||||
return True
|
||||
|
||||
def _data_traversal(self,
|
||||
predicate=lambda obj, data: True,
|
||||
modifier=lambda obj, data: None,
|
||||
data={}):
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
for d in self._data:
|
||||
d._data_traversal(predicate, modifier, data)
|
||||
|
||||
def __len__(self):
|
||||
return len(
|
||||
list(
|
||||
filter(
|
||||
lambda el: el is not None and not el.is_deleted(),
|
||||
self._data
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def time_convert(cls, data):
|
||||
if type(data) is str:
|
||||
if data.count("-") == 2:
|
||||
return date_iso_to_timestamp(data)
|
||||
if data.count("/") == 2:
|
||||
return date_dmy_to_timestamp(data)
|
||||
if data.count(":") == 3:
|
||||
return old_pamhyr_date_to_timestamp(data)
|
||||
if data.count(":") == 2:
|
||||
return old_pamhyr_date_to_timestamp("00:" + data)
|
||||
if data.count(".") == 1:
|
||||
return round(float(data))
|
||||
|
||||
return int(data)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._name = name
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def node(self):
|
||||
return self._node
|
||||
|
||||
@node.setter
|
||||
def node(self, node):
|
||||
self._node = node
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def header(self):
|
||||
return self._header.copy()
|
||||
|
||||
@header.setter
|
||||
def header(self, header):
|
||||
self._header = header
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return list(
|
||||
filter(
|
||||
lambda el: el is not None and not el.is_deleted(),
|
||||
self._data
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def _default_0(self):
|
||||
return self._types[0](0)
|
||||
|
||||
@property
|
||||
def _default_1(self):
|
||||
return self._types[1](0.0)
|
||||
|
||||
def new_from_data(self, header, data):
|
||||
new_0 = self._default_0
|
||||
new_1 = self._default_1
|
||||
|
||||
if len(header) != 0:
|
||||
for i in [0, 1]:
|
||||
for j in range(len(header)):
|
||||
if self._header[i] == header[j]:
|
||||
if i == 0:
|
||||
new_0 = self._types[i](data[j].replace(",", "."))
|
||||
else:
|
||||
new_1 = self._types[i](data[j].replace(",", "."))
|
||||
else:
|
||||
new_0 = self._types[0](data[0].replace(",", "."))
|
||||
new_1 = self._types[1](data[1].replace(",", "."))
|
||||
|
||||
return (new_0, new_1)
|
||||
|
||||
def add(self, index: int):
|
||||
value = Data(
|
||||
self._default_0, self._default_1,
|
||||
status=self._status
|
||||
)
|
||||
self._data.insert(index, value)
|
||||
self.modified()
|
||||
return value
|
||||
|
||||
def insert(self, index: int, value):
|
||||
self._data.insert(index, value)
|
||||
self.modified()
|
||||
|
||||
def delete_i(self, indexes):
|
||||
list(
|
||||
map(
|
||||
lambda e: e[1].set_as_deleted(),
|
||||
filter(
|
||||
lambda e: e[0] in indexes,
|
||||
enumerate(self.data)
|
||||
)
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
|
||||
def sort(self, _reverse=False, key=None):
|
||||
if key is None:
|
||||
self._data.sort(reverse=_reverse)
|
||||
else:
|
||||
self._data.sort(reverse=_reverse, key=key)
|
||||
self.modified()
|
||||
|
||||
def index(self, bc):
|
||||
self._data.index(bc)
|
||||
|
||||
def get_i(self, index):
|
||||
return self.data[index]
|
||||
|
||||
def get_range(self, _range):
|
||||
lst = []
|
||||
for r in _range:
|
||||
lst.append(r)
|
||||
return lst
|
||||
|
||||
def _set_i_c_v(self, index, column, value):
|
||||
v = self._data[index]
|
||||
v[column] = self._types[column](value)
|
||||
self._data[index] = v
|
||||
self.modified()
|
||||
|
||||
def set_i_0(self, index: int, value):
|
||||
self._set_i_c_v(index, 0, value)
|
||||
|
||||
def set_i_1(self, index: int, value):
|
||||
self._set_i_c_v(index, 1, value)
|
||||
@@ -95,12 +95,11 @@ class PointXYZ(Point):
|
||||
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
|
||||
)
|
||||
|
||||
if major == "0" and minor == "2":
|
||||
if int(release) < 5:
|
||||
execute(
|
||||
"CREATE INDEX idx_point " +
|
||||
"ON geometry_pointXYZ(profile, scenario);"
|
||||
)
|
||||
# Try to create index at each update
|
||||
execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_point " +
|
||||
"ON geometry_pointXYZ(profile, scenario);"
|
||||
)
|
||||
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
|
||||
@@ -58,8 +58,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
num=0,
|
||||
nb_point: int = 0,
|
||||
code1: int = 0, code2: int = 0,
|
||||
status=None, owner_scenario=-1,
|
||||
enabled=True):
|
||||
status=None, owner_scenario=-1):
|
||||
"""ProfileXYZ constructor
|
||||
|
||||
Args:
|
||||
@@ -91,7 +90,6 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
self.time_l = 0.0
|
||||
self._station = []
|
||||
self.station_up_to_date = False
|
||||
self._enabled = bool(enabled)
|
||||
|
||||
self._get_water_limits_cache = {}
|
||||
self._get_water_limits_ac_cache = {}
|
||||
@@ -110,7 +108,6 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
code1 INTEGER NOT NULL,
|
||||
code2 INTEGER NOT NULL,
|
||||
sl INTEGER,
|
||||
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id),
|
||||
@@ -155,13 +152,6 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
|
||||
)
|
||||
|
||||
if major == "0" and int(minor) <=2:
|
||||
if int(release) < 9:
|
||||
execute(
|
||||
"ALTER TABLE geometry_profileXYZ " +
|
||||
"ADD COLUMN enabled BOOLEAN NOT NULL DEFAULT TRUE"
|
||||
)
|
||||
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
@@ -247,7 +237,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, ind, deleted, name, rk, num, " +
|
||||
"code1, code2, sl, scenario, enabled " +
|
||||
"code1, code2, sl, scenario " +
|
||||
"FROM geometry_profileXYZ " +
|
||||
f"WHERE reach = {reach.id} " +
|
||||
f"AND scenario = {scenario.id} " +
|
||||
@@ -268,7 +258,6 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
code2 = next(it)
|
||||
sl = next(it)
|
||||
owner_scenario = next(it)
|
||||
enabled = (next(it) == 1)
|
||||
|
||||
profile = cls(
|
||||
id=pid, ind=ind, num=num,
|
||||
@@ -276,8 +265,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
code1=code1, code2=code2,
|
||||
reach=reach,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario,
|
||||
enabled=enabled
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
profile.set_as_deleted()
|
||||
@@ -330,12 +318,12 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
execute(
|
||||
"INSERT OR REPLACE INTO " +
|
||||
"geometry_profileXYZ(pamhyr_id, deleted, ind, name, reach, " +
|
||||
"rk, num, code1, code2, sl, scenario, enabled) " +
|
||||
"rk, num, code1, code2, sl, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.pamhyr_id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"{ind}, '{self._db_format(self._name)}', " +
|
||||
f"{self.reach.pamhyr_id}, {self.rk}, {self.num}, " +
|
||||
f"{self.code1}, {self.code1}, {sl}, {self._status.scenario_id}, {self._db_format(self._enabled)}" +
|
||||
f"{self.code1}, {self.code1}, {sl}, {self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
@@ -402,8 +390,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
name=self.name,
|
||||
rk=self.rk,
|
||||
reach=self.reach,
|
||||
status=self._status,
|
||||
enabled=self.is_enabled
|
||||
status=self._status
|
||||
)
|
||||
if self.is_deleted():
|
||||
new_p.set_as_deleted()
|
||||
@@ -423,8 +410,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
name=self.name,
|
||||
rk=self.rk,
|
||||
reach=new_reach,
|
||||
status=self._status,
|
||||
enabled=self.is_enabled
|
||||
status=self._status
|
||||
)
|
||||
if self.is_deleted():
|
||||
new_p.set_as_deleted()
|
||||
@@ -1145,8 +1131,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
p = ProfileXYZ(name=self.name,
|
||||
rk=self.rk,
|
||||
reach=self.reach,
|
||||
status=self._status,
|
||||
enabled=self.is_enabled)
|
||||
status=self._status)
|
||||
|
||||
for i, k in enumerate(self.points):
|
||||
p.insert_point(i, k.copy())
|
||||
@@ -1180,16 +1165,3 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
break
|
||||
self._points = points
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def is_enabled(self):
|
||||
return self._enabled
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
return self._enabled
|
||||
|
||||
@enabled.setter
|
||||
def enabled(self, value):
|
||||
self._enabled = bool(value)
|
||||
self.modified()
|
||||
@@ -157,14 +157,6 @@ class Reach(SQLSubModel):
|
||||
def profiles(self, profiles):
|
||||
self._profiles = profiles
|
||||
|
||||
@property
|
||||
def enabled_profiles(self):
|
||||
return list(filter(lambda p: p.is_enabled, self.profiles))
|
||||
|
||||
@property
|
||||
def number_enabled_profiles(self):
|
||||
return len(self.enabled_profiles)
|
||||
|
||||
def get_profiles_from_rk(self, rk):
|
||||
return list(
|
||||
filter(
|
||||
@@ -494,22 +486,14 @@ class Reach(SQLSubModel):
|
||||
)
|
||||
|
||||
@timer
|
||||
def compute_guidelines(self, profiles=None, update_cache=True):
|
||||
def compute_guidelines(self):
|
||||
"""Compute reach guidelines
|
||||
|
||||
Args:
|
||||
profiles: Profiles used to compute the guidelines. If omitted,
|
||||
all non-deleted profiles of the reach are used.
|
||||
update_cache: Whether to update the reach guidelines cache.
|
||||
|
||||
Returns:
|
||||
Tuple of complete and incomplete guidelines name.
|
||||
"""
|
||||
if profiles is None:
|
||||
profiles = self.profiles
|
||||
|
||||
# Get all point contained into a guideline
|
||||
named_points = [profile.named_points() for profile in profiles]
|
||||
named_points = [profile.named_points() for profile in self.profiles]
|
||||
points_name = list(
|
||||
map(
|
||||
lambda lst: list(map(lambda p: p.name, lst)),
|
||||
@@ -540,13 +524,11 @@ class Reach(SQLSubModel):
|
||||
|
||||
complete = guide_set - incomplete
|
||||
|
||||
if update_cache:
|
||||
# Compute guideline and put data in cache
|
||||
self._compute_guidelines_cache(
|
||||
guide_set, named_points, complete, incomplete
|
||||
)
|
||||
self.modified()
|
||||
# Compute guideline and put data in cache
|
||||
self._compute_guidelines_cache(guide_set, named_points,
|
||||
complete, incomplete)
|
||||
|
||||
self.modified()
|
||||
return (complete, incomplete)
|
||||
|
||||
def _map_guidelines_points(self, func, full=False):
|
||||
@@ -770,11 +752,8 @@ class Reach(SQLSubModel):
|
||||
list_profile.append(list_point_profile)
|
||||
list_point_profile = []
|
||||
else:
|
||||
# MAGE-8 ST files can append hydraulic data
|
||||
# after the regular x, y, z and point-name
|
||||
# fields. ProfileXYZ still expects exactly
|
||||
# those first four fields.
|
||||
list_point_profile.append(line[:4])
|
||||
line.append("")
|
||||
list_point_profile.append(line[:3])
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
@@ -277,10 +277,3 @@ class BasicHS(SQLSubModel):
|
||||
|
||||
def convert(self, new_type):
|
||||
return new_type(id=self.id, name=self.name, status=self._status)
|
||||
|
||||
def cloned(self):
|
||||
new = type(self)(name=self._name, status=self._status)
|
||||
new._enabled = self._enabled
|
||||
new._data = [value.cloned() for value in self._data]
|
||||
new.modified()
|
||||
return new
|
||||
@@ -208,11 +208,3 @@ class BHSValue(SQLSubModel):
|
||||
def value(self, value):
|
||||
self._value = self._type(value)
|
||||
self.modified()
|
||||
|
||||
def cloned(self):
|
||||
return BHSValue(
|
||||
name=self._name,
|
||||
type=self._type,
|
||||
value=self._value,
|
||||
status=self._status
|
||||
)
|
||||
@@ -427,18 +427,6 @@ class HydraulicStructure(SQLSubModel):
|
||||
def basic_structures(self):
|
||||
return self.lst.copy()
|
||||
|
||||
def cloned_for(self, input_reach, input_section,
|
||||
output_reach, output_section):
|
||||
new = HydraulicStructure(name=self._name, status=self._status)
|
||||
new._enabled = self._enabled
|
||||
new._input_reach = input_reach
|
||||
new._input_section = input_section
|
||||
new._output_reach = output_reach
|
||||
new._output_section = output_section
|
||||
new._data = [structure.cloned() for structure in self.lst]
|
||||
new.modified()
|
||||
return new
|
||||
|
||||
def basic_structure(self, index: int):
|
||||
if len(self._data) == 0:
|
||||
return None
|
||||
|
||||
@@ -61,71 +61,6 @@ class HydraulicStructureList(PamhyrModelList):
|
||||
self.modified()
|
||||
return n
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
profiles = reach.reach.profiles
|
||||
split_index = profiles.index(profile)
|
||||
sections1 = dict(zip(
|
||||
profiles[:split_index + 1],
|
||||
reach1.reach.profiles
|
||||
))
|
||||
sections2 = dict(zip(
|
||||
profiles[split_index:],
|
||||
reach2.reach.profiles
|
||||
))
|
||||
|
||||
def split_endpoint(endpoint_reach, section):
|
||||
if endpoint_reach is not reach:
|
||||
return endpoint_reach, section
|
||||
if section not in profiles:
|
||||
return endpoint_reach, section
|
||||
|
||||
index = profiles.index(section)
|
||||
if index < split_index:
|
||||
return reach1, sections1[section]
|
||||
return reach2, sections2[section]
|
||||
|
||||
structures = [
|
||||
structure
|
||||
for structure in self.lst
|
||||
if (structure.input_reach is reach or
|
||||
structure.output_reach is reach)
|
||||
]
|
||||
|
||||
for structure in structures:
|
||||
input_reach, input_section = split_endpoint(
|
||||
structure.input_reach,
|
||||
structure.input_section
|
||||
)
|
||||
output_reach, output_section = split_endpoint(
|
||||
structure.output_reach,
|
||||
structure.output_section
|
||||
)
|
||||
self._lst.append(structure.cloned_for(
|
||||
input_reach,
|
||||
input_section,
|
||||
output_reach,
|
||||
output_section
|
||||
))
|
||||
|
||||
if len(structures) != 0:
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def enabled_reaches_list(self):
|
||||
return [
|
||||
structure
|
||||
for structure in self.lst
|
||||
if (structure.input_reach is None or
|
||||
(not structure.input_reach.is_deleted() and
|
||||
structure.input_reach.is_enable()))
|
||||
]
|
||||
|
||||
def get_for_enabled_reaches(self, index):
|
||||
structures = self.enabled_reaches_list
|
||||
if not 0 <= index < len(structures):
|
||||
return None
|
||||
return structures[index]
|
||||
|
||||
def __copy__(self):
|
||||
new = HydraulicStructureList()
|
||||
|
||||
|
||||
@@ -256,17 +256,6 @@ class Data(SQLSubModel):
|
||||
)
|
||||
return new
|
||||
|
||||
def cloned_for(self, reach, section):
|
||||
return Data(
|
||||
name=self._name,
|
||||
comment=self._comment,
|
||||
section=section,
|
||||
discharge=self._discharge,
|
||||
height=self._height,
|
||||
reach=reach,
|
||||
status=self._status,
|
||||
)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
@@ -516,20 +505,6 @@ class InitialConditions(SQLSubModel):
|
||||
for data in self._data:
|
||||
data.set_as_deleted()
|
||||
|
||||
def _splited_for(self, reach, sections):
|
||||
new = InitialConditions(reach=reach, status=self._status)
|
||||
|
||||
new._data = [
|
||||
data.cloned_for(reach, sections[data["section"]])
|
||||
for data in self.data
|
||||
if data["section"] in sections
|
||||
]
|
||||
|
||||
if len(new._data) != 0:
|
||||
new.modified()
|
||||
|
||||
return new
|
||||
|
||||
def generate_growing_constant_depth(self, height: float,
|
||||
compute_discharge: bool):
|
||||
profiles = self._reach.reach.profiles.copy()
|
||||
|
||||
@@ -88,28 +88,3 @@ class InitialConditionsDict(PamhyrModelDict):
|
||||
new = InitialConditions(reach=reach, status=self._status)
|
||||
self.set(reach, new)
|
||||
return new
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
if reach not in self._dict:
|
||||
return
|
||||
|
||||
profiles = reach.reach.profiles
|
||||
split_index = profiles.index(profile)
|
||||
|
||||
sections1 = dict(zip(
|
||||
profiles[:split_index + 1],
|
||||
reach1.reach.profiles
|
||||
))
|
||||
sections2 = dict(zip(
|
||||
profiles[split_index:],
|
||||
reach2.reach.profiles
|
||||
))
|
||||
|
||||
self.set(
|
||||
reach1,
|
||||
self._dict[reach]._splited_for(reach1, sections1)
|
||||
)
|
||||
self.set(
|
||||
reach2,
|
||||
self._dict[reach]._splited_for(reach2, sections2)
|
||||
)
|
||||
@@ -359,60 +359,3 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||
x.set_as_not_deleted()
|
||||
|
||||
self.modified()
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
split_rk = profile.rk
|
||||
reach_rks = reach.reach.get_rk()
|
||||
if len(reach_rks) == 0:
|
||||
return
|
||||
|
||||
lower_reach_rk = min(reach_rks)
|
||||
upper_reach_rk = max(reach_rks)
|
||||
parts = [
|
||||
(reach1.id, lower_reach_rk, split_rk),
|
||||
(reach2.id, split_rk, upper_reach_rk),
|
||||
]
|
||||
specifications = [
|
||||
specification
|
||||
for specification in self._data
|
||||
if (not specification.is_deleted() and
|
||||
specification.reach == reach.id)
|
||||
]
|
||||
|
||||
for specification in specifications:
|
||||
begin = specification.start_rk
|
||||
end = specification.end_rk
|
||||
if begin is None or end is None:
|
||||
continue
|
||||
|
||||
lower, upper = sorted((begin, end))
|
||||
reverse = begin > end
|
||||
|
||||
for new_reach, part_lower, part_upper in parts:
|
||||
clipped_lower = max(lower, part_lower)
|
||||
clipped_upper = min(upper, part_upper)
|
||||
if clipped_lower > clipped_upper:
|
||||
continue
|
||||
|
||||
start_rk = clipped_upper if reverse else clipped_lower
|
||||
end_rk = clipped_lower if reverse else clipped_upper
|
||||
self._data.append(specification.cloned_for(
|
||||
new_reach, start_rk, end_rk
|
||||
))
|
||||
|
||||
if len(specifications) != 0:
|
||||
self.modified()
|
||||
|
||||
def get_specs_for_enabled_reaches(self, reaches):
|
||||
enabled_reaches = {
|
||||
reach.id
|
||||
for reach in reaches
|
||||
if not reach.is_deleted() and reach.is_enable()
|
||||
}
|
||||
return [
|
||||
specification
|
||||
for specification in self._data
|
||||
if (not specification.is_deleted() and
|
||||
(specification.reach in (None, -1) or
|
||||
specification.reach in enabled_reaches))
|
||||
]
|
||||
@@ -62,12 +62,6 @@ class InitialConditionsAdisTSList(PamhyrModelList):
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
for initial_condition in self.lst:
|
||||
initial_condition.split_reach(
|
||||
reach, profile, reach1, reach2
|
||||
)
|
||||
|
||||
@property
|
||||
def Initial_Conditions_List(self):
|
||||
return self.lst
|
||||
@@ -31,12 +31,10 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(ICAdisTSSpec, self).__init__(
|
||||
id=id,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
status=None, owner_scenario=None):
|
||||
super(ICAdisTSSpec, self).__init__()
|
||||
|
||||
self._status = status
|
||||
|
||||
self._name_section = name
|
||||
self._reach = None
|
||||
@@ -236,7 +234,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._name_section = name
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def reach(self):
|
||||
@@ -245,7 +243,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@reach.setter
|
||||
def reach(self, reach):
|
||||
self._reach = reach
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def start_rk(self):
|
||||
@@ -254,7 +252,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@start_rk.setter
|
||||
def start_rk(self, start_rk):
|
||||
self._start_rk = start_rk
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def end_rk(self):
|
||||
@@ -263,7 +261,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@end_rk.setter
|
||||
def end_rk(self, end_rk):
|
||||
self._end_rk = end_rk
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def concentration(self):
|
||||
@@ -272,7 +270,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@concentration.setter
|
||||
def concentration(self, concentration):
|
||||
self._concentration = concentration
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def eg(self):
|
||||
@@ -281,7 +279,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@eg.setter
|
||||
def eg(self, eg):
|
||||
self._eg = eg
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def em(self):
|
||||
@@ -290,7 +288,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@em.setter
|
||||
def em(self, em):
|
||||
self._em = em
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def ed(self):
|
||||
@@ -299,7 +297,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@ed.setter
|
||||
def ed(self, ed):
|
||||
self._ed = ed
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def rate(self):
|
||||
@@ -308,7 +306,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@rate.setter
|
||||
def rate(self, rate):
|
||||
self._rate = rate
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
@@ -317,18 +315,4 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@enabled.setter
|
||||
def enabled(self, enabled):
|
||||
self._enabled = enabled
|
||||
self.modified()
|
||||
|
||||
def cloned_for(self, reach, start_rk, end_rk):
|
||||
new = ICAdisTSSpec(name=self._name_section, status=self._status)
|
||||
new._reach = reach
|
||||
new._start_rk = start_rk
|
||||
new._end_rk = end_rk
|
||||
new._concentration = self._concentration
|
||||
new._eg = self._eg
|
||||
new._em = self._em
|
||||
new._ed = self._ed
|
||||
new._rate = self._rate
|
||||
new._enabled = self._enabled
|
||||
new.modified()
|
||||
return new
|
||||
self._status.modified()
|
||||
@@ -1,268 +0,0 @@
|
||||
# InitialConditionsTemperature.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 -*-
|
||||
|
||||
import logging
|
||||
from functools import reduce
|
||||
|
||||
from tools import trace, timer, old_pamhyr_date_to_timestamp
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
from Model.InitialConditionsTemperature.InitialConditionsTemperatureSpec \
|
||||
import ICTemperatureSpec
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class InitialConditionsTemperature(SQLSubModel):
|
||||
_sub_classes = [
|
||||
ICTemperatureSpec,
|
||||
]
|
||||
|
||||
def __init__(self, id: int = -1, name: str = "default",
|
||||
status=None, owner_scenario=-1):
|
||||
super(InitialConditionsTemperature, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
self._status = status
|
||||
|
||||
self._name = name
|
||||
self._temperature = None
|
||||
self._data = []
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE initial_conditions_temperature{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
name TEXT NOT NULL,
|
||||
temperature REAL NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()}
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
|
||||
if major == "0":
|
||||
if int(minor) < 2 or (int(minor) == 2 and int(release) < 7):
|
||||
table_name = "initial_conditions_temperature"
|
||||
if not cls.is_table_exists(execute, table_name):
|
||||
cls._db_create(execute)
|
||||
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, " +
|
||||
"name, temperature, scenario " +
|
||||
"FROM initial_conditions_temperature " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
deleted = (next(it) == 1)
|
||||
name = next(it)
|
||||
temperature = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
ic = cls(
|
||||
id=pid,
|
||||
name=name,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
ic.set_as_deleted()
|
||||
|
||||
ic.temperature = temperature
|
||||
|
||||
data['ic_default_id'] = pid
|
||||
ic._data = ICTemperatureSpec._db_load(execute, data)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(ic)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"DELETE FROM initial_conditions_temperature " +
|
||||
f"WHERE pamhyr_id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
temperature = self._temperature if \
|
||||
self._temperature is not None else 0.0
|
||||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"initial_conditions_temperature(" +
|
||||
"pamhyr_id, deleted, name, temperature, " +
|
||||
"scenario" +
|
||||
") " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self.is_deleted()}, " +
|
||||
f"'{self._db_format(self._name)}', " +
|
||||
f"{temperature}, {self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
execute(sql)
|
||||
|
||||
data['ic_default_id'] = self.id
|
||||
execute(
|
||||
"DELETE FROM initial_conditions_temperature_spec " +
|
||||
f"WHERE ic_default = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
for ic_spec in self._data:
|
||||
ic_spec._db_save(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
def __len__(self):
|
||||
return len(self._data)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._name = name
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def temperature(self):
|
||||
return self._temperature
|
||||
|
||||
@temperature.setter
|
||||
def temperature(self, temperature):
|
||||
self._temperature = temperature
|
||||
self.modified()
|
||||
|
||||
def new(self, index):
|
||||
n = ICTemperatureSpec(status=self._status)
|
||||
self._data.insert(index, n)
|
||||
self.modified()
|
||||
return n
|
||||
|
||||
def delete(self, data):
|
||||
list(
|
||||
map(
|
||||
lambda x: x.set_as_deleted(),
|
||||
data
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
|
||||
def delete_i(self, indexes):
|
||||
list(
|
||||
map(
|
||||
lambda e: e[1].set_as_deleted(),
|
||||
filter(
|
||||
lambda e: e[0] in indexes,
|
||||
enumerate(self._data)
|
||||
)
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
|
||||
def insert(self, index, data):
|
||||
if data in self._data:
|
||||
self.undelete([data])
|
||||
else:
|
||||
self._data.insert(index, data)
|
||||
|
||||
self.modified()
|
||||
|
||||
def undelete(self, lst):
|
||||
for x in lst:
|
||||
x.set_as_not_deleted()
|
||||
|
||||
self.modified()
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
parts = []
|
||||
for new_reach in (reach1, reach2):
|
||||
rks = new_reach.reach.get_rk()
|
||||
if rks:
|
||||
parts.append((new_reach.id, min(rks), max(rks)))
|
||||
|
||||
specifications = [
|
||||
specification
|
||||
for specification in self._data
|
||||
if (not specification.is_deleted() and
|
||||
specification.reach == reach.id)
|
||||
]
|
||||
clones = []
|
||||
|
||||
for specification in specifications:
|
||||
begin = specification.start_rk
|
||||
end = specification.end_rk
|
||||
if begin is None or end is None:
|
||||
continue
|
||||
|
||||
lower, upper = sorted((begin, end))
|
||||
reverse = begin > end
|
||||
for new_reach, part_lower, part_upper in parts:
|
||||
clipped_lower = max(lower, part_lower)
|
||||
clipped_upper = min(upper, part_upper)
|
||||
if clipped_lower > clipped_upper:
|
||||
continue
|
||||
|
||||
start_rk = clipped_upper if reverse else clipped_lower
|
||||
end_rk = clipped_lower if reverse else clipped_upper
|
||||
clones.append(specification.cloned_for(
|
||||
new_reach, start_rk, end_rk
|
||||
))
|
||||
|
||||
if clones:
|
||||
self._data.extend(clones)
|
||||
self.modified()
|
||||
@@ -1,73 +0,0 @@
|
||||
# InitialConditionsTemperatureList.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 copy import copy
|
||||
from tools import trace, timer
|
||||
|
||||
from Model.Tools.PamhyrListExt import PamhyrModelList
|
||||
from Model.InitialConditionsTemperature.InitialConditionsTemperature \
|
||||
import InitialConditionsTemperature
|
||||
|
||||
|
||||
class InitialConditionsTemperatureList(PamhyrModelList):
|
||||
_sub_classes = [
|
||||
InitialConditionsTemperature,
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = cls(status=data['status'])
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
new._lst = InitialConditionsTemperature._db_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
execute(
|
||||
"DELETE FROM initial_conditions_temperature " +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
for ic in self._lst:
|
||||
ic._db_save(execute, data=data)
|
||||
|
||||
return True
|
||||
|
||||
def new(self, index):
|
||||
n = InitialConditionsTemperature(status=self._status)
|
||||
self._lst.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
for initial_condition in self.lst:
|
||||
initial_condition.split_reach(
|
||||
reach, profile, reach1, reach2
|
||||
)
|
||||
|
||||
@property
|
||||
def Initial_Conditions_List(self):
|
||||
return self.lst
|
||||
@@ -1,214 +0,0 @@
|
||||
# InitialConditionsAdisTSSpec.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from tools import trace, timer
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class ICTemperatureSpec(SQLSubModel):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=None):
|
||||
super(ICTemperatureSpec, self).__init__()
|
||||
|
||||
self._status = status
|
||||
|
||||
self._name_section = name
|
||||
self._reach = None
|
||||
self._start_rk = None
|
||||
self._end_rk = None
|
||||
self._temperature = None
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE initial_conditions_temperature_spec{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
ic_default INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
reach INTEGER NOT NULL,
|
||||
start_rk REAL NOT NULL,
|
||||
end_rk REAL NOT NULL,
|
||||
temperature REAL NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(ic_default)
|
||||
REFERENCES initial_conditions_temperature(pamhyr_id),
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id)
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
|
||||
if major == "0":
|
||||
if int(minor) < 2 or (int(minor) == 2 and int(release) < 7):
|
||||
table_name = "initial_conditions_temperature_spec"
|
||||
if not cls.is_table_exists(execute, table_name):
|
||||
cls._db_create(execute)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
reachs = data["edges"]
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, name, reach, start_rk, end_rk, " +
|
||||
"temperature, scenario " +
|
||||
"FROM initial_conditions_temperature_spec " +
|
||||
f"WHERE ic_default = {data['ic_default_id']} " +
|
||||
f"AND scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
id = next(it)
|
||||
deleted = (next(it) == 1)
|
||||
name = next(it)
|
||||
reach = next(it)
|
||||
start_rk = next(it)
|
||||
end_rk = next(it)
|
||||
temperature = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
new_spec = cls(
|
||||
id=id, name=name,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
new_spec.set_as_deleted()
|
||||
|
||||
new_spec.reach = reach
|
||||
new_spec.start_rk = start_rk
|
||||
new_spec.end_rk = end_rk
|
||||
new_spec.temperature = temperature
|
||||
|
||||
# loaded.add(pid)
|
||||
new.append(new_spec)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
ic_default = data['ic_default_id']
|
||||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"initial_conditions_temperature_spec(pamhyr_id, deleted, " +
|
||||
"ic_default, name, reach, " +
|
||||
"start_rk, end_rk, temperature, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"{ic_default}, " +
|
||||
f"'{self._db_format(self._name_section)}', " +
|
||||
f"{self._reach}, " +
|
||||
f"{self._start_rk}, {self._end_rk}, " +
|
||||
f"{self._temperature}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
execute(sql)
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name_section
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._name_section = name
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def reach(self):
|
||||
return self._reach
|
||||
|
||||
@reach.setter
|
||||
def reach(self, reach):
|
||||
self._reach = reach
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def start_rk(self):
|
||||
return self._start_rk
|
||||
|
||||
@start_rk.setter
|
||||
def start_rk(self, start_rk):
|
||||
self._start_rk = start_rk
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def end_rk(self):
|
||||
return self._end_rk
|
||||
|
||||
@end_rk.setter
|
||||
def end_rk(self, end_rk):
|
||||
self._end_rk = end_rk
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def temperature(self):
|
||||
return self._temperature
|
||||
|
||||
@temperature.setter
|
||||
def temperature(self, temperature):
|
||||
self._temperature = temperature
|
||||
self._status.modified()
|
||||
|
||||
def cloned_for(self, reach, start_rk, end_rk):
|
||||
new = ICTemperatureSpec(
|
||||
name=self._name_section,
|
||||
status=self._status
|
||||
)
|
||||
new._reach = reach
|
||||
new._start_rk = start_rk
|
||||
new._end_rk = end_rk
|
||||
new._temperature = self._temperature
|
||||
new.modified()
|
||||
return new
|
||||
@@ -196,13 +196,6 @@ class Data(SQLSubModel):
|
||||
def __setitem__(self, key, value):
|
||||
self._data[key] = self._types[key](value)
|
||||
|
||||
def cloned(self):
|
||||
return Data(
|
||||
self[0], self[1],
|
||||
types=self._types,
|
||||
status=self._status
|
||||
)
|
||||
|
||||
|
||||
class LateralContribution(SQLSubModel):
|
||||
_sub_classes = [Data]
|
||||
@@ -518,15 +511,6 @@ class LateralContribution(SQLSubModel):
|
||||
def has_reach(self):
|
||||
return self._reach is not None
|
||||
|
||||
def cloned_for(self, reach, begin_section, end_section):
|
||||
new = type(self)(name=self._name, status=self._status)
|
||||
new._reach = reach
|
||||
new._begin_section = begin_section
|
||||
new._end_section = end_section
|
||||
new._data = [data.cloned() for data in self.data]
|
||||
new.modified()
|
||||
return new
|
||||
|
||||
@property
|
||||
def begin_rk(self):
|
||||
if self._begin_section is None:
|
||||
|
||||
@@ -71,89 +71,6 @@ class LateralContributionList(PamhyrModelListWithTab):
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
profiles = reach.reach.profiles
|
||||
split_index = profiles.index(profile)
|
||||
|
||||
parts = [
|
||||
(
|
||||
reach1,
|
||||
0,
|
||||
split_index,
|
||||
dict(zip(
|
||||
profiles[:split_index + 1],
|
||||
reach1.reach.profiles
|
||||
))
|
||||
),
|
||||
(
|
||||
reach2,
|
||||
split_index,
|
||||
len(profiles) - 1,
|
||||
dict(zip(
|
||||
profiles[split_index:],
|
||||
reach2.reach.profiles
|
||||
))
|
||||
),
|
||||
]
|
||||
|
||||
for tab in self._tabs:
|
||||
contributions = [
|
||||
contribution
|
||||
for contribution in self.get_tab(tab)
|
||||
if contribution.reach is reach
|
||||
]
|
||||
|
||||
for contribution in contributions:
|
||||
if (contribution.begin_section not in profiles or
|
||||
contribution.end_section not in profiles):
|
||||
continue
|
||||
|
||||
begin = profiles.index(contribution.begin_section)
|
||||
end = profiles.index(contribution.end_section)
|
||||
lower, upper = sorted((begin, end))
|
||||
reverse = begin > end
|
||||
clones = []
|
||||
|
||||
for new_reach, part_lower, part_upper, sections in parts:
|
||||
clipped_lower = max(lower, part_lower)
|
||||
clipped_upper = min(upper, part_upper)
|
||||
if clipped_lower > clipped_upper:
|
||||
continue
|
||||
|
||||
begin_index = (
|
||||
clipped_upper if reverse else clipped_lower
|
||||
)
|
||||
end_index = (
|
||||
clipped_lower if reverse else clipped_upper
|
||||
)
|
||||
clones.append(contribution.cloned_for(
|
||||
new_reach,
|
||||
sections[profiles[begin_index]],
|
||||
sections[profiles[end_index]]
|
||||
))
|
||||
|
||||
if len(clones) == 0:
|
||||
continue
|
||||
|
||||
self._tabs[tab].extend(clones)
|
||||
|
||||
self._status.modified()
|
||||
|
||||
def get_tab_for_enabled_reaches(self, tab):
|
||||
return [
|
||||
contribution
|
||||
for contribution in self.get_tab(tab)
|
||||
if (contribution.reach is None or
|
||||
(not contribution.reach.is_deleted() and
|
||||
contribution.reach.is_enable()))
|
||||
]
|
||||
|
||||
def get_for_enabled_reaches(self, tab, index):
|
||||
contributions = self.get_tab_for_enabled_reaches(tab)
|
||||
if not 0 <= index < len(contributions):
|
||||
return None
|
||||
return contributions[index]
|
||||
|
||||
def __copy__(self):
|
||||
new = LateralContributionList()
|
||||
|
||||
|
||||
@@ -192,13 +192,6 @@ class Data(SQLSubModel):
|
||||
def __setitem__(self, key, value):
|
||||
self._data[key] = self._types[key](value)
|
||||
|
||||
def cloned(self):
|
||||
return Data(
|
||||
self[0], self[1],
|
||||
types=self._types,
|
||||
status=self._status
|
||||
)
|
||||
|
||||
|
||||
class LateralContributionAdisTS(SQLSubModel):
|
||||
_sub_classes = [Data]
|
||||
@@ -484,18 +477,6 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||
self._end_rk = end_rk
|
||||
self.modified()
|
||||
|
||||
def cloned_for(self, reach, begin_rk, end_rk):
|
||||
new = LateralContributionAdisTS(
|
||||
pollutant=self._pollutant,
|
||||
status=self._status
|
||||
)
|
||||
new._reach = reach
|
||||
new._begin_rk = begin_rk
|
||||
new._end_rk = end_rk
|
||||
new._data = [data.cloned() for data in self.data]
|
||||
new.modified()
|
||||
return new
|
||||
|
||||
@property
|
||||
def _default_0(self):
|
||||
return self._types[0](0)
|
||||
|
||||
@@ -68,46 +68,6 @@ class LateralContributionsAdisTSList(PamhyrModelList):
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
parts = []
|
||||
for new_reach in (reach1, reach2):
|
||||
rks = new_reach.reach.get_rk()
|
||||
if len(rks) == 0:
|
||||
continue
|
||||
parts.append((new_reach.id, min(rks), max(rks)))
|
||||
|
||||
contributions = [
|
||||
contribution
|
||||
for contribution in self.lst
|
||||
if contribution.reach == reach.id
|
||||
]
|
||||
clones = []
|
||||
|
||||
for contribution in contributions:
|
||||
begin = contribution.begin_rk
|
||||
end = contribution.end_rk
|
||||
if begin is None or end is None:
|
||||
continue
|
||||
|
||||
lower, upper = sorted((begin, end))
|
||||
reverse = begin > end
|
||||
|
||||
for new_reach, part_lower, part_upper in parts:
|
||||
clipped_lower = max(lower, part_lower)
|
||||
clipped_upper = min(upper, part_upper)
|
||||
if clipped_lower > clipped_upper:
|
||||
continue
|
||||
|
||||
begin_rk = clipped_upper if reverse else clipped_lower
|
||||
end_rk = clipped_lower if reverse else clipped_upper
|
||||
clones.append(contribution.cloned_for(
|
||||
new_reach, begin_rk, end_rk
|
||||
))
|
||||
|
||||
if len(clones) != 0:
|
||||
self._lst.extend(clones)
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def Lat_Cont_List(self):
|
||||
return self.lst
|
||||
@@ -0,0 +1,208 @@
|
||||
# OutputRKAdists.py -- Pamhyr
|
||||
# Copyright (C) 2023-2026 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 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from tools import (
|
||||
trace, timer,
|
||||
old_pamhyr_date_to_timestamp,
|
||||
date_iso_to_timestamp,
|
||||
date_dmy_to_timestamp,
|
||||
)
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class OutputRKAdists(SQLSubModel):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self, id: int = -1, reach=None,
|
||||
rk=None, title: str = "", status=None,
|
||||
owner_scenario=-1):
|
||||
super(OutputRKAdists, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._reach = reach
|
||||
self._rk = rk
|
||||
self._title = str(title)
|
||||
self._enabled = True
|
||||
|
||||
@property
|
||||
def reach(self):
|
||||
return self._reach
|
||||
|
||||
@reach.setter
|
||||
def reach(self, reach_id):
|
||||
self._reach = reach_id
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def rk(self):
|
||||
return self._rk
|
||||
|
||||
@rk.setter
|
||||
def rk(self, profile_id):
|
||||
self._rk = profile_id
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
return self._title
|
||||
|
||||
@title.setter
|
||||
def title(self, title):
|
||||
self._title = title
|
||||
self._status.modified()
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE output_rk_adists{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
reach INTEGER NOT NULL,
|
||||
rk REAL NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(id)
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
if cls.is_table_exists(execute, "OutputRKAdists"):
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
else:
|
||||
cls._db_create(execute)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "OutputRKAdists"
|
||||
table_new = "output_rk_adists"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table_new}_tmp " +
|
||||
"(pamhyr_id, reach, rk, title, scenario) " +
|
||||
"SELECT pamhyr_id, reach, rk, title, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table_new}_tmp RENAME TO {table_new}")
|
||||
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table_new, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
# reach = data["reach"]
|
||||
# profile = data["profile"]
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, reach, rk, title, scenario " +
|
||||
f"FROM output_rk_adists"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
deleted = (next(it) == 1)
|
||||
id_reach = next(it)
|
||||
id_rk = next(it)
|
||||
title = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
new_output = cls(
|
||||
id=pid, reach=id_reach,
|
||||
rk=id_rk, title=title,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario,
|
||||
)
|
||||
if deleted:
|
||||
new_output.set_as_deleted()
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(new_output)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"DELETE FROM output_rk_adists " +
|
||||
f"WHERE pamhyr_id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
)
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"output_rk_adists(pamhyr_id, deleted, " +
|
||||
"reach, rk, title, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"{self._reach}, {self._rk}, " +
|
||||
f"'{self._db_format(self._title)}', " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
return self._enabled
|
||||
|
||||
@enabled.setter
|
||||
def enabled(self, enabled):
|
||||
self._enabled = enabled
|
||||
self._status.modified()
|
||||
+20
-32
@@ -1,5 +1,5 @@
|
||||
# BoundaryConditionsTemperatureList.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
# OutputRKListAdists.py -- Pamhyr
|
||||
# Copyright (C) 2024-2025 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
|
||||
@@ -16,56 +16,44 @@
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from copy import copy
|
||||
from tools import trace, timer
|
||||
|
||||
from Model.Tools.PamhyrListExt import PamhyrModelList
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
|
||||
from Model.BoundaryConditionsTemperature.BoundaryConditionTemperature \
|
||||
import BoundaryConditionTemperature
|
||||
from Model.Tools.PamhyrListExt import PamhyrModelList
|
||||
from Model.OutputRKAdists.OutputRKAdists import OutputRKAdists
|
||||
|
||||
|
||||
class BoundaryConditionsTemperatureList(PamhyrModelList):
|
||||
_sub_classes = [
|
||||
BoundaryConditionTemperature,
|
||||
]
|
||||
class OutputRKAdistsList(PamhyrModelList):
|
||||
_sub_classes = [OutputRKAdists]
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = cls(status=data['status'])
|
||||
new = cls(status=data["status"])
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
new._lst = BoundaryConditionTemperature._db_load(execute, data)
|
||||
new._lst = OutputRKAdists._db_load(execute, data)
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
ok = True
|
||||
|
||||
# Delete previous data
|
||||
execute(
|
||||
"DELETE FROM boundary_condition_temperature " +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
execute(
|
||||
"DELETE FROM boundary_condition_data_temperature " +
|
||||
"DELETE FROM output_rk_adists " +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
for sl in self._lst:
|
||||
ok &= sl._db_save(execute, data)
|
||||
|
||||
for bca in self._lst:
|
||||
bca._db_save(execute, data=data)
|
||||
return ok
|
||||
|
||||
return True
|
||||
@property
|
||||
def OutputRK_List(self):
|
||||
return self.lst
|
||||
|
||||
def new(self, index):
|
||||
n = BoundaryConditionTemperature(status=self._status)
|
||||
def new(self, lst, index):
|
||||
n = OutputRKAdists(status=self._status)
|
||||
self._lst.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
@property
|
||||
def BCs_Temperature_List(self):
|
||||
return self.lst
|
||||
@@ -276,7 +276,7 @@ class Profile(SQLSubModel):
|
||||
class Reach(SQLSubModel):
|
||||
_sub_classes = [Profile]
|
||||
|
||||
def __init__(self, reach, study, parent, with_init=True, profiles=None):
|
||||
def __init__(self, reach, study, parent, with_init=True):
|
||||
super(Reach, self).__init__(
|
||||
id=-1, status=study.status,
|
||||
owner_scenario=study.status.scenario.id
|
||||
@@ -287,12 +287,10 @@ class Reach(SQLSubModel):
|
||||
self._reach = reach # Source reach in the study
|
||||
self._profiles = []
|
||||
if with_init:
|
||||
if profiles is None:
|
||||
profiles = reach.profiles
|
||||
self._profiles = list(
|
||||
map(
|
||||
lambda p: Profile(p, self._study, self._parent),
|
||||
profiles
|
||||
reach.profiles
|
||||
)
|
||||
)
|
||||
|
||||
@@ -381,14 +379,7 @@ class Reach(SQLSubModel):
|
||||
|
||||
for i, profile in enumerate(reach.profiles):
|
||||
data["profile"] = profile
|
||||
result_profile = Profile._db_load(execute, data)
|
||||
if len(result_profile) > 0:
|
||||
new_reach._profiles.append(result_profile)
|
||||
|
||||
new_reach._profile_mask = [
|
||||
profile.name[0:8] != 'interpol'
|
||||
for profile in new_reach._profiles
|
||||
]
|
||||
new_reach._profiles += [Profile._db_load(execute, data)]
|
||||
|
||||
return new_reach
|
||||
|
||||
@@ -427,13 +418,10 @@ class River(SQLSubModel):
|
||||
def has_reach(self, id):
|
||||
return 0 <= id < len(self._reachs)
|
||||
|
||||
def add(self, reach_id, profiles=None):
|
||||
def add(self, reach_id):
|
||||
reachs = self._study.river.enable_edges()
|
||||
|
||||
new = Reach(
|
||||
reachs[reach_id].reach, self._study, self._parent,
|
||||
profiles=profiles
|
||||
)
|
||||
new = Reach(reachs[reach_id].reach, self._study, self._parent)
|
||||
|
||||
self._reachs.append(new)
|
||||
return new
|
||||
@@ -472,9 +460,9 @@ class River(SQLSubModel):
|
||||
|
||||
for reach in study.river.reachs():
|
||||
data["reach"] = reach.reach
|
||||
result_reach = Reach._db_load(execute, data)
|
||||
if len(result_reach) > 0:
|
||||
new_river._reachs.append(result_reach)
|
||||
new_river._reachs.append(
|
||||
Reach._db_load(execute, data)
|
||||
)
|
||||
|
||||
return new_river
|
||||
|
||||
|
||||
+13
-69
@@ -49,6 +49,7 @@ from Model.REPLine.REPLineList import REPLineList
|
||||
|
||||
from Solver.Solvers import solver_type_list
|
||||
|
||||
from Model.OutputRKAdists.OutputRKListAdists import OutputRKAdistsList
|
||||
from Model.Pollutants.PollutantsList import PollutantsList
|
||||
from Model.InitialConditionsAdisTS.InitialConditionsAdisTSList \
|
||||
import InitialConditionsAdisTSList
|
||||
@@ -58,16 +59,6 @@ from Model.LateralContributionsAdisTS.LateralContributionsAdisTSList \
|
||||
import LateralContributionsAdisTSList
|
||||
from Model.D90AdisTS.D90AdisTSList import D90AdisTSList
|
||||
from Model.DIFAdisTS.DIFAdisTSList import DIFAdisTSList
|
||||
|
||||
from Model.InitialConditionsTemperature.InitialConditionsTemperatureList \
|
||||
import InitialConditionsTemperatureList
|
||||
|
||||
from Model.BoundaryConditionsTemperature.BoundaryConditionsTemperatureList \
|
||||
import BoundaryConditionsTemperatureList
|
||||
|
||||
from Model.WeatherParameters.WeatherParametersList \
|
||||
import WeatherParametersList
|
||||
|
||||
from Model.GeoTIFF.GeoTIFFList import GeoTIFFList
|
||||
from Model.Results.Results import Results
|
||||
|
||||
@@ -477,15 +468,13 @@ class River(Graph):
|
||||
HydraulicStructureList,
|
||||
AddFileList,
|
||||
REPLineList,
|
||||
OutputRKAdistsList,
|
||||
PollutantsList,
|
||||
InitialConditionsAdisTSList,
|
||||
BoundaryConditionsAdisTSList,
|
||||
LateralContributionsAdisTSList,
|
||||
D90AdisTSList,
|
||||
DIFAdisTSList,
|
||||
InitialConditionsTemperatureList,
|
||||
BoundaryConditionsTemperatureList,
|
||||
WeatherParametersList,
|
||||
GeoTIFFList,
|
||||
Results
|
||||
]
|
||||
@@ -513,6 +502,7 @@ class River(Graph):
|
||||
)
|
||||
self._additional_files = AddFileList(status=self._status)
|
||||
self._rep_lines = REPLineList(status=self._status)
|
||||
self._Output_rk_adists = OutputRKAdistsList(status=self._status)
|
||||
self._Pollutants = PollutantsList(status=self._status)
|
||||
self._InitialConditionsAdisTS = InitialConditionsAdisTSList(
|
||||
status=self._status)
|
||||
@@ -522,13 +512,6 @@ class River(Graph):
|
||||
status=self._status)
|
||||
self._D90AdisTS = D90AdisTSList(status=self._status)
|
||||
self._DIFAdisTS = DIFAdisTSList(status=self._status)
|
||||
self._InitialConditionsTemperature = (
|
||||
InitialConditionsTemperatureList(status=self._status)
|
||||
)
|
||||
self._BoundaryConditionsTemperature = (
|
||||
BoundaryConditionsTemperatureList(status=self._status)
|
||||
)
|
||||
self._WeatherParameters = (WeatherParametersList(status=self._status))
|
||||
|
||||
self._geotiff = GeoTIFFList(status=self._status)
|
||||
|
||||
@@ -627,6 +610,10 @@ class River(Graph):
|
||||
|
||||
new._Pollutants = PollutantsList._db_load(execute, data)
|
||||
|
||||
new._Output_rk_adists = OutputRKAdistsList._db_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
new._InitialConditionsAdisTS = InitialConditionsAdisTSList._db_load(
|
||||
execute, data)
|
||||
|
||||
@@ -640,14 +627,6 @@ class River(Graph):
|
||||
|
||||
new._DIFAdisTS = DIFAdisTSList._db_load(execute, data)
|
||||
|
||||
new._InitialConditionsTemperature = \
|
||||
InitialConditionsTemperatureList._db_load(execute, data)
|
||||
|
||||
new._BoundaryConditionsTemperature = \
|
||||
BoundaryConditionsTemperatureList._db_load(execute, data)
|
||||
|
||||
new._WeatherParameters = WeatherParametersList._db_load(execute, data)
|
||||
|
||||
new._geotiff = GeoTIFFList._db_load(execute, data)
|
||||
|
||||
return new
|
||||
@@ -675,6 +654,7 @@ class River(Graph):
|
||||
for solver in self._parameters:
|
||||
objs.append(self._parameters[solver])
|
||||
|
||||
objs.append(self._Output_rk_adists)
|
||||
objs.append(self._Pollutants)
|
||||
objs.append(self._InitialConditionsAdisTS)
|
||||
objs.append(self._BoundaryConditionsAdisTS)
|
||||
@@ -682,10 +662,6 @@ class River(Graph):
|
||||
objs.append(self._D90AdisTS)
|
||||
objs.append(self._DIFAdisTS)
|
||||
|
||||
objs.append(self._InitialConditionsTemperature)
|
||||
objs.append(self._BoundaryConditionsTemperature)
|
||||
objs.append(self._WeatherParameters)
|
||||
|
||||
objs.append(self._geotiff)
|
||||
|
||||
for solv_type in self.results:
|
||||
@@ -758,14 +734,12 @@ class River(Graph):
|
||||
self._hydraulic_structures,
|
||||
self._additional_files,
|
||||
self._rep_lines,
|
||||
self._Output_rk_adists,
|
||||
self._Pollutants,
|
||||
self._InitialConditionsAdisTS,
|
||||
self._BoundaryConditionsAdisTS,
|
||||
self._LateralContributionsAdisTS,
|
||||
self._D90AdisTS, self._DIFAdisTS,
|
||||
self._InitialConditionsTemperature,
|
||||
self._BoundaryConditionsTemperature,
|
||||
self._WeatherParameters,
|
||||
self._geotiff,
|
||||
]
|
||||
|
||||
@@ -871,6 +845,10 @@ Last export at: @date."""
|
||||
def parameters(self):
|
||||
return self._parameters
|
||||
|
||||
@property
|
||||
def Output_rk_adists(self):
|
||||
return self._Output_rk_adists
|
||||
|
||||
@property
|
||||
def Pollutants(self):
|
||||
return self._Pollutants
|
||||
@@ -895,18 +873,6 @@ Last export at: @date."""
|
||||
def dif_adists(self):
|
||||
return self._DIFAdisTS
|
||||
|
||||
@property
|
||||
def ic_temperature(self):
|
||||
return self._InitialConditionsTemperature
|
||||
|
||||
@property
|
||||
def boundary_conditions_temperature(self):
|
||||
return self._BoundaryConditionsTemperature
|
||||
|
||||
@property
|
||||
def weather_parameters(self):
|
||||
return self._WeatherParameters
|
||||
|
||||
def get_params(self, solver):
|
||||
if solver in self._parameters:
|
||||
return self._parameters[solver]
|
||||
@@ -979,26 +945,4 @@ Last export at: @date."""
|
||||
self._add_edge(r1)
|
||||
self._add_edge(r2)
|
||||
|
||||
self._initial_conditions.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
self._lateral_contribution.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
self._hydraulic_structures.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
self._InitialConditionsAdisTS.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
self._LateralContributionsAdisTS.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
self._InitialConditionsTemperature.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
self._WeatherParameters.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
|
||||
return r1, r2
|
||||
+8
-10
@@ -32,6 +32,7 @@ class Scenario(SQLSubModel):
|
||||
|
||||
tables_with_deleted_column = [
|
||||
# Adists
|
||||
"output_rk_adists",
|
||||
"boundary_condition_adists", "boundary_condition_data_adists",
|
||||
"lateral_contribution_adists", "lateral_contribution_data_adists",
|
||||
"initial_conditions_adists", "initial_conditions_adists_spec",
|
||||
@@ -52,12 +53,6 @@ class Scenario(SQLSubModel):
|
||||
"geometry_pointXYZ", "geometry_profileXYZ",
|
||||
"river_reach", "river_node",
|
||||
"geotiff", "reservoir", "reservoir_data",
|
||||
# Temperature
|
||||
"boundary_condition_temperature",
|
||||
"boundary_condition_data_temperature",
|
||||
"initial_conditions_temperature",
|
||||
"initial_conditions_temperature_spec",
|
||||
"weather_parameters", "weather_parameters_data",
|
||||
]
|
||||
|
||||
related_tables = tables_with_deleted_column + [
|
||||
@@ -351,8 +346,11 @@ class Scenario(SQLSubModel):
|
||||
return None
|
||||
|
||||
def workdir(self):
|
||||
current = "scenario_" + str(self.id)
|
||||
if self.parent is None or self.parent.id == 0:
|
||||
return current
|
||||
srep = ""
|
||||
if self.id != 0:
|
||||
srep = os.path.join(
|
||||
self.parent.workdir(),
|
||||
"scenario_" + str(self.id)
|
||||
)
|
||||
|
||||
return os.path.join(self.parent.workdir(), current)
|
||||
return srep
|
||||
@@ -216,9 +216,6 @@ class Parameter(SQLSubModel):
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
ind = data["ind"]
|
||||
solver = data["solver"]
|
||||
|
||||
|
||||
@@ -60,12 +60,9 @@ class StricklersList(PamhyrModelList):
|
||||
return self.lst
|
||||
|
||||
def new(self, index):
|
||||
owner_scenario = (
|
||||
self._status.scenario_id if self._status is not None else -1
|
||||
)
|
||||
s = Stricklers(
|
||||
status=self._status,
|
||||
owner_scenario=owner_scenario
|
||||
owner_scenario=self._status.scenario_id
|
||||
)
|
||||
self.insert(index, s)
|
||||
self.modified()
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ logger = logging.getLogger()
|
||||
|
||||
|
||||
class Study(SQLModel):
|
||||
_version = "0.2.9"
|
||||
_version = "0.2.7"
|
||||
|
||||
_sub_classes = [
|
||||
Scenario,
|
||||
|
||||
@@ -1,756 +0,0 @@
|
||||
# WeatherParameters.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from tools import (
|
||||
trace, timer,
|
||||
old_pamhyr_date_to_timestamp,
|
||||
date_iso_to_timestamp,
|
||||
date_dmy_to_timestamp,
|
||||
)
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Data(SQLSubModel):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self,
|
||||
data0, data1,
|
||||
id: int = -1,
|
||||
types=[float, float],
|
||||
status=None,
|
||||
owner_scenario=-1):
|
||||
super(Data, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._types = types
|
||||
self._data = [data0, data1]
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE weather_parameters_data{ext} (
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
ind INTEGER NOT NULL,
|
||||
data0 TEXT NOT NULL,
|
||||
data1 TEXT NOT NULL,
|
||||
wp INTEGER,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(wp) REFERENCES weather_parameters(pamhyr_id),
|
||||
PRIMARY KEY(pamhyr_id, scenario)
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
|
||||
if major == "0" and (int(minor) < 2 or
|
||||
(int(minor) == 2 and int(release) < 7)):
|
||||
if not cls.is_table_exists(execute, "air_temperature_data"):
|
||||
cls._db_create(execute)
|
||||
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
wp = data["wp"]
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
values = execute(
|
||||
"SELECT pamhyr_id, deleted, " +
|
||||
"data0, data1, scenario " +
|
||||
"FROM weather_parameters_data " +
|
||||
f"WHERE wp = {wp._pamhyr_id} " +
|
||||
f"AND scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
|
||||
"ORDER BY ind ASC"
|
||||
)
|
||||
|
||||
for v in values:
|
||||
it = iter(v)
|
||||
|
||||
pid = next(it)
|
||||
deleted = next(it)
|
||||
data0 = wp._types[0](next(it))
|
||||
data1 = wp._types[1](next(it))
|
||||
owner_scenario = next(it)
|
||||
|
||||
nd = cls(
|
||||
data0, data1,
|
||||
id=pid,
|
||||
types=wp._types,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
nd.set_as_deleted()
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(nd)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
pid = self._pamhyr_id
|
||||
ind = data["ind"]
|
||||
data0 = self._db_format(str(self[0]))
|
||||
data1 = self._db_format(str(self[1]))
|
||||
wp = data["wp"]
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"weather_parameters_data (pamhyr_id, deleted, ind, " +
|
||||
"data0, data1, wp, scenario) " +
|
||||
f"VALUES ({pid}, {self._db_format(self.is_deleted())}, " +
|
||||
f"{ind}, '{self._db_format(data0)}', {self._db_format(data1)}, " +
|
||||
f"{wp._pamhyr_id}, {self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self._types[key](self._data[key])
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
self._data[key] = self._types[key](value)
|
||||
|
||||
def cloned(self):
|
||||
return Data(
|
||||
self[0], self[1],
|
||||
types=self._types,
|
||||
status=self._status
|
||||
)
|
||||
|
||||
|
||||
class WeatherParametersDefault(SQLSubModel):
|
||||
def __init__(self, type: str, value: float = 0.0,
|
||||
id: int = -1, status=None, owner_scenario=-1):
|
||||
super(WeatherParametersDefault, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = type
|
||||
self._value = float(value)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, type, value, scenario " +
|
||||
"FROM weather_parameters_default " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
)
|
||||
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
type = next(it)
|
||||
value = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
wp_default = cls(
|
||||
type=type,
|
||||
value=value,
|
||||
id=pid,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(wp_default)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"weather_parameters_default(" +
|
||||
"pamhyr_id, type, value, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, '{self._db_format(self._type)}', {self._value}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
return self._type
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self._value
|
||||
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
self._value = float(value)
|
||||
self.modified()
|
||||
|
||||
|
||||
class WeatherParameters(SQLSubModel):
|
||||
_sub_classes = [Data]
|
||||
|
||||
def __init__(self, id: int = -1,
|
||||
name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(WeatherParameters, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._name = name
|
||||
self._type = ""
|
||||
self._reach = None
|
||||
self._begin_section = None
|
||||
self._end_section = None
|
||||
self._data = []
|
||||
self._header = []
|
||||
self._types = [float, float]
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE weather_parameters{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
name TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
reach INTEGER,
|
||||
begin_section INTEGER,
|
||||
end_section INTEGER,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id),
|
||||
FOREIGN KEY(begin_section)
|
||||
REFERENCES geometry_profileXYZ(pamhyr_id),
|
||||
FOREIGN KEY(end_section)
|
||||
REFERENCES geometry_profileXYZ(pamhyr_id),
|
||||
PRIMARY KEY(pamhyr_id, scenario)
|
||||
)
|
||||
""")
|
||||
|
||||
execute(f"""
|
||||
CREATE TABLE weather_parameters_default{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
type TEXT NOT NULL,
|
||||
value FLOAT NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
primary KEY(pamhyr_id, scenario)
|
||||
)
|
||||
""")
|
||||
|
||||
if ext == "_tmp":
|
||||
return True
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _get_ctor_from_type(cls, t):
|
||||
from Model.WeatherParameters.WeatherParametersTypes import (
|
||||
NotDefined, WeatherParam, AirTemperature, SpecificHumidity,
|
||||
GlobalRadiation, ReferenceWindSpeed, GroundwaterTemperature,
|
||||
GroundwaterFlowRate, Albedo, ShadingCoefficient, CloudCoverFraction
|
||||
)
|
||||
|
||||
res = NotDefined
|
||||
if t == "WP":
|
||||
res = WeatherParam
|
||||
elif t == "AT":
|
||||
res = AirTemperature
|
||||
elif t == "SH":
|
||||
res = SpecificHumidity
|
||||
elif t == "GR":
|
||||
res = GlobalRadiation
|
||||
elif t == "RWS":
|
||||
res = ReferenceWindSpeed
|
||||
elif t == "GT":
|
||||
res = GroundwaterTemperature
|
||||
elif t == "GFR":
|
||||
res = GroundwaterFlowRate
|
||||
elif t == "ALB":
|
||||
res = Albedo
|
||||
elif t == "SC":
|
||||
res = ShadingCoefficient
|
||||
elif t == "CCF":
|
||||
res = CloudCoverFraction
|
||||
else:
|
||||
res = NotDefined
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and (int(minor) < 2 or
|
||||
(int(minor) == 2 and int(release) < 7)):
|
||||
if not cls.is_table_exists(execute, "air_temperature"):
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if not cls.is_table_exists(execute, "weather_parameters_default"):
|
||||
execute(f"""
|
||||
CREATE TABLE weather_parameters_default(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
type TEXT NOT NULL,
|
||||
value FLOAT NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
primary KEY(pamhyr_id, scenario)
|
||||
)
|
||||
""")
|
||||
|
||||
if not created:
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
edges = data["edges"]
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, name, type, " +
|
||||
"reach, begin_section, end_section, scenario " +
|
||||
"FROM weather_parameters " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
)
|
||||
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
deleted = next(it)
|
||||
name = next(it)
|
||||
t = next(it)
|
||||
reach = next(it)
|
||||
b_section = next(it)
|
||||
e_section = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
ctor = cls._get_ctor_from_type(t)
|
||||
wp = ctor(
|
||||
id=pid, name=name,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
wp.reach = None
|
||||
wp._begin_section = None
|
||||
wp._end_section = None
|
||||
|
||||
if reach not in (-1, None):
|
||||
wp.reach = next(
|
||||
(edge for edge in edges if edge.id == reach), None
|
||||
)
|
||||
profiles = (
|
||||
wp.reach.reach.profiles
|
||||
if wp.reach is not None else []
|
||||
)
|
||||
wp._begin_section = next(
|
||||
(profile for profile in profiles
|
||||
if profile.id == b_section), None
|
||||
)
|
||||
wp._end_section = next(
|
||||
(profile for profile in profiles
|
||||
if profile.id == e_section), None
|
||||
)
|
||||
|
||||
data["wp"] = wp
|
||||
wp._data = Data._db_load(execute, data=data)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(wp)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
data["wp"] = self
|
||||
|
||||
execute(
|
||||
"DELETE FROM weather_parameters_data " +
|
||||
f"WHERE wp = {self._pamhyr_id} " +
|
||||
f"AND scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
reach = None
|
||||
begin_section = None
|
||||
end_section = None
|
||||
|
||||
if self._reach is not None:
|
||||
reach = self._reach._pamhyr_id
|
||||
begin_section = self._begin_section._pamhyr_id
|
||||
end_section = self._end_section._pamhyr_id
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"weather_parameters(" +
|
||||
"pamhyr_id, deleted, name, type, " +
|
||||
"reach, begin_section, end_section, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"'{self._db_format(self._name)}', " +
|
||||
f"'{self._db_format(self._type)}', {reach}, " +
|
||||
f"{begin_section}, {end_section}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
ind = 0
|
||||
for d in self._data:
|
||||
data["ind"] = ind
|
||||
|
||||
d._db_save(execute, data)
|
||||
|
||||
ind += 1
|
||||
|
||||
return True
|
||||
|
||||
def _data_traversal(self,
|
||||
predicate=lambda obj, data: True,
|
||||
modifier=lambda obj, data: None,
|
||||
data={}):
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
for d in self._data:
|
||||
d._data_traversal(predicate, modifier, data)
|
||||
|
||||
def __len__(self):
|
||||
return len(
|
||||
list(
|
||||
filter(
|
||||
lambda el: not el.is_deleted(),
|
||||
self._data
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def compatibility(cls):
|
||||
return ["liquid", "solid", "suspenssion"]
|
||||
|
||||
@classmethod
|
||||
def time_convert(cls, data):
|
||||
if type(data) is str:
|
||||
if data.count("-") == 2:
|
||||
return date_iso_to_timestamp(data)
|
||||
if data.count("/") == 2:
|
||||
return date_dmy_to_timestamp(data)
|
||||
if data.count(":") == 3:
|
||||
return old_pamhyr_date_to_timestamp(data)
|
||||
if data.count(":") == 2:
|
||||
return old_pamhyr_date_to_timestamp("00:" + data)
|
||||
if data.count(".") == 1:
|
||||
return round(float(data))
|
||||
|
||||
return int(data)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
if self._name == "":
|
||||
return f"LC #{self.id}"
|
||||
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._name = name
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
return self._type
|
||||
|
||||
@property
|
||||
def reach(self):
|
||||
return self._reach
|
||||
|
||||
@reach.setter
|
||||
def reach(self, reach):
|
||||
self._reach = reach
|
||||
self._begin_section = None
|
||||
self._end_section = None
|
||||
|
||||
if reach is not None:
|
||||
profiles = reach.reach.profiles
|
||||
if profiles:
|
||||
self._begin_section = profiles[0]
|
||||
self._end_section = profiles[-1]
|
||||
|
||||
self.modified()
|
||||
|
||||
def has_reach(self):
|
||||
return self._reach is not None
|
||||
|
||||
@property
|
||||
def begin_rk(self):
|
||||
if self._begin_section is None:
|
||||
return 0
|
||||
|
||||
return self._begin_section.rk
|
||||
|
||||
@property
|
||||
def begin_section(self):
|
||||
return self._begin_section
|
||||
|
||||
@begin_section.setter
|
||||
def begin_section(self, section):
|
||||
self._begin_section = section
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def end_rk(self):
|
||||
if self._end_section is None:
|
||||
return 0
|
||||
|
||||
return self._end_section.rk
|
||||
|
||||
@property
|
||||
def end_section(self):
|
||||
return self._end_section
|
||||
|
||||
@end_section.setter
|
||||
def end_section(self, section):
|
||||
self._end_section = section
|
||||
self.modified()
|
||||
|
||||
def cloned_for(self, reach, begin_section, end_section):
|
||||
new = type(self)(name=self._name, status=self._status)
|
||||
new._reach = reach
|
||||
new._begin_section = begin_section
|
||||
new._end_section = end_section
|
||||
new._data = [data.cloned() for data in self.data]
|
||||
new.modified()
|
||||
return new
|
||||
|
||||
@property
|
||||
def header(self):
|
||||
return self._header.copy()
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return list(
|
||||
filter(
|
||||
lambda el: not el.is_deleted(),
|
||||
self._data
|
||||
)
|
||||
)
|
||||
|
||||
def get_type_column(self, column):
|
||||
if 0 <= column < 2:
|
||||
return self._types[column]
|
||||
return None
|
||||
|
||||
@property
|
||||
def _default_0(self):
|
||||
return self._types[0](0)
|
||||
|
||||
@property
|
||||
def _default_1(self):
|
||||
return self._types[1](0.0)
|
||||
|
||||
def is_define(self):
|
||||
return self._data is not None
|
||||
|
||||
def new_from_data(self, header, data):
|
||||
new_0 = self._default_0
|
||||
new_1 = self._default_1
|
||||
|
||||
def convert(column, value, default):
|
||||
if value.strip() == "":
|
||||
return default
|
||||
return self._types[column](value.replace(",", "."))
|
||||
|
||||
if len(header) != 0:
|
||||
for i in [0, 1]:
|
||||
for j in range(len(header)):
|
||||
if self._header[i] == header[j] and j < len(data):
|
||||
if i == 0:
|
||||
new_0 = convert(i, data[j], new_0)
|
||||
else:
|
||||
new_1 = convert(i, data[j], new_1)
|
||||
else:
|
||||
if len(data) > 0:
|
||||
new_0 = convert(0, data[0], new_0)
|
||||
if len(data) > 1:
|
||||
new_1 = convert(1, data[1], new_1)
|
||||
|
||||
return Data(new_0, new_1, status=self._status)
|
||||
|
||||
def add(self, index: int):
|
||||
value = Data(self._default_0, self._default_1, status=self._status)
|
||||
self._data.insert(index, value)
|
||||
self.modified()
|
||||
return value
|
||||
|
||||
def insert(self, index: int, value):
|
||||
self._data.insert(index, value)
|
||||
self.modified()
|
||||
|
||||
def delete_i(self, indexes):
|
||||
self._data = list(
|
||||
map(
|
||||
lambda e: e[1],
|
||||
filter(
|
||||
lambda e: e[0] not in indexes,
|
||||
enumerate(self.data)
|
||||
)
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
|
||||
def set_as_deleted_i(self, indexes):
|
||||
for i in indexes:
|
||||
self._data[i].set_as_deleted()
|
||||
self.modified()
|
||||
|
||||
def set_as_not_deleted_i(self, indexes):
|
||||
for i in indexes:
|
||||
self._data[i].set_as_not_deleted()
|
||||
self.modified()
|
||||
|
||||
def delete(self, els):
|
||||
self._data = list(
|
||||
filter(
|
||||
lambda e: e not in els,
|
||||
self.data
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
|
||||
def sort(self, _reverse=False, key=None):
|
||||
if key is None:
|
||||
self._data.sort(reverse=_reverse)
|
||||
else:
|
||||
self._data.sort(reverse=_reverse, key=key)
|
||||
self.modified()
|
||||
|
||||
def get_i(self, index):
|
||||
return self.data[index]
|
||||
|
||||
def get_range(self, _range):
|
||||
lst = []
|
||||
for r in _range:
|
||||
lst.append(r)
|
||||
return lst
|
||||
|
||||
def _set_i_c_v(self, index, column, value):
|
||||
v = self._data[index]
|
||||
v[column] = self._types[column](value)
|
||||
self._data[index] = v
|
||||
self.modified()
|
||||
|
||||
def set_i_0(self, index: int, value):
|
||||
self._set_i_c_v(index, 0, value)
|
||||
|
||||
def set_i_1(self, index: int, value):
|
||||
self._set_i_c_v(index, 1, value)
|
||||
|
||||
@timer
|
||||
def convert(self, cls):
|
||||
new = cls(name=self.name, status=self._status)
|
||||
new.reach = self.reach
|
||||
new.begin_section = self.begin_section
|
||||
new.end_section = self.end_section
|
||||
|
||||
for i, _ in enumerate(self.data):
|
||||
new.add(i)
|
||||
|
||||
for i in [0, 1]:
|
||||
for j in [0, 1]:
|
||||
if self._header[i] == new.header[j]:
|
||||
for ind, v in self.data:
|
||||
try:
|
||||
new._set_i_c_v(ind, j, v[i])
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
|
||||
self.modified()
|
||||
return new
|
||||
|
||||
def move_up(self, index):
|
||||
if index < len(self):
|
||||
next = index - 1
|
||||
d = self._data
|
||||
d[index], d[next] = d[next], d[index]
|
||||
self.modified()
|
||||
|
||||
def move_down(self, index):
|
||||
if index >= 0:
|
||||
prev = index + 1
|
||||
d = self._data
|
||||
d[index], d[prev] = d[prev], d[index]
|
||||
self.modified()
|
||||
@@ -1,234 +0,0 @@
|
||||
# WeatherParametersList.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 copy import copy
|
||||
from tools import trace, timer
|
||||
|
||||
from Model.Tools.PamhyrListExt import PamhyrModelList
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
|
||||
from Model.WeatherParameters.WeatherParameters import (
|
||||
WeatherParameters,
|
||||
WeatherParametersDefault,
|
||||
)
|
||||
from Model.WeatherParameters.WeatherParametersTypes import (
|
||||
NotDefined, WeatherParam, AirTemperature, SpecificHumidity,
|
||||
GlobalRadiation, ReferenceWindSpeed, GroundwaterTemperature,
|
||||
GroundwaterFlowRate, Albedo, ShadingCoefficient, CloudCoverFraction
|
||||
)
|
||||
|
||||
|
||||
class WeatherParametersList(PamhyrModelList):
|
||||
_sub_classes = [
|
||||
WeatherParameters,
|
||||
]
|
||||
_default_types = [
|
||||
"AT", "SH", "GR", "RWS", "GT", "GFR", "ALB", "SC", "CCF"
|
||||
]
|
||||
_default_values = {
|
||||
"AT": 20.0,
|
||||
"SH": 0.001,
|
||||
"GR": 10.0,
|
||||
"RWS": 1.0,
|
||||
"GT": 0.0,
|
||||
"GFR": 0.0,
|
||||
"ALB": 0.06,
|
||||
"SC": 0.15,
|
||||
"CCF": 0.5,
|
||||
}
|
||||
|
||||
def __init__(self, status=None):
|
||||
super(WeatherParametersList, self).__init__(status=status)
|
||||
self._default = []
|
||||
self._init_missing_default_values()
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = cls(status=data['status'])
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
new._lst = WeatherParameters._db_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
data['loaded_pid'] = set()
|
||||
new._default = WeatherParametersDefault._db_load(
|
||||
execute, data
|
||||
)
|
||||
new._init_missing_default_values()
|
||||
new._sort_default_values()
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
execute(
|
||||
"DELETE FROM weather_parameters " +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
execute(
|
||||
"DELETE FROM weather_parameters_data " +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
execute(
|
||||
"DELETE FROM weather_parameters_default " +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
for wp in self._lst:
|
||||
wp._db_save(execute, data=data)
|
||||
|
||||
for wp_default in self._default:
|
||||
wp_default._db_save(execute, data=data)
|
||||
|
||||
return True
|
||||
|
||||
def _data_traversal(self,
|
||||
predicate=lambda obj, data: True,
|
||||
modifier=lambda obj, data: None,
|
||||
data={}):
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
for el in self._lst:
|
||||
el._data_traversal(predicate, modifier, data)
|
||||
|
||||
for el in self._default:
|
||||
el._data_traversal(predicate, modifier, data)
|
||||
|
||||
def _init_missing_default_values(self):
|
||||
existing = [wp_default.type for wp_default in self.default]
|
||||
for type in self._default_types:
|
||||
if type not in existing:
|
||||
self._default.append(
|
||||
WeatherParametersDefault(
|
||||
type=type,
|
||||
value=self._default_values[type],
|
||||
status=self._status,
|
||||
)
|
||||
)
|
||||
|
||||
self._sort_default_values()
|
||||
|
||||
def _sort_default_values(self):
|
||||
self._default.sort(
|
||||
key=lambda wp_default: self._default_types.index(wp_default.type)
|
||||
if wp_default.type in self._default_types
|
||||
else len(self._default_types)
|
||||
)
|
||||
|
||||
def new(self, index, type="ND"):
|
||||
if type == "AT":
|
||||
n = AirTemperature(status=self._status)
|
||||
elif type == "SH":
|
||||
n = SpecificHumidity(status=self._status)
|
||||
elif type == "GR":
|
||||
n = GlobalRadiation(status=self._status)
|
||||
elif type == "RWS":
|
||||
n = ReferenceWindSpeed(status=self._status)
|
||||
elif type == "GT":
|
||||
n = GroundwaterTemperature(status=self._status)
|
||||
elif type == "GFR":
|
||||
n = GroundwaterFlowRate(status=self._status)
|
||||
elif type == "ALB":
|
||||
n = Albedo(status=self._status)
|
||||
elif type == "SC":
|
||||
n = ShadingCoefficient(status=self._status)
|
||||
elif type == "CCF":
|
||||
n = CloudCoverFraction(status=self._status)
|
||||
else:
|
||||
n = NotDefined(status=self._status)
|
||||
self._lst.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
profiles = reach.reach.profiles
|
||||
split_index = profiles.index(profile)
|
||||
parts = [
|
||||
(
|
||||
reach1,
|
||||
0,
|
||||
split_index,
|
||||
dict(zip(
|
||||
profiles[:split_index + 1],
|
||||
reach1.reach.profiles
|
||||
))
|
||||
),
|
||||
(
|
||||
reach2,
|
||||
split_index,
|
||||
len(profiles) - 1,
|
||||
dict(zip(
|
||||
profiles[split_index:],
|
||||
reach2.reach.profiles
|
||||
))
|
||||
),
|
||||
]
|
||||
weather_parameters = [
|
||||
weather_parameter
|
||||
for weather_parameter in self.lst
|
||||
if weather_parameter.reach is reach
|
||||
]
|
||||
clones = []
|
||||
|
||||
for weather_parameter in weather_parameters:
|
||||
if (weather_parameter.begin_section not in profiles or
|
||||
weather_parameter.end_section not in profiles):
|
||||
continue
|
||||
|
||||
begin = profiles.index(weather_parameter.begin_section)
|
||||
end = profiles.index(weather_parameter.end_section)
|
||||
lower, upper = sorted((begin, end))
|
||||
reverse = begin > end
|
||||
|
||||
for new_reach, part_lower, part_upper, sections in parts:
|
||||
clipped_lower = max(lower, part_lower)
|
||||
clipped_upper = min(upper, part_upper)
|
||||
if clipped_lower > clipped_upper:
|
||||
continue
|
||||
|
||||
begin_index = clipped_upper if reverse else clipped_lower
|
||||
end_index = clipped_lower if reverse else clipped_upper
|
||||
clones.append(weather_parameter.cloned_for(
|
||||
new_reach,
|
||||
sections[profiles[begin_index]],
|
||||
sections[profiles[end_index]]
|
||||
))
|
||||
|
||||
if clones:
|
||||
self._lst.extend(clones)
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def Weather_Parameters_List(self):
|
||||
return self.lst
|
||||
|
||||
@property
|
||||
def default(self):
|
||||
return self._default.copy()
|
||||
|
||||
def default_for_type(self, type):
|
||||
for wp_default in self.default:
|
||||
if wp_default.type == type:
|
||||
return wp_default
|
||||
return None
|
||||
@@ -1,171 +0,0 @@
|
||||
# LateralContributionTypes.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 Model.Except import NotImplementedMethodeError
|
||||
|
||||
from Model.WeatherParameters.WeatherParameters import WeatherParameters
|
||||
|
||||
|
||||
class NotDefined(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(NotDefined, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "ND"
|
||||
self._header = ["x", "y"]
|
||||
|
||||
@property
|
||||
def _default_0(self):
|
||||
return 0.0
|
||||
|
||||
|
||||
class WeatherParam(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(WeatherParam, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "WP"
|
||||
self._header = ["time", "value"]
|
||||
self._types = [WeatherParam.time_convert, float]
|
||||
|
||||
@classmethod
|
||||
def compatibility(cls):
|
||||
return ["liquid"]
|
||||
|
||||
|
||||
class AirTemperature(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(AirTemperature, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "AT"
|
||||
self._header = ["time", "temperature"]
|
||||
self._types = [AirTemperature.time_convert, float]
|
||||
|
||||
|
||||
class SpecificHumidity(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(SpecificHumidity, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "SH"
|
||||
self._header = ["time", "humidity"]
|
||||
self._types = [SpecificHumidity.time_convert, float]
|
||||
|
||||
|
||||
class GlobalRadiation(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(GlobalRadiation, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "GR"
|
||||
self._header = ["time", "radiation"]
|
||||
self._types = [GlobalRadiation.time_convert, float]
|
||||
|
||||
|
||||
class ReferenceWindSpeed(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(ReferenceWindSpeed, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "RWS"
|
||||
self._header = ["time", "wind speed"]
|
||||
self._types = [ReferenceWindSpeed.time_convert, float]
|
||||
|
||||
|
||||
class GroundwaterTemperature(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(GroundwaterTemperature, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "GT"
|
||||
self._header = ["time", "temperature"]
|
||||
self._types = [GroundwaterTemperature.time_convert, float]
|
||||
|
||||
|
||||
class GroundwaterFlowRate(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(GroundwaterFlowRate, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "GFR"
|
||||
self._header = ["time", "discharge"]
|
||||
self._types = [GroundwaterFlowRate.time_convert, float]
|
||||
|
||||
|
||||
class Albedo(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(Albedo, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "ALB"
|
||||
self._header = ["time", "albedo"]
|
||||
self._types = [Albedo.time_convert, float]
|
||||
|
||||
|
||||
class ShadingCoefficient(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(ShadingCoefficient, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "SC"
|
||||
self._header = ["time", "shading coefficient"]
|
||||
self._types = [ShadingCoefficient.time_convert, float]
|
||||
|
||||
|
||||
class CloudCoverFraction(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(CloudCoverFraction, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "CCF"
|
||||
self._header = ["time", "cloud cover fraction"]
|
||||
self._types = [CloudCoverFraction.time_convert, float]
|
||||
@@ -23,8 +23,6 @@ import tempfile
|
||||
from Model.Status import StudyStatus
|
||||
from Model.Study import Study
|
||||
from Model.River import River
|
||||
from Model.LateralContribution.LateralContributionTypes import LateralContrib
|
||||
from Model.HydraulicStructures.Basic.Types import DischargeWeir
|
||||
|
||||
|
||||
class StudyTestCase(unittest.TestCase):
|
||||
@@ -64,31 +62,6 @@ class StudyTestCase(unittest.TestCase):
|
||||
study = Study.new("foo", "bar")
|
||||
self.assertNotEqual(study.river, None)
|
||||
|
||||
def test_save_open_study_weather_parameters_default(self):
|
||||
study = Study.new("foo", "bar")
|
||||
defaults = study.river.weather_parameters.default
|
||||
|
||||
self.assertEqual(len(defaults), 9)
|
||||
self.assertEqual(
|
||||
[default.value for default in defaults],
|
||||
[20.0, 0.001, 10.0, 1.0, 0.0, 0.0, 0.06, 0.15, 0.5]
|
||||
)
|
||||
defaults[0].value = 12.5
|
||||
|
||||
dir = tempfile.mkdtemp()
|
||||
f = os.path.join(dir, "foo.pamhyr")
|
||||
|
||||
study.filename = f
|
||||
study.save()
|
||||
study.close()
|
||||
|
||||
study = Study.open(f)
|
||||
defaults = study.river.weather_parameters.default
|
||||
|
||||
self.assertEqual(len(defaults), 9)
|
||||
self.assertEqual(defaults[0].type, "AT")
|
||||
self.assertEqual(defaults[0].value, 12.5)
|
||||
|
||||
|
||||
class StudyScenarioTestCase(unittest.TestCase):
|
||||
def test_create_study(self):
|
||||
@@ -289,89 +262,3 @@ class RiverTestCase(unittest.TestCase):
|
||||
edges = river.edges()
|
||||
self.assertEqual(edges[0], e0)
|
||||
self.assertEqual(edges[1], e1)
|
||||
|
||||
def test_split_reach_splits_initial_conditions(self):
|
||||
status = StudyStatus()
|
||||
river = River(status=status)
|
||||
node1 = river.add_node()
|
||||
node2 = river.add_node(x=40.0)
|
||||
reach = river.add_edge(node1, node2)
|
||||
|
||||
profiles = []
|
||||
for index in range(5):
|
||||
profile = reach.reach.insert(index)
|
||||
profile.rk = index * 10.0
|
||||
profile.insert(0)
|
||||
profiles.append(profile)
|
||||
|
||||
initial_conditions = river.initial_conditions.get(reach)
|
||||
for index, profile in enumerate(profiles):
|
||||
data = initial_conditions.new_from_data(
|
||||
profile.rk,
|
||||
discharge=100.0 + index,
|
||||
elevation=10.0 + index,
|
||||
)
|
||||
initial_conditions.insert(index, data)
|
||||
|
||||
reach1, reach2 = river._split_reach(reach, profiles[2])
|
||||
conditions1 = river.initial_conditions.get(reach1).data
|
||||
conditions2 = river.initial_conditions.get(reach2).data
|
||||
|
||||
self.assertEqual(
|
||||
[data["discharge"] for data in conditions1],
|
||||
[100.0, 101.0, 102.0]
|
||||
)
|
||||
self.assertEqual(
|
||||
[data["discharge"] for data in conditions2],
|
||||
[102.0, 103.0, 104.0]
|
||||
)
|
||||
self.assertEqual(
|
||||
[data["section"] for data in conditions1],
|
||||
reach1.reach.profiles
|
||||
)
|
||||
self.assertEqual(
|
||||
[data["section"] for data in conditions2],
|
||||
reach2.reach.profiles
|
||||
)
|
||||
self.assertTrue(all(
|
||||
data._reach is reach1 for data in conditions1
|
||||
))
|
||||
self.assertTrue(all(
|
||||
data._reach is reach2 for data in conditions2
|
||||
))
|
||||
|
||||
def test_split_reach_keeps_partial_initial_conditions_in_scope(self):
|
||||
status = StudyStatus()
|
||||
river = River(status=status)
|
||||
node1 = river.add_node()
|
||||
node2 = river.add_node(x=40.0)
|
||||
reach = river.add_edge(node1, node2)
|
||||
|
||||
profiles = []
|
||||
for index in range(5):
|
||||
profile = reach.reach.insert(index)
|
||||
profile.rk = index * 10.0
|
||||
profile.insert(0)
|
||||
profiles.append(profile)
|
||||
|
||||
initial_conditions = river.initial_conditions.get(reach)
|
||||
for index in (1, 3):
|
||||
data = initial_conditions.new_from_data(
|
||||
profiles[index].rk,
|
||||
discharge=100.0 + index,
|
||||
elevation=10.0 + index,
|
||||
)
|
||||
initial_conditions.insert(len(initial_conditions.data), data)
|
||||
|
||||
reach1, reach2 = river._split_reach(reach, profiles[2])
|
||||
|
||||
self.assertEqual(
|
||||
[data["discharge"]
|
||||
for data in river.initial_conditions.get(reach1).data],
|
||||
[101.0]
|
||||
)
|
||||
self.assertEqual(
|
||||
[data["discharge"]
|
||||
for data in river.initial_conditions.get(reach2).data],
|
||||
[103.0]
|
||||
)
|
||||
@@ -55,6 +55,7 @@ class Modules(IterableFlag):
|
||||
RESERVOIR = auto()
|
||||
SEDIMENT_LAYER = auto()
|
||||
ADDITIONAL_FILES = auto()
|
||||
OUTPUT_RK = auto()
|
||||
GEOTIFF = auto()
|
||||
|
||||
# Results
|
||||
@@ -80,6 +81,7 @@ class Modules(IterableFlag):
|
||||
cls.ADDITIONAL_FILES,
|
||||
cls.RESULTS,
|
||||
cls.WINDOW_LIST,
|
||||
cls.OUTPUT_RK,
|
||||
cls.GEOTIFF
|
||||
]
|
||||
|
||||
|
||||
+1
-2
@@ -75,8 +75,7 @@ class ScriptRun(AScript):
|
||||
os.path.dirname(study.filename),
|
||||
"_PAMHYR_",
|
||||
study.name.replace(" ", "_"),
|
||||
solver.name.replace(" ", "_"),
|
||||
study.status.scenario.workdir(),
|
||||
solver.name.replace(" ", "_")
|
||||
)
|
||||
os.makedirs(workdir, exist_ok=True)
|
||||
logger.info(f"Set working dir to {workdir}")
|
||||
|
||||
@@ -79,7 +79,7 @@ class AbstractSolver(object):
|
||||
def default_parameters(cls):
|
||||
lst = [
|
||||
("all_init_time", "000:00:00:00"),
|
||||
("all_final_time", "10:00:00:00"),
|
||||
("all_final_time", "999:99:00:00"),
|
||||
("all_timestep", "300.0"),
|
||||
]
|
||||
|
||||
|
||||
+60
-48
@@ -35,6 +35,10 @@ from Solver.CommandLine import CommandLineSolver
|
||||
from Model.Results.ResultsAdisTS import Results
|
||||
from Model.Results.River.River import River, Reach, Profile
|
||||
|
||||
from Checker.Adists import (
|
||||
AdistsOutputRKChecker,
|
||||
)
|
||||
|
||||
from itertools import chain
|
||||
|
||||
logger = logging.getLogger()
|
||||
@@ -86,7 +90,11 @@ class AdisTS(CommandLineSolver):
|
||||
|
||||
@classmethod
|
||||
def checkers(cls):
|
||||
return []
|
||||
lst = [
|
||||
AdistsOutputRKChecker(),
|
||||
]
|
||||
|
||||
return lst
|
||||
|
||||
##########
|
||||
# Export #
|
||||
@@ -109,6 +117,9 @@ class AdisTS(CommandLineSolver):
|
||||
_nodes_names = {}
|
||||
_nodes_views = set()
|
||||
|
||||
def get_reach_name(self, reach):
|
||||
return f"Reach_{reach.pamhyr_id:>3}".replace(" ", "0")
|
||||
|
||||
def get_node_name(self, node):
|
||||
"""Generate a 3 char name for node
|
||||
|
||||
@@ -171,7 +182,7 @@ class AdisTS(CommandLineSolver):
|
||||
# Write header
|
||||
edges = study.river.enable_edges()
|
||||
for edge in edges:
|
||||
name = self.get_reach_name(edge)
|
||||
name = f"Reach_{edge.id + 1:>3}".replace(" ", "0")
|
||||
|
||||
with adists_file_open(
|
||||
os.path.join(repertory, "net", f"{name}.ST"),
|
||||
@@ -180,7 +191,7 @@ class AdisTS(CommandLineSolver):
|
||||
files.append(str(os.path.join("net", f"{name}.ST")))
|
||||
|
||||
cnt_num = 1
|
||||
for profile in edge.reach.enabled_profiles:
|
||||
for profile in edge.reach.profiles:
|
||||
self._export_ST_profile_header(
|
||||
f, files, profile, cnt_num
|
||||
)
|
||||
@@ -266,7 +277,7 @@ class AdisTS(CommandLineSolver):
|
||||
edges = study.river.enable_edges()
|
||||
|
||||
for e in edges:
|
||||
name = self.get_reach_name(e)
|
||||
name = f"Reach_{e.id + 1:>3}".replace(" ", "0")
|
||||
id = name
|
||||
|
||||
n1 = f"{self.get_node_name(e.node1):3}".replace(" ", "x")
|
||||
@@ -335,7 +346,7 @@ class AdisTS(CommandLineSolver):
|
||||
|
||||
return coeff.minor, coeff.medium
|
||||
|
||||
for j, profile in enumerate(edge.reach.enabled_profiles):
|
||||
for j, profile in enumerate(edge.reach.profiles):
|
||||
coef_min, coef_moy = get_stricklers_from_rk(profile.rk,
|
||||
lst)
|
||||
f.write(
|
||||
@@ -355,19 +366,13 @@ class AdisTS(CommandLineSolver):
|
||||
if qlog is not None:
|
||||
qlog.put("Export REP file")
|
||||
|
||||
mage_path = (mage_rep if os.path.isabs(mage_rep) else os.path.join(
|
||||
os.path.abspath(os.path.join(repertory, os.pardir)),
|
||||
mage_rep,
|
||||
))
|
||||
relative_mage_path = os.path.relpath(mage_path, repertory)
|
||||
|
||||
# Write header
|
||||
with adists_file_open(
|
||||
os.path.join(
|
||||
repertory, f"{name}.REP"
|
||||
), "w+"
|
||||
) as f:
|
||||
path = os.path.join(relative_mage_path, name)
|
||||
path = os.path.join("..", mage_rep, name)
|
||||
f.write(f"NET {name}.NET\n")
|
||||
f.write(f"REP {path}.REP\n")
|
||||
|
||||
@@ -382,7 +387,9 @@ class AdisTS(CommandLineSolver):
|
||||
|
||||
# fake mage_fin.ini:
|
||||
|
||||
self._export_fake_INI(study, mage_path,
|
||||
path_mage = os.path.join(os.path.abspath(
|
||||
os.path.join(repertory, os.pardir)), mage_rep)
|
||||
self._export_fake_INI(study, path_mage,
|
||||
qlog, name=name)
|
||||
|
||||
# path_mage_net = os.path.join(os.path.abspath(
|
||||
@@ -446,8 +453,7 @@ class AdisTS(CommandLineSolver):
|
||||
_nodes_views = set()
|
||||
|
||||
def get_reach_name(self, reach):
|
||||
index = self._study.river.get_edge_id(reach) + 1
|
||||
return f"Reach_{index:03d}"
|
||||
return f"Reach_{reach.pamhyr_id:>3}".replace(" ", "0")
|
||||
|
||||
#################################
|
||||
# Adis-TS in weak coupling mode #
|
||||
@@ -501,13 +507,12 @@ class AdisTSwc(AdisTS):
|
||||
study, pollutant._data, f, qlog
|
||||
)
|
||||
|
||||
POL_ICs = next((
|
||||
ic for ic in
|
||||
POL_ICs = next(filter(
|
||||
lambda ic: ic.pollutant == pollutant.id,
|
||||
study.river.ic_adists.Initial_Conditions_List
|
||||
if ic.pollutant == pollutant.id
|
||||
), None)
|
||||
))
|
||||
|
||||
if POL_ICs is not None and POL_ICs.concentration is not None:
|
||||
if POL_ICs.concentration is not None:
|
||||
f.write(f"file_ini = {name}.INI\n")
|
||||
self._export_ICs_AdisTS(
|
||||
study, repertory, POL_ICs, qlog, name
|
||||
@@ -547,18 +552,15 @@ class AdisTSwc(AdisTS):
|
||||
os.path.join(repertory, f"{POL_name}.ALD"), "w+"
|
||||
) as f:
|
||||
for LC in POL_LC:
|
||||
reach = next((
|
||||
edge for edge in study.river.enable_edges()
|
||||
if edge.id == LC.reach
|
||||
), None)
|
||||
if reach is None:
|
||||
continue
|
||||
reach = next(filter(
|
||||
lambda edge: edge.id == LC.edge, study.river.enable_edges()
|
||||
)) # .name
|
||||
reach_name = self.get_reach_name(reach)
|
||||
f.write(f"${reach_name} {LC.begin_rk} {LC.end_rk}\n")
|
||||
f.write(f"*temps |débit massique (kg/s)\n")
|
||||
f.write(f"*---------++++++++++\n")
|
||||
|
||||
for LC_data in LC.data:
|
||||
for LC_data in LC._data:
|
||||
tmp = timestamp_to_old_pamhyr_date_adists(int(LC_data[0]))
|
||||
f.write(" ".join((f"{tmp}",
|
||||
f"{LC_data[1]}\n")))
|
||||
@@ -575,10 +577,9 @@ class AdisTSwc(AdisTS):
|
||||
repertory, f"{POL_name}.CDT"), "w+"
|
||||
) as f:
|
||||
for BC in POL_BC:
|
||||
node = next((node for node in study.river.nodes()
|
||||
if node.id == BC.node), None)
|
||||
if node is None:
|
||||
continue
|
||||
node = next(filter(
|
||||
lambda x: x.id == BC.node, study.river._nodes
|
||||
))
|
||||
f.write(f"${self.get_node_name(node)}\n")
|
||||
|
||||
if BC.type == "Concentration":
|
||||
@@ -590,7 +591,7 @@ class AdisTSwc(AdisTS):
|
||||
f.write(f"*JJ:HH:MM | (kg/s)\n")
|
||||
f.write(f"*---------++++++++++\n")
|
||||
|
||||
for BC_data in BC.data:
|
||||
for BC_data in BC._data:
|
||||
tmp = timestamp_to_old_pamhyr_date_adists(int(BC_data[0]))
|
||||
f.write(" ".join((f"{tmp}",
|
||||
f"{BC_data[1]}\n")))
|
||||
@@ -624,9 +625,6 @@ class AdisTSwc(AdisTS):
|
||||
|
||||
edges = study.river.enable_edges()
|
||||
for ic_spec in pol_ics_spec_data:
|
||||
if ic_spec.is_deleted():
|
||||
continue
|
||||
|
||||
id_reach = ic_spec.reach
|
||||
reach = next((x for x in edges if x.id == id_reach), None)
|
||||
if reach is None:
|
||||
@@ -650,9 +648,7 @@ class AdisTSwc(AdisTS):
|
||||
list_characteristics = ["type", "diametre", "rho", "porosity",
|
||||
"cdc_riv", "cdc_cas", "apd", "ac", "bc"]
|
||||
|
||||
pol_data = [data for data in pol_data if not data.is_deleted()]
|
||||
|
||||
if pol_data and len(list_characteristics) <= len(pol_data[0]):
|
||||
if len(list_characteristics) <= (len(pol_data[0])):
|
||||
for i in range(len(list_characteristics)):
|
||||
f.write(f"{list_characteristics[i]} = {pol_data[0][i]}\n")
|
||||
|
||||
@@ -681,9 +677,6 @@ class AdisTSwc(AdisTS):
|
||||
def _export_d90_spec(self, study, d90_spec_data, f, qlog, name="0"):
|
||||
|
||||
for d90_spec in d90_spec_data:
|
||||
if d90_spec.is_deleted():
|
||||
continue
|
||||
|
||||
if (d90_spec.name is None
|
||||
or d90_spec.reach is None
|
||||
or d90_spec.start_rk is None
|
||||
@@ -743,9 +736,6 @@ class AdisTSwc(AdisTS):
|
||||
def _export_dif_spec(self, study, dif_spec_data, f, qlog, name="0"):
|
||||
|
||||
for dif_spec in dif_spec_data:
|
||||
if dif_spec.is_deleted():
|
||||
continue
|
||||
|
||||
if (dif_spec.reach is None
|
||||
or dif_spec.start_rk is None
|
||||
or dif_spec.end_rk is None
|
||||
@@ -813,8 +803,33 @@ class AdisTSwc(AdisTS):
|
||||
if name != "command_line_arguments":
|
||||
f.write(f"{dict_names[name]} = {value}\n")
|
||||
|
||||
outputrks = study.river.Output_rk_adists.OutputRK_List
|
||||
|
||||
for outputrk in outputrks:
|
||||
self._export_outputrk(study, outputrk, f, qlog)
|
||||
|
||||
return files
|
||||
|
||||
def _export_outputrk(self, study, outputrk, f, qlog, name="0"):
|
||||
if (outputrk.reach is None
|
||||
or outputrk.rk is None
|
||||
or outputrk.title is None):
|
||||
return
|
||||
|
||||
edges = study.river.enable_edges()
|
||||
|
||||
id_edges = list(map(lambda x: x.id, edges))
|
||||
|
||||
id_reach = outputrk.reach
|
||||
reach = next((x for x in edges if x.id == id_reach), None)
|
||||
rk = outputrk.rk
|
||||
title = outputrk.title
|
||||
|
||||
if reach is None:
|
||||
return
|
||||
|
||||
f.write(f"output = {study.river.get_edge_id(reach)+1} {rk} {title}\n")
|
||||
|
||||
@timer
|
||||
def read_bin(self, study, repertory, results, qlog=None, name="0"):
|
||||
|
||||
@@ -861,10 +876,7 @@ class AdisTSwc(AdisTS):
|
||||
|
||||
for i in range(ibmax):
|
||||
# Add results reach to reach list
|
||||
geometry_reach = study.river.enable_edges()[i].reach
|
||||
r = results.river.add(
|
||||
i, profiles=geometry_reach.enabled_profiles
|
||||
)
|
||||
r = results.river.add(i)
|
||||
reachs.append(r)
|
||||
|
||||
is1[i] = data[2 * i] - 1 # first section of reach i
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+12
-26
@@ -65,8 +65,6 @@ class Mage(CommandLineSolver):
|
||||
self._cmd_solver = "@path @input -o @output"
|
||||
self._cmd_output = ""
|
||||
|
||||
self._reset_node_names()
|
||||
|
||||
@classmethod
|
||||
def default_parameters(cls):
|
||||
lst = super(Mage, cls).default_parameters()
|
||||
@@ -127,15 +125,12 @@ class Mage(CommandLineSolver):
|
||||
|
||||
_l_alph = len(_alph)
|
||||
|
||||
def _reset_node_names(self):
|
||||
"""Reset the node-name registry for a new export."""
|
||||
self._nodes_cnt = 0
|
||||
self._nodes_names = {}
|
||||
self._nodes_views = set()
|
||||
_nodes_cnt = 0
|
||||
_nodes_names = {}
|
||||
_nodes_views = set()
|
||||
|
||||
def get_reach_name(self, reach):
|
||||
index = self._study.river.get_edge_id(reach) + 1
|
||||
return f"Reach_{index:03d}"
|
||||
return f"Reach_{reach.pamhyr_id:>3}".replace(" ", "0")
|
||||
|
||||
def get_node_name(self, node):
|
||||
"""Generate a 3 char name for node
|
||||
@@ -215,7 +210,7 @@ class Mage(CommandLineSolver):
|
||||
# Write header
|
||||
edges = study.river.enable_edges()
|
||||
for edge in edges:
|
||||
name = self.get_reach_name(edge)
|
||||
name = f"Reach_{edge.pamhyr_id:>3}".replace(" ", "0")
|
||||
|
||||
with mage_file_open(
|
||||
os.path.join(repertory, "net", f"{name}.ST"),
|
||||
@@ -224,7 +219,7 @@ class Mage(CommandLineSolver):
|
||||
files.append(str(os.path.join("net", f"{name}.ST")))
|
||||
|
||||
cnt_num = 1
|
||||
for profile in edge.reach.enabled_profiles:
|
||||
for profile in edge.reach.profiles:
|
||||
self._export_ST_profile_header(
|
||||
f, files, profile, cnt_num
|
||||
)
|
||||
@@ -489,12 +484,7 @@ class Mage(CommandLineSolver):
|
||||
if cond.is_deleted():
|
||||
continue
|
||||
|
||||
enabled_profiles = set(reach.reach.enabled_profiles)
|
||||
data = [
|
||||
item for item in cond.data
|
||||
if not item.is_deleted()
|
||||
and item["section"] in enabled_profiles
|
||||
]
|
||||
data = cond.data
|
||||
if len(data) == 0:
|
||||
continue
|
||||
|
||||
@@ -502,6 +492,9 @@ class Mage(CommandLineSolver):
|
||||
|
||||
id_sec = 1
|
||||
for d in data:
|
||||
if d.is_deleted():
|
||||
continue
|
||||
|
||||
IR = f"{id}"
|
||||
IS = f"{id_sec}"
|
||||
discharge = f"{d['discharge']:>10.5f}"
|
||||
@@ -1011,7 +1004,6 @@ class Mage8(Mage):
|
||||
@timer
|
||||
def export(self, study, repertory, qlog=None, name="0"):
|
||||
self._study = study
|
||||
self._reset_node_names()
|
||||
name = study.name.replace(" ", "_")
|
||||
|
||||
# Define GRA file name
|
||||
@@ -1099,10 +1091,7 @@ class Mage8(Mage):
|
||||
|
||||
for i in range(nb_reach):
|
||||
# Add results reach to reach list
|
||||
geometry_reach = study.river.enable_edges()[i].reach
|
||||
r = results.river.add(
|
||||
i, profiles=geometry_reach.enabled_profiles
|
||||
)
|
||||
r = results.river.add(i)
|
||||
reachs.append(r)
|
||||
|
||||
# ID of first and last reach profiles
|
||||
@@ -1407,10 +1396,7 @@ class Mage8(Mage):
|
||||
zfd_lst = []
|
||||
|
||||
for r in reachs:
|
||||
z_min = [
|
||||
profile.geometry.z_min()
|
||||
for profile in r.profiles
|
||||
]
|
||||
z_min = r.geometry.get_z_min()
|
||||
sls = map(
|
||||
lambda p: p.get_ts_key(ts_list[0], "sl")[0],
|
||||
r.profiles
|
||||
|
||||
@@ -23,7 +23,6 @@ from Solver.Mage import (
|
||||
Mage7, Mage8, MageFake7,
|
||||
)
|
||||
from Solver.AdisTS import AdisTSwc
|
||||
from Solver.AdisTT import AdisTTwc
|
||||
from Solver.RubarBE import Rubar3, RubarBE
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
@@ -34,7 +33,6 @@ solver_long_name = {
|
||||
"mage8": "Mage v8",
|
||||
# "mage_fake7": "Mage fake v7",
|
||||
"adistswc": "Adis-TS_WC",
|
||||
"adisttwc": "Adis-TT_WC",
|
||||
# "rubarbe": "RubarBE",
|
||||
"rubar3": "Rubar3",
|
||||
}
|
||||
@@ -45,7 +43,6 @@ solver_type_list = {
|
||||
"mage8": Mage8,
|
||||
# "mage_fake7": MageFake7,
|
||||
"adistswc": AdisTSwc,
|
||||
"adisttwc": AdisTTwc,
|
||||
# "rubarbe": RubarBE,
|
||||
"rubar3": Rubar3,
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class Plot(PamhyrPlot):
|
||||
self._isometric_axis = False
|
||||
|
||||
self._auto_relim_update = True
|
||||
self._autoscale_update = True
|
||||
self._autoscale_update = False
|
||||
|
||||
def custom_ticks(self):
|
||||
if self.data.header[0] != "time":
|
||||
|
||||
@@ -155,7 +155,6 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
||||
|
||||
def update(self):
|
||||
self.plot.update()
|
||||
self.plot.fit_to_data()
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
# Plot.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from tools import timer, trace
|
||||
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
QCoreApplication
|
||||
)
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Plot(PamhyrPlot):
|
||||
def __init__(self, mode="time", data=None,
|
||||
trad=None, canvas=None, toolbar=None,
|
||||
parent=None):
|
||||
super(Plot, self).__init__(
|
||||
canvas=canvas,
|
||||
trad=trad,
|
||||
data=data,
|
||||
toolbar=toolbar,
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self._table_headers = self._trad.get_dict("table_headers")
|
||||
|
||||
header = self.data.header
|
||||
|
||||
self.label_x = self._table_headers[header[0]]
|
||||
self.label_y = self._table_headers[header[1]]
|
||||
|
||||
self._mode = mode
|
||||
self._isometric_axis = False
|
||||
|
||||
self._auto_relim_update = True
|
||||
self._autoscale_update = False
|
||||
|
||||
def custom_ticks(self):
|
||||
if self.data.header[0] != "time":
|
||||
return
|
||||
|
||||
self.set_ticks_time_formater()
|
||||
|
||||
@timer
|
||||
def draw(self):
|
||||
self.init_axes()
|
||||
|
||||
if len(self.data) == 0:
|
||||
self._init = False
|
||||
return
|
||||
|
||||
self.draw_data()
|
||||
self.custom_ticks()
|
||||
|
||||
self.idle()
|
||||
self._init = True
|
||||
|
||||
def draw_data(self):
|
||||
# Plot data
|
||||
x = list(map(lambda v: v[0], self.data.data))
|
||||
y = list(map(lambda v: v[1], self.data.data))
|
||||
|
||||
self._line, = self.canvas.axes.plot(
|
||||
x, y,
|
||||
color=self.color_plot,
|
||||
**self.plot_default_kargs
|
||||
)
|
||||
|
||||
@timer
|
||||
def update(self, ind=None):
|
||||
if not self._init:
|
||||
self.draw()
|
||||
return
|
||||
|
||||
self.update_data()
|
||||
|
||||
self.update_idle()
|
||||
|
||||
def update_data(self):
|
||||
x = list(map(lambda v: v[0], self.data.data))
|
||||
y = list(map(lambda v: v[1], self.data.data))
|
||||
|
||||
self._line.set_data(x, y)
|
||||
@@ -1,185 +0,0 @@
|
||||
# Table.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 -*-
|
||||
|
||||
import logging
|
||||
import traceback
|
||||
|
||||
from datetime import date, time, datetime, timedelta
|
||||
|
||||
from tools import (
|
||||
trace, timer,
|
||||
timestamp_to_old_pamhyr_date,
|
||||
old_pamhyr_date_to_timestamp
|
||||
)
|
||||
|
||||
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel,
|
||||
QCoreApplication, QModelIndex, pyqtSlot,
|
||||
QRect, QTime, QDateTime,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QTableView, QAbstractItemView, QSpinBox,
|
||||
QTimeEdit, QDateTimeEdit, QItemDelegate,
|
||||
)
|
||||
|
||||
from View.BoundaryConditionsTemperature.Edit.UndoCommand import (
|
||||
AddCommand, DelCommand, SetDataCommand, PasteCommand, SortCommand,
|
||||
)
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class TableModel(PamhyrTableModel):
|
||||
def get_true_data_row(self, row):
|
||||
if len(self._data.data) > 0:
|
||||
bc = self._data.data[row]
|
||||
else:
|
||||
return 0
|
||||
|
||||
return next(
|
||||
map(
|
||||
lambda e: e[0],
|
||||
filter(
|
||||
lambda e: e[1] == bc,
|
||||
enumerate(self._data._data)
|
||||
)
|
||||
), 0
|
||||
)
|
||||
|
||||
def data(self, index, role):
|
||||
if role == Qt.TextAlignmentRole:
|
||||
return Qt.AlignHCenter | Qt.AlignVCenter
|
||||
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
return QVariant()
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
value = QVariant()
|
||||
|
||||
if 0 <= column < 2:
|
||||
row = self.get_true_data_row(row)
|
||||
v = self._data._data[row][column]
|
||||
if self._data._types[column] == float:
|
||||
value = f"{v:.2f}"
|
||||
elif self._data.header[column] == "time":
|
||||
if self._opt_data == "time":
|
||||
value = timestamp_to_old_pamhyr_date(int(v))
|
||||
else:
|
||||
value = str(datetime.fromtimestamp(v))
|
||||
else:
|
||||
value = f"{v}"
|
||||
|
||||
return value
|
||||
|
||||
def setData(self, index, value, role=Qt.EditRole):
|
||||
if not index.isValid() or role != Qt.EditRole:
|
||||
return False
|
||||
|
||||
if self.is_same_data(index, value):
|
||||
return False
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
try:
|
||||
row = self.get_true_data_row(row)
|
||||
|
||||
self._undo.push(
|
||||
SetDataCommand(
|
||||
self._data, row, column, value
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
logger.debug(traceback.format_exc())
|
||||
|
||||
self.dataChanged.emit(index, index)
|
||||
return True
|
||||
|
||||
def add(self, row, parent=QModelIndex()):
|
||||
self.beginInsertRows(parent, row, row - 1)
|
||||
|
||||
self._undo.push(
|
||||
AddCommand(
|
||||
self._data, row
|
||||
)
|
||||
)
|
||||
|
||||
self.endInsertRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def delete(self, rows, parent=QModelIndex()):
|
||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||
_rows = list(
|
||||
map(
|
||||
lambda r: self.get_true_data_row(r),
|
||||
rows
|
||||
)
|
||||
)
|
||||
self._undo.push(
|
||||
DelCommand(
|
||||
self._data, _rows
|
||||
)
|
||||
)
|
||||
|
||||
self.endRemoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def sort(self, _reverse, parent=QModelIndex()):
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
self._undo.push(
|
||||
SortCommand(
|
||||
self._data, _reverse
|
||||
)
|
||||
)
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.update()
|
||||
|
||||
def paste(self, row, header, data):
|
||||
if len(data) == 0:
|
||||
return
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
self._undo.push(
|
||||
PasteCommand(
|
||||
self._data, row,
|
||||
list(
|
||||
map(
|
||||
lambda d: self._data.new_from_data(header, d),
|
||||
data
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
# self.auto_sort()
|
||||
self.layoutChanged.emit()
|
||||
@@ -1,137 +0,0 @@
|
||||
# UndoCommand.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from copy import deepcopy
|
||||
from tools import trace, timer
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QMessageBox, QUndoCommand, QUndoStack,
|
||||
)
|
||||
|
||||
from Model.BoundaryConditionsTemperature.BoundaryConditionTemperature \
|
||||
import BoundaryConditionTemperature
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class SetDataCommand(QUndoCommand):
|
||||
def __init__(self, data, index, column, new_value):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._data = data
|
||||
self._index = index
|
||||
self._column = column
|
||||
self._old = self._data.get_i(self._index)[self._column]
|
||||
self._new = new_value
|
||||
|
||||
def undo(self):
|
||||
self._data._set_i_c_v(self._index, self._column, self._old)
|
||||
|
||||
def redo(self):
|
||||
self._data._set_i_c_v(self._index, self._column, self._new)
|
||||
|
||||
|
||||
class AddCommand(QUndoCommand):
|
||||
def __init__(self, data, index):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._data = data
|
||||
self._index = index
|
||||
self._new = None
|
||||
|
||||
def undo(self):
|
||||
del self._data._data[self._index]
|
||||
|
||||
def redo(self):
|
||||
if self._new is None:
|
||||
self._new = self._data.add(self._index)
|
||||
else:
|
||||
self._data.insert(self._index, self._new)
|
||||
|
||||
|
||||
class DelCommand(QUndoCommand):
|
||||
def __init__(self, data, rows):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._data = data
|
||||
self._rows = rows
|
||||
|
||||
self._bc = []
|
||||
for row in rows:
|
||||
self._bc.append((row, self._data._data[row]))
|
||||
self._bc.sort()
|
||||
|
||||
def undo(self):
|
||||
for row, el in self._bc:
|
||||
el.set_as_not_deleted()
|
||||
|
||||
def redo(self):
|
||||
for row, el in self._bc:
|
||||
el.set_as_deleted()
|
||||
|
||||
|
||||
class PasteCommand(QUndoCommand):
|
||||
def __init__(self, data, row, bcs):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._data = data
|
||||
self._row = row
|
||||
self._bcs = bcs
|
||||
self._bcs.reverse()
|
||||
|
||||
def undo(self):
|
||||
self._data.delete_i(
|
||||
range(self._row, self._row + len(self._bcs))
|
||||
)
|
||||
|
||||
def redo(self):
|
||||
for bc in self._bcs:
|
||||
self._data.insert(self._row, bc)
|
||||
|
||||
|
||||
class SortCommand(QUndoCommand):
|
||||
def __init__(self, data, _reverse):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._data = data
|
||||
self._reverse = _reverse
|
||||
|
||||
self._old = self._data.data
|
||||
self._indexes = None
|
||||
|
||||
def undo(self):
|
||||
ll = self._data.data
|
||||
self._data.sort(
|
||||
key=lambda x: self._indexes[ll.index(x)]
|
||||
)
|
||||
|
||||
def redo(self):
|
||||
self._data.sort(
|
||||
_reverse=self._reverse,
|
||||
key=lambda x: x[0]
|
||||
)
|
||||
if self._indexes is None:
|
||||
self._indexes = list(
|
||||
map(
|
||||
lambda p: self._old.index(p),
|
||||
self._data.data
|
||||
)
|
||||
)
|
||||
self._old = None
|
||||
@@ -1,230 +0,0 @@
|
||||
# Window.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from tools import timer, trace
|
||||
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
from View.Tools.PamhyrWidget import PamhyrWidget
|
||||
from View.Tools.PamhyrDelegate import PamhyrExTimeDelegate
|
||||
|
||||
from PyQt5.QtGui import (
|
||||
QKeySequence,
|
||||
)
|
||||
|
||||
from PyQt5 import QtCore
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel, QCoreApplication,
|
||||
pyqtSlot, pyqtSignal,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QPushButton, QLineEdit,
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QHeaderView, QDoubleSpinBox, QVBoxLayout,
|
||||
)
|
||||
|
||||
from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
||||
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
||||
|
||||
from View.BoundaryConditionsTemperature.Edit.translate import BCETranslate
|
||||
from View.BoundaryConditionsTemperature.Edit.Table import TableModel
|
||||
from View.BoundaryConditionsTemperature.Edit.Plot import Plot
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class EditBoundaryConditionWindow(PamhyrWindow):
|
||||
_pamhyr_ui = "EditBoundaryConditionsTemperature"
|
||||
_pamhyr_name = "Edit Boundary Conditions Temperature"
|
||||
|
||||
def __init__(self, data=None, study=None, config=None, parent=None):
|
||||
self._data = data
|
||||
trad = BCETranslate()
|
||||
|
||||
name = trad[self._pamhyr_name]
|
||||
|
||||
if self._data is not None:
|
||||
n = self._data.node
|
||||
node_name = next(filter(
|
||||
lambda x: x.id == n, study.river._nodes
|
||||
)).name
|
||||
name += (
|
||||
f" - {study.name} " +
|
||||
f"({node_name})"
|
||||
)
|
||||
|
||||
super(EditBoundaryConditionWindow, self).__init__(
|
||||
title=name,
|
||||
study=study,
|
||||
config=config,
|
||||
trad=trad,
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self._hash_data.append(data)
|
||||
|
||||
self.setup_table()
|
||||
self.setup_plot()
|
||||
self.setup_connections()
|
||||
|
||||
def setup_table(self):
|
||||
table_headers = self._trad.get_dict("table_headers")
|
||||
|
||||
if self._study.is_editable():
|
||||
editable_headers = self._trad.get_dict("table_headers")
|
||||
else:
|
||||
editable_headers = []
|
||||
|
||||
self._data.header = ["time", "temperature"]
|
||||
|
||||
headers = {}
|
||||
for h in self._data.header:
|
||||
headers[h] = table_headers[h]
|
||||
|
||||
self._delegate_time = PamhyrExTimeDelegate(
|
||||
data=self._data,
|
||||
mode=self._study.time_system,
|
||||
parent=self
|
||||
)
|
||||
|
||||
table = self.find(QTableView, "tableView")
|
||||
self._table = TableModel(
|
||||
table_view=table,
|
||||
table_headers=headers,
|
||||
editable_headers=editable_headers,
|
||||
delegates={
|
||||
# "time": self._delegate_time,
|
||||
},
|
||||
data=self._data,
|
||||
undo=self._undo_stack,
|
||||
opt_data=self._study.time_system
|
||||
)
|
||||
|
||||
table.setModel(self._table)
|
||||
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
table.setAlternatingRowColors(True)
|
||||
|
||||
def setup_plot(self):
|
||||
self.canvas = MplCanvas(width=5, height=4, dpi=100)
|
||||
self.canvas.setObjectName("canvas")
|
||||
self.toolbar = PamhyrPlotToolbar(
|
||||
self.canvas, self
|
||||
)
|
||||
self.verticalLayout.addWidget(self.toolbar)
|
||||
self.verticalLayout.addWidget(self.canvas)
|
||||
|
||||
self.plot = Plot(
|
||||
canvas=self.canvas,
|
||||
data=self._data,
|
||||
mode=self._study.time_system,
|
||||
trad=self._trad,
|
||||
toolbar=self.toolbar,
|
||||
)
|
||||
self.plot.draw()
|
||||
|
||||
def setup_connections(self):
|
||||
if self._study.is_editable():
|
||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||
self.find(QAction, "action_del").triggered.connect(self.delete)
|
||||
self.find(QAction, "action_sort").triggered.connect(self.sort)
|
||||
self._table.dataChanged.connect(self.update)
|
||||
|
||||
def update(self):
|
||||
self.plot.update()
|
||||
self.plot.fit_to_data()
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
return table.selectionModel()\
|
||||
.selectedRows()[0]\
|
||||
.row()
|
||||
|
||||
def index_selected_rows(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
return list(
|
||||
# Delete duplicate
|
||||
set(
|
||||
map(
|
||||
lambda i: i.row(),
|
||||
table.selectedIndexes()
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def add(self):
|
||||
rows = self.index_selected_rows()
|
||||
if len(self._data) == 0 or len(rows) == 0:
|
||||
self._table.add(0)
|
||||
else:
|
||||
self._table.add(rows[0])
|
||||
|
||||
self.plot.update()
|
||||
|
||||
def delete(self):
|
||||
rows = self.index_selected_rows()
|
||||
if len(rows) == 0:
|
||||
return
|
||||
|
||||
self._table.delete(rows)
|
||||
self.plot.update()
|
||||
|
||||
def sort(self):
|
||||
self._table.sort(False)
|
||||
self.plot.update()
|
||||
|
||||
def _copy(self):
|
||||
rows = self.index_selected_rows()
|
||||
|
||||
table = []
|
||||
table.append(self._data.header)
|
||||
|
||||
data = self._data.data
|
||||
for row in rows:
|
||||
table.append(list(data[row]))
|
||||
|
||||
self.copyTableIntoClipboard(table)
|
||||
|
||||
def _paste(self):
|
||||
header, data = self.parseClipboardTable()
|
||||
|
||||
logger.debug(f"paste: h:{header}, d:{data}")
|
||||
|
||||
if len(data) == 0:
|
||||
return
|
||||
|
||||
row = 0
|
||||
rows = self.index_selected_rows()
|
||||
if len(rows) != 0:
|
||||
row = rows[0]
|
||||
|
||||
self._table.paste(row, header, data)
|
||||
self.plot.update()
|
||||
|
||||
def _undo(self):
|
||||
self._table.undo()
|
||||
self.plot.update()
|
||||
|
||||
def _redo(self):
|
||||
self._table.redo()
|
||||
self.plot.update()
|
||||
@@ -1,111 +0,0 @@
|
||||
# UndoCommand.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 copy import deepcopy
|
||||
from tools import trace, timer
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QMessageBox, QUndoCommand, QUndoStack,
|
||||
)
|
||||
|
||||
from Model.BoundaryConditionsTemperature.BoundaryConditionTemperature \
|
||||
import BoundaryConditionTemperature
|
||||
from Model.BoundaryConditionsTemperature.BoundaryConditionsTemperatureList \
|
||||
import BoundaryConditionsTemperatureList
|
||||
|
||||
|
||||
class SetNodeCommand(QUndoCommand):
|
||||
def __init__(self, bcs, index, node):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._bcs = bcs
|
||||
self._index = index
|
||||
self._old = self._bcs.get(self._index).node
|
||||
self._new = node.id if node is not None else None
|
||||
self._previous = next(
|
||||
(
|
||||
bc for i, bc in enumerate(self._bcs.lst)
|
||||
if i != self._index and bc.node == self._new
|
||||
),
|
||||
None
|
||||
)
|
||||
|
||||
def undo(self):
|
||||
self._bcs.get(self._index).node = self._old
|
||||
if self._previous is not None:
|
||||
self._previous.node = self._new
|
||||
|
||||
def redo(self):
|
||||
self._bcs.get(self._index).node = self._new
|
||||
if self._previous is not None:
|
||||
self._previous.node = None
|
||||
|
||||
|
||||
class SetNameCommand(QUndoCommand):
|
||||
def __init__(self, bcs, index, name):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._bcs = bcs
|
||||
self._index = index
|
||||
self._name = name
|
||||
self._old = self._bcs.get(self._index).name
|
||||
self._new = self._name
|
||||
|
||||
def undo(self):
|
||||
self._bcs.get(self._index).name = self._old
|
||||
|
||||
def redo(self):
|
||||
self._bcs.get(self._index).name = self._new
|
||||
|
||||
|
||||
class AddCommand(QUndoCommand):
|
||||
def __init__(self, bcs, index):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._bcs = bcs
|
||||
self._index = index
|
||||
self._new = None
|
||||
|
||||
def undo(self):
|
||||
self._bcs.delete_i([self._index])
|
||||
|
||||
def redo(self):
|
||||
if self._new is None:
|
||||
self._new = self._bcs.new(self._index)
|
||||
else:
|
||||
self._bcs.insert(self._index, self._new)
|
||||
|
||||
|
||||
class DelCommand(QUndoCommand):
|
||||
def __init__(self, bcs, rows):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._bcs = bcs
|
||||
self._rows = rows
|
||||
|
||||
self._bc = []
|
||||
for row in rows:
|
||||
self._bc.append((row, self._bcs._lst[row]))
|
||||
self._bc.sort()
|
||||
|
||||
def undo(self):
|
||||
for row, el in self._bc:
|
||||
self._bcs.insert(row, el)
|
||||
|
||||
def redo(self):
|
||||
self._bcs.delete_i(self._rows)
|
||||
@@ -1,192 +0,0 @@
|
||||
# Window.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from tools import trace, timer, logger_exception
|
||||
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
|
||||
from PyQt5.QtGui import (
|
||||
QKeySequence,
|
||||
)
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel,
|
||||
QCoreApplication, QModelIndex, pyqtSlot,
|
||||
QRect,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QPushButton, QLineEdit,
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
|
||||
QWidget,
|
||||
)
|
||||
|
||||
from View.BoundaryConditionsTemperature.Table import (
|
||||
TableModel, ComboBoxDelegate
|
||||
)
|
||||
|
||||
from View.Network.GraphWidget import GraphWidget
|
||||
from View.BoundaryConditionsTemperature.translate import BCTemperatureTranslate
|
||||
from View.BoundaryConditionsTemperature.Edit.Window \
|
||||
import EditBoundaryConditionWindow
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class BoundaryConditionsTemperatureWindow(PamhyrWindow):
|
||||
_pamhyr_ui = "BoundaryConditionsTemperature"
|
||||
_pamhyr_name = "Boundary conditions temperature"
|
||||
|
||||
def __init__(self, data=None, study=None,
|
||||
config=None, parent=None):
|
||||
self._data = data
|
||||
trad = BCTemperatureTranslate()
|
||||
|
||||
name = (
|
||||
trad[self._pamhyr_name] +
|
||||
" - " + study.name
|
||||
)
|
||||
|
||||
super(BoundaryConditionsTemperatureWindow, self).__init__(
|
||||
title=name,
|
||||
study=study,
|
||||
config=config,
|
||||
trad=trad,
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self._bcs = self._study.river.boundary_conditions_temperature
|
||||
|
||||
self.setup_graph()
|
||||
self.setup_table()
|
||||
self.setup_connections()
|
||||
|
||||
def setup_table(self):
|
||||
self._delegate_node = ComboBoxDelegate(
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
mode="node",
|
||||
parent=self
|
||||
)
|
||||
|
||||
if self._study.is_editable():
|
||||
editable_headers = self._trad.get_dict("table_headers")
|
||||
else:
|
||||
editable_headers = []
|
||||
|
||||
table = self.find(QTableView, f"tableView")
|
||||
self._table = TableModel(
|
||||
table_view=table,
|
||||
table_headers=self._trad.get_dict("table_headers"),
|
||||
editable_headers=editable_headers,
|
||||
delegates={
|
||||
"node": self._delegate_node,
|
||||
},
|
||||
trad=self._trad,
|
||||
bc_list=self._study.river.boundary_conditions_temperature,
|
||||
undo=self._undo_stack,
|
||||
data=self._study.river
|
||||
)
|
||||
table.setModel(self._table)
|
||||
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
table.setAlternatingRowColors(True)
|
||||
|
||||
def setup_graph(self):
|
||||
self.graph_widget = GraphWidget(
|
||||
self._study.river,
|
||||
min_size=None, size=(200, 200),
|
||||
only_display=True,
|
||||
parent=self
|
||||
)
|
||||
self.graph_layout = self.find(QVBoxLayout, "verticalLayout")
|
||||
self.graph_layout.addWidget(self.graph_widget)
|
||||
|
||||
def setup_connections(self):
|
||||
if self._study.is_editable():
|
||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||
self.find(QAction, "action_del").triggered.connect(self.delete)
|
||||
|
||||
self.find(QAction, "action_edit").triggered.connect(self.edit)
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, f"tableView")
|
||||
return table.selectionModel()\
|
||||
.selectedRows()[0]\
|
||||
.row()
|
||||
|
||||
def index_selected_rows(self):
|
||||
table = self.find(QTableView, f"tableView")
|
||||
return list(
|
||||
# Delete duplicate
|
||||
set(
|
||||
map(
|
||||
lambda i: i.row(),
|
||||
table.selectedIndexes()
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def add(self):
|
||||
self._table.add(self._table.rowCount())
|
||||
|
||||
def delete(self):
|
||||
rows = self.index_selected_rows()
|
||||
if len(rows) == 0:
|
||||
return
|
||||
|
||||
self._table.delete(rows)
|
||||
|
||||
def _copy(self):
|
||||
logger.info("TODO: copy")
|
||||
|
||||
def _paste(self):
|
||||
logger.info("TODO: paste")
|
||||
|
||||
def _undo(self):
|
||||
self._table.undo()
|
||||
|
||||
def _redo(self):
|
||||
self._table.redo()
|
||||
|
||||
def edit(self):
|
||||
rows = self.index_selected_rows()
|
||||
for row in rows:
|
||||
data = self._table.get(row)
|
||||
|
||||
if data.node is None:
|
||||
continue
|
||||
|
||||
if self.sub_window_exists(
|
||||
EditBoundaryConditionWindow,
|
||||
data=[self._study, None, data]
|
||||
):
|
||||
continue
|
||||
|
||||
win = EditBoundaryConditionWindow(
|
||||
data=data,
|
||||
study=self._study,
|
||||
parent=self
|
||||
)
|
||||
win.show()
|
||||
@@ -53,13 +53,12 @@ class CheckListWindowAdisTS(PamhyrWindow):
|
||||
|
||||
def __init__(self, autorun: bool = True,
|
||||
study=None, config=None,
|
||||
solver=None, parent=None, mage_rep=None, mode="adists"):
|
||||
solver=None, parent=None, mage_rep=None):
|
||||
trad = CheckListTranslate()
|
||||
|
||||
self._autorun = autorun
|
||||
self._solver = solver
|
||||
self._mage_rep = mage_rep
|
||||
self._mode = mode
|
||||
|
||||
name = trad[self._pamhyr_name] + " - " + study.name
|
||||
|
||||
@@ -74,8 +73,6 @@ class CheckListWindowAdisTS(PamhyrWindow):
|
||||
|
||||
# Add solver to hash computation data
|
||||
self._hash_data.append(self._solver)
|
||||
self._hash_data.append(self._mage_rep)
|
||||
self._hash_data.append(self._mode)
|
||||
|
||||
self._checker_list = (
|
||||
self._study.checkers() +
|
||||
@@ -172,7 +169,7 @@ class CheckListWindowAdisTS(PamhyrWindow):
|
||||
if not errors:
|
||||
self.find(QPushButton, "pushButton_ok").setEnabled(True)
|
||||
if self._autorun:
|
||||
self.open_solver_log()
|
||||
self._parent.solver_log_adists(self._solver, self._mage_rep)
|
||||
self.end()
|
||||
|
||||
self.update_statusbar()
|
||||
@@ -199,11 +196,5 @@ class CheckListWindowAdisTS(PamhyrWindow):
|
||||
self.end()
|
||||
|
||||
def accept(self):
|
||||
self.open_solver_log()
|
||||
self._parent.solver_log_adists(self._solver, self._mage_rep)
|
||||
# self.end()
|
||||
|
||||
def open_solver_log(self):
|
||||
if self._mode == "adistt":
|
||||
self._parent.solver_log_adistt(self._solver, self._mage_rep)
|
||||
else:
|
||||
self._parent.solver_log_adists(self._solver, self._mage_rep)
|
||||
@@ -43,7 +43,6 @@ from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QPushButton, QLineEdit,
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QComboBox, QUndoStack, QShortcut, QHeaderView,
|
||||
QCheckBox,
|
||||
)
|
||||
|
||||
from Modules import Modules
|
||||
@@ -120,17 +119,11 @@ class ConfigureWindow(PamhyrDialog):
|
||||
editable_headers=["name", "comment", "minor", "medium"],
|
||||
data=self._stricklers,
|
||||
undo=self._undo_stack,
|
||||
trad=self._trad_stricklers,
|
||||
display_manning=self._config.display_manning,
|
||||
unique_names=True,
|
||||
)
|
||||
|
||||
def setup_data(self):
|
||||
# Backup
|
||||
self.set_check_box("checkBox_backup", self._config.backup_enable)
|
||||
self.set_check_box(
|
||||
"checkBox_display_manning", self._config.display_manning
|
||||
)
|
||||
# self.set_line_edit_text("lineEdit_backup_path",
|
||||
# self._config.backup_path)
|
||||
self.set_time_edit("timeEdit_backup_frequence",
|
||||
@@ -174,10 +167,6 @@ class ConfigureWindow(PamhyrDialog):
|
||||
for button in buttons:
|
||||
self.find(QPushButton, button).clicked.connect(buttons[button])
|
||||
|
||||
self.find(QCheckBox, "checkBox_display_manning").stateChanged.connect(
|
||||
self.update_stricklers_display
|
||||
)
|
||||
|
||||
def accept(self):
|
||||
# Solvers
|
||||
self._config.solvers = self.solver_table_model._data.copy()
|
||||
@@ -189,9 +178,6 @@ class ConfigureWindow(PamhyrDialog):
|
||||
self._config.backup_frequence = self.get_time_edit(
|
||||
"timeEdit_backup_frequence"
|
||||
)
|
||||
self._config.display_manning = self.get_check_box(
|
||||
"checkBox_display_manning"
|
||||
)
|
||||
# self._config.backup_max = self.get_spin_box("spinBox_backup_max")
|
||||
|
||||
# Stricklers
|
||||
@@ -251,12 +237,6 @@ class ConfigureWindow(PamhyrDialog):
|
||||
|
||||
# Stricklers
|
||||
|
||||
def update_stricklers_display(self):
|
||||
self._stricklers_table.display_manning = self.get_check_box(
|
||||
"checkBox_display_manning"
|
||||
)
|
||||
self._stricklers_table.layoutChanged.emit()
|
||||
|
||||
def index_selected_rows_strikclers(self):
|
||||
table = self.find(QTableView, f"tableView_stricklers")
|
||||
return list(
|
||||
|
||||
@@ -78,7 +78,7 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
else:
|
||||
val = list(
|
||||
map(
|
||||
lambda n: n.name, self._data.enable_edges()
|
||||
lambda n: n.name, self._data.edges()
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
else:
|
||||
val = list(
|
||||
map(
|
||||
lambda n: n.name, self._data.enable_edges()
|
||||
lambda n: n.name, self._data.edges()
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import logging
|
||||
|
||||
from tools import timer, flatten
|
||||
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||
from View.Tools.CoefficientDisplay import display_coefficient
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
QCoreApplication
|
||||
@@ -33,7 +32,7 @@ _translate = QCoreApplication.translate
|
||||
|
||||
class PlotStricklers(PamhyrPlot):
|
||||
def __init__(self, data=None, canvas=None, trad=None,
|
||||
toolbar=None, display_manning=True, parent=None):
|
||||
toolbar=None, parent=None):
|
||||
super(PlotStricklers, self).__init__(
|
||||
canvas=canvas,
|
||||
trad=trad,
|
||||
@@ -43,11 +42,7 @@ class PlotStricklers(PamhyrPlot):
|
||||
)
|
||||
|
||||
self.label_x = self._trad["rk"]
|
||||
self._display_manning = display_manning
|
||||
self.label_y = (
|
||||
self._trad["manning_plot"] if display_manning
|
||||
else self._trad["strickler_plot"]
|
||||
)
|
||||
self.label_y = self._trad["strickler_plot"]
|
||||
|
||||
self.line_rk_elevation = [None, None]
|
||||
|
||||
@@ -118,12 +113,8 @@ class PlotStricklers(PamhyrPlot):
|
||||
)
|
||||
)
|
||||
|
||||
coef_minor = [
|
||||
display_coefficient(s.minor, self._display_manning) for s in coef
|
||||
]
|
||||
coef_medium = [
|
||||
display_coefficient(s.medium, self._display_manning) for s in coef
|
||||
]
|
||||
coef_minor = list(map(lambda s: s.minor, coef))
|
||||
coef_medium = list(map(lambda s: s.medium, coef))
|
||||
|
||||
self.line_rk_elevation[0] = self.canvas.axes.plot(
|
||||
rk, coef_minor,
|
||||
|
||||
+16
-81
@@ -42,7 +42,6 @@ from View.Frictions.UndoCommand import (
|
||||
)
|
||||
|
||||
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||
from View.Tools.CoefficientDisplay import display_strickler
|
||||
|
||||
from View.Frictions.translate import *
|
||||
|
||||
@@ -52,64 +51,30 @@ _translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class ComboBoxDelegate(QItemDelegate):
|
||||
def __init__(self, data=None, study=None, application_stricklers=None,
|
||||
mode="stricklers", trad=None, display_manning=True,
|
||||
parent=None):
|
||||
def __init__(self, data=None, study=None,
|
||||
mode="stricklers", trad=None, parent=None):
|
||||
super(ComboBoxDelegate, self).__init__(parent)
|
||||
|
||||
self._data = data
|
||||
self._study = study
|
||||
self._application_stricklers = application_stricklers or []
|
||||
self._trad = trad
|
||||
self._mode = mode
|
||||
self._display_manning = display_manning
|
||||
|
||||
@staticmethod
|
||||
def same_strickler(first, second):
|
||||
return (
|
||||
first.name == second.name
|
||||
and first.comment == second.comment
|
||||
and first.minor == second.minor
|
||||
and first.medium == second.medium
|
||||
)
|
||||
|
||||
def createEditor(self, parent, option, index):
|
||||
self.editor = QComboBox(parent)
|
||||
|
||||
if self._mode == "stricklers":
|
||||
self.editor.addItem(self._trad["not_defined"], None)
|
||||
study_stricklers = self._study.river.stricklers.stricklers
|
||||
for strickler in study_stricklers:
|
||||
self.editor.addItem(
|
||||
display_strickler(strickler, self._display_manning),
|
||||
strickler
|
||||
)
|
||||
|
||||
application_stricklers = [
|
||||
application_strickler
|
||||
for application_strickler in self._application_stricklers
|
||||
if not any(
|
||||
self.same_strickler(
|
||||
application_strickler, study_strickler
|
||||
)
|
||||
for study_strickler in study_stricklers
|
||||
)
|
||||
]
|
||||
if application_stricklers:
|
||||
self.editor.insertSeparator(self.editor.count())
|
||||
for strickler in application_stricklers:
|
||||
self.editor.addItem(
|
||||
display_strickler(
|
||||
strickler, self._display_manning
|
||||
),
|
||||
strickler
|
||||
)
|
||||
elif self._mode == "rk":
|
||||
self.editor.addItems(
|
||||
list(map(str, self._data.reach.get_rk()))
|
||||
[self._trad["not_defined"]] +
|
||||
list(
|
||||
map(
|
||||
lambda s: str(s),
|
||||
self._study.river.stricklers.stricklers
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
self.editor.setCurrentText(str(index.data(Qt.DisplayRole)))
|
||||
self.editor.setCurrentText(index.data(Qt.DisplayRole))
|
||||
return self.editor
|
||||
|
||||
def setEditorData(self, editor, index):
|
||||
@@ -117,9 +82,8 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
self.editor.currentTextChanged.connect(self.currentItemChanged)
|
||||
|
||||
def setModelData(self, editor, model, index):
|
||||
value = editor.currentData() if self._mode == "stricklers" else \
|
||||
str(editor.currentText())
|
||||
model.setData(index, value)
|
||||
text = str(editor.currentText())
|
||||
model.setData(index, text)
|
||||
editor.close()
|
||||
editor.deleteLater()
|
||||
|
||||
@@ -136,33 +100,10 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
|
||||
|
||||
class FrictionTableModel(PamhyrTableModel):
|
||||
def __init__(self, *args, display_manning=False, **kwargs):
|
||||
self.display_manning = display_manning
|
||||
super(FrictionTableModel, self).__init__(*args, **kwargs)
|
||||
|
||||
def _setup_lst(self):
|
||||
self._lst = self._data.frictions
|
||||
self._study = self._opt_data
|
||||
|
||||
def study_strickler(self, strickler):
|
||||
if strickler is None:
|
||||
return None
|
||||
|
||||
study_stricklers = self._study.river.stricklers
|
||||
if any(s is strickler for s in study_stricklers.stricklers):
|
||||
return strickler
|
||||
|
||||
for current in study_stricklers.stricklers:
|
||||
if ComboBoxDelegate.same_strickler(current, strickler):
|
||||
return current
|
||||
|
||||
copied = study_stricklers.new(len(study_stricklers))
|
||||
copied.name = strickler.name
|
||||
copied.comment = strickler.comment
|
||||
copied.minor = strickler.minor
|
||||
copied.medium = strickler.medium
|
||||
return copied
|
||||
|
||||
def data(self, index, role):
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
return QVariant()
|
||||
@@ -180,12 +121,12 @@ class FrictionTableModel(PamhyrTableModel):
|
||||
value = self._lst.get(row).begin_strickler
|
||||
if value is None:
|
||||
return self._trad["not_defined"]
|
||||
return display_strickler(value, self.display_manning)
|
||||
return str(value)
|
||||
elif self._headers[column] == "end_strickler":
|
||||
value = self._lst.get(row).end_strickler
|
||||
if value is None:
|
||||
return self._trad["not_defined"]
|
||||
return display_strickler(value, self.display_manning)
|
||||
return str(value)
|
||||
|
||||
return QVariant()
|
||||
|
||||
@@ -219,21 +160,15 @@ class FrictionTableModel(PamhyrTableModel):
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "begin_strickler":
|
||||
strickler = value if hasattr(value, "minor") else \
|
||||
self._study.river.strickler(value)
|
||||
strickler = self.study_strickler(strickler)
|
||||
self._undo.push(
|
||||
SetBeginStricklerCommand(
|
||||
self._lst, row, strickler
|
||||
self._lst, row, self._study.river.strickler(value)
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "end_strickler":
|
||||
strickler = value if hasattr(value, "minor") else \
|
||||
self._study.river.strickler(value)
|
||||
strickler = self.study_strickler(strickler)
|
||||
self._undo.push(
|
||||
SetEndStricklerCommand(
|
||||
self._lst, row, strickler
|
||||
self._lst, row, self._study.river.strickler(value)
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
|
||||
@@ -67,9 +67,6 @@ class FrictionsWindow(PamhyrWindow):
|
||||
def __init__(self, reach=None, study=None, config=None, parent=None):
|
||||
trad = FrictionsTranslate()
|
||||
|
||||
if config is None and parent is not None:
|
||||
config = getattr(parent, "conf", None)
|
||||
|
||||
if reach is not None:
|
||||
self._reach = reach
|
||||
else:
|
||||
@@ -104,20 +101,8 @@ class FrictionsWindow(PamhyrWindow):
|
||||
self._delegate_stricklers = ComboBoxDelegate(
|
||||
data=self._reach,
|
||||
study=self._study,
|
||||
application_stricklers=(
|
||||
self._config.stricklers.stricklers
|
||||
if self._config is not None else []
|
||||
),
|
||||
mode="stricklers",
|
||||
trad=self._trad,
|
||||
display_manning=getattr(self._config, "display_manning", False),
|
||||
parent=self
|
||||
)
|
||||
self._delegate_rk = ComboBoxDelegate(
|
||||
data=self._reach,
|
||||
study=self._study,
|
||||
mode="rk",
|
||||
trad=self._trad,
|
||||
parent=self
|
||||
)
|
||||
|
||||
@@ -130,27 +115,18 @@ class FrictionsWindow(PamhyrWindow):
|
||||
editable_headers = []
|
||||
|
||||
table = self.find(QTableView, f"tableView")
|
||||
table_headers = self._trad.get_dict("table_headers").copy()
|
||||
table_headers["begin_strickler"] = (
|
||||
self._trad["manning"]
|
||||
if getattr(self._config, "display_manning", False)
|
||||
else self._trad["strickler"]
|
||||
)
|
||||
self._table = FrictionTableModel(
|
||||
table_view=table,
|
||||
table_headers=table_headers,
|
||||
table_headers=self._trad.get_dict("table_headers"),
|
||||
editable_headers=editable_headers,
|
||||
delegates={
|
||||
"begin_rk": self._delegate_rk,
|
||||
"end_rk": self._delegate_rk,
|
||||
"begin_strickler": self._delegate_stricklers,
|
||||
# "end_strickler": self._delegate_stricklers,
|
||||
"end_strickler": self._delegate_stricklers,
|
||||
},
|
||||
data=self._reach,
|
||||
trad=self._trad,
|
||||
undo=self._undo_stack,
|
||||
opt_data=self._study,
|
||||
display_manning=getattr(self._config, "display_manning", False)
|
||||
opt_data=self._study
|
||||
)
|
||||
table.setModel(self._table)
|
||||
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
@@ -182,8 +158,7 @@ class FrictionsWindow(PamhyrWindow):
|
||||
canvas=self.canvas_2,
|
||||
data=self._reach,
|
||||
trad=self._trad,
|
||||
toolbar=None,
|
||||
display_manning=getattr(self._config, "display_manning", False)
|
||||
toolbar=None
|
||||
)
|
||||
self.plot_2.draw()
|
||||
|
||||
@@ -223,41 +198,9 @@ class FrictionsWindow(PamhyrWindow):
|
||||
# self._propagate_update(key=Modules.FRICTION)
|
||||
|
||||
def _propagated_update(self, key=Modules(0)):
|
||||
if Modules.CONFIG in key:
|
||||
self.update_config()
|
||||
if Modules.GEOMETRY not in key:
|
||||
return
|
||||
|
||||
if Modules.GEOMETRY in key:
|
||||
self.update_plot()
|
||||
|
||||
for _, window in self.sub_win_list:
|
||||
window._propagated_update(key=key)
|
||||
|
||||
def update_config(self):
|
||||
display_manning = getattr(
|
||||
self._config, "display_manning", False
|
||||
)
|
||||
|
||||
self._delegate_stricklers._application_stricklers = (
|
||||
self._config.stricklers.stricklers
|
||||
if self._config is not None else []
|
||||
)
|
||||
self._delegate_stricklers._display_manning = display_manning
|
||||
|
||||
self._table.display_manning = display_manning
|
||||
self._table._table_headers["begin_strickler"] = (
|
||||
self._trad["manning"] if display_manning
|
||||
else self._trad["strickler"]
|
||||
)
|
||||
self._table.headerDataChanged.emit(
|
||||
Qt.Horizontal, 0, self._table.columnCount() - 1
|
||||
)
|
||||
self._table.layoutChanged.emit()
|
||||
|
||||
self.plot_2._display_manning = display_manning
|
||||
self.plot_2.label_y = (
|
||||
self._trad["manning_plot"] if display_manning
|
||||
else self._trad["strickler_plot"]
|
||||
)
|
||||
self.update_plot()
|
||||
|
||||
def _set_current_reach(self):
|
||||
@@ -322,13 +265,13 @@ class FrictionsWindow(PamhyrWindow):
|
||||
def edit_stricklers(self):
|
||||
if self.sub_window_exists(
|
||||
StricklersWindow,
|
||||
data=[self._study, self._config]
|
||||
data=[self._study, self.parent.conf]
|
||||
):
|
||||
return
|
||||
|
||||
strick = StricklersWindow(
|
||||
study=self._study,
|
||||
config=self._config,
|
||||
config=self.parent.conf,
|
||||
parent=self
|
||||
)
|
||||
strick.show()
|
||||
|
||||
@@ -31,18 +31,9 @@ class FrictionsTranslate(MainTranslate):
|
||||
self._dict["strickler_plot"] = _translate(
|
||||
"Frictions", "Strickler ($m^{1/3}/s$)"
|
||||
)
|
||||
self._dict["manning_plot"] = _translate(
|
||||
"Frictions", "Manning ($s/m^{1/3}$)"
|
||||
)
|
||||
self._dict["stricklers"] = _translate(
|
||||
"Frictions", "Stricklers"
|
||||
)
|
||||
self._dict["strickler"] = _translate(
|
||||
"Frictions", "Strickler"
|
||||
)
|
||||
self._dict["manning"] = _translate(
|
||||
"Frictions", "Manning"
|
||||
)
|
||||
|
||||
self._dict["Edit frictions"] = _translate(
|
||||
"Frictions", "Edit frictions"
|
||||
|
||||
@@ -128,15 +128,6 @@ class ProfileWindow(PamhyrWindow):
|
||||
self._tablemodel.blockSignals(False)
|
||||
|
||||
def setup_connections(self):
|
||||
navigation_actions = {
|
||||
"action_previous_profile": self.previous_profile,
|
||||
"action_next_profile": self.next_profile,
|
||||
}
|
||||
|
||||
for action in navigation_actions:
|
||||
self.find(QAction, action)\
|
||||
.triggered.connect(navigation_actions[action])
|
||||
|
||||
if self._study.is_read_only():
|
||||
actions = {}
|
||||
else:
|
||||
@@ -161,75 +152,6 @@ class ProfileWindow(PamhyrWindow):
|
||||
.connect(self.update_points_selection)
|
||||
|
||||
self._tablemodel.dataChanged.connect(self.update)
|
||||
self.update_navigation_actions()
|
||||
|
||||
def previous_profile(self):
|
||||
self.navigate_profile(-1)
|
||||
|
||||
def next_profile(self):
|
||||
self.navigate_profile(1)
|
||||
|
||||
def profiles(self):
|
||||
"""Return profiles from the geometry model owning this profile."""
|
||||
return self._profile.reach.reach.profiles
|
||||
|
||||
def navigate_profile(self, offset):
|
||||
profiles = self.profiles()
|
||||
|
||||
try:
|
||||
index = profiles.index(self._profile)
|
||||
except ValueError:
|
||||
self.update_navigation_actions()
|
||||
return
|
||||
|
||||
target_index = index + offset
|
||||
if not 0 <= target_index < len(profiles):
|
||||
self.update_navigation_actions()
|
||||
return
|
||||
|
||||
target = profiles[target_index]
|
||||
if self._parent is not None and self._parent.sub_window_exists(
|
||||
ProfileWindow,
|
||||
data=[self._study, self._config, target]
|
||||
):
|
||||
self.close()
|
||||
return
|
||||
|
||||
self.set_profile(target)
|
||||
|
||||
def set_profile(self, profile):
|
||||
self._profile = profile
|
||||
self._hash_data[-1] = profile
|
||||
self._undo_stack.clear()
|
||||
|
||||
self._tablemodel.beginResetModel()
|
||||
self._tablemodel._data = profile
|
||||
# update lst to display correct data and apply connexions to add/remove points
|
||||
self._tablemodel._setup_lst()
|
||||
self._tablemodel.endResetModel()
|
||||
|
||||
self._plot.data = profile
|
||||
self._plot.highlight = None
|
||||
self._plot.draw()
|
||||
|
||||
self._title = (
|
||||
self._trad[self._pamhyr_name] +
|
||||
f" - {profile.name} {profile.rk}"
|
||||
)
|
||||
self._set_title()
|
||||
self.update_navigation_actions()
|
||||
|
||||
def update_navigation_actions(self):
|
||||
profiles = self.profiles()
|
||||
try:
|
||||
index = profiles.index(self._profile)
|
||||
except ValueError:
|
||||
index = -1
|
||||
|
||||
self.find(QAction, "action_previous_profile")\
|
||||
.setEnabled(index > 0)
|
||||
self.find(QAction, "action_next_profile")\
|
||||
.setEnabled(0 <= index < len(profiles) - 1)
|
||||
|
||||
def update_points_selection(self):
|
||||
rows = self.index_selected_rows()
|
||||
|
||||
@@ -64,20 +64,15 @@ class GeometryReachTableModel(PamhyrTableModel):
|
||||
if not index.isValid():
|
||||
return QVariant()
|
||||
|
||||
profile = self._data.profile(index.row())
|
||||
|
||||
if role == Qt.BackgroundRole and not profile.is_enabled:
|
||||
return QColor(190, 190, 190)
|
||||
|
||||
if role == Qt.DisplayRole and index.column() == 0:
|
||||
return profile.name
|
||||
return self._data.profile(index.row()).name
|
||||
|
||||
if role == Qt.DisplayRole and index.column() == 1:
|
||||
rk = profile.rk
|
||||
rk = self._data.profile(index.row()).rk
|
||||
return f"{rk:.4f}"
|
||||
|
||||
if role == Qt.DisplayRole and index.column() == 2:
|
||||
return str(profile.nb_points)
|
||||
return str(self._data.profile(index.row()).nb_points)
|
||||
|
||||
if role == Qt.TextAlignmentRole:
|
||||
return Qt.AlignHCenter | Qt.AlignVCenter
|
||||
@@ -160,14 +155,6 @@ class GeometryReachTableModel(PamhyrTableModel):
|
||||
self.endRemoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def enabled(self, rows, enabled):
|
||||
self._undo.push(
|
||||
SetEnabledCommand(
|
||||
self._data, rows, enabled
|
||||
)
|
||||
)
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def sort_profiles(self, _reverse):
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
|
||||
@@ -44,9 +44,6 @@ class GeometryTranslate(MainTranslate):
|
||||
self._dict["cross_sections"] = _translate("Geometry", "cross-sections")
|
||||
self._dict["profile"] = _translate("Geometry", "cross-section")
|
||||
self._dict["profiles"] = _translate("Geometry", "cross-sections")
|
||||
self._dict["cross_section_enabled_count"] = _translate(
|
||||
"Geometry", "Cross-section enabled ({count} disabled)"
|
||||
)
|
||||
|
||||
self._dict["transverse_abscissa"] = _translate(
|
||||
"Geometry", "Transverse abscissa (m)"
|
||||
@@ -100,15 +97,6 @@ class GeometryTranslate(MainTranslate):
|
||||
self._dict["format_not_exportable"] = _translate(
|
||||
"Geometry", "The format of the file is not exportable."
|
||||
)
|
||||
self._dict["export_options"] = _translate(
|
||||
"Geometry", "Export options"
|
||||
)
|
||||
self._dict["export_options_text"] = _translate(
|
||||
"Geometry", "Choose which cross-sections to export."
|
||||
)
|
||||
self._dict["export_interpolated_profiles"] = _translate(
|
||||
"Geometry", "Export interpolated cross-sections"
|
||||
)
|
||||
self._dict["update_rk_error"] = _translate(
|
||||
"Geometry",
|
||||
"RK update can't be executed."
|
||||
|
||||
@@ -68,27 +68,6 @@ class SetRKCommand(SetDataCommand):
|
||||
self._reach.profile(self._index).rk = self._new
|
||||
|
||||
|
||||
class SetEnabledCommand(QUndoCommand):
|
||||
def __init__(self, reach, rows, enabled):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._profiles = [reach.profile(row) for row in rows]
|
||||
self._old = [profile.is_enabled for profile in self._profiles]
|
||||
self._new = bool(enabled)
|
||||
|
||||
@staticmethod
|
||||
def _set_enabled(profile, enabled):
|
||||
profile.enabled = enabled
|
||||
|
||||
def undo(self):
|
||||
for profile, enabled in zip(self._profiles, self._old):
|
||||
self._set_enabled(profile, enabled)
|
||||
|
||||
def redo(self):
|
||||
for profile in self._profiles:
|
||||
self._set_enabled(profile, self._new)
|
||||
|
||||
|
||||
class AddCommand(QUndoCommand):
|
||||
def __init__(self, reach, index):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
@@ -99,7 +99,6 @@ class GeometryWindow(PamhyrWindow):
|
||||
self._profile_window = []
|
||||
|
||||
self.setup_table()
|
||||
self.setup_checkbox()
|
||||
self.setup_plots()
|
||||
self.setup_statusbar()
|
||||
self.setup_connections()
|
||||
@@ -125,10 +124,6 @@ class GeometryWindow(PamhyrWindow):
|
||||
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
table.setAlternatingRowColors(True)
|
||||
|
||||
def setup_checkbox(self):
|
||||
self._checkbox = self.find(QCheckBox, "checkBox_enabled")
|
||||
self._set_checkbox_state()
|
||||
|
||||
def setup_plots(self):
|
||||
self.setup_plots_xy()
|
||||
self.setup_plots_rkc()
|
||||
@@ -228,9 +223,6 @@ class GeometryWindow(PamhyrWindow):
|
||||
.selectionChanged\
|
||||
.connect(self.select_current_profile)
|
||||
|
||||
if not self._study.is_read_only():
|
||||
self._checkbox.clicked.connect(self._set_profiles_state)
|
||||
|
||||
self._table.layoutChanged.connect(self.update_redraw)
|
||||
|
||||
def update(self):
|
||||
@@ -295,14 +287,13 @@ class GeometryWindow(PamhyrWindow):
|
||||
|
||||
if self.sub_window_exists(
|
||||
ProfileWindow,
|
||||
data=[self._study, self._config, profile]
|
||||
data=[None, None, profile]
|
||||
):
|
||||
continue
|
||||
|
||||
win = ProfileWindow(
|
||||
profile=profile,
|
||||
study=self._study,
|
||||
config=self._config,
|
||||
parent=self,
|
||||
)
|
||||
self._profile_window.append(win)
|
||||
@@ -323,10 +314,6 @@ class GeometryWindow(PamhyrWindow):
|
||||
trad=self._trad,
|
||||
parent=self
|
||||
)
|
||||
dlg.adjustSize()
|
||||
dialog_geometry = dlg.frameGeometry()
|
||||
dialog_geometry.moveCenter(self.frameGeometry().center())
|
||||
dlg.move(dialog_geometry.topLeft())
|
||||
if dlg.exec():
|
||||
data = {
|
||||
"step": dlg.space_step,
|
||||
@@ -533,48 +520,6 @@ class GeometryWindow(PamhyrWindow):
|
||||
self._plot_ac.draw()
|
||||
|
||||
self.tableView.model().blockSignals(False)
|
||||
self._set_checkbox_state()
|
||||
|
||||
def index_selected_rows(self):
|
||||
return [
|
||||
index.row()
|
||||
for index in self.tableView.selectionModel().selectedRows()
|
||||
]
|
||||
|
||||
def _set_checkbox_state(self):
|
||||
rows = self.index_selected_rows()
|
||||
editable = not self._study.is_read_only()
|
||||
disabled_count = self._reach.number_profiles - self._reach.number_enabled_profiles
|
||||
self._checkbox.setText(
|
||||
self._trad["cross_section_enabled_count"].format(
|
||||
count=disabled_count
|
||||
)
|
||||
)
|
||||
|
||||
self._checkbox.setEnabled(editable and len(rows) > 0)
|
||||
if len(rows) == 0:
|
||||
self._checkbox.setTristate(False)
|
||||
self._checkbox.setChecked(False)
|
||||
return
|
||||
|
||||
states = {
|
||||
self._reach.profile(row).is_enabled
|
||||
for row in rows
|
||||
}
|
||||
if len(states) == 1:
|
||||
self._checkbox.setTristate(False)
|
||||
self._checkbox.setChecked(states.pop())
|
||||
else:
|
||||
self._checkbox.setTristate(True)
|
||||
self._checkbox.setCheckState(Qt.PartiallyChecked)
|
||||
|
||||
def _set_profiles_state(self, enabled):
|
||||
rows = self.index_selected_rows()
|
||||
if len(rows) == 0:
|
||||
return
|
||||
|
||||
self._checkbox.setTristate(False)
|
||||
self._table.enabled(rows, enabled)
|
||||
|
||||
def add(self):
|
||||
if len(self.tableView.selectedIndexes()) == 0:
|
||||
@@ -790,11 +735,7 @@ class GeometryWindow(PamhyrWindow):
|
||||
suffix = Path(filename).suffix
|
||||
if suffix != "":
|
||||
if suffix == ".st" or suffix == ".ST":
|
||||
export_interpolated = self._ask_export_options()
|
||||
if export_interpolated is not None:
|
||||
self._export_to_file_st(
|
||||
filename[:-3], export_interpolated
|
||||
)
|
||||
self._export_to_file_st(filename[:-3])
|
||||
else:
|
||||
# Warning popup when the format is not exportable
|
||||
win = QtWidgets.QMessageBox()
|
||||
@@ -805,45 +746,16 @@ class GeometryWindow(PamhyrWindow):
|
||||
|
||||
pass
|
||||
else:
|
||||
export_interpolated = self._ask_export_options()
|
||||
if export_interpolated is not None:
|
||||
self._export_to_file_st(filename, export_interpolated)
|
||||
self._export_to_file_st(filename)
|
||||
|
||||
def _ask_export_options(self):
|
||||
win = QtWidgets.QMessageBox(self)
|
||||
win.setIcon(QtWidgets.QMessageBox.Question)
|
||||
win.setWindowTitle(self._trad["export_options"])
|
||||
win.setText(self._trad["export_options_text"])
|
||||
win.setStandardButtons(
|
||||
QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel
|
||||
)
|
||||
|
||||
export_interpolated = QCheckBox(
|
||||
self._trad["export_interpolated_profiles"], win
|
||||
)
|
||||
export_interpolated.setChecked(True)
|
||||
win.setCheckBox(export_interpolated)
|
||||
|
||||
if win.exec() != QtWidgets.QMessageBox.Ok:
|
||||
return None
|
||||
|
||||
return export_interpolated.isChecked()
|
||||
|
||||
def _export_to_file_st(self, filename, export_interpolated=True):
|
||||
def _export_to_file_st(self, filename):
|
||||
with open(filename+".st", "w+") as f:
|
||||
f.write("# Exported from Pamhyr2\n")
|
||||
self._export_to_file_st_reach(
|
||||
f, self._reach, export_interpolated
|
||||
)
|
||||
self._export_to_file_st_reach(f, self._reach)
|
||||
|
||||
def _export_to_file_st_reach(self, wfile, reach,
|
||||
export_interpolated=True):
|
||||
def _export_to_file_st_reach(self, wfile, reach):
|
||||
pid = 0
|
||||
for profile in reach.profiles:
|
||||
is_interpolated = profile.name.lower().startswith("interpol")
|
||||
if is_interpolated and not export_interpolated:
|
||||
continue
|
||||
|
||||
self._export_to_file_st_profile(wfile, profile, pid)
|
||||
pid += 1
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
val = []
|
||||
if self._mode == "rk":
|
||||
reach = self._data.hydraulic_structures\
|
||||
.get_for_enabled_reaches(index.row())\
|
||||
.get(index.row())\
|
||||
.input_reach
|
||||
if reach is not None:
|
||||
val = list(
|
||||
@@ -73,7 +73,7 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
else:
|
||||
val = list(
|
||||
map(
|
||||
lambda n: n.name, self._data.enable_edges()
|
||||
lambda n: n.name, self._data.edges()
|
||||
)
|
||||
)
|
||||
|
||||
@@ -94,7 +94,7 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
|
||||
if self._mode == "rk":
|
||||
reach = self._data.hydraulic_structures\
|
||||
.get_for_enabled_reaches(index.row())\
|
||||
.get(index.row())\
|
||||
.input_reach
|
||||
profiles = list(
|
||||
filter(
|
||||
@@ -128,22 +128,20 @@ class TableModel(PamhyrTableModel):
|
||||
self._lst = self._data._hydraulic_structures
|
||||
|
||||
def get_true_data_row(self, row):
|
||||
hs = self._lst.get_for_enabled_reaches(row)
|
||||
if hs is None:
|
||||
return len(self._lst.lst)
|
||||
hs = self._lst.get(row)
|
||||
|
||||
return next(
|
||||
map(
|
||||
lambda e: e[0],
|
||||
filter(
|
||||
lambda e: e[1] == hs,
|
||||
enumerate(self._lst.lst)
|
||||
enumerate(self._lst._lst)
|
||||
)
|
||||
), 0
|
||||
)
|
||||
|
||||
def rowCount(self, parent):
|
||||
return len(self._lst.enabled_reaches_list)
|
||||
return len(self._lst)
|
||||
|
||||
def data(self, index, role):
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
@@ -151,17 +149,16 @@ class TableModel(PamhyrTableModel):
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
structure = self._lst.get_for_enabled_reaches(row)
|
||||
|
||||
if self._headers[column] == "name":
|
||||
return structure.name
|
||||
return self._lst.get(row).name
|
||||
elif self._headers[column] == "reach":
|
||||
n = structure.input_reach
|
||||
n = self._lst.get(row).input_reach
|
||||
if n is None:
|
||||
return self._trad['not_associated']
|
||||
return n.name
|
||||
elif self._headers[column] == "rk":
|
||||
n = structure.input_section
|
||||
n = self._lst.get(row).input_section
|
||||
if n is None:
|
||||
return self._trad['not_associated']
|
||||
return n.display_name()
|
||||
@@ -177,7 +174,6 @@ class TableModel(PamhyrTableModel):
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
row = self.get_true_data_row(row)
|
||||
na = self._trad['not_associated']
|
||||
|
||||
try:
|
||||
|
||||
@@ -220,7 +220,7 @@ class HydraulicStructuresWindow(PamhyrWindow):
|
||||
|
||||
def add(self):
|
||||
rows = self.index_selected_rows()
|
||||
if len(self._hs_lst.enabled_reaches_list) == 0 or len(rows) == 0:
|
||||
if len(self._hs_lst) == 0 or len(rows) == 0:
|
||||
self._table.add(0)
|
||||
else:
|
||||
self._table.add(rows[0])
|
||||
@@ -247,7 +247,7 @@ class HydraulicStructuresWindow(PamhyrWindow):
|
||||
def edit(self):
|
||||
rows = self.index_selected_rows()
|
||||
for row in rows:
|
||||
data = self._hs_lst.get_for_enabled_reaches(row)
|
||||
data = self._hs_lst.get(row)
|
||||
|
||||
if self.sub_window_exists(
|
||||
BasicHydraulicStructuresWindow,
|
||||
@@ -269,8 +269,7 @@ class HydraulicStructuresWindow(PamhyrWindow):
|
||||
self._checkbox.setChecked(True)
|
||||
else:
|
||||
self._checkbox.setEnabled(True)
|
||||
structure = self._hs_lst.get_for_enabled_reaches(row)
|
||||
self._checkbox.setChecked(structure.enabled)
|
||||
self._checkbox.setChecked(self._hs_lst.get(row).enabled)
|
||||
|
||||
def _set_structure_state(self):
|
||||
rows = self.index_selected_rows()
|
||||
@@ -289,18 +288,16 @@ class HydraulicStructuresWindow(PamhyrWindow):
|
||||
def _update_clear_plot(self):
|
||||
rows = self.index_selected_rows()
|
||||
|
||||
if (len(rows) == 0 or
|
||||
len(self._hs_lst.enabled_reaches_list) == 0):
|
||||
if len(rows) == 0 or len(self._hs_lst) == 0:
|
||||
self._update_clear_all()
|
||||
return
|
||||
|
||||
structure = self._hs_lst.get_for_enabled_reaches(rows[0])
|
||||
reach = structure.input_reach
|
||||
reach = self._hs_lst.get(rows[0]).input_reach
|
||||
if reach is not None:
|
||||
self.plot_rkc.set_reach(reach)
|
||||
self.plot_ac.set_reach(reach)
|
||||
|
||||
profile = structure.input_section
|
||||
profile = self._hs_lst.get(rows[0]).input_section
|
||||
if profile is not None:
|
||||
profiles = reach.reach\
|
||||
.get_profiles_from_rk(
|
||||
|
||||
@@ -55,27 +55,17 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
self._trad = trad
|
||||
self._ic_spec_lst = ic_spec_lst
|
||||
|
||||
def _specifications(self):
|
||||
if hasattr(
|
||||
self._ic_spec_lst,
|
||||
"get_specs_for_enabled_reaches"
|
||||
):
|
||||
return self._ic_spec_lst.get_specs_for_enabled_reaches(
|
||||
self._data.edges()
|
||||
)
|
||||
return self._ic_spec_lst
|
||||
|
||||
def createEditor(self, parent, option, index):
|
||||
self.editor = QComboBox(parent)
|
||||
|
||||
val = []
|
||||
if self._mode == "rk":
|
||||
reach_id = self._specifications()[index.row()].reach
|
||||
reach_id = self._ic_spec_lst[index.row()].reach
|
||||
|
||||
reach = next(filter(lambda edge: edge.id == reach_id,
|
||||
self._data.edges()), None)
|
||||
|
||||
if reach is not None:
|
||||
if reach_id is not None:
|
||||
val = list(
|
||||
map(
|
||||
lambda rk: str(rk), reach.reach.get_rk()
|
||||
@@ -84,7 +74,7 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
else:
|
||||
val = list(
|
||||
map(
|
||||
lambda n: n.name, self._data.enable_edges()
|
||||
lambda n: n.name, self._data.edges()
|
||||
)
|
||||
)
|
||||
|
||||
@@ -127,8 +117,11 @@ class InitialConditionTableModel(PamhyrTableModel):
|
||||
self._data = data
|
||||
|
||||
def _setup_lst(self):
|
||||
self._lst = self._data.get_specs_for_enabled_reaches(
|
||||
self._river.edges()
|
||||
self._lst = list(
|
||||
filter(
|
||||
lambda ica: ica._deleted is False,
|
||||
self._data._data
|
||||
)
|
||||
)
|
||||
|
||||
def rowCount(self, parent):
|
||||
@@ -144,7 +137,7 @@ class InitialConditionTableModel(PamhyrTableModel):
|
||||
if self._headers[column] == "name":
|
||||
n = self._lst[row].name
|
||||
if n is None or n == "":
|
||||
return self._trad['not_defined']
|
||||
return self._trad['not_associated']
|
||||
return n
|
||||
elif self._headers[column] == "reach":
|
||||
n = self._lst[row].reach
|
||||
@@ -166,27 +159,27 @@ class InitialConditionTableModel(PamhyrTableModel):
|
||||
elif self._headers[column] == "concentration":
|
||||
n = self._lst[row].concentration
|
||||
if n is None:
|
||||
return self._trad['not_defined']
|
||||
return self._trad['not_associated']
|
||||
return n
|
||||
elif self._headers[column] == "eg":
|
||||
n = self._lst[row].eg
|
||||
if n is None:
|
||||
return self._trad['not_defined']
|
||||
return self._trad['not_associated']
|
||||
return n
|
||||
elif self._headers[column] == "em":
|
||||
n = self._lst[row].em
|
||||
if n is None:
|
||||
return self._trad['not_defined']
|
||||
return self._trad['not_associated']
|
||||
return n
|
||||
elif self._headers[column] == "ed":
|
||||
n = self._lst[row].ed
|
||||
if n is None:
|
||||
return self._trad['not_defined']
|
||||
return self._trad['not_associated']
|
||||
return n
|
||||
elif self._headers[column] == "rate":
|
||||
n = self._lst[row].rate
|
||||
if n is None:
|
||||
return self._trad['not_defined']
|
||||
return self._trad['not_associated']
|
||||
return n
|
||||
|
||||
return QVariant()
|
||||
|
||||
@@ -152,14 +152,14 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
|
||||
self._delegate_reach = ComboBoxDelegate(
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
ic_spec_lst=self._data[0],
|
||||
ic_spec_lst=self._data[0]._data,
|
||||
parent=self,
|
||||
mode="reaches"
|
||||
)
|
||||
self._delegate_rk = ComboBoxDelegate(
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
ic_spec_lst=self._data[0],
|
||||
ic_spec_lst=self._data[0]._data,
|
||||
parent=self,
|
||||
mode="rk"
|
||||
)
|
||||
@@ -308,10 +308,7 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
|
||||
|
||||
def add(self):
|
||||
rows = self.index_selected_rows()
|
||||
visible = self._data[0].get_specs_for_enabled_reaches(
|
||||
self._study.river.edges()
|
||||
)
|
||||
if len(visible) == 0 or len(rows) == 0:
|
||||
if len(self._data[0]._data) == 0 or len(rows) == 0:
|
||||
self._table_spec.add(0)
|
||||
else:
|
||||
self._table_spec.add(rows[0])
|
||||
|
||||
@@ -1,307 +0,0 @@
|
||||
# Table.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 -*-
|
||||
|
||||
import logging
|
||||
import traceback
|
||||
from tools import trace, timer
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel,
|
||||
QCoreApplication, QModelIndex, pyqtSlot,
|
||||
QRect,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QPushButton, QLineEdit,
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QComboBox,
|
||||
)
|
||||
|
||||
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||
|
||||
from View.InitialConditionsTemperature.UndoCommand import (
|
||||
SetCommand, AddCommand, SetCommandSpec,
|
||||
DelCommand,
|
||||
)
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class ComboBoxDelegate(QItemDelegate):
|
||||
def __init__(self, data=None, ic_spec_lst=None,
|
||||
trad=None, parent=None, mode="reaches"):
|
||||
super(ComboBoxDelegate, self).__init__(parent)
|
||||
|
||||
self._data = data
|
||||
self._mode = mode
|
||||
self._trad = trad
|
||||
self._ic_spec_lst = ic_spec_lst
|
||||
|
||||
def createEditor(self, parent, option, index):
|
||||
self.editor = QComboBox(parent)
|
||||
|
||||
val = []
|
||||
if self._mode == "rk":
|
||||
reach_id = self._ic_spec_lst[index.row()].reach
|
||||
|
||||
reach = next(filter(lambda edge: edge.id == reach_id,
|
||||
self._data.edges()), None)
|
||||
|
||||
if reach is not None:
|
||||
val = list(
|
||||
map(
|
||||
lambda profile: profile.display_name(),
|
||||
reach.reach.profiles
|
||||
)
|
||||
)
|
||||
else:
|
||||
val = list(
|
||||
map(
|
||||
lambda n: n.name, self._data.enable_edges()
|
||||
)
|
||||
)
|
||||
|
||||
self.editor.addItems(
|
||||
[self._trad['not_associated']] +
|
||||
val
|
||||
)
|
||||
|
||||
self.editor.setCurrentText(str(index.data(Qt.DisplayRole)))
|
||||
return self.editor
|
||||
|
||||
def setEditorData(self, editor, index):
|
||||
value = index.data(Qt.DisplayRole)
|
||||
self.editor.currentTextChanged.connect(self.currentItemChanged)
|
||||
|
||||
def setModelData(self, editor, model, index):
|
||||
text = str(editor.currentText())
|
||||
value = text
|
||||
|
||||
if self._mode == "rk":
|
||||
reach_id = self._ic_spec_lst[index.row()].reach
|
||||
reach = next(
|
||||
(
|
||||
edge for edge in self._data.edges()
|
||||
if edge.id == reach_id
|
||||
),
|
||||
None
|
||||
)
|
||||
if reach is not None:
|
||||
profile = next(
|
||||
(
|
||||
profile for profile in reach.reach.profiles
|
||||
if profile.display_name() == text
|
||||
),
|
||||
None
|
||||
)
|
||||
if profile is not None:
|
||||
value = profile.rk
|
||||
|
||||
model.setData(index, value)
|
||||
editor.close()
|
||||
editor.deleteLater()
|
||||
|
||||
def updateEditorGeometry(self, editor, option, index):
|
||||
r = QRect(option.rect)
|
||||
if self.editor.windowFlags() & Qt.Popup:
|
||||
if editor.parent() is not None:
|
||||
r.setTopLeft(self.editor.parent().mapToGlobal(r.topLeft()))
|
||||
editor.setGeometry(r)
|
||||
|
||||
@pyqtSlot()
|
||||
def currentItemChanged(self):
|
||||
self.commitData.emit(self.sender())
|
||||
|
||||
|
||||
class InitialConditionTableModel(PamhyrTableModel):
|
||||
def __init__(self, river=None, data=None, **kwargs):
|
||||
self._river = river
|
||||
|
||||
super(InitialConditionTableModel, self).__init__(data=data, **kwargs)
|
||||
|
||||
self._data = data
|
||||
|
||||
def _setup_lst(self):
|
||||
enabled_reach_ids = {
|
||||
reach.id
|
||||
for reach in self._river.enable_edges()
|
||||
}
|
||||
self._lst = list(
|
||||
filter(
|
||||
lambda ica: (
|
||||
ica._deleted is False and
|
||||
(
|
||||
ica.reach in (None, -1) or
|
||||
ica.reach in enabled_reach_ids
|
||||
)
|
||||
),
|
||||
self._data._data
|
||||
)
|
||||
)
|
||||
|
||||
def refresh(self):
|
||||
self.beginResetModel()
|
||||
try:
|
||||
self._setup_lst()
|
||||
finally:
|
||||
self.endResetModel()
|
||||
|
||||
def rowCount(self, parent):
|
||||
return len(self._lst)
|
||||
|
||||
def data(self, index, role):
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
return QVariant()
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
if self._headers[column] == "name":
|
||||
n = self._lst[row].name
|
||||
if n is None or n == "":
|
||||
return self._trad['not_defined']
|
||||
return n
|
||||
elif self._headers[column] == "reach":
|
||||
n = self._lst[row].reach
|
||||
if n is None:
|
||||
return self._trad['not_associated']
|
||||
return next(filter(
|
||||
lambda edge: edge.id == n, self._river.edges()
|
||||
)).name
|
||||
elif self._headers[column] == "rk":
|
||||
n = self._lst[row].start_rk
|
||||
if n is None:
|
||||
return self._trad['not_associated']
|
||||
return self._rk_display_name(row, n)
|
||||
elif self._headers[column] == "temperature":
|
||||
n = self._lst[row].temperature
|
||||
if n is None:
|
||||
return self._trad['not_defined']
|
||||
return n
|
||||
|
||||
return QVariant()
|
||||
|
||||
def _rk_display_name(self, row, rk):
|
||||
reach_id = self._lst[row].reach
|
||||
reach = next(
|
||||
(
|
||||
edge for edge in self._river.edges()
|
||||
if edge.id == reach_id
|
||||
),
|
||||
None
|
||||
)
|
||||
if reach is None:
|
||||
return str(rk)
|
||||
|
||||
profile = next(
|
||||
(
|
||||
profile for profile in reach.reach.profiles
|
||||
if profile.rk == rk
|
||||
),
|
||||
None
|
||||
)
|
||||
return profile.display_name() if profile is not None else str(rk)
|
||||
|
||||
def setData(self, index, value, role=Qt.EditRole):
|
||||
if not index.isValid() or role != Qt.EditRole:
|
||||
return False
|
||||
|
||||
if self.is_same_data(index, value):
|
||||
return False
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
try:
|
||||
if self._headers[column] in ["name", "temperature"]:
|
||||
self._undo.push(
|
||||
SetCommand(
|
||||
self._lst, row, self._headers[column], value
|
||||
)
|
||||
)
|
||||
else:
|
||||
new_value = value
|
||||
if self._headers[column] == "reach":
|
||||
reach = self._river.edge(value)
|
||||
rks = reach.reach.get_rk()
|
||||
if not rks:
|
||||
return False
|
||||
new_value = (reach.id, min(rks))
|
||||
|
||||
self._undo.push(
|
||||
SetCommandSpec(
|
||||
self._lst, row, self._headers[column],
|
||||
new_value
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
logger.debug(traceback.format_exc())
|
||||
|
||||
if self._headers[column] == "reach":
|
||||
rk_index = self.index(
|
||||
row, self._headers.index("rk")
|
||||
)
|
||||
self.dataChanged.emit(index, rk_index)
|
||||
else:
|
||||
self.dataChanged.emit(index, index)
|
||||
return True
|
||||
|
||||
def add(self, row, parent=QModelIndex()):
|
||||
self.beginInsertRows(parent, row, row - 1)
|
||||
|
||||
self._undo.push(
|
||||
AddCommand(
|
||||
self._data, self._lst, row
|
||||
)
|
||||
)
|
||||
|
||||
self._setup_lst()
|
||||
self.endInsertRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def delete(self, rows, parent=QModelIndex()):
|
||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||
|
||||
data_rows = {
|
||||
id(ica): i for i, ica in enumerate(self._data._data)
|
||||
}
|
||||
self._undo.push(
|
||||
DelCommand(
|
||||
self._data,
|
||||
self._data._data,
|
||||
[data_rows[id(self._lst[row])] for row in rows]
|
||||
)
|
||||
)
|
||||
|
||||
self._setup_lst()
|
||||
self.endRemoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def undo(self):
|
||||
self._undo.undo()
|
||||
self._setup_lst()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def redo(self):
|
||||
self._undo.redo()
|
||||
self._setup_lst()
|
||||
self.layoutChanged.emit()
|
||||
@@ -1,94 +0,0 @@
|
||||
# Table.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 -*-
|
||||
|
||||
import logging
|
||||
import traceback
|
||||
from tools import trace, timer
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel,
|
||||
QCoreApplication, QModelIndex, pyqtSlot,
|
||||
QRect,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QPushButton, QLineEdit,
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QComboBox,
|
||||
)
|
||||
|
||||
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||
|
||||
from View.InitialConditionsTemperature.UndoCommand import (
|
||||
SetCommand,
|
||||
)
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class InitialConditionTableDefaultModel(PamhyrTableModel):
|
||||
def __init__(self, **kwargs):
|
||||
super(InitialConditionTableDefaultModel, self).__init__(**kwargs)
|
||||
|
||||
def data(self, index, role):
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
return QVariant()
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
if self._headers[column] == "name":
|
||||
return self._data[row].name
|
||||
elif self._headers[column] == "temperature":
|
||||
n = self._data[row].temperature
|
||||
if n is None:
|
||||
return 0
|
||||
return n
|
||||
|
||||
return QVariant()
|
||||
|
||||
def setData(self, index, value, role=Qt.EditRole):
|
||||
if not index.isValid() or role != Qt.EditRole:
|
||||
return False
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
try:
|
||||
if self._headers[column] is not None:
|
||||
self._undo.push(
|
||||
SetCommand(
|
||||
self._data, row, self._headers[column], value
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
logger.debug(traceback.format_exc())
|
||||
|
||||
self.dataChanged.emit(index, index)
|
||||
return True
|
||||
|
||||
def undo(self):
|
||||
self._undo.undo()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def redo(self):
|
||||
self._undo.redo()
|
||||
self.layoutChanged.emit()
|
||||
@@ -1,159 +0,0 @@
|
||||
# UndoCommand.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 copy import deepcopy
|
||||
from tools import trace, timer
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QMessageBox, QUndoCommand, QUndoStack,
|
||||
)
|
||||
|
||||
from Model.InitialConditionsTemperature.InitialConditionsTemperature \
|
||||
import InitialConditionsTemperature
|
||||
from Model.InitialConditionsTemperature.InitialConditionsTemperatureList \
|
||||
import InitialConditionsTemperatureList
|
||||
|
||||
|
||||
class SetCommand(QUndoCommand):
|
||||
def __init__(self, data, row, column, new_value):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._data = data
|
||||
self._row = row
|
||||
self._column = column
|
||||
|
||||
if self._column == "name":
|
||||
self._old = self._data[self._row].name
|
||||
elif self._column == "temperature":
|
||||
self._old = self._data[self._row].temperature
|
||||
|
||||
_type = float
|
||||
if column == "name":
|
||||
_type = str
|
||||
|
||||
self._new = _type(new_value)
|
||||
|
||||
def undo(self):
|
||||
if self._column == "name":
|
||||
self._data[self._row].name = self._old
|
||||
elif self._column == "temperature":
|
||||
self._data[self._row].temperature = self._old
|
||||
|
||||
def redo(self):
|
||||
if self._column == "name":
|
||||
self._data[self._row].name = self._new
|
||||
elif self._column == "temperature":
|
||||
self._data[self._row].temperature = self._new
|
||||
|
||||
|
||||
class SetCommandSpec(QUndoCommand):
|
||||
def __init__(self, data, row, column, new_value):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._data = data
|
||||
self._row = row
|
||||
self._column = column
|
||||
|
||||
if self._column == "name":
|
||||
self._old = self._data[self._row].name
|
||||
elif self._column == "reach":
|
||||
self._old = self._data[self._row].reach
|
||||
self._old_start_rk = self._data[self._row].start_rk
|
||||
self._old_end_rk = self._data[self._row].end_rk
|
||||
elif self._column == "rk":
|
||||
self._old = self._data[self._row].start_rk
|
||||
elif self._column == "temperature":
|
||||
self._old = self._data[self._row].temperature
|
||||
|
||||
_type = float
|
||||
if column == "name":
|
||||
_type = str
|
||||
elif column == "reach":
|
||||
_type = int
|
||||
|
||||
if column == "reach":
|
||||
self._new = _type(new_value[0])
|
||||
self._new_rk = float(new_value[1])
|
||||
else:
|
||||
self._new = _type(new_value)
|
||||
|
||||
def undo(self):
|
||||
if self._column == "name":
|
||||
self._data[self._row].name = self._old
|
||||
elif self._column == "reach":
|
||||
self._data[self._row].reach = self._old
|
||||
self._data[self._row].start_rk = self._old_start_rk
|
||||
self._data[self._row].end_rk = self._old_end_rk
|
||||
elif self._column == "rk":
|
||||
self._data[self._row].start_rk = self._old
|
||||
self._data[self._row].end_rk = self._old
|
||||
elif self._column == "temperature":
|
||||
self._data[self._row].temperature = self._old
|
||||
|
||||
def redo(self):
|
||||
if self._column == "name":
|
||||
self._data[self._row].name = self._new
|
||||
elif self._column == "reach":
|
||||
self._data[self._row].reach = self._new
|
||||
self._data[self._row].start_rk = self._new_rk
|
||||
self._data[self._row].end_rk = self._new_rk
|
||||
elif self._column == "rk":
|
||||
self._data[self._row].start_rk = self._new
|
||||
self._data[self._row].end_rk = self._new
|
||||
elif self._column == "temperature":
|
||||
self._data[self._row].temperature = self._new
|
||||
|
||||
|
||||
class AddCommand(QUndoCommand):
|
||||
def __init__(self, data, ics_spec, index):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._data = data
|
||||
self._ics_spec = ics_spec
|
||||
self._index = index
|
||||
self._new = None
|
||||
|
||||
def undo(self):
|
||||
self._data.delete_i([self._index])
|
||||
|
||||
def redo(self):
|
||||
if self._new is None:
|
||||
self._new = self._data.new(self._index)
|
||||
else:
|
||||
self._data.insert(self._index, self._new)
|
||||
|
||||
|
||||
class DelCommand(QUndoCommand):
|
||||
def __init__(self, data, ics_spec, rows):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._data = data
|
||||
self._ics_spec = ics_spec
|
||||
self._rows = rows
|
||||
|
||||
self._ic = []
|
||||
for row in rows:
|
||||
self._ic.append((row, self._ics_spec[row]))
|
||||
self._ic.sort()
|
||||
|
||||
def undo(self):
|
||||
for row, el in self._ic:
|
||||
self._data.insert(row, el)
|
||||
|
||||
def redo(self):
|
||||
self._data.delete_i(self._rows)
|
||||
@@ -1,318 +0,0 @@
|
||||
# Window.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 -*-
|
||||
|
||||
import os
|
||||
import logging
|
||||
|
||||
from tools import trace, timer, logger_exception
|
||||
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
|
||||
from PyQt5.QtGui import (
|
||||
QKeySequence, QIcon,
|
||||
)
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel,
|
||||
QCoreApplication, QModelIndex, pyqtSlot,
|
||||
QRect, QItemSelectionModel,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QPushButton, QLineEdit,
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
|
||||
QVBoxLayout, QToolBar, QAction, QToolButton,
|
||||
)
|
||||
|
||||
from Modules import Modules
|
||||
|
||||
from View.InitialConditionsTemperature.UndoCommand import (
|
||||
SetCommand,
|
||||
)
|
||||
|
||||
from View.InitialConditionsTemperature.TableDefault import (
|
||||
InitialConditionTableDefaultModel,
|
||||
)
|
||||
|
||||
from View.InitialConditionsTemperature.Table import (
|
||||
InitialConditionTableModel, ComboBoxDelegate,
|
||||
)
|
||||
|
||||
from View.InitialConditionsTemperature.translate import IcTemperatureTranslate
|
||||
|
||||
from Solver.Mage import Mage8
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class InitialConditionsTemperatureWindow(PamhyrWindow):
|
||||
_pamhyr_ui = "InitialConditionsTemperature"
|
||||
_pamhyr_name = "Initial condition Temperature"
|
||||
|
||||
def __init__(self, data=None, study=None,
|
||||
config=None, parent=None):
|
||||
self._data = []
|
||||
self._data.append(data)
|
||||
trad = IcTemperatureTranslate()
|
||||
|
||||
name = (
|
||||
trad[self._pamhyr_name] +
|
||||
" - " + study.name
|
||||
)
|
||||
|
||||
super(InitialConditionsTemperatureWindow, self).__init__(
|
||||
title=name,
|
||||
study=study,
|
||||
config=config,
|
||||
trad=trad,
|
||||
parent=parent
|
||||
)
|
||||
self._hash_data.append(data)
|
||||
|
||||
# self._ics_Temperature_lst = study.river.ic_Temperature
|
||||
|
||||
self.setup_table()
|
||||
|
||||
def setup_table(self):
|
||||
|
||||
path_icons = os.path.join(self._get_ui_directory(), f"ressources")
|
||||
|
||||
table_default = self.find(QTableView, f"tableView")
|
||||
|
||||
if self._study.is_editable():
|
||||
editable_headers = self._trad.get_dict("table_headers")
|
||||
else:
|
||||
editable_headers = []
|
||||
|
||||
self._table = InitialConditionTableDefaultModel(
|
||||
table_view=table_default,
|
||||
table_headers=self._trad.get_dict("table_headers"),
|
||||
editable_headers=editable_headers,
|
||||
delegates={},
|
||||
data=self._data,
|
||||
undo=self._undo_stack,
|
||||
trad=self._trad
|
||||
)
|
||||
|
||||
table_default.setModel(self._table)
|
||||
table_default.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
table_default.horizontalHeader().setSectionResizeMode(
|
||||
QHeaderView.Stretch
|
||||
)
|
||||
table_default.setAlternatingRowColors(True)
|
||||
|
||||
layout = self.find(QVBoxLayout, f"verticalLayout_1")
|
||||
toolBar = QToolBar()
|
||||
layout.addWidget(toolBar)
|
||||
|
||||
action_add = QAction(self)
|
||||
action_add.setIcon(QIcon(os.path.join(path_icons, f"add.png")))
|
||||
|
||||
if self._study.is_editable():
|
||||
action_add.triggered.connect(self.add)
|
||||
action_delete = QAction(self)
|
||||
action_delete.setIcon(QIcon(os.path.join(path_icons, f"del.png")))
|
||||
|
||||
if self._study.is_editable():
|
||||
action_delete.triggered.connect(self.delete)
|
||||
|
||||
toolBar.addAction(action_add)
|
||||
toolBar.addAction(action_delete)
|
||||
|
||||
self.table_spec = QTableView()
|
||||
layout.addWidget(self.table_spec)
|
||||
|
||||
self._delegate_reach = ComboBoxDelegate(
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
ic_spec_lst=self._data[0]._data,
|
||||
parent=self,
|
||||
mode="reaches"
|
||||
)
|
||||
self._delegate_rk = ComboBoxDelegate(
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
ic_spec_lst=self._data[0]._data,
|
||||
parent=self,
|
||||
mode="rk"
|
||||
)
|
||||
|
||||
if self._study.is_editable():
|
||||
editable_headers_spec = self._trad.get_dict("table_headers_spec")
|
||||
else:
|
||||
editable_headers_spec = []
|
||||
|
||||
self._table_spec = InitialConditionTableModel(
|
||||
table_view=self.table_spec,
|
||||
table_headers=self._trad.get_dict("table_headers_spec"),
|
||||
editable_headers=editable_headers_spec,
|
||||
delegates={
|
||||
"reach": self._delegate_reach,
|
||||
"rk": self._delegate_rk
|
||||
},
|
||||
data=self._data[0],
|
||||
undo=self._undo_stack,
|
||||
trad=self._trad,
|
||||
river=self._study.river
|
||||
)
|
||||
|
||||
self.table_spec.setModel(self._table_spec)
|
||||
self.table_spec.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
self.table_spec.horizontalHeader().setSectionResizeMode(
|
||||
QHeaderView.Stretch
|
||||
)
|
||||
self.table_spec.setAlternatingRowColors(True)
|
||||
|
||||
selectionModel = self.table_spec.selectionModel()
|
||||
index = self.table_spec.model().index(0, 0)
|
||||
|
||||
selectionModel.select(
|
||||
index,
|
||||
QItemSelectionModel.Rows |
|
||||
QItemSelectionModel.ClearAndSelect |
|
||||
QItemSelectionModel.Select
|
||||
)
|
||||
self.table_spec.scrollTo(index)
|
||||
|
||||
def index_selected_row(self):
|
||||
# table = self.find(QTableView, f"tableView")
|
||||
table = self.table_spec
|
||||
rows = table.selectionModel()\
|
||||
.selectedRows()
|
||||
|
||||
if len(rows) == 0:
|
||||
return 0
|
||||
|
||||
return rows[0].row()
|
||||
|
||||
def index_selected_rows(self):
|
||||
# table = self.find(QTableView, f"tableView")
|
||||
table = self.table_spec
|
||||
return list(
|
||||
# Delete duplicate
|
||||
set(
|
||||
map(
|
||||
lambda i: i.row(),
|
||||
table.selectedIndexes()
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def move_up(self):
|
||||
row = self.index_selected_row()
|
||||
self._table.move_up(row)
|
||||
self._update()
|
||||
|
||||
def move_down(self):
|
||||
row = self.index_selected_row()
|
||||
self._table.move_down(row)
|
||||
self._update()
|
||||
|
||||
def _copy(self):
|
||||
rows = list(
|
||||
map(
|
||||
lambda row: row.row(),
|
||||
self.tableView.selectionModel().selectedRows()
|
||||
)
|
||||
)
|
||||
|
||||
table = list(
|
||||
map(
|
||||
lambda eic: list(
|
||||
map(
|
||||
lambda k: eic[1][k],
|
||||
["rk", "discharge", "elevation"]
|
||||
)
|
||||
),
|
||||
filter(
|
||||
lambda eic: eic[0] in rows,
|
||||
enumerate(self._ics.lst())
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
self.copyTableIntoClipboard(table)
|
||||
|
||||
def _paste(self):
|
||||
header, data = self.parseClipboardTable()
|
||||
|
||||
if len(data) + len(header) == 0:
|
||||
return
|
||||
|
||||
logger.debug(
|
||||
"IC: Paste: " +
|
||||
f"header = {header}, " +
|
||||
f"data = {data}"
|
||||
)
|
||||
|
||||
try:
|
||||
row = self.index_selected_row()
|
||||
# self._table.paste(row, header, data)
|
||||
self._table.paste(row, [], data)
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
|
||||
self._update()
|
||||
|
||||
def _undo(self):
|
||||
undo_stack = self._undo_stack
|
||||
if undo_stack is None or not undo_stack.canUndo():
|
||||
return
|
||||
|
||||
if isinstance(undo_stack.command(undo_stack.index() - 1), SetCommand):
|
||||
self._table.undo()
|
||||
else:
|
||||
self._table_spec.undo()
|
||||
|
||||
self._update()
|
||||
|
||||
def _redo(self):
|
||||
undo_stack = self._undo_stack
|
||||
if undo_stack is None or not undo_stack.canRedo():
|
||||
return
|
||||
|
||||
if isinstance(undo_stack.command(undo_stack.index()), SetCommand):
|
||||
self._table.redo()
|
||||
else:
|
||||
self._table_spec.redo()
|
||||
|
||||
self._update()
|
||||
|
||||
def add(self):
|
||||
rows = self.index_selected_rows()
|
||||
if len(self._data[0]._data) == 0 or len(rows) == 0:
|
||||
self._table_spec.add(0)
|
||||
else:
|
||||
self._table_spec.add(rows[0])
|
||||
|
||||
def delete(self):
|
||||
rows = self.index_selected_rows()
|
||||
if len(rows) == 0:
|
||||
return
|
||||
self._table_spec.delete(rows)
|
||||
|
||||
def _propagated_update(self, key=Modules(0)):
|
||||
if Modules.NETWORK not in key:
|
||||
return
|
||||
|
||||
self._table_spec.refresh()
|
||||
self.table_spec.clearSelection()
|
||||
@@ -1,45 +0,0 @@
|
||||
# translate.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 PyQt5.QtCore import QCoreApplication
|
||||
|
||||
from View.Translate import MainTranslate
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class IcTemperatureTranslate(MainTranslate):
|
||||
def __init__(self):
|
||||
super(IcTemperatureTranslate, self).__init__()
|
||||
|
||||
self._dict["Initial condition Temperature"] = _translate(
|
||||
"InitialConditionTemperature", "Initial condition temperature")
|
||||
|
||||
self._dict["rk"] = self._dict["unit_rk"]
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
"name": self._dict["name"],
|
||||
"temperature": self._dict["unit_temperature"],
|
||||
}
|
||||
|
||||
self._sub_dict["table_headers_spec"] = {
|
||||
"name": self._dict["name"],
|
||||
"reach": self._dict["reach"],
|
||||
"rk": _translate("Unit", "RK (m)"),
|
||||
"temperature": self._dict["unit_temperature"],
|
||||
}
|
||||
@@ -147,7 +147,6 @@ class EditLateralContributionWindow(PamhyrWindow):
|
||||
|
||||
def update(self):
|
||||
self.plot.update()
|
||||
self.plot.fit_to_data()
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
|
||||
@@ -103,10 +103,7 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
else:
|
||||
self.editor.addItems(
|
||||
[self._trad['not_associated']] +
|
||||
[
|
||||
reach.name
|
||||
for reach in self._data.enable_edges()
|
||||
]
|
||||
self._data.edges_names()
|
||||
)
|
||||
|
||||
self.editor.setCurrentText(index.data(Qt.DisplayRole))
|
||||
@@ -157,9 +154,7 @@ class TableModel(PamhyrTableModel):
|
||||
self._long_types = self._trad.get_dict("long_types")
|
||||
|
||||
def get_true_data_row(self, row):
|
||||
lc = self._lst.get_for_enabled_reaches(self._tab, row)
|
||||
if lc is None:
|
||||
return len(self._lst.get_tab(self._tab))
|
||||
lc = self._lst.get(self._tab, row)
|
||||
|
||||
return next(
|
||||
map(
|
||||
@@ -172,7 +167,7 @@ class TableModel(PamhyrTableModel):
|
||||
)
|
||||
|
||||
def rowCount(self, parent):
|
||||
return len(self._lst.get_tab_for_enabled_reaches(self._tab))
|
||||
return self._lst.len(self._tab)
|
||||
|
||||
def data(self, index, role):
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
@@ -180,22 +175,21 @@ class TableModel(PamhyrTableModel):
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
contribution = self._lst.get_for_enabled_reaches(self._tab, row)
|
||||
|
||||
if self._headers[column] == "name":
|
||||
return contribution.name
|
||||
return self._lst.get(self._tab, row).name
|
||||
elif self._headers[column] == "type":
|
||||
t = contribution.lctype
|
||||
t = self._lst.get(self._tab, row).lctype
|
||||
return self._long_types[t]
|
||||
elif self._headers[column] == "edge":
|
||||
n = contribution.reach
|
||||
n = self._lst.get(self._tab, row).reach
|
||||
if n is None:
|
||||
return self._trad['not_associated']
|
||||
return n.name
|
||||
elif self._headers[column] == "begin_rk":
|
||||
return str(contribution.begin_rk)
|
||||
return str(self._lst.get(self._tab, row).begin_rk)
|
||||
elif self._headers[column] == "end_rk":
|
||||
return str(contribution.end_rk)
|
||||
return str(self._lst.get(self._tab, row).end_rk)
|
||||
|
||||
return QVariant()
|
||||
|
||||
@@ -208,8 +202,6 @@ class TableModel(PamhyrTableModel):
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
contribution = self._lst.get_for_enabled_reaches(self._tab, row)
|
||||
row = self.get_true_data_row(row)
|
||||
|
||||
try:
|
||||
if self._headers[column] == "name":
|
||||
@@ -233,7 +225,7 @@ class TableModel(PamhyrTableModel):
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "begin_rk":
|
||||
_edge = contribution.reach
|
||||
_edge = self._lst.get(self._tab, row).reach
|
||||
_begin_rk = next(
|
||||
p for p in _edge.reach.profiles
|
||||
if p.pamhyr_id == value
|
||||
@@ -244,7 +236,7 @@ class TableModel(PamhyrTableModel):
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "end_rk":
|
||||
_edge = contribution.reach
|
||||
_edge = self._lst.get(self._tab, row).reach
|
||||
_end_rk = next(
|
||||
p for p in _edge.reach.profiles
|
||||
if p.pamhyr_id == value
|
||||
|
||||
@@ -213,11 +213,11 @@ class LateralContributionWindow(PamhyrWindow):
|
||||
if len(rows) > 0:
|
||||
edge = self._study.river\
|
||||
.lateral_contribution\
|
||||
.get_for_enabled_reaches(tab, rows[0])\
|
||||
.get(tab, rows[0])\
|
||||
.reach
|
||||
if edge:
|
||||
data = edge.reach
|
||||
lc = self._lcs.get_for_enabled_reaches(tab, rows[0])
|
||||
lc = self._lcs.get(tab, rows[0])
|
||||
highlight = (lc.begin_rk, lc.end_rk)
|
||||
|
||||
for delegate in self._delegate_rk:
|
||||
@@ -236,8 +236,7 @@ class LateralContributionWindow(PamhyrWindow):
|
||||
def add(self):
|
||||
tab = self.current_tab()
|
||||
rows = self.index_selected_rows()
|
||||
visible = self._lcs.get_tab_for_enabled_reaches(tab)
|
||||
if len(visible) == 0 or len(rows) == 0:
|
||||
if self._lcs.len(tab) == 0 or len(rows) == 0:
|
||||
self._table[tab].add(0)
|
||||
else:
|
||||
self._table[tab].add(rows[0])
|
||||
@@ -292,7 +291,7 @@ class LateralContributionWindow(PamhyrWindow):
|
||||
tab = self.current_tab()
|
||||
rows = self.index_selected_rows()
|
||||
for row in rows:
|
||||
data = self._lcs.get_for_enabled_reaches(tab, row)
|
||||
data = self._lcs.get(tab, row)
|
||||
|
||||
if self.sub_window_exists(
|
||||
EditLateralContributionWindow,
|
||||
|
||||
@@ -160,7 +160,6 @@ class EditLateralContributionAdisTSWindow(PamhyrWindow):
|
||||
|
||||
def update(self):
|
||||
self.plot.update()
|
||||
self.plot.fit_to_data()
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
|
||||
@@ -81,10 +81,7 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
else:
|
||||
self.editor.addItems(
|
||||
[self._trad['not_associated']] +
|
||||
[
|
||||
reach.name
|
||||
for reach in self._data.enable_edges()
|
||||
]
|
||||
self._data.edges_names()
|
||||
)
|
||||
|
||||
self.editor.setCurrentText(index.data(Qt.DisplayRole))
|
||||
@@ -122,11 +119,6 @@ class TableModel(PamhyrTableModel):
|
||||
self._setup_lst()
|
||||
|
||||
def _setup_lst(self):
|
||||
enabled_reach_ids = {
|
||||
reach.id
|
||||
for reach in self._data.enable_edges()
|
||||
}
|
||||
|
||||
if self._lcs_list is not None:
|
||||
self._lcs_pol_list = [
|
||||
lcs for lcs in self._lcs_list._lst
|
||||
@@ -135,13 +127,7 @@ class TableModel(PamhyrTableModel):
|
||||
|
||||
self._lst = list(
|
||||
filter(
|
||||
lambda x: (
|
||||
x._deleted is False and
|
||||
(
|
||||
x.reach in (None, -1) or
|
||||
x.reach in enabled_reach_ids
|
||||
)
|
||||
),
|
||||
lambda x: x._deleted is False,
|
||||
self._lcs_pol_list
|
||||
)
|
||||
)
|
||||
@@ -151,18 +137,6 @@ class TableModel(PamhyrTableModel):
|
||||
def rowCount(self, parent):
|
||||
return len(self._lst)
|
||||
|
||||
def get(self, row):
|
||||
if 0 <= row < len(self._lst):
|
||||
return self._lst[row]
|
||||
return None
|
||||
|
||||
def refresh(self):
|
||||
self.beginResetModel()
|
||||
try:
|
||||
self._setup_lst()
|
||||
finally:
|
||||
self.endResetModel()
|
||||
|
||||
def data(self, index, role):
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
return QVariant()
|
||||
@@ -196,18 +170,11 @@ class TableModel(PamhyrTableModel):
|
||||
|
||||
try:
|
||||
if self._headers[column] == "reach":
|
||||
reach = self._data.reach(value)
|
||||
rks = reach.reach.get_rk()
|
||||
if len(rks) == 0:
|
||||
return False
|
||||
|
||||
self._undo.push(
|
||||
SetReachCommand(
|
||||
self._lcs_list, self._lst,
|
||||
row,
|
||||
reach.id,
|
||||
min(rks),
|
||||
max(rks)
|
||||
self._data.reach(value).id
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "begin_rk":
|
||||
@@ -226,13 +193,7 @@ class TableModel(PamhyrTableModel):
|
||||
logger.info(e)
|
||||
logger.debug(traceback.format_exc())
|
||||
|
||||
if self._headers[column] == "reach":
|
||||
end_index = self.index(
|
||||
row, self._headers.index("end_rk")
|
||||
)
|
||||
self.dataChanged.emit(index, end_index)
|
||||
else:
|
||||
self.dataChanged.emit(index, index)
|
||||
self.dataChanged.emit(index, index)
|
||||
return True
|
||||
|
||||
def add(self, row, parent=QModelIndex()):
|
||||
|
||||
@@ -64,30 +64,20 @@ class SetEndCommand(QUndoCommand):
|
||||
|
||||
|
||||
class SetReachCommand(QUndoCommand):
|
||||
def __init__(self, lcs, lcs_lst, index, reach, begin_rk, end_rk):
|
||||
def __init__(self, lcs, lcs_lst, index, reach):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._lcs_lst = lcs_lst
|
||||
self._index = index
|
||||
self._old = self._lcs_lst[self._index].reach
|
||||
self._old_begin_rk = self._lcs_lst[self._index].begin_rk
|
||||
self._old_end_rk = self._lcs_lst[self._index].end_rk
|
||||
self._new = reach
|
||||
self._new_begin_rk = begin_rk
|
||||
self._new_end_rk = end_rk
|
||||
|
||||
def undo(self):
|
||||
contribution = self._lcs_lst[self._index]
|
||||
contribution.reach = self._old
|
||||
contribution.begin_rk = self._old_begin_rk
|
||||
contribution.end_rk = self._old_end_rk
|
||||
self._lcs_lst[self._index].reach = self._old
|
||||
|
||||
def redo(self):
|
||||
contribution = self._lcs_lst[self._index]
|
||||
contribution.reach = self._new
|
||||
contribution.begin_rk = self._new_begin_rk
|
||||
contribution.end_rk = self._new_end_rk
|
||||
self._lcs_lst[self._index].reach = self._new
|
||||
|
||||
|
||||
class AddCommand(QUndoCommand):
|
||||
|
||||
@@ -20,7 +20,6 @@ import logging
|
||||
|
||||
from tools import trace, timer
|
||||
|
||||
from Modules import Modules
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
|
||||
from PyQt5.QtGui import (
|
||||
@@ -188,13 +187,12 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
|
||||
data = None
|
||||
highlight = None
|
||||
|
||||
tab = "liquid"
|
||||
|
||||
if len(rows) > 0:
|
||||
contribution = self._table.get(rows[0])
|
||||
reach_id = (
|
||||
contribution.reach
|
||||
if contribution is not None
|
||||
else None
|
||||
)
|
||||
reach_id = self._study.river\
|
||||
.lateral_contributions_adists.lst[rows[0]]\
|
||||
.reach
|
||||
|
||||
if reach_id:
|
||||
reach = next(
|
||||
@@ -203,10 +201,8 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
|
||||
self._study.river.reachs()))
|
||||
|
||||
data = reach.reach
|
||||
highlight = (
|
||||
contribution.begin_rk,
|
||||
contribution.end_rk
|
||||
)
|
||||
lc = self._lcs.lst[rows[0]]
|
||||
highlight = (lc.begin_rk, lc.end_rk)
|
||||
|
||||
for delegate in self._delegate_rk:
|
||||
delegate.data = reach
|
||||
@@ -258,23 +254,13 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
|
||||
self._table.redo()
|
||||
self._set_current_reach()
|
||||
|
||||
def _propagated_update(self, key=Modules(0)):
|
||||
if Modules.NETWORK not in key:
|
||||
return
|
||||
|
||||
self._table.refresh()
|
||||
self.find(QTableView, "tableView").clearSelection()
|
||||
self._set_current_reach()
|
||||
|
||||
def edit(self):
|
||||
rows = self.index_selected_rows()
|
||||
if not rows:
|
||||
return
|
||||
|
||||
for row in rows:
|
||||
data = self._table.get(row)
|
||||
if data is None:
|
||||
continue
|
||||
data = self._lcs.lst[row]
|
||||
|
||||
if self.sub_window_exists(
|
||||
EditLateralContributionAdisTSWindow,
|
||||
|
||||
+35
-208
@@ -91,11 +91,6 @@ from View.Results.CompareDialog import (
|
||||
CompareScenariosWindow
|
||||
)
|
||||
|
||||
from View.RunSolver.WindowAdisTT import (
|
||||
SelectSolverWindowAdisTT,
|
||||
SolverLogWindowAdisTT
|
||||
)
|
||||
|
||||
from View.RunSolver.WindowAdisTS import (
|
||||
SelectSolverWindowAdisTS,
|
||||
SolverLogWindowAdisTS
|
||||
@@ -103,26 +98,14 @@ from View.RunSolver.WindowAdisTS import (
|
||||
from View.CheckList.Window import CheckListWindow
|
||||
from View.CheckList.WindowAdisTS import CheckListWindowAdisTS
|
||||
from View.Results.WindowAdisTS import ResultsWindowAdisTS
|
||||
from View.Results.WindowAdisTT import ResultsWindowAdisTT
|
||||
from View.Results.ReadingResultsDialog import ReadingResultsDialog
|
||||
|
||||
from View.Debug.Window import ReplWindow, TimerWindow
|
||||
from View.OutputRKAdisTS.Window import OutputRKAdisTSWindow
|
||||
from View.Pollutants.Window import PollutantsWindow
|
||||
from View.D90AdisTS.Window import D90AdisTSWindow
|
||||
from View.DIFAdisTS.Window import DIFAdisTSWindow
|
||||
|
||||
from View.InitialConditionsTemperature.Window import (
|
||||
InitialConditionsTemperatureWindow
|
||||
)
|
||||
|
||||
from View.BoundaryConditionsTemperature.Window import (
|
||||
BoundaryConditionsTemperatureWindow
|
||||
)
|
||||
|
||||
from View.WeatherParameters.Window import (
|
||||
WeatherParametersWindow
|
||||
)
|
||||
|
||||
from Solver.Solvers import GenericSolver
|
||||
|
||||
from Model.Results.Results import Results
|
||||
@@ -148,7 +131,7 @@ model_action = [
|
||||
"action_menu_close", "action_menu_edit", "action_menu_save",
|
||||
"action_menu_save_as", "action_toolBar_close", "action_toolBar_save",
|
||||
"action_menu_numerical_parameter", "action_menu_open_results_from_file",
|
||||
"action_menu_open_results_adists", "action_menu_open_results_adistt",
|
||||
"action_menu_open_results_adists",
|
||||
]
|
||||
|
||||
other_model_action = [
|
||||
@@ -158,7 +141,6 @@ other_model_action = [
|
||||
define_model_action = [
|
||||
# Toolbar
|
||||
"action_toolBar_network", "action_toolBar_geometry",
|
||||
"action_toolBar_meshing",
|
||||
"action_toolBar_boundary_cond", "action_toolBar_lateral_contrib",
|
||||
"action_toolBar_frictions", "action_toolBar_initial_cond",
|
||||
# Menu
|
||||
@@ -173,13 +155,9 @@ define_model_action = [
|
||||
"action_menu_results_last", "action_menu_open_results_from_file",
|
||||
"action_menu_compare_scenarios_results",
|
||||
"action_menu_boundary_conditions_sediment",
|
||||
"action_menu_rep_additional_lines",
|
||||
"action_menu_rep_additional_lines", "action_menu_output_rk",
|
||||
"action_menu_run_adists", "action_menu_pollutants",
|
||||
"action_menu_d90", "action_menu_dif", "action_menu_edit_geotiff",
|
||||
"action_menu_meshing",
|
||||
"action_menu_boundary_conditions_temperature",
|
||||
"action_menu_initial_conditions_temperature",
|
||||
"action_menu_weather_parameters", "action_menu_run_adistt",
|
||||
"action_menu_d90", "action_menu_dif", "action_menu_edit_geotiff"
|
||||
]
|
||||
|
||||
action = (
|
||||
@@ -289,19 +267,11 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
"""
|
||||
actions = {
|
||||
# Menu action
|
||||
"action_menu_initial_conditions_temperature":
|
||||
self.open_initial_conditions_temperature,
|
||||
"action_menu_boundary_conditions_temperature":
|
||||
self.open_boundary_conditions_temperature,
|
||||
"action_menu_weather_parameters":
|
||||
self.open_weather_parameters,
|
||||
"action_menu_dif": self.open_dif,
|
||||
"action_menu_d90": self.open_d90,
|
||||
"action_menu_pollutants": self.open_pollutants,
|
||||
"action_menu_run_adists":
|
||||
self.select_run_solver_adists,
|
||||
"action_menu_run_adistt":
|
||||
self.select_run_solver_adistt,
|
||||
"action_menu_run_adists": self.select_run_solver_adists,
|
||||
"action_menu_output_rk": self.open_output_rk_adists,
|
||||
"action_menu_config": self.open_configure,
|
||||
"action_menu_new": self.open_new_study,
|
||||
"action_menu_edit": self.open_edit_study,
|
||||
@@ -312,7 +282,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
"action_menu_edit_scenarios": self.open_scenarios,
|
||||
"action_menu_edit_network": self.open_network,
|
||||
"action_menu_edit_geometry": self.open_geometry,
|
||||
"action_menu_meshing": self.open_meshing,
|
||||
"action_menu_boundary_conditions": self.open_boundary_cond,
|
||||
"action_menu_boundary_conditions_sediment":
|
||||
self.open_boundary_cond_sed,
|
||||
@@ -336,8 +305,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
"action_menu_compare_scenarios_results":
|
||||
self.compare_results_scenarios,
|
||||
"action_menu_open_results_adists": self.open_results_adists,
|
||||
"action_menu_open_results_adistt":
|
||||
lambda: self.open_results_adists(mode="adistt"),
|
||||
# Help
|
||||
"action_menu_pamhyr_users_wiki": self.open_doc_user,
|
||||
"action_menu_pamhyr_developers_pdf":
|
||||
@@ -354,7 +321,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
# Current actions
|
||||
"action_toolBar_network": self.open_network,
|
||||
"action_toolBar_geometry": self.open_geometry,
|
||||
"action_toolBar_meshing": self.open_meshing,
|
||||
"action_toolBar_boundary_cond": self.open_boundary_cond,
|
||||
"action_toolBar_lateral_contrib": self.open_lateral_contrib,
|
||||
"action_toolBar_frictions": self.open_frictions,
|
||||
@@ -1063,60 +1029,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
# SUB WINDOWS #
|
||||
###############
|
||||
|
||||
def open_weather_parameters(self):
|
||||
river = self._study.river
|
||||
weather_param = river.weather_parameters
|
||||
|
||||
if self.sub_window_exists(
|
||||
WeatherParametersWindow,
|
||||
data=[self._study, None, weather_param]
|
||||
):
|
||||
return
|
||||
|
||||
bound = WeatherParametersWindow(
|
||||
study=self._study,
|
||||
parent=self,
|
||||
data=weather_param
|
||||
)
|
||||
bound.show()
|
||||
|
||||
def open_boundary_conditions_temperature(self):
|
||||
river = self._study.river
|
||||
bclist = river.boundary_conditions_temperature.lst
|
||||
|
||||
if self.sub_window_exists(
|
||||
BoundaryConditionsTemperatureWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
return
|
||||
|
||||
bound = BoundaryConditionsTemperatureWindow(
|
||||
study=self._study,
|
||||
parent=self,
|
||||
data=bclist,
|
||||
)
|
||||
bound.show()
|
||||
|
||||
def open_initial_conditions_temperature(self):
|
||||
iclist = self._study.river.ic_temperature.lst
|
||||
if len(iclist) != 0:
|
||||
ic_default = iclist[0]
|
||||
else:
|
||||
ic_default = self._study.river.ic_temperature.new(0)
|
||||
|
||||
if self.sub_window_exists(
|
||||
InitialConditionsTemperatureWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
return
|
||||
|
||||
InitialConditions = InitialConditionsTemperatureWindow(
|
||||
study=self._study,
|
||||
parent=self,
|
||||
data=ic_default
|
||||
)
|
||||
InitialConditions.show()
|
||||
|
||||
def open_d90(self):
|
||||
if len(self._study.river.d90_adists.lst) != 0:
|
||||
d90_default = self._study.river.d90_adists.lst[0]
|
||||
@@ -1168,6 +1080,19 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
)
|
||||
Pollutants.show()
|
||||
|
||||
def open_output_rk_adists(self):
|
||||
if self.sub_window_exists(
|
||||
OutputRKAdisTSWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
return
|
||||
|
||||
Output_RK_AdisTS = OutputRKAdisTSWindow(
|
||||
study=self._study,
|
||||
parent=self
|
||||
)
|
||||
Output_RK_AdisTS.show()
|
||||
|
||||
def open_configure(self):
|
||||
"""Open configure window
|
||||
|
||||
@@ -1343,10 +1268,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
GeometryWindow,
|
||||
data=[self._study, self.conf, reach]
|
||||
):
|
||||
return self.get_sub_window(
|
||||
GeometryWindow,
|
||||
data=[self._study, self.conf, reach]
|
||||
)
|
||||
return
|
||||
|
||||
geometry = GeometryWindow(
|
||||
study=self._study,
|
||||
@@ -1355,21 +1277,8 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
parent=self
|
||||
)
|
||||
geometry.show()
|
||||
return geometry
|
||||
else:
|
||||
self.msg_select_reach()
|
||||
return None
|
||||
|
||||
def open_meshing(self):
|
||||
"""Open the current reach geometry and its meshing dialog."""
|
||||
geometry = self.open_geometry()
|
||||
if geometry is None or self._study.is_read_only():
|
||||
return
|
||||
|
||||
geometry.raise_()
|
||||
geometry.activateWindow()
|
||||
QApplication.processEvents()
|
||||
geometry.edit_meshing()
|
||||
|
||||
def open_boundary_cond_sed(self):
|
||||
self.open_boundary_cond(tab=1)
|
||||
@@ -1447,13 +1356,12 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
|
||||
if self.sub_window_exists(
|
||||
FrictionsWindow,
|
||||
data=[self._study, self.conf, reach]
|
||||
data=[self._study, None, reach]
|
||||
):
|
||||
return
|
||||
|
||||
frictions = FrictionsWindow(
|
||||
study=self._study,
|
||||
config=self.conf,
|
||||
parent=self
|
||||
)
|
||||
frictions.show()
|
||||
@@ -1546,16 +1454,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
sl.show()
|
||||
|
||||
def open_reach_sediment_layers(self):
|
||||
if self._study is None:
|
||||
logger.debug(
|
||||
"No study open for reach sediment layers edition..."
|
||||
)
|
||||
return
|
||||
|
||||
if not self._study.river.has_current_reach():
|
||||
self.msg_select_reach()
|
||||
return
|
||||
|
||||
reach = self._study.river.current_reach().reach
|
||||
|
||||
if self.sub_window_exists(
|
||||
@@ -1607,25 +1505,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
if run.exec():
|
||||
self.run_solver_adists(run.solver, run.mage_rep)
|
||||
|
||||
def select_run_solver_adistt(self):
|
||||
if self._study is None:
|
||||
return
|
||||
|
||||
run = SelectSolverWindowAdisTT(
|
||||
study=self._study,
|
||||
config=self.conf,
|
||||
parent=self
|
||||
)
|
||||
if run.exec():
|
||||
self.run_solver_adistt(run.solver, run.mage_rep)
|
||||
|
||||
def run_solver_adists(self, solver, mage_rep):
|
||||
self._run_solver_adis(solver, mage_rep, mode="adists")
|
||||
|
||||
def run_solver_adistt(self, solver, mage_rep):
|
||||
self._run_solver_adis(solver, mage_rep, mode="adistt")
|
||||
|
||||
def _run_solver_adis(self, solver, mage_rep, mode):
|
||||
if self._study is None:
|
||||
return
|
||||
|
||||
@@ -1635,8 +1515,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
self._study,
|
||||
self.conf,
|
||||
solver,
|
||||
mage_rep,
|
||||
mode,
|
||||
mage_rep
|
||||
]
|
||||
):
|
||||
return
|
||||
@@ -1647,7 +1526,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
solver=solver,
|
||||
parent=self,
|
||||
mage_rep=mage_rep,
|
||||
mode=mode,
|
||||
)
|
||||
check.show()
|
||||
|
||||
@@ -1683,16 +1561,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
)
|
||||
sol.show()
|
||||
|
||||
def solver_log_adistt(self, solver, mage_rep):
|
||||
sol = SolverLogWindowAdisTT(
|
||||
study=self._study,
|
||||
config=self.conf,
|
||||
solver=solver,
|
||||
parent=self,
|
||||
mage_rep=mage_rep,
|
||||
)
|
||||
sol.show()
|
||||
|
||||
def solver_log(self, solver):
|
||||
sol = SolverLogWindow(
|
||||
study=self._study,
|
||||
@@ -1812,16 +1680,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
)
|
||||
|
||||
def open_solver_results_adists(self, solver, results=None):
|
||||
self._open_solver_results_adis(
|
||||
solver, ResultsWindowAdisTS, results=results
|
||||
)
|
||||
|
||||
def open_solver_results_adistt(self, solver, results=None):
|
||||
self._open_solver_results_adis(
|
||||
solver, ResultsWindowAdisTT, results=results
|
||||
)
|
||||
|
||||
def _open_solver_results_adis(self, solver, window_class, results=None):
|
||||
def reading_fn():
|
||||
self._tmp_results = results
|
||||
|
||||
@@ -1863,7 +1721,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
|
||||
# Windows already opened
|
||||
if self.sub_window_exists(
|
||||
window_class,
|
||||
ResultsWindowAdisTS,
|
||||
data=[
|
||||
self._study,
|
||||
None, # No config
|
||||
@@ -1874,7 +1732,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
):
|
||||
return
|
||||
|
||||
res = window_class(
|
||||
res = ResultsWindowAdisTS(
|
||||
study=self._study,
|
||||
solver=solver,
|
||||
results=results,
|
||||
@@ -1901,23 +1759,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
self._solver_workdir(solver, scenario)
|
||||
)
|
||||
|
||||
def _solver_from_results_path(self, results_path):
|
||||
solvers_by_directory = {
|
||||
solver.name.replace(" ", "_"): solver
|
||||
for solver in self.conf.solvers
|
||||
}
|
||||
|
||||
path = os.path.abspath(results_path)
|
||||
while True:
|
||||
directory = os.path.basename(path)
|
||||
if directory in solvers_by_directory:
|
||||
return solvers_by_directory[directory]
|
||||
|
||||
parent = os.path.dirname(path)
|
||||
if parent == path:
|
||||
return None
|
||||
path = parent
|
||||
|
||||
def open_last_results(self):
|
||||
if self._last_solver is None:
|
||||
return
|
||||
@@ -2182,7 +2023,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
|
||||
return [result4, result5, result3]
|
||||
|
||||
def open_results_adists(self, mode="adists"):
|
||||
def open_results_adists(self):
|
||||
if self._study is None:
|
||||
return
|
||||
|
||||
@@ -2219,7 +2060,10 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
text=self._trad["mb_results_bin_not_found"]
|
||||
)
|
||||
return
|
||||
solver_results = self._solver_from_results_path(dir_path)
|
||||
path = os.path.normpath(dir_path)
|
||||
solver_name = path.split(os.sep)[-2]
|
||||
solver_results = next(filter(lambda x: x.name == solver_name,
|
||||
self.conf.solvers), None)
|
||||
if solver_results is None:
|
||||
self.msg_results_warning(
|
||||
info=self._trad["mb_results_not_found"],
|
||||
@@ -2227,34 +2071,16 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
)
|
||||
return
|
||||
|
||||
expected_type = "adistt" if mode == "adistt" else "adists"
|
||||
solver_type = solver_results._type.lower()
|
||||
if not solver_type.startswith(expected_type):
|
||||
self.msg_results_warning(
|
||||
info=self._trad["mb_results_not_found"],
|
||||
text=self._trad["mb_results_solver_mode_mismatch"].format(
|
||||
solver=solver_results.name,
|
||||
mode=expected_type.upper(),
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
solver_results_adists = solver_results.results(
|
||||
self._study,
|
||||
repertory=dir_path, qlog=None) # self._output)
|
||||
|
||||
logger.info(f"Select results: {dir_path}")
|
||||
if len(bin_list) >= 2 and ("total_sediment.bin" in bin_list):
|
||||
if mode == "adistt":
|
||||
self.open_solver_results_adistt(
|
||||
solver_results,
|
||||
results=solver_results_adists,
|
||||
)
|
||||
else:
|
||||
self.open_solver_results_adists(
|
||||
solver_results,
|
||||
results=solver_results_adists,
|
||||
)
|
||||
self.open_solver_results_adists(
|
||||
solver_results,
|
||||
results=solver_results_adists,
|
||||
)
|
||||
else:
|
||||
self.msg_results_warning(
|
||||
info=self._trad["mb_results_not_found"],
|
||||
@@ -2339,5 +2165,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
|
||||
file = self._study.filename
|
||||
_ = subprocess.Popen(
|
||||
["sqlitebrowser", file]
|
||||
f"sqlitebrowser {file}",
|
||||
shell=True
|
||||
)
|
||||
@@ -928,11 +928,6 @@ class GraphWidget(QGraphicsView):
|
||||
if self._only_display:
|
||||
return
|
||||
|
||||
if event.button() == Qt.RightButton \
|
||||
and self._block_right_click_in_add_state():
|
||||
event.accept()
|
||||
return
|
||||
|
||||
locked = self.graph._status.is_read_only()
|
||||
|
||||
pos = self.mapToScene(event.pos())
|
||||
@@ -1067,15 +1062,7 @@ class GraphWidget(QGraphicsView):
|
||||
|
||||
# Contextual menu
|
||||
|
||||
def _block_right_click_in_add_state(self):
|
||||
return self._state == "add" \
|
||||
and self.selected_new_edge_src_node() is not None
|
||||
|
||||
def contextMenuEvent(self, event):
|
||||
if self._block_right_click_in_add_state():
|
||||
event.accept()
|
||||
return
|
||||
|
||||
if self._only_display or self.graph._status.is_read_only():
|
||||
return
|
||||
|
||||
|
||||
@@ -180,11 +180,7 @@ class NetworkWindow(PamhyrWindow):
|
||||
key = event.key()
|
||||
|
||||
if key == Qt.Key_Escape:
|
||||
self._graph_widget.reset_selection()
|
||||
event.accept()
|
||||
return
|
||||
|
||||
super(NetworkWindow, self).keyPressEvent(event)
|
||||
self._graph_widget.reset_selection
|
||||
|
||||
def add_node_reservoir(self, node):
|
||||
if self._reservoir.get_assoc_to_node(node) is None:
|
||||
|
||||
+87
-83
@@ -1,5 +1,5 @@
|
||||
# Table.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
# Copyright (C) 2023-2026 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
|
||||
@@ -36,36 +36,60 @@ from PyQt5.QtWidgets import (
|
||||
|
||||
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||
|
||||
from View.BoundaryConditionsTemperature.UndoCommand import (
|
||||
SetNodeCommand, SetNameCommand,
|
||||
AddCommand, DelCommand
|
||||
from View.OutputRKAdisTS.UndoCommand import (
|
||||
SetTitleCommand, SetReachCommand, SetRKCommand,
|
||||
SetEnabledCommand, AddCommand, DelCommand,
|
||||
)
|
||||
|
||||
from functools import reduce
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class ComboBoxDelegate(QItemDelegate):
|
||||
def __init__(self, data=None, mode="node", tab="",
|
||||
trad=None, parent=None):
|
||||
def __init__(self, data=None, trad=None, parent=None, mode="reaches"):
|
||||
super(ComboBoxDelegate, self).__init__(parent)
|
||||
|
||||
self._data = data
|
||||
self._mode = mode
|
||||
self._tab = tab
|
||||
self._trad = trad
|
||||
self._mode = mode
|
||||
|
||||
def createEditor(self, parent, option, index):
|
||||
self.editor = QComboBox(parent)
|
||||
|
||||
if self._mode == "node":
|
||||
self.editor.addItems(
|
||||
[self._trad["not_associated"]] +
|
||||
self._data.nodes_names()
|
||||
val = []
|
||||
if self._mode == "rk":
|
||||
reach_id = self._data.Output_rk_adists \
|
||||
.get(index.row()) \
|
||||
.reach
|
||||
|
||||
if reach_id is not None:
|
||||
reach = next(
|
||||
filter(
|
||||
lambda edge: edge.id == reach_id, self._data.edges()
|
||||
)
|
||||
)
|
||||
|
||||
val = list(
|
||||
map(
|
||||
lambda rk: str(rk), reach.reach.get_rk()
|
||||
)
|
||||
)
|
||||
else:
|
||||
val = list(
|
||||
map(
|
||||
lambda n: n.name, self._data.edges()
|
||||
)
|
||||
)
|
||||
|
||||
self.editor.setCurrentText(index.data(Qt.DisplayRole))
|
||||
self.editor.addItems(
|
||||
[self._trad['not_associated']] +
|
||||
val
|
||||
)
|
||||
|
||||
self.editor.setCurrentText(str(index.data(Qt.DisplayRole)))
|
||||
return self.editor
|
||||
|
||||
def setEditorData(self, editor, index):
|
||||
@@ -91,27 +115,10 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
|
||||
|
||||
class TableModel(PamhyrTableModel):
|
||||
def __init__(self, bc_list=None, trad=None, **kwargs):
|
||||
self._trad = trad
|
||||
self._bc_list = bc_list
|
||||
|
||||
super(TableModel, self).__init__(trad=trad, **kwargs)
|
||||
|
||||
def _setup_lst(self):
|
||||
self._lst = self._bc_list.lst
|
||||
self._lst = self._data._Output_rk_adists
|
||||
|
||||
def get(self, row):
|
||||
if row < 0 or row >= len(self._lst):
|
||||
return None
|
||||
return self._lst[row]
|
||||
|
||||
def _global_row(self, row):
|
||||
bc = self.get(row)
|
||||
if bc is None:
|
||||
return None
|
||||
return self._bc_list.index(bc)
|
||||
|
||||
def rowCount(self, parent=QModelIndex()):
|
||||
def rowCount(self, parent):
|
||||
return len(self._lst)
|
||||
|
||||
def data(self, index, role):
|
||||
@@ -121,20 +128,20 @@ class TableModel(PamhyrTableModel):
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
if self._headers[column] == "name":
|
||||
n = self._lst[row].name
|
||||
if n is None or n == "":
|
||||
return self._trad["default"]
|
||||
return n
|
||||
elif self._headers[column] == "node":
|
||||
n = self._lst[row].node
|
||||
if self._headers[column] == "title":
|
||||
return self._lst.get(row).title
|
||||
elif self._headers[column] == "reach":
|
||||
n = self._lst.get(row).reach
|
||||
if n is None:
|
||||
return self._trad["not_associated"]
|
||||
tmp = next(filter(lambda x: x.id == n, self._data._nodes), None)
|
||||
if tmp is not None:
|
||||
return tmp.name
|
||||
else:
|
||||
return self._trad["not_associated"]
|
||||
return self._trad['not_associated']
|
||||
return next(filter(
|
||||
lambda edge: edge.id == n, self._data.edges())
|
||||
).name
|
||||
elif self._headers[column] == "rk":
|
||||
n = self._lst.get(row).rk
|
||||
if n is None:
|
||||
return self._trad['not_associated']
|
||||
return n
|
||||
|
||||
return QVariant()
|
||||
|
||||
@@ -147,79 +154,76 @@ class TableModel(PamhyrTableModel):
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
na = self._trad['not_associated']
|
||||
|
||||
try:
|
||||
if self._headers[column] == "name":
|
||||
global_row = self._global_row(row)
|
||||
if self._headers[column] == "title":
|
||||
self._undo.push(
|
||||
SetNameCommand(
|
||||
self._bc_list, global_row, value
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "node":
|
||||
global_row = self._global_row(row)
|
||||
node = next(
|
||||
filter(lambda n: n.name == value, self._data.nodes()),
|
||||
None
|
||||
)
|
||||
self._undo.push(
|
||||
SetNodeCommand(
|
||||
self._bc_list, global_row, node
|
||||
SetTitleCommand(
|
||||
self._lst, row, value
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "reach":
|
||||
if value == na:
|
||||
value = None
|
||||
|
||||
self._undo.push(
|
||||
SetReachCommand(
|
||||
self._lst, row, self._data.edge(value)
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "rk":
|
||||
if value == na:
|
||||
value = None
|
||||
|
||||
self._undo.push(
|
||||
SetRKCommand(
|
||||
self._lst, row, value
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
logger.debug(traceback.format_exc())
|
||||
|
||||
if self._headers[column] == "node" and self.rowCount() > 0:
|
||||
self.dataChanged.emit(
|
||||
self.index(0, column),
|
||||
self.index(self.rowCount() - 1, column)
|
||||
)
|
||||
else:
|
||||
self.dataChanged.emit(index, index)
|
||||
self.dataChanged.emit(index, index)
|
||||
return True
|
||||
|
||||
def add(self, row, parent=QModelIndex()):
|
||||
row = len(self._lst)
|
||||
self.beginInsertRows(parent, row, row)
|
||||
self.beginInsertRows(parent, row, row - 1)
|
||||
|
||||
self._undo.push(
|
||||
AddCommand(
|
||||
self._bc_list, len(self._bc_list)
|
||||
self._lst, row
|
||||
)
|
||||
)
|
||||
self._setup_lst()
|
||||
|
||||
self.endInsertRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def delete(self, rows, parent=QModelIndex()):
|
||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||
|
||||
row_by_bc = {
|
||||
id(bc): row for row, bc in enumerate(self._bc_list._lst)
|
||||
}
|
||||
global_rows = [
|
||||
row_by_bc[id(self._lst[row])]
|
||||
for row in rows
|
||||
if 0 <= row < len(self._lst)
|
||||
]
|
||||
self._undo.push(
|
||||
DelCommand(
|
||||
self._bc_list, global_rows
|
||||
self._lst, rows
|
||||
)
|
||||
)
|
||||
|
||||
self._setup_lst()
|
||||
self.endRemoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def enabled(self, row, enabled, parent=QModelIndex()):
|
||||
self._undo.push(
|
||||
SetEnabledCommand(
|
||||
self._lst, row, enabled
|
||||
)
|
||||
)
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def undo(self):
|
||||
self._undo.undo()
|
||||
self._setup_lst()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def redo(self):
|
||||
self._undo.redo()
|
||||
self._setup_lst()
|
||||
self.layoutChanged.emit()
|
||||
+10
-10
@@ -1,5 +1,5 @@
|
||||
# translate.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
# Copyright (C) 2023-2026 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
|
||||
@@ -20,21 +20,21 @@ from PyQt5.QtCore import QCoreApplication
|
||||
|
||||
from View.Translate import MainTranslate
|
||||
|
||||
from View.BoundaryCondition.translate import BCTranslate
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class BCETranslate(BCTranslate):
|
||||
class OutputRKAdisTSTranslate(MainTranslate):
|
||||
def __init__(self):
|
||||
super(BCETranslate, self).__init__()
|
||||
super(OutputRKAdisTSTranslate, self).__init__()
|
||||
|
||||
self._dict["Edit Boundary Conditions Temperature"] = _translate(
|
||||
"BoundaryConditionsTemperature",
|
||||
"Edit boundary conditions Temperature"
|
||||
self._dict["Output RK"] = _translate(
|
||||
"OutputRKAdisTS", "Output RK"
|
||||
)
|
||||
|
||||
self._dict["x"] = _translate("OutputRKAdisTS", "X (m)")
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
"time": self._dict["time"],
|
||||
"temperature": self._dict["unit_temperature"],
|
||||
"title": self._dict["title"],
|
||||
"reach": self._dict["reach"],
|
||||
"rk": self._dict["unit_rk"],
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
# UndoCommand.py -- Pamhyr
|
||||
# Copyright (C) 2023-2026 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 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from copy import deepcopy
|
||||
from tools import trace, timer
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QMessageBox, QUndoCommand, QUndoStack,
|
||||
)
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class SetTitleCommand(QUndoCommand):
|
||||
def __init__(self, outputrk_lst, index, new_value):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._outputrk_lst = outputrk_lst
|
||||
self._index = index
|
||||
self._old = self._outputrk_lst.get(self._index).title
|
||||
self._new = str(new_value)
|
||||
|
||||
def undo(self):
|
||||
self._outputrk_lst.get(self._index).title = self._old
|
||||
|
||||
def redo(self):
|
||||
self._outputrk_lst.get(self._index).title = self._new
|
||||
|
||||
|
||||
class SetReachCommand(QUndoCommand):
|
||||
def __init__(self, outputrk_lst, index, reach):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._outputrk_lst = outputrk_lst
|
||||
self._index = index
|
||||
self._old = self._outputrk_lst.get(self._index).reach
|
||||
self._new = reach.id
|
||||
|
||||
def undo(self):
|
||||
i = self._outputrk_lst.get(self._index)
|
||||
i.reach = self._old
|
||||
|
||||
def redo(self):
|
||||
i = self._outputrk_lst.get(self._index)
|
||||
i.reach = self._new
|
||||
|
||||
|
||||
class SetRKCommand(QUndoCommand):
|
||||
def __init__(self, outputrk_lst, index, rk):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._outputrk_lst = outputrk_lst
|
||||
self._index = index
|
||||
self._old = self._outputrk_lst.get(self._index).rk
|
||||
self._new = rk
|
||||
|
||||
def undo(self):
|
||||
self._outputrk_lst.get(self._index).rk = self._old
|
||||
|
||||
def redo(self):
|
||||
self._outputrk_lst.get(self._index).rk = self._new
|
||||
|
||||
|
||||
class SetEnabledCommand(QUndoCommand):
|
||||
def __init__(self, outputrk_lst, index, enabled):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._outputrk_lst = outputrk_lst
|
||||
self._index = index
|
||||
self._old = not enabled
|
||||
self._new = enabled
|
||||
|
||||
def undo(self):
|
||||
self._outputrk_lst.get(self._index).enabled = self._old
|
||||
|
||||
def redo(self):
|
||||
self._outputrk_lst.get(self._index).enabled = self._new
|
||||
|
||||
|
||||
class AddCommand(QUndoCommand):
|
||||
def __init__(self, outputrk_lst, index):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._outputrk_lst = outputrk_lst
|
||||
|
||||
self._index = index
|
||||
self._new = None
|
||||
|
||||
def undo(self):
|
||||
self._outputrk_lst.delete_i([self._index])
|
||||
|
||||
def redo(self):
|
||||
if self._new is None:
|
||||
self._new = self._outputrk_lst.new(self._outputrk_lst, self._index)
|
||||
else:
|
||||
self._outputrk_lst.insert(self._index, self._new)
|
||||
|
||||
|
||||
class DelCommand(QUndoCommand):
|
||||
def __init__(self, outputrk_lst, rows):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._outputrk_lst = outputrk_lst
|
||||
|
||||
self._rows = rows
|
||||
|
||||
self._outputrk = []
|
||||
for row in rows:
|
||||
self._outputrk.append((row, self._outputrk_lst.get(row)))
|
||||
self._outputrk.sort()
|
||||
|
||||
def undo(self):
|
||||
for row, el in self._outputrk:
|
||||
self._outputrk_lst.insert(row, el)
|
||||
|
||||
def redo(self):
|
||||
self._outputrk_lst.delete_i(self._rows)
|
||||
|
||||
|
||||
class PasteCommand(QUndoCommand):
|
||||
def __init__(self, outputrk_lst, row, outputrk):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._outputrk_lst = outputrk_lst
|
||||
|
||||
self._row = row
|
||||
self._outputrk = deepcopy(outputrk)
|
||||
self._outputrk.reverse()
|
||||
|
||||
def undo(self):
|
||||
self._outputrk_lst.delete_i(
|
||||
self._tab,
|
||||
range(self._row, self._row + len(self._outputrk))
|
||||
)
|
||||
|
||||
def redo(self):
|
||||
for r in self._outputrk:
|
||||
self._outputrk_lst.insert(self._row, r)
|
||||
@@ -0,0 +1,209 @@
|
||||
# Window.py -- Pamhyr
|
||||
# Copyright (C) 2023-2026 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 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from tools import timer, trace
|
||||
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
|
||||
from PyQt5 import QtCore
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel, QCoreApplication,
|
||||
pyqtSlot, pyqtSignal, QItemSelectionModel,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QPushButton, QLineEdit,
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QHeaderView, QDoubleSpinBox, QVBoxLayout, QCheckBox
|
||||
)
|
||||
|
||||
from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
||||
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
||||
|
||||
from View.OutputRKAdisTS.Table import (
|
||||
TableModel, ComboBoxDelegate,
|
||||
)
|
||||
|
||||
from View.Network.GraphWidget import GraphWidget
|
||||
from View.OutputRKAdisTS.Translate import OutputRKAdisTSTranslate
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class OutputRKAdisTSWindow(PamhyrWindow):
|
||||
_pamhyr_ui = "OutputRKAdisTS"
|
||||
_pamhyr_name = "Output RK"
|
||||
|
||||
def __init__(self, study=None, config=None, parent=None):
|
||||
trad = OutputRKAdisTSTranslate()
|
||||
name = trad[self._pamhyr_name] + " - " + study.name
|
||||
|
||||
super(OutputRKAdisTSWindow, self).__init__(
|
||||
title=name,
|
||||
study=study,
|
||||
config=config,
|
||||
trad=trad,
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self._outputrk_lst = self._study.river._Output_rk_adists
|
||||
|
||||
self.setup_table()
|
||||
self.setup_checkbox()
|
||||
self.setup_connections()
|
||||
|
||||
self.update()
|
||||
|
||||
def setup_table(self):
|
||||
self._table = None
|
||||
|
||||
self._delegate_reach = ComboBoxDelegate(
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
parent=self,
|
||||
mode="reaches"
|
||||
)
|
||||
self._delegate_rk = ComboBoxDelegate(
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
parent=self,
|
||||
mode="rk"
|
||||
)
|
||||
|
||||
table = self.find(QTableView, f"tableView")
|
||||
self._table = TableModel(
|
||||
table_view=table,
|
||||
table_headers=self._trad.get_dict("table_headers"),
|
||||
editable_headers=["title", "reach", "rk"],
|
||||
delegates={
|
||||
"reach": self._delegate_reach,
|
||||
"rk": self._delegate_rk,
|
||||
},
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
undo=self._undo_stack,
|
||||
)
|
||||
|
||||
selectionModel = table.selectionModel()
|
||||
index = table.model().index(0, 0)
|
||||
|
||||
selectionModel.select(
|
||||
index,
|
||||
QItemSelectionModel.Rows |
|
||||
QItemSelectionModel.ClearAndSelect |
|
||||
QItemSelectionModel.Select
|
||||
)
|
||||
table.scrollTo(index)
|
||||
|
||||
def setup_checkbox(self):
|
||||
self._checkbox = self.find(QCheckBox, f"checkBox")
|
||||
self._set_checkbox_state()
|
||||
|
||||
def setup_connections(self):
|
||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||
self.find(QAction, "action_delete").triggered.connect(self.delete)
|
||||
self._checkbox.clicked.connect(self._set_outputrk_state)
|
||||
|
||||
table = self.find(QTableView, "tableView")
|
||||
table.selectionModel()\
|
||||
.selectionChanged\
|
||||
.connect(self.update)
|
||||
|
||||
self._table.dataChanged.connect(self.update)
|
||||
self._table.layoutChanged.connect(self.update)
|
||||
|
||||
def index_selected(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
r = table.selectionModel().selectedRows()
|
||||
|
||||
if len(r) > 0:
|
||||
return r[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
r = table.selectionModel().selectedRows()
|
||||
|
||||
if len(r) > 0:
|
||||
return r[0].row()
|
||||
else:
|
||||
return None
|
||||
|
||||
def index_selected_rows(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
return list(
|
||||
# Delete duplicate
|
||||
set(
|
||||
map(
|
||||
lambda i: i.row(),
|
||||
table.selectedIndexes()
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def add(self):
|
||||
rows = self.index_selected_rows()
|
||||
if len(self._outputrk_lst) == 0 or len(rows) == 0:
|
||||
self._table.add(0)
|
||||
else:
|
||||
self._table.add(rows[0])
|
||||
|
||||
def delete(self):
|
||||
rows = self.index_selected_rows()
|
||||
if len(rows) == 0:
|
||||
return
|
||||
|
||||
self._table.delete(rows)
|
||||
|
||||
def _copy(self):
|
||||
logger.info("TODO: copy")
|
||||
|
||||
def _paste(self):
|
||||
logger.info("TODO: paste")
|
||||
|
||||
def _undo(self):
|
||||
self._table.undo()
|
||||
|
||||
def _redo(self):
|
||||
self._table.redo()
|
||||
|
||||
def _set_checkbox_state(self):
|
||||
row = self.index_selected_row()
|
||||
if row is None:
|
||||
self._checkbox.setEnabled(False)
|
||||
self._checkbox.setChecked(True)
|
||||
else:
|
||||
self._checkbox.setEnabled(True)
|
||||
self._checkbox.setChecked(self._outputrk_lst.get(row).enabled)
|
||||
|
||||
def _set_outputrk_state(self):
|
||||
rows = self.index_selected_rows()
|
||||
if len(rows) != 0:
|
||||
for row in rows:
|
||||
if row is not None:
|
||||
self._table.enabled(
|
||||
row,
|
||||
self._checkbox.isChecked()
|
||||
)
|
||||
|
||||
def update(self):
|
||||
self._set_checkbox_state()
|
||||
@@ -137,7 +137,6 @@ class EditReservoirWindow(PamhyrWindow):
|
||||
|
||||
def update(self):
|
||||
self.plot.update()
|
||||
self.plot.fit_to_data()
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
|
||||
@@ -95,7 +95,7 @@ class PlotAC(PamhyrPlot):
|
||||
|
||||
def draw_profile(self, reach, profile):
|
||||
x = profile.geometry.get_station()
|
||||
z = self.get_bottom_elevation(profile)
|
||||
z = profile.geometry.z()
|
||||
|
||||
self.line_rk, = self.canvas.axes.plot(
|
||||
x, z,
|
||||
@@ -110,7 +110,7 @@ class PlotAC(PamhyrPlot):
|
||||
result = self.results[self._current_res_id]
|
||||
|
||||
x = profile.geometry.get_station()
|
||||
z = self.get_bottom_elevation(profile)
|
||||
z = profile.geometry.z()
|
||||
rk = reach.geometry.get_rk()
|
||||
water_z = result.get("table")["Z"][
|
||||
result.get_timestamp_id(
|
||||
@@ -139,7 +139,7 @@ class PlotAC(PamhyrPlot):
|
||||
result = self.results[self._current_res_id]
|
||||
|
||||
x = profile.geometry.get_station()
|
||||
z = self.get_bottom_elevation(profile)
|
||||
z = profile.geometry.z()
|
||||
rk = reach.geometry.get_rk()
|
||||
|
||||
water_z = np.max(
|
||||
@@ -162,7 +162,7 @@ class PlotAC(PamhyrPlot):
|
||||
return
|
||||
|
||||
station = profile.geometry.get_station()
|
||||
elevation = self.get_bottom_elevation(profile)
|
||||
elevation = profile.geometry.z()
|
||||
gl = profile.geometry.names()
|
||||
|
||||
self.annotation = []
|
||||
@@ -239,11 +239,9 @@ class PlotAC(PamhyrPlot):
|
||||
self._current_reach_id)
|
||||
profile = reach.profile(self._current_profile_id)
|
||||
x = profile.geometry.get_station()
|
||||
z = self.get_bottom_elevation(profile)
|
||||
z = profile.geometry.z()
|
||||
|
||||
self.update_river_bottom(reach, profile, x, z)
|
||||
self.update_water(reach, profile, x, z)
|
||||
self.update_gl()
|
||||
self.update_idle()
|
||||
|
||||
def update(self):
|
||||
@@ -254,7 +252,7 @@ class PlotAC(PamhyrPlot):
|
||||
.river.reach(self._current_reach_id)
|
||||
profile = reach.profile(self._current_profile_id)
|
||||
x = profile.geometry.get_station()
|
||||
z = self.get_bottom_elevation(profile)
|
||||
z = profile.geometry.z()
|
||||
|
||||
self.update_river_bottom(reach, profile, x, z)
|
||||
self.update_water(reach, profile, x, z)
|
||||
@@ -281,69 +279,6 @@ class PlotAC(PamhyrPlot):
|
||||
def update_river_bottom(self, reach, profile, x, z):
|
||||
self.line_rk.set_data(x, z)
|
||||
|
||||
def get_bottom_elevation(self, profile):
|
||||
"""Return the cross-section elevation at the selected timestamp."""
|
||||
initial_z = np.asarray(profile.geometry.z(), dtype=float)
|
||||
result = self.results[self._current_res_id]
|
||||
|
||||
try:
|
||||
sediment_timestamps = sorted(result.get("sediment_timestamps"))
|
||||
except (KeyError, TypeError):
|
||||
return initial_z
|
||||
|
||||
if not sediment_timestamps:
|
||||
return initial_z
|
||||
|
||||
initial_timestamp = sediment_timestamps[0]
|
||||
current_timestamp = min(
|
||||
sediment_timestamps,
|
||||
key=lambda timestamp: abs(timestamp - self._current_timestamp)
|
||||
)
|
||||
initial_layers = profile.get_ts_key(initial_timestamp, "sl")
|
||||
current_layers = profile.get_ts_key(current_timestamp, "sl")
|
||||
|
||||
if not initial_layers or not current_layers:
|
||||
return initial_z
|
||||
|
||||
initial_thickness = self._get_sediment_thickness(initial_layers)
|
||||
current_thickness = self._get_sediment_thickness(current_layers)
|
||||
point_count = len(initial_z)
|
||||
wet_mask = self._get_wet_mask(profile, initial_z)
|
||||
|
||||
if wet_mask is None:
|
||||
return initial_z
|
||||
|
||||
if len(initial_thickness) == len(current_thickness) == 1:
|
||||
elevation_delta = current_thickness[0] - initial_thickness[0]
|
||||
return initial_z + np.where(wet_mask, elevation_delta, 0.0)
|
||||
|
||||
if (len(initial_thickness) == len(current_thickness) == point_count):
|
||||
elevation_delta = np.asarray(current_thickness) \
|
||||
- np.asarray(initial_thickness)
|
||||
return initial_z + np.where(wet_mask, elevation_delta, 0.0)
|
||||
|
||||
return initial_z
|
||||
|
||||
def _get_wet_mask(self, profile, elevation):
|
||||
result = self.results[self._current_res_id]
|
||||
|
||||
try:
|
||||
water_elevation = result.get("table")["Z"][
|
||||
result.get_timestamp_id(self._current_timestamp),
|
||||
profile.global_index
|
||||
]
|
||||
except (KeyError, IndexError, TypeError):
|
||||
return None
|
||||
|
||||
return elevation <= water_elevation
|
||||
|
||||
@staticmethod
|
||||
def _get_sediment_thickness(section_layers):
|
||||
return [
|
||||
sum(float(layer[0]) for layer in point_layers)
|
||||
for point_layers in section_layers
|
||||
]
|
||||
|
||||
def update_water(self, reach, profile, x, z):
|
||||
result = self.results[self._current_res_id]
|
||||
water_z = result.get("table")["Z"][
|
||||
|
||||
@@ -63,9 +63,6 @@ class PlotAdis(PamhyrPlot):
|
||||
self.label["C"] = _translate("Results", "Concentration")
|
||||
self.label_max["C"] = _translate("Results", "Max Concentration")
|
||||
self.label_min["C"] = _translate("Results", "Min Concentration")
|
||||
self.label["T"] = _translate("Results", "Temperature")
|
||||
self.label_max["T"] = _translate("Results", "Max Temperature")
|
||||
self.label_min["T"] = _translate("Results", "Min Temperature")
|
||||
if self._type_pol[pol_id[0]] == -1: # Total
|
||||
self.label["M"] = _translate("Results", "Thickness")
|
||||
self.label_max["M"] = _translate("Results", "Max Thickness")
|
||||
@@ -78,7 +75,6 @@ class PlotAdis(PamhyrPlot):
|
||||
self.label_y = self._available_values_y["unit_"+self._key]
|
||||
self.val_id = {}
|
||||
self.val_id["C"] = 0
|
||||
self.val_id["T"] = 0
|
||||
self.val_id["G"] = 1
|
||||
self.val_id["M"] = 2
|
||||
self.val_id["D"] = 3
|
||||
@@ -209,12 +205,9 @@ class PlotAdis_dx(PlotAdis):
|
||||
self._current_timestamp, "pols"
|
||||
)[pol_id][self.val_id[self._key]],
|
||||
reach.profiles))
|
||||
label = self.label[self._key]
|
||||
if name != "TEM":
|
||||
label += (" "+name)
|
||||
self._lines.append(self.canvas.axes.plot(
|
||||
x, y,
|
||||
label=label,
|
||||
label=self.label[self._key]+" "+name,
|
||||
color=self.colors[pol_id % len(self.colors)],
|
||||
**self.plot_default_kargs
|
||||
)[0])
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
# TableAdisTT.py -- Pamhyr
|
||||
# Copyright (C) 2023-2026 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 -*-
|
||||
|
||||
import logging
|
||||
import traceback
|
||||
|
||||
from tools import timer, trace
|
||||
|
||||
from PyQt5.QtGui import (
|
||||
QKeySequence, QColor
|
||||
)
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QAbstractTableModel, QModelIndex,
|
||||
QVariant, pyqtSlot, QCoreApplication,
|
||||
)
|
||||
from PyQt5.QtWidgets import (
|
||||
QMessageBox, QUndoCommand, QUndoStack,
|
||||
QStyledItemDelegate, QLineEdit, QAbstractItemView,
|
||||
QComboBox,
|
||||
)
|
||||
|
||||
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||
from View.Results.translate import *
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class TableModel(PamhyrTableModel):
|
||||
def _setup_lst(self):
|
||||
_river = self._data.river
|
||||
self._timestamp = min(list(self._data.get("timestamps")))
|
||||
if self._opt_data == "reach":
|
||||
self._lst = _river.reachs
|
||||
elif self._opt_data == "profile":
|
||||
self._lst = _river.reach(0).profiles
|
||||
elif self._opt_data == "raw_data":
|
||||
self._lst = _river.reach(0).profiles
|
||||
|
||||
def __init__(self, type_pol, **kwargs):
|
||||
self._type_pol = type_pol
|
||||
super(TableModel, self).__init__(**kwargs)
|
||||
|
||||
def data(self, index, role=Qt.DisplayRole):
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
return QVariant()
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
if self._opt_data == "reach":
|
||||
if self._headers[column] == "name":
|
||||
v = self._lst[row].name
|
||||
return str(v)
|
||||
elif self._opt_data == "profile":
|
||||
if self._headers[column] == "name":
|
||||
v = self._lst[row].name
|
||||
return str(v)
|
||||
elif self._headers[column] == "rk":
|
||||
v = self._lst[row].rk
|
||||
return f"{v:.4f}"
|
||||
elif self._opt_data == "raw_data":
|
||||
p = self._lst[row]
|
||||
if self._headers[column] == "name":
|
||||
if p.name == "":
|
||||
return f"{p.rk:.4f}"
|
||||
return f"{p.name}"
|
||||
tmp_list = self._data.pollutants_list.copy()
|
||||
tmp_list.remove("total_sediment")
|
||||
tmp_list2 = self._data.pollutants_list.copy()
|
||||
for pol in tmp_list:
|
||||
pol_index = tmp_list2.index(pol)
|
||||
if self._headers[column] == pol + " Concentration":
|
||||
v = self._lst[row].get_ts_key(
|
||||
self._timestamp, "pols")[pol_index][0]
|
||||
return f"{v:.4f}"
|
||||
if self._headers[column] == pol + " Temperature":
|
||||
v = self._lst[row].get_ts_key(
|
||||
self._timestamp, "pols")[pol_index][0]
|
||||
return f"{v:.4f}"
|
||||
if self._headers[column] == pol + " Mass":
|
||||
if self._type_pol[pol_index] == 7:
|
||||
m1 = self._lst[row].get_ts_key(
|
||||
self._timestamp, "pols")[pol_index][1]
|
||||
m2 = self._lst[row].get_ts_key(
|
||||
self._timestamp, "pols")[pol_index][2]
|
||||
m3 = self._lst[row].get_ts_key(
|
||||
self._timestamp, "pols")[pol_index][3]
|
||||
v = m1 + m2 + m3
|
||||
return f"{v:.4f}"
|
||||
else:
|
||||
return ""
|
||||
|
||||
return QVariant()
|
||||
|
||||
def update(self, reach):
|
||||
_river = self._data.river
|
||||
|
||||
if self._opt_data == "reach":
|
||||
self._lst = _river.reachs
|
||||
elif self._opt_data == "profile" or self._opt_data == "raw_data":
|
||||
self._lst = _river.reach(reach).profiles
|
||||
|
||||
self.layoutChanged.emit()
|
||||
|
||||
@property
|
||||
def timestamp(self):
|
||||
return self._timestamp
|
||||
|
||||
def set_timestamp(self, timestamp):
|
||||
self._timestamp = timestamp
|
||||
self.layoutChanged.emit()
|
||||
@@ -527,16 +527,14 @@ class ResultsWindow(PamhyrWindow):
|
||||
# self._additional_plot[plot].set_result(solver_id)
|
||||
|
||||
if timestamp is not None:
|
||||
self.plot_xy.set_timestamp_preserve_view(timestamp)
|
||||
self.plot_ac.set_timestamp_preserve_view(timestamp)
|
||||
self.plot_rkc.set_timestamp_preserve_view(timestamp)
|
||||
self.plot_xy.set_timestamp(timestamp)
|
||||
self.plot_ac.set_timestamp(timestamp)
|
||||
self.plot_rkc.set_timestamp(timestamp)
|
||||
if tab_index == 2:
|
||||
self.plot_h.set_timestamp_preserve_view(timestamp)
|
||||
self.plot_h.set_timestamp(timestamp)
|
||||
|
||||
if tab_widget.currentIndex() > 2:
|
||||
self._additional_plot[name].set_timestamp_preserve_view(
|
||||
timestamp
|
||||
)
|
||||
self._additional_plot[name].set_timestamp(timestamp)
|
||||
|
||||
# for plot in self._additional_plot:
|
||||
# self._additional_plot[plot].set_timestamp(timestamp)
|
||||
@@ -1152,7 +1150,6 @@ class ResultsWindow(PamhyrWindow):
|
||||
z = table["Z"][:, profile.global_index]
|
||||
q = table["Q"][:, profile.global_index]
|
||||
v = table["V"][:, profile.global_index]
|
||||
zfd = table["zfd"][:, profile.global_index]
|
||||
|
||||
if self._current_results == 2:
|
||||
reach1 = self._results[0].river.reach(self._reach)
|
||||
@@ -1171,8 +1168,8 @@ class ResultsWindow(PamhyrWindow):
|
||||
v2 = table["V"][:, profile2.global_index]
|
||||
|
||||
if "bed_elevation" in y:
|
||||
if reach.has_bedload():
|
||||
z_min = zfd
|
||||
if reach.has_bedload() and "zfd" in table:
|
||||
z_min = table["zfd"][:, profile.global_index]
|
||||
else:
|
||||
z_min = [profile.geometry.z_min()] * len(self._timestamps)
|
||||
|
||||
|
||||
@@ -532,12 +532,12 @@ class ResultsWindowAdisTS(PamhyrWindow):
|
||||
self.plot_mdt.set_pollutant(self._current_pol_id)
|
||||
|
||||
if timestamp is not None:
|
||||
self.plot_cdt.set_timestamp_preserve_view(timestamp)
|
||||
self.plot_cdx.set_timestamp_preserve_view(timestamp)
|
||||
self.plot_mdx.set_timestamp_preserve_view(timestamp)
|
||||
self.plot_mdt.set_timestamp_preserve_view(timestamp)
|
||||
self.plot_tdt.set_timestamp_preserve_view(timestamp)
|
||||
self.plot_tdx.set_timestamp_preserve_view(timestamp)
|
||||
self.plot_cdt.set_timestamp(timestamp)
|
||||
self.plot_cdx.set_timestamp(timestamp)
|
||||
self.plot_mdx.set_timestamp(timestamp)
|
||||
self.plot_mdt.set_timestamp(timestamp)
|
||||
self.plot_tdt.set_timestamp(timestamp)
|
||||
self.plot_tdx.set_timestamp(timestamp)
|
||||
|
||||
self._table["raw_data"].set_timestamp(timestamp)
|
||||
|
||||
|
||||
@@ -1,756 +0,0 @@
|
||||
# WindowAdisTT.py -- Pamhyr
|
||||
# Copyright (C) 2023-2026 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 -*-
|
||||
|
||||
import os
|
||||
import csv
|
||||
import logging
|
||||
|
||||
from datetime import datetime
|
||||
from tools import trace, timer, logger_exception
|
||||
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
|
||||
from PyQt5.QtGui import (
|
||||
QKeySequence, QIcon, QPixmap,
|
||||
)
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel,
|
||||
QCoreApplication, QModelIndex, pyqtSlot,
|
||||
QItemSelectionModel, QTimer,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QPushButton, QLineEdit,
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
|
||||
QSlider, QLabel, QWidget, QGridLayout,
|
||||
)
|
||||
|
||||
from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
||||
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
||||
|
||||
from View.Results.PlotSedAdis import PlotAdis_dx, PlotAdis_dt
|
||||
|
||||
from View.Results.CustomPlot.Plot import CustomPlot
|
||||
from View.Results.CustomExport.CustomExportAdis import (
|
||||
CustomExportAdisDialog,
|
||||
)
|
||||
|
||||
from View.Results.TableAdisTT import TableModel
|
||||
from View.Results.translate import ResultsTranslate
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class ResultsWindowAdisTT(PamhyrWindow):
|
||||
_pamhyr_ui = "ResultsAdisTT"
|
||||
_pamhyr_name = "Results"
|
||||
|
||||
def _path_file(self, filename):
|
||||
return os.path.abspath(
|
||||
os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
"..", "ui", "ressources", filename
|
||||
)
|
||||
)
|
||||
|
||||
def __init__(self, study=None, config=None,
|
||||
solver=None, results=None,
|
||||
parent=None):
|
||||
self._solver = solver
|
||||
self._results = results
|
||||
self.pollutant_label = ["None"]
|
||||
|
||||
pollutants_headers = self._results.pollutants_list.copy()
|
||||
|
||||
trad = ResultsTranslate(pollutants_headers)
|
||||
name = (
|
||||
trad[self._pamhyr_name] + " - "
|
||||
+ study.name + " - "
|
||||
+ self._solver.name
|
||||
)
|
||||
|
||||
super(ResultsWindowAdisTT, self).__init__(
|
||||
title=name,
|
||||
study=study,
|
||||
config=config,
|
||||
trad=trad,
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self._hash_data.append(self._solver)
|
||||
self._hash_data.append(self._results._repertory)
|
||||
self._hash_data.append(self._results._name)
|
||||
|
||||
self._additional_plot = {}
|
||||
self._current_pol_id = [1]
|
||||
self._reach_id = 0
|
||||
self._profile_id = 0
|
||||
|
||||
try:
|
||||
self._timestamps = sorted(list(self._results.get("timestamps")))
|
||||
self.set_type_pol()
|
||||
self.setup_slider()
|
||||
self.setup_table()
|
||||
self.setup_plots()
|
||||
self.setup_statusbar()
|
||||
self.setup_connections()
|
||||
self.update_table_selection_reach(self._reach_id)
|
||||
self.update_table_selection_profile(self._profile_id)
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
return
|
||||
|
||||
def set_type_pol(self):
|
||||
self._type_pol = []
|
||||
self._pol_id_dict = {}
|
||||
tmp_list = self._results.river.reach(0).profiles
|
||||
for pol_index in range(self._results.nb_pollutants):
|
||||
pol_name = self._results.pollutants_list[pol_index]
|
||||
if pol_name == "total_sediment":
|
||||
self._type_pol.append(-1)
|
||||
else:
|
||||
self._type_pol.append(len(
|
||||
tmp_list[0].get_ts_key(
|
||||
self._timestamps[0], "pols")[pol_index])
|
||||
)
|
||||
self._pol_id_dict[pol_name] = pol_index
|
||||
|
||||
def setup_table(self):
|
||||
self._table = {}
|
||||
for t in ["reach", "profile", "raw_data"]:
|
||||
table = self.find(QTableView, f"tableView_{t}")
|
||||
self._table[t] = TableModel(
|
||||
self._type_pol,
|
||||
table_view=table,
|
||||
table_headers=self._trad.get_dict(f"table_headers_{t}"),
|
||||
data=self._results,
|
||||
undo=self._undo_stack,
|
||||
opt_data=t,
|
||||
)
|
||||
self._table[t]._timestamp = self._timestamps[
|
||||
self._slider_time.value()]
|
||||
|
||||
def setup_slider(self):
|
||||
self._slider_time = self.find(QSlider, f"horizontalSlider_time")
|
||||
self._slider_time.setMaximum(len(self._timestamps) - 1)
|
||||
self._slider_time.setValue(len(self._timestamps) - 1)
|
||||
|
||||
self._icon_start = QIcon()
|
||||
self._icon_start.addPixmap(
|
||||
QPixmap(self._path_file("media-playback-start.png"))
|
||||
)
|
||||
|
||||
self._icon_pause = QIcon()
|
||||
self._icon_pause.addPixmap(
|
||||
QPixmap(self._path_file("media-playback-pause.png"))
|
||||
)
|
||||
self._button_play = self.find(QPushButton, f"playButton")
|
||||
self._button_play.setIcon(self._icon_start)
|
||||
self._button_back = self.find(QPushButton, f"backButton")
|
||||
self._button_next = self.find(QPushButton, f"nextButton")
|
||||
self._button_first = self.find(QPushButton, f"firstButton")
|
||||
self._button_last = self.find(QPushButton, f"lastButton")
|
||||
self._timer = QTimer(self)
|
||||
|
||||
def setup_plots(self):
|
||||
self.canvas_cdt = MplCanvas(width=5, height=4, dpi=100)
|
||||
self.canvas_cdt.setObjectName("canvas_cdt")
|
||||
self.toolbar_cdt = PamhyrPlotToolbar(
|
||||
self.canvas_cdt, self, items=[
|
||||
"home", "move", "zoom", "save",
|
||||
"iso", "back/forward"
|
||||
]
|
||||
)
|
||||
self.plot_layout_cdt = self.find(
|
||||
QVBoxLayout, "verticalLayout_concentration_dt")
|
||||
self.plot_layout_cdt.addWidget(self.toolbar_cdt)
|
||||
self.plot_layout_cdt.addWidget(self.canvas_cdt)
|
||||
|
||||
self.plot_cdt = PlotAdis_dt(
|
||||
canvas=self.canvas_cdt,
|
||||
results=self._results,
|
||||
reach_id=self._reach_id,
|
||||
profile_id=self._profile_id,
|
||||
pol_id=self._current_pol_id,
|
||||
key="T",
|
||||
type_pol=self._type_pol,
|
||||
trad=self._trad,
|
||||
toolbar=self.toolbar_cdt
|
||||
)
|
||||
self.plot_cdt.draw()
|
||||
|
||||
self.canvas_cdx = MplCanvas(width=5, height=4, dpi=100)
|
||||
self.canvas_cdx.setObjectName("canvas_cdx")
|
||||
self.toolbar_cdx = PamhyrPlotToolbar(
|
||||
self.canvas_cdx, self, items=[
|
||||
"home", "move", "zoom", "save",
|
||||
"iso", "back/forward"
|
||||
]
|
||||
)
|
||||
self.plot_layout_cdx = self.find(
|
||||
QVBoxLayout, "verticalLayout_concentration_dx")
|
||||
self.plot_layout_cdx.addWidget(self.toolbar_cdx)
|
||||
self.plot_layout_cdx.addWidget(self.canvas_cdx)
|
||||
|
||||
self.plot_cdx = PlotAdis_dx(
|
||||
canvas=self.canvas_cdx,
|
||||
results=self._results,
|
||||
reach_id=self._reach_id,
|
||||
profile_id=self._profile_id,
|
||||
pol_id=self._current_pol_id,
|
||||
key="T",
|
||||
type_pol=self._type_pol,
|
||||
trad=self._trad,
|
||||
toolbar=self.toolbar_cdx
|
||||
)
|
||||
self.plot_cdx.draw()
|
||||
|
||||
# The AdisTT window only displays temperature plots. The code below
|
||||
# belongs to the sediment/pollutant result window and its layouts are
|
||||
# intentionally absent from ResultsAdisTT.ui.
|
||||
return
|
||||
|
||||
self.canvas_mdx = MplCanvas(width=5, height=4, dpi=100)
|
||||
self.canvas_mdx.setObjectName("canvas_mdx")
|
||||
self.toolbar_mdx = PamhyrPlotToolbar(
|
||||
self.canvas_mdx, self, items=[
|
||||
"home", "move", "zoom", "save",
|
||||
"iso", "back/forward"
|
||||
]
|
||||
)
|
||||
self.plot_layout_mdx = self.find(
|
||||
QVBoxLayout, "verticalLayout_mass_dx2")
|
||||
self.plot_layout_mdx.addWidget(self.toolbar_mdx)
|
||||
self.plot_layout_mdx.addWidget(self.canvas_mdx)
|
||||
|
||||
self.plot_mdx = PlotAdis_dx(
|
||||
canvas=self.canvas_mdx,
|
||||
results=self._results,
|
||||
reach_id=self._reach_id,
|
||||
profile_id=self._profile_id,
|
||||
pol_id=self._current_pol_id,
|
||||
key="M",
|
||||
type_pol=self._type_pol,
|
||||
trad=self._trad,
|
||||
toolbar=self.toolbar_mdx
|
||||
)
|
||||
|
||||
self.plot_mdx.draw()
|
||||
|
||||
self.canvas_mdt = MplCanvas(width=5, height=4, dpi=100)
|
||||
self.canvas_mdt.setObjectName("canvas_mdt")
|
||||
self.toolbar_mdt = PamhyrPlotToolbar(
|
||||
self.canvas_mdt, self, items=[
|
||||
"home", "move", "zoom", "save",
|
||||
"iso", "back/forward"
|
||||
]
|
||||
)
|
||||
self.plot_layout_mdt = self.find(
|
||||
QVBoxLayout, "verticalLayout_mass_dt2")
|
||||
self.plot_layout_mdt.addWidget(self.toolbar_mdt)
|
||||
self.plot_layout_mdt.addWidget(self.canvas_mdt)
|
||||
|
||||
self.plot_mdt = PlotAdis_dt(
|
||||
canvas=self.canvas_mdt,
|
||||
results=self._results,
|
||||
reach_id=self._reach_id,
|
||||
profile_id=self._profile_id,
|
||||
pol_id=self._current_pol_id,
|
||||
key="M",
|
||||
type_pol=self._type_pol,
|
||||
trad=self._trad,
|
||||
toolbar=self.toolbar_mdt
|
||||
)
|
||||
|
||||
self.plot_mdt.draw()
|
||||
|
||||
# Thickness
|
||||
|
||||
self.canvas_tdx = MplCanvas(width=5, height=4, dpi=100)
|
||||
self.canvas_tdx.setObjectName("canvas_tdx")
|
||||
self.toolbar_tdx = PamhyrPlotToolbar(
|
||||
self.canvas_tdx, self, items=[
|
||||
"home", "move", "zoom", "save",
|
||||
"iso", "back/forward"
|
||||
]
|
||||
)
|
||||
self.plot_layout_tdx = self.find(
|
||||
QVBoxLayout, "verticalLayout_tdx")
|
||||
self.plot_layout_tdx.addWidget(self.toolbar_tdx)
|
||||
self.plot_layout_tdx.addWidget(self.canvas_tdx)
|
||||
|
||||
self.plot_tdx = PlotAdis_dx(
|
||||
canvas=self.canvas_tdx,
|
||||
results=self._results,
|
||||
reach_id=self._reach_id,
|
||||
profile_id=self._profile_id,
|
||||
pol_id=[0],
|
||||
key="M",
|
||||
type_pol=self._type_pol,
|
||||
trad=self._trad,
|
||||
toolbar=self.toolbar_tdx
|
||||
)
|
||||
|
||||
self.plot_tdx.draw()
|
||||
|
||||
self.canvas_tdt = MplCanvas(width=5, height=4, dpi=100)
|
||||
self.canvas_tdt.setObjectName("canvas_tdt")
|
||||
self.toolbar_tdt = PamhyrPlotToolbar(
|
||||
self.canvas_tdt, self, items=[
|
||||
"home", "move", "zoom", "save",
|
||||
"iso", "back/forward"
|
||||
]
|
||||
)
|
||||
self.plot_layout_tdt = self.find(
|
||||
QVBoxLayout, "verticalLayout_tdt")
|
||||
self.plot_layout_tdt.addWidget(self.toolbar_tdt)
|
||||
self.plot_layout_tdt.addWidget(self.canvas_tdt)
|
||||
|
||||
self.plot_tdt = PlotAdis_dt(
|
||||
canvas=self.canvas_tdt,
|
||||
results=self._results,
|
||||
reach_id=self._reach_id,
|
||||
profile_id=self._profile_id,
|
||||
pol_id=[0],
|
||||
key="M",
|
||||
type_pol=self._type_pol,
|
||||
trad=self._trad,
|
||||
toolbar=self.toolbar_tdt
|
||||
)
|
||||
|
||||
self.plot_tdt.draw()
|
||||
|
||||
def closeEvent(self, event):
|
||||
try:
|
||||
self._timer.stop()
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
|
||||
super(ResultsWindowAdisTT, self).closeEvent(event)
|
||||
|
||||
def _compute_status_label(self):
|
||||
return (self.text_bief() + " | " +
|
||||
self.text_profile() + " | " +
|
||||
self.text_time())
|
||||
|
||||
def text_bief(self):
|
||||
# Reach
|
||||
table = self.find(QTableView, f"tableView_reach")
|
||||
indexes = table.selectedIndexes()
|
||||
if len(indexes) == 0:
|
||||
reach = self._study.river.enable_edges()[0]
|
||||
else:
|
||||
reach = self._study.river.enable_edges()[indexes[0].row()]
|
||||
return f"{self._trad['reach']}: {reach.name}"
|
||||
|
||||
def text_profile(self):
|
||||
# Reach
|
||||
table = self.find(QTableView, f"tableView_reach")
|
||||
indexes = table.selectedIndexes()
|
||||
if len(indexes) == 0:
|
||||
reach = self._study.river.enable_edges()[0]
|
||||
else:
|
||||
reach = self._study.river.enable_edges()[indexes[0].row()]
|
||||
# Profile
|
||||
table = self.find(QTableView, f"tableView_profile")
|
||||
indexes = table.selectedIndexes()
|
||||
if len(indexes) == 0:
|
||||
profile = reach.reach.profile(0)
|
||||
else:
|
||||
profile = reach.reach.profile(indexes[0].row())
|
||||
|
||||
pname = profile.name if profile.name != "" else profile.rk
|
||||
return f"{self._trad['cross_section']}: {pname}"
|
||||
|
||||
def text_time(self):
|
||||
# Timestamp
|
||||
ts = self._timestamps[self._slider_time.value()]
|
||||
|
||||
t0 = datetime.fromtimestamp(0)
|
||||
fts = str(
|
||||
datetime.fromtimestamp(ts) - t0
|
||||
)
|
||||
fts = str(
|
||||
datetime.fromtimestamp(ts) - t0
|
||||
)
|
||||
fts.replace("days", _translate("Results", "days"))\
|
||||
.replace("day", _translate("Results", "day"))
|
||||
return f"{self._trad['time']} : {fts} ({ts} sec)"
|
||||
|
||||
def text_pollutant(self):
|
||||
# Pollutant
|
||||
table = self.find(QTableView, f"tableView_pollutants")
|
||||
indexes = table.selectedIndexes()
|
||||
if len(indexes) != 0:
|
||||
self.pollutant_label = [
|
||||
self._results.pollutants_list[i.row()+1] for i in indexes
|
||||
]
|
||||
|
||||
return (f"Pollutant: {', '.join(self.pollutant_label)}")
|
||||
|
||||
def setup_statusbar(self):
|
||||
txt = self._compute_status_label()
|
||||
self._status_label = QLabel(txt)
|
||||
self.statusbar.addPermanentWidget(self._status_label)
|
||||
|
||||
def update_statusbar(self):
|
||||
txt = self._compute_status_label()
|
||||
self._status_label.setText(txt)
|
||||
|
||||
def setup_connections(self):
|
||||
# Action
|
||||
actions = {
|
||||
"action_reload": self._reload,
|
||||
# TODO "action_add": self._add_custom_plot,
|
||||
"action_export": self.export,
|
||||
}
|
||||
|
||||
self.find(QAction, "action_add").setEnabled(False)
|
||||
|
||||
for action in actions:
|
||||
self.find(QAction, action).triggered.connect(
|
||||
actions[action]
|
||||
)
|
||||
|
||||
# Table and Plot
|
||||
fun = {
|
||||
"reach": self._set_current_reach,
|
||||
"profile": self._set_current_profile,
|
||||
"raw_data": self._set_current_profile_raw_data,
|
||||
}
|
||||
|
||||
for t in ["reach", "profile"]:
|
||||
table = self.find(QTableView, f"tableView_{t}")
|
||||
|
||||
table.selectionModel()\
|
||||
.selectionChanged\
|
||||
.connect(fun[t])
|
||||
|
||||
self._table[t].dataChanged.connect(fun[t])
|
||||
|
||||
self._slider_time.valueChanged.connect(self._set_current_timestamp)
|
||||
self._button_play.setChecked(False)
|
||||
self._button_play.clicked.connect(self._pause)
|
||||
self._button_back.clicked.connect(self._back)
|
||||
self._button_next.clicked.connect(self._next)
|
||||
self._button_first.clicked.connect(self._first)
|
||||
self._button_last.clicked.connect(self._last)
|
||||
self._timer.timeout.connect(self._update_slider)
|
||||
|
||||
def update_table_selection_reach(self, ind):
|
||||
table = self.find(QTableView, f"tableView_reach")
|
||||
selectionModel = table.selectionModel()
|
||||
index = table.model().index(ind, 0)
|
||||
|
||||
selectionModel.select(
|
||||
index,
|
||||
QItemSelectionModel.Rows |
|
||||
QItemSelectionModel.ClearAndSelect |
|
||||
QItemSelectionModel.Select
|
||||
)
|
||||
table.scrollTo(index)
|
||||
|
||||
self._table["profile"].update(ind)
|
||||
self._table["raw_data"].update(ind)
|
||||
|
||||
def update_table_selection_profile(self, ind):
|
||||
for t in ["profile"]:
|
||||
table = self.find(QTableView, f"tableView_{t}")
|
||||
selectionModel = table.selectionModel()
|
||||
index = table.model().index(ind, 0)
|
||||
|
||||
selectionModel.select(
|
||||
index,
|
||||
QItemSelectionModel.Rows |
|
||||
QItemSelectionModel.ClearAndSelect |
|
||||
QItemSelectionModel.Select
|
||||
)
|
||||
table.scrollTo(index)
|
||||
|
||||
def update_table_selection_pol(self, ind):
|
||||
for t in ["pollutants"]:
|
||||
table = self.find(QTableView, f"tableView_{t}")
|
||||
selectionModel = table.selectionModel()
|
||||
index = table.model().index(ind[0] - 1, 0)
|
||||
|
||||
selectionModel.select(
|
||||
index,
|
||||
QItemSelectionModel.Rows |
|
||||
QItemSelectionModel.ClearAndSelect |
|
||||
QItemSelectionModel.Select
|
||||
)
|
||||
table.scrollTo(index)
|
||||
|
||||
def update(self, reach_id=None, profile_id=None,
|
||||
pol_id=None, timestamp=None):
|
||||
if reach_id is not None:
|
||||
self._reach_id = reach_id
|
||||
self.plot_cdt.set_reach(reach_id)
|
||||
self.plot_cdx.set_reach(reach_id)
|
||||
|
||||
self.update_table_selection_reach(reach_id)
|
||||
self.update_table_selection_profile(0)
|
||||
|
||||
if profile_id is not None:
|
||||
self._profile_id = profile_id
|
||||
self.plot_cdt.set_profile(profile_id)
|
||||
self.plot_cdx.set_profile(profile_id)
|
||||
|
||||
self.update_table_selection_profile(profile_id)
|
||||
|
||||
if pol_id is not None:
|
||||
self._current_pol_id = [p+1 for p in pol_id] # rm total_sediment
|
||||
self.plot_cdt.set_pollutant(self._current_pol_id)
|
||||
self.plot_cdx.set_pollutant(self._current_pol_id)
|
||||
|
||||
if timestamp is not None:
|
||||
self.plot_cdt.set_timestamp_preserve_view(timestamp)
|
||||
self.plot_cdx.set_timestamp_preserve_view(timestamp)
|
||||
|
||||
self._table["raw_data"].set_timestamp(timestamp)
|
||||
|
||||
self.update_statusbar()
|
||||
|
||||
def _get_current_timestamp(self):
|
||||
return self._timestamps[
|
||||
self._slider_time.value()
|
||||
]
|
||||
|
||||
def _set_current_reach(self):
|
||||
table = self.find(QTableView, f"tableView_reach")
|
||||
indexes = table.selectedIndexes()
|
||||
if len(indexes) == 0:
|
||||
return
|
||||
|
||||
self.update(reach_id=indexes[0].row())
|
||||
|
||||
def _set_current_profile(self):
|
||||
table = self.find(QTableView, f"tableView_profile")
|
||||
indexes = table.selectedIndexes()
|
||||
if len(indexes) == 0:
|
||||
return
|
||||
|
||||
self.update(profile_id=indexes[0].row())
|
||||
|
||||
def _set_current_pol(self):
|
||||
table = self.find(QTableView, f"tableView_pollutants")
|
||||
indexes = table.selectedIndexes()
|
||||
rows = [i.row() for i in indexes]
|
||||
if len(indexes) == 0:
|
||||
return
|
||||
|
||||
self.update(pol_id=rows)
|
||||
|
||||
def _set_current_profile_raw_data(self):
|
||||
return
|
||||
|
||||
def _set_current_timestamp(self):
|
||||
timestamp = self._timestamps[self._slider_time.value()]
|
||||
self.update(timestamp=timestamp)
|
||||
|
||||
def _reload_plots(self):
|
||||
self.plot_cdt.results = self._results
|
||||
self.plot_cdx.results = self._results
|
||||
|
||||
self.plot_cdt.draw()
|
||||
self.plot_cdx.draw()
|
||||
|
||||
def _reload_slider(self):
|
||||
self._slider_time = self.find(QSlider, f"horizontalSlider_time")
|
||||
self._slider_time.setMaximum(len(self._timestamps) - 1)
|
||||
self._slider_time.setValue(len(self._timestamps) - 1)
|
||||
|
||||
def _reload(self):
|
||||
logger.debug("Reload results...")
|
||||
self._results = self._results.reload()
|
||||
|
||||
self._timestamps = sorted(list(self._results.get("timestamps")))
|
||||
|
||||
self._reload_plots()
|
||||
self._reload_slider()
|
||||
|
||||
def _copy(self):
|
||||
# focus on raw data table
|
||||
if self.find(QTabWidget, f"tabWidget").currentIndex() == 0:
|
||||
table = self.find(QTableView, f"tableView_raw_data")
|
||||
model = self._table["raw_data"]
|
||||
|
||||
coltext = []
|
||||
for index in sorted(table.selectionModel().selectedRows()):
|
||||
row = index.row()
|
||||
rowtext = []
|
||||
for column in range(model.columnCount()):
|
||||
i = model.createIndex(row, column)
|
||||
try:
|
||||
rowtext.append(str(model.data(i)))
|
||||
except AttributeError:
|
||||
rowtext.append("")
|
||||
coltext.append(rowtext)
|
||||
|
||||
self.copyTableIntoClipboard(coltext)
|
||||
else:
|
||||
logger.info("TODO: copy")
|
||||
|
||||
def _paste(self):
|
||||
logger.info("TODO: paste")
|
||||
|
||||
def _undo(self):
|
||||
self._table.undo()
|
||||
|
||||
def _redo(self):
|
||||
self._table.redo()
|
||||
|
||||
# play / pause buttons
|
||||
def _update_slider(self):
|
||||
if self._slider_time.value() == self._slider_time.maximum():
|
||||
self._slider_time.setValue(self._slider_time.minimum())
|
||||
else:
|
||||
self._slider_time.setValue(self._slider_time.value()+1)
|
||||
|
||||
def _next(self):
|
||||
self._slider_time.setValue(self._slider_time.value()+1)
|
||||
|
||||
def _back(self):
|
||||
self._slider_time.setValue(self._slider_time.value()-1)
|
||||
|
||||
def _first(self):
|
||||
self._slider_time.setValue(self._slider_time.minimum())
|
||||
|
||||
def _last(self):
|
||||
self._slider_time.setValue(self._slider_time.maximum())
|
||||
|
||||
def _pause(self):
|
||||
if self._button_play.isChecked():
|
||||
self._button_next.setEnabled(False)
|
||||
self._button_back.setEnabled(False)
|
||||
self._button_first.setEnabled(False)
|
||||
self._button_last.setEnabled(False)
|
||||
self._timer.start(100)
|
||||
self._button_play.setIcon(self._icon_pause)
|
||||
else:
|
||||
self._timer.stop()
|
||||
self._button_next.setEnabled(True)
|
||||
self._button_back.setEnabled(True)
|
||||
self._button_first.setEnabled(True)
|
||||
self._button_last.setEnabled(True)
|
||||
self._button_play.setIcon(self._icon_start)
|
||||
|
||||
def export(self):
|
||||
|
||||
pols = self._results.pollutants_list.copy()
|
||||
dlg = CustomExportAdisDialog(pollutants=pols,
|
||||
parent=self)
|
||||
if dlg.exec():
|
||||
x, y, pol = dlg.value
|
||||
else:
|
||||
return
|
||||
|
||||
self.file_dialog(
|
||||
select_file="AnyFile",
|
||||
callback=lambda f: self.export_to(f[0], x, y, pol),
|
||||
default_suffix=".csv",
|
||||
file_filter=["CSV (*.csv)"],
|
||||
)
|
||||
|
||||
def export_to(self, filename, x, y, pol):
|
||||
timestamps = sorted(self._results.get("timestamps"))
|
||||
reach = self._results.river.reachs[self._reach_id]
|
||||
first_line = [f"Study: {self._results.study.name}",
|
||||
f"Reach: {reach.name}"]
|
||||
if x == "rk":
|
||||
timestamp = self._get_current_timestamp()
|
||||
first_line.append(f"Time: {timestamp}s")
|
||||
val_dict = self._export_rk(timestamp, y, pol)
|
||||
elif x == "time":
|
||||
profile = reach.profile(self._profile_id)
|
||||
pname = profile.name if profile.name != "" else profile.rk
|
||||
first_line.append(f"Profile: {pname}")
|
||||
val_dict = self._export_time(self._profile_id, y, pol)
|
||||
with open(filename, 'w', newline='') as csvfile:
|
||||
writer = csv.writer(csvfile, delimiter=',',
|
||||
quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||
dict_x = self._trad.get_dict("values_x")
|
||||
header = []
|
||||
writer.writerow(first_line)
|
||||
for text in val_dict.keys():
|
||||
header.append(text)
|
||||
writer.writerow(header)
|
||||
for row in range(len(val_dict[dict_x[x]])):
|
||||
line = []
|
||||
for var in val_dict.keys():
|
||||
line.append(val_dict[var][row])
|
||||
writer.writerow(line)
|
||||
|
||||
def _export_rk(self, timestamp, y, pol):
|
||||
reach = self._results.river.reachs[self._reach_id]
|
||||
dict_x = self._trad.get_dict("values_x")
|
||||
dict_y = self._trad.get_dict("values_y_pol")
|
||||
my_dict = {}
|
||||
my_dict[dict_x["rk"]] = reach.geometry.get_rk()
|
||||
val_id = {}
|
||||
val_id["unit_C"] = 0
|
||||
val_id["unit_M"] = 2
|
||||
val_id["unit_thickness"] = 2
|
||||
for unit in y:
|
||||
if unit == "unit_thickness":
|
||||
pol_id = 0
|
||||
else:
|
||||
pol_id = self._pol_id_dict[pol]
|
||||
if unit == "unit_M" and self._type_pol[pol_id] == 1:
|
||||
my_dict[dict_y[unit]] = [0.0]*len(reach.profiles)
|
||||
else:
|
||||
my_dict[dict_y[unit]] = list(map(lambda p:
|
||||
p.get_ts_key(
|
||||
timestamp, "pols"
|
||||
)[pol_id][val_id[unit]],
|
||||
reach.profiles))
|
||||
|
||||
return my_dict
|
||||
|
||||
def _export_time(self, profile, y, pol):
|
||||
reach = self._results.river.reachs[self._reach_id]
|
||||
profile = reach.profile(profile)
|
||||
ts = list(self._results.get("timestamps"))
|
||||
ts.sort()
|
||||
dict_x = self._trad.get_dict("values_x")
|
||||
dict_y = self._trad.get_dict("values_y_pol")
|
||||
my_dict = {}
|
||||
my_dict[dict_x["time"]] = ts
|
||||
val_id = {}
|
||||
val_id["unit_C"] = 0
|
||||
val_id["unit_M"] = 2
|
||||
val_id["unit_thickness"] = 2
|
||||
for unit in y:
|
||||
if unit == "unit_thickness":
|
||||
pol_id = 0
|
||||
else:
|
||||
pol_id = self._pol_id_dict[pol]
|
||||
if unit == "unit_M" and self._type_pol[pol_id] == 1:
|
||||
my_dict[dict_y[unit]] = [0.0]*len(ts)
|
||||
else:
|
||||
my_dict[dict_y[unit]] = list(map(lambda data_el:
|
||||
data_el[pol_id][val_id[unit]],
|
||||
profile.get_key("pols")
|
||||
))
|
||||
|
||||
return my_dict
|
||||
@@ -121,11 +121,8 @@ class ResultsTranslate(MainTranslate):
|
||||
}
|
||||
tmp = self._sub_dict["table_headers_raw_data"]
|
||||
for pol in self.pollutants:
|
||||
if pol == "TEM":
|
||||
tmp[pol + " Temperature"] = "Temperature (°C)"
|
||||
else:
|
||||
tmp[pol + " Concentration"] = pol + "\n Concentration"
|
||||
tmp[pol + " Mass"] = pol + "\n Mass"
|
||||
tmp[pol + " Concentration"] = pol + "\n Concentration"
|
||||
tmp[pol + " Mass"] = pol + "\n Mass"
|
||||
else:
|
||||
self._sub_dict["table_headers_raw_data"] = {
|
||||
"name": _translate("Results", "Profile"),
|
||||
@@ -149,7 +146,6 @@ class ResultsTranslate(MainTranslate):
|
||||
|
||||
self._sub_dict["values_y_pol"] = {
|
||||
"unit_C": self._dict["unit_concentration"],
|
||||
"unit_T": self._dict["unit_temperature"],
|
||||
"unit_M": self._dict["unit_mass"],
|
||||
"unit_thickness": self._dict["unit_thickness"],
|
||||
}
|
||||
|
||||
@@ -82,9 +82,7 @@ class SelectSolverWindow(PamhyrDialog):
|
||||
# solvers = self._config.solvers
|
||||
# solvers mage
|
||||
solvers = list(filter(
|
||||
lambda x: "adists" not in x._type
|
||||
and "adistt" not in x._type,
|
||||
self._config.solvers
|
||||
lambda x: "adists" not in x._type, self._config.solvers
|
||||
))
|
||||
solvers_name = list(
|
||||
map(
|
||||
|
||||
@@ -83,7 +83,7 @@ class SelectSolverWindowAdisTS(PamhyrDialog):
|
||||
# solvers = self._config.solvers
|
||||
# solvers mage
|
||||
solvers = list(filter(
|
||||
lambda x: "adists" in x._type.lower(),
|
||||
lambda x: "mage" not in x._type and "rubar" not in x._type,
|
||||
self._config.solvers
|
||||
))
|
||||
solvers_name = list(
|
||||
@@ -94,8 +94,7 @@ class SelectSolverWindowAdisTS(PamhyrDialog):
|
||||
)
|
||||
|
||||
solvers_mage = list(filter(
|
||||
lambda x: ("mage" in x._type.lower() or
|
||||
"rubar" in x._type.lower()),
|
||||
lambda x: "mage" or "rubar" in x._type.lower(),
|
||||
self._config.solvers
|
||||
))
|
||||
solvers_mage_names = list(map(lambda x: x._name, solvers_mage))
|
||||
|
||||
@@ -1,506 +0,0 @@
|
||||
# WindowAdisTS.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 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 -*-
|
||||
|
||||
import os
|
||||
import logging
|
||||
import tempfile
|
||||
|
||||
from queue import Queue
|
||||
from tools import trace, timer, logger_exception
|
||||
|
||||
from View.Tools.PamhyrWindow import PamhyrDialog, PamhyrWindow
|
||||
|
||||
from PyQt5.QtGui import (
|
||||
QKeySequence,
|
||||
)
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel,
|
||||
QCoreApplication, QModelIndex, pyqtSlot,
|
||||
QRect, QTimer, QProcess,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QPushButton, QLineEdit,
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
|
||||
QTextEdit,
|
||||
)
|
||||
|
||||
from View.RunSolver.Log.Window import SolverLogFileWindow
|
||||
from View.Results.ReadingResultsDialog import ReadingResultsDialog
|
||||
from View.WaitingDialog import WaitingDialog
|
||||
|
||||
try:
|
||||
from signal import SIGTERM, SIGSTOP, SIGCONT
|
||||
_signal = True
|
||||
except Exception:
|
||||
_signal = False
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class SelectSolverWindowAdisTT(PamhyrDialog):
|
||||
_pamhyr_ui = "SelectSolverAdisTT"
|
||||
_pamhyr_name = "Select solver"
|
||||
|
||||
def __init__(self, study=None, config=None,
|
||||
parent=None):
|
||||
self._solver = None
|
||||
|
||||
name = _translate("Solver", "Select solver")
|
||||
super(SelectSolverWindowAdisTT, self).__init__(
|
||||
title=name,
|
||||
study=study,
|
||||
config=config,
|
||||
options=[],
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self.setup_combobox()
|
||||
self.setup_connections()
|
||||
self.select_last_solver()
|
||||
|
||||
def setup_combobox(self):
|
||||
# solvers = self._config.solvers
|
||||
# solvers mage
|
||||
solvers = list(filter(
|
||||
lambda x: "adistt" in x._type.lower(),
|
||||
self._config.solvers
|
||||
))
|
||||
solvers_name = list(
|
||||
map(
|
||||
self._format_solver_name,
|
||||
solvers
|
||||
)
|
||||
)
|
||||
|
||||
solvers_mage = list(filter(
|
||||
lambda x: ("mage" in x._type.lower() or
|
||||
"rubar" in x._type.lower()),
|
||||
self._config.solvers
|
||||
))
|
||||
solvers_mage_names = list(map(lambda x: x._name, solvers_mage))
|
||||
|
||||
solvers_dir = os.path.join(
|
||||
os.path.dirname(self._study.filename),
|
||||
"_PAMHYR_",
|
||||
self._study.name.replace(" ", "_"),
|
||||
)
|
||||
|
||||
dir_solvers_List = os.listdir(solvers_dir)
|
||||
|
||||
display_mage_names = list(filter(
|
||||
lambda x: x in solvers_mage_names, dir_solvers_List
|
||||
))
|
||||
|
||||
self.combobox_add_items("comboBox", solvers_name)
|
||||
self.combobox_add_items("comboBoxRepMage", display_mage_names)
|
||||
|
||||
def setup_connections(self):
|
||||
self.find(QPushButton, "pushButton_run").clicked.connect(self.accept)
|
||||
self.find(QPushButton, "pushButton_cancel") \
|
||||
.clicked.connect(self.reject)
|
||||
|
||||
def select_last_solver(self):
|
||||
solvers = self._config.solvers
|
||||
last = self._config.last_solver_name
|
||||
|
||||
solver = list(
|
||||
filter(
|
||||
lambda s: s.name == last,
|
||||
solvers
|
||||
)
|
||||
)
|
||||
|
||||
if len(solver) != 0:
|
||||
self.set_combobox_text(
|
||||
"comboBox",
|
||||
self._format_solver_name(solver[0])
|
||||
)
|
||||
|
||||
def _format_solver_name(self, solver):
|
||||
return f"{solver.name} - ({solver._type})"
|
||||
|
||||
@property
|
||||
def solver(self):
|
||||
return self._solver
|
||||
|
||||
@property
|
||||
def mage_rep(self):
|
||||
return self._mage_result_rep
|
||||
|
||||
def accept(self):
|
||||
solver_name = self.get_combobox_text("comboBox")
|
||||
solver_name = solver_name.rsplit(" - ", 1)[0]
|
||||
|
||||
self._mage_result_rep = self.get_combobox_text("comboBoxRepMage")
|
||||
|
||||
self._config.update_last_solver_used(solver_name)
|
||||
|
||||
self._solver = next(
|
||||
filter(
|
||||
lambda s: s.name == solver_name,
|
||||
self._config.solvers
|
||||
)
|
||||
)
|
||||
|
||||
super(SelectSolverWindowAdisTT, self).accept()
|
||||
|
||||
|
||||
class SolverLogWindowAdisTT(PamhyrWindow):
|
||||
_pamhyr_ui = "SolverLogAdisTT"
|
||||
_pamhyr_name = "Solver Log"
|
||||
|
||||
def __init__(self, study=None, config=None,
|
||||
solver=None, parent=None, mage_rep=None):
|
||||
self._solver = solver
|
||||
self._results = None
|
||||
self._results_mage = None
|
||||
self._mage_rep = mage_rep
|
||||
|
||||
name = _translate("Solver", "Select log")
|
||||
super(SolverLogWindowAdisTT, self).__init__(
|
||||
title=name,
|
||||
study=study,
|
||||
config=config,
|
||||
options=[],
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self._workdir = ""
|
||||
self._workdir_mage = ""
|
||||
|
||||
self.setup_action()
|
||||
self.setup_alarm()
|
||||
self.setup_connections()
|
||||
self.setup_workdir()
|
||||
self.setup_process()
|
||||
|
||||
ok = self.export()
|
||||
if ok:
|
||||
self.run()
|
||||
else:
|
||||
self._log(
|
||||
f" *** Failed to export study to {self._solver._type}",
|
||||
color="red"
|
||||
)
|
||||
|
||||
def setup_action(self):
|
||||
self.find(QAction, "action_start").setEnabled(False)
|
||||
if _signal:
|
||||
self.find(QAction, "action_pause").setEnabled(True)
|
||||
else:
|
||||
self.find(QAction, "action_pause").setEnabled(False)
|
||||
|
||||
self.find(QAction, "action_stop").setEnabled(True)
|
||||
self.find(QAction, "action_log_file").setEnabled(False)
|
||||
self.find(QAction, "action_results").setEnabled(False)
|
||||
|
||||
def setup_alarm(self):
|
||||
self._alarm = QTimer()
|
||||
|
||||
def setup_connections(self):
|
||||
self.find(QAction, "action_start").triggered.connect(self.start)
|
||||
self.find(QAction, "action_pause").triggered.connect(self.pause)
|
||||
self.find(QAction, "action_stop").triggered.connect(self.stop)
|
||||
self.find(QAction, "action_log_file").triggered.connect(self.log_file)
|
||||
self.find(QAction, "action_results").triggered.connect(self.results)
|
||||
self.find(QAction, "action_results_Mage").triggered.connect(
|
||||
self.resultsMage
|
||||
)
|
||||
|
||||
self._alarm.timeout.connect(self.update)
|
||||
|
||||
def setup_workdir(self):
|
||||
scenario = self._study.status.scenario
|
||||
srep = scenario.workdir()
|
||||
|
||||
if self._study.filename == "":
|
||||
self._workdir = os.path.join(
|
||||
tempfile.TemporaryDirectory(),
|
||||
srep
|
||||
)
|
||||
else:
|
||||
self._workdir = os.path.join(
|
||||
os.path.dirname(self._study.filename),
|
||||
"_PAMHYR_",
|
||||
self._study.name.replace(" ", "_"),
|
||||
self._solver.name.replace(" ", "_"),
|
||||
srep
|
||||
)
|
||||
|
||||
logger.info(f"Create workdir: '{self._workdir}'")
|
||||
os.makedirs(self._workdir, exist_ok=True)
|
||||
|
||||
self.setup_mage_workdir()
|
||||
|
||||
def setup_mage_workdir(self):
|
||||
scenario = self._study.status.scenario
|
||||
srep = scenario.workdir()
|
||||
|
||||
if self._study.filename == "":
|
||||
self._workdir_mage = os.path.join(
|
||||
tempfile.TemporaryDirectory(),
|
||||
srep
|
||||
)
|
||||
else:
|
||||
self._workdir_mage = os.path.join(
|
||||
os.path.dirname(self._study.filename),
|
||||
"_PAMHYR_",
|
||||
self._study.name.replace(" ", "_"),
|
||||
self._mage_rep.replace(" ", "_"),
|
||||
srep
|
||||
)
|
||||
|
||||
logger.info(f"Create workdir: '{self._workdir_mage}'")
|
||||
|
||||
def setup_process(self):
|
||||
self._alarm.start(100)
|
||||
self._output = Queue()
|
||||
self._process = self.new_process(self._parent)
|
||||
|
||||
def new_process(self, parent):
|
||||
new = QProcess(parent)
|
||||
new.setWorkingDirectory(self._workdir)
|
||||
new.setProcessChannelMode(QProcess.MergedChannels)
|
||||
return new
|
||||
|
||||
def export(self):
|
||||
self._log(f" *** Export study {self._solver.name}", color="blue")
|
||||
ok = self._solver.export(
|
||||
self._study, self._workdir, self._workdir_mage,
|
||||
qlog=self._output
|
||||
)
|
||||
self.update()
|
||||
|
||||
return ok
|
||||
|
||||
def closeEvent(self, event):
|
||||
self._alarm.stop()
|
||||
super(SolverLogWindowAdisTT, self).closeEvent(event)
|
||||
|
||||
def _copy(self):
|
||||
self.find(QTextEdit, "textEdit").copy()
|
||||
|
||||
#######
|
||||
# LOG #
|
||||
#######
|
||||
|
||||
def _log(self, msg, color=None):
|
||||
if type(msg) is str:
|
||||
self._log_str(msg, color)
|
||||
elif type(msg) is int:
|
||||
self._log_int(msg, color)
|
||||
|
||||
def _log_str(self, msg, color=None):
|
||||
if msg == "":
|
||||
return
|
||||
|
||||
logger.info(f"solver: {msg}")
|
||||
msg = msg.rsplit('\n', 1)[0]
|
||||
|
||||
if color is not None:
|
||||
msg = f"<font color=\"{color}\">" + msg + "</font>"
|
||||
|
||||
self.find(QTextEdit, "textEdit").append(msg)
|
||||
|
||||
def _log_int(self, int_code, color=None):
|
||||
logger.info(f"solver: Returns {int_code}")
|
||||
color = "blue" if int_code == 0 else "red"
|
||||
|
||||
self.find(QTextEdit, "textEdit")\
|
||||
.append(
|
||||
f"<font color=\"{color}\">" +
|
||||
f" *** Finished with code {int_code}" +
|
||||
"</font>"
|
||||
)
|
||||
|
||||
self.statusbar.showMessage(
|
||||
"Done" if int_code == 0 else "Failed",
|
||||
3000
|
||||
)
|
||||
|
||||
##########
|
||||
# UPDATE #
|
||||
##########
|
||||
|
||||
def update(self):
|
||||
if self._solver.is_stoped():
|
||||
self.find(QAction, "action_start").setEnabled(True)
|
||||
self.find(QAction, "action_pause").setEnabled(False)
|
||||
self.find(QAction, "action_stop").setEnabled(False)
|
||||
self.find(QAction, "action_results").setEnabled(True)
|
||||
|
||||
if self._solver.log_file() != "":
|
||||
self.find(QAction, "action_log_file").setEnabled(True)
|
||||
|
||||
self._update_logs_all()
|
||||
# self._update_get_results()
|
||||
|
||||
self._update_logs_all()
|
||||
|
||||
def _update_get_results(self):
|
||||
if self._results is None:
|
||||
def reading_fn():
|
||||
try:
|
||||
self._results = self._solver.results(
|
||||
self._study, self._workdir, qlog=self._output
|
||||
)
|
||||
self._parent.set_results(self._solver, self._results)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to open results")
|
||||
logger_exception(e)
|
||||
|
||||
dlg = ReadingResultsDialog(reading_fn=reading_fn, parent=self)
|
||||
dlg.exec_()
|
||||
|
||||
def _update_logs_all(self):
|
||||
while self._output.qsize() != 0:
|
||||
s = self._output.get()
|
||||
|
||||
try:
|
||||
if type(s) is str and "[ERROR]" in s:
|
||||
self._log(s.encode("utf-8"), color="red")
|
||||
else:
|
||||
self._log(s)
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
|
||||
####################
|
||||
# Process controle #
|
||||
####################
|
||||
|
||||
def run(self):
|
||||
self._log(f" *** Run solver {self._solver.name}", color="blue")
|
||||
self._solver.run(
|
||||
self._study,
|
||||
process=self._process,
|
||||
output_queue=self._output
|
||||
)
|
||||
|
||||
def start(self):
|
||||
if self._solver.is_stoped():
|
||||
self._log(f" *** Export study {self._solver.name}", color="blue")
|
||||
|
||||
ok = self._solver.export(
|
||||
self._study, self._workdir, self._workdir_mage,
|
||||
qlog=self._output
|
||||
)
|
||||
|
||||
if not ok:
|
||||
self._log(f" *** Failed to export", color="red")
|
||||
self.update()
|
||||
return
|
||||
else:
|
||||
self.update()
|
||||
self._process = self.new_process(self._parent)
|
||||
|
||||
self._log(" *** Start", color="blue")
|
||||
self._results = None
|
||||
self._solver.start(self._study, process=self._process)
|
||||
|
||||
self.find(QAction, "action_start").setEnabled(False)
|
||||
if _signal:
|
||||
self.find(QAction, "action_pause").setEnabled(True)
|
||||
else:
|
||||
self.find(QAction, "action_pause").setEnabled(False)
|
||||
self.find(QAction, "action_stop").setEnabled(True)
|
||||
self.find(QAction, "action_log_file").setEnabled(False)
|
||||
self.find(QAction, "action_results").setEnabled(False)
|
||||
|
||||
def pause(self):
|
||||
self._log(" *** Pause", color="blue")
|
||||
self._solver.pause()
|
||||
|
||||
self.find(QAction, "action_start").setEnabled(True)
|
||||
self.find(QAction, "action_pause").setEnabled(False)
|
||||
self.find(QAction, "action_stop").setEnabled(True)
|
||||
self.find(QAction, "action_results").setEnabled(False)
|
||||
|
||||
def stop(self):
|
||||
self._log(" *** Stop", color="blue")
|
||||
self._solver.kill()
|
||||
|
||||
self.find(QAction, "action_start").setEnabled(True)
|
||||
self.find(QAction, "action_pause").setEnabled(False)
|
||||
self.find(QAction, "action_stop").setEnabled(False)
|
||||
self.find(QAction, "action_results").setEnabled(True)
|
||||
if self._solver.log_file() != "":
|
||||
self.find(QAction, "action_log_file").setEnabled(True)
|
||||
|
||||
###########
|
||||
# Results #
|
||||
###########
|
||||
|
||||
def results(self):
|
||||
if self._results is None:
|
||||
dir_list = os.listdir(self._workdir)
|
||||
if "resultats" in dir_list:
|
||||
dir_path = os.path.join(self._workdir, "resultats")
|
||||
else:
|
||||
dir_path = self._workdir
|
||||
|
||||
def reading_fn():
|
||||
self._results = self._solver.results(
|
||||
self._study, dir_path, qlog=self._output
|
||||
)
|
||||
|
||||
dlg = WaitingDialog(payload_fn=reading_fn,
|
||||
title="waiting_result",
|
||||
parent=self)
|
||||
dlg.exec_()
|
||||
|
||||
self._parent.set_results(self._solver, self._results)
|
||||
self._parent.open_solver_results_adistt(self._solver, self._results)
|
||||
|
||||
self._solver.has_results_loaded()
|
||||
|
||||
def resultsMage(self):
|
||||
mage_solver = next(filter(
|
||||
lambda x: x._name == self._mage_rep, self._config.solvers
|
||||
))
|
||||
if self._results_mage is None:
|
||||
workdir_mage = self._workdir_mage
|
||||
|
||||
def reading_fn():
|
||||
self._results_mage = mage_solver.results(
|
||||
self._study, workdir_mage, qlog=self._output
|
||||
)
|
||||
|
||||
dlg = ReadingResultsDialog(reading_fn=reading_fn, parent=self)
|
||||
dlg.exec_()
|
||||
|
||||
self._parent.set_results(mage_solver, self._results_mage)
|
||||
self._parent.open_solver_results(mage_solver, self._results_mage)
|
||||
|
||||
mage_solver.has_results_loaded()
|
||||
|
||||
def log_file(self):
|
||||
file_name = os.path.join(self._workdir, self._solver.log_file())
|
||||
log = SolverLogFileWindow(
|
||||
file_name=file_name,
|
||||
study=self._study,
|
||||
config=self._config,
|
||||
solver=self._solver,
|
||||
parent=self,
|
||||
)
|
||||
log.show()
|
||||
@@ -31,7 +31,7 @@ from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QPushButton, QLineEdit,
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QComboBox, QMessageBox,
|
||||
QComboBox,
|
||||
)
|
||||
|
||||
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||
@@ -41,9 +41,6 @@ from View.Stricklers.UndoCommand import (
|
||||
SetMinorCommand, SetMediumCommand,
|
||||
AddCommand, DelCommand, SortCommand,
|
||||
)
|
||||
from View.Tools.CoefficientDisplay import (
|
||||
display_coefficient, stored_coefficient
|
||||
)
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
@@ -51,55 +48,8 @@ _translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class TableModel(PamhyrTableModel):
|
||||
def __init__(self, *args, display_manning=False, unique_names=False,
|
||||
hidden_stricklers=None, **kwargs):
|
||||
self.display_manning = display_manning
|
||||
self.unique_names = unique_names
|
||||
self.hidden_stricklers = hidden_stricklers or []
|
||||
super(TableModel, self).__init__(*args, **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def same_strickler(first, second):
|
||||
return (
|
||||
first.name == second.name
|
||||
and first.comment == second.comment
|
||||
and first.minor == second.minor
|
||||
and first.medium == second.medium
|
||||
)
|
||||
|
||||
@property
|
||||
def visible_stricklers(self):
|
||||
return [
|
||||
strickler
|
||||
for strickler in self._data.stricklers
|
||||
if not any(
|
||||
self.same_strickler(strickler, hidden)
|
||||
for hidden in self.hidden_stricklers
|
||||
)
|
||||
]
|
||||
|
||||
def rowCount(self, parent=QModelIndex()):
|
||||
return len(self.visible_stricklers)
|
||||
|
||||
def get_visible(self, row):
|
||||
return self.visible_stricklers[row]
|
||||
|
||||
def get_data_row(self, row):
|
||||
return self._data.stricklers.index(self.get_visible(row))
|
||||
|
||||
def name_is_already_used(self, row, name):
|
||||
current = self.get_visible(row)
|
||||
return any(
|
||||
strickler is not current and strickler.name == name
|
||||
for strickler in self._data.stricklers
|
||||
)
|
||||
|
||||
def get_true_data_row(self, row):
|
||||
visible = self.visible_stricklers
|
||||
if row >= len(visible):
|
||||
return len(self._data._lst)
|
||||
|
||||
el = visible[row]
|
||||
el = self._data.get(row)
|
||||
|
||||
return next(
|
||||
map(
|
||||
@@ -117,20 +67,15 @@ class TableModel(PamhyrTableModel):
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
strickler = self.get_visible(row)
|
||||
|
||||
if self._headers[column] == "name":
|
||||
return strickler.name
|
||||
return self._data.get(row).name
|
||||
elif self._headers[column] == "comment":
|
||||
return strickler.comment
|
||||
return self._data.get(row).comment
|
||||
elif self._headers[column] == "minor":
|
||||
return display_coefficient(
|
||||
strickler.minor, self.display_manning
|
||||
)
|
||||
return self._data.get(row).minor
|
||||
elif self._headers[column] == "medium":
|
||||
return display_coefficient(
|
||||
strickler.medium, self.display_manning
|
||||
)
|
||||
return self._data.get(row).medium
|
||||
|
||||
return QVariant()
|
||||
|
||||
@@ -145,20 +90,6 @@ class TableModel(PamhyrTableModel):
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
if (
|
||||
self._headers[column] == "name"
|
||||
and self.unique_names
|
||||
and self.name_is_already_used(row, str(value))
|
||||
):
|
||||
QMessageBox.warning(
|
||||
self._table_view,
|
||||
self._trad["duplicate_name_title"],
|
||||
self._trad["duplicate_name_message"]
|
||||
)
|
||||
return False
|
||||
|
||||
row = self.get_data_row(row)
|
||||
|
||||
try:
|
||||
if self._headers[column] == "name":
|
||||
self._undo.push(
|
||||
@@ -175,15 +106,13 @@ class TableModel(PamhyrTableModel):
|
||||
elif self._headers[column] == "minor":
|
||||
self._undo.push(
|
||||
SetMinorCommand(
|
||||
self._data, row,
|
||||
stored_coefficient(value, self.display_manning)
|
||||
self._data, row, value
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "medium":
|
||||
self._undo.push(
|
||||
SetMediumCommand(
|
||||
self._data, row,
|
||||
stored_coefficient(value, self.display_manning)
|
||||
self._data, row, value
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
@@ -214,7 +143,7 @@ class TableModel(PamhyrTableModel):
|
||||
DelCommand(
|
||||
self._data, list(
|
||||
map(
|
||||
lambda r: self.get_visible(r),
|
||||
lambda r: self._data.get(r),
|
||||
rows
|
||||
)
|
||||
)
|
||||
|
||||
@@ -37,11 +37,9 @@ from PyQt5.QtWidgets import (
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
|
||||
QGroupBox,
|
||||
)
|
||||
|
||||
from Model.Stricklers.Stricklers import Stricklers
|
||||
from Modules import Modules
|
||||
|
||||
from View.Stricklers.UndoCommand import PasteCommand
|
||||
from View.Stricklers.Table import TableModel
|
||||
@@ -58,7 +56,7 @@ class StricklersWindow(PamhyrWindow):
|
||||
|
||||
def __init__(self, study=None, config=None, parent=None):
|
||||
trad = StricklersTranslate()
|
||||
name = self.window_name(study, config, trad)
|
||||
name = trad[self._pamhyr_name] + " - " + study.name
|
||||
|
||||
super(StricklersWindow, self).__init__(
|
||||
title=name,
|
||||
@@ -68,46 +66,23 @@ class StricklersWindow(PamhyrWindow):
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self.setup_labels()
|
||||
self.setup_table()
|
||||
self.setup_connections()
|
||||
|
||||
@classmethod
|
||||
def window_name(cls, study, config, trad):
|
||||
display_manning = getattr(config, "display_manning", False)
|
||||
coefficient_name = (
|
||||
"Mannings" if display_manning else cls._pamhyr_name
|
||||
)
|
||||
return trad[coefficient_name] + " - " + study.name
|
||||
|
||||
def setup_labels(self):
|
||||
display_manning = getattr(self._config, "display_manning", False)
|
||||
study_label = (
|
||||
self._trad["study_mannings"] if display_manning
|
||||
else self._trad["study_stricklers"]
|
||||
)
|
||||
application_label = (
|
||||
self._trad["application_mannings"] if display_manning
|
||||
else self._trad["application_stricklers"]
|
||||
)
|
||||
self.find(QGroupBox, "groupBox_2").setTitle(study_label)
|
||||
self.find(QGroupBox, "groupBox").setTitle(application_label)
|
||||
|
||||
def setup_table(self):
|
||||
self._table = {}
|
||||
|
||||
if self._study.is_editable():
|
||||
editable_headers = ["name", "comment", "minor", "medium"]
|
||||
else:
|
||||
editable_headers = []
|
||||
|
||||
for t in ["app", "study"]:
|
||||
table = self.find(QTableView, f"tableView_{t}")
|
||||
if t == "study":
|
||||
data = self._study.river.stricklers
|
||||
hidden_stricklers = self._config.stricklers.stricklers
|
||||
else:
|
||||
data = self._config.stricklers
|
||||
hidden_stricklers = []
|
||||
|
||||
editable_headers = []
|
||||
if t == "study" and self._study.is_editable():
|
||||
editable_headers = ["name", "comment", "minor", "medium"]
|
||||
|
||||
self._table[t] = TableModel(
|
||||
table_view=table,
|
||||
@@ -115,10 +90,6 @@ class StricklersWindow(PamhyrWindow):
|
||||
editable_headers=editable_headers,
|
||||
data=data,
|
||||
undo=self._undo_stack,
|
||||
display_manning=getattr(
|
||||
self._config, "display_manning", False
|
||||
),
|
||||
hidden_stricklers=hidden_stricklers,
|
||||
)
|
||||
|
||||
table.setModel(self._table[t])
|
||||
@@ -132,31 +103,6 @@ class StricklersWindow(PamhyrWindow):
|
||||
self.find(QAction, "action_del").triggered.connect(self.delete)
|
||||
self.find(QAction, "action_sort").triggered.connect(self.sort)
|
||||
|
||||
def _propagated_update(self, key=Modules(0)):
|
||||
if Modules.CONFIG not in key:
|
||||
return
|
||||
|
||||
display_manning = getattr(
|
||||
self._config, "display_manning", False
|
||||
)
|
||||
application_stricklers = self._config.stricklers
|
||||
|
||||
self._table["app"]._data = application_stricklers
|
||||
self._table["app"].display_manning = display_manning
|
||||
self._table["app"].layoutChanged.emit()
|
||||
|
||||
self._table["study"].hidden_stricklers = (
|
||||
application_stricklers.stricklers
|
||||
)
|
||||
self._table["study"].display_manning = display_manning
|
||||
self._table["study"].layoutChanged.emit()
|
||||
|
||||
self._title = self.window_name(
|
||||
self._study, self._config, self._trad
|
||||
)
|
||||
self._set_title()
|
||||
self.setup_labels()
|
||||
|
||||
def index_selected_rows(self):
|
||||
table = self.find(QTableView, f"tableView_study")
|
||||
return list(
|
||||
|
||||
@@ -30,28 +30,6 @@ class StricklersTranslate(MainTranslate):
|
||||
self._dict["Stricklers"] = _translate(
|
||||
"Stricklers", "Strickler coefficients"
|
||||
)
|
||||
self._dict["Mannings"] = _translate(
|
||||
"Stricklers", "Manning coefficients"
|
||||
)
|
||||
self._dict["study_stricklers"] = _translate(
|
||||
"Stricklers", "Strickler coefficients of the study"
|
||||
)
|
||||
self._dict["study_mannings"] = _translate(
|
||||
"Stricklers", "Manning coefficients of the study"
|
||||
)
|
||||
self._dict["application_stricklers"] = _translate(
|
||||
"Stricklers", "Strickler coefficients of the application"
|
||||
)
|
||||
self._dict["application_mannings"] = _translate(
|
||||
"Stricklers", "Manning coefficients of the application"
|
||||
)
|
||||
self._dict["duplicate_name_title"] = _translate(
|
||||
"Stricklers", "Name already used"
|
||||
)
|
||||
self._dict["duplicate_name_message"] = _translate(
|
||||
"Stricklers",
|
||||
"This name is already used by another coefficient."
|
||||
)
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
"name": self._dict["name"],
|
||||
|
||||
Loaded 100 of 130 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user