Compare commits

..

43 Commits

Author SHA1 Message Date
Dylan Jeannin 4d20c2457a pep8 fix 2026-05-20 10:19:52 +02:00
Dylan Jeannin 2dd9003721 merge scenario (missing tables) 2026-05-20 10:18:56 +02:00
Dylan Jeannin 94ceb44fd4 debug load study after deleting a node in the child scenario network 2026-05-20 09:51:38 +02:00
Dylan Jeannin ab50d2adf4 little fixes with variable names 2026-05-19 18:00:39 +02:00
Dylan Jeannin 0eb979256f little fixes with variable names 2026-05-19 17:59:30 +02:00
Pierre-Antoine 5ce94a63d3 Scenario: Clean DB add minimal comment. 2026-05-19 17:54:28 +02:00
Pierre-Antoine 42ea50d62e Study: Minor change. 2026-05-19 16:51:57 +02:00
Pierre-Antoine 0df4cf0fd5 Scenario: Clean DB. 2026-05-19 16:13:30 +02:00
Dylan Jeannin ccf3da114b fix duplication of same objects in db with when saving a child scenario 2026-05-19 16:13:21 +02:00
Dylan Jeannin 348417977d add missing tables in drop_all function, called on a scenario deletion 2026-05-19 15:58:37 +02:00
Pierre-Antoine 914a1f8866 Scenario: Add DB clean methode (not tested yet). 2026-05-19 12:22:20 +02:00
Dylan Jeannin cbbbeeac0b correct error that made InitialCondition addition bug 2026-05-19 11:40:03 +02:00
Dylan Jeannin c9ea726bfb correct error that made LateralContrib deletion bug 2026-05-19 11:30:38 +02:00
Pierre-Antoine fa88e05d91 AdisTS: BC: Fix dual sub classes dependencies. 2026-05-19 10:15:23 +02:00
Pierre-Antoine a6915020cb BC: Minor change. 2026-05-19 09:46:46 +02:00
Dylan Jeannin ea2287215e fix pep8 before push 2026-05-18 15:33:36 +02:00
Dylan Jeannin e940dead70 Merge branch 'dev_dylan' into scenarios 2026-05-18 15:04:37 +02:00
Theophile Terraz b6a6d54a22 Merge branch 'scenarios' of gitlab.com:pamhyr/pamhyr2 into scenarios 2026-05-12 16:17:32 +02:00
Theophile Terraz 11a95cb391 debug 2026-05-12 16:16:56 +02:00
Pierre-Antoine cdcbbc2cf4 doc: Remove watermark. 2026-05-06 11:03:56 +02:00
Dylan Jeannin cb4dfab482 conflicts resolution before merge 2026-05-05 10:50:42 +02:00
Dylan Jeannin cea4dcd9cb refacto variable names for D90 2026-04-28 11:06:57 +02:00
Dylan Jeannin e1c1f411c3 fix bug when add button didnt refresh the tab list in Initial conditions AdisTS and d90 2026-04-28 11:06:57 +02:00
Dylan Jeannin 4550fc95d7 debug delete functionnality in InitialConditionsAdisTS 2026-04-28 11:06:57 +02:00
Dylan Jeannin 1f97af9c03 clean useless data 2026-04-28 11:06:57 +02:00
Dylan Jeannin df9e1ec42d fix delete for pollutants D90 2026-04-28 11:06:57 +02:00
Dylan Jeannin ac79fae1fb debug save db d90 2026-04-28 11:06:57 +02:00
Dylan Jeannin fe39f07981 consistency with called functions in the file 2026-04-28 11:06:57 +02:00
Dylan Jeannin b578e0c50c désactivation temporaire de undo dans la fenêtre résultat qui fait crash Pamhyr 2026-04-28 11:06:57 +02:00
Dylan Jeannin 4408a8f368 debug save BoundaryConditionsAdisTS 2026-04-28 11:06:57 +02:00
Dylan Jeannin d3e922af6e desactivation du clic sur le graph du réseau hors de l'onglet d'édition du réseau (ex. BoundaryConditions...) 2026-04-28 11:06:57 +02:00
Dylan Jeannin 8adf878584 garde le zoom sur un graph après rafraichissement des données 2026-04-28 11:06:57 +02:00
Dylan Jeannin aa6973813f debug fonction SAVE des figures, qui utilisait une méthode Matplotlib, plutôt qu'une méthode native Qt 2026-04-28 11:06:57 +02:00
Dylan Jeannin e21a64fcad zoom plus intuitif avec translation du widget pour garder une cohérence dans le zoom 2026-04-28 11:06:57 +02:00
Dylan Jeannin 8b6308d3c9 inversion du sens de zoom avec la molette sur les graphs (contrintuitif auparavant) 2026-04-28 11:06:57 +02:00
Dylan Jeannin bc3ea9c4b9 ajout automatique de l'extansion .st lorsque l'on ne le stipule pas manuellement dans l'export des tronçons 2026-04-28 11:06:57 +02:00
Dylan Jeannin 04ea55e21a can use '.' caracter and not only ',' in Shift Geometry window 2026-04-28 11:06:57 +02:00
Dylan Jeannin a68270ff67 update model + view to display only BCAdisTS related to pollutant, and not the global list, todo: reconnect add/del buttons 2026-04-28 11:06:57 +02:00
Dylan Jeannin c498ed2d96 add d50/sigma in database + load/save data in UI 2026-04-28 11:06:57 +02:00
Dylan Jeannin e6d059bc19 correction erreur identifiant bdd 2026-04-28 11:06:57 +02:00
Dylan Jeannin cc500ceccf debug model InitialConditionsAdisTSSpec 2026-04-28 11:06:57 +02:00
Theophile Terraz 6bd3605d10 update doc links 2026-04-28 10:13:43 +02:00
Theophile Terraz 6c6da90952 debug QSO export 2026-04-28 10:09:49 +02:00
19 changed files with 2753 additions and 2649 deletions

