mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Compare commits
262
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5327c29641 | ||
|
|
be865102a8 | ||
|
|
37f1b43b93 | ||
|
|
16f0775783 | ||
|
|
f2c4285b4c | ||
|
|
ee95f0e89e | ||
|
|
1306977954 | ||
|
|
476fa81bc2 | ||
|
|
e8f1f0ac43 | ||
|
|
1adf24ce77 | ||
|
|
a61d130baa | ||
|
|
0a1760cee6 | ||
|
|
3e094af325 | ||
|
|
762e4d70a0 | ||
|
|
6c4f863b96 | ||
|
|
b87f82f74d | ||
|
|
ffad53a331 | ||
|
|
662a218e41 | ||
|
|
0501ae9bec | ||
|
|
7fd38eec00 | ||
|
|
4bab4580ad | ||
|
|
21d2e6ad20 | ||
|
|
d0a8f369ef | ||
|
|
fef2e1a40c | ||
|
|
20c2cb7ea4 | ||
|
|
64a26e987e | ||
|
|
eb233847de | ||
|
|
7bb810d427 | ||
|
|
e49724072b | ||
|
|
3664ba93e9 | ||
|
|
a9903e987b | ||
|
|
f9a88a211c | ||
|
|
32535af3e6 | ||
|
|
fa8948c1b6 | ||
|
|
2d5455c09d | ||
|
|
83680bbe57 | ||
|
|
1d1a00a0ff | ||
|
|
ffd95b9fdf | ||
|
|
ecb2544cab | ||
|
|
9c66021b53 | ||
|
|
8255fc3c1b | ||
|
|
32e7413aad | ||
|
|
d87db5fd48 | ||
|
|
388368adad | ||
|
|
4d014d5a1d | ||
|
|
181a6c226f | ||
|
|
1975ed7eaa | ||
|
|
565a7530fb | ||
|
|
32cbc6bc3e | ||
|
|
7d7a05c04c | ||
|
|
6ac268b668 | ||
|
|
19c72892a8 | ||
|
|
9717968e08 | ||
|
|
e19c3229bd | ||
|
|
b3c6f1031b | ||
|
|
c2d93b4a4a | ||
|
|
76430322dd | ||
|
|
31ae0ab8e0 | ||
|
|
8182d434ec | ||
|
|
da78d0cdb1 | ||
|
|
850db144ac | ||
|
|
0f6709075f | ||
|
|
e86b84b0b9 | ||
|
|
e08d212986 | ||
|
|
7b88d955e5 | ||
|
|
d1c34fb437 | ||
|
|
611f9cdfa3 | ||
|
|
bd2fc22e96 | ||
|
|
efa16837d8 | ||
|
|
db7aad26fd | ||
|
|
229b3da2d1 | ||
|
|
48d6728e1e | ||
|
|
c51c06e6ec | ||
|
|
a425c9a6ac | ||
|
|
e79ae8ebf5 | ||
|
|
e3020d15ba | ||
|
|
83e0ecbdc7 | ||
|
|
3087023caa | ||
|
|
7e080767da | ||
|
|
44c3a91d72 | ||
|
|
26dc7d8761 | ||
|
|
e573fa4197 | ||
|
|
7aa0cf4361 | ||
|
|
c3faf45f75 | ||
|
|
fb8b5aa77f | ||
|
|
8183a284af | ||
|
|
09997a0074 | ||
|
|
c44597dfbd | ||
|
|
b1632eaea5 | ||
|
|
a2461af084 | ||
|
|
5c366839f3 | ||
|
|
311df46a2c | ||
|
|
a235f61044 | ||
|
|
0b80b86d31 | ||
|
|
0c7ede5f43 | ||
|
|
445c1ac7ba | ||
|
|
c687e05d8f | ||
|
|
5fb6fecc24 | ||
|
|
3dfbdc328e | ||
|
|
97d87f2455 | ||
|
|
a78be47e2b | ||
|
|
eed2ce4243 | ||
|
|
78ba7b70b4 | ||
|
|
f86cd4602c | ||
|
|
ee28afac86 | ||
|
|
81ff6372e9 | ||
|
|
61156f1c3e | ||
|
|
e26b170b05 | ||
|
|
ddbaa0fb94 | ||
|
|
64d2b2678a | ||
|
|
3a3b5ea2dd | ||
|
|
7cb3ac8a80 | ||
|
|
190ca5d171 | ||
|
|
5d8ec51417 | ||
|
|
d922436ada | ||
|
|
4537a829af | ||
|
|
363b9c7132 | ||
|
|
f9d83ac68c | ||
|
|
63b5cbaba7 | ||
|
|
1989914aef | ||
|
|
2c0b155baf | ||
|
|
4d20c2457a | ||
|
|
2dd9003721 | ||
|
|
94ceb44fd4 | ||
|
|
ab50d2adf4 | ||
|
|
0eb979256f | ||
|
|
5ce94a63d3 | ||
|
|
42ea50d62e | ||
|
|
0df4cf0fd5 | ||
|
|
ccf3da114b | ||
|
|
348417977d | ||
|
|
914a1f8866 | ||
|
|
cbbbeeac0b | ||
|
|
c9ea726bfb | ||
|
|
fa88e05d91 | ||
|
|
a6915020cb | ||
|
|
ea2287215e | ||
|
|
e940dead70 | ||
|
|
b6a6d54a22 | ||
|
|
11a95cb391 | ||
|
|
084c22836b | ||
|
|
726b81bf12 | ||
|
|
7c3de520d9 | ||
|
|
b450796df5 | ||
|
|
b1daadf9f2 | ||
|
|
c38e3ee446 | ||
|
|
606b9919e3 | ||
|
|
e3de7e7100 | ||
|
|
92fae0e13f | ||
|
|
a8b260ad38 | ||
|
|
faff877c80 | ||
|
|
0a0eeb3c3f | ||
|
|
cdcbbc2cf4 | ||
|
|
7565d8ee95 | ||
|
|
11e1302e05 | ||
|
|
99cb2883a1 | ||
|
|
e61dede7f8 | ||
|
|
cb4dfab482 | ||
|
|
377c508038 | ||
|
|
30e34b6847 | ||
|
|
102702e1df | ||
|
|
c014f0ef34 | ||
|
|
e615a6b9d4 | ||
|
|
f1dca727c6 | ||
|
|
2db1f4c7f7 | ||
|
|
b3d631943c | ||
|
|
b6895ae99c | ||
|
|
9f26a7323c | ||
|
|
2a7e322ee5 | ||
|
|
13a44264ac | ||
|
|
6165719829 | ||
|
|
51dd6d27c5 | ||
|
|
cea4dcd9cb | ||
|
|
e1c1f411c3 | ||
|
|
4550fc95d7 | ||
|
|
1f97af9c03 | ||
|
|
df9e1ec42d | ||
|
|
ac79fae1fb | ||
|
|
fe39f07981 | ||
|
|
b578e0c50c | ||
|
|
4408a8f368 | ||
|
|
d3e922af6e | ||
|
|
8adf878584 | ||
|
|
aa6973813f | ||
|
|
e21a64fcad | ||
|
|
8b6308d3c9 | ||
|
|
bc3ea9c4b9 | ||
|
|
04ea55e21a | ||
|
|
a68270ff67 | ||
|
|
c498ed2d96 | ||
|
|
e6d059bc19 | ||
|
|
cc500ceccf | ||
|
|
7a91969f41 | ||
|
|
6bd3605d10 | ||
|
|
6c6da90952 | ||
|
|
539b63f765 | ||
|
|
e755459004 | ||
|
|
a8f95e2386 | ||
|
|
55b200a48e | ||
|
|
6b8d7c2df2 | ||
|
|
eb7c4895ca | ||
|
|
a060dbd461 | ||
|
|
9379f7a27d | ||
|
|
19fedc2278 | ||
|
|
260efc17a9 | ||
|
|
a4026d6386 | ||
|
|
d6f7755d12 | ||
|
|
00b89635f3 | ||
|
|
f54dc07432 | ||
|
|
3bbc55b4be | ||
|
|
b58d3e005d | ||
|
|
870bb41ff7 | ||
|
|
0701531d37 | ||
|
|
43eb486700 | ||
|
|
82eeb9a478 | ||
|
|
432c263cdf | ||
|
|
c2d28b0110 | ||
|
|
23361d142e | ||
|
|
63836527c7 | ||
|
|
4f6e8249e0 | ||
|
|
ab2f775b95 | ||
|
|
bb0e176956 | ||
|
|
c0d4aced5e | ||
|
|
4ed865759a | ||
|
|
70e09d3b3a | ||
|
|
2bcfa4d121 | ||
|
|
5b497d61f0 | ||
|
|
242df7f648 | ||
|
|
421e6797f6 | ||
|
|
0886956ec8 | ||
|
|
9670bde56f | ||
|
|
3277cf551b | ||
|
|
ad5cc831a3 | ||
|
|
b00cca953e | ||
|
|
1f35020e3f | ||
|
|
7ef41ad886 | ||
|
|
ada396f26d | ||
|
|
674247db09 | ||
|
|
5fecd29666 | ||
|
|
71e1324a0f | ||
|
|
07cae542b0 | ||
|
|
b693f67b99 | ||
|
|
18a3d51d75 | ||
|
|
118a39bd5c | ||
|
|
2009e8223b | ||
|
|
bdaa38ea5c | ||
|
|
713732b1dd | ||
|
|
f053539cdd | ||
|
|
fc6916bb3e | ||
|
|
97c26cb4fb | ||
|
|
10c98bb96e | ||
|
|
7c2d9891d0 | ||
|
|
3c3ac1f1df | ||
|
|
80af278a0f | ||
|
|
f254eaee25 | ||
|
|
5adb0bdee5 | ||
|
|
64c99d46d4 | ||
|
|
0f0defb36f | ||
|
|
1e1ee67d4b | ||
|
|
5bc514c565 | ||
|
|
1da3461dfe | ||
|
|
dd5eecb1e2 |
No files matched your search
+3
-3
@@ -186,7 +186,7 @@ unittest:
|
|||||||
- pip3 install -r ./full-requirements.txt
|
- pip3 install -r ./full-requirements.txt
|
||||||
- pip3 install -U -r ./full-requirements.txt
|
- pip3 install -U -r ./full-requirements.txt
|
||||||
- cd src
|
- cd src
|
||||||
- python3 -m unittest discover -t .
|
- python3.12 -m unittest discover -t .
|
||||||
|
|
||||||
test-pep8:
|
test-pep8:
|
||||||
stage: test
|
stage: test
|
||||||
@@ -638,7 +638,7 @@ shadow-release:
|
|||||||
- job: pkg-hash
|
- job: pkg-hash
|
||||||
artifacts: true
|
artifacts: true
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_BRANCH != 'master' && $CI_COMMIT_TAG
|
- if: $CI_COMMIT_TAG && $CI_COMMIT_TAG !~ /^v/
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- linux/pamhyr-gnulinux.tar.xz
|
- linux/pamhyr-gnulinux.tar.xz
|
||||||
@@ -672,7 +672,7 @@ tag-release:
|
|||||||
- job: pkg-hash
|
- job: pkg-hash
|
||||||
artifacts: true
|
artifacts: true
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_BRANCH == 'master' && $CI_COMMIT_TAG
|
- if: $CI_COMMIT_TAG =~ /^v/
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- linux/pamhyr-gnulinux.tar.xz
|
- linux/pamhyr-gnulinux.tar.xz
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
Sylvain COULIBALY, INRAE, 2020 - 2022
|
Sylvain COULIBALY, INRAE, 2020 - 2022
|
||||||
Théophile TERRAZ, INRAE, 2022 - 2024
|
Théophile TERRAZ, INRAE, 2022 - 2024
|
||||||
Pierre-Antoine ROUBY, INRAE, 2023 - 2025
|
Pierre-Antoine ROUBY, INRAE, 2023 - 2026
|
||||||
|
Dylan JEANNIN, INRAE, 2026
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
Pamhyr is a free and open source graphical user interface for 1D hydro-sedimentary
|
Pamhyr is a free and open source graphical user interface for 1D hydro-sedimentary
|
||||||
modelling of rivers.
|
modelling of rivers.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@@ -21,9 +21,9 @@ modelling of rivers.
|
|||||||
+ Create and edit study alternative scenario tree
|
+ Create and edit study alternative scenario tree
|
||||||
|
|
||||||
Let see the
|
Let see the
|
||||||
[documentation](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home)
|
[documentation](https://gitlab.com/pamhyr/pamhyr2/-/wikis/home)
|
||||||
([:fr:](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home-fr),
|
([:fr:](https://gitlab.com/pamhyr/pamhyr2/-/wikis/home-fr),
|
||||||
[:gb:](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home-en))
|
[:gb:](https://gitlab.com/pamhyr/pamhyr2/-/wikis/home-en))
|
||||||
for more details.
|
for more details.
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
@@ -31,11 +31,11 @@ for more details.
|
|||||||
### GNU/Linux
|
### GNU/Linux
|
||||||
|
|
||||||
See documentation:
|
See documentation:
|
||||||
- [French :fr:](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home/fr/Install%20on%20GNULinux)
|
- [French :fr:](https://gitlab.com/pamhyr/pamhyr2/-/wikis/home/fr/Install%20on%20GNULinux)
|
||||||
- [English :gb:](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home/en/Install%20on%20GNULinux)
|
- [English :gb:](https://gitlab.com/pamhyr/pamhyr2/-/wikis/home/en/Install%20on%20GNULinux)
|
||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
See documentation:
|
See documentation:
|
||||||
- [French :fr:](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home/fr/Install%20on%20Windows)
|
- [French :fr:](https://gitlab.com/pamhyr/pamhyr2/-/wikis/home/fr/Install%20on%20Windows)
|
||||||
- [English :gb:](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home/en/Install%20on%20Windows)
|
- [English :gb:](https://gitlab.com/pamhyr/pamhyr2/-/wikis/home/en/Install%20on%20Windows)
|
||||||
@@ -157,12 +157,12 @@
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
%% FIXME: Delete me for the first realease
|
%% FIXME: Delete me for the first realease
|
||||||
\usepackage{draftwatermark}
|
%% \usepackage{draftwatermark}
|
||||||
\SetWatermarkLightness{0.8}
|
%% \SetWatermarkLightness{0.8}
|
||||||
\SetWatermarkAngle{25}
|
%% \SetWatermarkAngle{25}
|
||||||
\SetWatermarkScale{3}
|
%% \SetWatermarkScale{3}
|
||||||
\SetWatermarkFontSize{1cm}
|
%% \SetWatermarkFontSize{1cm}
|
||||||
\SetWatermarkText{Work in progress}
|
%% \SetWatermarkText{Work in progress}
|
||||||
|
|
||||||
%% Icons
|
%% Icons
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -14,3 +14,4 @@ platformdirs>=4.2.0
|
|||||||
pyshp>=2.3.1
|
pyshp>=2.3.1
|
||||||
rasterio==1.3.11
|
rasterio==1.3.11
|
||||||
#fortranformat==2.0.3
|
#fortranformat==2.0.3
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# Adists.py -- Pamhyr study checkers
|
# Adists.py -- Pamhyr study checkers
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Checker.py -- Pamhyr abstract checker class
|
# Checker.py -- Pamhyr abstract checker class
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
# Mage.py -- Pamhyr MAGE checkers
|
# Mage.py -- Pamhyr MAGE checkers
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Study.py -- Pamhyr study checkers
|
# Study.py -- Pamhyr study checkers
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# AMeshingTool.py -- Pamhyr
|
# AMeshingTool.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Internal.py -- Pamhyr
|
# Internal.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -66,7 +66,6 @@ class InternalMeshing(AMeshingTool):
|
|||||||
return new_profiles
|
return new_profiles
|
||||||
|
|
||||||
def st_to_m(self, profiles, guide_list):
|
def st_to_m(self, profiles, guide_list):
|
||||||
|
|
||||||
guide_list = ["un"] + guide_list + ["np"]
|
guide_list = ["un"] + guide_list + ["np"]
|
||||||
max_values = [0] * (len(guide_list) - 1)
|
max_values = [0] * (len(guide_list) - 1)
|
||||||
max_values_index = [0] * (len(guide_list) - 1)
|
max_values_index = [0] * (len(guide_list) - 1)
|
||||||
@@ -85,11 +84,13 @@ class InternalMeshing(AMeshingTool):
|
|||||||
profiles[isect+1],
|
profiles[isect+1],
|
||||||
guide_list[i],
|
guide_list[i],
|
||||||
guide_list[i+1])
|
guide_list[i+1])
|
||||||
|
|
||||||
for isect in reversed(range(0, max_values_index[i])):
|
for isect in reversed(range(0, max_values_index[i])):
|
||||||
self.compl_sect(profiles[isect+1],
|
self.compl_sect(profiles[isect+1],
|
||||||
profiles[isect],
|
profiles[isect],
|
||||||
guide_list[i],
|
guide_list[i],
|
||||||
guide_list[i+1])
|
guide_list[i+1])
|
||||||
|
|
||||||
return profiles
|
return profiles
|
||||||
|
|
||||||
def interpolate_transversal_step(self,
|
def interpolate_transversal_step(self,
|
||||||
@@ -129,6 +130,7 @@ class InternalMeshing(AMeshingTool):
|
|||||||
p.name = f'interpol{p.rk}'
|
p.name = f'interpol{p.rk}'
|
||||||
new_profiles2.append(p)
|
new_profiles2.append(p)
|
||||||
new_profiles.append(new_profiles2)
|
new_profiles.append(new_profiles2)
|
||||||
|
|
||||||
return new_profiles
|
return new_profiles
|
||||||
|
|
||||||
def compl_sect(self, sect1, sect2, tag1, tag2):
|
def compl_sect(self, sect1, sect2, tag1, tag2):
|
||||||
@@ -164,7 +166,6 @@ class InternalMeshing(AMeshingTool):
|
|||||||
for i in range(len1):
|
for i in range(len1):
|
||||||
ltot1 += sect1.point(start1+i).dist(sect1.point(start1+i+1))
|
ltot1 += sect1.point(start1+i).dist(sect1.point(start1+i+1))
|
||||||
alpha.append(ltot1)
|
alpha.append(ltot1)
|
||||||
alpha = list(map(lambda x: x/ltot1, alpha)) # target ratios
|
|
||||||
for i in range(len2):
|
for i in range(len2):
|
||||||
ltot2 += sect2.point(start2+i).dist(sect2.point(start2+i+1))
|
ltot2 += sect2.point(start2+i).dist(sect2.point(start2+i+1))
|
||||||
beta.append(ltot2)
|
beta.append(ltot2)
|
||||||
@@ -179,6 +180,7 @@ class InternalMeshing(AMeshingTool):
|
|||||||
sect2.add_npoints(len1-len2)
|
sect2.add_npoints(len1-len2)
|
||||||
len2 = len1
|
len2 = len1
|
||||||
else: # regular case
|
else: # regular case
|
||||||
|
alpha = list(map(lambda x: x/ltot1, alpha)) # target ratios
|
||||||
beta = list(map(lambda x: x/ltot2, beta)) # current ratios
|
beta = list(map(lambda x: x/ltot2, beta)) # current ratios
|
||||||
for i in range(len1 - len2):
|
for i in range(len1 - len2):
|
||||||
beta.append(1.0)
|
beta.append(1.0)
|
||||||
@@ -214,7 +216,7 @@ class InternalMeshing(AMeshingTool):
|
|||||||
ratio = (alpha[j0] - beta[j0-1]) \
|
ratio = (alpha[j0] - beta[j0-1]) \
|
||||||
/ (beta[j0] - beta[j0-1])
|
/ (beta[j0] - beta[j0-1])
|
||||||
if ratio < 0.0:
|
if ratio < 0.0:
|
||||||
print(f"ratio négatif {ratio}")
|
logger.warning(f"ratio négatif {ratio}")
|
||||||
# on double le point a gauche
|
# on double le point a gauche
|
||||||
p = sect2.point(start2+j0-1).copy()
|
p = sect2.point(start2+j0-1).copy()
|
||||||
sect2.insert_point(start2+j0-1, p)
|
sect2.insert_point(start2+j0-1, p)
|
||||||
@@ -243,8 +245,9 @@ class InternalMeshing(AMeshingTool):
|
|||||||
sect2.point(start2+len2).name = ''
|
sect2.point(start2+len2).name = ''
|
||||||
if tag1 != "un":
|
if tag1 != "un":
|
||||||
sect2.point(start2).name = tag1
|
sect2.point(start2).name = tag1
|
||||||
if tag1 != "np":
|
if tag2 != "np":
|
||||||
sect2.point(start2+len2).name = tag2
|
sect2.point(start2+len2).name = tag2
|
||||||
|
|
||||||
sect2.modified()
|
sect2.modified()
|
||||||
|
|
||||||
def update_rk(self, reach, begin_rk, end_rk,
|
def update_rk(self, reach, begin_rk, end_rk,
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
# Mage.py -- Pamhyr
|
# Mage.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# __init__.py -- Pamhyr
|
# __init__.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# test_Model.py -- Pamhyr
|
# test_Model.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# BoundaryCondition.py -- Pamhyr
|
# BoundaryCondition.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -232,6 +232,8 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
type TEXT NOT NULL,
|
type TEXT NOT NULL,
|
||||||
tab TEXT NOT NULL,
|
tab TEXT NOT NULL,
|
||||||
node INTEGER,
|
node INTEGER,
|
||||||
|
d50 REAL DEFAULT 0.002,
|
||||||
|
sigma REAL DEFAULT 1,
|
||||||
{Scenario.create_db_add_scenario()},
|
{Scenario.create_db_add_scenario()},
|
||||||
{Scenario.create_db_add_scenario_fk()},
|
{Scenario.create_db_add_scenario_fk()},
|
||||||
FOREIGN KEY(node) REFERENCES river_node(pamhyr_id),
|
FOREIGN KEY(node) REFERENCES river_node(pamhyr_id),
|
||||||
@@ -258,6 +260,17 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
|
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if major == "0" and int(minor) <= 2:
|
||||||
|
if int(release) < 4:
|
||||||
|
execute(
|
||||||
|
"ALTER TABLE boundary_condition " +
|
||||||
|
"ADD COLUMN d50 REAL DEFAULT 0.002"
|
||||||
|
)
|
||||||
|
execute(
|
||||||
|
"ALTER TABLE boundary_condition " +
|
||||||
|
"ADD COLUMN sigma REAL DEFAULT 1"
|
||||||
|
)
|
||||||
|
|
||||||
return cls._update_submodel(execute, version, data)
|
return cls._update_submodel(execute, version, data)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -316,7 +329,8 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
return new
|
return new
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, deleted, name, type, node, scenario " +
|
"SELECT pamhyr_id, deleted, name, type, node, d50, sigma, " +
|
||||||
|
"scenario " +
|
||||||
"FROM boundary_condition " +
|
"FROM boundary_condition " +
|
||||||
f"WHERE tab = '{tab}' " +
|
f"WHERE tab = '{tab}' " +
|
||||||
f"AND scenario = {scenario.id} " +
|
f"AND scenario = {scenario.id} " +
|
||||||
@@ -331,6 +345,8 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
name = next(it)
|
name = next(it)
|
||||||
t = next(it)
|
t = next(it)
|
||||||
node = next(it)
|
node = next(it)
|
||||||
|
d50 = next(it)
|
||||||
|
sigma = next(it)
|
||||||
owner_scenario = next(it)
|
owner_scenario = next(it)
|
||||||
|
|
||||||
ctor = cls._get_ctor_from_type(t)
|
ctor = cls._get_ctor_from_type(t)
|
||||||
@@ -340,9 +356,14 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
status=data['status'],
|
status=data['status'],
|
||||||
owner_scenario=owner_scenario
|
owner_scenario=owner_scenario
|
||||||
)
|
)
|
||||||
|
|
||||||
if deleted:
|
if deleted:
|
||||||
bc.set_as_deleted()
|
bc.set_as_deleted()
|
||||||
|
|
||||||
|
if t == "SL":
|
||||||
|
bc.d50 = d50
|
||||||
|
bc.sigma = sigma
|
||||||
|
|
||||||
bc.node = None
|
bc.node = None
|
||||||
if node != -1:
|
if node != -1:
|
||||||
bc.node = next(filter(lambda n: n.id == node, nodes), None)
|
bc.node = next(filter(lambda n: n.id == node, nodes), None)
|
||||||
@@ -375,15 +396,22 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
if self._node is not None:
|
if self._node is not None:
|
||||||
node = self._node.id
|
node = self._node.id
|
||||||
|
|
||||||
|
d50 = 0.002
|
||||||
|
sigma = 1
|
||||||
|
if self._type == "SL":
|
||||||
|
d50 = self._d50
|
||||||
|
sigma = self._sigma
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"boundary_condition(" +
|
"boundary_condition(" +
|
||||||
"pamhyr_id, deleted, name, type, tab, node, scenario" +
|
"pamhyr_id, deleted, name, type, tab, node, d50, sigma, scenario" +
|
||||||
") " +
|
") " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self._pamhyr_id}, {self._db_format(self.is_deleted())}, " +
|
f"{self._pamhyr_id}, {self._db_format(self.is_deleted())}, " +
|
||||||
f"'{self._db_format(self._name)}', " +
|
f"'{self._db_format(self._name)}', " +
|
||||||
f"'{self._db_format(self._type)}', '{tab}', {node}, " +
|
f"'{self._db_format(self._type)}', '{tab}', {node}, " +
|
||||||
|
f"{d50}, {sigma}, " +
|
||||||
f"{self._status.scenario_id}" +
|
f"{self._status.scenario_id}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
@@ -468,6 +496,24 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
def has_node(self):
|
def has_node(self):
|
||||||
return self._node is not None
|
return self._node is not None
|
||||||
|
|
||||||
|
@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
|
@property
|
||||||
def header(self):
|
def header(self):
|
||||||
return self._header.copy()
|
return self._header.copy()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# BoundaryConditionList.py -- Pamhyr
|
# BoundaryConditionList.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# BoundaryConditionTypes.py -- Pamhyr
|
# BoundaryConditionTypes.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# BoundaryConditionsAdisTS.py -- Pamhyr
|
# BoundaryConditionsAdisTS.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -70,9 +70,8 @@ class Data(SQLSubModel):
|
|||||||
def _db_update(cls, execute, version, data=None):
|
def _db_update(cls, execute, version, data=None):
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
created = False
|
created = False
|
||||||
|
if major == "0" and minor == "0":
|
||||||
if major == "0" and int(minor) <= 1:
|
if int(release) < 11:
|
||||||
if int(release) < 7:
|
|
||||||
cls._db_create(execute)
|
cls._db_create(execute)
|
||||||
created = True
|
created = True
|
||||||
|
|
||||||
@@ -143,8 +142,9 @@ class Data(SQLSubModel):
|
|||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, deleted, data0, data1, scenario FROM " +
|
"SELECT pamhyr_id, deleted, data0, data1, scenario FROM " +
|
||||||
"boundary_condition_data_adists " +
|
"boundary_condition_data_adists " +
|
||||||
f"WHERE bca = {bca.id} " +
|
f"WHERE scenario = {scenario.id} " +
|
||||||
f"AND scenario = {scenario.id}"
|
# f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
|
||||||
|
f"AND bca = {bca.id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if table is not None:
|
if table is not None:
|
||||||
@@ -187,8 +187,9 @@ class Data(SQLSubModel):
|
|||||||
execute(
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"boundary_condition_data_adists(" +
|
"boundary_condition_data_adists(" +
|
||||||
"pamhyr_id, data0, data1, bca, scenario) " +
|
"pamhyr_id, deleted, data0, data1, bca, scenario) " +
|
||||||
f"VALUES ({self.id}, '{data0}', {data1}, {bca.id}, " +
|
f"VALUES ({self.id}, {self._db_format(self.is_deleted())}, " +
|
||||||
|
f"'{data0}', {data1}, {bca.id}, " +
|
||||||
f"{self._status.scenario_id})"
|
f"{self._status.scenario_id})"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -247,15 +248,13 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
created = False
|
created = False
|
||||||
|
|
||||||
if major == "0" and int(minor) <= 1:
|
if major == "0" and int(minor) < 2:
|
||||||
if int(release) < 7:
|
if cls.is_table_exists(execute, "boundary_condition_adists"):
|
||||||
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
else:
|
||||||
cls._db_create(execute)
|
cls._db_create(execute)
|
||||||
created = True
|
created = True
|
||||||
|
|
||||||
if major == "0" and int(minor) < 2:
|
|
||||||
if not created:
|
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
|
||||||
|
|
||||||
if not created:
|
if not created:
|
||||||
return cls._update_submodel(execute, version, data)
|
return cls._update_submodel(execute, version, data)
|
||||||
|
|
||||||
@@ -300,6 +299,14 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||||||
if pol_id == -1:
|
if pol_id == -1:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if pol_id not in pid_pol:
|
||||||
|
# ⚠️ cas important : probablement déjà migré
|
||||||
|
logger.warning(
|
||||||
|
f"pol_id {pol_id} not in pid_pol " +
|
||||||
|
"→ probably already migrated"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
f"UPDATE boundary_condition_adists " +
|
f"UPDATE boundary_condition_adists " +
|
||||||
f"SET pollutant = {pid_pol[pol_id]} " +
|
f"SET pollutant = {pid_pol[pol_id]} " +
|
||||||
@@ -312,17 +319,21 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||||||
status = data['status']
|
status = data['status']
|
||||||
nodes = data['nodes']
|
nodes = data['nodes']
|
||||||
scenario = data["scenario"]
|
scenario = data["scenario"]
|
||||||
|
pollutant = data.get("pollutant")
|
||||||
loaded = data['loaded_pid']
|
loaded = data['loaded_pid']
|
||||||
|
|
||||||
if scenario is None:
|
if scenario is None:
|
||||||
return new
|
return new
|
||||||
|
|
||||||
table = execute(
|
sql = (
|
||||||
"SELECT pamhyr_id, deleted, pollutant, type, node, scenario " +
|
"SELECT pamhyr_id, deleted, pollutant, type, node, scenario "
|
||||||
"FROM boundary_condition_adists " +
|
"FROM boundary_condition_adists " +
|
||||||
f"WHERE scenario = {scenario.id} " +
|
f"WHERE scenario = {scenario.id} "
|
||||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
|
||||||
)
|
)
|
||||||
|
if pollutant is not None:
|
||||||
|
sql += f"AND pollutant = {pollutant.id} "
|
||||||
|
|
||||||
|
table = execute(sql)
|
||||||
|
|
||||||
if table is not None:
|
if table is not None:
|
||||||
for row in table:
|
for row in table:
|
||||||
@@ -347,7 +358,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||||||
bc.type = bc_type
|
bc.type = bc_type
|
||||||
|
|
||||||
bc.node = None
|
bc.node = None
|
||||||
if row[3] != -1:
|
if node != -1:
|
||||||
tmp = next(
|
tmp = next(
|
||||||
filter(
|
filter(
|
||||||
lambda n: n.id == node, nodes
|
lambda n: n.id == node, nodes
|
||||||
@@ -426,7 +437,14 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||||||
d._data_traversal(predicate, modifier, data)
|
d._data_traversal(predicate, modifier, data)
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._data)
|
return len(
|
||||||
|
list(
|
||||||
|
filter(
|
||||||
|
lambda el: el is not None and not el.is_deleted(),
|
||||||
|
self._data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def time_convert(cls, data):
|
def time_convert(cls, data):
|
||||||
@@ -451,7 +469,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||||||
@node.setter
|
@node.setter
|
||||||
def node(self, node):
|
def node(self, node):
|
||||||
self._node = node
|
self._node = node
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def header(self):
|
def header(self):
|
||||||
@@ -460,7 +478,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||||||
@header.setter
|
@header.setter
|
||||||
def header(self, header):
|
def header(self, header):
|
||||||
self._header = header
|
self._header = header
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pollutant(self):
|
def pollutant(self):
|
||||||
@@ -469,7 +487,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||||||
@pollutant.setter
|
@pollutant.setter
|
||||||
def pollutant(self, pollutant):
|
def pollutant(self, pollutant):
|
||||||
self._pollutant = pollutant
|
self._pollutant = pollutant
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self):
|
def type(self):
|
||||||
@@ -478,11 +496,16 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||||||
@type.setter
|
@type.setter
|
||||||
def type(self, type):
|
def type(self, type):
|
||||||
self._type = type
|
self._type = type
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def data(self):
|
def data(self):
|
||||||
return self._data.copy()
|
return list(
|
||||||
|
filter(
|
||||||
|
lambda el: el is not None and not el.is_deleted(),
|
||||||
|
self._data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _default_0(self):
|
def _default_0(self):
|
||||||
@@ -511,33 +534,36 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||||||
return (new_0, new_1)
|
return (new_0, new_1)
|
||||||
|
|
||||||
def add(self, index: int):
|
def add(self, index: int):
|
||||||
value = (self._default_0, self._default_1)
|
value = Data(
|
||||||
|
self._default_0, self._default_1,
|
||||||
|
status=self._status
|
||||||
|
)
|
||||||
self._data.insert(index, value)
|
self._data.insert(index, value)
|
||||||
self._status.modified()
|
self.modified()
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def insert(self, index: int, value):
|
def insert(self, index: int, value):
|
||||||
self._data.insert(index, value)
|
self._data.insert(index, value)
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
def delete_i(self, indexes):
|
def delete_i(self, indexes):
|
||||||
self._data = list(
|
list(
|
||||||
map(
|
map(
|
||||||
lambda e: e[1],
|
lambda e: e[1].set_as_deleted(),
|
||||||
filter(
|
filter(
|
||||||
lambda e: e[0] not in indexes,
|
lambda e: e[0] in indexes,
|
||||||
enumerate(self.data)
|
enumerate(self.data)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
def sort(self, _reverse=False, key=None):
|
def sort(self, _reverse=False, key=None):
|
||||||
if key is None:
|
if key is None:
|
||||||
self._data.sort(reverse=_reverse)
|
self._data.sort(reverse=_reverse)
|
||||||
else:
|
else:
|
||||||
self._data.sort(reverse=_reverse, key=key)
|
self._data.sort(reverse=_reverse, key=key)
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
def index(self, bc):
|
def index(self, bc):
|
||||||
self._data.index(bc)
|
self._data.index(bc)
|
||||||
@@ -552,10 +578,10 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||||||
return lst
|
return lst
|
||||||
|
|
||||||
def _set_i_c_v(self, index, column, value):
|
def _set_i_c_v(self, index, column, value):
|
||||||
v = list(self._data[index])
|
v = self._data[index]
|
||||||
v[column] = self._types[column](value)
|
v[column] = self._types[column](value)
|
||||||
self._data[index] = tuple(v)
|
self._data[index] = v
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
def set_i_0(self, index: int, value):
|
def set_i_0(self, index: int, value):
|
||||||
self._set_i_c_v(index, 0, value)
|
self._set_i_c_v(index, 0, value)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# BoundaryConditionsAdisTSList.py -- Pamhyr
|
# BoundaryConditionsAdisTSList.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -38,9 +38,13 @@ class BoundaryConditionsAdisTSList(PamhyrModelList):
|
|||||||
if data is None:
|
if data is None:
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
new._lst = BoundaryConditionAdisTS._db_load(
|
previous_pollutant = data.get("pollutant")
|
||||||
execute, data
|
data.pop("pollutant", None)
|
||||||
)
|
|
||||||
|
new._lst = BoundaryConditionAdisTS._db_load(execute, data)
|
||||||
|
|
||||||
|
if previous_pollutant is not None:
|
||||||
|
data["pollutant"] = previous_pollutant
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# D90AdisTS.py -- Pamhyr
|
# D90AdisTS.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -73,15 +73,13 @@ class D90AdisTS(SQLSubModel):
|
|||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
created = False
|
created = False
|
||||||
|
|
||||||
if major == "0" and int(minor) <= 1:
|
if major == "0" and int(minor) < 2:
|
||||||
if int(release) < 6:
|
if cls.is_table_exists(execute, "d90_adists"):
|
||||||
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
else:
|
||||||
cls._db_create(execute)
|
cls._db_create(execute)
|
||||||
created = True
|
created = True
|
||||||
|
|
||||||
if major == "0" and int(minor) < 2:
|
|
||||||
if not created:
|
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
|
||||||
|
|
||||||
if not created:
|
if not created:
|
||||||
return cls._update_submodel(execute, version, data)
|
return cls._update_submodel(execute, version, data)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# D90AdisTSList.py -- Pamhyr
|
# D90AdisTSList.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# D90AdisTSSpec.py -- Pamhyr
|
# D90AdisTSSpec.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -70,16 +70,12 @@ class D90AdisTSSpec(SQLSubModel):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def _db_update(cls, execute, version, data=None):
|
def _db_update(cls, execute, version, data=None):
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
created = False
|
|
||||||
|
|
||||||
if major == 0 and minor < 1:
|
|
||||||
if int(release) < 6:
|
|
||||||
cls._db_create(execute)
|
|
||||||
created = True
|
|
||||||
|
|
||||||
if major == "0" and int(minor) < 2:
|
if major == "0" and int(minor) < 2:
|
||||||
if not created:
|
if cls.is_table_exists(execute, "d90_spec"):
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
else:
|
||||||
|
cls._db_create(execute)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -87,6 +83,7 @@ class D90AdisTSSpec(SQLSubModel):
|
|||||||
def _db_update_to_0_2_0(cls, execute, data):
|
def _db_update_to_0_2_0(cls, execute, data):
|
||||||
table = "d90_spec"
|
table = "d90_spec"
|
||||||
table_new = "d90_adists_spec"
|
table_new = "d90_adists_spec"
|
||||||
|
reachs = data['id2pid']['river_reach']
|
||||||
|
|
||||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||||
Scenario.update_db_add_scenario(execute, table)
|
Scenario.update_db_add_scenario(execute, table)
|
||||||
@@ -95,8 +92,10 @@ class D90AdisTSSpec(SQLSubModel):
|
|||||||
|
|
||||||
execute(
|
execute(
|
||||||
f"INSERT INTO {table_new}_tmp " +
|
f"INSERT INTO {table_new}_tmp " +
|
||||||
"(pamhyr_id, name, d90, enabled, scenario) " +
|
"(pamhyr_id, d90_default, name, reach, " +
|
||||||
"SELECT pamhyr_id, name, d90, enabled, scenario " +
|
" start_rk, end_rk, d90, enabled, scenario) " +
|
||||||
|
"SELECT pamhyr_id, d90_default, name, reach, " +
|
||||||
|
" start_rk, end_rk, d90, enabled, scenario " +
|
||||||
f"FROM {table}"
|
f"FROM {table}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -104,12 +103,13 @@ class D90AdisTSSpec(SQLSubModel):
|
|||||||
execute(f"ALTER TABLE {table_new}_tmp RENAME TO {table_new}")
|
execute(f"ALTER TABLE {table_new}_tmp RENAME TO {table_new}")
|
||||||
|
|
||||||
cls._db_update_to_0_2_0_set_d90_pid(execute, data)
|
cls._db_update_to_0_2_0_set_d90_pid(execute, data)
|
||||||
|
cls._db_update_to_0_2_0_set_reach_pid(execute, table_new, reachs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_update_to_0_2_0_set_d90_pid(cls, execute, data):
|
def _db_update_to_0_2_0_set_d90_pid(cls, execute, data):
|
||||||
pid_d90 = data["id2pid"]["d90_adists"]
|
pid_d90 = data["id2pid"]["d90_adists"]
|
||||||
els = execute(
|
els = execute(
|
||||||
f"SELECT pamhyr_id, d90 FROM d90_adists_spec"
|
f"SELECT pamhyr_id, d90_default FROM d90_adists_spec"
|
||||||
)
|
)
|
||||||
|
|
||||||
for row in els:
|
for row in els:
|
||||||
@@ -121,8 +121,8 @@ class D90AdisTSSpec(SQLSubModel):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
f"UPDATE d90_adists_spec" +
|
f"UPDATE d90_adists_spec " +
|
||||||
f"SET d90 = {pid_d90[d90_id]} " +
|
f"SET d90_default = {pid_d90[d90_id]} " +
|
||||||
f"WHERE pamhyr_id = {pid}"
|
f"WHERE pamhyr_id = {pid}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ class D90AdisTSSpec(SQLSubModel):
|
|||||||
owner_scenario=owner_scenario
|
owner_scenario=owner_scenario
|
||||||
)
|
)
|
||||||
if deleted:
|
if deleted:
|
||||||
new_spec.is_deleted()
|
new_spec.set_as_deleted()
|
||||||
|
|
||||||
new_spec.reach = reach
|
new_spec.reach = reach
|
||||||
new_spec.start_rk = start_rk
|
new_spec.start_rk = start_rk
|
||||||
@@ -196,12 +196,12 @@ class D90AdisTSSpec(SQLSubModel):
|
|||||||
"d90_default, name, reach, " +
|
"d90_default, name, reach, " +
|
||||||
"start_rk, end_rk, d90, enabled, scenario) " +
|
"start_rk, end_rk, d90, enabled, scenario) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {self._db_format(self.is_deleted())}" +
|
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||||
f"{d90_default}, " +
|
f"{d90_default}, " +
|
||||||
f"'{self._db_format(self._name_section)}', " +
|
f"'{self._db_format(self._name_section)}', " +
|
||||||
f"{self._reach}, " +
|
f"{self._reach}, " +
|
||||||
f"{self._start_rk}, {self._end_rk}, " +
|
f"{self._start_rk}, {self._end_rk}, " +
|
||||||
f"{self._d90}, {self._enabled}" +
|
f"{self._d90}, {self._enabled}, " +
|
||||||
f"{self._status.scenario_id}" +
|
f"{self._status.scenario_id}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# DIFAdisTS.py -- Pamhyr
|
# DIFAdisTS.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -79,15 +79,13 @@ class DIFAdisTS(SQLSubModel):
|
|||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
created = False
|
created = False
|
||||||
|
|
||||||
if major == "0" and int(minor) <= 1:
|
if major == "0" and int(minor) < 2:
|
||||||
if int(release) < 6:
|
if cls.is_table_exists(execute, "dif_adists"):
|
||||||
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
else:
|
||||||
cls._db_create(execute)
|
cls._db_create(execute)
|
||||||
created = True
|
created = True
|
||||||
|
|
||||||
if major == "0" and int(minor) < 2:
|
|
||||||
if not created:
|
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
|
||||||
|
|
||||||
if not created:
|
if not created:
|
||||||
return cls._update_submodel(execute, version, data)
|
return cls._update_submodel(execute, version, data)
|
||||||
|
|
||||||
@@ -142,24 +140,24 @@ class DIFAdisTS(SQLSubModel):
|
|||||||
enabled = (next(it) == 1)
|
enabled = (next(it) == 1)
|
||||||
owner_scenario = next(it)
|
owner_scenario = next(it)
|
||||||
|
|
||||||
dif = cls(
|
DIF = cls(
|
||||||
id=pid,
|
id=pid,
|
||||||
name=name,
|
name=name,
|
||||||
status=status,
|
status=status,
|
||||||
owner_scenario=owner_scenario,
|
owner_scenario=owner_scenario,
|
||||||
)
|
)
|
||||||
|
|
||||||
dif.method = method
|
DIF.method = method
|
||||||
dif.dif = dif
|
DIF.dif = dif
|
||||||
dif.b = b
|
DIF.b = b
|
||||||
dif.c = c
|
DIF.c = c
|
||||||
dif.enabled = enabled
|
DIF.enabled = enabled
|
||||||
|
|
||||||
data['dif_default_id'] = pid
|
data['dif_default_id'] = pid
|
||||||
dif._data = DIFAdisTSSpec._db_load(execute, data)
|
DIF._data = DIFAdisTSSpec._db_load(execute, data)
|
||||||
|
|
||||||
loaded.add(pid)
|
loaded.add(pid)
|
||||||
new.append(dif)
|
new.append(DIF)
|
||||||
|
|
||||||
data["scenario"] = scenario.parent
|
data["scenario"] = scenario.parent
|
||||||
new += cls._db_load(execute, data)
|
new += cls._db_load(execute, data)
|
||||||
@@ -190,7 +188,7 @@ class DIFAdisTS(SQLSubModel):
|
|||||||
b = self.b
|
b = self.b
|
||||||
|
|
||||||
c = -1.
|
c = -1.
|
||||||
if self.dif is not None:
|
if self.c is not None:
|
||||||
c = self.c
|
c = self.c
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
@@ -201,7 +199,7 @@ class DIFAdisTS(SQLSubModel):
|
|||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, '{self._db_format(self._name)}', " +
|
f"{self.id}, '{self._db_format(self._name)}', " +
|
||||||
f"'{self._db_format(self._method)}', " +
|
f"'{self._db_format(self._method)}', " +
|
||||||
f"{dif.id}, {b}, {c}, {self._enabled}, " +
|
f"{dif}, {b}, {c}, {self._enabled}, " +
|
||||||
f"{self._status.scenario_id}" +
|
f"{self._status.scenario_id}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# DIFAdisTSList.py -- Pamhyr
|
# DIFAdisTSList.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# DIFAdisTSSpec.py -- Pamhyr
|
# DIFAdisTSSpec.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -33,16 +33,14 @@ class DIFAdisTSSpec(SQLSubModel):
|
|||||||
_id_cnt = 0
|
_id_cnt = 0
|
||||||
|
|
||||||
def __init__(self, id: int = -1, method: str = "",
|
def __init__(self, id: int = -1, method: str = "",
|
||||||
status=None):
|
status=None, owner_scenario=-1):
|
||||||
super(DIFAdisTSSpec, self).__init__()
|
super(DIFAdisTSSpec, self).__init__(
|
||||||
|
id=id, status=status,
|
||||||
|
owner_scenario=owner_scenario
|
||||||
|
)
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
|
|
||||||
if id == -1:
|
|
||||||
self.id = DIFAdisTSSpec._id_cnt
|
|
||||||
else:
|
|
||||||
self.id = id
|
|
||||||
|
|
||||||
self._method = method
|
self._method = method
|
||||||
self._reach = None
|
self._reach = None
|
||||||
self._start_rk = None
|
self._start_rk = None
|
||||||
@@ -52,8 +50,6 @@ class DIFAdisTSSpec(SQLSubModel):
|
|||||||
self._c = None
|
self._c = None
|
||||||
self._enabled = True
|
self._enabled = True
|
||||||
|
|
||||||
DIFAdisTSSpec._id_cnt = max(DIFAdisTSSpec._id_cnt + 1, self.id)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_create(cls, execute, ext=""):
|
def _db_create(cls, execute, ext=""):
|
||||||
execute(f"""
|
execute(f"""
|
||||||
@@ -81,16 +77,12 @@ class DIFAdisTSSpec(SQLSubModel):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def _db_update(cls, execute, version, data=None):
|
def _db_update(cls, execute, version, data=None):
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
created = False
|
|
||||||
|
|
||||||
if major == 0 and minor < 1:
|
|
||||||
if int(release) < 6:
|
|
||||||
cls._db_create(execute)
|
|
||||||
created = True
|
|
||||||
|
|
||||||
if major == "0" and int(minor) < 2:
|
if major == "0" and int(minor) < 2:
|
||||||
if not created:
|
if cls.is_table_exists(execute, "dif_spec"):
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
else:
|
||||||
|
cls._db_create(execute)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -195,7 +187,7 @@ class DIFAdisTSSpec(SQLSubModel):
|
|||||||
new_spec.c = c
|
new_spec.c = c
|
||||||
new_spec.enabled = enabled
|
new_spec.enabled = enabled
|
||||||
|
|
||||||
loaded.add(pid)
|
loaded.add(id)
|
||||||
new.append(new_spec)
|
new.append(new_spec)
|
||||||
|
|
||||||
data["scenario"] = scenario.parent
|
data["scenario"] = scenario.parent
|
||||||
@@ -210,22 +202,23 @@ class DIFAdisTSSpec(SQLSubModel):
|
|||||||
|
|
||||||
dif_default = data['dif_default_id']
|
dif_default = data['dif_default_id']
|
||||||
|
|
||||||
execute(
|
sql = (
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"dif_adists_spec(pamhyr_id, deleted, " +
|
"dif_adists_spec(pamhyr_id, deleted, " +
|
||||||
"dif_default, method, reach, " +
|
"dif_default, method, reach, " +
|
||||||
"start_rk, end_rk, dif, b, c, enabled, scenario) " +
|
"start_rk, end_rk, dif, b, c, enabled, scenario) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {self._db_format(self.is_deleted())}" +
|
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||||
f"{dif_default}, " +
|
f"{dif_default}, " +
|
||||||
f"'{self._db_format(self._method)}', " +
|
f"'{self._db_format(self._method)}', " +
|
||||||
f"{self._reach}, " +
|
f"{self._reach}, " +
|
||||||
f"{self._start_rk}, {self._end_rk}, " +
|
f"{self._start_rk}, {self._end_rk}, " +
|
||||||
f"{self._dif}, {self._b}, {self._c}, " +
|
f"{self._dif}, {self._b}, {self._c}, " +
|
||||||
f"{self._enabled}" +
|
f"{self._enabled}, " +
|
||||||
f"{self._status.scenario_id}" +
|
f"{self._status.scenario_id}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
|
execute(sql)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
# Except.py -- Pamhyr model exceptions
|
# Except.py -- Pamhyr model exceptions
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Friction.py -- Pamhyr
|
# Friction.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -228,9 +228,10 @@ class Friction(SQLSubModel):
|
|||||||
ssi = self._status.scenario_id
|
ssi = self._status.scenario_id
|
||||||
|
|
||||||
return (
|
return (
|
||||||
self._begin_strickler._owner_scenario == ssi
|
self._begin_strickler is not None
|
||||||
|
and (self._begin_strickler._owner_scenario == ssi
|
||||||
# or self._end_strickler._owner_scenario == ssi
|
# or self._end_strickler._owner_scenario == ssi
|
||||||
or super(Friction, self).must_be_saved()
|
or super(Friction, self).must_be_saved())
|
||||||
)
|
)
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
@@ -364,3 +365,9 @@ class Friction(SQLSubModel):
|
|||||||
# self.end_strickler.medium])
|
# self.end_strickler.medium])
|
||||||
|
|
||||||
return minor, medium
|
return minor, medium
|
||||||
|
|
||||||
|
def update_rks(self, begin_rk, end_rk):
|
||||||
|
self._begin_rk = begin_rk
|
||||||
|
self._end_rk = end_rk
|
||||||
|
|
||||||
|
self.modified()
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# FrictionList.py -- Pamhyr
|
# FrictionList.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Point.py -- Pamhyr
|
# Point.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# PointXY.py -- Pamhyr
|
# PointXY.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# PointXYZ.py -- Pamhyr
|
# PointXYZ.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -66,6 +66,11 @@ class PointXYZ(Point):
|
|||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
execute(
|
||||||
|
"CREATE INDEX idx_point " +
|
||||||
|
"ON geometry_pointXYZ(profile, scenario);"
|
||||||
|
)
|
||||||
|
|
||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -90,6 +95,13 @@ class PointXYZ(Point):
|
|||||||
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
|
"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);"
|
||||||
|
)
|
||||||
|
|
||||||
return cls._update_submodel(execute, version, data)
|
return cls._update_submodel(execute, version, data)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -338,6 +350,13 @@ class PointXYZ(Point):
|
|||||||
self._z = float(value)
|
self._z = float(value)
|
||||||
self.modified()
|
self.modified()
|
||||||
|
|
||||||
|
def shift(self, x, y, z):
|
||||||
|
self.x += x
|
||||||
|
self.y += y
|
||||||
|
self.z += z
|
||||||
|
|
||||||
|
self.modified()
|
||||||
|
|
||||||
def get_coordinate(self):
|
def get_coordinate(self):
|
||||||
return (self._x, self._y, self._z)
|
return (self._x, self._y, self._z)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Profile.py -- Pamhyr
|
# Profile.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# ProfileXYZ.py -- Pamhyr
|
# ProfileXYZ.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -24,7 +24,7 @@ from typing import List
|
|||||||
from functools import reduce
|
from functools import reduce
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from tools import timer, flatten
|
from tools import trace, timer, flatten
|
||||||
from shapely import geometry
|
from shapely import geometry
|
||||||
|
|
||||||
from Model.Tools.PamhyrDB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
@@ -91,6 +91,9 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
self._station = []
|
self._station = []
|
||||||
self.station_up_to_date = False
|
self.station_up_to_date = False
|
||||||
|
|
||||||
|
self._get_water_limits_cache = {}
|
||||||
|
self._get_water_limits_ac_cache = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_create(cls, execute, ext=""):
|
def _db_create(cls, execute, ext=""):
|
||||||
execute(f"""
|
execute(f"""
|
||||||
@@ -396,7 +399,6 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
|
|
||||||
for point in self._points:
|
for point in self._points:
|
||||||
p = point.copy()
|
p = point.copy()
|
||||||
print(p)
|
|
||||||
new_p._points.append(p)
|
new_p._points.append(p)
|
||||||
|
|
||||||
new_p.modified()
|
new_p.modified()
|
||||||
@@ -620,6 +622,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
"""
|
"""
|
||||||
return [x for x in lst if not np.isnan(x)]
|
return [x for x in lst if not np.isnan(x)]
|
||||||
|
|
||||||
|
@timer
|
||||||
def speed(self, q, z):
|
def speed(self, q, z):
|
||||||
area = self.wet_area(z)
|
area = self.wet_area(z)
|
||||||
|
|
||||||
@@ -671,6 +674,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
length += line.length
|
length += line.length
|
||||||
return length
|
return length
|
||||||
|
|
||||||
|
@timer
|
||||||
def compute_wet_area(self, z):
|
def compute_wet_area(self, z):
|
||||||
area = 0.0
|
area = 0.0
|
||||||
if len(self.tab.L) > 0:
|
if len(self.tab.L) > 0:
|
||||||
@@ -711,6 +715,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
if len(line.coords) > 2:
|
if len(line.coords) > 2:
|
||||||
poly = geometry.Polygon(line)
|
poly = geometry.Polygon(line)
|
||||||
area += poly.area
|
area += poly.area
|
||||||
|
|
||||||
return area
|
return area
|
||||||
|
|
||||||
def wet_radius(self, z):
|
def wet_radius(self, z):
|
||||||
@@ -733,6 +738,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
line = geometry.LineString(list(zip(station, zz)))
|
line = geometry.LineString(list(zip(station, zz)))
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
@timer
|
||||||
def wet_lines(self, z):
|
def wet_lines(self, z):
|
||||||
points = self._points
|
points = self._points
|
||||||
if len(points) < 3:
|
if len(points) < 3:
|
||||||
@@ -809,7 +815,6 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
return points
|
return points
|
||||||
|
|
||||||
def get_nb_wet_areas(self, z):
|
def get_nb_wet_areas(self, z):
|
||||||
|
|
||||||
n_zones = 0
|
n_zones = 0
|
||||||
points = self._points
|
points = self._points
|
||||||
if points[0].z <= z:
|
if points[0].z <= z:
|
||||||
@@ -821,10 +826,13 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
|
|
||||||
return n_zones
|
return n_zones
|
||||||
|
|
||||||
|
@timer
|
||||||
def get_all_water_limits_ac(self, z):
|
def get_all_water_limits_ac(self, z):
|
||||||
"""
|
"""
|
||||||
Determine all water limits for z elevation.
|
Determine all water limits for z elevation.
|
||||||
"""
|
"""
|
||||||
|
if z in self._get_water_limits_ac_cache:
|
||||||
|
return self._get_water_limits_ac_cache[z]
|
||||||
|
|
||||||
points = self._points
|
points = self._points
|
||||||
if len(points) < 3:
|
if len(points) < 3:
|
||||||
@@ -857,69 +865,94 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
logger.error(f"ERROR in get_all_water_limits_ac")
|
logger.error(f"ERROR in get_all_water_limits_ac")
|
||||||
return [], []
|
return [], []
|
||||||
|
|
||||||
return start, list(reversed(end))
|
res = start, list(reversed(end))
|
||||||
|
self._get_water_limits_ac_cache[z] = res
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
@timer
|
||||||
def get_water_limits(self, z):
|
def get_water_limits(self, z):
|
||||||
|
if z in self._get_water_limits_cache:
|
||||||
|
return self._get_water_limits_cache[z]
|
||||||
|
|
||||||
|
v = self.get_water_limits_compute(z)
|
||||||
|
|
||||||
|
return v
|
||||||
|
|
||||||
|
def get_water_limits_compute(self, z):
|
||||||
"""
|
"""
|
||||||
Determine left and right limits of water elevation.
|
Determine left and right limits of water elevation.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Get the index of first point with elevation lesser than water
|
# Get the index of first point with elevation lesser than water
|
||||||
# elevation (for the right and left river side)
|
# elevation (for the right and left river side)
|
||||||
i_left = -1
|
i_left = next(
|
||||||
i_right = -1
|
filter(
|
||||||
|
lambda i: self.point(i).z <= z,
|
||||||
|
range(self.number_points)
|
||||||
|
),
|
||||||
|
-1
|
||||||
|
)
|
||||||
|
|
||||||
for i in range(self.number_points):
|
i_right = next(
|
||||||
if self.point(i).z <= z:
|
filter(
|
||||||
i_left = i
|
lambda i: self.point(i).z <= z,
|
||||||
break
|
reversed(range(self.number_points))
|
||||||
|
),
|
||||||
for i in reversed(range(self.number_points)):
|
-1
|
||||||
if self.point(i).z <= z:
|
)
|
||||||
i_right = i
|
|
||||||
break
|
|
||||||
|
|
||||||
# Interpolate points at river left side
|
# Interpolate points at river left side
|
||||||
if (i_left > 0):
|
if (i_left > 0):
|
||||||
if abs(self.point(i_left - 1).z - self.point(i_left).z) < 1e-20:
|
pi = self.point(i_left)
|
||||||
pt_left = self.point(i_left)
|
pim1 = self.point(i_left - 1)
|
||||||
|
|
||||||
|
if abs(pim1.z - pi.z) < 1e-20:
|
||||||
|
pt_left = pi
|
||||||
else:
|
else:
|
||||||
fact = (z - self.point(i_left).z) / \
|
fact = (z - pi.z) / (pim1.z - pi.z)
|
||||||
(self.point(i_left - 1).z - self.point(i_left).z)
|
x = pi.x + fact * (pim1.x - pi.x)
|
||||||
x = self.point(i_left).x + fact * \
|
y = pi.y + fact * (pim1.y - pi.y)
|
||||||
(self.point(i_left - 1).x - self.point(i_left).x)
|
|
||||||
y = self.point(i_left).y + fact * \
|
|
||||||
(self.point(i_left - 1).y - self.point(i_left).y)
|
|
||||||
pt_left = PointXYZ(x=x, y=y, z=z, name="wl_left")
|
pt_left = PointXYZ(x=x, y=y, z=z, name="wl_left")
|
||||||
else:
|
else:
|
||||||
pt_left = self.point(0)
|
pt_left = self.point(0)
|
||||||
|
|
||||||
# Interpolate points at river right side
|
# Interpolate points at river right side
|
||||||
if (i_right < self.number_points - 1):
|
if (i_right < self.number_points - 1):
|
||||||
if abs(self.point(i_right + 1).z - self.point(i_right).z) < 1e-20:
|
pi = self.point(i_right)
|
||||||
pt_right = self.point(i_right)
|
pip1 = self.point(i_right + 1)
|
||||||
|
|
||||||
|
if abs(pip1.z - pi.z) < 1e-20:
|
||||||
|
pt_right = pi
|
||||||
else:
|
else:
|
||||||
fact = (z - self.point(i_right).z) / \
|
fact = (z - pi.z) / (pip1.z - pi.z)
|
||||||
(self.point(i_right + 1).z - self.point(i_right).z)
|
x = pi.x + fact * (pip1.x - pi.x)
|
||||||
x = self.point(i_right).x + fact * \
|
y = pi.y + fact * (pip1.y - pi.y)
|
||||||
(self.point(i_right + 1).x - self.point(i_right).x)
|
|
||||||
y = self.point(i_right).y + fact * \
|
|
||||||
(self.point(i_right + 1).y - self.point(i_right).y)
|
|
||||||
pt_right = PointXYZ(x=x, y=y, z=z, name="wl_right")
|
pt_right = PointXYZ(x=x, y=y, z=z, name="wl_right")
|
||||||
else:
|
else:
|
||||||
pt_right = self.point(self.number_points - 1)
|
pt_right = self.point(self.number_points - 1)
|
||||||
|
|
||||||
return pt_left, pt_right
|
v = (pt_left, pt_right)
|
||||||
|
|
||||||
|
# Put results in cache
|
||||||
|
self._get_water_limits_cache[z] = v
|
||||||
|
|
||||||
|
# Create a generator to improve results data reading speed
|
||||||
|
yield v
|
||||||
|
|
||||||
|
@timer
|
||||||
def compute_tabulation(self):
|
def compute_tabulation(self):
|
||||||
sorted_points = sorted(self._points, key=lambda p: p.z)
|
sorted_points = sorted(self._points, key=lambda p: p.z)
|
||||||
|
|
||||||
self.tab.z = np.array([p.z for p in sorted_points], np.float64)
|
self.tab.z = np.array([p.z for p in sorted_points], np.float64)
|
||||||
self.tab.L = np.zeros(len(self.tab.z), np.float64)
|
self.tab.L = np.zeros(len(self.tab.z), np.float64)
|
||||||
self.tab.A = np.zeros(len(self.tab.z), np.float64)
|
self.tab.A = np.zeros(len(self.tab.z), np.float64)
|
||||||
|
|
||||||
for i in range(1, len(self.tab.z)):
|
for i in range(1, len(self.tab.z)):
|
||||||
self.tab.L[i] = self.compute_wet_width(self.tab.z[i])
|
self.tab.L[i] = self.compute_wet_width(self.tab.z[i])
|
||||||
|
|
||||||
dx = (self.tab.L[i] + self.tab.L[i-1])/2
|
dx = (self.tab.L[i] + self.tab.L[i-1])/2
|
||||||
dz = self.tab.z[i] - self.tab.z[i-1]
|
dz = self.tab.z[i] - self.tab.z[i-1]
|
||||||
|
|
||||||
self.tab.A[i] = self.tab.A[i-1] + dz * dx
|
self.tab.A[i] = self.tab.A[i-1] + dz * dx
|
||||||
|
|
||||||
self.tab_up_to_date = True
|
self.tab_up_to_date = True
|
||||||
@@ -1074,16 +1107,10 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
|
|
||||||
def shift(self, x, y, z):
|
def shift(self, x, y, z):
|
||||||
for p in self._points:
|
for p in self._points:
|
||||||
p.x = p.x + x
|
p.shift(x, y, z)
|
||||||
p.y = p.y + y
|
|
||||||
p.z = p.z + z
|
|
||||||
|
|
||||||
self.modified()
|
self.modified()
|
||||||
|
|
||||||
def modified(self):
|
|
||||||
self.tab_up_to_date = False
|
|
||||||
self.station_up_to_date = False
|
|
||||||
|
|
||||||
def add_npoints(self, npoints):
|
def add_npoints(self, npoints):
|
||||||
# add npoints in a profile
|
# add npoints in a profile
|
||||||
for k in range(npoints):
|
for k in range(npoints):
|
||||||
@@ -1105,6 +1132,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
rk=self.rk,
|
rk=self.rk,
|
||||||
reach=self.reach,
|
reach=self.reach,
|
||||||
status=self._status)
|
status=self._status)
|
||||||
|
|
||||||
for i, k in enumerate(self.points):
|
for i, k in enumerate(self.points):
|
||||||
p.insert_point(i, k.copy())
|
p.insert_point(i, k.copy())
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Reach.py -- Pamhyr
|
# Reach.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -52,6 +52,11 @@ class Reach(SQLSubModel):
|
|||||||
self._guidelines_is_valid = False
|
self._guidelines_is_valid = False
|
||||||
self._guidelines = {}
|
self._guidelines = {}
|
||||||
|
|
||||||
|
super(Reach, self).__init__(
|
||||||
|
id=parent.pamhyr_id,
|
||||||
|
status=status,
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pamhyr_id(self):
|
def pamhyr_id(self):
|
||||||
return self._parent.pamhyr_id
|
return self._parent.pamhyr_id
|
||||||
@@ -60,6 +65,10 @@ class Reach(SQLSubModel):
|
|||||||
def _pamhyr_id(self):
|
def _pamhyr_id(self):
|
||||||
return self._parent.pamhyr_id
|
return self._parent.pamhyr_id
|
||||||
|
|
||||||
|
@_pamhyr_id.setter
|
||||||
|
def _pamhyr_id(self, id):
|
||||||
|
return
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
@@ -103,6 +112,9 @@ class Reach(SQLSubModel):
|
|||||||
predicate=lambda obj, data: True,
|
predicate=lambda obj, data: True,
|
||||||
modifier=lambda obj, data: None,
|
modifier=lambda obj, data: None,
|
||||||
data={}):
|
data={}):
|
||||||
|
if predicate(self, data):
|
||||||
|
modifier(self, data)
|
||||||
|
|
||||||
for p in self._profiles:
|
for p in self._profiles:
|
||||||
p._data_traversal(predicate, modifier, data)
|
p._data_traversal(predicate, modifier, data)
|
||||||
|
|
||||||
@@ -199,13 +211,12 @@ class Reach(SQLSubModel):
|
|||||||
else:
|
else:
|
||||||
gi = self.get_global_profil_index(index)
|
gi = self.get_global_profil_index(index)
|
||||||
profile.num = gi
|
profile.num = gi
|
||||||
print(f"gi = {gi}")
|
|
||||||
self._profiles.insert(gi, profile)
|
self._profiles.insert(gi, profile)
|
||||||
|
|
||||||
self.modified()
|
self.modified()
|
||||||
|
|
||||||
def delete(self, indexes):
|
def delete(self, indexes):
|
||||||
"""Delete some elements in profile list
|
"""Set some elements as deleted in profile list
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
indexes: The list of index to delete
|
indexes: The list of index to delete
|
||||||
@@ -247,7 +258,7 @@ class Reach(SQLSubModel):
|
|||||||
self.modified()
|
self.modified()
|
||||||
|
|
||||||
def delete_profiles(self, profiles):
|
def delete_profiles(self, profiles):
|
||||||
"""Delete some elements in profile list
|
"""Set profiles list as deleted
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
profiles: The list of profile to delete
|
profiles: The list of profile to delete
|
||||||
@@ -956,3 +967,9 @@ class Reach(SQLSubModel):
|
|||||||
break
|
break
|
||||||
|
|
||||||
return global_index
|
return global_index
|
||||||
|
|
||||||
|
def update_rks(self, rks):
|
||||||
|
for rk, profile in zip(rks, self.profiles):
|
||||||
|
profile.rk = rk
|
||||||
|
|
||||||
|
self.modified()
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# Vector_1d.py -- Pamhyr
|
# Vector_1d.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# HydraulicStructures.py -- Pamhyr
|
# HydraulicStructures.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -183,7 +183,6 @@ class BasicHS(SQLSubModel):
|
|||||||
bhs._data = BHSValue._db_load(
|
bhs._data = BHSValue._db_load(
|
||||||
execute, data
|
execute, data
|
||||||
)
|
)
|
||||||
print(f"{bhs_pid} : {deleted}")
|
|
||||||
if deleted:
|
if deleted:
|
||||||
bhs.set_as_deleted()
|
bhs.set_as_deleted()
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Types.py -- Pamhyr
|
# Types.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Value.py -- Pamhyr
|
# Value.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# HydraulicStructures.py -- Pamhyr
|
# HydraulicStructures.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -274,6 +274,9 @@ class HydraulicStructure(SQLSubModel):
|
|||||||
return hs
|
return hs
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
|
if not self.must_be_saved():
|
||||||
|
return True
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"DELETE FROM hydraulic_structures " +
|
"DELETE FROM hydraulic_structures " +
|
||||||
f"WHERE pamhyr_id = {self.pamhyr_id} " +
|
f"WHERE pamhyr_id = {self.pamhyr_id} " +
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# HydraulicStructuresList.py -- Pamhyr
|
# HydraulicStructuresList.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# InitialConditions.py -- Pamhyr
|
# InitialConditions.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -225,6 +225,8 @@ class Data(SQLSubModel):
|
|||||||
return new
|
return new
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
|
if not self.must_be_saved():
|
||||||
|
return True
|
||||||
ind = data["ind"]
|
ind = data["ind"]
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
@@ -396,7 +398,7 @@ class InitialConditions(SQLSubModel):
|
|||||||
|
|
||||||
@reach.setter
|
@reach.setter
|
||||||
def reach(self, new):
|
def reach(self, new):
|
||||||
self._reach = reach
|
self._reach = new
|
||||||
self.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -586,8 +588,6 @@ class InitialConditions(SQLSubModel):
|
|||||||
for data in self._data:
|
for data in self._data:
|
||||||
data_height[data["rk"].rk] = data["height"]
|
data_height[data["rk"].rk] = data["height"]
|
||||||
|
|
||||||
print(data_height)
|
|
||||||
|
|
||||||
incline = self._reach.reach.get_incline_median_mean()
|
incline = self._reach.reach.get_incline_median_mean()
|
||||||
logger.debug(f"incline = {incline}")
|
logger.debug(f"incline = {incline}")
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# InitialConditionsDict.py -- Pamhyr
|
# InitialConditionsDict.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# InitialConditionsAdisTS.py -- Pamhyr
|
# InitialConditionsAdisTS.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -79,16 +79,12 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def _db_update(cls, execute, version, data=None):
|
def _db_update(cls, execute, version, data=None):
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
created = False
|
|
||||||
|
|
||||||
if major == "0" and int(minor) <= 1:
|
|
||||||
if int(release) < 6:
|
|
||||||
cls._db_create(execute)
|
|
||||||
created = True
|
|
||||||
|
|
||||||
if major == "0" and int(minor) < 2:
|
if major == "0" and int(minor) < 2:
|
||||||
if not created:
|
if cls.is_table_exists(execute, "initial_conditions_adists"):
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
else:
|
||||||
|
cls._db_create(execute)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -267,7 +263,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||||||
@name.setter
|
@name.setter
|
||||||
def name(self, name):
|
def name(self, name):
|
||||||
self._name = name
|
self._name = name
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pollutant(self):
|
def pollutant(self):
|
||||||
@@ -276,7 +272,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||||||
@pollutant.setter
|
@pollutant.setter
|
||||||
def pollutant(self, pollutant):
|
def pollutant(self, pollutant):
|
||||||
self._pollutant = pollutant
|
self._pollutant = pollutant
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def concentration(self):
|
def concentration(self):
|
||||||
@@ -285,7 +281,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||||||
@concentration.setter
|
@concentration.setter
|
||||||
def concentration(self, concentration):
|
def concentration(self, concentration):
|
||||||
self._concentration = concentration
|
self._concentration = concentration
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def eg(self):
|
def eg(self):
|
||||||
@@ -294,7 +290,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||||||
@eg.setter
|
@eg.setter
|
||||||
def eg(self, eg):
|
def eg(self, eg):
|
||||||
self._eg = eg
|
self._eg = eg
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def em(self):
|
def em(self):
|
||||||
@@ -303,7 +299,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||||||
@em.setter
|
@em.setter
|
||||||
def em(self, em):
|
def em(self, em):
|
||||||
self._em = em
|
self._em = em
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ed(self):
|
def ed(self):
|
||||||
@@ -312,7 +308,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||||||
@ed.setter
|
@ed.setter
|
||||||
def ed(self, ed):
|
def ed(self, ed):
|
||||||
self._ed = ed
|
self._ed = ed
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def enabled(self):
|
def enabled(self):
|
||||||
@@ -321,28 +317,45 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||||||
@enabled.setter
|
@enabled.setter
|
||||||
def enabled(self, enabled):
|
def enabled(self, enabled):
|
||||||
self._enabled = enabled
|
self._enabled = enabled
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
def new(self, index):
|
def new(self, index):
|
||||||
n = ICAdisTSSpec(status=self._status)
|
n = ICAdisTSSpec(status=self._status)
|
||||||
self._data.insert(index, n)
|
self._data.insert(index, n)
|
||||||
self._status.modified()
|
self.modified()
|
||||||
return n
|
return n
|
||||||
|
|
||||||
def delete(self, data):
|
def delete(self, data):
|
||||||
self._data = list(
|
list(
|
||||||
filter(
|
map(
|
||||||
lambda x: x not in data,
|
lambda x: x.set_as_deleted(),
|
||||||
self._data
|
data
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
def delete_i(self, indexes):
|
def delete_i(self, indexes):
|
||||||
for ind in indexes:
|
list(
|
||||||
del self._data[ind]
|
map(
|
||||||
self._status.modified()
|
lambda e: e[1].set_as_deleted(),
|
||||||
|
filter(
|
||||||
|
lambda e: e[0] in indexes,
|
||||||
|
enumerate(self._data)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.modified()
|
||||||
|
|
||||||
def insert(self, index, data):
|
def insert(self, index, data):
|
||||||
|
if data in self._data:
|
||||||
|
self.undelete([data])
|
||||||
|
else:
|
||||||
self._data.insert(index, data)
|
self._data.insert(index, data)
|
||||||
self._status.modified()
|
|
||||||
|
self.modified()
|
||||||
|
|
||||||
|
def undelete(self, lst):
|
||||||
|
for x in lst:
|
||||||
|
x.set_as_not_deleted()
|
||||||
|
|
||||||
|
self.modified()
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# InitialConditionsAdisTSList.py -- Pamhyr
|
# InitialConditionsAdisTSList.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# InitialConditionsAdisTSSpec.py -- Pamhyr
|
# InitialConditionsAdisTSSpec.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -31,7 +31,7 @@ class ICAdisTSSpec(SQLSubModel):
|
|||||||
_sub_classes = []
|
_sub_classes = []
|
||||||
|
|
||||||
def __init__(self, id: int = -1, name: str = "",
|
def __init__(self, id: int = -1, name: str = "",
|
||||||
status=None):
|
status=None, owner_scenario=None):
|
||||||
super(ICAdisTSSpec, self).__init__()
|
super(ICAdisTSSpec, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
@@ -77,16 +77,12 @@ class ICAdisTSSpec(SQLSubModel):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def _db_update(cls, execute, version, data=None):
|
def _db_update(cls, execute, version, data=None):
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
created = False
|
|
||||||
|
|
||||||
if major == 0 and minor < 1:
|
|
||||||
if int(release) < 6:
|
|
||||||
cls._db_create(execute)
|
|
||||||
created = True
|
|
||||||
|
|
||||||
if major == "0" and int(minor) < 2:
|
if major == "0" and int(minor) < 2:
|
||||||
if not created:
|
if cls.is_table_exists(execute, "initial_conditions_adists_spec"):
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
else:
|
||||||
|
cls._db_create(execute)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -194,7 +190,7 @@ class ICAdisTSSpec(SQLSubModel):
|
|||||||
new_spec.rate = rate
|
new_spec.rate = rate
|
||||||
new_spec.enabled = enabled
|
new_spec.enabled = enabled
|
||||||
|
|
||||||
loaded.add(pid)
|
# loaded.add(pid)
|
||||||
new.append(new_spec)
|
new.append(new_spec)
|
||||||
|
|
||||||
data["scenario"] = scenario.parent
|
data["scenario"] = scenario.parent
|
||||||
@@ -211,7 +207,7 @@ class ICAdisTSSpec(SQLSubModel):
|
|||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"initial_conditions_adists_spec(id, deleted, " +
|
"initial_conditions_adists_spec(pamhyr_id, deleted, " +
|
||||||
"ic_default, name, reach, " +
|
"ic_default, name, reach, " +
|
||||||
"start_rk, end_rk, concentration, eg, em, ed, rate, " +
|
"start_rk, end_rk, concentration, eg, em, ed, rate, " +
|
||||||
"enabled, scenario) " +
|
"enabled, scenario) " +
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# LateralContribution.py -- Pamhyr
|
# LateralContribution.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -147,9 +147,9 @@ class Data(SQLSubModel):
|
|||||||
it = iter(v)
|
it = iter(v)
|
||||||
|
|
||||||
pid = next(it)
|
pid = next(it)
|
||||||
delete = next(it)
|
deleted = next(it)
|
||||||
data0 = bc._types[0](next(it))
|
data0 = lc._types[0](next(it))
|
||||||
data1 = bc._types[1](next(it))
|
data1 = lc._types[1](next(it))
|
||||||
owner_scenario = next(it)
|
owner_scenario = next(it)
|
||||||
|
|
||||||
nd = cls(
|
nd = cls(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# LateralContributionList.py -- Pamhyr
|
# LateralContributionList.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# LateralContributionTypes.py -- Pamhyr
|
# LateralContributionTypes.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# LateralContributionAdisTS.py -- Pamhyr
|
# LateralContributionAdisTS.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -69,14 +69,12 @@ class Data(SQLSubModel):
|
|||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
created = False
|
created = False
|
||||||
|
|
||||||
if major == "0" and int(minor) <= 1:
|
|
||||||
if int(release) < 7:
|
|
||||||
cls._db_create(execute)
|
|
||||||
created = True
|
|
||||||
|
|
||||||
if major == "0" and int(minor) < 2:
|
if major == "0" and int(minor) < 2:
|
||||||
if not created:
|
if cls.is_table_exists(
|
||||||
|
execute, "lateral_contribution_data_adists"):
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
else:
|
||||||
|
cls._db_create(execute)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -132,11 +130,13 @@ class Data(SQLSubModel):
|
|||||||
if scenario is None:
|
if scenario is None:
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
lca = data["lca"]
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, deleted, data0, data1 " +
|
"SELECT pamhyr_id, deleted, data0, data1, scenario " +
|
||||||
"FROM lateral_contribution_data_adists " +
|
"FROM lateral_contribution_data_adists " +
|
||||||
f"WHERE scenario = {scenario.id} " +
|
f"WHERE scenario = {scenario.id} " +
|
||||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
|
||||||
f"AND lca = '{lca.id}'"
|
f"AND lca = '{lca.id}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -150,16 +150,16 @@ class Data(SQLSubModel):
|
|||||||
data1 = next(it)
|
data1 = next(it)
|
||||||
owner_scenario = next(it)
|
owner_scenario = next(it)
|
||||||
|
|
||||||
data = cls(
|
lc = cls(
|
||||||
data0, data1,
|
data0, data1,
|
||||||
id=pid, status=status,
|
id=pid, status=status,
|
||||||
owner_scenario=owner_scenario
|
owner_scenario=owner_scenario
|
||||||
)
|
)
|
||||||
if deleted:
|
if deleted:
|
||||||
data.set_as_deleted()
|
lc.set_as_deleted()
|
||||||
|
|
||||||
loaded.add(pid)
|
loaded.add(pid)
|
||||||
new.append(data)
|
new.append(lc)
|
||||||
|
|
||||||
data["scenario"] = scenario.parent
|
data["scenario"] = scenario.parent
|
||||||
new += cls._db_load(execute, data)
|
new += cls._db_load(execute, data)
|
||||||
@@ -175,7 +175,7 @@ class Data(SQLSubModel):
|
|||||||
|
|
||||||
execute(
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"lateral_contribution_adists(pamhyr_id, deleted," +
|
"lateral_contribution_data_adists(pamhyr_id, deleted," +
|
||||||
"data0, data1, lca, scenario) " +
|
"data0, data1, lca, scenario) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||||
@@ -241,15 +241,13 @@ class LateralContributionAdisTS(SQLSubModel):
|
|||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
created = False
|
created = False
|
||||||
|
|
||||||
if major == "0" and int(minor) <= 1:
|
if major == "0" and int(minor) < 2:
|
||||||
if int(release) < 7:
|
if cls.is_table_exists(execute, "lateral_contribution_adists"):
|
||||||
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
else:
|
||||||
cls._db_create(execute)
|
cls._db_create(execute)
|
||||||
created = True
|
created = True
|
||||||
|
|
||||||
if major == "0" and int(minor) < 2:
|
|
||||||
if not created:
|
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
|
||||||
|
|
||||||
if not created:
|
if not created:
|
||||||
return cls._update_submodel(execute, version, data)
|
return cls._update_submodel(execute, version, data)
|
||||||
|
|
||||||
@@ -372,16 +370,18 @@ class LateralContributionAdisTS(SQLSubModel):
|
|||||||
|
|
||||||
execute(
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"lateral_contribution_adists(id, deleted," +
|
"lateral_contribution_adists(pamhyr_id, deleted, " +
|
||||||
"pollutant, reach, begin_rk, end_rk, scenario) " +
|
"pollutant, reach, begin_rk, end_rk, scenario) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||||
f"{self._pollutant}, {self.reach}, " +
|
f"{self._pollutant}, {self.reach}, " +
|
||||||
f"{self._begin_rk}, {self._end_rk}" +
|
f"{self._begin_rk}, {self._end_rk}, " +
|
||||||
f"{self._status.scenario_id}" +
|
f"{self._status.scenario_id}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data["lca"] = self
|
||||||
|
|
||||||
ind = 0
|
ind = 0
|
||||||
for d in self._data:
|
for d in self._data:
|
||||||
data["ind"] = ind
|
data["ind"] = ind
|
||||||
@@ -406,7 +406,7 @@ class LateralContributionAdisTS(SQLSubModel):
|
|||||||
return len(
|
return len(
|
||||||
list(
|
list(
|
||||||
filter(
|
filter(
|
||||||
lambda el: not el.is_deleted(),
|
lambda el: el is not None and not el.is_deleted(),
|
||||||
self._data
|
self._data
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -452,7 +452,12 @@ class LateralContributionAdisTS(SQLSubModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def data(self):
|
def data(self):
|
||||||
return self._data.copy()
|
return list(
|
||||||
|
filter(
|
||||||
|
lambda el: el is not None and not el.is_deleted(),
|
||||||
|
self._data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def begin_rk(self):
|
def begin_rk(self):
|
||||||
@@ -471,3 +476,57 @@ class LateralContributionAdisTS(SQLSubModel):
|
|||||||
def end_rk(self, end_rk):
|
def end_rk(self, end_rk):
|
||||||
self._end_rk = end_rk
|
self._end_rk = end_rk
|
||||||
self.modified()
|
self.modified()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _default_0(self):
|
||||||
|
return self._types[0](0)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _default_1(self):
|
||||||
|
return self._types[1](0.0)
|
||||||
|
|
||||||
|
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, data: Data):
|
||||||
|
self._data.insert(index, data)
|
||||||
|
self.modified()
|
||||||
|
|
||||||
|
def delete_i(self, indexes):
|
||||||
|
self._data = list(
|
||||||
|
map(
|
||||||
|
lambda e: e[1].set_as_deleted(),
|
||||||
|
filter(
|
||||||
|
lambda e: e[0] not in indexes,
|
||||||
|
enumerate(self.data)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.modified()
|
||||||
|
|
||||||
|
def index(self, bc):
|
||||||
|
self._data.index(bc)
|
||||||
|
|
||||||
|
def get_i(self, index: int):
|
||||||
|
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: int, column: int, 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)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# LateralContributionsAdisTSList.py -- Pamhyr
|
# LateralContributionsAdisTSList.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Edge.py -- Pamhyr
|
# Edge.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Graph.py -- Pamhyr
|
# Graph.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Node.py -- Pamhyr
|
# Node.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Point.py -- Pamhyr
|
# Point.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# __init__.py -- Pamhyr
|
# __init__.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# test_Network.py -- Pamhyr
|
# test_Network.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# OutputRKAdists.py -- Pamhyr
|
# OutputRKAdists.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -95,16 +95,12 @@ class OutputRKAdists(SQLSubModel):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def _db_update(cls, execute, version, data=None):
|
def _db_update(cls, execute, version, data=None):
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
created = False
|
|
||||||
|
|
||||||
if major == "0" and int(minor) <= 1:
|
|
||||||
if int(release) < 7:
|
|
||||||
cls._db_create(execute)
|
|
||||||
created = True
|
|
||||||
|
|
||||||
if major == "0" and int(minor) < 2:
|
if major == "0" and int(minor) < 2:
|
||||||
if not created:
|
if cls.is_table_exists(execute, "OutputRKAdists"):
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
else:
|
||||||
|
cls._db_create(execute)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -193,7 +189,7 @@ class OutputRKAdists(SQLSubModel):
|
|||||||
"output_rk_adists(pamhyr_id, deleted, " +
|
"output_rk_adists(pamhyr_id, deleted, " +
|
||||||
"reach, rk, title, scenario) " +
|
"reach, rk, title, scenario) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {self._db_format(self.is_deleted())}" +
|
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||||
f"{self._reach}, {self._rk}, " +
|
f"{self._reach}, {self._rk}, " +
|
||||||
f"'{self._db_format(self._title)}', " +
|
f"'{self._db_format(self._title)}', " +
|
||||||
f"{self._status.scenario_id}" +
|
f"{self._status.scenario_id}" +
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Pollutants.py -- Pamhyr
|
# Pollutants.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -28,6 +28,9 @@ from tools import (
|
|||||||
from Model.Tools.PamhyrDB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
from Model.Scenario import Scenario
|
from Model.Scenario import Scenario
|
||||||
|
from Model.BoundaryConditionsAdisTS.BoundaryConditionAdisTS import (
|
||||||
|
BoundaryConditionAdisTS,
|
||||||
|
)
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
@@ -101,6 +104,12 @@ class PollutantCharacteristics(SQLSubModel):
|
|||||||
self._ac = value
|
self._ac = value
|
||||||
elif key == 8:
|
elif key == 8:
|
||||||
self._bc = value
|
self._bc = value
|
||||||
|
self.propagate_modified()
|
||||||
|
|
||||||
|
def propagate_modified(self):
|
||||||
|
self.modified()
|
||||||
|
if hasattr(self, "_pollutant") and self._pollutant:
|
||||||
|
self._pollutant.modified()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_create(cls, execute, ext=""):
|
def _db_create(cls, execute, ext=""):
|
||||||
@@ -129,16 +138,12 @@ class PollutantCharacteristics(SQLSubModel):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def _db_update(cls, execute, version, data=None):
|
def _db_update(cls, execute, version, data=None):
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
created = False
|
|
||||||
|
|
||||||
if major == "0" and int(minor) <= 1:
|
|
||||||
if int(release) < 7:
|
|
||||||
cls._db_create(execute)
|
|
||||||
created = True
|
|
||||||
|
|
||||||
if major == "0" and int(minor) < 2:
|
if major == "0" and int(minor) < 2:
|
||||||
if not created:
|
if cls.is_table_exists(execute, "Pollutants_characteristics"):
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
else:
|
||||||
|
cls._db_create(execute)
|
||||||
|
|
||||||
return cls._update_submodel(execute, version, data)
|
return cls._update_submodel(execute, version, data)
|
||||||
|
|
||||||
@@ -253,6 +258,12 @@ class PollutantCharacteristics(SQLSubModel):
|
|||||||
if not self.must_be_saved():
|
if not self.must_be_saved():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
execute(
|
||||||
|
"DELETE FROM pollutants_characteristics " +
|
||||||
|
f"WHERE pamhyr_id = {self.id} " +
|
||||||
|
f"AND scenario = {self._status.scenario_id}"
|
||||||
|
)
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"pollutants_characteristics(pamhyr_id, deleted, " +
|
"pollutants_characteristics(pamhyr_id, deleted, " +
|
||||||
@@ -275,7 +286,10 @@ class PollutantCharacteristics(SQLSubModel):
|
|||||||
|
|
||||||
|
|
||||||
class Pollutants(SQLSubModel):
|
class Pollutants(SQLSubModel):
|
||||||
_sub_classes = [PollutantCharacteristics]
|
_sub_classes = [
|
||||||
|
PollutantCharacteristics,
|
||||||
|
# BoundaryConditionAdisTS
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self, id: int = -1, name: str = "",
|
def __init__(self, id: int = -1, name: str = "",
|
||||||
status=None, owner_scenario=-1):
|
status=None, owner_scenario=-1):
|
||||||
@@ -293,6 +307,11 @@ class Pollutants(SQLSubModel):
|
|||||||
self._enabled = True
|
self._enabled = True
|
||||||
|
|
||||||
self._data = []
|
self._data = []
|
||||||
|
self._boundary_conditions_adists = []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def boundary_conditions_adists(self):
|
||||||
|
return self._boundary_conditions_adists
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@@ -301,7 +320,7 @@ class Pollutants(SQLSubModel):
|
|||||||
@name.setter
|
@name.setter
|
||||||
def name(self, name):
|
def name(self, name):
|
||||||
self._name = name
|
self._name = name
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def data(self):
|
def data(self):
|
||||||
@@ -309,7 +328,9 @@ class Pollutants(SQLSubModel):
|
|||||||
|
|
||||||
@data.setter
|
@data.setter
|
||||||
def data(self, data):
|
def data(self, data):
|
||||||
self._data = [PollutantCharacteristics(type=int(data[0]),
|
self._data = [
|
||||||
|
PollutantCharacteristics(
|
||||||
|
type=int(data[0]),
|
||||||
diametre=float(data[1]),
|
diametre=float(data[1]),
|
||||||
rho=float(data[2]),
|
rho=float(data[2]),
|
||||||
porosity=float(data[3]),
|
porosity=float(data[3]),
|
||||||
@@ -329,6 +350,7 @@ class Pollutants(SQLSubModel):
|
|||||||
CREATE TABLE pollutants{ext}(
|
CREATE TABLE pollutants{ext}(
|
||||||
{cls.create_db_add_pamhyr_id()},
|
{cls.create_db_add_pamhyr_id()},
|
||||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
{Scenario.create_db_add_scenario()},
|
{Scenario.create_db_add_scenario()},
|
||||||
{Scenario.create_db_add_scenario_fk()}
|
{Scenario.create_db_add_scenario_fk()}
|
||||||
@@ -345,14 +367,20 @@ class Pollutants(SQLSubModel):
|
|||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
created = False
|
created = False
|
||||||
|
|
||||||
if major == "0" and int(minor) <= 1:
|
if major == "0" and int(minor) < 2:
|
||||||
if int(release) < 7:
|
if cls.is_table_exists(execute, "Pollutants"):
|
||||||
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
else:
|
||||||
cls._db_create(execute)
|
cls._db_create(execute)
|
||||||
created = True
|
created = True
|
||||||
|
|
||||||
if major == "0" and int(minor) < 2:
|
if major == "0" and minor == "2":
|
||||||
if not created:
|
if int(release) < 6:
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
execute(f"ALTER TABLE pollutants " +
|
||||||
|
f"ADD COLUMN enabled BOOLEAN NOT NULL DEFAULT TRUE")
|
||||||
|
|
||||||
|
# cls._db_update_to_0_2_5(execute, data)
|
||||||
|
# # created = True
|
||||||
|
|
||||||
if not created:
|
if not created:
|
||||||
return cls._update_submodel(execute, version, data)
|
return cls._update_submodel(execute, version, data)
|
||||||
@@ -391,7 +419,8 @@ class Pollutants(SQLSubModel):
|
|||||||
return new
|
return new
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, deleted, name FROM pollutants " +
|
"SELECT pamhyr_id, deleted, enabled, name, scenario " +
|
||||||
|
"FROM pollutants " +
|
||||||
f"WHERE scenario = {scenario.id} " +
|
f"WHERE scenario = {scenario.id} " +
|
||||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
|
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
|
||||||
)
|
)
|
||||||
@@ -402,20 +431,32 @@ class Pollutants(SQLSubModel):
|
|||||||
|
|
||||||
pid = next(it)
|
pid = next(it)
|
||||||
deleted = (next(it) == 1)
|
deleted = (next(it) == 1)
|
||||||
|
enabled = (next(it) == 1)
|
||||||
name = next(it)
|
name = next(it)
|
||||||
|
owner_scenario = next(it)
|
||||||
|
|
||||||
new_pollutant = cls(
|
new_pollutant = cls(
|
||||||
id=pid, name=name,
|
id=pid, name=name,
|
||||||
status=status
|
status=status,
|
||||||
|
owner_scenario=owner_scenario
|
||||||
)
|
)
|
||||||
if deleted:
|
if deleted:
|
||||||
new_pollutant.set_as_deleted()
|
new_pollutant.set_as_deleted()
|
||||||
|
if not enabled:
|
||||||
|
new_pollutant.enabled = False
|
||||||
|
|
||||||
data["pollutant"] = new_pollutant
|
data["pollutant"] = new_pollutant
|
||||||
new_pollutant._data = PollutantCharacteristics._db_load(
|
new_pollutant._data = PollutantCharacteristics._db_load(
|
||||||
execute, data=data
|
execute, data=data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
new_pollutant._boundary_conditions_adists = (
|
||||||
|
BoundaryConditionAdisTS._db_load(
|
||||||
|
execute,
|
||||||
|
data=data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
loaded.add(pid)
|
loaded.add(pid)
|
||||||
new.append(new_pollutant)
|
new.append(new_pollutant)
|
||||||
|
|
||||||
@@ -444,9 +485,10 @@ class Pollutants(SQLSubModel):
|
|||||||
|
|
||||||
execute(
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"pollutants(pamhyr_id, deleted, name, scenario) " +
|
"pollutants(pamhyr_id, deleted, enabled, name, scenario) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||||
|
f"{self._db_format(self._enabled)}, " +
|
||||||
f"'{self._db_format(self._name)}', " +
|
f"'{self._db_format(self._name)}', " +
|
||||||
f"{self._status.scenario_id}" +
|
f"{self._status.scenario_id}" +
|
||||||
")"
|
")"
|
||||||
@@ -455,6 +497,9 @@ class Pollutants(SQLSubModel):
|
|||||||
for d in self._data:
|
for d in self._data:
|
||||||
ok &= d._db_save(execute, data)
|
ok &= d._db_save(execute, data)
|
||||||
|
|
||||||
|
for bc in self._boundary_conditions_adists:
|
||||||
|
ok &= bc._db_save(execute, data)
|
||||||
|
|
||||||
return ok
|
return ok
|
||||||
|
|
||||||
def _data_traversal(self,
|
def _data_traversal(self,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
from Model.Tools.PamhyrList import PamhyrModelList
|
from Model.Tools.PamhyrListExt import PamhyrModelList
|
||||||
from Model.Pollutants.Pollutants import Pollutants
|
from Model.Pollutants.Pollutants import Pollutants
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Reservoir.py -- Pamhyr
|
# Reservoir.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -263,8 +263,6 @@ class Reservoir(SQLSubModel):
|
|||||||
cls._db_update_to_0_2_0_set_node_pid(execute, table, nodes)
|
cls._db_update_to_0_2_0_set_node_pid(execute, table, nodes)
|
||||||
Scenario.update_db_add_scenario(execute, table)
|
Scenario.update_db_add_scenario(execute, table)
|
||||||
|
|
||||||
print(execute(f"SELECT * FROM {table}"))
|
|
||||||
|
|
||||||
cls._db_create(execute, ext="_tmp")
|
cls._db_create(execute, ext="_tmp")
|
||||||
execute(
|
execute(
|
||||||
f"INSERT INTO {table}_tmp " +
|
f"INSERT INTO {table}_tmp " +
|
||||||
@@ -314,7 +312,7 @@ class Reservoir(SQLSubModel):
|
|||||||
new_reservoir._node = next(
|
new_reservoir._node = next(
|
||||||
filter(
|
filter(
|
||||||
lambda n: n.id == node_id, data["nodes"]
|
lambda n: n.id == node_id, data["nodes"]
|
||||||
)
|
), None
|
||||||
)
|
)
|
||||||
|
|
||||||
data["reservoir"] = new_reservoir
|
data["reservoir"] = new_reservoir
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# ReservoirList.py -- Pamhyr
|
# ReservoirList.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Results.py -- Pamhyr
|
# Results.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,6 +22,8 @@ import numpy as np
|
|||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from tools import timer
|
||||||
|
|
||||||
from Model.Scenario import Scenario
|
from Model.Scenario import Scenario
|
||||||
from Model.Tools.PamhyrDB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
from Model.Results.River.River import River
|
from Model.Results.River.River import River
|
||||||
@@ -155,8 +157,185 @@ class AdditionalData(SQLSubModel):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class TableData(SQLSubModel):
|
||||||
|
_sub_classes = []
|
||||||
|
|
||||||
|
def __init__(self, id=-1, study=None,
|
||||||
|
legend="", data=None,
|
||||||
|
owner_scenario=-1):
|
||||||
|
super(TableData, self).__init__(
|
||||||
|
id=id, status=study.status,
|
||||||
|
owner_scenario=owner_scenario
|
||||||
|
)
|
||||||
|
|
||||||
|
self._study = study
|
||||||
|
self._legend = legend
|
||||||
|
self._data = data
|
||||||
|
|
||||||
|
@property
|
||||||
|
def data(self):
|
||||||
|
return self._data
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_create(cls, execute, ext=""):
|
||||||
|
execute(f"""
|
||||||
|
CREATE TABLE results_table_data{ext} (
|
||||||
|
{cls.create_db_add_pamhyr_id()},
|
||||||
|
result INTEGER NOT NULL,
|
||||||
|
legend TEXT NOT NULL,
|
||||||
|
unit TEXT NOT NULL,
|
||||||
|
data_shape_x INTEGER NOT NULL,
|
||||||
|
data_shape_y INTEGER NOT NULL,
|
||||||
|
data_shape_z INTEGER DEFAULT -1,
|
||||||
|
data BLOB NOT NULL,
|
||||||
|
{Scenario.create_db_add_scenario()},
|
||||||
|
{Scenario.create_db_add_scenario_fk()},
|
||||||
|
FOREIGN KEY(result) REFERENCES results(pamhyr_id),
|
||||||
|
PRIMARY KEY(pamhyr_id, result, legend, scenario)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
if ext != "":
|
||||||
|
return True
|
||||||
|
|
||||||
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_update(cls, execute, version, data=None):
|
||||||
|
major, minor, release = version.strip().split(".")
|
||||||
|
create = False
|
||||||
|
|
||||||
|
if major == "0" and int(minor) == 2:
|
||||||
|
if int(release) < 7 and not create:
|
||||||
|
cls._db_create(execute)
|
||||||
|
create = True
|
||||||
|
|
||||||
|
return cls._update_submodel(execute, version, data)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_load(cls, execute, data=None):
|
||||||
|
res = {}
|
||||||
|
|
||||||
|
study = data['study']
|
||||||
|
status = data['status']
|
||||||
|
scenario = data["scenario"]
|
||||||
|
result = data["result"]
|
||||||
|
rid = data["result_pid"]
|
||||||
|
|
||||||
|
table = execute(
|
||||||
|
"SELECT pamhyr_id, " +
|
||||||
|
"legend, unit, " +
|
||||||
|
"data_shape_x, data_shape_y, data_shape_z, " +
|
||||||
|
"data, " +
|
||||||
|
"scenario " +
|
||||||
|
"FROM results_table_data " +
|
||||||
|
f"WHERE scenario = {scenario.id} " +
|
||||||
|
f"AND result = {rid}"
|
||||||
|
)
|
||||||
|
|
||||||
|
for v in table:
|
||||||
|
it = iter(v)
|
||||||
|
|
||||||
|
pid = next(it)
|
||||||
|
legend = next(it)
|
||||||
|
unit = next(it)
|
||||||
|
data_shape_x = next(it)
|
||||||
|
data_shape_y = next(it)
|
||||||
|
data_shape_z = next(it)
|
||||||
|
data = next(it)
|
||||||
|
owner_scenario = next(it)
|
||||||
|
|
||||||
|
dtype = cls._unit_to_dtype(unit)
|
||||||
|
|
||||||
|
np_data = np.frombuffer(data, dtype=dtype)
|
||||||
|
if data_shape_y == -1:
|
||||||
|
np_data = np.reshape(np_data, data_shape_x)
|
||||||
|
elif data_shape_z == -1:
|
||||||
|
np_data = np.reshape(np_data, (data_shape_x,
|
||||||
|
data_shape_y))
|
||||||
|
else:
|
||||||
|
np_data = np.reshape(np_data, (data_shape_x,
|
||||||
|
data_shape_y,
|
||||||
|
data_shape_z))
|
||||||
|
|
||||||
|
new_table = cls(study=study,
|
||||||
|
legend=legend, data=np_data,
|
||||||
|
owner_scenario=owner_scenario)
|
||||||
|
|
||||||
|
res[legend] = new_table
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
def _db_save(self, execute, data=None):
|
||||||
|
if self._status.scenario.id != self._owner_scenario:
|
||||||
|
return
|
||||||
|
|
||||||
|
shape_x = -1
|
||||||
|
shape_y = -1
|
||||||
|
shape_z = -1
|
||||||
|
shape = self._data.shape
|
||||||
|
|
||||||
|
if len(shape) == 2:
|
||||||
|
shape_x, shape_y = shape
|
||||||
|
elif len(shape == 1):
|
||||||
|
shape_x, = shape
|
||||||
|
elif len(shape == 3):
|
||||||
|
shape_x, shape_y, shape_z = shape
|
||||||
|
else:
|
||||||
|
logger.error(
|
||||||
|
f"Failed to parse numpy shape: {shape}"
|
||||||
|
)
|
||||||
|
|
||||||
|
execute(
|
||||||
|
"INSERT INTO " +
|
||||||
|
"results_table_data (pamhyr_id, result, " +
|
||||||
|
"legend, unit, " +
|
||||||
|
"data_shape_x, data_shape_y, data_shape_z, " +
|
||||||
|
"data, " +
|
||||||
|
"scenario) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
|
self._pamhyr_id, data["result"],
|
||||||
|
self._legend, self._dtype_to_unit(self._data.dtype),
|
||||||
|
shape_x, shape_y, shape_z,
|
||||||
|
self._data,
|
||||||
|
self._owner_scenario
|
||||||
|
)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _unit_to_dtype(cls, unit):
|
||||||
|
t = {
|
||||||
|
"i32": np.int32, "i64": np.int64,
|
||||||
|
"u32": np.uint32, "u64": np.uint64,
|
||||||
|
"f32": np.float32, "f64": np.float64,
|
||||||
|
}
|
||||||
|
|
||||||
|
return t[unit]
|
||||||
|
|
||||||
|
def _dtype_to_unit(self, dtype):
|
||||||
|
t = {
|
||||||
|
np.dtype(np.int32): "i32", np.dtype(np.int64): "i64",
|
||||||
|
np.dtype(np.uint32): "u32", np.dtype(np.uint64): "u64",
|
||||||
|
np.dtype(np.float32): "f32", np.dtype(np.float64): "f64",
|
||||||
|
}
|
||||||
|
|
||||||
|
return t[dtype]
|
||||||
|
|
||||||
|
def table(self):
|
||||||
|
return self._data
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self._data)
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
if isinstance(key, tuple):
|
||||||
|
return self._data[key[0], key[1]]
|
||||||
|
|
||||||
|
self._date[key]
|
||||||
|
|
||||||
|
|
||||||
class Results(SQLSubModel):
|
class Results(SQLSubModel):
|
||||||
_sub_classes = [River, AdditionalData]
|
_sub_classes = [River, TableData, AdditionalData]
|
||||||
|
|
||||||
def __init__(self, id=-1, study=None, solver=None,
|
def __init__(self, id=-1, study=None, solver=None,
|
||||||
repertory="", name="0"):
|
repertory="", name="0"):
|
||||||
@@ -167,7 +346,7 @@ class Results(SQLSubModel):
|
|||||||
|
|
||||||
self._name = name
|
self._name = name
|
||||||
self._study = study
|
self._study = study
|
||||||
self._river = River(self._study)
|
self._river = River(self._study, self)
|
||||||
|
|
||||||
self._solver = solver
|
self._solver = solver
|
||||||
self._repertory = repertory
|
self._repertory = repertory
|
||||||
@@ -177,8 +356,11 @@ class Results(SQLSubModel):
|
|||||||
"creation_date": datetime.now(),
|
"creation_date": datetime.now(),
|
||||||
"study_revision": study.status.version,
|
"study_revision": study.status.version,
|
||||||
"additional_data": [],
|
"additional_data": [],
|
||||||
|
"table": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self._ts_index = {}
|
||||||
|
|
||||||
if solver is not None:
|
if solver is not None:
|
||||||
self.set("solver_type", solver._type)
|
self.set("solver_type", solver._type)
|
||||||
|
|
||||||
@@ -195,6 +377,7 @@ class Results(SQLSubModel):
|
|||||||
def study(self):
|
def study(self):
|
||||||
return self._study
|
return self._study
|
||||||
|
|
||||||
|
@timer
|
||||||
def set(self, key, value):
|
def set(self, key, value):
|
||||||
self._meta_data[key] = value
|
self._meta_data[key] = value
|
||||||
|
|
||||||
@@ -212,6 +395,16 @@ class Results(SQLSubModel):
|
|||||||
def get(self, key):
|
def get(self, key):
|
||||||
return self._meta_data[key]
|
return self._meta_data[key]
|
||||||
|
|
||||||
|
def set_timestamp_index(self, index):
|
||||||
|
self._ts_index = index
|
||||||
|
|
||||||
|
def get_timestamp_id(self, ts):
|
||||||
|
return self._ts_index[ts]
|
||||||
|
|
||||||
|
def compute_timestamp_index(self):
|
||||||
|
for i, ts in enumerate(self._meta_data["timestamps"]):
|
||||||
|
self._ts_index[ts] = i
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
return self._solver.results(
|
return self._solver.results(
|
||||||
self._study,
|
self._study,
|
||||||
@@ -219,6 +412,11 @@ class Results(SQLSubModel):
|
|||||||
qlog=None,
|
qlog=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def bufferize(self, key):
|
||||||
|
if self.is_valid:
|
||||||
|
for reach in self._river._reachs:
|
||||||
|
reach.bufferize(self._meta_data["timestamps"], key)
|
||||||
|
|
||||||
def timestamps_to_struct(self):
|
def timestamps_to_struct(self):
|
||||||
ts = self._meta_data["timestamps"]
|
ts = self._meta_data["timestamps"]
|
||||||
sf = ">" + ''.join(itertools.repeat("d", len(ts)))
|
sf = ">" + ''.join(itertools.repeat("d", len(ts)))
|
||||||
@@ -304,11 +502,20 @@ class Results(SQLSubModel):
|
|||||||
new_results.set("study_revision", revision)
|
new_results.set("study_revision", revision)
|
||||||
new_results.set("creation_date", creation_date)
|
new_results.set("creation_date", creation_date)
|
||||||
|
|
||||||
|
data["result_pid"] = pid
|
||||||
|
data["result"] = new_results
|
||||||
|
|
||||||
|
table_data = TableData._db_load(execute, data)
|
||||||
|
new_results.set("table", table_data)
|
||||||
|
|
||||||
sf = ">" + ''.join(itertools.repeat("d", nb_timestamps))
|
sf = ">" + ''.join(itertools.repeat("d", nb_timestamps))
|
||||||
ts = struct.unpack(sf, timestamps_bytes)
|
ts = struct.unpack(sf, timestamps_bytes)
|
||||||
new_results.set("timestamps", ts)
|
new_results.set("timestamps", ts)
|
||||||
|
|
||||||
data["timestamps"] = sorted(ts)
|
data["timestamps"] = sorted(ts)
|
||||||
|
new_results.compute_timestamp_index()
|
||||||
|
|
||||||
|
data["parent"] = new_results
|
||||||
new_results._river = River._db_load(execute, data)
|
new_results._river = River._db_load(execute, data)
|
||||||
|
|
||||||
new_results.set(
|
new_results.set(
|
||||||
@@ -316,6 +523,20 @@ class Results(SQLSubModel):
|
|||||||
AdditionalData._db_load(execute, data)
|
AdditionalData._db_load(execute, data)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Update global index
|
||||||
|
i = 0
|
||||||
|
for reach in new_results._river.reachs:
|
||||||
|
nb = len(reach.profiles)
|
||||||
|
reach.set_global_index(range(i, i + nb + 1))
|
||||||
|
i += nb
|
||||||
|
|
||||||
|
if "Z" in table_data:
|
||||||
|
for ts in data["timestamps"]:
|
||||||
|
new_results._river.update_water_limits(
|
||||||
|
ts,
|
||||||
|
table_data["Z"][new_results.get_timestamp_id(ts), :]
|
||||||
|
)
|
||||||
|
|
||||||
yield (solver_type, new_results)
|
yield (solver_type, new_results)
|
||||||
|
|
||||||
def _db_save_clear(self, execute, solver_type, data=None):
|
def _db_save_clear(self, execute, solver_type, data=None):
|
||||||
@@ -338,15 +559,26 @@ class Results(SQLSubModel):
|
|||||||
f"WHERE scenario = {self._owner_scenario} " +
|
f"WHERE scenario = {self._owner_scenario} " +
|
||||||
f"AND result = {pid}"
|
f"AND result = {pid}"
|
||||||
)
|
)
|
||||||
|
execute(
|
||||||
|
"DELETE FROM results_table_data " +
|
||||||
|
f"WHERE scenario = {self._owner_scenario} " +
|
||||||
|
f"AND result = {pid}"
|
||||||
|
)
|
||||||
execute(
|
execute(
|
||||||
"DELETE FROM results_add_data " +
|
"DELETE FROM results_add_data " +
|
||||||
f"WHERE scenario = {self._owner_scenario} " +
|
f"WHERE scenario = {self._owner_scenario} " +
|
||||||
f"AND result = {pid}"
|
f"AND result = {pid}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _is_valid(self):
|
||||||
|
return "timestamps" in self._meta_data
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
if self._status.scenario.id != self._owner_scenario:
|
if self._status.scenario.id != self._owner_scenario:
|
||||||
return
|
return True
|
||||||
|
|
||||||
|
if not self._is_valid():
|
||||||
|
return False
|
||||||
|
|
||||||
pid = self._pamhyr_id
|
pid = self._pamhyr_id
|
||||||
if self._solver is None:
|
if self._solver is None:
|
||||||
@@ -375,7 +607,19 @@ class Results(SQLSubModel):
|
|||||||
data["result"] = self._pamhyr_id
|
data["result"] = self._pamhyr_id
|
||||||
self._river._db_save(execute, data)
|
self._river._db_save(execute, data)
|
||||||
|
|
||||||
|
tables = self.get("table")
|
||||||
|
for legend in tables:
|
||||||
|
tables[legend]._db_save(execute, data)
|
||||||
|
|
||||||
for add_data in self.get("additional_data"):
|
for add_data in self.get("additional_data"):
|
||||||
add_data._db_save(execute, data)
|
add_data._db_save(execute, data)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def new_table_data(self, legend, data):
|
||||||
|
return TableData(
|
||||||
|
study=self._study,
|
||||||
|
legend=legend,
|
||||||
|
data=data,
|
||||||
|
owner_scenario=self._owner_scenario
|
||||||
|
)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# Results.py -- Pamhyr
|
# Results.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,12 +21,13 @@ import os
|
|||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
from Model.Results.River.RiverAdisTS import River
|
from Model.Results.River.RiverAdisTS import River
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class Results(object):
|
class Results(SQLSubModel):
|
||||||
def __init__(self, study=None, solver=None,
|
def __init__(self, study=None, solver=None,
|
||||||
repertory="", name="0", type_pol=None):
|
repertory="", name="0", type_pol=None):
|
||||||
self._study = study
|
self._study = study
|
||||||
@@ -90,3 +91,6 @@ class Results(object):
|
|||||||
self._repertory,
|
self._repertory,
|
||||||
qlog=None,
|
qlog=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _db_save(self, execute, data=None):
|
||||||
|
return False
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# River.py -- Pamhyr
|
# River.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -14,11 +14,13 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import types
|
||||||
import struct
|
import struct
|
||||||
import logging
|
import logging
|
||||||
import itertools
|
import itertools
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
from tools import flatten
|
from tools import flatten, timer
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@@ -29,15 +31,17 @@ logger = logging.getLogger()
|
|||||||
|
|
||||||
|
|
||||||
class Profile(SQLSubModel):
|
class Profile(SQLSubModel):
|
||||||
def __init__(self, profile, study):
|
def __init__(self, profile, study, parent):
|
||||||
super(Profile, self).__init__(
|
super(Profile, self).__init__(
|
||||||
id=-1, status=study.status,
|
id=-1, status=study.status,
|
||||||
owner_scenario=study.status.scenario.id
|
owner_scenario=study.status.scenario.id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._parent = parent
|
||||||
self._study = study
|
self._study = study
|
||||||
self._profile = profile # Source profile in the study
|
self._profile = profile # Source profile in the study
|
||||||
self._data = {} # Dict of dict {<ts>: {<key>: <value>, ...}, ...}
|
self._data = {} # Dict of dict {<ts>: {<key>: <value>, ...}, ...}
|
||||||
|
self._global_index = -1
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._data)
|
return len(self._data)
|
||||||
@@ -54,15 +58,26 @@ class Profile(SQLSubModel):
|
|||||||
def geometry(self):
|
def geometry(self):
|
||||||
return self._profile
|
return self._profile
|
||||||
|
|
||||||
|
@property
|
||||||
|
def global_index(self):
|
||||||
|
return self._global_index
|
||||||
|
|
||||||
|
@global_index.setter
|
||||||
|
def global_index(self, id):
|
||||||
|
self._global_index = id
|
||||||
|
|
||||||
|
@timer
|
||||||
def set(self, timestamp, key, data):
|
def set(self, timestamp, key, data):
|
||||||
if timestamp not in self._data:
|
if timestamp not in self._data:
|
||||||
self._data[timestamp] = {}
|
self._data[timestamp] = {}
|
||||||
|
|
||||||
self._data[timestamp][key] = data
|
self._data[timestamp][key] = data
|
||||||
|
|
||||||
|
@timer
|
||||||
def get_ts(self, timestamp):
|
def get_ts(self, timestamp):
|
||||||
return self._data[timestamp]
|
return self._data[timestamp]
|
||||||
|
|
||||||
|
@timer
|
||||||
def get_key(self, key):
|
def get_key(self, key):
|
||||||
res = list(
|
res = list(
|
||||||
map(lambda ts: self._data[ts][key],
|
map(lambda ts: self._data[ts][key],
|
||||||
@@ -70,13 +85,25 @@ class Profile(SQLSubModel):
|
|||||||
)
|
)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@timer
|
||||||
def get_ts_key(self, timestamp, key):
|
def get_ts_key(self, timestamp, key):
|
||||||
if timestamp in self._data:
|
if timestamp in self._data:
|
||||||
if key in self._data[timestamp]:
|
if key in self._data[timestamp]:
|
||||||
return self._data[timestamp][key]
|
v = self._data[timestamp][key]
|
||||||
|
|
||||||
|
# If is a generator, compute value(s)
|
||||||
|
if isinstance(v, types.GeneratorType):
|
||||||
|
v = next(v)
|
||||||
|
self._data[timestamp][key] = v
|
||||||
|
|
||||||
|
return v
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def has_sediment(self):
|
def has_sediment_layers(self):
|
||||||
|
return any(map(lambda ts: "sl" in self._data[ts], self._data))
|
||||||
|
|
||||||
|
def has_bedload(self):
|
||||||
return any(map(lambda ts: "sl" in self._data[ts], self._data))
|
return any(map(lambda ts: "sl" in self._data[ts], self._data))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -110,9 +137,9 @@ class Profile(SQLSubModel):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = {}
|
|
||||||
status = data['status']
|
status = data['status']
|
||||||
|
|
||||||
|
parent = data['parent']
|
||||||
study = data['study']
|
study = data['study']
|
||||||
reach = data['reach']
|
reach = data['reach']
|
||||||
profile = data['profile']
|
profile = data['profile']
|
||||||
@@ -120,6 +147,8 @@ class Profile(SQLSubModel):
|
|||||||
loaded = data['loaded_pid']
|
loaded = data['loaded_pid']
|
||||||
timestamps = data['timestamps']
|
timestamps = data['timestamps']
|
||||||
|
|
||||||
|
new = cls(profile, study, parent)
|
||||||
|
|
||||||
values = execute(
|
values = execute(
|
||||||
"SELECT pamhyr_id, result, key, " +
|
"SELECT pamhyr_id, result, key, " +
|
||||||
"len_data, data, scenario " +
|
"len_data, data, scenario " +
|
||||||
@@ -139,12 +168,6 @@ class Profile(SQLSubModel):
|
|||||||
data = next(it)
|
data = next(it)
|
||||||
owner_scenario = next(it)
|
owner_scenario = next(it)
|
||||||
|
|
||||||
if profile not in new:
|
|
||||||
new_data = cls(profile, study)
|
|
||||||
new[profile] = new_data
|
|
||||||
else:
|
|
||||||
new_data = new[profile]
|
|
||||||
|
|
||||||
if key in ["Z", "Q", "V"]:
|
if key in ["Z", "Q", "V"]:
|
||||||
sf = ">" + ''.join(itertools.repeat("f", len_data))
|
sf = ">" + ''.join(itertools.repeat("f", len_data))
|
||||||
len_values = len(values)
|
len_values = len(values)
|
||||||
@@ -157,11 +180,11 @@ class Profile(SQLSubModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for timestamp, value in zip(timestamps, values):
|
for timestamp, value in zip(timestamps, values):
|
||||||
new_data.set(timestamp, key, value)
|
new.set(timestamp, key, value)
|
||||||
if key == "Z":
|
if key == "Z":
|
||||||
new_data.update_water_limits(timestamp, value)
|
new.update_water_limits(timestamp, value)
|
||||||
|
|
||||||
return list(new.values())
|
return new
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load_data_sl_format(cls, values, len_data, timestamps):
|
def _db_load_data_sl_format(cls, values, len_data, timestamps):
|
||||||
@@ -253,19 +276,20 @@ class Profile(SQLSubModel):
|
|||||||
class Reach(SQLSubModel):
|
class Reach(SQLSubModel):
|
||||||
_sub_classes = [Profile]
|
_sub_classes = [Profile]
|
||||||
|
|
||||||
def __init__(self, reach, study, with_init=True):
|
def __init__(self, reach, study, parent, with_init=True):
|
||||||
super(Reach, self).__init__(
|
super(Reach, self).__init__(
|
||||||
id=-1, status=study.status,
|
id=-1, status=study.status,
|
||||||
owner_scenario=study.status.scenario.id
|
owner_scenario=study.status.scenario.id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._parent = parent
|
||||||
self._study = study
|
self._study = study
|
||||||
self._reach = reach # Source reach in the study
|
self._reach = reach # Source reach in the study
|
||||||
self._profiles = []
|
self._profiles = []
|
||||||
if with_init:
|
if with_init:
|
||||||
self._profiles = list(
|
self._profiles = list(
|
||||||
map(
|
map(
|
||||||
lambda p: Profile(p, self._study),
|
lambda p: Profile(p, self._study, self._parent),
|
||||||
reach.profiles
|
reach.profiles
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -276,6 +300,10 @@ class Reach(SQLSubModel):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._global_index = (-1, -1)
|
||||||
|
|
||||||
|
self._buffers = {}
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._profiles)
|
return len(self._profiles)
|
||||||
|
|
||||||
@@ -295,14 +323,42 @@ class Reach(SQLSubModel):
|
|||||||
def profile_mask(self):
|
def profile_mask(self):
|
||||||
return self._profile_mask
|
return self._profile_mask
|
||||||
|
|
||||||
|
@property
|
||||||
|
def buffers(self):
|
||||||
|
return self._buffers
|
||||||
|
|
||||||
def profile(self, id):
|
def profile(self, id):
|
||||||
return self._profiles[id]
|
return self._profiles[id]
|
||||||
|
|
||||||
|
def set_global_index(self, indexs):
|
||||||
|
self._global_index = (indexs[0], indexs[-1])
|
||||||
|
|
||||||
|
for profile, ind in zip(self._profiles, indexs):
|
||||||
|
profile.global_index = ind
|
||||||
|
|
||||||
|
@property
|
||||||
|
def global_index(self):
|
||||||
|
return self._global_index
|
||||||
|
|
||||||
|
@timer
|
||||||
def set(self, profile_id, timestamp, key, data):
|
def set(self, profile_id, timestamp, key, data):
|
||||||
self._profiles[profile_id].set(timestamp, key, data)
|
self._profiles[profile_id].set(timestamp, key, data)
|
||||||
|
|
||||||
def has_sediment(self):
|
def has_sediment(self):
|
||||||
return any(map(lambda profile: profile.has_sediment(), self._profiles))
|
return any(map(lambda profile: profile.has_sediment_layers(),
|
||||||
|
self._profiles))
|
||||||
|
|
||||||
|
def has_bedload(self):
|
||||||
|
return any(map(lambda profile: profile.has_bedload(), self._profiles))
|
||||||
|
|
||||||
|
def bufferize(self, timestamps, key):
|
||||||
|
self._buffers[key] = np.zeros((len(timestamps), len(self)))
|
||||||
|
for i, p in enumerate(self._profiles):
|
||||||
|
self._buffers[key][:, i] = p.get_key(key)
|
||||||
|
|
||||||
|
def update_water_limits(self, timestamp, z_data):
|
||||||
|
for profile, z in zip(self._profiles, z_data):
|
||||||
|
profile.update_water_limits(timestamp, z)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_create(cls, execute, ext=""):
|
def _db_create(cls, execute, ext=""):
|
||||||
@@ -317,12 +373,13 @@ class Reach(SQLSubModel):
|
|||||||
reach = data["reach"]
|
reach = data["reach"]
|
||||||
|
|
||||||
new_reach = cls(
|
new_reach = cls(
|
||||||
data["reach"], data["study"], with_init=False
|
data["reach"], data["study"], data["parent"],
|
||||||
|
with_init=False
|
||||||
)
|
)
|
||||||
|
|
||||||
for i, profile in enumerate(reach.profiles):
|
for i, profile in enumerate(reach.profiles):
|
||||||
data["profile"] = profile
|
data["profile"] = profile
|
||||||
new_reach._profiles += Profile._db_load(execute, data)
|
new_reach._profiles += [Profile._db_load(execute, data)]
|
||||||
|
|
||||||
return new_reach
|
return new_reach
|
||||||
|
|
||||||
@@ -336,13 +393,14 @@ class Reach(SQLSubModel):
|
|||||||
class River(SQLSubModel):
|
class River(SQLSubModel):
|
||||||
_sub_classes = [Reach]
|
_sub_classes = [Reach]
|
||||||
|
|
||||||
def __init__(self, study):
|
def __init__(self, study, parent):
|
||||||
super(River, self).__init__(
|
super(River, self).__init__(
|
||||||
id=-1, status=study.status,
|
id=-1, status=study.status,
|
||||||
owner_scenario=study.status.scenario.id
|
owner_scenario=study.status.scenario.id
|
||||||
)
|
)
|
||||||
|
|
||||||
self._study = study
|
self._study = study
|
||||||
|
self._parent = parent
|
||||||
|
|
||||||
# Dict with timestamps as key
|
# Dict with timestamps as key
|
||||||
self._reachs = []
|
self._reachs = []
|
||||||
@@ -363,7 +421,7 @@ class River(SQLSubModel):
|
|||||||
def add(self, reach_id):
|
def add(self, reach_id):
|
||||||
reachs = self._study.river.enable_edges()
|
reachs = self._study.river.enable_edges()
|
||||||
|
|
||||||
new = Reach(reachs[reach_id].reach, self._study)
|
new = Reach(reachs[reach_id].reach, self._study, self._parent)
|
||||||
|
|
||||||
self._reachs.append(new)
|
self._reachs.append(new)
|
||||||
return new
|
return new
|
||||||
@@ -376,6 +434,15 @@ class River(SQLSubModel):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def update_water_limits(self, timestamp, data):
|
||||||
|
for reach in self._reachs:
|
||||||
|
ind = reach.global_index
|
||||||
|
|
||||||
|
reach.update_water_limits(
|
||||||
|
timestamp,
|
||||||
|
data[ind[0]:ind[1]]
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_create(cls, execute, ext=""):
|
def _db_create(cls, execute, ext=""):
|
||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
@@ -387,7 +454,9 @@ class River(SQLSubModel):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
study = data["study"]
|
study = data["study"]
|
||||||
new_river = cls(study)
|
parent = data["parent"]
|
||||||
|
|
||||||
|
new_river = cls(study, parent)
|
||||||
|
|
||||||
for reach in study.river.reachs():
|
for reach in study.river.reachs():
|
||||||
data["reach"] = reach.reach
|
data["reach"] = reach.reach
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# River.py -- Pamhyr
|
# River.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+10
-4
@@ -1,5 +1,5 @@
|
|||||||
# River.py -- Pamhyr river model
|
# River.py -- Pamhyr river model
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -180,6 +180,9 @@ class RiverNode(Node):
|
|||||||
return nodes
|
return nodes
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
|
if not self.must_be_saved():
|
||||||
|
return True
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"INSERT OR REPLACE INTO river_node(" +
|
"INSERT OR REPLACE INTO river_node(" +
|
||||||
"pamhyr_id, deleted, name, x, y, scenario" +
|
"pamhyr_id, deleted, name, x, y, scenario" +
|
||||||
@@ -361,7 +364,7 @@ class RiverReach(Edge):
|
|||||||
)
|
)
|
||||||
new.enable(enable=enabled)
|
new.enable(enable=enabled)
|
||||||
if deleted:
|
if deleted:
|
||||||
nd.set_as_deleted()
|
new.set_as_deleted()
|
||||||
|
|
||||||
data["reach"] = new
|
data["reach"] = new
|
||||||
new._reach = Reach._db_load(execute, data)
|
new._reach = Reach._db_load(execute, data)
|
||||||
@@ -377,6 +380,9 @@ class RiverReach(Edge):
|
|||||||
return reachs
|
return reachs
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
|
if not self.must_be_saved():
|
||||||
|
return True
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"INSERT OR REPLACE INTO " +
|
"INSERT OR REPLACE INTO " +
|
||||||
"river_reach(" +
|
"river_reach(" +
|
||||||
@@ -386,7 +392,7 @@ class RiverReach(Edge):
|
|||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.pamhyr_id}, {self._db_format(self.is_deleted())}, " +
|
f"{self.pamhyr_id}, {self._db_format(self.is_deleted())}, " +
|
||||||
f"'{self._db_format(self._name)}', " +
|
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.node1.pamhyr_id}, {self.node2.pamhyr_id}, " +
|
||||||
f"{self._status.scenario_id}" +
|
f"{self._status.scenario_id}" +
|
||||||
")"
|
")"
|
||||||
@@ -543,7 +549,7 @@ class River(Graph):
|
|||||||
new._nodes = RiverNode._db_load(
|
new._nodes = RiverNode._db_load(
|
||||||
execute, data
|
execute, data
|
||||||
)
|
)
|
||||||
data["nodes"] = new.nodes()
|
data["nodes"] = new._nodes
|
||||||
data['loaded_pid'] = set()
|
data['loaded_pid'] = set()
|
||||||
|
|
||||||
new._edges = RiverReach._db_load(
|
new._edges = RiverReach._db_load(
|
||||||
|
|||||||
+98
-24
@@ -17,16 +17,51 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
|
|
||||||
from tools import logger_exception
|
from tools import logger_exception, timer, flatten
|
||||||
|
|
||||||
from Model.Tools.PamhyrDB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class Scenario(SQLSubModel):
|
class Scenario(SQLSubModel):
|
||||||
_id_cnt = 0
|
_id_cnt = 0
|
||||||
_sub_classes = []
|
_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_spec",
|
||||||
|
"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,
|
def __init__(self,
|
||||||
id: int = -1,
|
id: int = -1,
|
||||||
name: str = "",
|
name: str = "",
|
||||||
@@ -171,29 +206,7 @@ class Scenario(SQLSubModel):
|
|||||||
def drop_all(self, execute):
|
def drop_all(self, execute):
|
||||||
execute(f"DELETE FROM scenario WHERE id = {self.id}")
|
execute(f"DELETE FROM scenario WHERE id = {self.id}")
|
||||||
|
|
||||||
tables = [
|
tables = self.related_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",
|
|
||||||
]
|
|
||||||
|
|
||||||
for table in tables:
|
for table in tables:
|
||||||
execute(
|
execute(
|
||||||
@@ -203,6 +216,67 @@ class Scenario(SQLSubModel):
|
|||||||
|
|
||||||
return True
|
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, [])
|
||||||
|
|
||||||
|
@timer
|
||||||
|
def clean_deleted_data(self, execute):
|
||||||
|
tables = self.tables_with_deleted_column
|
||||||
|
branch = self.get_parent_branch()
|
||||||
|
|
||||||
|
all_ids = []
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
ids = flatten(ids)
|
||||||
|
|
||||||
|
logger.debug(
|
||||||
|
f"({self.name}) Drop deleted data into '{table}' : {ids}"
|
||||||
|
)
|
||||||
|
|
||||||
|
execute(
|
||||||
|
f"DELETE FROM {table} " +
|
||||||
|
f"WHERE scenario = {self.id} " +
|
||||||
|
"AND pamhyr_id IN " +
|
||||||
|
f"({', '.join(map(str, ids))})"
|
||||||
|
)
|
||||||
|
|
||||||
|
all_ids += ids
|
||||||
|
|
||||||
|
return all_ids
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def id(self):
|
def id(self):
|
||||||
return self._id
|
return self._id
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
from tools import logger_exception
|
from tools import logger_exception
|
||||||
|
|
||||||
from Model.Tools.PamhyrDict import PamhyrModelDict
|
from Model.Tools.PamhyrDict import PamhyrModelDict
|
||||||
@@ -78,3 +80,12 @@ class Scenarios(PamhyrModelDict):
|
|||||||
|
|
||||||
self._dict[key].set_as_deleted()
|
self._dict[key].set_as_deleted()
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
|
def is_leaf(self, scenario):
|
||||||
|
return not reduce(
|
||||||
|
lambda acc, s: (
|
||||||
|
acc or (not s.is_deleted() and s.parent is scenario)
|
||||||
|
),
|
||||||
|
self._dict.values(),
|
||||||
|
False
|
||||||
|
)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# Serializable.py -- Pamhyr pickle abstract class
|
# Serializable.py -- Pamhyr pickle abstract class
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# SolverParametersList.py -- Pamhyr
|
# SolverParametersList.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+14
-1
@@ -1,5 +1,5 @@
|
|||||||
# Status.py -- Pamhyr model status class
|
# Status.py -- Pamhyr model status class
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -34,6 +34,7 @@ class StudyStatus(object):
|
|||||||
self._status = Status.EDIT
|
self._status = Status.EDIT
|
||||||
self._scenario = scenario
|
self._scenario = scenario
|
||||||
self._saved = True
|
self._saved = True
|
||||||
|
self._loading = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def scenario_id(self):
|
def scenario_id(self):
|
||||||
@@ -86,6 +87,15 @@ class StudyStatus(object):
|
|||||||
def is_saved(self):
|
def is_saved(self):
|
||||||
return self._saved
|
return self._saved
|
||||||
|
|
||||||
|
def is_loading(self):
|
||||||
|
return self._loading
|
||||||
|
|
||||||
|
def start_loading(self):
|
||||||
|
self._loading = True
|
||||||
|
|
||||||
|
def stop_loading(self):
|
||||||
|
self._loading = False
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
logger.debug("model status set as saved")
|
logger.debug("model status set as saved")
|
||||||
self._saved = True
|
self._saved = True
|
||||||
@@ -97,6 +107,9 @@ class StudyStatus(object):
|
|||||||
self._saved = True
|
self._saved = True
|
||||||
|
|
||||||
def modified(self):
|
def modified(self):
|
||||||
|
if self._loading:
|
||||||
|
return
|
||||||
|
|
||||||
if self._saved:
|
if self._saved:
|
||||||
self.version += 1
|
self.version += 1
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Stricklers.py -- Pamhyr
|
# Stricklers.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# StricklersList.py -- Pamhyr
|
# StricklersList.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+76
-6
@@ -1,5 +1,5 @@
|
|||||||
# Study.py -- Pamhyr Study class
|
# Study.py -- Pamhyr Study class
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -24,12 +24,21 @@ from datetime import datetime
|
|||||||
from tools import timer, timestamp
|
from tools import timer, timestamp
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
|
||||||
|
from Model.Tools.PamhyrListExt import PamhyrModelList
|
||||||
|
from Model.Tools.PamhyrDict import PamhyrModelDict
|
||||||
from Model.Tools.PamhyrDB import SQLModel
|
from Model.Tools.PamhyrDB import SQLModel
|
||||||
from Model.Scenarios import Scenarios
|
from Model.Scenarios import Scenarios
|
||||||
from Model.Scenario import Scenario
|
from Model.Scenario import Scenario
|
||||||
from Model.Status import StudyStatus
|
from Model.Status import StudyStatus
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
from Model.River import River
|
from Model.River import River
|
||||||
|
from Model.Geometry.Reach import Reach
|
||||||
|
from Model.HydraulicStructures.HydraulicStructures import (
|
||||||
|
HydraulicStructure
|
||||||
|
)
|
||||||
|
from Model.HydraulicStructures.Basic.HydraulicStructures import (
|
||||||
|
BasicHS
|
||||||
|
)
|
||||||
|
|
||||||
from Checker.Study import *
|
from Checker.Study import *
|
||||||
|
|
||||||
@@ -37,7 +46,7 @@ logger = logging.getLogger()
|
|||||||
|
|
||||||
|
|
||||||
class Study(SQLModel):
|
class Study(SQLModel):
|
||||||
_version = "0.2.3"
|
_version = "0.2.7"
|
||||||
|
|
||||||
_sub_classes = [
|
_sub_classes = [
|
||||||
Scenario,
|
Scenario,
|
||||||
@@ -449,8 +458,60 @@ class Study(SQLModel):
|
|||||||
[self.scenarios, self._river],
|
[self.scenarios, self._river],
|
||||||
data=progress
|
data=progress
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Clear DB for current scenario
|
||||||
|
ids = self.status.scenario.clean_deleted_data(self.execute)
|
||||||
|
self.memory_clean(ids)
|
||||||
|
|
||||||
|
progress()
|
||||||
|
|
||||||
self.commit()
|
self.commit()
|
||||||
|
|
||||||
|
@timer
|
||||||
|
def memory_clean(self, ids):
|
||||||
|
if len(ids) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
reach_class = Reach
|
||||||
|
hs_classes = [HydraulicStructure, BasicHS]
|
||||||
|
list_classes = set(PamhyrModelList.__subclasses__())
|
||||||
|
dict_classes = set(PamhyrModelDict.__subclasses__())
|
||||||
|
|
||||||
|
def modifier(obj, data):
|
||||||
|
t = type(obj)
|
||||||
|
|
||||||
|
if t is reach_class:
|
||||||
|
obj._profiles = list(
|
||||||
|
filter(
|
||||||
|
lambda el: el.id not in ids,
|
||||||
|
obj._profiles
|
||||||
|
)
|
||||||
|
)
|
||||||
|
elif t in hs_classes:
|
||||||
|
obj._data = list(
|
||||||
|
filter(
|
||||||
|
lambda el: el.id not in ids,
|
||||||
|
obj._data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
elif t in dict_classes:
|
||||||
|
new = {}
|
||||||
|
for key in obj._dict:
|
||||||
|
if obj._dict[key].id not in ids:
|
||||||
|
new[key] = obj._dict[key]
|
||||||
|
obj._dict = new
|
||||||
|
elif t in list_classes:
|
||||||
|
obj._lst = list(
|
||||||
|
filter(
|
||||||
|
lambda el: el.id not in ids,
|
||||||
|
obj._lst
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.river._data_traversal(
|
||||||
|
lambda o, d: True, modifier, {}
|
||||||
|
)
|
||||||
|
|
||||||
def sql_save_request_count(self, *args, **kargs):
|
def sql_save_request_count(self, *args, **kargs):
|
||||||
return self._count()
|
return self._count()
|
||||||
|
|
||||||
@@ -459,7 +520,10 @@ class Study(SQLModel):
|
|||||||
[self.scenarios, self._river]
|
[self.scenarios, self._river]
|
||||||
)
|
)
|
||||||
logger.debug(cnt)
|
logger.debug(cnt)
|
||||||
return cnt + 7
|
# HACK: 8 is the number of SQL request do and dont counted in
|
||||||
|
# submodel save_count (let's count sql execute into the
|
||||||
|
# '_save' method)
|
||||||
|
return cnt + 8
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Close db connection
|
"""Close db connection
|
||||||
@@ -485,7 +549,8 @@ class Study(SQLModel):
|
|||||||
self.status.scenario = scenario
|
self.status.scenario = scenario
|
||||||
|
|
||||||
if reduce(
|
if reduce(
|
||||||
lambda a, s: a or (s.parent is scenario),
|
lambda a, s: a or (s.parent is scenario
|
||||||
|
and not s.is_deleted()),
|
||||||
self.scenarios.lst,
|
self.scenarios.lst,
|
||||||
False
|
False
|
||||||
):
|
):
|
||||||
@@ -511,16 +576,21 @@ class Study(SQLModel):
|
|||||||
"scenario": scenario
|
"scenario": scenario
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.status.start_loading()
|
||||||
|
try:
|
||||||
# Load river data
|
# Load river data
|
||||||
river = River._db_load(
|
river = River._db_load(
|
||||||
sql_exec, data=data
|
sql_exec, data=data
|
||||||
)
|
)
|
||||||
data["study"] = self
|
data["study"] = self
|
||||||
river._db_load_results(sql_exec, data=data)
|
river._db_load_results(sql_exec, data=data)
|
||||||
|
finally:
|
||||||
self._river_scenario_cache[scenario] = river
|
self.status.stop_loading()
|
||||||
self.status.scenario = old_scenario
|
self.status.scenario = old_scenario
|
||||||
|
|
||||||
|
# FIXME: Disable scenario cache to save memory usage
|
||||||
|
# self._river_scenario_cache[scenario] = river
|
||||||
|
|
||||||
return river
|
return river
|
||||||
|
|
||||||
def copy_from_scenario(self, scenario):
|
def copy_from_scenario(self, scenario):
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# PamhyrDB.py -- Pamhyr abstract model database classes
|
# PamhyrDB.py -- Pamhyr abstract model database classes
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -26,6 +26,8 @@ from functools import reduce
|
|||||||
from SQL import SQL
|
from SQL import SQL
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
|
from tools import trace
|
||||||
|
|
||||||
from Model.Tools.PamhyrID import PamhyrID
|
from Model.Tools.PamhyrID import PamhyrID
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
@@ -48,11 +50,9 @@ class SQLModel(SQL):
|
|||||||
self._cur = self._db.cursor()
|
self._cur = self._db.cursor()
|
||||||
|
|
||||||
if is_new:
|
if is_new:
|
||||||
logger.info("Create database")
|
|
||||||
self._create() # Create db
|
self._create() # Create db
|
||||||
# self._save() # Save
|
# self._save() # Save
|
||||||
else:
|
else:
|
||||||
logger.info("Update database")
|
|
||||||
self._update() # Update db scheme if necessary
|
self._update() # Update db scheme if necessary
|
||||||
# self._load() # Load data
|
# self._load() # Load data
|
||||||
|
|
||||||
@@ -202,6 +202,8 @@ class SQLSubModel(PamhyrID):
|
|||||||
"""
|
"""
|
||||||
if self._status is None:
|
if self._status is None:
|
||||||
return
|
return
|
||||||
|
if self._status.is_loading():
|
||||||
|
return
|
||||||
|
|
||||||
self._owner_scenario = self._status.scenario_id
|
self._owner_scenario = self._status.scenario_id
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
@@ -218,6 +220,8 @@ class SQLSubModel(PamhyrID):
|
|||||||
"""
|
"""
|
||||||
if self._status is None:
|
if self._status is None:
|
||||||
return
|
return
|
||||||
|
if self._status.is_loading():
|
||||||
|
return
|
||||||
|
|
||||||
self._owner_scenario = self._status.scenario_id
|
self._owner_scenario = self._status.scenario_id
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
@@ -297,6 +301,15 @@ class SQLSubModel(PamhyrID):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedMethodeError(cls, cls._db_update)
|
raise NotImplementedMethodeError(cls, cls._db_update)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def is_table_exists(cls, execute, table):
|
||||||
|
return any(
|
||||||
|
execute(
|
||||||
|
"SELECT name FROM sqlite_master " +
|
||||||
|
f"WHERE type='table' AND name='{table}'"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_update_to_0_2_0_set_node_pid(cls, execute, table, nodes):
|
def _db_update_to_0_2_0_set_node_pid(cls, execute, table, nodes):
|
||||||
els = execute(
|
els = execute(
|
||||||
@@ -311,6 +324,14 @@ class SQLSubModel(PamhyrID):
|
|||||||
if node_id == -1:
|
if node_id == -1:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if node_id not in nodes:
|
||||||
|
# ⚠️ cas important : probablement déjà migré
|
||||||
|
logger.warning(
|
||||||
|
f"node_id {node_id} not in nodes " +
|
||||||
|
"→ probably already migrated"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
f"UPDATE {table} " +
|
f"UPDATE {table} " +
|
||||||
f"SET node = {nodes[node_id]} " +
|
f"SET node = {nodes[node_id]} " +
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# PamhyrDict.py -- Pamhyr abstract dict for model classes
|
# PamhyrDict.py -- Pamhyr abstract dict for model classes
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -97,6 +97,9 @@ class PamhyrModelDict(SQLSubModel):
|
|||||||
Nothing
|
Nothing
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if predicate(self, data):
|
||||||
|
modifier(self, data)
|
||||||
|
|
||||||
for key in self._dict:
|
for key in self._dict:
|
||||||
self._dict[key]\
|
self._dict[key]\
|
||||||
._data_traversal(predicate, modifier, data)
|
._data_traversal(predicate, modifier, data)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# PamhyrList.py -- Pamhyr Abstract List object for the Model
|
# PamhyrList.py -- Pamhyr Abstract List object for the Model
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -100,6 +100,9 @@ class PamhyrModelList(SQLSubModel):
|
|||||||
Nothing
|
Nothing
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if predicate(self, data):
|
||||||
|
modifier(self, data)
|
||||||
|
|
||||||
for el in self._lst:
|
for el in self._lst:
|
||||||
el._data_traversal(predicate, modifier, data)
|
el._data_traversal(predicate, modifier, data)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# PamhyrList.py -- Pamhyr Abstract List object for the Model
|
# PamhyrList.py -- Pamhyr Abstract List object for the Model
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -107,6 +107,9 @@ class PamhyrModelList(SQLSubModel):
|
|||||||
Returns:
|
Returns:
|
||||||
Nothing
|
Nothing
|
||||||
"""
|
"""
|
||||||
|
if predicate(self, data):
|
||||||
|
modifier(self, data)
|
||||||
|
|
||||||
for el in self._lst:
|
for el in self._lst:
|
||||||
el._data_traversal(predicate, modifier, data)
|
el._data_traversal(predicate, modifier, data)
|
||||||
|
|
||||||
@@ -168,7 +171,7 @@ class PamhyrModelList(SQLSubModel):
|
|||||||
lambda x: x[1],
|
lambda x: x[1],
|
||||||
filter(
|
filter(
|
||||||
lambda x: x[0] in indexes,
|
lambda x: x[0] in indexes,
|
||||||
enumerate(self._lst)
|
enumerate(self.lst)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# __init__.py -- Pamhyr
|
# __init__.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# test_Model.py -- Pamhyr
|
# test_Model.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
# SQL.py -- Pamhyr
|
# SQL.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# AScript.py -- Pamhyr abstract script class
|
# AScript.py -- Pamhyr abstract script class
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Hello.py -- Pamhyr
|
# Hello.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# ListSolver.py -- Pamhyr
|
# ListSolver.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# MageMesh.py -- Pamhyr
|
# MageMesh.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# P3DST.py -- Pamhyr
|
# P3DST.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
# Run.py -- Pamhyr
|
# Run.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,3 +1,20 @@
|
|||||||
|
# mage_to_mascaret.py -- Pamhyr
|
||||||
|
# Copyright (C) 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 -*-
|
||||||
#!/bin/env python3
|
#!/bin/env python3
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@@ -336,6 +353,3 @@ if __name__ == "__main__":
|
|||||||
print( 'Number of arguments:', len(sys.argv), 'arguments.')
|
print( 'Number of arguments:', len(sys.argv), 'arguments.')
|
||||||
print( 'Argument List:', str(sys.argv))
|
print( 'Argument List:', str(sys.argv))
|
||||||
mage_to_mascaret(sys.argv[1])
|
mage_to_mascaret(sys.argv[1])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,3 +1,20 @@
|
|||||||
|
# mascaret_to_mage.py -- Pamhyr
|
||||||
|
# Copyright (C) 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 -*-
|
||||||
#!/bin/env python3
|
#!/bin/env python3
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# ASolver.py -- Pamhyr
|
# ASolver.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+207
-53
@@ -1,5 +1,5 @@
|
|||||||
# AdisTS.py -- Pamhyr
|
# AdisTS.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -164,13 +164,194 @@ class AdisTS(CommandLineSolver):
|
|||||||
return lst
|
return lst
|
||||||
|
|
||||||
def input_param(self):
|
def input_param(self):
|
||||||
name = self._study.name
|
name = self._study.name.replace(" ", "_")
|
||||||
return f"{name}.REP"
|
return f"{name}.REP"
|
||||||
|
|
||||||
def log_file(self):
|
def log_file(self):
|
||||||
name = self._study.name
|
name = self._study.name.replace(" ", "_")
|
||||||
return f"{name}.TRA"
|
return f"{name}.TRA"
|
||||||
|
|
||||||
|
def _export_ST(self, study, repertory, qlog, name="0"):
|
||||||
|
files = []
|
||||||
|
|
||||||
|
if qlog is not None:
|
||||||
|
qlog.put("Export ST file")
|
||||||
|
|
||||||
|
os.makedirs(os.path.join(repertory, "net"), exist_ok=True)
|
||||||
|
|
||||||
|
# Write header
|
||||||
|
edges = study.river.enable_edges()
|
||||||
|
for edge in edges:
|
||||||
|
name = f"Reach_{edge.id + 1:>3}".replace(" ", "0")
|
||||||
|
|
||||||
|
with adists_file_open(
|
||||||
|
os.path.join(repertory, "net", f"{name}.ST"),
|
||||||
|
"w+"
|
||||||
|
) as f:
|
||||||
|
files.append(str(os.path.join("net", f"{name}.ST")))
|
||||||
|
|
||||||
|
cnt_num = 1
|
||||||
|
for profile in edge.reach.profiles:
|
||||||
|
self._export_ST_profile_header(
|
||||||
|
f, files, profile, cnt_num
|
||||||
|
)
|
||||||
|
cnt_num += 1
|
||||||
|
|
||||||
|
# Points
|
||||||
|
for point in profile.points:
|
||||||
|
self._export_ST_point_line(
|
||||||
|
f, files, point
|
||||||
|
)
|
||||||
|
|
||||||
|
# Profile last line
|
||||||
|
f.write(f" 999.9990 999.9990 999.9990\n")
|
||||||
|
|
||||||
|
def _export_ST_profile_header(self, wfile, files,
|
||||||
|
profile, cnt):
|
||||||
|
num = f"{cnt:>6}"
|
||||||
|
c1 = f"{profile.code1:>6}"
|
||||||
|
c2 = f"{profile.code2:>6}"
|
||||||
|
t = f"{len(profile.points):>6}"
|
||||||
|
rk = f"{profile.rk:>12f}"[0:12]
|
||||||
|
pname = profile.name
|
||||||
|
if profile.name == "":
|
||||||
|
# Generate name from profile id prefixed with
|
||||||
|
# 'p' (and replace space char with '0' char)
|
||||||
|
pname = f"p{profile.id:>3}".replace(" ", "0")
|
||||||
|
name = f"{pname:<19}"
|
||||||
|
|
||||||
|
# Generate sediment additional data if available
|
||||||
|
sediment = ""
|
||||||
|
if profile.sl is not None:
|
||||||
|
if not any(filter(lambda f: ".GRA" in f, files)):
|
||||||
|
files.append(self._gra_file)
|
||||||
|
|
||||||
|
# Number of layers
|
||||||
|
nl = len(profile.sl)
|
||||||
|
sediment = f" {nl:>3}"
|
||||||
|
|
||||||
|
# Layers data
|
||||||
|
for layer in profile.sl.layers:
|
||||||
|
sediment += (
|
||||||
|
f" {layer.height:>10} {layer.d50:>10} " +
|
||||||
|
f"{layer.sigma:>10} " +
|
||||||
|
f"{layer.critical_constraint:>10}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Profile header line
|
||||||
|
wfile.write(f"{num}{c1}{c2}{t} {rk} {pname} {sediment}\n")
|
||||||
|
|
||||||
|
def _export_ST_point_line(self, wfile, files, point):
|
||||||
|
x = f"{point.x:<12.4f}"[0:12]
|
||||||
|
y = f"{point.y:<12.4f}"[0:12]
|
||||||
|
z = f"{point.z:<12.4f}"[0:12]
|
||||||
|
n = f"{point.name:<3}"
|
||||||
|
|
||||||
|
# Generate sediment additional data if available
|
||||||
|
sediment = ""
|
||||||
|
prev = point.z
|
||||||
|
if point.sl is not None:
|
||||||
|
# Number of layers
|
||||||
|
nl = len(point.sl)
|
||||||
|
sediment = f"{nl:>3}"
|
||||||
|
|
||||||
|
# Layers data
|
||||||
|
for layer in point.sl.layers:
|
||||||
|
prev = round(prev - layer.height, 5)
|
||||||
|
sediment += (
|
||||||
|
f" {prev:>10} {layer.d50:>10} " +
|
||||||
|
f"{layer.sigma:>10} " +
|
||||||
|
f"{layer.critical_constraint:>10}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Point line
|
||||||
|
wfile.write(f"{x} {y} {z} {n} {sediment}\n")
|
||||||
|
|
||||||
|
def _export_NET(self, study, repertory, qlog=None, name="0"):
|
||||||
|
|
||||||
|
if qlog is not None:
|
||||||
|
qlog.put("Export NET file")
|
||||||
|
|
||||||
|
with adists_file_open(
|
||||||
|
os.path.join(repertory, f"{name}.NET"), "w+") as f:
|
||||||
|
edges = study.river.enable_edges()
|
||||||
|
|
||||||
|
for e in edges:
|
||||||
|
name = f"Reach_{e.id + 1:>3}".replace(" ", "0")
|
||||||
|
id = name
|
||||||
|
|
||||||
|
n1 = f"{self.get_node_name(e.node1):3}".replace(" ", "x")
|
||||||
|
n2 = f"{self.get_node_name(e.node2):3}".replace(" ", "x")
|
||||||
|
file = os.path.join("net", name + ".ST")
|
||||||
|
|
||||||
|
f.write(f"{id} {n1} {n2} {file}\n")
|
||||||
|
|
||||||
|
def _export_fake_INI(self, study, repertory, qlog=None, name="0"):
|
||||||
|
if qlog is not None:
|
||||||
|
qlog.put("Export fake INI file")
|
||||||
|
|
||||||
|
with adists_file_open(
|
||||||
|
os.path.join(
|
||||||
|
repertory, "Mage_fin.ini"
|
||||||
|
), "w+"
|
||||||
|
) as f:
|
||||||
|
edges = study.river.enable_edges()
|
||||||
|
for i, edge in enumerate(edges):
|
||||||
|
lst = list(filter(
|
||||||
|
lambda f: f.is_full_defined(),
|
||||||
|
edge.frictions.frictions
|
||||||
|
))
|
||||||
|
rk_min = 9999999.9
|
||||||
|
rk_max = -9999999.9
|
||||||
|
coeff_min = -1.0
|
||||||
|
coeff_max = -1.0
|
||||||
|
for s in lst: # TODO optimise ?
|
||||||
|
if s.begin_rk > rk_max:
|
||||||
|
rk_max = s.begin_rk
|
||||||
|
coeff_max = s.begin_strickler
|
||||||
|
if s.begin_rk < rk_min:
|
||||||
|
rk_min = s.begin_rk
|
||||||
|
coeff_min = s.begin_strickler
|
||||||
|
if s.end_rk > rk_max:
|
||||||
|
rk_max = s.end_rk
|
||||||
|
coeff_max = s.end_strickler
|
||||||
|
if s.end_rk < rk_min:
|
||||||
|
rk_min = s.end_rk
|
||||||
|
coeff_min = s.end_strickler
|
||||||
|
|
||||||
|
print("min max", rk_min, rk_max)
|
||||||
|
|
||||||
|
def get_stricklers_from_rk(rk, lst):
|
||||||
|
print("rk", rk)
|
||||||
|
|
||||||
|
coeff = None
|
||||||
|
if rk > rk_max:
|
||||||
|
coeff = coeff_max
|
||||||
|
elif rk < rk_min:
|
||||||
|
coeff = coeff_min
|
||||||
|
else:
|
||||||
|
for s in lst:
|
||||||
|
if (rk >= s.begin_rk and rk <= s.end_rk or
|
||||||
|
rk <= s.begin_rk and rk >= s.end_rk):
|
||||||
|
coeff = s.begin_strickler # TODO: inerpolate
|
||||||
|
break
|
||||||
|
|
||||||
|
# TODO interpolation if rk is not in frictons
|
||||||
|
|
||||||
|
if coeff is None:
|
||||||
|
logger.error(
|
||||||
|
"Study frictions are not fully defined"
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
return coeff.minor, coeff.medium
|
||||||
|
|
||||||
|
for j, profile in enumerate(edge.reach.profiles):
|
||||||
|
coef_min, coef_moy = get_stricklers_from_rk(profile.rk,
|
||||||
|
lst)
|
||||||
|
f.write(
|
||||||
|
f" {i+1:3}{j+1:4}{' '*116}{coef_min:9}{coef_moy:9}\n")
|
||||||
|
|
||||||
def _export_REP_additional_lines(self, study, rep_file):
|
def _export_REP_additional_lines(self, study, rep_file):
|
||||||
lines = filter(
|
lines = filter(
|
||||||
lambda line: line.is_enabled(),
|
lambda line: line.is_enabled(),
|
||||||
@@ -192,7 +373,7 @@ class AdisTS(CommandLineSolver):
|
|||||||
), "w+"
|
), "w+"
|
||||||
) as f:
|
) as f:
|
||||||
path = os.path.join("..", mage_rep, name)
|
path = os.path.join("..", mage_rep, name)
|
||||||
f.write(f"NET {path}.NET\n")
|
f.write(f"NET {name}.NET\n")
|
||||||
f.write(f"REP {path}.REP\n")
|
f.write(f"REP {path}.REP\n")
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
@@ -201,13 +382,25 @@ class AdisTS(CommandLineSolver):
|
|||||||
|
|
||||||
self._export_REP_additional_lines(study, f)
|
self._export_REP_additional_lines(study, f)
|
||||||
|
|
||||||
path_mage_net = os.path.join(os.path.abspath(
|
self._export_ST(study, repertory, qlog, name=name)
|
||||||
os.path.join(repertory, os.pardir)
|
self._export_NET(study, repertory, qlog, name=name)
|
||||||
), os.path.join(mage_rep, "net"))
|
|
||||||
path_adists_net = os.path.join(repertory, "net")
|
|
||||||
|
|
||||||
if os.path.exists(path_mage_net):
|
# fake mage_fin.ini:
|
||||||
shutil.copytree(path_mage_net, path_adists_net, dirs_exist_ok=True)
|
|
||||||
|
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(
|
||||||
|
# os.path.join(repertory, os.pardir)
|
||||||
|
# ), os.path.join(mage_rep, "net"))
|
||||||
|
# path_adists_net = os.path.join(repertory, "net")
|
||||||
|
|
||||||
|
# if os.path.exists(path_mage_net):
|
||||||
|
# shutil.copytree(path_mage_net,
|
||||||
|
# path_adists_net,
|
||||||
|
# dirs_exist_ok=True)
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def export(self, study, repertory, qlog=None):
|
def export(self, study, repertory, qlog=None):
|
||||||
@@ -262,47 +455,6 @@ class AdisTS(CommandLineSolver):
|
|||||||
def get_reach_name(self, reach):
|
def get_reach_name(self, reach):
|
||||||
return f"Reach_{reach.pamhyr_id:>3}".replace(" ", "0")
|
return f"Reach_{reach.pamhyr_id:>3}".replace(" ", "0")
|
||||||
|
|
||||||
def get_node_name(self, node):
|
|
||||||
"""Generate a 3 char name for node
|
|
||||||
|
|
||||||
Args:
|
|
||||||
node: The node
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
A 3 char name string
|
|
||||||
"""
|
|
||||||
n = node.pamhyr_id
|
|
||||||
|
|
||||||
# print("node name id: ", n)
|
|
||||||
|
|
||||||
# if n in self._nodes_names:
|
|
||||||
# return self._nodes_names[n]
|
|
||||||
|
|
||||||
name = ""
|
|
||||||
|
|
||||||
checked_new = False
|
|
||||||
while not checked_new:
|
|
||||||
self._nodes_cnt += 1
|
|
||||||
nc = self._nodes_cnt
|
|
||||||
|
|
||||||
name = "".join(
|
|
||||||
map(
|
|
||||||
lambda i: self._alph[i % self._l_alph],
|
|
||||||
[
|
|
||||||
int(nc / (self._l_alph * self._l_alph)),
|
|
||||||
int(nc / self._l_alph),
|
|
||||||
nc
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
checked_new = name not in self._nodes_views
|
|
||||||
|
|
||||||
self._nodes_views.add(name)
|
|
||||||
self._nodes_names[n] = name
|
|
||||||
|
|
||||||
return name
|
|
||||||
|
|
||||||
#################################
|
#################################
|
||||||
# Adis-TS in weak coupling mode #
|
# Adis-TS in weak coupling mode #
|
||||||
#################################
|
#################################
|
||||||
@@ -793,6 +945,7 @@ class AdisTSwc(AdisTS):
|
|||||||
for file_bin in path_files:
|
for file_bin in path_files:
|
||||||
key_pol = os.path.basename(file_bin)[0:-4]
|
key_pol = os.path.basename(file_bin)[0:-4]
|
||||||
data_tmp[key_pol] = {}
|
data_tmp[key_pol] = {}
|
||||||
|
logger.info(f"read_bin: Start reading '{file_bin}' ...")
|
||||||
with open(file_bin, 'rb') as f:
|
with open(file_bin, 'rb') as f:
|
||||||
# header
|
# header
|
||||||
# first line
|
# first line
|
||||||
@@ -844,7 +997,9 @@ class AdisTSwc(AdisTS):
|
|||||||
# seventh line (useless)
|
# seventh line (useless)
|
||||||
for k in range(0, ismax, kbl):
|
for k in range(0, ismax, kbl):
|
||||||
data = np.fromfile(f, dtype=np.int32, count=1) # (start)
|
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)
|
data = np.fromfile(f, dtype=np.int32, count=1) # (end)
|
||||||
# end header
|
# end header
|
||||||
# data
|
# data
|
||||||
@@ -875,7 +1030,6 @@ class AdisTSwc(AdisTS):
|
|||||||
for r, reach in enumerate(reachs):
|
for r, reach in enumerate(reachs):
|
||||||
for i in range(is1[r]-1, is2[r]):
|
for i in range(is1[r]-1, is2[r]):
|
||||||
p_i = ip_to_ri(reach, i)
|
p_i = ip_to_ri(reach, i)
|
||||||
|
|
||||||
for t_data in timestamps_keys:
|
for t_data in timestamps_keys:
|
||||||
pol_view = []
|
pol_view = []
|
||||||
for pol in pollutants_keys:
|
for pol in pollutants_keys:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# CommandLine.py -- Pamhyr
|
# CommandLine.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# GenericSolver.py -- Pamhyr
|
# GenericSolver.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
+121
-51
@@ -1,5 +1,5 @@
|
|||||||
# Mage.py -- Pamhyr
|
# Mage.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -19,6 +19,8 @@
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import time
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from tools import timer, trace, logger_exception
|
from tools import timer, trace, logger_exception
|
||||||
@@ -325,7 +327,7 @@ class Mage(CommandLineSolver):
|
|||||||
v0 = d[0]
|
v0 = d[0]
|
||||||
v1 = d[1]
|
v1 = d[1]
|
||||||
|
|
||||||
if t in ["HYD", "QSO", "LIM"]:
|
if t in ["HYD", "LIM"]:
|
||||||
v0 /= 60 # Convert first column to minute
|
v0 /= 60 # Convert first column to minute
|
||||||
|
|
||||||
f.write(f"{v0:9} {v1:9} \n")
|
f.write(f"{v0:9} {v1:9} \n")
|
||||||
@@ -384,26 +386,26 @@ class Mage(CommandLineSolver):
|
|||||||
return files
|
return files
|
||||||
|
|
||||||
def _export_LC(self, study, lateral, f, qlog, name="0"):
|
def _export_LC(self, study, lateral, f, qlog, name="0"):
|
||||||
if lateral.edge is None:
|
if lateral.reach is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if lateral.is_deleted():
|
if lateral.is_deleted():
|
||||||
return
|
return
|
||||||
|
|
||||||
edges = study.river.enable_edges()
|
edges = study.river.enable_edges()
|
||||||
if lateral.edge not in edges:
|
if lateral.reach not in edges:
|
||||||
return
|
return
|
||||||
|
|
||||||
eid, _ = next(
|
eid, _ = next(
|
||||||
filter(
|
filter(
|
||||||
lambda e: e[1] == lateral.edge,
|
lambda e: e[1] == lateral.reach,
|
||||||
enumerate(edges)
|
enumerate(edges)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
name = f"{eid+1:>3}"
|
name = f"{eid+1:>3}"
|
||||||
# name = f"Reach_{lateral.edge.id + 1:>3}".replace(" ", "0")
|
# name = f"Reach_{lateral.reach.id + 1:>3}".replace(" ", "0")
|
||||||
f.write(f"* {lateral.edge.name} ({name}) {lateral.lctype}\n")
|
f.write(f"* {lateral.reach.name} ({name}) {lateral.lctype}\n")
|
||||||
f.write(
|
f.write(
|
||||||
f"${name} " +
|
f"${name} " +
|
||||||
f"{lateral.begin_rk:>10.4f} {lateral.end_rk:>10.4f}\n"
|
f"{lateral.begin_rk:>10.4f} {lateral.end_rk:>10.4f}\n"
|
||||||
@@ -544,6 +546,15 @@ class Mage(CommandLineSolver):
|
|||||||
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
def skip_hs(self, hs):
|
||||||
|
return (
|
||||||
|
hs.input_reach is None
|
||||||
|
or not hs.input_reach.is_enable()
|
||||||
|
or not hs.enabled
|
||||||
|
or hs.input_section is None
|
||||||
|
or hs.is_deleted()
|
||||||
|
)
|
||||||
|
|
||||||
def _export_SIN(self, study, repertory, qlog, name="0"):
|
def _export_SIN(self, study, repertory, qlog, name="0"):
|
||||||
files = []
|
files = []
|
||||||
|
|
||||||
@@ -569,19 +580,7 @@ class Mage(CommandLineSolver):
|
|||||||
files.append(f"{name}.SIN")
|
files.append(f"{name}.SIN")
|
||||||
|
|
||||||
for hs in hydraulic_structures:
|
for hs in hydraulic_structures:
|
||||||
if hs.input_reach is None:
|
if self.skip_hs(hs):
|
||||||
continue
|
|
||||||
|
|
||||||
if not hs.input_reach.is_enable():
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not hs.enabled:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if hs.input_section is None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if hs.is_deleted():
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
f.write(
|
f.write(
|
||||||
@@ -988,7 +987,7 @@ class Mage8(Mage):
|
|||||||
|
|
||||||
# Data
|
# Data
|
||||||
for d in bound.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
|
return files
|
||||||
|
|
||||||
@@ -1035,6 +1034,7 @@ class Mage8(Mage):
|
|||||||
@timer
|
@timer
|
||||||
def read_bin(self, study, fname, results, qlog=None, name="0"):
|
def read_bin(self, study, fname, results, qlog=None, name="0"):
|
||||||
logger.info(f"read_bin: Start reading '{fname}' ...")
|
logger.info(f"read_bin: Start reading '{fname}' ...")
|
||||||
|
start = time.time()
|
||||||
|
|
||||||
with mage_file_open(fname, "r") as f:
|
with mage_file_open(fname, "r") as f:
|
||||||
def newline(): return np.fromfile(f, dtype=np.int32, count=1)
|
def newline(): return np.fromfile(f, dtype=np.int32, count=1)
|
||||||
@@ -1083,7 +1083,7 @@ class Mage8(Mage):
|
|||||||
newline()
|
newline()
|
||||||
|
|
||||||
reachs = []
|
reachs = []
|
||||||
iprofiles = {}
|
iprofiles = []
|
||||||
profile_len = []
|
profile_len = []
|
||||||
reach_offset = {}
|
reach_offset = {}
|
||||||
|
|
||||||
@@ -1098,15 +1098,18 @@ class Mage8(Mage):
|
|||||||
i1 = data[2*i] - 1
|
i1 = data[2*i] - 1
|
||||||
i2 = data[2*i+1] - 1
|
i2 = data[2*i+1] - 1
|
||||||
|
|
||||||
|
# Keep profiles index of all river
|
||||||
|
r.set_global_index(range(i1, i2 + 1))
|
||||||
|
|
||||||
# Add profile id correspondance to reach
|
# Add profile id correspondance to reach
|
||||||
key = (i1, i2)
|
for key in range(i1, i2 + 1):
|
||||||
iprofiles[key] = r
|
iprofiles.append(i)
|
||||||
|
|
||||||
# Profile ID offset
|
# Profile ID offset
|
||||||
reach_offset[r] = i1
|
reach_offset[r] = i1
|
||||||
profile_len.append(i2-i1+1)
|
profile_len.append(i2 - i1 + 1)
|
||||||
|
|
||||||
logger.debug(f"read_bin: iprofiles = {iprofiles}")
|
logger.debug(f"read_bin: iprofiles = {len(iprofiles)}")
|
||||||
|
|
||||||
endline()
|
endline()
|
||||||
|
|
||||||
@@ -1117,22 +1120,13 @@ class Mage8(Mage):
|
|||||||
|
|
||||||
# Z and Y (4th line)
|
# Z and Y (4th line)
|
||||||
newline()
|
newline()
|
||||||
_ = read_float(3*nb_profile)
|
tmp = read_float(3*nb_profile)
|
||||||
|
zfd = tmp[::3]
|
||||||
endline()
|
endline()
|
||||||
|
|
||||||
# Data
|
# Data
|
||||||
newline()
|
newline()
|
||||||
|
|
||||||
def ip_to_r(i): return iprofiles[
|
|
||||||
next(
|
|
||||||
filter(
|
|
||||||
lambda k: k[0] <= i <= k[1],
|
|
||||||
iprofiles
|
|
||||||
)
|
|
||||||
)
|
|
||||||
]
|
|
||||||
def ip_to_ri(r, i): return i - reach_offset[r]
|
|
||||||
|
|
||||||
# check results and geometry consistency
|
# check results and geometry consistency
|
||||||
for i, r in enumerate(reachs):
|
for i, r in enumerate(reachs):
|
||||||
lp = len(r.profiles)
|
lp = len(r.profiles)
|
||||||
@@ -1143,6 +1137,8 @@ class Mage8(Mage):
|
|||||||
return
|
return
|
||||||
|
|
||||||
ts = set()
|
ts = set()
|
||||||
|
tmp_table = {}
|
||||||
|
|
||||||
end = False
|
end = False
|
||||||
while not end:
|
while not end:
|
||||||
n = read_int(1)[0]
|
n = read_int(1)[0]
|
||||||
@@ -1151,18 +1147,21 @@ class Mage8(Mage):
|
|||||||
f, dtype=np.byte, count=1)).decode()
|
f, dtype=np.byte, count=1)).decode()
|
||||||
data = read_float(n)
|
data = read_float(n)
|
||||||
|
|
||||||
# logger.debug(f"read_bin: timestamp = {timestamp} sec")
|
if key not in tmp_table:
|
||||||
|
tmp_table[key] = []
|
||||||
|
|
||||||
|
tmp_table[key].append(data)
|
||||||
ts.add(timestamp)
|
ts.add(timestamp)
|
||||||
|
|
||||||
if key in ["Z", "Q"]:
|
if key in ["Z", "Q"]:
|
||||||
for i, d in enumerate(data):
|
for i, d in enumerate(data):
|
||||||
# Get reach corresponding to profile ID
|
# Get reach corresponding to profile ID
|
||||||
reach = ip_to_r(i)
|
reach = reachs[iprofiles[i]]
|
||||||
# Get profile id in reach
|
# Get profile id in reach
|
||||||
ri = ip_to_ri(reach, i)
|
ri = i - reach_offset[reach]
|
||||||
|
|
||||||
# Set data for profile RI
|
# Set data for profile RI
|
||||||
reach.set(ri, timestamp, key, d)
|
# reach.set(ri, timestamp, key, d)
|
||||||
if key == "Z":
|
if key == "Z":
|
||||||
profile = reach.profile(ri)
|
profile = reach.profile(ri)
|
||||||
limits = profile.geometry.get_water_limits(d)
|
limits = profile.geometry.get_water_limits(d)
|
||||||
@@ -1175,26 +1174,53 @@ class Mage8(Mage):
|
|||||||
endline()
|
endline()
|
||||||
end = newline().size <= 0
|
end = newline().size <= 0
|
||||||
|
|
||||||
|
ts_index = {}
|
||||||
|
for i, t in enumerate(sorted(ts)):
|
||||||
|
ts_index[t] = i
|
||||||
|
results.set_timestamp_index(ts_index)
|
||||||
|
|
||||||
|
table = {}
|
||||||
|
for k in tmp_table:
|
||||||
|
table[k] = np.array(tmp_table[k])
|
||||||
|
|
||||||
results.set("timestamps", ts)
|
results.set("timestamps", ts)
|
||||||
ts_list = sorted(ts)
|
ts_list = sorted(ts)
|
||||||
logger.info(f"compute tab...")
|
logger.info(f"compute tab...")
|
||||||
for r in reachs:
|
for r in reachs:
|
||||||
for p in r.profiles:
|
for p in r.profiles:
|
||||||
if not p.geometry.tab_up_to_date:
|
|
||||||
p.geometry.compute_tabulation()
|
p.geometry.compute_tabulation()
|
||||||
|
|
||||||
logger.info(f"compute velocily...")
|
logger.info(f"compute velocity...")
|
||||||
|
|
||||||
|
velocity_arr = np.zeros((len(ts), len(iprofiles)))
|
||||||
|
for ti, t in enumerate(ts_list):
|
||||||
|
j = 0
|
||||||
for r in reachs:
|
for r in reachs:
|
||||||
for t in ts_list:
|
for pi, p in enumerate(r.profiles):
|
||||||
for i, p in enumerate(r.profiles):
|
|
||||||
v = p.geometry.speed(
|
v = p.geometry.speed(
|
||||||
p.get_ts_key(t, "Q"),
|
table["Q"][ti, p.global_index],
|
||||||
p.get_ts_key(t, "Z")
|
table["Z"][ti, p.global_index],
|
||||||
)
|
)
|
||||||
r.set(i, t, "V", v)
|
# r.set(pi, t, "V", v)
|
||||||
|
velocity_arr[ti, j] = v
|
||||||
|
j += 1
|
||||||
|
|
||||||
|
table["V"] = velocity_arr
|
||||||
|
|
||||||
|
for legend in table:
|
||||||
|
table[legend] = results.new_table_data(
|
||||||
|
legend, table[legend]
|
||||||
|
)
|
||||||
|
|
||||||
|
results.set("table", table)
|
||||||
|
|
||||||
logger.info(f"read_bin: ... end with {len(ts)} timestamp read")
|
logger.info(f"read_bin: ... end with {len(ts)} timestamp read")
|
||||||
|
|
||||||
|
# results.bufferize("Z")
|
||||||
|
# results.bufferize("Q")
|
||||||
|
# results.bufferize("V")
|
||||||
|
logger.info(f"reading time: '{time.time() - start}'")
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def read_gra(self, study, repertory, results, qlog=None, name="0"):
|
def read_gra(self, study, repertory, results, qlog=None, name="0"):
|
||||||
if not study.river.has_sediment():
|
if not study.river.has_sediment():
|
||||||
@@ -1202,6 +1228,7 @@ class Mage8(Mage):
|
|||||||
|
|
||||||
fname = os.path.join(repertory, f"{name}.GRA")
|
fname = os.path.join(repertory, f"{name}.GRA")
|
||||||
logger.info(f"read_gra: Start reading '{fname}' ...")
|
logger.info(f"read_gra: Start reading '{fname}' ...")
|
||||||
|
start = time.time()
|
||||||
|
|
||||||
with mage_file_open(fname, "r") as f:
|
with mage_file_open(fname, "r") as f:
|
||||||
def newline(): return np.fromfile(f, dtype=np.int32, count=1)
|
def newline(): return np.fromfile(f, dtype=np.int32, count=1)
|
||||||
@@ -1261,8 +1288,8 @@ class Mage8(Mage):
|
|||||||
reachs.append(r)
|
reachs.append(r)
|
||||||
|
|
||||||
# ID of first and last reach profiles
|
# ID of first and last reach profiles
|
||||||
i1 = data[2*i] - 1
|
i1 = data[2 * i] - 1
|
||||||
i2 = data[2*i+1] - 1
|
i2 = data[2 * i + 1] - 1
|
||||||
|
|
||||||
# Add profile id correspondance to reach
|
# Add profile id correspondance to reach
|
||||||
key = (i1, i2)
|
key = (i1, i2)
|
||||||
@@ -1316,6 +1343,7 @@ class Mage8(Mage):
|
|||||||
newline()
|
newline()
|
||||||
npts = read_int(n)
|
npts = read_int(n)
|
||||||
endline()
|
endline()
|
||||||
|
|
||||||
sum_npts = sum(npts)
|
sum_npts = sum(npts)
|
||||||
logger.debug(f"read_gra: Number of points: {sum_npts}")
|
logger.debug(f"read_gra: Number of points: {sum_npts}")
|
||||||
|
|
||||||
@@ -1332,7 +1360,7 @@ class Mage8(Mage):
|
|||||||
|
|
||||||
i_pts = 0
|
i_pts = 0
|
||||||
i_data = 0
|
i_data = 0
|
||||||
# Loop on cross section
|
# Loop on cross sections
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
sec_sl = []
|
sec_sl = []
|
||||||
reach = ip_to_r(i)
|
reach = ip_to_r(i)
|
||||||
@@ -1361,8 +1389,50 @@ class Mage8(Mage):
|
|||||||
)
|
)
|
||||||
end = newline().size <= 0
|
end = newline().size <= 0
|
||||||
|
|
||||||
|
ts_list = sorted(ts)
|
||||||
|
|
||||||
|
logger.info(f"compute river bed elevation...")
|
||||||
|
|
||||||
|
zfd_lst = []
|
||||||
|
|
||||||
|
for r in reachs:
|
||||||
|
z_min = r.geometry.get_z_min()
|
||||||
|
sls = map(
|
||||||
|
lambda p: p.get_ts_key(ts_list[0], "sl")[0],
|
||||||
|
r.profiles
|
||||||
|
)
|
||||||
|
z_br = list(map(
|
||||||
|
lambda z, sl: reduce(
|
||||||
|
lambda z, h: z - h[0],
|
||||||
|
sl, z
|
||||||
|
),
|
||||||
|
z_min, # Original geometry
|
||||||
|
sls # Original sediment layers
|
||||||
|
))
|
||||||
|
for its, t in enumerate(ts_list):
|
||||||
|
sls = map(
|
||||||
|
lambda p: p.get_ts_key(t, "sl")[0],
|
||||||
|
r.profiles
|
||||||
|
)
|
||||||
|
zfd = list(map(
|
||||||
|
lambda z, sl: reduce(
|
||||||
|
lambda z, h: z + h[0],
|
||||||
|
sl, z
|
||||||
|
),
|
||||||
|
z_br, # bedrock
|
||||||
|
sls # Original sediment layers
|
||||||
|
))
|
||||||
|
|
||||||
|
zfd_lst.append(np.array(zfd))
|
||||||
|
|
||||||
|
table = results.get("table")
|
||||||
|
table["zfd"] = results.new_table_data(
|
||||||
|
"zfd", np.array(zfd_lst)
|
||||||
|
)
|
||||||
|
|
||||||
results.set("sediment_timestamps", ts)
|
results.set("sediment_timestamps", ts)
|
||||||
logger.info(f"read_gra: ... end with {len(ts)} timestamp read")
|
logger.info(f"read_gra: ... end with {len(ts)} timestamp read")
|
||||||
|
logger.debug(f"reading time: '{time.time() - start}'")
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def results(self, study, repertory,
|
def results(self, study, repertory,
|
||||||
|
|||||||
+122
-6
@@ -58,12 +58,12 @@ class Rubar3(CommandLineSolver):
|
|||||||
("rubarbe_iovis", "n"),
|
("rubarbe_iovis", "n"),
|
||||||
("rubarbe_rep", "n"),
|
("rubarbe_rep", "n"),
|
||||||
("rubarbe_tinit", "000:00:00:00"),
|
("rubarbe_tinit", "000:00:00:00"),
|
||||||
("rubarbe_tmax", "999:99:99:00"),
|
("rubarbe_tmax", "000:01:00:00"), # 1 day
|
||||||
("rubarbe_tiopdt", "000:00:00:00"),
|
("rubarbe_tiopdt", "000:00:00:00"),
|
||||||
("rubarbe_dt", "5.0"),
|
("rubarbe_dt", "5.0"),
|
||||||
("rubarbe_ts", "999:99:99:00"),
|
("rubarbe_ts", "999:99:99:00"),
|
||||||
("rubarbe_dtsauv", "00:00:00:05"),
|
("rubarbe_dtsauv", "00:00:05:00"),
|
||||||
("rubarbe_psave", "00:00:00:05"),
|
("rubarbe_psave", "00:00:05:00"),
|
||||||
("rubarbe_fdeb1", "1"),
|
("rubarbe_fdeb1", "1"),
|
||||||
("rubarbe_fdeb2", "10"),
|
("rubarbe_fdeb2", "10"),
|
||||||
("rubarbe_fdeb3", "100"),
|
("rubarbe_fdeb3", "100"),
|
||||||
@@ -426,7 +426,6 @@ class Rubar3(CommandLineSolver):
|
|||||||
coeff = coeff_min
|
coeff = coeff_min
|
||||||
else:
|
else:
|
||||||
for s in lst:
|
for s in lst:
|
||||||
print(s.begin_rk, s.end_rk)
|
|
||||||
if (rk >= s.begin_rk and rk <= s.end_rk or
|
if (rk >= s.begin_rk and rk <= s.end_rk or
|
||||||
rk <= s.begin_rk and rk >= s.end_rk):
|
rk <= s.begin_rk and rk >= s.end_rk):
|
||||||
coeff = s.begin_strickler # TODO: inerpolate
|
coeff = s.begin_strickler # TODO: inerpolate
|
||||||
@@ -473,7 +472,6 @@ class Rubar3(CommandLineSolver):
|
|||||||
last = profiles[-1]
|
last = profiles[-1]
|
||||||
|
|
||||||
if first not in data or last not in data:
|
if first not in data or last not in data:
|
||||||
print(data)
|
|
||||||
logger.error(
|
logger.error(
|
||||||
"Study initial condition is not fully defined"
|
"Study initial condition is not fully defined"
|
||||||
)
|
)
|
||||||
@@ -590,6 +588,8 @@ class Rubar3(CommandLineSolver):
|
|||||||
# Add results reach to reach list
|
# Add results reach to reach list
|
||||||
res_reach = results.river.add(i)
|
res_reach = results.river.add(i)
|
||||||
reachs.append((res_reach, len(reach) + 1))
|
reachs.append((res_reach, len(reach) + 1))
|
||||||
|
results.set("nb_reach", f"{len(reachs)}")
|
||||||
|
results.set("nb_profile", f"{sum([r[1] - 1 for r in reachs])}")
|
||||||
|
|
||||||
def read_data_line(f):
|
def read_data_line(f):
|
||||||
line = f.readline().split()
|
line = f.readline().split()
|
||||||
@@ -610,6 +610,28 @@ class Rubar3(CommandLineSolver):
|
|||||||
)
|
)
|
||||||
|
|
||||||
ts = set()
|
ts = set()
|
||||||
|
timestamp = next(filter(
|
||||||
|
lambda p: p.name == 'rubarbe_tinit',
|
||||||
|
study.river.get_params(self._type).parameters
|
||||||
|
)).value
|
||||||
|
if timestamp.count(':') == 3:
|
||||||
|
timestamp = old_pamhyr_date_to_timestamp(timestamp)
|
||||||
|
ts.add(timestamp)
|
||||||
|
|
||||||
|
# add initial condition
|
||||||
|
for r, edge in enumerate(study.river.enable_edges()):
|
||||||
|
reach = edge.reach
|
||||||
|
ics = study.river.initial_conditions.get(edge)
|
||||||
|
q = ics.get_discharge()
|
||||||
|
z = ics.get_elevation()
|
||||||
|
k = 0
|
||||||
|
for i, j in zip(z, q):
|
||||||
|
v = reach.profiles[k].speed(i, j)
|
||||||
|
set_and_compute_limites(reachs[r][0], k, i, j, v)
|
||||||
|
k += 1
|
||||||
|
|
||||||
|
# start read
|
||||||
|
|
||||||
end = False
|
end = False
|
||||||
while True:
|
while True:
|
||||||
line = f.readline()
|
line = f.readline()
|
||||||
@@ -650,13 +672,107 @@ class Rubar3(CommandLineSolver):
|
|||||||
set_and_compute_limites(reach, ind, z+h, q, s)
|
set_and_compute_limites(reach, ind, z+h, q, s)
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def results(self, study, repertory, qlog=None, name="0"):
|
def write_bin(self, study, fname, results, qlog=None, name="0"):
|
||||||
|
logger.info(f"write_bin: Start writing '{fname}' ...")
|
||||||
|
|
||||||
|
with open(fname, "wb") as f:
|
||||||
|
def newline(j): return np.asarray([j], dtype=np.int32).tofile(f)
|
||||||
|
def endline(j): return np.asarray([j], dtype=np.int32).tofile(f)
|
||||||
|
|
||||||
|
def write_int(i):
|
||||||
|
newline(len(i)*4)
|
||||||
|
np.array(i, dtype=np.int32).tofile(f)
|
||||||
|
endline(len(i)*4)
|
||||||
|
|
||||||
|
def write_float(i):
|
||||||
|
newline(len(i)*4)
|
||||||
|
np.array(i, dtype=np.float32).tofile(f)
|
||||||
|
endline(len(i)*4)
|
||||||
|
|
||||||
|
def write_float64(i):
|
||||||
|
newline(len(i)*8)
|
||||||
|
np.array(i, dtype=np.float64).tofile(f)
|
||||||
|
endline(len(i)*8)
|
||||||
|
|
||||||
|
def write_float64(i):
|
||||||
|
newline(len(i)*8)
|
||||||
|
np.array(i, dtype=np.float64).tofile(f)
|
||||||
|
endline(len(i)*8)
|
||||||
|
|
||||||
|
def write_data(npts, t, a, val):
|
||||||
|
newline(npts*4 + 13)
|
||||||
|
np.array(npts, dtype=np.int32).tofile(f)
|
||||||
|
np.array(t, dtype=np.float64).tofile(f)
|
||||||
|
np.array(bytearray(a.encode()), dtype=np.byte).tofile(f)
|
||||||
|
np.array(val, dtype=np.float32).tofile(f)
|
||||||
|
endline(npts*4 + 13)
|
||||||
|
|
||||||
|
ts_list = sorted(results.get("timestamps"))
|
||||||
|
profiles = []
|
||||||
|
for r in results.river.reachs:
|
||||||
|
profiles += r.profiles
|
||||||
|
|
||||||
|
# Meta data (1st line)
|
||||||
|
nb_reach = len(results.river)
|
||||||
|
nb_profile = len(profiles)
|
||||||
|
write_int([nb_reach, nb_profile, "82"])
|
||||||
|
|
||||||
|
# Reach information (2nd line)
|
||||||
|
is1 = []
|
||||||
|
is2 = []
|
||||||
|
ltmp = []
|
||||||
|
i = 1
|
||||||
|
for r in results.river.reachs:
|
||||||
|
j = i+len(r)-1
|
||||||
|
ltmp += [i, j]
|
||||||
|
is1.append(i)
|
||||||
|
is2.append(j)
|
||||||
|
i += i+len(r)
|
||||||
|
write_int(ltmp)
|
||||||
|
|
||||||
|
# X (3rd line)
|
||||||
|
rk = []
|
||||||
|
for r in results.river.reachs:
|
||||||
|
rk += r.geometry.get_rk()
|
||||||
|
write_float(rk)
|
||||||
|
|
||||||
|
# Z and Y (4th line)
|
||||||
|
# ltmp = []
|
||||||
|
# for r in results.river.reachs:
|
||||||
|
# for p in r.prifiles:
|
||||||
|
# ltpm.append(p.rk)
|
||||||
|
write_float(3*nb_profile*[0.0])
|
||||||
|
|
||||||
|
# Data
|
||||||
|
|
||||||
|
for timestamp in ts_list:
|
||||||
|
q = list(
|
||||||
|
map(
|
||||||
|
lambda p: p.get_ts_key(timestamp, "Q"),
|
||||||
|
profiles
|
||||||
|
)
|
||||||
|
)
|
||||||
|
write_data(nb_profile, timestamp, "Q", q)
|
||||||
|
z = list(
|
||||||
|
map(
|
||||||
|
lambda p: p.get_ts_key(timestamp, "Z"),
|
||||||
|
profiles
|
||||||
|
)
|
||||||
|
)
|
||||||
|
write_data(nb_profile, timestamp, "Z", z)
|
||||||
|
logger.info(f"write_bin: ... end with {len(ts_list)} timestamps")
|
||||||
|
|
||||||
|
@timer
|
||||||
|
def results(self, study, repertory, qlog=None, name=None):
|
||||||
results = Results(
|
results = Results(
|
||||||
study=study,
|
study=study,
|
||||||
solver=self,
|
solver=self,
|
||||||
repertory=repertory,
|
repertory=repertory,
|
||||||
name=name,
|
name=name,
|
||||||
)
|
)
|
||||||
|
if name is None:
|
||||||
|
name = study.name.replace(" ", "_")
|
||||||
|
|
||||||
results_file = f"profil.{name}"
|
results_file = f"profil.{name}"
|
||||||
|
|
||||||
fname = os.path.join(repertory, results_file)
|
fname = os.path.join(repertory, results_file)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Solvers.py -- Pamhyr
|
# Solvers.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Window.py -- Pamhyr
|
# Window.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -55,7 +55,7 @@ class AboutWindow(PamhyrDialog):
|
|||||||
|
|
||||||
label = self.get_label_text("label_version")
|
label = self.get_label_text("label_version")
|
||||||
label = label.replace("@version", version)
|
label = label.replace("@version", version)
|
||||||
label = label.replace("@codename", "(Adis-TS)")
|
label = label.replace("@codename", "")
|
||||||
self.set_label_text("label_version", label)
|
self.set_label_text("label_version", label)
|
||||||
|
|
||||||
# Authors
|
# Authors
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# GenerateDialog.py -- Pamhyr
|
# GenerateDialog.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Plot.py -- Pamhyr
|
# Plot.py -- Pamhyr
|
||||||
# Copyright (C) 2023-2025 INRAE
|
# Copyright (C) 2023-2026 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -54,7 +54,7 @@ class Plot(PamhyrPlot):
|
|||||||
self._isometric_axis = False
|
self._isometric_axis = False
|
||||||
|
|
||||||
self._auto_relim_update = True
|
self._auto_relim_update = True
|
||||||
self._autoscale_update = True
|
self._autoscale_update = False
|
||||||
|
|
||||||
def custom_ticks(self):
|
def custom_ticks(self):
|
||||||
if self.data.header[0] != "time":
|
if self.data.header[0] != "time":
|
||||||
|
|||||||
Loaded 100 of 309 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user