View File

@ -157,12 +157,12 @@
%%
%% FIXME: Delete me for the first realease
\usepackage{draftwatermark}
\SetWatermarkLightness{0.8}
\SetWatermarkAngle{25}
\SetWatermarkScale{3}
\SetWatermarkFontSize{1cm}
\SetWatermarkText{Work in progress}
%% \usepackage{draftwatermark}
%% \SetWatermarkLightness{0.8}
%% \SetWatermarkAngle{25}
%% \SetWatermarkScale{3}
%% \SetWatermarkFontSize{1cm}
%% \SetWatermarkText{Work in progress}
%% Icons

View File

@ -514,6 +514,42 @@ class BoundaryCondition(SQLSubModel):
self._sigma = float(value)
self.modified()
@property
def d50(self):
return self._d50
@d50.setter
def d50(self, value):
self._d50 = float(value)
self.modified()
@property
def sigma(self):
return self._sigma
@sigma.setter
def sigma(self, value):
self._sigma = float(value)
self.modified()
@property
def d50(self):
return self._d50
@d50.setter
def d50(self, value):
self._d50 = float(value)
self.modified()
@property
def sigma(self):
return self._sigma
@sigma.setter
def sigma(self, value):
self._sigma = float(value)
self.modified()
@property
def header(self):
return self._header.copy()

View File

@ -71,7 +71,7 @@ class Data(SQLSubModel):
major, minor, release = version.strip().split(".")
created = False
if major == "0" and int(minor) <= 1:
if major == "0" and minor == "0":
if int(release) < 7:
cls._db_create(execute)
created = True
@ -249,7 +249,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
major, minor, release = version.strip().split(".")
created = False
if major == "0" and int(minor) <= 1:
if major == "0" and minor == "0":
if int(release) < 7:
cls._db_create(execute)
created = True

View File

@ -274,6 +274,9 @@ class HydraulicStructure(SQLSubModel):
return hs
def _db_save(self, execute, data=None):
if not self.must_be_saved():
return True
execute(
"DELETE FROM hydraulic_structures " +
f"WHERE pamhyr_id = {self.pamhyr_id} " +

View File

@ -225,6 +225,8 @@ class Data(SQLSubModel):
return new
def _db_save(self, execute, data=None):
if not self.must_be_saved():
return True
ind = data["ind"]
execute(
@ -396,7 +398,7 @@ class InitialConditions(SQLSubModel):
@reach.setter
def reach(self, new):
self._reach = reach
self._reach = new
self.modified()
@property

View File

@ -147,9 +147,9 @@ class Data(SQLSubModel):
it = iter(v)
pid = next(it)
delete = next(it)
data0 = bc._types[0](next(it))
data1 = bc._types[1](next(it))
deleted = next(it)
data0 = lc._types[0](next(it))
data1 = lc._types[1](next(it))
owner_scenario = next(it)
nd = cls(

View File

@ -278,8 +278,10 @@ class PollutantCharacteristics(SQLSubModel):
class Pollutants(SQLSubModel):
_sub_classes = [PollutantCharacteristics,
BoundaryConditionAdisTS]
_sub_classes = [
PollutantCharacteristics,
# BoundaryConditionAdisTS
]
def __init__(self, id: int = -1, name: str = "",
status=None, owner_scenario=-1):
@ -400,7 +402,7 @@ class Pollutants(SQLSubModel):
return new
table = execute(
"SELECT pamhyr_id, deleted, name FROM pollutants " +
"SELECT pamhyr_id, deleted, name, scenario FROM pollutants " +
f"WHERE scenario = {scenario.id} " +
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
)
@ -412,10 +414,12 @@ class Pollutants(SQLSubModel):
pid = next(it)
deleted = (next(it) == 1)
name = next(it)
owner_scenario = next(it)
new_pollutant = cls(
id=pid, name=name,
status=status
status=status,
owner_scenario=owner_scenario
)
if deleted:
new_pollutant.set_as_deleted()

View File

@ -180,6 +180,9 @@ class RiverNode(Node):
return nodes
def _db_save(self, execute, data=None):
if not self.must_be_saved():
return True
execute(
"INSERT OR REPLACE INTO river_node(" +
"pamhyr_id, deleted, name, x, y, scenario" +
@ -361,7 +364,7 @@ class RiverReach(Edge):
)
new.enable(enable=enabled)
if deleted:
nd.set_as_deleted()
new.set_as_deleted()
data["reach"] = new
new._reach = Reach._db_load(execute, data)
@ -377,6 +380,9 @@ class RiverReach(Edge):
return reachs
def _db_save(self, execute, data=None):
if not self.must_be_saved():
return True
execute(
"INSERT OR REPLACE INTO " +
"river_reach(" +
@ -386,7 +392,7 @@ class RiverReach(Edge):
"VALUES (" +
f"{self.pamhyr_id}, {self._db_format(self.is_deleted())}, " +
f"'{self._db_format(self._name)}', " +
f"{self._db_format(self.is_enable())},"
f"{self._db_format(self.is_enable())}," +
f"{self.node1.pamhyr_id}, {self.node2.pamhyr_id}, " +
f"{self._status.scenario_id}" +
")"
@ -543,7 +549,7 @@ class River(Graph):
new._nodes = RiverNode._db_load(
execute, data
)
data["nodes"] = new.nodes()
data["nodes"] = new._nodes
data['loaded_pid'] = set()
new._edges = RiverReach._db_load(

View File

@ -17,16 +17,51 @@
# -*- coding: utf-8 -*-
import os
import logging
from tools import logger_exception
from Model.Tools.PamhyrDB import SQLSubModel
logger = logging.getLogger()
class Scenario(SQLSubModel):
_id_cnt = 0
_sub_classes = []
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_data",
"d90_adists", "d90_adists_spec",
"dif_adists_spec",
"pollutants", "pollutants_characteristics",
# Hydraulic
"additional_files",
"boundary_condition", "boundary_condition_data",
"lateral_contribution", "lateral_contribution_data",
"friction", "stricklers",
"hydraulic_structures",
"hydraulic_structures_basic",
"initial_conditions",
"sedimentary_layer", "sedimentary_layer_layer",
"reservoir", "reservoir_data",
"rep_lines",
"geometry_pointXYZ", "geometry_profileXYZ",
"river_reach", "river_node",
"geotiff", "reservoir", "reservoir_data",
]
related_tables = tables_with_deleted_column + [
"dif_adists",
"solver_parameter",
"hydraulic_structures_basic_value",
"results", "results_data", "results_add_data",
]
def __init__(self,
id: int = -1,
name: str = "",
@ -171,29 +206,7 @@ class Scenario(SQLSubModel):
def drop_all(self, execute):
execute(f"DELETE FROM scenario WHERE id = {self.id}")
tables = [
# Adists
"output_rk_adists",
"boundary_condition_adists", "boundary_condition_data_adists",
"lateral_contribution_adists", "lateral_contribution_data_adists",
"initial_conditions_adists",
"d90_adists", "dif_adists",
"pollutants", "pollutants_characteristics",
# Hydraulic
"additional_files",
"boundary_condition", "boundary_condition_data",
"lateral_contribution", "lateral_contribution_data",
"friction", "stricklers",
"hydraulic_structures",
"hydraulic_structures_basic", "hydraulic_structures_basic_value",
"initial_conditions",
"sedimentary_layer", "sedimentary_layer_layer",
"reservoir", "reservoir_data",
"rep_lines",
"solver_parameter",
"geometry_pointXYZ", "geometry_profileXYZ",
"river_reach", "river_node",
]
tables = self.related_tables
for table in tables:
execute(
@ -203,6 +216,58 @@ class Scenario(SQLSubModel):
return True
def get_parent_branch(self):
def aux(scenario, acc):
if scenario is None:
return acc
return aux(scenario.parent, [scenario.id] + acc)
return aux(self, [])
def drop_deleted_data(self, execute):
tables = self.tables_with_deleted_column
branch = self.get_parent_branch()
for table in tables:
if self.parent is None:
# This scenario is the default scenario, so we can
# delete all data marked as deleted
execute(
f"DELETE FROM {table} " +
f"WHERE scenario = {self.id} " +
"AND deleted = TRUE"
)
continue
# Select pamhyr_id for each deleted data in this scenario
# who do not exists into parents scenarios
ids = execute(
f"""
SELECT pamhyr_id FROM {table}
WHERE deleted = TRUE
AND scenario = {self.id}
AND pamhyr_id NOT IN (
SELECT pamhyr_id FROM {table}
WHERE scenario IN
({', '.join(map(str, branch[:-1]))})
)
""", fetch_one=False
)
if ids is None or len(ids) == 0:
continue
logger.debug(
f"(s{self.id}) Drop deleted data into '{table}' : {ids}"
)
execute(
f"DELETE FROM {table} " +
f"WHERE scenario = {self.id} " +
"AND pamhyr_id IN " +
f"({', '.join(map(lambda x: str(x[0]), ids))})"
)
@property
def id(self):
return self._id

View File

@ -449,6 +449,13 @@ class Study(SQLModel):
[self.scenarios, self._river],
data=progress
)
# Clear DB for each scenarios
for scenar in self.scenarios.lst:
scenar.drop_deleted_data(self.execute)
progress()
self.commit()
def sql_save_request_count(self, *args, **kargs):
@ -459,7 +466,7 @@ class Study(SQLModel):
[self.scenarios, self._river]
)
logger.debug(cnt)
return cnt + 7
return cnt + 8
def close(self):
"""Close db connection
@ -518,7 +525,8 @@ class Study(SQLModel):
data["study"] = self
river._db_load_results(sql_exec, data=data)
self._river_scenario_cache[scenario] = river
# FIXME: Disable scenario cache to save memory usage
# self._river_scenario_cache[scenario] = river
self.status.scenario = old_scenario
return river

View File

@ -793,6 +793,7 @@ class AdisTSwc(AdisTS):
for file_bin in path_files:
key_pol = os.path.basename(file_bin)[0:-4]
data_tmp[key_pol] = {}
logger.info(f"read_bin: Start reading '{file_bin}' ...")
with open(file_bin, 'rb') as f:
# header
# first line
@ -844,7 +845,9 @@ class AdisTSwc(AdisTS):
# seventh line (useless)
for k in range(0, ismax, kbl):
data = np.fromfile(f, dtype=np.int32, count=1) # (start)
zero = np.fromfile(f, dtype=np.int32, count=ismax)
zero = np.fromfile(
f, dtype=np.int32, count=min(k + kbl, ismax) - k
)
data = np.fromfile(f, dtype=np.int32, count=1) # (end)
# end header
# data
@ -875,7 +878,6 @@ class AdisTSwc(AdisTS):
for r, reach in enumerate(reachs):
for i in range(is1[r]-1, is2[r]):
p_i = ip_to_ri(reach, i)
for t_data in timestamps_keys:
pol_view = []
for pol in pollutants_keys:

View File

@ -19,6 +19,7 @@
import os
import logging
import numpy as np
import time
from functools import reduce
from itertools import chain
@ -326,7 +327,7 @@ class Mage(CommandLineSolver):
v0 = d[0]
v1 = d[1]
if t in ["HYD", "QSO", "LIM"]:
if t in ["HYD", "LIM"]:
v0 /= 60 # Convert first column to minute
f.write(f"{v0:9} {v1:9} \n")
@ -989,7 +990,7 @@ class Mage8(Mage):
# Data
for d in bound.data:
f.write(f"{d[0]:10.3f}{d[1]:10.3f}\n")
f.write(f"{d[0]/60:10.3f}{d[1]:10.3f}\n")
return files
@ -1036,6 +1037,7 @@ class Mage8(Mage):
@timer
def read_bin(self, study, fname, results, qlog=None, name="0"):
logger.info(f"read_bin: Start reading '{fname}' ...")
start = time.time()
with mage_file_open(fname, "r") as f:
def newline(): return np.fromfile(f, dtype=np.int32, count=1)
@ -1182,7 +1184,6 @@ class Mage8(Mage):
logger.info(f"compute tab...")
for r in reachs:
for p in r.profiles:
if not p.geometry.tab_up_to_date:
p.geometry.compute_tabulation()
logger.info(f"compute velocily...")
@ -1200,6 +1201,7 @@ class Mage8(Mage):
results.bufferize("Z")
results.bufferize("Q")
results.bufferize("V")
logger.info(f"reading time: '{time.time() - start}'")
@timer
def read_gra(self, study, repertory, results, qlog=None, name="0"):
@ -1208,6 +1210,7 @@ class Mage8(Mage):
fname = os.path.join(repertory, f"{name}.GRA")
logger.info(f"read_gra: Start reading '{fname}' ...")
start = time.time()
with mage_file_open(fname, "r") as f:
def newline(): return np.fromfile(f, dtype=np.int32, count=1)
@ -1403,6 +1406,7 @@ class Mage8(Mage):
results.set("sediment_timestamps", ts)
logger.info(f"read_gra: ... end with {len(ts)} timestamp read")
logger.debug(f"reading time: '{time.time() - start}'")
@timer
def results(self, study, repertory,

View File

@ -55,7 +55,7 @@ class AboutWindow(PamhyrDialog):
label = self.get_label_text("label_version")
label = label.replace("@version", version)
label = label.replace("@codename", "(Adis-TS)")
label = label.replace("@codename", "")
self.set_label_text("label_version", label)
# Authors

View File

@ -19,6 +19,8 @@
from View.Tools.PamhyrWindow import PamhyrDialog
from PyQt5.QtWidgets import QDoubleSpinBox
from View.Tools.FlexibleDoubleSpinBox import FlexibleDoubleSpinBox
from PyQt5.QtWidgets import QDoubleSpinBox
from View.Tools.FlexibleDoubleSpinBox import FlexibleDoubleSpinBox
class ShiftDialog(PamhyrDialog):

View File

@ -173,7 +173,7 @@ class InitialConditionTableModel(PamhyrTableModel):
def add(self, row, parent=QModelIndex()):
self.beginInsertRows(parent, row, row - 1)
row = self.get_true_data_row(row)
# row = self.get_true_data_row(row)
self._undo.push(
AddCommand(

View File

@ -156,7 +156,7 @@ class DelCommand(QUndoCommand):
el.set_as_not_deleted()
def redo(self):
for el in self._bc:
for el in self._lc:
el.set_as_deleted()

View File

@ -23,7 +23,6 @@ from PyQt5.QtWidgets import QDoubleSpinBox
class FlexibleDoubleSpinBox(QDoubleSpinBox):
def keyPressEvent(self, event):
if event.text() == ".":
# Simule une virgule à la place du point

View File

@ -225,7 +225,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;a href=&quot;https://gitlab.irstea.fr/theophile.terraz/pamhyr&quot;&gt;Source code&lt;/a&gt;</string>
<string>&lt;a href=&quot;https://gitlab.com/pamhyr/pamhyr2&quot;&gt;Source code&lt;/a&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>

File diff suppressed because it is too large Load Diff