mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Compare commits
442
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a699f46ca | ||
|
|
33ad91d1a6 | ||
|
|
7d2ef35128 | ||
|
|
40b48a2080 | ||
|
|
bddaad0193 | ||
|
|
49eb28056e | ||
|
|
ddb682dff6 | ||
|
|
89c6e8bb29 | ||
|
|
d4c596a6fe | ||
|
|
d15fa684b7 | ||
|
|
9879094661 | ||
|
|
5ce5478bf4 | ||
|
|
5fb36e7fbe | ||
|
|
0dbea26a2e | ||
|
|
b0e0dc75f1 | ||
|
|
318f6a4668 | ||
|
|
fdb5cd23e7 | ||
|
|
e064c1aee5 | ||
|
|
e0bc481ae2 | ||
|
|
081e6e7322 | ||
|
|
a0d8b9ea43 | ||
|
|
d97620ad56 | ||
|
|
6d4dc3a22b | ||
|
|
74d23386a7 | ||
|
|
9f46bcd853 | ||
|
|
bcc9dd1a0d | ||
|
|
fc40552d68 | ||
|
|
f41050fe5c | ||
|
|
97f487c0af | ||
|
|
499e16975f | ||
|
|
75f3c07cd9 | ||
|
|
0a0c00d877 | ||
|
|
8d2c18b6af | ||
|
|
2d2f83436c | ||
|
|
71914fdf57 | ||
|
|
2d7409debb | ||
|
|
beece68498 | ||
|
|
92fb653676 | ||
|
|
d8e9d786d9 | ||
|
|
7ef305e724 | ||
|
|
5da607865c | ||
|
|
1f5ce72fb2 | ||
|
|
b6be245764 | ||
|
|
46d0f52b3e | ||
|
|
80f0b181d1 | ||
|
|
9161c54e18 | ||
|
|
64d9e456b7 | ||
|
|
846aaeadf0 | ||
|
|
eaf8d7364a | ||
|
|
54bfff9623 | ||
|
|
237364a4e2 | ||
|
|
c3288b44bb | ||
|
|
70128bbdd1 | ||
|
|
a88a164ead | ||
|
|
d6aeb5df21 | ||
|
|
32db5795da | ||
|
|
a81a641d41 | ||
|
|
53da35d959 | ||
|
|
0f1d1b0797 | ||
|
|
6586a7b191 | ||
|
|
b7aab9f263 | ||
|
|
ef34fecc31 | ||
|
|
e9aa980c88 | ||
|
|
ab495efc65 | ||
|
|
14e13d6624 | ||
|
|
8db099c5c7 | ||
|
|
b503e54210 | ||
|
|
68e4dfb598 | ||
|
|
63dfab6654 | ||
|
|
707577521f | ||
|
|
3458a5df9f | ||
|
|
e19eeedcc3 | ||
|
|
c95de5e606 | ||
|
|
53f7f380ae | ||
|
|
2028d84554 | ||
|
|
da28bae6c5 | ||
|
|
944f99f14b | ||
|
|
8978cc3482 | ||
|
|
f08d4b1a37 | ||
|
|
824fbe506e | ||
|
|
deb84ca331 | ||
|
|
5b778af745 | ||
|
|
776d9ab610 | ||
|
|
587e5412d5 | ||
|
|
ef5430ae2c | ||
|
|
059d7203a9 | ||
|
|
82b6cbfd72 | ||
|
|
c170dbc46c | ||
|
|
890dbd9d32 | ||
|
|
f17b395c4c | ||
|
|
a44dddb51b | ||
|
|
0fdb362313 | ||
|
|
50fa4f7bd8 | ||
|
|
9309aa9d2d | ||
|
|
dd31ffc5a2 | ||
|
|
3d467c9620 | ||
|
|
f95c646ef3 | ||
|
|
c0000bb332 | ||
|
|
cdbcb2b539 | ||
|
|
252ac257fe | ||
|
|
afe0217655 | ||
|
|
516efb64e8 | ||
|
|
4cad251e57 | ||
|
|
48e9c14525 | ||
|
|
db62af6f71 | ||
|
|
b468a1eb70 | ||
|
|
b9ab202e3f | ||
|
|
129dde1c57 | ||
|
|
ff2d3926b1 | ||
|
|
fefc6ebc4f | ||
|
|
0076faf03a | ||
|
|
bbdd18e8ef | ||
|
|
87d31c134e | ||
|
|
ce04f5fd1e | ||
|
|
435ccd1f2d | ||
|
|
74c28d40a6 | ||
|
|
7b2c276643 | ||
|
|
0e1264ca4f | ||
|
|
defcb3af84 | ||
|
|
5cf0a0ec76 | ||
|
|
1c44590def | ||
|
|
53732744f4 | ||
|
|
5e95c286a9 | ||
|
|
6175e8a03e | ||
|
|
8e3d784e92 | ||
|
|
698e300690 | ||
|
|
e3fbe59585 | ||
|
|
0c7fecb123 | ||
|
|
78eed7af13 | ||
|
|
6f5743a030 | ||
|
|
d027946fb2 | ||
|
|
37ea83d42a | ||
|
|
ae39f33131 | ||
|
|
291f80e904 | ||
|
|
61baaeeffb | ||
|
|
68aabb343d | ||
|
|
f2d6e07931 | ||
|
|
123259c2ef | ||
|
|
816d7663b5 | ||
|
|
9b9202c739 | ||
|
|
57f82415bd | ||
|
|
36c93a0c93 | ||
|
|
3cd1dbab49 | ||
|
|
4e3da95b1d | ||
|
|
0d0c4f913e | ||
|
|
600f86aeb4 | ||
|
|
c9bb222bff | ||
|
|
456559ffe2 | ||
|
|
6d58c09104 | ||
|
|
bc87d6add1 | ||
|
|
3fe49b70d0 | ||
|
|
5287f30636 | ||
|
|
67433ae325 | ||
|
|
d27ce9d1d8 | ||
|
|
c8ea9bd774 | ||
|
|
885c8ea502 | ||
|
|
c8b32f9877 | ||
|
|
cf61fd8d09 | ||
|
|
cac20d4f24 | ||
|
|
965443a8f9 | ||
|
|
02be084faf | ||
|
|
bb2e83b6ce | ||
|
|
c09c62f077 | ||
|
|
7a2e93a995 | ||
|
|
4a94c946d1 | ||
|
|
5327c29641 | ||
|
|
be865102a8 | ||
|
|
2dca5d2905 | ||
|
|
b5ae352af5 | ||
|
|
868215705c | ||
|
|
37f1b43b93 | ||
|
|
16f0775783 | ||
|
|
f2c4285b4c | ||
|
|
ee95f0e89e | ||
|
|
1306977954 | ||
|
|
476fa81bc2 | ||
|
|
6d16d9dff4 | ||
|
|
b60ab881b1 | ||
|
|
f2d76a0d67 | ||
|
|
5dcc82d81e | ||
|
|
a01e47f205 | ||
|
|
c87563b7ed | ||
|
|
246b411114 | ||
|
|
e8f1f0ac43 | ||
|
|
cfbc2d96a1 | ||
|
|
1adf24ce77 | ||
|
|
a61d130baa | ||
|
|
0a1760cee6 | ||
|
|
3e094af325 | ||
|
|
762e4d70a0 | ||
|
|
6c4f863b96 | ||
|
|
b87f82f74d | ||
|
|
ffad53a331 | ||
|
|
b2ca1c2ab7 | ||
|
|
2cbfaec0c2 | ||
|
|
95dd648b90 | ||
|
|
662a218e41 | ||
|
|
0501ae9bec | ||
|
|
7fd38eec00 | ||
|
|
4bab4580ad | ||
|
|
21d2e6ad20 | ||
|
|
d0a8f369ef | ||
|
|
fef2e1a40c | ||
|
|
20c2cb7ea4 | ||
|
|
333a8a0970 | ||
|
|
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 -U -r ./full-requirements.txt
|
||||
- cd src
|
||||
- python3 -m unittest discover -t .
|
||||
- python3.12 -m unittest discover -t .
|
||||
|
||||
test-pep8:
|
||||
stage: test
|
||||
@@ -638,7 +638,7 @@ shadow-release:
|
||||
- job: pkg-hash
|
||||
artifacts: true
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH != 'master' && $CI_COMMIT_TAG
|
||||
- if: $CI_COMMIT_TAG && $CI_COMMIT_TAG !~ /^v/
|
||||
artifacts:
|
||||
paths:
|
||||
- linux/pamhyr-gnulinux.tar.xz
|
||||
@@ -672,7 +672,7 @@ tag-release:
|
||||
- job: pkg-hash
|
||||
artifacts: true
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == 'master' && $CI_COMMIT_TAG
|
||||
- if: $CI_COMMIT_TAG =~ /^v/
|
||||
artifacts:
|
||||
paths:
|
||||
- linux/pamhyr-gnulinux.tar.xz
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
Sylvain COULIBALY, INRAE, 2020 - 2022
|
||||
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
|
||||
modelling of rivers.
|
||||
|
||||

|
||||

|
||||
|
||||
## Features
|
||||
|
||||
@@ -21,9 +21,9 @@ modelling of rivers.
|
||||
+ Create and edit study alternative scenario tree
|
||||
|
||||
Let see the
|
||||
[documentation](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home)
|
||||
([:fr:](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home-fr),
|
||||
[:gb:](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home-en))
|
||||
[documentation](https://gitlab.com/pamhyr/pamhyr2/-/wikis/home)
|
||||
([:fr:](https://gitlab.com/pamhyr/pamhyr2/-/wikis/home-fr),
|
||||
[:gb:](https://gitlab.com/pamhyr/pamhyr2/-/wikis/home-en))
|
||||
for more details.
|
||||
|
||||
## Install
|
||||
@@ -31,11 +31,11 @@ for more details.
|
||||
### GNU/Linux
|
||||
|
||||
See documentation:
|
||||
- [French :fr:](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home/fr/Install%20on%20GNULinux)
|
||||
- [English :gb:](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home/en/Install%20on%20GNULinux)
|
||||
- [French :fr:](https://gitlab.com/pamhyr/pamhyr2/-/wikis/home/fr/Install%20on%20GNULinux)
|
||||
- [English :gb:](https://gitlab.com/pamhyr/pamhyr2/-/wikis/home/en/Install%20on%20GNULinux)
|
||||
|
||||
### Windows
|
||||
|
||||
See documentation:
|
||||
- [French :fr:](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home/fr/Install%20on%20Windows)
|
||||
- [English :gb:](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home/en/Install%20on%20Windows)
|
||||
- [French :fr:](https://gitlab.com/pamhyr/pamhyr2/-/wikis/home/fr/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
|
||||
\usepackage{draftwatermark}
|
||||
\SetWatermarkLightness{0.8}
|
||||
\SetWatermarkAngle{25}
|
||||
\SetWatermarkScale{3}
|
||||
\SetWatermarkFontSize{1cm}
|
||||
\SetWatermarkText{Work in progress}
|
||||
%% \usepackage{draftwatermark}
|
||||
%% \SetWatermarkLightness{0.8}
|
||||
%% \SetWatermarkAngle{25}
|
||||
%% \SetWatermarkScale{3}
|
||||
%% \SetWatermarkFontSize{1cm}
|
||||
%% \SetWatermarkText{Work in progress}
|
||||
|
||||
%% Icons
|
||||
|
||||
|
||||
Binary file not shown.
@@ -14,3 +14,4 @@ platformdirs>=4.2.0
|
||||
pyshp>=2.3.1
|
||||
rasterio==1.3.11
|
||||
#fortranformat==2.0.3
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
+6
-3
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -229,7 +229,11 @@ for each reach"
|
||||
gls = []
|
||||
|
||||
for edge in edges:
|
||||
comp, incomp = edge.reach.compute_guidelines()
|
||||
profiles = edge.reach.enabled_profiles
|
||||
comp, incomp = edge.reach.compute_guidelines(
|
||||
profiles=profiles,
|
||||
update_cache=False
|
||||
)
|
||||
if len(incomp) != 0:
|
||||
self._status = STATUS.WARNING
|
||||
self._summary = "incomplete_guideline"
|
||||
@@ -237,7 +241,6 @@ for each reach"
|
||||
|
||||
gls.append(comp)
|
||||
|
||||
profiles = edge.reach.profiles
|
||||
for profile in profiles:
|
||||
if not profile.has_standard_named_points():
|
||||
self._status = STATUS.WARNING
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -87,7 +87,7 @@ class StudyGeometryChecker(AbstractModelChecker):
|
||||
return False
|
||||
|
||||
for edge in edges:
|
||||
if len(edge.reach.profiles) < 2:
|
||||
if len(edge.reach.enabled_profiles) < 2:
|
||||
summary = "no_geometry_defined"
|
||||
status = STATUS.ERROR
|
||||
ok = False
|
||||
@@ -132,8 +132,12 @@ class StudyInitialConditionsChecker(AbstractModelChecker):
|
||||
return ok
|
||||
|
||||
ic = river.initial_conditions[reach]
|
||||
len_ic = len(ic)
|
||||
len_reach = len(reach)
|
||||
enabled_profiles = set(reach.enabled_profiles)
|
||||
len_ic = sum(
|
||||
data["section"] in enabled_profiles
|
||||
for data in ic.data
|
||||
)
|
||||
len_reach = len(enabled_profiles)
|
||||
|
||||
if len_ic < len_reach:
|
||||
self._summary = "initial_condition_missing_profile"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
+121
-68
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -57,6 +57,13 @@ class InternalMeshing(AMeshingTool):
|
||||
|
||||
# we never modify original profiles, we work on the copies
|
||||
m_profiles = self.st_to_m(profiles, guide_list)
|
||||
|
||||
# Adapt the spacing to the kilometre-point direction. The value from
|
||||
# the dialog is a distance, so only its magnitude is significant.
|
||||
step = self.signed_step(
|
||||
step, m_profiles[0].rk, m_profiles[-1].rk
|
||||
)
|
||||
|
||||
new_profiles = self.interpolate_transversal_step(m_profiles, step)
|
||||
|
||||
for new_profiles2 in new_profiles:
|
||||
@@ -65,8 +72,13 @@ class InternalMeshing(AMeshingTool):
|
||||
|
||||
return new_profiles
|
||||
|
||||
def st_to_m(self, profiles, guide_list):
|
||||
@staticmethod
|
||||
def signed_step(step, begin_rk, end_rk):
|
||||
if end_rk < begin_rk:
|
||||
return -abs(step)
|
||||
return abs(step)
|
||||
|
||||
def st_to_m(self, profiles, guide_list):
|
||||
guide_list = ["un"] + guide_list + ["np"]
|
||||
max_values = [0] * (len(guide_list) - 1)
|
||||
max_values_index = [0] * (len(guide_list) - 1)
|
||||
@@ -85,11 +97,13 @@ class InternalMeshing(AMeshingTool):
|
||||
profiles[isect+1],
|
||||
guide_list[i],
|
||||
guide_list[i+1])
|
||||
|
||||
for isect in reversed(range(0, max_values_index[i])):
|
||||
self.compl_sect(profiles[isect+1],
|
||||
profiles[isect],
|
||||
guide_list[i],
|
||||
guide_list[i+1])
|
||||
|
||||
return profiles
|
||||
|
||||
def interpolate_transversal_step(self,
|
||||
@@ -123,12 +137,14 @@ class InternalMeshing(AMeshingTool):
|
||||
p.points[k].z = pt1[k].z + \
|
||||
dj*(pt2[k].z -
|
||||
pt1[k].z)
|
||||
p.rk = profiles[i].rk + \
|
||||
dj*(profiles[i+1].rk -
|
||||
profiles[i].rk)
|
||||
p.rk = round(profiles[i].rk +
|
||||
dj*(profiles[i+1].rk -
|
||||
profiles[i].rk), 2)
|
||||
p.name = f'interpol{p.rk}'
|
||||
p.interpolated = True
|
||||
new_profiles2.append(p)
|
||||
new_profiles.append(new_profiles2)
|
||||
|
||||
return new_profiles
|
||||
|
||||
def compl_sect(self, sect1, sect2, tag1, tag2):
|
||||
@@ -156,15 +172,14 @@ class InternalMeshing(AMeshingTool):
|
||||
|
||||
ltot1 = 0.0
|
||||
ltot2 = 0.0
|
||||
alpha = []
|
||||
beta = []
|
||||
alpha = [0.0]
|
||||
beta = [0.0]
|
||||
# remove names
|
||||
sect2.points[start2].name = ''
|
||||
sect2.points[end2].name = ''
|
||||
for i in range(len1):
|
||||
ltot1 += sect1.point(start1+i).dist(sect1.point(start1+i+1))
|
||||
alpha.append(ltot1)
|
||||
alpha = list(map(lambda x: x/ltot1, alpha)) # target ratios
|
||||
for i in range(len2):
|
||||
ltot2 += sect2.point(start2+i).dist(sect2.point(start2+i+1))
|
||||
beta.append(ltot2)
|
||||
@@ -179,74 +194,112 @@ class InternalMeshing(AMeshingTool):
|
||||
sect2.add_npoints(len1-len2)
|
||||
len2 = len1
|
||||
else: # regular case
|
||||
alpha = list(map(lambda x: x/ltot1, alpha)) # target ratios
|
||||
beta = list(map(lambda x: x/ltot2, beta)) # current ratios
|
||||
for i in range(len1 - len2):
|
||||
beta.append(1.0)
|
||||
beta.append(0.0) # beta[-1]
|
||||
# loop on the points to insert
|
||||
for k in range(len1-len2):
|
||||
trouve = False
|
||||
for j0 in range(len2):
|
||||
if trouve:
|
||||
break
|
||||
undeplus = True
|
||||
for j1 in range(j0, len2):
|
||||
if undeplus:
|
||||
if beta[j1] <= alpha[j1]:
|
||||
undeplus = False
|
||||
break
|
||||
if undeplus:
|
||||
if j0 == len2:
|
||||
trouve = True
|
||||
else:
|
||||
j1 = j0+1
|
||||
if beta[j0]-alpha[j0] > alpha[j1]-beta[j0]:
|
||||
trouve = True
|
||||
match = self._match_indices(alpha, beta)
|
||||
|
||||
if trouve:
|
||||
len2 += 1
|
||||
for i in reversed(range(j0, len2)):
|
||||
beta[i+1] = beta[i]
|
||||
if (beta[j0] == beta[j0-1]):
|
||||
# rien
|
||||
pass
|
||||
else:
|
||||
ratio = (alpha[j0] - beta[j0-1]) \
|
||||
/ (beta[j0] - beta[j0-1])
|
||||
if ratio < 0.0:
|
||||
print(f"ratio négatif {ratio}")
|
||||
# on double le point a gauche
|
||||
p = sect2.point(start2+j0-1).copy()
|
||||
sect2.insert_point(start2+j0-1, p)
|
||||
sect2.point(start2+j0-1).name = ''
|
||||
beta[j0] = beta[j0-1]
|
||||
else:
|
||||
p = sect2.point(start2+j0).copy()
|
||||
sect2.insert_point(start2+j0, p)
|
||||
sect2.point(start2+j0+1).name = ''
|
||||
sect2.point(start2+j0+1).x = \
|
||||
(1.0-ratio) * sect2.point(start2+j0).x + \
|
||||
ratio * sect2.point(start2+j0+2).x
|
||||
sect2.point(start2+j0+1).y = \
|
||||
(1.0-ratio) * sect2.point(start2+j0).y + \
|
||||
ratio * sect2.point(start2+j0+2).y
|
||||
sect2.point(start2+j0+1).z = \
|
||||
(1.0-ratio) * sect2.point(start2+j0).z + \
|
||||
ratio * sect2.point(start2+j0+2).z
|
||||
beta[j0] = (1.-ratio)*beta[j0-1] \
|
||||
+ ratio*beta[j0+1]
|
||||
insertions_per_segment = [] # liste de (index, [points])
|
||||
for j in range(len2):
|
||||
i_start = match[j]
|
||||
i_end = match[j + 1]
|
||||
q_start = sect2.point(start2 + j)
|
||||
q_end = sect2.point(start2 + j + 1)
|
||||
|
||||
new_points = []
|
||||
if i_end - i_start > 1:
|
||||
u_start, u_end = alpha[i_start], alpha[i_end]
|
||||
span = u_end - u_start
|
||||
for k in range(i_start + 1, i_end):
|
||||
ratio = (alpha[k] - u_start) / span # dans [0,1]
|
||||
p = q_start.copy()
|
||||
p.name = ''
|
||||
p.x = (1.0-ratio) * q_start.x + ratio * q_end.x
|
||||
p.y = (1.0-ratio) * q_start.y + ratio * q_end.y
|
||||
p.z = (1.0-ratio) * q_start.z + ratio * q_end.z
|
||||
new_points.append(p)
|
||||
|
||||
# à insérer après l'indice j
|
||||
insertions_per_segment.append((j, new_points))
|
||||
|
||||
# Insertion en ordre décroissant de j
|
||||
# pour ne pas perturber les indices
|
||||
for j, new_points in reversed(insertions_per_segment):
|
||||
for offset, p in enumerate(new_points):
|
||||
sect2.insert_point(start2 + j + 1 + offset, p)
|
||||
len2 += 1
|
||||
|
||||
if len1 > len2:
|
||||
for i in range(len1 - len2):
|
||||
p = sect2.point(start2+len2).copy()
|
||||
sect2.insert_point(start2+len2, p)
|
||||
sect2.point(start2+len2).name = ''
|
||||
if tag1 != "un":
|
||||
sect2.point(start2).name = tag1
|
||||
if tag1 != "np":
|
||||
if tag2 != "np":
|
||||
sect2.point(start2+len2).name = tag2
|
||||
|
||||
sect2.modified()
|
||||
|
||||
def _match_indices(self, u_ref, v_target):
|
||||
# appariement optimal (ordre croissant) par programmation dynamique
|
||||
"""
|
||||
Trouve, pour chaque v_target[j], un indice i_j dans u_ref tel que
|
||||
i_0 < i_1 < ... < i_{m-1} et
|
||||
Sum |u_ref[i_j] - v_target[j]| soit minimal.
|
||||
|
||||
Retourne la liste des indices i_j (longueur m),
|
||||
avec i_0 = 0 et i_{m-1} = n-1 imposés
|
||||
(les extrémités se correspondent forcément).
|
||||
|
||||
"""
|
||||
n = len(u_ref)
|
||||
m = len(v_target)
|
||||
|
||||
# Les extrémités sont fixées.
|
||||
fixed_first, fixed_last = 0, n - 1
|
||||
|
||||
# DP sur les indices disponibles entre fixed_first+1 et fixed_last-1
|
||||
# dp[j][i] = coût minimal pour apparier v_target[1..j] aux indices
|
||||
# se terminant à l'indice i (i croissant strict), j de 1 à m-2.
|
||||
if m == 2:
|
||||
return [fixed_first, fixed_last]
|
||||
|
||||
# indices internes possibles
|
||||
candidates = list(range(fixed_first + 1, fixed_last))
|
||||
inner_targets = v_target[1:-1] # cibles internes (j = 1..m-2)
|
||||
|
||||
INF = float("inf")
|
||||
# dp[j] : dict indice_candidat -> (coût_min, provenance)
|
||||
dp = [{} for _ in range(len(inner_targets))]
|
||||
|
||||
for j, vt in enumerate(inner_targets):
|
||||
for idx_pos, i in enumerate(candidates):
|
||||
cost_here = abs(u_ref[i] - vt)
|
||||
if j == 0:
|
||||
# doit être > fixed_first
|
||||
dp[j][i] = (cost_here, fixed_first)
|
||||
else:
|
||||
best = (INF, None)
|
||||
for i_prev in candidates[:idx_pos]:
|
||||
if i_prev in dp[j - 1]:
|
||||
c = dp[j - 1][i_prev][0] + cost_here
|
||||
if c < best[0]:
|
||||
best = (c, i_prev)
|
||||
if best[1] is not None:
|
||||
dp[j][i] = best
|
||||
|
||||
# Reconstruction : on part du dernier niveau, on choisit le
|
||||
# meilleur indice tel que la suite jusqu'à fixed_last
|
||||
# reste croissante et valide.
|
||||
last_level = dp[-1]
|
||||
valid = {i: c for i, c in last_level.items() if i < fixed_last}
|
||||
if not valid:
|
||||
raise RuntimeError("Alignement impossible avec ces données.")
|
||||
best_i = min(valid, key=lambda i: valid[i][0])
|
||||
|
||||
chain = [best_i]
|
||||
for j in range(len(inner_targets) - 1, 0, -1):
|
||||
prev_i = dp[j][chain[-1]][1]
|
||||
chain.append(prev_i)
|
||||
chain.reverse()
|
||||
|
||||
return [fixed_first] + chain + [fixed_last]
|
||||
|
||||
def update_rk(self, reach, begin_rk, end_rk,
|
||||
step: float = 50,
|
||||
limites=[-1, -1],
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# __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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -232,6 +232,8 @@ class BoundaryCondition(SQLSubModel):
|
||||
type TEXT NOT NULL,
|
||||
tab TEXT NOT NULL,
|
||||
node INTEGER,
|
||||
d50 REAL DEFAULT 0.002,
|
||||
sigma REAL DEFAULT 1,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(node) REFERENCES river_node(pamhyr_id),
|
||||
@@ -258,6 +260,17 @@ class BoundaryCondition(SQLSubModel):
|
||||
"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)
|
||||
|
||||
@classmethod
|
||||
@@ -316,7 +329,8 @@ class BoundaryCondition(SQLSubModel):
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, name, type, node, scenario " +
|
||||
"SELECT pamhyr_id, deleted, name, type, node, d50, sigma, " +
|
||||
"scenario " +
|
||||
"FROM boundary_condition " +
|
||||
f"WHERE tab = '{tab}' " +
|
||||
f"AND scenario = {scenario.id} " +
|
||||
@@ -331,6 +345,8 @@ class BoundaryCondition(SQLSubModel):
|
||||
name = next(it)
|
||||
t = next(it)
|
||||
node = next(it)
|
||||
d50 = next(it)
|
||||
sigma = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
ctor = cls._get_ctor_from_type(t)
|
||||
@@ -340,9 +356,14 @@ class BoundaryCondition(SQLSubModel):
|
||||
status=data['status'],
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
if deleted:
|
||||
bc.set_as_deleted()
|
||||
|
||||
if t == "SL":
|
||||
bc.d50 = d50
|
||||
bc.sigma = sigma
|
||||
|
||||
bc.node = None
|
||||
if node != -1:
|
||||
bc.node = next(filter(lambda n: n.id == node, nodes), None)
|
||||
@@ -375,15 +396,22 @@ class BoundaryCondition(SQLSubModel):
|
||||
if self._node is not None:
|
||||
node = self._node.id
|
||||
|
||||
d50 = 0.002
|
||||
sigma = 1
|
||||
if self._type == "SL":
|
||||
d50 = self._d50
|
||||
sigma = self._sigma
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"boundary_condition(" +
|
||||
"pamhyr_id, deleted, name, type, tab, node, scenario" +
|
||||
"pamhyr_id, deleted, name, type, tab, node, d50, sigma, scenario" +
|
||||
") " +
|
||||
"VALUES (" +
|
||||
f"{self._pamhyr_id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"'{self._db_format(self._name)}', " +
|
||||
f"'{self._db_format(self._type)}', '{tab}', {node}, " +
|
||||
f"{d50}, {sigma}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
@@ -468,6 +496,24 @@ class BoundaryCondition(SQLSubModel):
|
||||
def has_node(self):
|
||||
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
|
||||
def header(self):
|
||||
return self._header.copy()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if int(release) < 7:
|
||||
if major == "0" and minor == "0":
|
||||
if int(release) < 11:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
@@ -143,8 +142,9 @@ class Data(SQLSubModel):
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, data0, data1, scenario FROM " +
|
||||
"boundary_condition_data_adists " +
|
||||
f"WHERE bca = {bca.id} " +
|
||||
f"AND scenario = {scenario.id}"
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
# f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
|
||||
f"AND bca = {bca.id}"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
@@ -187,8 +187,9 @@ class Data(SQLSubModel):
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"boundary_condition_data_adists(" +
|
||||
"pamhyr_id, data0, data1, bca, scenario) " +
|
||||
f"VALUES ({self.id}, '{data0}', {data1}, {bca.id}, " +
|
||||
"pamhyr_id, deleted, data0, data1, bca, scenario) " +
|
||||
f"VALUES ({self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"'{data0}', {data1}, {bca.id}, " +
|
||||
f"{self._status.scenario_id})"
|
||||
)
|
||||
|
||||
@@ -247,15 +248,13 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if int(release) < 7:
|
||||
if major == "0" and int(minor) < 2:
|
||||
if cls.is_table_exists(execute, "boundary_condition_adists"):
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
else:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if not created:
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@@ -300,6 +299,14 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
if pol_id == -1:
|
||||
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(
|
||||
f"UPDATE boundary_condition_adists " +
|
||||
f"SET pollutant = {pid_pol[pol_id]} " +
|
||||
@@ -312,17 +319,21 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
status = data['status']
|
||||
nodes = data['nodes']
|
||||
scenario = data["scenario"]
|
||||
pollutant = data.get("pollutant")
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, pollutant, type, node, scenario " +
|
||||
sql = (
|
||||
"SELECT pamhyr_id, deleted, pollutant, type, node, scenario "
|
||||
"FROM boundary_condition_adists " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
f"WHERE scenario = {scenario.id} "
|
||||
)
|
||||
if pollutant is not None:
|
||||
sql += f"AND pollutant = {pollutant.id} "
|
||||
|
||||
table = execute(sql)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
@@ -347,7 +358,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
bc.type = bc_type
|
||||
|
||||
bc.node = None
|
||||
if row[3] != -1:
|
||||
if node != -1:
|
||||
tmp = next(
|
||||
filter(
|
||||
lambda n: n.id == node, nodes
|
||||
@@ -426,7 +437,14 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
d._data_traversal(predicate, modifier, data)
|
||||
|
||||
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
|
||||
def time_convert(cls, data):
|
||||
@@ -451,7 +469,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
@node.setter
|
||||
def node(self, node):
|
||||
self._node = node
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def header(self):
|
||||
@@ -460,7 +478,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
@header.setter
|
||||
def header(self, header):
|
||||
self._header = header
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def pollutant(self):
|
||||
@@ -469,7 +487,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
@pollutant.setter
|
||||
def pollutant(self, pollutant):
|
||||
self._pollutant = pollutant
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
@@ -478,11 +496,16 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
@type.setter
|
||||
def type(self, type):
|
||||
self._type = type
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return self._data.copy()
|
||||
return list(
|
||||
filter(
|
||||
lambda el: el is not None and not el.is_deleted(),
|
||||
self._data
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def _default_0(self):
|
||||
@@ -508,36 +531,42 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
new_0 = self._types[0](data[0].replace(",", "."))
|
||||
new_1 = self._types[1](data[1].replace(",", "."))
|
||||
|
||||
return (new_0, new_1)
|
||||
return Data(new_0, new_1, types=self._types, status=self._status)
|
||||
|
||||
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._status.modified()
|
||||
self.modified()
|
||||
return value
|
||||
|
||||
def insert(self, index: int, value):
|
||||
self._data.insert(index, value)
|
||||
self._status.modified()
|
||||
if value in self._data:
|
||||
value.set_as_not_deleted()
|
||||
else:
|
||||
self._data.insert(index, value)
|
||||
self.modified()
|
||||
|
||||
def delete_i(self, indexes):
|
||||
self._data = list(
|
||||
list(
|
||||
map(
|
||||
lambda e: e[1],
|
||||
lambda e: e[1].set_as_deleted(),
|
||||
filter(
|
||||
lambda e: e[0] not in indexes,
|
||||
lambda e: e[0] in indexes,
|
||||
enumerate(self.data)
|
||||
)
|
||||
)
|
||||
)
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
def sort(self, _reverse=False, key=None):
|
||||
if key is None:
|
||||
self._data.sort(reverse=_reverse)
|
||||
else:
|
||||
self._data.sort(reverse=_reverse, key=key)
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
def index(self, bc):
|
||||
self._data.index(bc)
|
||||
@@ -552,10 +581,10 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
return lst
|
||||
|
||||
def _set_i_c_v(self, index, column, value):
|
||||
v = list(self._data[index])
|
||||
v = self._data[index]
|
||||
v[column] = self._types[column](value)
|
||||
self._data[index] = tuple(v)
|
||||
self._status.modified()
|
||||
self._data[index] = v
|
||||
self.modified()
|
||||
|
||||
def set_i_0(self, index: int, value):
|
||||
self._set_i_c_v(index, 0, value)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -38,9 +38,13 @@ class BoundaryConditionsAdisTSList(PamhyrModelList):
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
new._lst = BoundaryConditionAdisTS._db_load(
|
||||
execute, data
|
||||
)
|
||||
previous_pollutant = data.get("pollutant")
|
||||
data.pop("pollutant", None)
|
||||
|
||||
new._lst = BoundaryConditionAdisTS._db_load(execute, data)
|
||||
|
||||
if previous_pollutant is not None:
|
||||
data["pollutant"] = previous_pollutant
|
||||
|
||||
return new
|
||||
|
||||
|
||||
@@ -0,0 +1,481 @@
|
||||
# BoundaryConditionsTemperature.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from tools import (
|
||||
trace, timer,
|
||||
old_pamhyr_date_to_timestamp,
|
||||
date_iso_to_timestamp,
|
||||
date_dmy_to_timestamp,
|
||||
)
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Data(SQLSubModel):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self,
|
||||
data0, data1,
|
||||
id: int = -1,
|
||||
types=[float, float],
|
||||
status=None,
|
||||
owner_scenario=-1):
|
||||
super(Data, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._types = types
|
||||
self._data = [data0, data1]
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE boundary_condition_data_temperature{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
data0 TEXT NOT NULL,
|
||||
data1 TEXT NOT NULL,
|
||||
bca INTEGER,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(bca)
|
||||
REFERENCES boundary_condition_temperature(pamhyr_id)
|
||||
)
|
||||
""")
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
if major == "0" and minor == "0":
|
||||
if int(release) < 11:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if major == "0" and (int(minor) < 2 or
|
||||
(int(minor) == 2 and int(release) <= 7)):
|
||||
if not cls.is_table_exists(execute,
|
||||
"boundary_condition_data_temperature"):
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if not created:
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
bca = data["bca"]
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, data0, data1, scenario FROM " +
|
||||
"boundary_condition_data_temperature " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
# f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
|
||||
f"AND bca = {bca.id}"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
deleted = (next(it) == 1)
|
||||
data0 = next(it)
|
||||
data1 = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
bc = cls(
|
||||
data0, data1,
|
||||
id=pid,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
bc.set_as_deleted()
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(bc)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
bca = data["bca"]
|
||||
|
||||
data0 = self._db_format(self._data[0])
|
||||
data1 = self._db_format(self._data[1])
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"boundary_condition_data_temperature(" +
|
||||
"pamhyr_id, deleted, data0, data1, bca, scenario) " +
|
||||
f"VALUES ({self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"'{data0}', {data1}, {bca.id}, " +
|
||||
f"{self._status.scenario_id})"
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self._types[key](self._data[key])
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
self._data[key] = self._types[key](value)
|
||||
|
||||
|
||||
class BoundaryConditionTemperature(SQLSubModel):
|
||||
_sub_classes = [Data]
|
||||
|
||||
def __init__(self, id: int = -1, status=None, owner_scenario=-1):
|
||||
super(BoundaryConditionTemperature, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._status = status
|
||||
|
||||
self._name = ""
|
||||
self._node = None
|
||||
self._data = []
|
||||
self._header = []
|
||||
self._types = [self.time_convert, float]
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE boundary_condition_temperature{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
name TEXT NOT NULL,
|
||||
node INTEGER,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(node) REFERENCES river_node(pamhyr_id)
|
||||
)
|
||||
""")
|
||||
|
||||
if ext != "":
|
||||
return True
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and (int(minor) < 2 or (
|
||||
int(minor) == 2 and int(release) <= 7)):
|
||||
if not cls.is_table_exists(execute,
|
||||
"boundary_condition_temperature"):
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if not created:
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
nodes = data['nodes']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
sql = (
|
||||
"SELECT pamhyr_id, deleted, name, node, scenario "
|
||||
"FROM boundary_condition_temperature " +
|
||||
f"WHERE scenario = {scenario.id} "
|
||||
)
|
||||
|
||||
table = execute(sql)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
deleted = (next(it) == 1)
|
||||
bc_name = next(it)
|
||||
node = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
bc = cls(
|
||||
id=pid,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
bc.set_as_deleted()
|
||||
|
||||
bc.name = bc_name
|
||||
|
||||
bc.node = None
|
||||
if node != -1:
|
||||
tmp = next(
|
||||
filter(
|
||||
lambda n: n.id == node, nodes
|
||||
),
|
||||
None
|
||||
)
|
||||
if tmp is not None:
|
||||
bc.node = tmp.id
|
||||
else:
|
||||
bc.node = -1
|
||||
|
||||
data["bca"] = bc
|
||||
bc._data = Data._db_load(execute, data=data)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(bc)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"DELETE FROM boundary_condition_temperature " +
|
||||
f"WHERE pamhyr_id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
)
|
||||
execute(
|
||||
"DELETE FROM boundary_condition_data_temperature " +
|
||||
f"WHERE bca = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
)
|
||||
|
||||
node = -1
|
||||
if self._node is not None:
|
||||
node = self._node
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"boundary_condition_temperature(" +
|
||||
"pamhyr_id, deleted, name, " +
|
||||
"node, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"'{self._db_format(self._name)}', {node}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
data["bca"] = self
|
||||
|
||||
ind = 0
|
||||
for d in self._data:
|
||||
data["ind"] = ind
|
||||
|
||||
d._db_save(execute, data)
|
||||
|
||||
ind += 1
|
||||
|
||||
return True
|
||||
|
||||
def _data_traversal(self,
|
||||
predicate=lambda obj, data: True,
|
||||
modifier=lambda obj, data: None,
|
||||
data={}):
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
for d in self._data:
|
||||
d._data_traversal(predicate, modifier, data)
|
||||
|
||||
def __len__(self):
|
||||
return len(
|
||||
list(
|
||||
filter(
|
||||
lambda el: el is not None and not el.is_deleted(),
|
||||
self._data
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def time_convert(cls, data):
|
||||
if type(data) is str:
|
||||
if data.count("-") == 2:
|
||||
return date_iso_to_timestamp(data)
|
||||
if data.count("/") == 2:
|
||||
return date_dmy_to_timestamp(data)
|
||||
if data.count(":") == 3:
|
||||
return old_pamhyr_date_to_timestamp(data)
|
||||
if data.count(":") == 2:
|
||||
return old_pamhyr_date_to_timestamp("00:" + data)
|
||||
if data.count(".") == 1:
|
||||
return round(float(data))
|
||||
|
||||
return int(data)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._name = name
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def node(self):
|
||||
return self._node
|
||||
|
||||
@node.setter
|
||||
def node(self, node):
|
||||
self._node = node
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def header(self):
|
||||
return self._header.copy()
|
||||
|
||||
@header.setter
|
||||
def header(self, header):
|
||||
self._header = header
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return list(
|
||||
filter(
|
||||
lambda el: el is not None and not el.is_deleted(),
|
||||
self._data
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def _default_0(self):
|
||||
return self._types[0](0)
|
||||
|
||||
@property
|
||||
def _default_1(self):
|
||||
return self._types[1](0.0)
|
||||
|
||||
def new_from_data(self, header, data):
|
||||
new_0 = self._default_0
|
||||
new_1 = self._default_1
|
||||
|
||||
if len(header) != 0:
|
||||
for i in [0, 1]:
|
||||
for j in range(len(header)):
|
||||
if self._header[i] == header[j]:
|
||||
if i == 0:
|
||||
new_0 = self._types[i](data[j].replace(",", "."))
|
||||
else:
|
||||
new_1 = self._types[i](data[j].replace(",", "."))
|
||||
else:
|
||||
new_0 = self._types[0](data[0].replace(",", "."))
|
||||
new_1 = self._types[1](data[1].replace(",", "."))
|
||||
|
||||
return Data(new_0, new_1, types=self._types, status=self._status)
|
||||
|
||||
def add(self, index: int):
|
||||
value = Data(
|
||||
self._default_0, self._default_1,
|
||||
status=self._status
|
||||
)
|
||||
self._data.insert(index, value)
|
||||
self.modified()
|
||||
return value
|
||||
|
||||
def insert(self, index: int, value):
|
||||
if value in self._data:
|
||||
value.set_as_not_deleted()
|
||||
else:
|
||||
self._data.insert(index, value)
|
||||
self.modified()
|
||||
|
||||
def delete_i(self, indexes):
|
||||
list(
|
||||
map(
|
||||
lambda e: e[1].set_as_deleted(),
|
||||
filter(
|
||||
lambda e: e[0] in indexes,
|
||||
enumerate(self.data)
|
||||
)
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
|
||||
def sort(self, _reverse=False, key=None):
|
||||
if key is None:
|
||||
self._data.sort(reverse=_reverse)
|
||||
else:
|
||||
self._data.sort(reverse=_reverse, key=key)
|
||||
self.modified()
|
||||
|
||||
def index(self, bc):
|
||||
self._data.index(bc)
|
||||
|
||||
def get_i(self, index):
|
||||
return self.data[index]
|
||||
|
||||
def get_range(self, _range):
|
||||
lst = []
|
||||
for r in _range:
|
||||
lst.append(r)
|
||||
return lst
|
||||
|
||||
def _set_i_c_v(self, index, column, value):
|
||||
v = self._data[index]
|
||||
v[column] = self._types[column](value)
|
||||
self._data[index] = v
|
||||
self.modified()
|
||||
|
||||
def set_i_0(self, index: int, value):
|
||||
self._set_i_c_v(index, 0, value)
|
||||
|
||||
def set_i_1(self, index: int, value):
|
||||
self._set_i_c_v(index, 1, value)
|
||||
+32
-20
@@ -1,5 +1,5 @@
|
||||
# OutputRKListAdists.py -- Pamhyr
|
||||
# Copyright (C) 2024-2025 INRAE
|
||||
# BoundaryConditionsTemperatureList.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -16,44 +16,56 @@
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from copy import copy
|
||||
from tools import trace, timer
|
||||
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Tools.PamhyrListExt import PamhyrModelList
|
||||
from Model.OutputRKAdists.OutputRKAdists import OutputRKAdists
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
|
||||
from Model.BoundaryConditionsTemperature.BoundaryConditionTemperature \
|
||||
import BoundaryConditionTemperature
|
||||
|
||||
|
||||
class OutputRKAdistsList(PamhyrModelList):
|
||||
_sub_classes = [OutputRKAdists]
|
||||
class BoundaryConditionsTemperatureList(PamhyrModelList):
|
||||
_sub_classes = [
|
||||
BoundaryConditionTemperature,
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = cls(status=data["status"])
|
||||
new = cls(status=data['status'])
|
||||
|
||||
new._lst = OutputRKAdists._db_load(execute, data)
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
new._lst = BoundaryConditionTemperature._db_load(execute, data)
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
ok = True
|
||||
|
||||
# Delete previous data
|
||||
execute(
|
||||
"DELETE FROM output_rk_adists " +
|
||||
"DELETE FROM boundary_condition_temperature " +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
execute(
|
||||
"DELETE FROM boundary_condition_data_temperature " +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
for sl in self._lst:
|
||||
ok &= sl._db_save(execute, data)
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
return ok
|
||||
for bca in self._lst:
|
||||
bca._db_save(execute, data=data)
|
||||
|
||||
@property
|
||||
def OutputRK_List(self):
|
||||
return self.lst
|
||||
return True
|
||||
|
||||
def new(self, lst, index):
|
||||
n = OutputRKAdists(status=self._status)
|
||||
def new(self, index):
|
||||
n = BoundaryConditionTemperature(status=self._status)
|
||||
self._lst.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
@property
|
||||
def BCs_Temperature_List(self):
|
||||
return self.lst
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if int(release) < 6:
|
||||
if major == "0" and int(minor) < 2:
|
||||
if cls.is_table_exists(execute, "d90_adists"):
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
else:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if not created:
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@@ -277,3 +275,44 @@ class D90AdisTS(SQLSubModel):
|
||||
x.set_as_not_deleted()
|
||||
|
||||
self.modified()
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
split_rk = profile.rk
|
||||
reach_rks = reach.reach.get_rk()
|
||||
if len(reach_rks) == 0:
|
||||
return
|
||||
|
||||
parts = [
|
||||
(reach1.id, min(reach_rks), split_rk),
|
||||
(reach2.id, split_rk, max(reach_rks)),
|
||||
]
|
||||
specifications = [
|
||||
specification
|
||||
for specification in self._data
|
||||
if (not specification.is_deleted() and
|
||||
specification.reach == reach.id)
|
||||
]
|
||||
|
||||
for specification in specifications:
|
||||
begin = specification.start_rk
|
||||
end = specification.end_rk
|
||||
if begin is None or end is None:
|
||||
continue
|
||||
|
||||
lower, upper = sorted((begin, end))
|
||||
reverse = begin > end
|
||||
|
||||
for new_reach, part_lower, part_upper in parts:
|
||||
clipped_lower = max(lower, part_lower)
|
||||
clipped_upper = min(upper, part_upper)
|
||||
if clipped_lower >= clipped_upper:
|
||||
continue
|
||||
|
||||
start_rk = clipped_upper if reverse else clipped_lower
|
||||
end_rk = clipped_lower if reverse else clipped_upper
|
||||
self._data.append(specification.cloned_for(
|
||||
new_reach, start_rk, end_rk
|
||||
))
|
||||
|
||||
if len(specifications) != 0:
|
||||
self.modified()
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -61,6 +61,10 @@ class D90AdisTSList(PamhyrModelList):
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
for d90 in self.lst:
|
||||
d90.split_reach(reach, profile, reach1, reach2)
|
||||
|
||||
@property
|
||||
def D90_AdisTS_List(self):
|
||||
return self.lst
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -70,16 +70,12 @@ class D90AdisTSSpec(SQLSubModel):
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
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 not created:
|
||||
if cls.is_table_exists(execute, "d90_spec"):
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
else:
|
||||
cls._db_create(execute)
|
||||
|
||||
return True
|
||||
|
||||
@@ -87,6 +83,7 @@ class D90AdisTSSpec(SQLSubModel):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "d90_spec"
|
||||
table_new = "d90_adists_spec"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
@@ -95,8 +92,10 @@ class D90AdisTSSpec(SQLSubModel):
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table_new}_tmp " +
|
||||
"(pamhyr_id, name, d90, enabled, scenario) " +
|
||||
"SELECT pamhyr_id, name, d90, enabled, scenario " +
|
||||
"(pamhyr_id, d90_default, name, reach, " +
|
||||
" start_rk, end_rk, d90, enabled, scenario) " +
|
||||
"SELECT pamhyr_id, d90_default, name, reach, " +
|
||||
" start_rk, end_rk, d90, enabled, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
@@ -104,12 +103,13 @@ class D90AdisTSSpec(SQLSubModel):
|
||||
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_reach_pid(execute, table_new, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0_set_d90_pid(cls, execute, data):
|
||||
pid_d90 = data["id2pid"]["d90_adists"]
|
||||
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:
|
||||
@@ -121,8 +121,8 @@ class D90AdisTSSpec(SQLSubModel):
|
||||
continue
|
||||
|
||||
execute(
|
||||
f"UPDATE d90_adists_spec" +
|
||||
f"SET d90 = {pid_d90[d90_id]} " +
|
||||
f"UPDATE d90_adists_spec " +
|
||||
f"SET d90_default = {pid_d90[d90_id]} " +
|
||||
f"WHERE pamhyr_id = {pid}"
|
||||
)
|
||||
|
||||
@@ -167,7 +167,7 @@ class D90AdisTSSpec(SQLSubModel):
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
new_spec.is_deleted()
|
||||
new_spec.set_as_deleted()
|
||||
|
||||
new_spec.reach = reach
|
||||
new_spec.start_rk = start_rk
|
||||
@@ -196,12 +196,12 @@ class D90AdisTSSpec(SQLSubModel):
|
||||
"d90_default, name, reach, " +
|
||||
"start_rk, end_rk, d90, enabled, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"{d90_default}, " +
|
||||
f"'{self._db_format(self._name_section)}', " +
|
||||
f"{self._reach}, " +
|
||||
f"{self._start_rk}, {self._end_rk}, " +
|
||||
f"{self._d90}, {self._enabled}" +
|
||||
f"{self._d90}, {self._enabled}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
@@ -261,3 +261,13 @@ class D90AdisTSSpec(SQLSubModel):
|
||||
def enabled(self, enabled):
|
||||
self._enabled = enabled
|
||||
self.modified()
|
||||
|
||||
def cloned_for(self, reach, start_rk, end_rk):
|
||||
new = D90AdisTSSpec(name=self._name_section, status=self._status)
|
||||
new._reach = reach
|
||||
new._start_rk = start_rk
|
||||
new._end_rk = end_rk
|
||||
new._d90 = self._d90
|
||||
new._enabled = self._enabled
|
||||
new.modified()
|
||||
return new
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if int(release) < 6:
|
||||
if major == "0" and int(minor) < 2:
|
||||
if cls.is_table_exists(execute, "dif_adists"):
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
else:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if not created:
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@@ -142,24 +140,24 @@ class DIFAdisTS(SQLSubModel):
|
||||
enabled = (next(it) == 1)
|
||||
owner_scenario = next(it)
|
||||
|
||||
dif = cls(
|
||||
DIF = cls(
|
||||
id=pid,
|
||||
name=name,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario,
|
||||
)
|
||||
|
||||
dif.method = method
|
||||
dif.dif = dif
|
||||
dif.b = b
|
||||
dif.c = c
|
||||
dif.enabled = enabled
|
||||
DIF.method = method
|
||||
DIF.dif = dif
|
||||
DIF.b = b
|
||||
DIF.c = c
|
||||
DIF.enabled = enabled
|
||||
|
||||
data['dif_default_id'] = pid
|
||||
dif._data = DIFAdisTSSpec._db_load(execute, data)
|
||||
DIF._data = DIFAdisTSSpec._db_load(execute, data)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(dif)
|
||||
new.append(DIF)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
@@ -190,7 +188,7 @@ class DIFAdisTS(SQLSubModel):
|
||||
b = self.b
|
||||
|
||||
c = -1.
|
||||
if self.dif is not None:
|
||||
if self.c is not None:
|
||||
c = self.c
|
||||
|
||||
sql = (
|
||||
@@ -201,7 +199,7 @@ class DIFAdisTS(SQLSubModel):
|
||||
"VALUES (" +
|
||||
f"{self.id}, '{self._db_format(self._name)}', " +
|
||||
f"'{self._db_format(self._method)}', " +
|
||||
f"{dif.id}, {b}, {c}, {self._enabled}, " +
|
||||
f"{dif}, {b}, {c}, {self._enabled}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
@@ -331,3 +329,44 @@ class DIFAdisTS(SQLSubModel):
|
||||
x.set_as_not_deleted()
|
||||
|
||||
self.modified()
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
split_rk = profile.rk
|
||||
reach_rks = reach.reach.get_rk()
|
||||
if len(reach_rks) == 0:
|
||||
return
|
||||
|
||||
parts = [
|
||||
(reach1.id, min(reach_rks), split_rk),
|
||||
(reach2.id, split_rk, max(reach_rks)),
|
||||
]
|
||||
specifications = [
|
||||
specification
|
||||
for specification in self._data
|
||||
if (not specification.is_deleted() and
|
||||
specification.reach == reach.id)
|
||||
]
|
||||
|
||||
for specification in specifications:
|
||||
begin = specification.start_rk
|
||||
end = specification.end_rk
|
||||
if begin is None or end is None:
|
||||
continue
|
||||
|
||||
lower, upper = sorted((begin, end))
|
||||
reverse = begin > end
|
||||
|
||||
for new_reach, part_lower, part_upper in parts:
|
||||
clipped_lower = max(lower, part_lower)
|
||||
clipped_upper = min(upper, part_upper)
|
||||
if clipped_lower >= clipped_upper:
|
||||
continue
|
||||
|
||||
start_rk = clipped_upper if reverse else clipped_lower
|
||||
end_rk = clipped_lower if reverse else clipped_upper
|
||||
self._data.append(specification.cloned_for(
|
||||
new_reach, start_rk, end_rk
|
||||
))
|
||||
|
||||
if len(specifications) != 0:
|
||||
self.modified()
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -61,6 +61,10 @@ class DIFAdisTSList(PamhyrModelList):
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
for dif in self.lst:
|
||||
dif.split_reach(reach, profile, reach1, reach2)
|
||||
|
||||
@property
|
||||
def DIF_AdisTS_List(self):
|
||||
return self.lst
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -33,16 +33,14 @@ class DIFAdisTSSpec(SQLSubModel):
|
||||
_id_cnt = 0
|
||||
|
||||
def __init__(self, id: int = -1, method: str = "",
|
||||
status=None):
|
||||
super(DIFAdisTSSpec, self).__init__()
|
||||
status=None, owner_scenario=-1):
|
||||
super(DIFAdisTSSpec, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._status = status
|
||||
|
||||
if id == -1:
|
||||
self.id = DIFAdisTSSpec._id_cnt
|
||||
else:
|
||||
self.id = id
|
||||
|
||||
self._method = method
|
||||
self._reach = None
|
||||
self._start_rk = None
|
||||
@@ -52,8 +50,6 @@ class DIFAdisTSSpec(SQLSubModel):
|
||||
self._c = None
|
||||
self._enabled = True
|
||||
|
||||
DIFAdisTSSpec._id_cnt = max(DIFAdisTSSpec._id_cnt + 1, self.id)
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
@@ -81,16 +77,12 @@ class DIFAdisTSSpec(SQLSubModel):
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
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 not created:
|
||||
if cls.is_table_exists(execute, "dif_spec"):
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
else:
|
||||
cls._db_create(execute)
|
||||
|
||||
return True
|
||||
|
||||
@@ -195,7 +187,7 @@ class DIFAdisTSSpec(SQLSubModel):
|
||||
new_spec.c = c
|
||||
new_spec.enabled = enabled
|
||||
|
||||
loaded.add(pid)
|
||||
loaded.add(id)
|
||||
new.append(new_spec)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
@@ -210,22 +202,23 @@ class DIFAdisTSSpec(SQLSubModel):
|
||||
|
||||
dif_default = data['dif_default_id']
|
||||
|
||||
execute(
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"dif_adists_spec(pamhyr_id, deleted, " +
|
||||
"dif_default, method, reach, " +
|
||||
"start_rk, end_rk, dif, b, c, enabled, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"{dif_default}, " +
|
||||
f"'{self._db_format(self._method)}', " +
|
||||
f"{self._reach}, " +
|
||||
f"{self._start_rk}, {self._end_rk}, " +
|
||||
f"{self._dif}, {self._b}, {self._c}, " +
|
||||
f"{self._enabled}" +
|
||||
f"{self._enabled}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
execute(sql)
|
||||
|
||||
return True
|
||||
|
||||
@@ -300,3 +293,15 @@ class DIFAdisTSSpec(SQLSubModel):
|
||||
def enabled(self, enabled):
|
||||
self._enabled = enabled
|
||||
self._status.modified()
|
||||
|
||||
def cloned_for(self, reach, start_rk, end_rk):
|
||||
new = DIFAdisTSSpec(method=self._method, status=self._status)
|
||||
new._reach = reach
|
||||
new._start_rk = start_rk
|
||||
new._end_rk = end_rk
|
||||
new._dif = self._dif
|
||||
new._b = self._b
|
||||
new._c = self._c
|
||||
new._enabled = self._enabled
|
||||
new.modified()
|
||||
return new
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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
|
||||
|
||||
return (
|
||||
self._begin_strickler._owner_scenario == ssi
|
||||
# or self._end_strickler._owner_scenario == ssi
|
||||
or super(Friction, self).must_be_saved()
|
||||
self._begin_strickler is not None
|
||||
and (self._begin_strickler._owner_scenario == ssi
|
||||
# or self._end_strickler._owner_scenario == ssi
|
||||
or super(Friction, self).must_be_saved())
|
||||
)
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
@@ -364,3 +365,9 @@ class Friction(SQLSubModel):
|
||||
# self.end_strickler.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
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
# Copyright (C) 2023-2026 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -109,16 +109,22 @@ class FrictionList(PamhyrModelList):
|
||||
((999 ** 100), -(999 ** 100))
|
||||
)
|
||||
|
||||
frictions = list(
|
||||
filter(
|
||||
lambda f: ((rk_min <= f.begin_rk <= rk_max) or
|
||||
(rk_min <= f.end_rk <= rk_max)),
|
||||
self._lst))
|
||||
for friction in self.lst:
|
||||
lower, upper = sorted((friction.begin_rk, friction.end_rk))
|
||||
clipped_lower = max(lower, rk_min)
|
||||
clipped_upper = min(upper, rk_max)
|
||||
if clipped_lower >= clipped_upper:
|
||||
continue
|
||||
|
||||
for ind, friction in enumerate(frictions):
|
||||
n = friction.cloned_for(reach)
|
||||
if friction.begin_rk > friction.end_rk:
|
||||
n.begin_rk = clipped_upper
|
||||
n.end_rk = clipped_lower
|
||||
else:
|
||||
n.begin_rk = clipped_lower
|
||||
n.end_rk = clipped_upper
|
||||
|
||||
new._lst.insert(ind, n)
|
||||
new._lst.append(n)
|
||||
new._status.modified()
|
||||
|
||||
return new
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -55,8 +55,11 @@ class Point(SQLSubModel):
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
changed = self._name != name
|
||||
self._name = name
|
||||
self.modified()
|
||||
if changed and self._profile is not None:
|
||||
self._profile.content_modified()
|
||||
|
||||
def is_named(self):
|
||||
"""
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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)
|
||||
|
||||
@classmethod
|
||||
@@ -90,6 +95,12 @@ class PointXYZ(Point):
|
||||
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
|
||||
)
|
||||
|
||||
# Try to create index at each update
|
||||
execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_point " +
|
||||
"ON geometry_pointXYZ(profile, scenario);"
|
||||
)
|
||||
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
@@ -317,8 +328,11 @@ class PointXYZ(Point):
|
||||
|
||||
@x.setter
|
||||
def x(self, value):
|
||||
changed = self._x != float(value)
|
||||
self._x = float(value)
|
||||
self.modified()
|
||||
if changed and self._profile is not None:
|
||||
self._profile.content_modified()
|
||||
|
||||
@property
|
||||
def y(self):
|
||||
@@ -326,8 +340,11 @@ class PointXYZ(Point):
|
||||
|
||||
@y.setter
|
||||
def y(self, value):
|
||||
changed = self._y != float(value)
|
||||
self._y = float(value)
|
||||
self.modified()
|
||||
if changed and self._profile is not None:
|
||||
self._profile.content_modified()
|
||||
|
||||
@property
|
||||
def z(self):
|
||||
@@ -335,8 +352,18 @@ class PointXYZ(Point):
|
||||
|
||||
@z.setter
|
||||
def z(self, value):
|
||||
changed = self._z != float(value)
|
||||
self._z = float(value)
|
||||
self.modified()
|
||||
if changed and self._profile is not None:
|
||||
self._profile.content_modified()
|
||||
|
||||
def shift(self, x, y, z):
|
||||
self.x += x
|
||||
self.y += y
|
||||
self.z += z
|
||||
|
||||
self.modified()
|
||||
|
||||
def get_coordinate(self):
|
||||
return (self._x, self._y, self._z)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -47,6 +47,8 @@ class Profile(object):
|
||||
self._sl = None
|
||||
|
||||
self._points: List[Point] = []
|
||||
self._modification_count = 0
|
||||
self._old_interpolated = ""
|
||||
|
||||
self._profile_type = _type
|
||||
|
||||
@@ -160,8 +162,13 @@ class Profile(object):
|
||||
|
||||
@rk.setter
|
||||
def rk(self, value: float):
|
||||
self._rk = float(value)
|
||||
self.modified()
|
||||
value = float(value)
|
||||
changed = value != self._rk
|
||||
self._rk = value
|
||||
if changed:
|
||||
self.content_modified()
|
||||
else:
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@@ -173,8 +180,13 @@ class Profile(object):
|
||||
|
||||
@name.setter
|
||||
def name(self, value: str):
|
||||
self._name = value.strip()
|
||||
self.modified()
|
||||
value = value.strip()
|
||||
changed = value != self._name
|
||||
self._name = value
|
||||
if changed:
|
||||
self.content_modified()
|
||||
else:
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def sl(self):
|
||||
@@ -217,6 +229,38 @@ class Profile(object):
|
||||
return [point for point in self.points
|
||||
if point.is_named()]
|
||||
|
||||
@property
|
||||
def modification_count(self):
|
||||
"""Content revision for this session; not stored in the database."""
|
||||
return self._modification_count
|
||||
|
||||
def increase_modification_count(self):
|
||||
"""Increase content revision for this session;
|
||||
not stored in the database."""
|
||||
self._modification_count += 1
|
||||
|
||||
def decrease_modification_count(self):
|
||||
"""Decrease content revision for this session;
|
||||
not stored in the database."""
|
||||
self._modification_count -= 1
|
||||
|
||||
@property
|
||||
def old_interpolated(self):
|
||||
"""Old interpolated value for this session;
|
||||
not stored in the database."""
|
||||
return self._old_interpolated
|
||||
|
||||
@old_interpolated.setter
|
||||
def old_interpolated(self, value):
|
||||
self._old_interpolated = value
|
||||
|
||||
def content_modified(self):
|
||||
"""An edited profile is no longer an interpolation result."""
|
||||
# self._modification_count += 1
|
||||
if hasattr(self, "_interpolated"):
|
||||
self._interpolated = False
|
||||
self.modified()
|
||||
|
||||
def insert_point(self, index: int, point: Point):
|
||||
"""Insert point at index.
|
||||
|
||||
@@ -232,7 +276,7 @@ class Profile(object):
|
||||
else:
|
||||
self._points.insert(index, point)
|
||||
|
||||
self.modified()
|
||||
self.content_modified()
|
||||
|
||||
def delete_i(self, indexes: list):
|
||||
list(
|
||||
@@ -245,7 +289,7 @@ class Profile(object):
|
||||
)
|
||||
)
|
||||
|
||||
self.modified()
|
||||
self.content_modified()
|
||||
|
||||
def delete_points(self, points):
|
||||
"""Delete some elements in profile list
|
||||
@@ -262,7 +306,7 @@ class Profile(object):
|
||||
points
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
self.content_modified()
|
||||
|
||||
# Move
|
||||
|
||||
@@ -272,7 +316,7 @@ class Profile(object):
|
||||
|
||||
p = self._points
|
||||
p[index], p[next] = p[next], p[index]
|
||||
self.modified()
|
||||
self.content_modified()
|
||||
|
||||
def move_down_point(self, index: int):
|
||||
if index >= 0:
|
||||
@@ -280,7 +324,7 @@ class Profile(object):
|
||||
|
||||
p = self._points
|
||||
p[index], p[prev] = p[prev], p[index]
|
||||
self.modified()
|
||||
self.content_modified()
|
||||
|
||||
# Sort
|
||||
|
||||
@@ -297,7 +341,7 @@ class Profile(object):
|
||||
key=predicate,
|
||||
reverse=is_reversed
|
||||
)
|
||||
self.modified()
|
||||
self.content_modified()
|
||||
|
||||
@timer
|
||||
def sort_with_indexes(self, indexes: list):
|
||||
@@ -313,12 +357,12 @@ class Profile(object):
|
||||
)
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
self.content_modified()
|
||||
|
||||
@timer
|
||||
def reverse(self):
|
||||
self._points.reverse()
|
||||
self.modified()
|
||||
self.content_modified()
|
||||
|
||||
# Sediment Layers
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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 dataclasses import dataclass
|
||||
|
||||
from tools import timer, flatten
|
||||
from tools import trace, timer, flatten
|
||||
from shapely import geometry
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
@@ -58,7 +58,8 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
num=0,
|
||||
nb_point: int = 0,
|
||||
code1: int = 0, code2: int = 0,
|
||||
status=None, owner_scenario=-1):
|
||||
status=None, owner_scenario=-1,
|
||||
enabled=True, interpolated=False):
|
||||
"""ProfileXYZ constructor
|
||||
|
||||
Args:
|
||||
@@ -90,6 +91,11 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
self.time_l = 0.0
|
||||
self._station = []
|
||||
self.station_up_to_date = False
|
||||
self._enabled = bool(enabled)
|
||||
self._interpolated = bool(interpolated)
|
||||
|
||||
self._get_water_limits_cache = {}
|
||||
self._get_water_limits_ac_cache = {}
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
@@ -105,6 +111,8 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
code1 INTEGER NOT NULL,
|
||||
code2 INTEGER NOT NULL,
|
||||
sl INTEGER,
|
||||
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
interpolated BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id),
|
||||
@@ -149,6 +157,27 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
|
||||
)
|
||||
|
||||
if major == "0" and int(minor) <= 2:
|
||||
if int(release) < 9:
|
||||
execute(
|
||||
"ALTER TABLE geometry_profileXYZ " +
|
||||
"ADD COLUMN enabled BOOLEAN NOT NULL DEFAULT TRUE"
|
||||
)
|
||||
|
||||
if major == "0" and (int(minor) < 2 or
|
||||
(minor == "2" and int(release) < 10)):
|
||||
if minor != "0":
|
||||
execute(
|
||||
"ALTER TABLE geometry_profileXYZ " +
|
||||
"ADD COLUMN interpolated BOOLEAN NOT NULL DEFAULT FALSE"
|
||||
)
|
||||
execute(
|
||||
"UPDATE geometry_profileXYZ " +
|
||||
"SET interpolated = CASE " +
|
||||
"WHEN LOWER(name) LIKE 'interpol%' THEN TRUE " +
|
||||
"ELSE FALSE END"
|
||||
)
|
||||
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
@@ -234,7 +263,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, ind, deleted, name, rk, num, " +
|
||||
"code1, code2, sl, scenario " +
|
||||
"code1, code2, sl, scenario, enabled, interpolated " +
|
||||
"FROM geometry_profileXYZ " +
|
||||
f"WHERE reach = {reach.id} " +
|
||||
f"AND scenario = {scenario.id} " +
|
||||
@@ -255,6 +284,8 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
code2 = next(it)
|
||||
sl = next(it)
|
||||
owner_scenario = next(it)
|
||||
enabled = (next(it) == 1)
|
||||
interpolated = (next(it) == 1)
|
||||
|
||||
profile = cls(
|
||||
id=pid, ind=ind, num=num,
|
||||
@@ -262,7 +293,9 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
code1=code1, code2=code2,
|
||||
reach=reach,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
owner_scenario=owner_scenario,
|
||||
enabled=enabled,
|
||||
interpolated=interpolated
|
||||
)
|
||||
if deleted:
|
||||
profile.set_as_deleted()
|
||||
@@ -315,12 +348,14 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
execute(
|
||||
"INSERT OR REPLACE INTO " +
|
||||
"geometry_profileXYZ(pamhyr_id, deleted, ind, name, reach, " +
|
||||
"rk, num, code1, code2, sl, scenario) " +
|
||||
"rk, num, code1, code2, sl, scenario, enabled, interpolated) " +
|
||||
"VALUES (" +
|
||||
f"{self.pamhyr_id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"{ind}, '{self._db_format(self._name)}', " +
|
||||
f"{self.reach.pamhyr_id}, {self.rk}, {self.num}, " +
|
||||
f"{self.code1}, {self.code1}, {sl}, {self._status.scenario_id}" +
|
||||
f"{self.code1}, {self.code1}, {sl}, {self._status.scenario_id}, " +
|
||||
f"{self._db_format(self._enabled)}, " +
|
||||
f"{self._db_format(self._interpolated)}" +
|
||||
")"
|
||||
)
|
||||
|
||||
@@ -387,7 +422,9 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
name=self.name,
|
||||
rk=self.rk,
|
||||
reach=self.reach,
|
||||
status=self._status
|
||||
status=self._status,
|
||||
enabled=self.is_enabled,
|
||||
interpolated=self.interpolated
|
||||
)
|
||||
if self.is_deleted():
|
||||
new_p.set_as_deleted()
|
||||
@@ -396,7 +433,6 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
|
||||
for point in self._points:
|
||||
p = point.copy()
|
||||
print(p)
|
||||
new_p._points.append(p)
|
||||
|
||||
new_p.modified()
|
||||
@@ -408,7 +444,9 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
name=self.name,
|
||||
rk=self.rk,
|
||||
reach=new_reach,
|
||||
status=self._status
|
||||
status=self._status,
|
||||
enabled=self.is_enabled,
|
||||
interpolated=self.interpolated
|
||||
)
|
||||
if self.is_deleted():
|
||||
new_p.set_as_deleted()
|
||||
@@ -521,7 +559,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
)
|
||||
self._points.append(pt)
|
||||
|
||||
self.modified()
|
||||
self.content_modified()
|
||||
|
||||
def get_point_i(self, index: int) -> PointXYZ:
|
||||
"""Get point at index.
|
||||
@@ -586,7 +624,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
)
|
||||
self.points.append(point_xyz)
|
||||
|
||||
self.modified()
|
||||
self.content_modified()
|
||||
|
||||
def insert(self, index: int):
|
||||
"""Insert a new point at index.
|
||||
@@ -605,7 +643,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
point = PointXYZ(x=x, y=y, z=z, profile=self, status=self._status)
|
||||
self._points.insert(index, point)
|
||||
|
||||
self.modified()
|
||||
self.content_modified()
|
||||
|
||||
return point
|
||||
|
||||
@@ -620,6 +658,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
"""
|
||||
return [x for x in lst if not np.isnan(x)]
|
||||
|
||||
@timer
|
||||
def speed(self, q, z):
|
||||
area = self.wet_area(z)
|
||||
|
||||
@@ -671,6 +710,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
length += line.length
|
||||
return length
|
||||
|
||||
@timer
|
||||
def compute_wet_area(self, z):
|
||||
area = 0.0
|
||||
if len(self.tab.L) > 0:
|
||||
@@ -711,6 +751,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
if len(line.coords) > 2:
|
||||
poly = geometry.Polygon(line)
|
||||
area += poly.area
|
||||
|
||||
return area
|
||||
|
||||
def wet_radius(self, z):
|
||||
@@ -733,6 +774,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
line = geometry.LineString(list(zip(station, zz)))
|
||||
return line
|
||||
|
||||
@timer
|
||||
def wet_lines(self, z):
|
||||
points = self._points
|
||||
if len(points) < 3:
|
||||
@@ -809,7 +851,6 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
return points
|
||||
|
||||
def get_nb_wet_areas(self, z):
|
||||
|
||||
n_zones = 0
|
||||
points = self._points
|
||||
if points[0].z <= z:
|
||||
@@ -821,10 +862,13 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
|
||||
return n_zones
|
||||
|
||||
@timer
|
||||
def get_all_water_limits_ac(self, z):
|
||||
"""
|
||||
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
|
||||
if len(points) < 3:
|
||||
@@ -857,69 +901,94 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
logger.error(f"ERROR in get_all_water_limits_ac")
|
||||
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):
|
||||
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.
|
||||
"""
|
||||
|
||||
# Get the index of first point with elevation lesser than water
|
||||
# elevation (for the right and left river side)
|
||||
i_left = -1
|
||||
i_right = -1
|
||||
i_left = next(
|
||||
filter(
|
||||
lambda i: self.point(i).z <= z,
|
||||
range(self.number_points)
|
||||
),
|
||||
-1
|
||||
)
|
||||
|
||||
for i in range(self.number_points):
|
||||
if self.point(i).z <= z:
|
||||
i_left = i
|
||||
break
|
||||
|
||||
for i in reversed(range(self.number_points)):
|
||||
if self.point(i).z <= z:
|
||||
i_right = i
|
||||
break
|
||||
i_right = next(
|
||||
filter(
|
||||
lambda i: self.point(i).z <= z,
|
||||
reversed(range(self.number_points))
|
||||
),
|
||||
-1
|
||||
)
|
||||
|
||||
# Interpolate points at river left side
|
||||
if (i_left > 0):
|
||||
if abs(self.point(i_left - 1).z - self.point(i_left).z) < 1e-20:
|
||||
pt_left = self.point(i_left)
|
||||
pi = self.point(i_left)
|
||||
pim1 = self.point(i_left - 1)
|
||||
|
||||
if abs(pim1.z - pi.z) < 1e-20:
|
||||
pt_left = pi
|
||||
else:
|
||||
fact = (z - self.point(i_left).z) / \
|
||||
(self.point(i_left - 1).z - self.point(i_left).z)
|
||||
x = self.point(i_left).x + fact * \
|
||||
(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)
|
||||
fact = (z - pi.z) / (pim1.z - pi.z)
|
||||
x = pi.x + fact * (pim1.x - pi.x)
|
||||
y = pi.y + fact * (pim1.y - pi.y)
|
||||
pt_left = PointXYZ(x=x, y=y, z=z, name="wl_left")
|
||||
else:
|
||||
pt_left = self.point(0)
|
||||
|
||||
# Interpolate points at river right side
|
||||
if (i_right < self.number_points - 1):
|
||||
if abs(self.point(i_right + 1).z - self.point(i_right).z) < 1e-20:
|
||||
pt_right = self.point(i_right)
|
||||
pi = self.point(i_right)
|
||||
pip1 = self.point(i_right + 1)
|
||||
|
||||
if abs(pip1.z - pi.z) < 1e-20:
|
||||
pt_right = pi
|
||||
else:
|
||||
fact = (z - self.point(i_right).z) / \
|
||||
(self.point(i_right + 1).z - self.point(i_right).z)
|
||||
x = self.point(i_right).x + fact * \
|
||||
(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)
|
||||
fact = (z - pi.z) / (pip1.z - pi.z)
|
||||
x = pi.x + fact * (pip1.x - pi.x)
|
||||
y = pi.y + fact * (pip1.y - pi.y)
|
||||
pt_right = PointXYZ(x=x, y=y, z=z, name="wl_right")
|
||||
else:
|
||||
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):
|
||||
sorted_points = sorted(self._points, key=lambda p: p.z)
|
||||
|
||||
self.tab.z = np.array([p.z for p in sorted_points], np.float64)
|
||||
self.tab.L = np.zeros(len(self.tab.z), np.float64)
|
||||
self.tab.A = np.zeros(len(self.tab.z), np.float64)
|
||||
|
||||
for i in range(1, len(self.tab.z)):
|
||||
self.tab.L[i] = self.compute_wet_width(self.tab.z[i])
|
||||
|
||||
dx = (self.tab.L[i] + self.tab.L[i-1])/2
|
||||
dz = self.tab.z[i] - self.tab.z[i-1]
|
||||
|
||||
self.tab.A[i] = self.tab.A[i-1] + dz * dx
|
||||
|
||||
self.tab_up_to_date = True
|
||||
@@ -934,7 +1003,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
Projection of the points of the profile on a plane.
|
||||
"""
|
||||
if self.nb_points < 2:
|
||||
return [0.0]
|
||||
return [0.0] * self.nb_points
|
||||
else:
|
||||
if self.station_up_to_date:
|
||||
return self._station
|
||||
@@ -1074,16 +1143,10 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
|
||||
def shift(self, x, y, z):
|
||||
for p in self._points:
|
||||
p.x = p.x + x
|
||||
p.y = p.y + y
|
||||
p.z = p.z + z
|
||||
p.shift(x, y, z)
|
||||
|
||||
self.modified()
|
||||
|
||||
def modified(self):
|
||||
self.tab_up_to_date = False
|
||||
self.station_up_to_date = False
|
||||
|
||||
def add_npoints(self, npoints):
|
||||
# add npoints in a profile
|
||||
for k in range(npoints):
|
||||
@@ -1104,10 +1167,14 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
p = ProfileXYZ(name=self.name,
|
||||
rk=self.rk,
|
||||
reach=self.reach,
|
||||
status=self._status)
|
||||
for i, k in enumerate(self.points):
|
||||
p.insert_point(i, k.copy())
|
||||
status=self._status,
|
||||
enabled=self.is_enabled,
|
||||
interpolated=self.interpolated)
|
||||
|
||||
for i, k in enumerate(self.points):
|
||||
p.insert_point(i, k.cloned_for(p))
|
||||
|
||||
p._interpolated = self.interpolated
|
||||
return p
|
||||
|
||||
def purge_aligned_points(self):
|
||||
@@ -1137,3 +1204,25 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
break
|
||||
self._points = points
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def is_enabled(self):
|
||||
return self._enabled
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
return self._enabled
|
||||
|
||||
@enabled.setter
|
||||
def enabled(self, value):
|
||||
self._enabled = bool(value)
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def interpolated(self):
|
||||
return self._interpolated
|
||||
|
||||
@interpolated.setter
|
||||
def interpolated(self, value):
|
||||
self._interpolated = bool(value)
|
||||
self.modified()
|
||||
+86
-13
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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 = {}
|
||||
|
||||
super(Reach, self).__init__(
|
||||
id=parent.pamhyr_id,
|
||||
status=status,
|
||||
)
|
||||
|
||||
@property
|
||||
def pamhyr_id(self):
|
||||
return self._parent.pamhyr_id
|
||||
@@ -60,6 +65,10 @@ class Reach(SQLSubModel):
|
||||
def _pamhyr_id(self):
|
||||
return self._parent.pamhyr_id
|
||||
|
||||
@_pamhyr_id.setter
|
||||
def _pamhyr_id(self, id):
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
return cls._create_submodel(execute)
|
||||
@@ -71,11 +80,13 @@ class Reach(SQLSubModel):
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = cls(status=data["status"], parent=data["reach"])
|
||||
profile_data = data.copy()
|
||||
profile_data["reach"] = new
|
||||
|
||||
new._profiles = sorted(
|
||||
ProfileXYZ._db_load(
|
||||
execute,
|
||||
data=data.copy()
|
||||
data=profile_data
|
||||
),
|
||||
key=lambda p: p._db_ind
|
||||
)
|
||||
@@ -103,6 +114,9 @@ class Reach(SQLSubModel):
|
||||
predicate=lambda obj, data: True,
|
||||
modifier=lambda obj, data: None,
|
||||
data={}):
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
for p in self._profiles:
|
||||
p._data_traversal(predicate, modifier, data)
|
||||
|
||||
@@ -145,6 +159,14 @@ class Reach(SQLSubModel):
|
||||
def profiles(self, profiles):
|
||||
self._profiles = profiles
|
||||
|
||||
@property
|
||||
def enabled_profiles(self):
|
||||
return list(filter(lambda p: p.is_enabled, self.profiles))
|
||||
|
||||
@property
|
||||
def number_enabled_profiles(self):
|
||||
return len(self.enabled_profiles)
|
||||
|
||||
def get_profiles_from_rk(self, rk):
|
||||
return list(
|
||||
filter(
|
||||
@@ -199,13 +221,12 @@ class Reach(SQLSubModel):
|
||||
else:
|
||||
gi = self.get_global_profil_index(index)
|
||||
profile.num = gi
|
||||
print(f"gi = {gi}")
|
||||
self._profiles.insert(gi, profile)
|
||||
|
||||
self.modified()
|
||||
|
||||
def delete(self, indexes):
|
||||
"""Delete some elements in profile list
|
||||
"""Set some elements as deleted in profile list
|
||||
|
||||
Args:
|
||||
indexes: The list of index to delete
|
||||
@@ -247,7 +268,7 @@ class Reach(SQLSubModel):
|
||||
self.modified()
|
||||
|
||||
def delete_profiles(self, profiles):
|
||||
"""Delete some elements in profile list
|
||||
"""Set profiles list as deleted
|
||||
|
||||
Args:
|
||||
profiles: The list of profile to delete
|
||||
@@ -356,6 +377,28 @@ class Reach(SQLSubModel):
|
||||
)
|
||||
)
|
||||
|
||||
def get_z_min_enabled_profiles(self):
|
||||
return list(
|
||||
map(
|
||||
lambda profile: profile.z_min(),
|
||||
filter(
|
||||
lambda profile: len(profile) > 0 and profile.is_enabled,
|
||||
self.profiles
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def get_z_max_enabled_profiles(self):
|
||||
return list(
|
||||
map(
|
||||
lambda profile: profile.z_max(),
|
||||
filter(
|
||||
lambda profile: len(profile) > 0 and profile.is_enabled,
|
||||
self.profiles
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def get_rk(self):
|
||||
"""List of profiles rk
|
||||
|
||||
@@ -364,6 +407,17 @@ class Reach(SQLSubModel):
|
||||
"""
|
||||
return [profile.rk for profile in self.profiles]
|
||||
|
||||
def get_rk_enabled_profiles(self):
|
||||
return list(
|
||||
map(
|
||||
lambda profile: profile.rk,
|
||||
filter(
|
||||
lambda profile: len(profile) > 0 and profile.is_enabled,
|
||||
self.profiles
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def get_rk_complete_profiles(self):
|
||||
return list(
|
||||
map(
|
||||
@@ -475,14 +529,22 @@ class Reach(SQLSubModel):
|
||||
)
|
||||
|
||||
@timer
|
||||
def compute_guidelines(self):
|
||||
def compute_guidelines(self, profiles=None, update_cache=True):
|
||||
"""Compute reach guidelines
|
||||
|
||||
Args:
|
||||
profiles: Profiles used to compute the guidelines. If omitted,
|
||||
all non-deleted profiles of the reach are used.
|
||||
update_cache: Whether to update the reach guidelines cache.
|
||||
|
||||
Returns:
|
||||
Tuple of complete and incomplete guidelines name.
|
||||
"""
|
||||
if profiles is None:
|
||||
profiles = self.profiles
|
||||
|
||||
# Get all point contained into a guideline
|
||||
named_points = [profile.named_points() for profile in self.profiles]
|
||||
named_points = [profile.named_points() for profile in profiles]
|
||||
points_name = list(
|
||||
map(
|
||||
lambda lst: list(map(lambda p: p.name, lst)),
|
||||
@@ -513,11 +575,13 @@ class Reach(SQLSubModel):
|
||||
|
||||
complete = guide_set - incomplete
|
||||
|
||||
# Compute guideline and put data in cache
|
||||
self._compute_guidelines_cache(guide_set, named_points,
|
||||
complete, incomplete)
|
||||
if update_cache:
|
||||
# Compute guideline and put data in cache
|
||||
self._compute_guidelines_cache(
|
||||
guide_set, named_points, complete, incomplete
|
||||
)
|
||||
self.modified()
|
||||
|
||||
self.modified()
|
||||
return (complete, incomplete)
|
||||
|
||||
def _map_guidelines_points(self, func, full=False):
|
||||
@@ -741,8 +805,11 @@ class Reach(SQLSubModel):
|
||||
list_profile.append(list_point_profile)
|
||||
list_point_profile = []
|
||||
else:
|
||||
line.append("")
|
||||
list_point_profile.append(line[:3])
|
||||
# MAGE-8 ST files can append hydraulic data
|
||||
# after the regular x, y, z and point-name
|
||||
# fields. ProfileXYZ still expects exactly
|
||||
# those first four fields.
|
||||
list_point_profile.append(line[:4])
|
||||
else:
|
||||
pass
|
||||
|
||||
@@ -956,3 +1023,9 @@ class Reach(SQLSubModel):
|
||||
break
|
||||
|
||||
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
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
# Copyright (C) 2023-2026 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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(
|
||||
execute, data
|
||||
)
|
||||
print(f"{bhs_pid} : {deleted}")
|
||||
if deleted:
|
||||
bhs.set_as_deleted()
|
||||
|
||||
@@ -278,3 +277,10 @@ class BasicHS(SQLSubModel):
|
||||
|
||||
def convert(self, new_type):
|
||||
return new_type(id=self.id, name=self.name, status=self._status)
|
||||
|
||||
def cloned(self):
|
||||
new = type(self)(name=self._name, status=self._status)
|
||||
new._enabled = self._enabled
|
||||
new._data = [value.cloned() for value in self._data]
|
||||
new.modified()
|
||||
return new
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -208,3 +208,11 @@ class BHSValue(SQLSubModel):
|
||||
def value(self, value):
|
||||
self._value = self._type(value)
|
||||
self.modified()
|
||||
|
||||
def cloned(self):
|
||||
return BHSValue(
|
||||
name=self._name,
|
||||
type=self._type,
|
||||
value=self._value,
|
||||
status=self._status
|
||||
)
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -47,9 +47,7 @@ class HydraulicStructure(SQLSubModel):
|
||||
|
||||
self._name = name
|
||||
self._input_section = None
|
||||
self._output_section = None
|
||||
self._input_reach = None
|
||||
self._output_reach = None
|
||||
self._enabled = True
|
||||
self._data = []
|
||||
|
||||
@@ -62,17 +60,12 @@ class HydraulicStructure(SQLSubModel):
|
||||
name TEXT NOT NULL,
|
||||
enabled BOOLEAN NOT NULL,
|
||||
input_reach INTEGER,
|
||||
output_reach INTEGER,
|
||||
input_section INTEGER,
|
||||
output_section INTEGER,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(input_reach) REFERENCES river_reach(pamhyr_id),
|
||||
FOREIGN KEY(output_reach) REFERENCES river_reach(pamhyr_id),
|
||||
FOREIGN KEY(input_section)
|
||||
REFERENCES geometry_profileXYZ(pamhyr_id),
|
||||
FOREIGN KEY(output_section)
|
||||
REFERENCES geometry_profileXYZ(pamhyr_id),
|
||||
PRIMARY KEY(pamhyr_id, scenario)
|
||||
)
|
||||
""")
|
||||
@@ -92,13 +85,12 @@ class HydraulicStructure(SQLSubModel):
|
||||
return True
|
||||
|
||||
if rl < 11:
|
||||
for v in ["input", "output"]:
|
||||
execute(
|
||||
f"""
|
||||
ALTER TABLE hydraulic_structures
|
||||
RENAME COLUMN {v}_kp TO {v}_rk
|
||||
"""
|
||||
)
|
||||
execute(
|
||||
"""
|
||||
ALTER TABLE hydraulic_structures
|
||||
RENAME COLUMN input_kp TO input_rk
|
||||
"""
|
||||
)
|
||||
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
@@ -112,8 +104,28 @@ class HydraulicStructure(SQLSubModel):
|
||||
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
|
||||
)
|
||||
|
||||
if major == "0" and (int(minor) < 2 or
|
||||
(minor == "2" and rl < 10)):
|
||||
cls._db_update_to_0_2_10(execute)
|
||||
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_10(cls, execute):
|
||||
table = "hydraulic_structures"
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, deleted, name, enabled, input_section, " +
|
||||
"input_reach, scenario) " +
|
||||
"SELECT pamhyr_id, deleted, name, enabled, input_section, " +
|
||||
f"input_reach, scenario FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "hydraulic_structures"
|
||||
@@ -131,11 +143,10 @@ class HydraulicStructure(SQLSubModel):
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, name, enabled, input_section, output_section, " +
|
||||
"input_reach, output_reach, scenario) " +
|
||||
"(pamhyr_id, name, enabled, input_section, " +
|
||||
"input_reach, scenario) " +
|
||||
"SELECT pamhyr_id, name, enabled, " +
|
||||
"input_section, output_section, " +
|
||||
"input_reach, output_reach, scenario " +
|
||||
"input_section, input_reach, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
@@ -145,44 +156,38 @@ class HydraulicStructure(SQLSubModel):
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0_set_reach_pid(cls, execute, table, reachs):
|
||||
els = execute(
|
||||
f"SELECT pamhyr_id, input_reach, output_reach FROM {table}"
|
||||
f"SELECT pamhyr_id, input_reach FROM {table}"
|
||||
)
|
||||
|
||||
for row in els:
|
||||
it = iter(row)
|
||||
pid = next(it)
|
||||
in_reach_id = next(it)
|
||||
out_reach_id = next(it)
|
||||
|
||||
if in_reach_id == -1:
|
||||
return
|
||||
|
||||
if out_reach_id == -1:
|
||||
out_reach_id = in_reach_id
|
||||
|
||||
execute(
|
||||
f"UPDATE {table} " +
|
||||
f"SET input_reach = {reachs[in_reach_id]}, " +
|
||||
f"output_reach = {reachs[out_reach_id]} " +
|
||||
f"SET input_reach = {reachs[in_reach_id]} " +
|
||||
f"WHERE pamhyr_id = {pid}"
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_1(cls, execute, data,
|
||||
origin_version="0.1.0"):
|
||||
for v in ["input", "output"]:
|
||||
execute(
|
||||
"ALTER TABLE hydraulic_structures " +
|
||||
f"ADD COLUMN {v}_section INTEGER"
|
||||
)
|
||||
execute(
|
||||
"ALTER TABLE hydraulic_structures " +
|
||||
"ADD COLUMN input_section INTEGER"
|
||||
)
|
||||
|
||||
cls._db_update_to_0_1_1_assoc_section_from_rk(
|
||||
execute, "hydraulic_structures",
|
||||
reach_column=f"{v}_reach",
|
||||
rk_column=f"{v}_rk",
|
||||
section_column=f"{v}_section",
|
||||
origin_version=origin_version
|
||||
)
|
||||
cls._db_update_to_0_1_1_assoc_section_from_rk(
|
||||
execute, "hydraulic_structures",
|
||||
reach_column="input_reach",
|
||||
rk_column="input_rk",
|
||||
section_column="input_section",
|
||||
origin_version=origin_version
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
@@ -196,8 +201,7 @@ class HydraulicStructure(SQLSubModel):
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, name, enabled, " +
|
||||
"input_section, output_section, " +
|
||||
"input_reach, output_reach, scenario " +
|
||||
"input_section, input_reach, scenario " +
|
||||
"FROM hydraulic_structures " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
|
||||
@@ -227,12 +231,7 @@ class HydraulicStructure(SQLSubModel):
|
||||
input_section_id = (
|
||||
-1 if input_section_id is None else input_section_id
|
||||
)
|
||||
output_section_id = next(it)
|
||||
output_section_id = (
|
||||
-1 if output_section_id is None else output_section_id
|
||||
)
|
||||
input_reach_id = next(it)
|
||||
output_reach_id = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
hs = cls(
|
||||
@@ -243,27 +242,19 @@ class HydraulicStructure(SQLSubModel):
|
||||
hs.set_as_deleted()
|
||||
|
||||
hs.enabled = enabled
|
||||
hs.input_reach, hs.output_reach = reduce(
|
||||
lambda acc, n: (
|
||||
n if n.pamhyr_id == input_reach_id else acc[0],
|
||||
n if n.pamhyr_id == output_reach_id else acc[1]
|
||||
),
|
||||
hs.input_reach = reduce(
|
||||
lambda acc, n: n if n.pamhyr_id == input_reach_id else acc,
|
||||
data["edges"],
|
||||
[None, None]
|
||||
None
|
||||
)
|
||||
sections = []
|
||||
if hs.input_reach is not None:
|
||||
sections += hs.input_reach.reach.profiles
|
||||
if hs.output_reach is not None:
|
||||
sections += hs.output_reach.reach.profiles
|
||||
|
||||
hs.input_section, hs.output_section = reduce(
|
||||
lambda acc, s: (
|
||||
s if s.pamhyr_id == input_section_id else acc[0],
|
||||
s if s.pamhyr_id == output_section_id else acc[1]
|
||||
),
|
||||
hs.input_section = reduce(
|
||||
lambda acc, s: s if s.pamhyr_id == input_section_id else acc,
|
||||
sections,
|
||||
[None, None]
|
||||
None
|
||||
)
|
||||
|
||||
loaded.add(hs_id)
|
||||
@@ -274,6 +265,9 @@ class HydraulicStructure(SQLSubModel):
|
||||
return hs
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"DELETE FROM hydraulic_structures " +
|
||||
f"WHERE pamhyr_id = {self.pamhyr_id} " +
|
||||
@@ -284,24 +278,15 @@ class HydraulicStructure(SQLSubModel):
|
||||
if self._input_reach is not None:
|
||||
input_reach_id = self._input_reach.pamhyr_id
|
||||
|
||||
output_reach_id = -1
|
||||
if self._output_reach is not None:
|
||||
output_reach_id = self._output_reach.pamhyr_id
|
||||
|
||||
input_section = 'NULL'
|
||||
if self.input_section is not None:
|
||||
input_section = self.input_section.pamhyr_id
|
||||
|
||||
output_section = 'NULL'
|
||||
if self.output_section is not None:
|
||||
output_section = self.output_section.pamhyr_id
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"hydraulic_structures(" +
|
||||
" pamhyr_id, deleted, name, enabled, " +
|
||||
" input_section, output_section, " +
|
||||
" input_reach, output_reach, " +
|
||||
" input_section, input_reach, " +
|
||||
" scenario" +
|
||||
") " +
|
||||
"VALUES (" +
|
||||
@@ -309,8 +294,7 @@ class HydraulicStructure(SQLSubModel):
|
||||
f"{self._db_format(self.is_deleted())}, " +
|
||||
f"'{self._db_format(self._name)}', " +
|
||||
f"{self._db_format(self.enabled)}, " +
|
||||
f"{input_section}, {output_section}, " +
|
||||
f"{input_reach_id}, {output_reach_id}, " +
|
||||
f"{input_section}, {input_reach_id}, " +
|
||||
f"{self._status.scenario_id}"
|
||||
")"
|
||||
)
|
||||
@@ -368,13 +352,6 @@ class HydraulicStructure(SQLSubModel):
|
||||
|
||||
return self._input_section
|
||||
|
||||
@property
|
||||
def output_rk(self):
|
||||
if self._output_section is None:
|
||||
return None
|
||||
|
||||
return self._output_section
|
||||
|
||||
@property
|
||||
def input_section(self):
|
||||
return self._input_section
|
||||
@@ -384,15 +361,6 @@ class HydraulicStructure(SQLSubModel):
|
||||
self._input_section = input_section
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def output_section(self):
|
||||
return self._output_section
|
||||
|
||||
@output_section.setter
|
||||
def output_section(self, output_section):
|
||||
self._output_section = output_section
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
return self._enabled
|
||||
@@ -411,19 +379,19 @@ class HydraulicStructure(SQLSubModel):
|
||||
self._input_reach = input_reach
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def output_reach(self):
|
||||
return self._output_reach
|
||||
|
||||
@output_reach.setter
|
||||
def output_reach(self, output_reach):
|
||||
self._output_reach = output_reach
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def basic_structures(self):
|
||||
return self.lst.copy()
|
||||
|
||||
def cloned_for(self, input_reach, input_section):
|
||||
new = HydraulicStructure(name=self._name, status=self._status)
|
||||
new._enabled = self._enabled
|
||||
new._input_reach = input_reach
|
||||
new._input_section = input_section
|
||||
new._data = [structure.cloned() for structure in self.lst]
|
||||
new.modified()
|
||||
return new
|
||||
|
||||
def basic_structure(self, index: int):
|
||||
if len(self._data) == 0:
|
||||
return None
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -61,6 +61,64 @@ class HydraulicStructureList(PamhyrModelList):
|
||||
self.modified()
|
||||
return n
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
profiles = reach.reach.profiles
|
||||
split_index = profiles.index(profile)
|
||||
sections1 = dict(zip(
|
||||
profiles[:split_index + 1],
|
||||
reach1.reach.profiles
|
||||
))
|
||||
sections2 = dict(zip(
|
||||
profiles[split_index:],
|
||||
reach2.reach.profiles
|
||||
))
|
||||
|
||||
def split_endpoint(endpoint_reach, section):
|
||||
if endpoint_reach is not reach:
|
||||
return endpoint_reach, section
|
||||
if section not in profiles:
|
||||
return endpoint_reach, section
|
||||
|
||||
index = profiles.index(section)
|
||||
if index < split_index:
|
||||
return reach1, sections1[section]
|
||||
return reach2, sections2[section]
|
||||
|
||||
structures = [
|
||||
structure
|
||||
for structure in self.lst
|
||||
if structure.input_reach is reach
|
||||
]
|
||||
|
||||
for structure in structures:
|
||||
input_reach, input_section = split_endpoint(
|
||||
structure.input_reach,
|
||||
structure.input_section
|
||||
)
|
||||
self._lst.append(structure.cloned_for(
|
||||
input_reach,
|
||||
input_section
|
||||
))
|
||||
|
||||
if len(structures) != 0:
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def enabled_reaches_list(self):
|
||||
return [
|
||||
structure
|
||||
for structure in self.lst
|
||||
if (structure.input_reach is None or
|
||||
(not structure.input_reach.is_deleted() and
|
||||
structure.input_reach.is_enable()))
|
||||
]
|
||||
|
||||
def get_for_enabled_reaches(self, index):
|
||||
structures = self.enabled_reaches_list
|
||||
if not 0 <= index < len(structures):
|
||||
return None
|
||||
return structures[index]
|
||||
|
||||
def __copy__(self):
|
||||
new = HydraulicStructureList()
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -19,6 +19,7 @@
|
||||
import logging
|
||||
|
||||
from copy import copy, deepcopy
|
||||
from math import isclose
|
||||
from tools import trace, timer
|
||||
from functools import reduce
|
||||
from numpy import interp
|
||||
@@ -225,6 +226,8 @@ class Data(SQLSubModel):
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
ind = data["ind"]
|
||||
|
||||
execute(
|
||||
@@ -254,6 +257,17 @@ class Data(SQLSubModel):
|
||||
)
|
||||
return new
|
||||
|
||||
def cloned_for(self, reach, section):
|
||||
return Data(
|
||||
name=self._name,
|
||||
comment=self._comment,
|
||||
section=section,
|
||||
discharge=self._discharge,
|
||||
height=self._height,
|
||||
reach=reach,
|
||||
status=self._status,
|
||||
)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
@@ -396,7 +410,7 @@ class InitialConditions(SQLSubModel):
|
||||
|
||||
@reach.setter
|
||||
def reach(self, new):
|
||||
self._reach = reach
|
||||
self._reach = new
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
@@ -426,15 +440,28 @@ class InitialConditions(SQLSubModel):
|
||||
|
||||
def new_from_data(self, rk, discharge, elevation):
|
||||
n = Data(reach=self._reach, status=self._status)
|
||||
# Values read from Mage INI files are strings, whereas profile RK
|
||||
# values are stored as floats. Normalize the imported value before
|
||||
# looking up its associated profile.
|
||||
rk = float(rk)
|
||||
|
||||
section = reduce(
|
||||
lambda acc, s: (
|
||||
s if s.rk == rk else acc
|
||||
# Mage INI files store RK values with two decimal places.
|
||||
# Allow for the rounding introduced by that format.
|
||||
s if isclose(s.rk, rk, rel_tol=0.0, abs_tol=0.0051)
|
||||
else acc
|
||||
),
|
||||
self._reach.reach.profiles,
|
||||
None
|
||||
)
|
||||
|
||||
if section is None:
|
||||
raise ValueError(
|
||||
f"No profile with RK {rk} exists in reach "
|
||||
f"{self._reach.name}"
|
||||
)
|
||||
|
||||
n['section'] = section
|
||||
n['discharge'] = discharge
|
||||
n['elevation'] = elevation
|
||||
@@ -503,6 +530,20 @@ class InitialConditions(SQLSubModel):
|
||||
for data in self._data:
|
||||
data.set_as_deleted()
|
||||
|
||||
def _splited_for(self, reach, sections):
|
||||
new = InitialConditions(reach=reach, status=self._status)
|
||||
|
||||
new._data = [
|
||||
data.cloned_for(reach, sections[data["section"]])
|
||||
for data in self.data
|
||||
if data["section"] in sections
|
||||
]
|
||||
|
||||
if len(new._data) != 0:
|
||||
new.modified()
|
||||
|
||||
return new
|
||||
|
||||
def generate_growing_constant_depth(self, height: float,
|
||||
compute_discharge: bool):
|
||||
profiles = self._reach.reach.profiles.copy()
|
||||
@@ -586,8 +627,6 @@ class InitialConditions(SQLSubModel):
|
||||
for data in self._data:
|
||||
data_height[data["rk"].rk] = data["height"]
|
||||
|
||||
print(data_height)
|
||||
|
||||
incline = self._reach.reach.get_incline_median_mean()
|
||||
logger.debug(f"incline = {incline}")
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -88,3 +88,28 @@ class InitialConditionsDict(PamhyrModelDict):
|
||||
new = InitialConditions(reach=reach, status=self._status)
|
||||
self.set(reach, new)
|
||||
return new
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
if reach not in self._dict:
|
||||
return
|
||||
|
||||
profiles = reach.reach.profiles
|
||||
split_index = profiles.index(profile)
|
||||
|
||||
sections1 = dict(zip(
|
||||
profiles[:split_index + 1],
|
||||
reach1.reach.profiles
|
||||
))
|
||||
sections2 = dict(zip(
|
||||
profiles[split_index:],
|
||||
reach2.reach.profiles
|
||||
))
|
||||
|
||||
self.set(
|
||||
reach1,
|
||||
self._dict[reach]._splited_for(reach1, sections1)
|
||||
)
|
||||
self.set(
|
||||
reach2,
|
||||
self._dict[reach]._splited_for(reach2, sections2)
|
||||
)
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -79,16 +79,12 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
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 not created:
|
||||
if cls.is_table_exists(execute, "initial_conditions_adists"):
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
else:
|
||||
cls._db_create(execute)
|
||||
|
||||
return True
|
||||
|
||||
@@ -267,7 +263,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._name = name
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def pollutant(self):
|
||||
@@ -276,7 +272,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||
@pollutant.setter
|
||||
def pollutant(self, pollutant):
|
||||
self._pollutant = pollutant
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def concentration(self):
|
||||
@@ -285,7 +281,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||
@concentration.setter
|
||||
def concentration(self, concentration):
|
||||
self._concentration = concentration
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def eg(self):
|
||||
@@ -294,7 +290,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||
@eg.setter
|
||||
def eg(self, eg):
|
||||
self._eg = eg
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def em(self):
|
||||
@@ -303,7 +299,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||
@em.setter
|
||||
def em(self, em):
|
||||
self._em = em
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def ed(self):
|
||||
@@ -312,7 +308,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||
@ed.setter
|
||||
def ed(self, ed):
|
||||
self._ed = ed
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
@@ -321,28 +317,102 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||
@enabled.setter
|
||||
def enabled(self, enabled):
|
||||
self._enabled = enabled
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
def new(self, index):
|
||||
n = ICAdisTSSpec(status=self._status)
|
||||
self._data.insert(index, n)
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
return n
|
||||
|
||||
def delete(self, data):
|
||||
self._data = list(
|
||||
filter(
|
||||
lambda x: x not in data,
|
||||
self._data
|
||||
list(
|
||||
map(
|
||||
lambda x: x.set_as_deleted(),
|
||||
data
|
||||
)
|
||||
)
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
def delete_i(self, indexes):
|
||||
for ind in indexes:
|
||||
del self._data[ind]
|
||||
self._status.modified()
|
||||
list(
|
||||
map(
|
||||
lambda e: e[1].set_as_deleted(),
|
||||
filter(
|
||||
lambda e: e[0] in indexes,
|
||||
enumerate(self._data)
|
||||
)
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
|
||||
def insert(self, index, data):
|
||||
self._data.insert(index, data)
|
||||
self._status.modified()
|
||||
if data in self._data:
|
||||
self.undelete([data])
|
||||
else:
|
||||
self._data.insert(index, data)
|
||||
|
||||
self.modified()
|
||||
|
||||
def undelete(self, lst):
|
||||
for x in lst:
|
||||
x.set_as_not_deleted()
|
||||
|
||||
self.modified()
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
split_rk = profile.rk
|
||||
reach_rks = reach.reach.get_rk()
|
||||
if len(reach_rks) == 0:
|
||||
return
|
||||
|
||||
lower_reach_rk = min(reach_rks)
|
||||
upper_reach_rk = max(reach_rks)
|
||||
parts = [
|
||||
(reach1.id, lower_reach_rk, split_rk),
|
||||
(reach2.id, split_rk, upper_reach_rk),
|
||||
]
|
||||
specifications = [
|
||||
specification
|
||||
for specification in self._data
|
||||
if (not specification.is_deleted() and
|
||||
specification.reach == reach.id)
|
||||
]
|
||||
|
||||
for specification in specifications:
|
||||
begin = specification.start_rk
|
||||
end = specification.end_rk
|
||||
if begin is None or end is None:
|
||||
continue
|
||||
|
||||
lower, upper = sorted((begin, end))
|
||||
reverse = begin > end
|
||||
|
||||
for new_reach, part_lower, part_upper in parts:
|
||||
clipped_lower = max(lower, part_lower)
|
||||
clipped_upper = min(upper, part_upper)
|
||||
if clipped_lower >= clipped_upper:
|
||||
continue
|
||||
|
||||
start_rk = clipped_upper if reverse else clipped_lower
|
||||
end_rk = clipped_lower if reverse else clipped_upper
|
||||
self._data.append(specification.cloned_for(
|
||||
new_reach, start_rk, end_rk
|
||||
))
|
||||
|
||||
if len(specifications) != 0:
|
||||
self.modified()
|
||||
|
||||
def get_specs_for_enabled_reaches(self, reaches):
|
||||
enabled_reaches = {
|
||||
reach.id
|
||||
for reach in reaches
|
||||
if not reach.is_deleted() and reach.is_enable()
|
||||
}
|
||||
return [
|
||||
specification
|
||||
for specification in self._data
|
||||
if (not specification.is_deleted() and
|
||||
(specification.reach in (None, -1) or
|
||||
specification.reach in enabled_reaches))
|
||||
]
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -62,6 +62,12 @@ class InitialConditionsAdisTSList(PamhyrModelList):
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
for initial_condition in self.lst:
|
||||
initial_condition.split_reach(
|
||||
reach, profile, reach1, reach2
|
||||
)
|
||||
|
||||
@property
|
||||
def Initial_Conditions_List(self):
|
||||
return self.lst
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -31,10 +31,12 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None):
|
||||
super(ICAdisTSSpec, self).__init__()
|
||||
|
||||
self._status = status
|
||||
status=None, owner_scenario=-1):
|
||||
super(ICAdisTSSpec, self).__init__(
|
||||
id=id,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._name_section = name
|
||||
self._reach = None
|
||||
@@ -77,16 +79,12 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
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 not created:
|
||||
if cls.is_table_exists(execute, "initial_conditions_adists_spec"):
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
else:
|
||||
cls._db_create(execute)
|
||||
|
||||
return True
|
||||
|
||||
@@ -194,7 +192,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
new_spec.rate = rate
|
||||
new_spec.enabled = enabled
|
||||
|
||||
loaded.add(pid)
|
||||
loaded.add(id)
|
||||
new.append(new_spec)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
@@ -211,7 +209,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"initial_conditions_adists_spec(id, deleted, " +
|
||||
"initial_conditions_adists_spec(pamhyr_id, deleted, " +
|
||||
"ic_default, name, reach, " +
|
||||
"start_rk, end_rk, concentration, eg, em, ed, rate, " +
|
||||
"enabled, scenario) " +
|
||||
@@ -238,7 +236,8 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._name_section = name
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def reach(self):
|
||||
@@ -247,7 +246,8 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@reach.setter
|
||||
def reach(self, reach):
|
||||
self._reach = reach
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def start_rk(self):
|
||||
@@ -256,7 +256,8 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@start_rk.setter
|
||||
def start_rk(self, start_rk):
|
||||
self._start_rk = start_rk
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def end_rk(self):
|
||||
@@ -265,7 +266,8 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@end_rk.setter
|
||||
def end_rk(self, end_rk):
|
||||
self._end_rk = end_rk
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def concentration(self):
|
||||
@@ -274,7 +276,8 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@concentration.setter
|
||||
def concentration(self, concentration):
|
||||
self._concentration = concentration
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def eg(self):
|
||||
@@ -283,7 +286,8 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@eg.setter
|
||||
def eg(self, eg):
|
||||
self._eg = eg
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def em(self):
|
||||
@@ -292,7 +296,8 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@em.setter
|
||||
def em(self, em):
|
||||
self._em = em
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def ed(self):
|
||||
@@ -301,7 +306,8 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@ed.setter
|
||||
def ed(self, ed):
|
||||
self._ed = ed
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def rate(self):
|
||||
@@ -310,7 +316,8 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@rate.setter
|
||||
def rate(self, rate):
|
||||
self._rate = rate
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
@@ -319,4 +326,18 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
@enabled.setter
|
||||
def enabled(self, enabled):
|
||||
self._enabled = enabled
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
def cloned_for(self, reach, start_rk, end_rk):
|
||||
new = ICAdisTSSpec(name=self._name_section, status=self._status)
|
||||
new._reach = reach
|
||||
new._start_rk = start_rk
|
||||
new._end_rk = end_rk
|
||||
new._concentration = self._concentration
|
||||
new._eg = self._eg
|
||||
new._em = self._em
|
||||
new._ed = self._ed
|
||||
new._rate = self._rate
|
||||
new._enabled = self._enabled
|
||||
new.modified()
|
||||
return new
|
||||
@@ -0,0 +1,272 @@
|
||||
# InitialConditionsTemperature.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
from functools import reduce
|
||||
|
||||
from tools import trace, timer, old_pamhyr_date_to_timestamp
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
from Model.InitialConditionsTemperature.InitialConditionsTemperatureSpec \
|
||||
import ICTemperatureSpec
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class InitialConditionsTemperature(SQLSubModel):
|
||||
_sub_classes = [
|
||||
ICTemperatureSpec,
|
||||
]
|
||||
|
||||
def __init__(self, id: int = -1, name: str = "default",
|
||||
status=None, owner_scenario=-1):
|
||||
super(InitialConditionsTemperature, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
self._status = status
|
||||
|
||||
self._name = name
|
||||
self._temperature = None
|
||||
self._data = []
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE initial_conditions_temperature{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
name TEXT NOT NULL,
|
||||
temperature REAL NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()}
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
|
||||
if major == "0":
|
||||
if int(minor) < 2 or (int(minor) == 2 and int(release) <= 7):
|
||||
table_name = "initial_conditions_temperature"
|
||||
if not cls.is_table_exists(execute, table_name):
|
||||
cls._db_create(execute)
|
||||
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, " +
|
||||
"name, temperature, scenario " +
|
||||
"FROM initial_conditions_temperature " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
deleted = (next(it) == 1)
|
||||
name = next(it)
|
||||
temperature = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
ic = cls(
|
||||
id=pid,
|
||||
name=name,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
ic.set_as_deleted()
|
||||
|
||||
ic.temperature = temperature
|
||||
|
||||
data['ic_default_id'] = pid
|
||||
ic._data = ICTemperatureSpec._db_load(execute, data)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(ic)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"DELETE FROM initial_conditions_temperature " +
|
||||
f"WHERE pamhyr_id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
temperature = self._temperature if \
|
||||
self._temperature is not None else 0.0
|
||||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"initial_conditions_temperature(" +
|
||||
"pamhyr_id, deleted, name, temperature, " +
|
||||
"scenario" +
|
||||
") " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self.is_deleted()}, " +
|
||||
f"'{self._db_format(self._name)}', " +
|
||||
f"{temperature}, {self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
execute(sql)
|
||||
|
||||
data['ic_default_id'] = self.id
|
||||
execute(
|
||||
"DELETE FROM initial_conditions_temperature_spec " +
|
||||
f"WHERE ic_default = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
for ic_spec in self._data:
|
||||
ic_spec._db_save(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
def __len__(self):
|
||||
return len(self.data)
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return list(filter(lambda item: not item.is_deleted(), self._data))
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._name = name
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def temperature(self):
|
||||
return self._temperature
|
||||
|
||||
@temperature.setter
|
||||
def temperature(self, temperature):
|
||||
self._temperature = temperature
|
||||
self.modified()
|
||||
|
||||
def new(self, index):
|
||||
n = ICTemperatureSpec(status=self._status)
|
||||
self._data.insert(index, n)
|
||||
self.modified()
|
||||
return n
|
||||
|
||||
def delete(self, data):
|
||||
list(
|
||||
map(
|
||||
lambda x: x.set_as_deleted(),
|
||||
data
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
|
||||
def delete_i(self, indexes):
|
||||
list(
|
||||
map(
|
||||
lambda e: e[1].set_as_deleted(),
|
||||
filter(
|
||||
lambda e: e[0] in indexes,
|
||||
enumerate(self._data)
|
||||
)
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
|
||||
def insert(self, index, data):
|
||||
if data in self._data:
|
||||
self.undelete([data])
|
||||
else:
|
||||
self._data.insert(index, data)
|
||||
|
||||
self.modified()
|
||||
|
||||
def undelete(self, lst):
|
||||
for x in lst:
|
||||
x.set_as_not_deleted()
|
||||
|
||||
self.modified()
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
parts = []
|
||||
for new_reach in (reach1, reach2):
|
||||
rks = new_reach.reach.get_rk()
|
||||
if rks:
|
||||
parts.append((new_reach.id, min(rks), max(rks)))
|
||||
|
||||
specifications = [
|
||||
specification
|
||||
for specification in self._data
|
||||
if (not specification.is_deleted() and
|
||||
specification.reach == reach.id)
|
||||
]
|
||||
clones = []
|
||||
|
||||
for specification in specifications:
|
||||
begin = specification.start_rk
|
||||
end = specification.end_rk
|
||||
if begin is None or end is None:
|
||||
continue
|
||||
|
||||
lower, upper = sorted((begin, end))
|
||||
reverse = begin > end
|
||||
for new_reach, part_lower, part_upper in parts:
|
||||
clipped_lower = max(lower, part_lower)
|
||||
clipped_upper = min(upper, part_upper)
|
||||
if clipped_lower >= clipped_upper:
|
||||
continue
|
||||
|
||||
start_rk = clipped_upper if reverse else clipped_lower
|
||||
end_rk = clipped_lower if reverse else clipped_upper
|
||||
clones.append(specification.cloned_for(
|
||||
new_reach, start_rk, end_rk
|
||||
))
|
||||
|
||||
if clones:
|
||||
self._data.extend(clones)
|
||||
self.modified()
|
||||
@@ -0,0 +1,73 @@
|
||||
# InitialConditionsTemperatureList.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from copy import copy
|
||||
from tools import trace, timer
|
||||
|
||||
from Model.Tools.PamhyrListExt import PamhyrModelList
|
||||
from Model.InitialConditionsTemperature.InitialConditionsTemperature \
|
||||
import InitialConditionsTemperature
|
||||
|
||||
|
||||
class InitialConditionsTemperatureList(PamhyrModelList):
|
||||
_sub_classes = [
|
||||
InitialConditionsTemperature,
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = cls(status=data['status'])
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
new._lst = InitialConditionsTemperature._db_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
execute(
|
||||
"DELETE FROM initial_conditions_temperature " +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
for ic in self._lst:
|
||||
ic._db_save(execute, data=data)
|
||||
|
||||
return True
|
||||
|
||||
def new(self, index):
|
||||
n = InitialConditionsTemperature(status=self._status)
|
||||
self._lst.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
for initial_condition in self.lst:
|
||||
initial_condition.split_reach(
|
||||
reach, profile, reach1, reach2
|
||||
)
|
||||
|
||||
@property
|
||||
def Initial_Conditions_List(self):
|
||||
return self.lst
|
||||
@@ -0,0 +1,215 @@
|
||||
# InitialConditionsAdisTSSpec.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from tools import trace, timer
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class ICTemperatureSpec(SQLSubModel):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(ICTemperatureSpec, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._name_section = name
|
||||
self._reach = None
|
||||
self._start_rk = None
|
||||
self._end_rk = None
|
||||
self._temperature = None
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE initial_conditions_temperature_spec{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
ic_default INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
reach INTEGER NOT NULL,
|
||||
start_rk REAL NOT NULL,
|
||||
end_rk REAL NOT NULL,
|
||||
temperature REAL NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(ic_default)
|
||||
REFERENCES initial_conditions_temperature(pamhyr_id),
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id)
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
|
||||
if major == "0":
|
||||
if int(minor) < 2 or (int(minor) == 2 and int(release) <= 7):
|
||||
table_name = "initial_conditions_temperature_spec"
|
||||
if not cls.is_table_exists(execute, table_name):
|
||||
cls._db_create(execute)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
reachs = data["edges"]
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, name, reach, start_rk, end_rk, " +
|
||||
"temperature, scenario " +
|
||||
"FROM initial_conditions_temperature_spec " +
|
||||
f"WHERE ic_default = {data['ic_default_id']} " +
|
||||
f"AND scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
id = next(it)
|
||||
deleted = (next(it) == 1)
|
||||
name = next(it)
|
||||
reach = next(it)
|
||||
start_rk = next(it)
|
||||
end_rk = next(it)
|
||||
temperature = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
new_spec = cls(
|
||||
id=id, name=name,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
new_spec.set_as_deleted()
|
||||
|
||||
new_spec.reach = reach
|
||||
new_spec.start_rk = start_rk
|
||||
new_spec.end_rk = end_rk
|
||||
new_spec.temperature = temperature
|
||||
|
||||
loaded.add(id)
|
||||
new.append(new_spec)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
ic_default = data['ic_default_id']
|
||||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"initial_conditions_temperature_spec(pamhyr_id, deleted, " +
|
||||
"ic_default, name, reach, " +
|
||||
"start_rk, end_rk, temperature, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"{ic_default}, " +
|
||||
f"'{self._db_format(self._name_section)}', " +
|
||||
f"{self._reach}, " +
|
||||
f"{self._start_rk}, {self._end_rk}, " +
|
||||
f"{self._temperature}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
execute(sql)
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name_section
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._name_section = name
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def reach(self):
|
||||
return self._reach
|
||||
|
||||
@reach.setter
|
||||
def reach(self, reach):
|
||||
self._reach = reach
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def start_rk(self):
|
||||
return self._start_rk
|
||||
|
||||
@start_rk.setter
|
||||
def start_rk(self, start_rk):
|
||||
self._start_rk = start_rk
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def end_rk(self):
|
||||
return self._end_rk
|
||||
|
||||
@end_rk.setter
|
||||
def end_rk(self, end_rk):
|
||||
self._end_rk = end_rk
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def temperature(self):
|
||||
return self._temperature
|
||||
|
||||
@temperature.setter
|
||||
def temperature(self, temperature):
|
||||
self._temperature = temperature
|
||||
self._status.modified()
|
||||
|
||||
def cloned_for(self, reach, start_rk, end_rk):
|
||||
new = ICTemperatureSpec(
|
||||
name=self._name_section,
|
||||
status=self._status
|
||||
)
|
||||
new._reach = reach
|
||||
new._start_rk = start_rk
|
||||
new._end_rk = end_rk
|
||||
new._temperature = self._temperature
|
||||
new.modified()
|
||||
return new
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -147,9 +147,9 @@ class Data(SQLSubModel):
|
||||
it = iter(v)
|
||||
|
||||
pid = next(it)
|
||||
delete = next(it)
|
||||
data0 = bc._types[0](next(it))
|
||||
data1 = bc._types[1](next(it))
|
||||
deleted = next(it)
|
||||
data0 = lc._types[0](next(it))
|
||||
data1 = lc._types[1](next(it))
|
||||
owner_scenario = next(it)
|
||||
|
||||
nd = cls(
|
||||
@@ -196,6 +196,13 @@ class Data(SQLSubModel):
|
||||
def __setitem__(self, key, value):
|
||||
self._data[key] = self._types[key](value)
|
||||
|
||||
def cloned(self):
|
||||
return Data(
|
||||
self[0], self[1],
|
||||
types=self._types,
|
||||
status=self._status
|
||||
)
|
||||
|
||||
|
||||
class LateralContribution(SQLSubModel):
|
||||
_sub_classes = [Data]
|
||||
@@ -511,6 +518,15 @@ class LateralContribution(SQLSubModel):
|
||||
def has_reach(self):
|
||||
return self._reach is not None
|
||||
|
||||
def cloned_for(self, reach, begin_section, end_section):
|
||||
new = type(self)(name=self._name, status=self._status)
|
||||
new._reach = reach
|
||||
new._begin_section = begin_section
|
||||
new._end_section = end_section
|
||||
new._data = [data.cloned() for data in self.data]
|
||||
new.modified()
|
||||
return new
|
||||
|
||||
@property
|
||||
def begin_rk(self):
|
||||
if self._begin_section is None:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -71,6 +71,89 @@ class LateralContributionList(PamhyrModelListWithTab):
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
profiles = reach.reach.profiles
|
||||
split_index = profiles.index(profile)
|
||||
|
||||
parts = [
|
||||
(
|
||||
reach1,
|
||||
0,
|
||||
split_index,
|
||||
dict(zip(
|
||||
profiles[:split_index + 1],
|
||||
reach1.reach.profiles
|
||||
))
|
||||
),
|
||||
(
|
||||
reach2,
|
||||
split_index,
|
||||
len(profiles) - 1,
|
||||
dict(zip(
|
||||
profiles[split_index:],
|
||||
reach2.reach.profiles
|
||||
))
|
||||
),
|
||||
]
|
||||
|
||||
for tab in self._tabs:
|
||||
contributions = [
|
||||
contribution
|
||||
for contribution in self.get_tab(tab)
|
||||
if contribution.reach is reach
|
||||
]
|
||||
|
||||
for contribution in contributions:
|
||||
if (contribution.begin_section not in profiles or
|
||||
contribution.end_section not in profiles):
|
||||
continue
|
||||
|
||||
begin = profiles.index(contribution.begin_section)
|
||||
end = profiles.index(contribution.end_section)
|
||||
lower, upper = sorted((begin, end))
|
||||
reverse = begin > end
|
||||
clones = []
|
||||
|
||||
for new_reach, part_lower, part_upper, sections in parts:
|
||||
clipped_lower = max(lower, part_lower)
|
||||
clipped_upper = min(upper, part_upper)
|
||||
if clipped_lower >= clipped_upper:
|
||||
continue
|
||||
|
||||
begin_index = (
|
||||
clipped_upper if reverse else clipped_lower
|
||||
)
|
||||
end_index = (
|
||||
clipped_lower if reverse else clipped_upper
|
||||
)
|
||||
clones.append(contribution.cloned_for(
|
||||
new_reach,
|
||||
sections[profiles[begin_index]],
|
||||
sections[profiles[end_index]]
|
||||
))
|
||||
|
||||
if len(clones) == 0:
|
||||
continue
|
||||
|
||||
self._tabs[tab].extend(clones)
|
||||
|
||||
self._status.modified()
|
||||
|
||||
def get_tab_for_enabled_reaches(self, tab):
|
||||
return [
|
||||
contribution
|
||||
for contribution in self.get_tab(tab)
|
||||
if (contribution.reach is None or
|
||||
(not contribution.reach.is_deleted() and
|
||||
contribution.reach.is_enable()))
|
||||
]
|
||||
|
||||
def get_for_enabled_reaches(self, tab, index):
|
||||
contributions = self.get_tab_for_enabled_reaches(tab)
|
||||
if not 0 <= index < len(contributions):
|
||||
return None
|
||||
return contributions[index]
|
||||
|
||||
def __copy__(self):
|
||||
new = LateralContributionList()
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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(".")
|
||||
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 not created:
|
||||
if cls.is_table_exists(
|
||||
execute, "lateral_contribution_data_adists"):
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
else:
|
||||
cls._db_create(execute)
|
||||
|
||||
return True
|
||||
|
||||
@@ -132,11 +130,13 @@ class Data(SQLSubModel):
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
lca = data["lca"]
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, data0, data1 " +
|
||||
"SELECT pamhyr_id, deleted, data0, data1, scenario " +
|
||||
"FROM lateral_contribution_data_adists " +
|
||||
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}'"
|
||||
)
|
||||
|
||||
@@ -150,16 +150,16 @@ class Data(SQLSubModel):
|
||||
data1 = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
data = cls(
|
||||
lc = cls(
|
||||
data0, data1,
|
||||
id=pid, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
data.set_as_deleted()
|
||||
lc.set_as_deleted()
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(data)
|
||||
new.append(lc)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
@@ -175,7 +175,7 @@ class Data(SQLSubModel):
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"lateral_contribution_adists(pamhyr_id, deleted," +
|
||||
"lateral_contribution_data_adists(pamhyr_id, deleted," +
|
||||
"data0, data1, lca, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
@@ -192,6 +192,13 @@ class Data(SQLSubModel):
|
||||
def __setitem__(self, key, value):
|
||||
self._data[key] = self._types[key](value)
|
||||
|
||||
def cloned(self):
|
||||
return Data(
|
||||
self[0], self[1],
|
||||
types=self._types,
|
||||
status=self._status
|
||||
)
|
||||
|
||||
|
||||
class LateralContributionAdisTS(SQLSubModel):
|
||||
_sub_classes = [Data]
|
||||
@@ -241,15 +248,13 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if int(release) < 7:
|
||||
if major == "0" and int(minor) < 2:
|
||||
if cls.is_table_exists(execute, "lateral_contribution_adists"):
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
else:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if not created:
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@@ -372,16 +377,18 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"lateral_contribution_adists(id, deleted," +
|
||||
"lateral_contribution_adists(pamhyr_id, deleted, " +
|
||||
"pollutant, reach, begin_rk, end_rk, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"{self._pollutant}, {self.reach}, " +
|
||||
f"{self._begin_rk}, {self._end_rk}" +
|
||||
f"{self._begin_rk}, {self._end_rk}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
data["lca"] = self
|
||||
|
||||
ind = 0
|
||||
for d in self._data:
|
||||
data["ind"] = ind
|
||||
@@ -406,7 +413,7 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||
return len(
|
||||
list(
|
||||
filter(
|
||||
lambda el: not el.is_deleted(),
|
||||
lambda el: el is not None and not el.is_deleted(),
|
||||
self._data
|
||||
)
|
||||
)
|
||||
@@ -452,7 +459,12 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return self._data.copy()
|
||||
return list(
|
||||
filter(
|
||||
lambda el: el is not None and not el.is_deleted(),
|
||||
self._data
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def begin_rk(self):
|
||||
@@ -471,3 +483,69 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||
def end_rk(self, end_rk):
|
||||
self._end_rk = end_rk
|
||||
self.modified()
|
||||
|
||||
def cloned_for(self, reach, begin_rk, end_rk):
|
||||
new = LateralContributionAdisTS(
|
||||
pollutant=self._pollutant,
|
||||
status=self._status
|
||||
)
|
||||
new._reach = reach
|
||||
new._begin_rk = begin_rk
|
||||
new._end_rk = end_rk
|
||||
new._data = [data.cloned() for data in self.data]
|
||||
new.modified()
|
||||
return new
|
||||
|
||||
@property
|
||||
def _default_0(self):
|
||||
return self._types[0](0)
|
||||
|
||||
@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
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
# Copyright (C) 2023-2026 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -68,6 +68,46 @@ class LateralContributionsAdisTSList(PamhyrModelList):
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
parts = []
|
||||
for new_reach in (reach1, reach2):
|
||||
rks = new_reach.reach.get_rk()
|
||||
if len(rks) == 0:
|
||||
continue
|
||||
parts.append((new_reach.id, min(rks), max(rks)))
|
||||
|
||||
contributions = [
|
||||
contribution
|
||||
for contribution in self.lst
|
||||
if contribution.reach == reach.id
|
||||
]
|
||||
clones = []
|
||||
|
||||
for contribution in contributions:
|
||||
begin = contribution.begin_rk
|
||||
end = contribution.end_rk
|
||||
if begin is None or end is None:
|
||||
continue
|
||||
|
||||
lower, upper = sorted((begin, end))
|
||||
reverse = begin > end
|
||||
|
||||
for new_reach, part_lower, part_upper in parts:
|
||||
clipped_lower = max(lower, part_lower)
|
||||
clipped_upper = min(upper, part_upper)
|
||||
if clipped_lower >= clipped_upper:
|
||||
continue
|
||||
|
||||
begin_rk = clipped_upper if reverse else clipped_lower
|
||||
end_rk = clipped_lower if reverse else clipped_upper
|
||||
clones.append(contribution.cloned_for(
|
||||
new_reach, begin_rk, end_rk
|
||||
))
|
||||
|
||||
if len(clones) != 0:
|
||||
self._lst.extend(clones)
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def Lat_Cont_List(self):
|
||||
return self.lst
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# __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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,212 +0,0 @@
|
||||
# OutputRKAdists.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from tools import (
|
||||
trace, timer,
|
||||
old_pamhyr_date_to_timestamp,
|
||||
date_iso_to_timestamp,
|
||||
date_dmy_to_timestamp,
|
||||
)
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class OutputRKAdists(SQLSubModel):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self, id: int = -1, reach=None,
|
||||
rk=None, title: str = "", status=None,
|
||||
owner_scenario=-1):
|
||||
super(OutputRKAdists, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._reach = reach
|
||||
self._rk = rk
|
||||
self._title = str(title)
|
||||
self._enabled = True
|
||||
|
||||
@property
|
||||
def reach(self):
|
||||
return self._reach
|
||||
|
||||
@reach.setter
|
||||
def reach(self, reach_id):
|
||||
self._reach = reach_id
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def rk(self):
|
||||
return self._rk
|
||||
|
||||
@rk.setter
|
||||
def rk(self, profile_id):
|
||||
self._rk = profile_id
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
return self._title
|
||||
|
||||
@title.setter
|
||||
def title(self, title):
|
||||
self._title = title
|
||||
self._status.modified()
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE output_rk_adists{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
reach INTEGER NOT NULL,
|
||||
rk REAL NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(id)
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
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 not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "OutputRKAdists"
|
||||
table_new = "output_rk_adists"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table_new}_tmp " +
|
||||
"(pamhyr_id, reach, rk, title, scenario) " +
|
||||
"SELECT pamhyr_id, reach, rk, title, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table_new}_tmp RENAME TO {table_new}")
|
||||
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table_new, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
# reach = data["reach"]
|
||||
# profile = data["profile"]
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, reach, rk, title, scenario " +
|
||||
f"FROM output_rk_adists"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
deleted = (next(it) == 1)
|
||||
id_reach = next(it)
|
||||
id_rk = next(it)
|
||||
title = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
new_output = cls(
|
||||
id=pid, reach=id_reach,
|
||||
rk=id_rk, title=title,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario,
|
||||
)
|
||||
if deleted:
|
||||
new_output.set_as_deleted()
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(new_output)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"DELETE FROM output_rk_adists " +
|
||||
f"WHERE pamhyr_id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
)
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"output_rk_adists(pamhyr_id, deleted, " +
|
||||
"reach, rk, title, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}" +
|
||||
f"{self._reach}, {self._rk}, " +
|
||||
f"'{self._db_format(self._title)}', " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
return self._enabled
|
||||
|
||||
@enabled.setter
|
||||
def enabled(self, enabled):
|
||||
self._enabled = enabled
|
||||
self._status.modified()
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
from Model.BoundaryConditionsAdisTS.BoundaryConditionAdisTS import (
|
||||
BoundaryConditionAdisTS,
|
||||
)
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
@@ -101,6 +104,12 @@ class PollutantCharacteristics(SQLSubModel):
|
||||
self._ac = value
|
||||
elif key == 8:
|
||||
self._bc = value
|
||||
self.propagate_modified()
|
||||
|
||||
def propagate_modified(self):
|
||||
self.modified()
|
||||
if hasattr(self, "_pollutant") and self._pollutant:
|
||||
self._pollutant.modified()
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
@@ -129,16 +138,12 @@ class PollutantCharacteristics(SQLSubModel):
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
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 not created:
|
||||
if cls.is_table_exists(execute, "Pollutants_characteristics"):
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
else:
|
||||
cls._db_create(execute)
|
||||
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@@ -253,6 +258,12 @@ class PollutantCharacteristics(SQLSubModel):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"DELETE FROM pollutants_characteristics " +
|
||||
f"WHERE pamhyr_id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"pollutants_characteristics(pamhyr_id, deleted, " +
|
||||
@@ -275,7 +286,10 @@ class PollutantCharacteristics(SQLSubModel):
|
||||
|
||||
|
||||
class Pollutants(SQLSubModel):
|
||||
_sub_classes = [PollutantCharacteristics]
|
||||
_sub_classes = [
|
||||
PollutantCharacteristics,
|
||||
# BoundaryConditionAdisTS
|
||||
]
|
||||
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
@@ -293,6 +307,11 @@ class Pollutants(SQLSubModel):
|
||||
self._enabled = True
|
||||
|
||||
self._data = []
|
||||
self._boundary_conditions_adists = []
|
||||
|
||||
@property
|
||||
def boundary_conditions_adists(self):
|
||||
return self._boundary_conditions_adists
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@@ -301,7 +320,7 @@ class Pollutants(SQLSubModel):
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._name = name
|
||||
self._status.modified()
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
@@ -309,19 +328,21 @@ class Pollutants(SQLSubModel):
|
||||
|
||||
@data.setter
|
||||
def data(self, data):
|
||||
self._data = [PollutantCharacteristics(type=int(data[0]),
|
||||
diametre=float(data[1]),
|
||||
rho=float(data[2]),
|
||||
porosity=float(data[3]),
|
||||
cdc_riv=float(data[4]),
|
||||
cdc_cas=float(data[5]),
|
||||
apd=float(data[6]),
|
||||
ac=float(data[7]),
|
||||
bc=float(data[8]),
|
||||
pollutant=self,
|
||||
status=self._status
|
||||
)
|
||||
]
|
||||
self._data = [
|
||||
PollutantCharacteristics(
|
||||
type=int(data[0]),
|
||||
diametre=float(data[1]),
|
||||
rho=float(data[2]),
|
||||
porosity=float(data[3]),
|
||||
cdc_riv=float(data[4]),
|
||||
cdc_cas=float(data[5]),
|
||||
apd=float(data[6]),
|
||||
ac=float(data[7]),
|
||||
bc=float(data[8]),
|
||||
pollutant=self,
|
||||
status=self._status
|
||||
)
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
@@ -329,6 +350,7 @@ class Pollutants(SQLSubModel):
|
||||
CREATE TABLE pollutants{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
name TEXT NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()}
|
||||
@@ -345,14 +367,20 @@ class Pollutants(SQLSubModel):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if int(release) < 7:
|
||||
if major == "0" and int(minor) < 2:
|
||||
if cls.is_table_exists(execute, "Pollutants"):
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
else:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
if major == "0" and minor == "2":
|
||||
if int(release) < 6:
|
||||
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:
|
||||
return cls._update_submodel(execute, version, data)
|
||||
@@ -391,7 +419,8 @@ class Pollutants(SQLSubModel):
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, name FROM pollutants " +
|
||||
"SELECT pamhyr_id, deleted, enabled, name, scenario " +
|
||||
"FROM pollutants " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
|
||||
)
|
||||
@@ -402,20 +431,32 @@ class Pollutants(SQLSubModel):
|
||||
|
||||
pid = next(it)
|
||||
deleted = (next(it) == 1)
|
||||
enabled = (next(it) == 1)
|
||||
name = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
new_pollutant = cls(
|
||||
id=pid, name=name,
|
||||
status=status
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
new_pollutant.set_as_deleted()
|
||||
if not enabled:
|
||||
new_pollutant.enabled = False
|
||||
|
||||
data["pollutant"] = new_pollutant
|
||||
new_pollutant._data = PollutantCharacteristics._db_load(
|
||||
execute, data=data
|
||||
)
|
||||
|
||||
new_pollutant._boundary_conditions_adists = (
|
||||
BoundaryConditionAdisTS._db_load(
|
||||
execute,
|
||||
data=data
|
||||
)
|
||||
)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(new_pollutant)
|
||||
|
||||
@@ -444,9 +485,10 @@ class Pollutants(SQLSubModel):
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"pollutants(pamhyr_id, deleted, name, scenario) " +
|
||||
"pollutants(pamhyr_id, deleted, enabled, name, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"{self._db_format(self._enabled)}, " +
|
||||
f"'{self._db_format(self._name)}', " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
@@ -455,6 +497,9 @@ class Pollutants(SQLSubModel):
|
||||
for d in self._data:
|
||||
ok &= d._db_save(execute, data)
|
||||
|
||||
for bc in self._boundary_conditions_adists:
|
||||
ok &= bc._db_save(execute, data)
|
||||
|
||||
return ok
|
||||
|
||||
def _data_traversal(self,
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
from tools import trace, timer
|
||||
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Tools.PamhyrList import PamhyrModelList
|
||||
from Model.Tools.PamhyrListExt import PamhyrModelList
|
||||
from Model.Pollutants.Pollutants import Pollutants
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
print(execute(f"SELECT * FROM {table}"))
|
||||
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
@@ -314,7 +312,7 @@ class Reservoir(SQLSubModel):
|
||||
new_reservoir._node = next(
|
||||
filter(
|
||||
lambda n: n.id == node_id, data["nodes"]
|
||||
)
|
||||
), None
|
||||
)
|
||||
|
||||
data["reservoir"] = new_reservoir
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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 datetime import datetime
|
||||
|
||||
from tools import timer
|
||||
|
||||
from Model.Scenario import Scenario
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Results.River.River import River
|
||||
@@ -155,8 +157,180 @@ class AdditionalData(SQLSubModel):
|
||||
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):
|
||||
if not cls.is_table_exists(execute, "results_table_data"):
|
||||
cls._db_create(execute)
|
||||
|
||||
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):
|
||||
_sub_classes = [River, AdditionalData]
|
||||
_sub_classes = [River, TableData, AdditionalData]
|
||||
|
||||
def __init__(self, id=-1, study=None, solver=None,
|
||||
repertory="", name="0"):
|
||||
@@ -167,7 +341,7 @@ class Results(SQLSubModel):
|
||||
|
||||
self._name = name
|
||||
self._study = study
|
||||
self._river = River(self._study)
|
||||
self._river = River(self._study, self)
|
||||
|
||||
self._solver = solver
|
||||
self._repertory = repertory
|
||||
@@ -177,8 +351,11 @@ class Results(SQLSubModel):
|
||||
"creation_date": datetime.now(),
|
||||
"study_revision": study.status.version,
|
||||
"additional_data": [],
|
||||
"table": {},
|
||||
}
|
||||
|
||||
self._ts_index = {}
|
||||
|
||||
if solver is not None:
|
||||
self.set("solver_type", solver._type)
|
||||
|
||||
@@ -195,6 +372,7 @@ class Results(SQLSubModel):
|
||||
def study(self):
|
||||
return self._study
|
||||
|
||||
@timer
|
||||
def set(self, key, value):
|
||||
self._meta_data[key] = value
|
||||
|
||||
@@ -212,6 +390,16 @@ class Results(SQLSubModel):
|
||||
def get(self, 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):
|
||||
return self._solver.results(
|
||||
self._study,
|
||||
@@ -219,6 +407,11 @@ class Results(SQLSubModel):
|
||||
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):
|
||||
ts = self._meta_data["timestamps"]
|
||||
sf = ">" + ''.join(itertools.repeat("d", len(ts)))
|
||||
@@ -304,11 +497,20 @@ class Results(SQLSubModel):
|
||||
new_results.set("study_revision", revision)
|
||||
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))
|
||||
ts = struct.unpack(sf, timestamps_bytes)
|
||||
new_results.set("timestamps", ts)
|
||||
|
||||
data["timestamps"] = sorted(ts)
|
||||
new_results.compute_timestamp_index()
|
||||
|
||||
data["parent"] = new_results
|
||||
new_results._river = River._db_load(execute, data)
|
||||
|
||||
new_results.set(
|
||||
@@ -316,6 +518,20 @@ class Results(SQLSubModel):
|
||||
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))
|
||||
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)
|
||||
|
||||
def _db_save_clear(self, execute, solver_type, data=None):
|
||||
@@ -338,15 +554,26 @@ class Results(SQLSubModel):
|
||||
f"WHERE scenario = {self._owner_scenario} " +
|
||||
f"AND result = {pid}"
|
||||
)
|
||||
execute(
|
||||
"DELETE FROM results_table_data " +
|
||||
f"WHERE scenario = {self._owner_scenario} " +
|
||||
f"AND result = {pid}"
|
||||
)
|
||||
execute(
|
||||
"DELETE FROM results_add_data " +
|
||||
f"WHERE scenario = {self._owner_scenario} " +
|
||||
f"AND result = {pid}"
|
||||
)
|
||||
|
||||
def _is_valid(self):
|
||||
return "timestamps" in self._meta_data
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if self._status.scenario.id != self._owner_scenario:
|
||||
return
|
||||
return True
|
||||
|
||||
if not self._is_valid():
|
||||
return False
|
||||
|
||||
pid = self._pamhyr_id
|
||||
if self._solver is None:
|
||||
@@ -375,7 +602,19 @@ class Results(SQLSubModel):
|
||||
data["result"] = self._pamhyr_id
|
||||
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"):
|
||||
add_data._db_save(execute, data)
|
||||
|
||||
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
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
# Copyright (C) 2023-2026 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -21,12 +21,13 @@ import os
|
||||
from copy import deepcopy
|
||||
from datetime import datetime
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Results.River.RiverAdisTS import River
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Results(object):
|
||||
class Results(SQLSubModel):
|
||||
def __init__(self, study=None, solver=None,
|
||||
repertory="", name="0", type_pol=None):
|
||||
self._study = study
|
||||
@@ -90,3 +91,6 @@ class Results(object):
|
||||
self._repertory,
|
||||
qlog=None,
|
||||
)
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
return False
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import types
|
||||
import struct
|
||||
import logging
|
||||
import itertools
|
||||
import numpy as np
|
||||
|
||||
from tools import flatten
|
||||
from tools import flatten, timer
|
||||
from functools import reduce
|
||||
from datetime import datetime
|
||||
|
||||
@@ -29,15 +31,17 @@ logger = logging.getLogger()
|
||||
|
||||
|
||||
class Profile(SQLSubModel):
|
||||
def __init__(self, profile, study):
|
||||
def __init__(self, profile, study, parent):
|
||||
super(Profile, self).__init__(
|
||||
id=-1, status=study.status,
|
||||
owner_scenario=study.status.scenario.id
|
||||
)
|
||||
|
||||
self._parent = parent
|
||||
self._study = study
|
||||
self._profile = profile # Source profile in the study
|
||||
self._data = {} # Dict of dict {<ts>: {<key>: <value>, ...}, ...}
|
||||
self._global_index = -1
|
||||
|
||||
def __len__(self):
|
||||
return len(self._data)
|
||||
@@ -54,15 +58,26 @@ class Profile(SQLSubModel):
|
||||
def geometry(self):
|
||||
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):
|
||||
if timestamp not in self._data:
|
||||
self._data[timestamp] = {}
|
||||
|
||||
self._data[timestamp][key] = data
|
||||
|
||||
@timer
|
||||
def get_ts(self, timestamp):
|
||||
return self._data[timestamp]
|
||||
|
||||
@timer
|
||||
def get_key(self, key):
|
||||
res = list(
|
||||
map(lambda ts: self._data[ts][key],
|
||||
@@ -70,13 +85,25 @@ class Profile(SQLSubModel):
|
||||
)
|
||||
return res
|
||||
|
||||
@timer
|
||||
def get_ts_key(self, timestamp, key):
|
||||
if timestamp in self._data:
|
||||
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
|
||||
|
||||
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))
|
||||
|
||||
@classmethod
|
||||
@@ -110,9 +137,9 @@ class Profile(SQLSubModel):
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = {}
|
||||
status = data['status']
|
||||
|
||||
parent = data['parent']
|
||||
study = data['study']
|
||||
reach = data['reach']
|
||||
profile = data['profile']
|
||||
@@ -120,11 +147,14 @@ class Profile(SQLSubModel):
|
||||
loaded = data['loaded_pid']
|
||||
timestamps = data['timestamps']
|
||||
|
||||
new = cls(profile, study, parent)
|
||||
|
||||
values = execute(
|
||||
"SELECT pamhyr_id, result, key, " +
|
||||
"len_data, data, scenario " +
|
||||
"FROM results_data " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND result = {data['result_pid']} " +
|
||||
f"AND reach = {reach.pamhyr_id} " +
|
||||
f"AND section = {profile.pamhyr_id}"
|
||||
)
|
||||
@@ -139,12 +169,6 @@ class Profile(SQLSubModel):
|
||||
data = 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"]:
|
||||
sf = ">" + ''.join(itertools.repeat("f", len_data))
|
||||
len_values = len(values)
|
||||
@@ -157,11 +181,11 @@ class Profile(SQLSubModel):
|
||||
)
|
||||
|
||||
for timestamp, value in zip(timestamps, values):
|
||||
new_data.set(timestamp, key, value)
|
||||
new.set(timestamp, key, value)
|
||||
if key == "Z":
|
||||
new_data.update_water_limits(timestamp, value)
|
||||
new.update_water_limits(timestamp, value)
|
||||
|
||||
return list(new.values())
|
||||
return new
|
||||
|
||||
@classmethod
|
||||
def _db_load_data_sl_format(cls, values, len_data, timestamps):
|
||||
@@ -253,20 +277,23 @@ class Profile(SQLSubModel):
|
||||
class Reach(SQLSubModel):
|
||||
_sub_classes = [Profile]
|
||||
|
||||
def __init__(self, reach, study, with_init=True):
|
||||
def __init__(self, reach, study, parent, with_init=True, profiles=None):
|
||||
super(Reach, self).__init__(
|
||||
id=-1, status=study.status,
|
||||
owner_scenario=study.status.scenario.id
|
||||
)
|
||||
|
||||
self._parent = parent
|
||||
self._study = study
|
||||
self._reach = reach # Source reach in the study
|
||||
self._profiles = []
|
||||
if with_init:
|
||||
if profiles is None:
|
||||
profiles = reach.profiles
|
||||
self._profiles = list(
|
||||
map(
|
||||
lambda p: Profile(p, self._study),
|
||||
reach.profiles
|
||||
lambda p: Profile(p, self._study, self._parent),
|
||||
profiles
|
||||
)
|
||||
)
|
||||
|
||||
@@ -276,6 +303,10 @@ class Reach(SQLSubModel):
|
||||
)
|
||||
)
|
||||
|
||||
self._global_index = (-1, -1)
|
||||
|
||||
self._buffers = {}
|
||||
|
||||
def __len__(self):
|
||||
return len(self._profiles)
|
||||
|
||||
@@ -295,14 +326,42 @@ class Reach(SQLSubModel):
|
||||
def profile_mask(self):
|
||||
return self._profile_mask
|
||||
|
||||
@property
|
||||
def buffers(self):
|
||||
return self._buffers
|
||||
|
||||
def profile(self, 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):
|
||||
self._profiles[profile_id].set(timestamp, key, data)
|
||||
|
||||
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
|
||||
def _db_create(cls, execute, ext=""):
|
||||
@@ -317,12 +376,20 @@ class Reach(SQLSubModel):
|
||||
reach = data["reach"]
|
||||
|
||||
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):
|
||||
data["profile"] = profile
|
||||
new_reach._profiles += Profile._db_load(execute, data)
|
||||
result_profile = Profile._db_load(execute, data)
|
||||
if len(result_profile) > 0:
|
||||
new_reach._profiles.append(result_profile)
|
||||
|
||||
new_reach._profile_mask = [
|
||||
profile.name[0:8] != 'interpol'
|
||||
for profile in new_reach._profiles
|
||||
]
|
||||
|
||||
return new_reach
|
||||
|
||||
@@ -336,13 +403,14 @@ class Reach(SQLSubModel):
|
||||
class River(SQLSubModel):
|
||||
_sub_classes = [Reach]
|
||||
|
||||
def __init__(self, study):
|
||||
def __init__(self, study, parent):
|
||||
super(River, self).__init__(
|
||||
id=-1, status=study.status,
|
||||
owner_scenario=study.status.scenario.id
|
||||
)
|
||||
|
||||
self._study = study
|
||||
self._parent = parent
|
||||
|
||||
# Dict with timestamps as key
|
||||
self._reachs = []
|
||||
@@ -360,10 +428,13 @@ class River(SQLSubModel):
|
||||
def has_reach(self, id):
|
||||
return 0 <= id < len(self._reachs)
|
||||
|
||||
def add(self, reach_id):
|
||||
def add(self, reach_id, profiles=None):
|
||||
reachs = self._study.river.enable_edges()
|
||||
|
||||
new = Reach(reachs[reach_id].reach, self._study)
|
||||
new = Reach(
|
||||
reachs[reach_id].reach, self._study, self._parent,
|
||||
profiles=profiles
|
||||
)
|
||||
|
||||
self._reachs.append(new)
|
||||
return new
|
||||
@@ -376,6 +447,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
|
||||
def _db_create(cls, execute, ext=""):
|
||||
return cls._create_submodel(execute)
|
||||
@@ -387,13 +467,15 @@ class River(SQLSubModel):
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
study = data["study"]
|
||||
new_river = cls(study)
|
||||
parent = data["parent"]
|
||||
|
||||
new_river = cls(study, parent)
|
||||
|
||||
for reach in study.river.reachs():
|
||||
data["reach"] = reach.reach
|
||||
new_river._reachs.append(
|
||||
Reach._db_load(execute, data)
|
||||
)
|
||||
result_reach = Reach._db_load(execute, data)
|
||||
if len(result_reach) > 0:
|
||||
new_river._reachs.append(result_reach)
|
||||
|
||||
return new_river
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -64,13 +64,15 @@ class Profile(object):
|
||||
|
||||
|
||||
class Reach(object):
|
||||
def __init__(self, reach, study):
|
||||
def __init__(self, reach, study, profiles=None):
|
||||
self._study = study
|
||||
self._reach = reach # Source reach in the study
|
||||
if profiles is None:
|
||||
profiles = reach.profiles
|
||||
self._profiles = list(
|
||||
map(
|
||||
lambda p: Profile(p, self._study),
|
||||
reach.profiles
|
||||
profiles
|
||||
)
|
||||
)
|
||||
|
||||
@@ -89,6 +91,10 @@ class Reach(object):
|
||||
def profiles(self):
|
||||
return self._profiles.copy()
|
||||
|
||||
def get_rk(self):
|
||||
"""Return the PK values for profiles present in the results."""
|
||||
return [profile.rk for profile in self._profiles]
|
||||
|
||||
def profile(self, id):
|
||||
return self._profiles[id]
|
||||
|
||||
@@ -119,10 +125,10 @@ class River(object):
|
||||
def has_reach(self, id):
|
||||
return 0 <= id < len(self._reachs)
|
||||
|
||||
def add(self, reach_id):
|
||||
def add(self, reach_id, profiles=None):
|
||||
reachs = self._study.river.enable_edges()
|
||||
|
||||
new = Reach(reachs[reach_id].reach, self._study)
|
||||
new = Reach(reachs[reach_id].reach, self._study, profiles=profiles)
|
||||
|
||||
self._reachs.append(new)
|
||||
return new
|
||||
|
||||
+140
-17
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -49,7 +49,6 @@ from Model.REPLine.REPLineList import REPLineList
|
||||
|
||||
from Solver.Solvers import solver_type_list
|
||||
|
||||
from Model.OutputRKAdists.OutputRKListAdists import OutputRKAdistsList
|
||||
from Model.Pollutants.PollutantsList import PollutantsList
|
||||
from Model.InitialConditionsAdisTS.InitialConditionsAdisTSList \
|
||||
import InitialConditionsAdisTSList
|
||||
@@ -59,6 +58,16 @@ from Model.LateralContributionsAdisTS.LateralContributionsAdisTSList \
|
||||
import LateralContributionsAdisTSList
|
||||
from Model.D90AdisTS.D90AdisTSList import D90AdisTSList
|
||||
from Model.DIFAdisTS.DIFAdisTSList import DIFAdisTSList
|
||||
|
||||
from Model.InitialConditionsTemperature.InitialConditionsTemperatureList \
|
||||
import InitialConditionsTemperatureList
|
||||
|
||||
from Model.BoundaryConditionsTemperature.BoundaryConditionsTemperatureList \
|
||||
import BoundaryConditionsTemperatureList
|
||||
|
||||
from Model.WeatherParameters.WeatherParametersList \
|
||||
import WeatherParametersList
|
||||
|
||||
from Model.GeoTIFF.GeoTIFFList import GeoTIFFList
|
||||
from Model.Results.Results import Results
|
||||
|
||||
@@ -180,6 +189,9 @@ class RiverNode(Node):
|
||||
return nodes
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"INSERT OR REPLACE INTO river_node(" +
|
||||
"pamhyr_id, deleted, name, x, y, scenario" +
|
||||
@@ -361,7 +373,7 @@ class RiverReach(Edge):
|
||||
)
|
||||
new.enable(enable=enabled)
|
||||
if deleted:
|
||||
nd.set_as_deleted()
|
||||
new.set_as_deleted()
|
||||
|
||||
data["reach"] = new
|
||||
new._reach = Reach._db_load(execute, data)
|
||||
@@ -377,6 +389,9 @@ class RiverReach(Edge):
|
||||
return reachs
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"INSERT OR REPLACE INTO " +
|
||||
"river_reach(" +
|
||||
@@ -386,7 +401,7 @@ class RiverReach(Edge):
|
||||
"VALUES (" +
|
||||
f"{self.pamhyr_id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"'{self._db_format(self._name)}', " +
|
||||
f"{self._db_format(self.is_enable())},"
|
||||
f"{self._db_format(self.is_enable())}," +
|
||||
f"{self.node1.pamhyr_id}, {self.node2.pamhyr_id}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
@@ -462,13 +477,15 @@ class River(Graph):
|
||||
HydraulicStructureList,
|
||||
AddFileList,
|
||||
REPLineList,
|
||||
OutputRKAdistsList,
|
||||
PollutantsList,
|
||||
InitialConditionsAdisTSList,
|
||||
BoundaryConditionsAdisTSList,
|
||||
LateralContributionsAdisTSList,
|
||||
D90AdisTSList,
|
||||
DIFAdisTSList,
|
||||
InitialConditionsTemperatureList,
|
||||
BoundaryConditionsTemperatureList,
|
||||
WeatherParametersList,
|
||||
GeoTIFFList,
|
||||
Results
|
||||
]
|
||||
@@ -496,7 +513,6 @@ class River(Graph):
|
||||
)
|
||||
self._additional_files = AddFileList(status=self._status)
|
||||
self._rep_lines = REPLineList(status=self._status)
|
||||
self._Output_rk_adists = OutputRKAdistsList(status=self._status)
|
||||
self._Pollutants = PollutantsList(status=self._status)
|
||||
self._InitialConditionsAdisTS = InitialConditionsAdisTSList(
|
||||
status=self._status)
|
||||
@@ -506,6 +522,13 @@ class River(Graph):
|
||||
status=self._status)
|
||||
self._D90AdisTS = D90AdisTSList(status=self._status)
|
||||
self._DIFAdisTS = DIFAdisTSList(status=self._status)
|
||||
self._InitialConditionsTemperature = (
|
||||
InitialConditionsTemperatureList(status=self._status)
|
||||
)
|
||||
self._BoundaryConditionsTemperature = (
|
||||
BoundaryConditionsTemperatureList(status=self._status)
|
||||
)
|
||||
self._WeatherParameters = (WeatherParametersList(status=self._status))
|
||||
|
||||
self._geotiff = GeoTIFFList(status=self._status)
|
||||
|
||||
@@ -543,7 +566,7 @@ class River(Graph):
|
||||
new._nodes = RiverNode._db_load(
|
||||
execute, data
|
||||
)
|
||||
data["nodes"] = new.nodes()
|
||||
data["nodes"] = new._nodes
|
||||
data['loaded_pid'] = set()
|
||||
|
||||
new._edges = RiverReach._db_load(
|
||||
@@ -604,10 +627,6 @@ class River(Graph):
|
||||
|
||||
new._Pollutants = PollutantsList._db_load(execute, data)
|
||||
|
||||
new._Output_rk_adists = OutputRKAdistsList._db_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
new._InitialConditionsAdisTS = InitialConditionsAdisTSList._db_load(
|
||||
execute, data)
|
||||
|
||||
@@ -621,6 +640,14 @@ class River(Graph):
|
||||
|
||||
new._DIFAdisTS = DIFAdisTSList._db_load(execute, data)
|
||||
|
||||
new._InitialConditionsTemperature = \
|
||||
InitialConditionsTemperatureList._db_load(execute, data)
|
||||
|
||||
new._BoundaryConditionsTemperature = \
|
||||
BoundaryConditionsTemperatureList._db_load(execute, data)
|
||||
|
||||
new._WeatherParameters = WeatherParametersList._db_load(execute, data)
|
||||
|
||||
new._geotiff = GeoTIFFList._db_load(execute, data)
|
||||
|
||||
return new
|
||||
@@ -648,7 +675,6 @@ class River(Graph):
|
||||
for solver in self._parameters:
|
||||
objs.append(self._parameters[solver])
|
||||
|
||||
objs.append(self._Output_rk_adists)
|
||||
objs.append(self._Pollutants)
|
||||
objs.append(self._InitialConditionsAdisTS)
|
||||
objs.append(self._BoundaryConditionsAdisTS)
|
||||
@@ -656,6 +682,10 @@ class River(Graph):
|
||||
objs.append(self._D90AdisTS)
|
||||
objs.append(self._DIFAdisTS)
|
||||
|
||||
objs.append(self._InitialConditionsTemperature)
|
||||
objs.append(self._BoundaryConditionsTemperature)
|
||||
objs.append(self._WeatherParameters)
|
||||
|
||||
objs.append(self._geotiff)
|
||||
|
||||
for solv_type in self.results:
|
||||
@@ -728,12 +758,14 @@ class River(Graph):
|
||||
self._hydraulic_structures,
|
||||
self._additional_files,
|
||||
self._rep_lines,
|
||||
self._Output_rk_adists,
|
||||
self._Pollutants,
|
||||
self._InitialConditionsAdisTS,
|
||||
self._BoundaryConditionsAdisTS,
|
||||
self._LateralContributionsAdisTS,
|
||||
self._D90AdisTS, self._DIFAdisTS,
|
||||
self._InitialConditionsTemperature,
|
||||
self._BoundaryConditionsTemperature,
|
||||
self._WeatherParameters,
|
||||
self._geotiff,
|
||||
]
|
||||
|
||||
@@ -839,10 +871,6 @@ Last export at: @date."""
|
||||
def parameters(self):
|
||||
return self._parameters
|
||||
|
||||
@property
|
||||
def Output_rk_adists(self):
|
||||
return self._Output_rk_adists
|
||||
|
||||
@property
|
||||
def Pollutants(self):
|
||||
return self._Pollutants
|
||||
@@ -867,6 +895,67 @@ Last export at: @date."""
|
||||
def dif_adists(self):
|
||||
return self._DIFAdisTS
|
||||
|
||||
@property
|
||||
def ic_temperature(self):
|
||||
return self._InitialConditionsTemperature
|
||||
|
||||
@property
|
||||
def boundary_conditions_temperature(self):
|
||||
return self._BoundaryConditionsTemperature
|
||||
|
||||
@property
|
||||
def weather_parameters(self):
|
||||
return self._WeatherParameters
|
||||
|
||||
def profile_dependencies(self, profile):
|
||||
"""Return model data which directly reference *profile*.
|
||||
|
||||
PK-based intervals are deliberately not included: only explicit
|
||||
references to the profile object prevent it from being disabled.
|
||||
"""
|
||||
dependencies = []
|
||||
|
||||
def add(kind, item, association):
|
||||
dependencies.append({
|
||||
"kind": kind,
|
||||
"item": item,
|
||||
"association": association,
|
||||
})
|
||||
|
||||
for structure in self._hydraulic_structures.lst:
|
||||
if structure.input_section is profile:
|
||||
add("hydraulic_structure", structure, "")
|
||||
|
||||
for tab in self._lateral_contribution._tabs_list:
|
||||
for contribution in self._lateral_contribution.get_tab(tab):
|
||||
if contribution.begin_section is profile:
|
||||
add("lateral_contribution", contribution, "begin_section")
|
||||
if contribution.end_section is profile:
|
||||
add("lateral_contribution", contribution, "end_section")
|
||||
|
||||
for parameter in self._WeatherParameters.lst:
|
||||
if parameter.begin_section is profile:
|
||||
add("weather_parameter", parameter, "begin_section")
|
||||
if parameter.end_section is profile:
|
||||
add("weather_parameter", parameter, "end_section")
|
||||
|
||||
reach_id = profile.reach.pamhyr_id
|
||||
for initial_condition in self._InitialConditionsTemperature.lst:
|
||||
for specification in initial_condition.data:
|
||||
same_reach = specification.reach == reach_id
|
||||
same_rk = (
|
||||
specification.start_rk == profile.rk or
|
||||
specification.end_rk == profile.rk
|
||||
)
|
||||
if same_reach and same_rk:
|
||||
add(
|
||||
"initial_condition_temperature",
|
||||
specification,
|
||||
"cross_section_pk",
|
||||
)
|
||||
|
||||
return dependencies
|
||||
|
||||
def get_params(self, solver):
|
||||
if solver in self._parameters:
|
||||
return self._parameters[solver]
|
||||
@@ -923,6 +1012,12 @@ Last export at: @date."""
|
||||
self._results[solv_type] = results
|
||||
|
||||
def _split_reach(self, reach, profile):
|
||||
profiles = reach.reach.profiles
|
||||
if not profiles or profile not in profiles[1:-1]:
|
||||
raise ValueError(
|
||||
"A reach cannot be split at its first or last profile"
|
||||
)
|
||||
|
||||
node1 = reach.node1
|
||||
node2 = reach.node2
|
||||
|
||||
@@ -939,4 +1034,32 @@ Last export at: @date."""
|
||||
self._add_edge(r1)
|
||||
self._add_edge(r2)
|
||||
|
||||
self._initial_conditions.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
self._lateral_contribution.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
self._hydraulic_structures.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
self._InitialConditionsAdisTS.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
self._LateralContributionsAdisTS.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
self._InitialConditionsTemperature.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
self._WeatherParameters.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
self._D90AdisTS.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
self._DIFAdisTS.split_reach(
|
||||
reach, profile, r1, r2
|
||||
)
|
||||
|
||||
return r1, r2
|
||||
+107
-31
@@ -17,16 +17,56 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import logging
|
||||
|
||||
from tools import logger_exception
|
||||
from tools import logger_exception, timer, flatten
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Scenario(SQLSubModel):
|
||||
_id_cnt = 0
|
||||
_sub_classes = []
|
||||
|
||||
tables_with_deleted_column = [
|
||||
# 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",
|
||||
# Temperature
|
||||
"boundary_condition_temperature",
|
||||
"boundary_condition_data_temperature",
|
||||
"initial_conditions_temperature",
|
||||
"initial_conditions_temperature_spec",
|
||||
"weather_parameters", "weather_parameters_data",
|
||||
]
|
||||
|
||||
related_tables = tables_with_deleted_column + [
|
||||
"dif_adists",
|
||||
"solver_parameter",
|
||||
"hydraulic_structures_basic_value",
|
||||
"results", "results_data", "results_add_data",
|
||||
]
|
||||
|
||||
def __init__(self,
|
||||
id: int = -1,
|
||||
name: str = "",
|
||||
@@ -171,29 +211,7 @@ class Scenario(SQLSubModel):
|
||||
def drop_all(self, execute):
|
||||
execute(f"DELETE FROM scenario WHERE id = {self.id}")
|
||||
|
||||
tables = [
|
||||
# Adists
|
||||
"output_rk_adists",
|
||||
"boundary_condition_adists", "boundary_condition_data_adists",
|
||||
"lateral_contribution_adists", "lateral_contribution_data_adists",
|
||||
"initial_conditions_adists",
|
||||
"d90_adists", "dif_adists",
|
||||
"pollutants", "pollutants_characteristics",
|
||||
# Hydraulic
|
||||
"additional_files",
|
||||
"boundary_condition", "boundary_condition_data",
|
||||
"lateral_contribution", "lateral_contribution_data",
|
||||
"friction", "stricklers",
|
||||
"hydraulic_structures",
|
||||
"hydraulic_structures_basic", "hydraulic_structures_basic_value",
|
||||
"initial_conditions",
|
||||
"sedimentary_layer", "sedimentary_layer_layer",
|
||||
"reservoir", "reservoir_data",
|
||||
"rep_lines",
|
||||
"solver_parameter",
|
||||
"geometry_pointXYZ", "geometry_profileXYZ",
|
||||
"river_reach", "river_node",
|
||||
]
|
||||
tables = self.related_tables
|
||||
|
||||
for table in tables:
|
||||
execute(
|
||||
@@ -203,6 +221,67 @@ class Scenario(SQLSubModel):
|
||||
|
||||
return True
|
||||
|
||||
def get_parent_branch(self):
|
||||
def aux(scenario, acc):
|
||||
if scenario is None:
|
||||
return acc
|
||||
|
||||
return aux(scenario.parent, [scenario.id] + acc)
|
||||
|
||||
return aux(self, [])
|
||||
|
||||
@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
|
||||
def id(self):
|
||||
return self._id
|
||||
@@ -272,11 +351,8 @@ class Scenario(SQLSubModel):
|
||||
return None
|
||||
|
||||
def workdir(self):
|
||||
srep = ""
|
||||
if self.id != 0:
|
||||
srep = os.path.join(
|
||||
self.parent.workdir(),
|
||||
"scenario_" + str(self.id)
|
||||
)
|
||||
current = "scenario_" + str(self.id)
|
||||
if self.parent is None or self.parent.id == 0:
|
||||
return current
|
||||
|
||||
return srep
|
||||
return os.path.join(self.parent.workdir(), current)
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from functools import reduce
|
||||
|
||||
from tools import logger_exception
|
||||
|
||||
from Model.Tools.PamhyrDict import PamhyrModelDict
|
||||
@@ -78,3 +80,12 @@ class Scenarios(PamhyrModelDict):
|
||||
|
||||
self._dict[key].set_as_deleted()
|
||||
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
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
# Copyright (C) 2023-2026 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -216,6 +216,9 @@ class Parameter(SQLSubModel):
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
ind = data["ind"]
|
||||
solver = data["solver"]
|
||||
|
||||
|
||||
+14
-1
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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._scenario = scenario
|
||||
self._saved = True
|
||||
self._loading = False
|
||||
|
||||
@property
|
||||
def scenario_id(self):
|
||||
@@ -86,6 +87,15 @@ class StudyStatus(object):
|
||||
def is_saved(self):
|
||||
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):
|
||||
logger.debug("model status set as saved")
|
||||
self._saved = True
|
||||
@@ -97,6 +107,9 @@ class StudyStatus(object):
|
||||
self._saved = True
|
||||
|
||||
def modified(self):
|
||||
if self._loading:
|
||||
return
|
||||
|
||||
if self._saved:
|
||||
self.version += 1
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -60,9 +60,12 @@ class StricklersList(PamhyrModelList):
|
||||
return self.lst
|
||||
|
||||
def new(self, index):
|
||||
owner_scenario = (
|
||||
self._status.scenario_id if self._status is not None else -1
|
||||
)
|
||||
s = Stricklers(
|
||||
status=self._status,
|
||||
owner_scenario=self._status.scenario_id
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
self.insert(index, s)
|
||||
self.modified()
|
||||
|
||||
+119
-17
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -21,15 +21,25 @@ import shutil
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
from tools import timer, timestamp
|
||||
from tools import timer, timestamp, parse_datetime
|
||||
from functools import reduce
|
||||
|
||||
from Model.Tools.PamhyrListExt import PamhyrModelList
|
||||
from Model.Tools.PamhyrDict import PamhyrModelDict
|
||||
from Model.Tools.PamhyrDB import SQLModel
|
||||
from Model.Scenarios import Scenarios
|
||||
from Model.Scenario import Scenario
|
||||
from Model.Status import StudyStatus
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.River import River
|
||||
from Model.TimeShift import shift_river_times, shift_database_times
|
||||
from Model.Geometry.Reach import Reach
|
||||
from Model.HydraulicStructures.HydraulicStructures import (
|
||||
HydraulicStructure
|
||||
)
|
||||
from Model.HydraulicStructures.Basic.HydraulicStructures import (
|
||||
BasicHS
|
||||
)
|
||||
|
||||
from Checker.Study import *
|
||||
|
||||
@@ -37,7 +47,7 @@ logger = logging.getLogger()
|
||||
|
||||
|
||||
class Study(SQLModel):
|
||||
_version = "0.2.3"
|
||||
_version = "0.2.10"
|
||||
|
||||
_sub_classes = [
|
||||
Scenario,
|
||||
@@ -63,6 +73,7 @@ class Study(SQLModel):
|
||||
self.description = ""
|
||||
# Time system
|
||||
self._time_system = "time"
|
||||
self._pending_time_offset = 0.0
|
||||
self._date = datetime.fromtimestamp(0)
|
||||
|
||||
if init_new:
|
||||
@@ -189,6 +200,16 @@ class Study(SQLModel):
|
||||
self._date = date
|
||||
self.status.modified()
|
||||
|
||||
def change_start_date(self, date, preserve_dates=False):
|
||||
"""Change the origin, optionally preserving series calendar dates."""
|
||||
new_date = parse_datetime(date)
|
||||
offset = (parse_datetime(self.date) - new_date).total_seconds()
|
||||
if preserve_dates and offset:
|
||||
shift_river_times(self.river, offset)
|
||||
self._pending_time_offset += offset
|
||||
self._river_scenario_cache.clear()
|
||||
self.use_date(new_date)
|
||||
|
||||
@property
|
||||
def date(self):
|
||||
return self._date
|
||||
@@ -208,8 +229,7 @@ class Study(SQLModel):
|
||||
me.name = name
|
||||
me.description = description
|
||||
if date is not None:
|
||||
me.use_date()
|
||||
me.date = date
|
||||
me.use_date(date)
|
||||
return me
|
||||
|
||||
@classmethod
|
||||
@@ -281,7 +301,14 @@ class Study(SQLModel):
|
||||
if major == "0" and int(minor) < 2:
|
||||
self._add_into_info_if_not_exists('current_scenario', '0')
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
needs_foreign_keys_disabled = (
|
||||
major == "0" and (
|
||||
int(minor) < 2 or
|
||||
(minor == "2" and int(release) < 10)
|
||||
)
|
||||
)
|
||||
|
||||
if needs_foreign_keys_disabled:
|
||||
# Need to temporary disable the sqlite foreign keys
|
||||
# checking to update db dans change the table id fk to
|
||||
# table pamhyr_id fk
|
||||
@@ -291,7 +318,7 @@ class Study(SQLModel):
|
||||
|
||||
ok = self._update_submodel(version[0], data={})
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
if needs_foreign_keys_disabled:
|
||||
# Reactivate foreign keys checking
|
||||
self.execute(
|
||||
"PRAGMA foreign_keys = ON;"
|
||||
@@ -445,12 +472,75 @@ class Study(SQLModel):
|
||||
)
|
||||
progress()
|
||||
|
||||
if self._pending_time_offset:
|
||||
self._db.execute('SAVEPOINT shift_time_origin')
|
||||
try:
|
||||
shift_database_times(self._db, self._pending_time_offset)
|
||||
self._db.execute('RELEASE SAVEPOINT shift_time_origin')
|
||||
except Exception:
|
||||
self._db.execute('ROLLBACK TO SAVEPOINT shift_time_origin')
|
||||
self._db.execute('RELEASE SAVEPOINT shift_time_origin')
|
||||
raise
|
||||
self._pending_time_offset = 0.0
|
||||
|
||||
self._save_submodel(
|
||||
[self.scenarios, self._river],
|
||||
data=progress
|
||||
)
|
||||
|
||||
# Clear DB for current scenario
|
||||
ids = self.status.scenario.clean_deleted_data(self.execute)
|
||||
self.memory_clean(ids)
|
||||
|
||||
progress()
|
||||
|
||||
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):
|
||||
return self._count()
|
||||
|
||||
@@ -459,7 +549,10 @@ class Study(SQLModel):
|
||||
[self.scenarios, self._river]
|
||||
)
|
||||
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):
|
||||
"""Close db connection
|
||||
@@ -485,7 +578,8 @@ class Study(SQLModel):
|
||||
self.status.scenario = scenario
|
||||
|
||||
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,
|
||||
False
|
||||
):
|
||||
@@ -511,15 +605,23 @@ class Study(SQLModel):
|
||||
"scenario": scenario
|
||||
}
|
||||
|
||||
# Load river data
|
||||
river = River._db_load(
|
||||
sql_exec, data=data
|
||||
)
|
||||
data["study"] = self
|
||||
river._db_load_results(sql_exec, data=data)
|
||||
self.status.start_loading()
|
||||
try:
|
||||
# Load river data
|
||||
river = River._db_load(
|
||||
sql_exec, data=data
|
||||
)
|
||||
data["study"] = self
|
||||
river._db_load_results(sql_exec, data=data)
|
||||
finally:
|
||||
self.status.stop_loading()
|
||||
self.status.scenario = old_scenario
|
||||
|
||||
self._river_scenario_cache[scenario] = river
|
||||
self.status.scenario = old_scenario
|
||||
if self._pending_time_offset:
|
||||
shift_river_times(river, self._pending_time_offset)
|
||||
|
||||
# FIXME: Disable scenario cache to save memory usage
|
||||
# self._river_scenario_cache[scenario] = river
|
||||
|
||||
return river
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
"""Shift temporal series when preserving calendar dates across a new origin."""
|
||||
from Model.BoundaryCondition.BoundaryCondition import BoundaryCondition
|
||||
from Model.LateralContribution.LateralContribution import LateralContribution
|
||||
from Model.WeatherParameters.WeatherParameters import WeatherParameters
|
||||
from Model.BoundaryConditionsAdisTS.BoundaryConditionAdisTS import (
|
||||
BoundaryConditionAdisTS
|
||||
)
|
||||
from Model.LateralContributionsAdisTS.LateralContributionAdisTS import (
|
||||
LateralContributionAdisTS
|
||||
)
|
||||
from Model.BoundaryConditionsTemperature.BoundaryConditionTemperature import (
|
||||
BoundaryConditionTemperature
|
||||
)
|
||||
|
||||
|
||||
def shift_river_times(river, offset):
|
||||
changes = []
|
||||
seen = set()
|
||||
|
||||
def collect(obj, data):
|
||||
temporal = isinstance(obj, (
|
||||
BoundaryConditionAdisTS,
|
||||
LateralContributionAdisTS,
|
||||
BoundaryConditionTemperature
|
||||
))
|
||||
if isinstance(obj, (
|
||||
BoundaryCondition, LateralContribution, WeatherParameters
|
||||
)):
|
||||
temporal = bool(obj.header) and obj.header[0] == 'time'
|
||||
if temporal:
|
||||
for point in obj._data:
|
||||
if id(point) not in seen:
|
||||
changes.append((point, float(point[0]) + offset))
|
||||
seen.add(id(point))
|
||||
|
||||
river._data_traversal(modifier=collect)
|
||||
for point, value in changes:
|
||||
# This is a global change of origin, not a scenario-specific edit.
|
||||
point[0] = value
|
||||
|
||||
|
||||
def shift_database_times(connection, offset):
|
||||
tables = [
|
||||
(
|
||||
'boundary_condition_data', 'boundary_condition',
|
||||
'bc', BoundaryCondition
|
||||
),
|
||||
(
|
||||
'lateral_contribution_data', 'lateral_contribution',
|
||||
'lc', LateralContribution
|
||||
),
|
||||
(
|
||||
'weather_parameters_data', 'weather_parameters',
|
||||
'wp', WeatherParameters
|
||||
),
|
||||
('boundary_condition_data_adists', None, None, None),
|
||||
('lateral_contribution_data_adists', None, None, None),
|
||||
('boundary_condition_data_temperature', None, None, None),
|
||||
]
|
||||
for table, parent, fk, model in tables:
|
||||
if model is None:
|
||||
rows = connection.execute(
|
||||
f'SELECT rowid, data0 FROM {table}'
|
||||
).fetchall()
|
||||
else:
|
||||
rows = []
|
||||
for kind, in connection.execute(
|
||||
f'SELECT DISTINCT type FROM {parent}'
|
||||
):
|
||||
headers = model._get_ctor_from_type(kind)().header
|
||||
if not headers or headers[0] != 'time':
|
||||
continue
|
||||
rows.extend(connection.execute(
|
||||
f'SELECT d.rowid, d.data0 FROM {table} d JOIN {parent} p '
|
||||
f'ON p.pamhyr_id=d.{fk} AND p.scenario=d.scenario '
|
||||
f'WHERE p.type=?',
|
||||
(kind,)
|
||||
).fetchall())
|
||||
connection.executemany(
|
||||
f'UPDATE {table} SET data0=? WHERE rowid=?',
|
||||
[(float(value) + offset, rowid) for rowid, value in rows]
|
||||
)
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# 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 Model.Except import NotImplementedMethodeError
|
||||
|
||||
from tools import trace
|
||||
|
||||
from Model.Tools.PamhyrID import PamhyrID
|
||||
|
||||
logger = logging.getLogger()
|
||||
@@ -48,11 +50,9 @@ class SQLModel(SQL):
|
||||
self._cur = self._db.cursor()
|
||||
|
||||
if is_new:
|
||||
logger.info("Create database")
|
||||
self._create() # Create db
|
||||
# self._save() # Save
|
||||
else:
|
||||
logger.info("Update database")
|
||||
self._update() # Update db scheme if necessary
|
||||
# self._load() # Load data
|
||||
|
||||
@@ -202,6 +202,8 @@ class SQLSubModel(PamhyrID):
|
||||
"""
|
||||
if self._status is None:
|
||||
return
|
||||
if self._status.is_loading():
|
||||
return
|
||||
|
||||
self._owner_scenario = self._status.scenario_id
|
||||
self._status.modified()
|
||||
@@ -218,6 +220,8 @@ class SQLSubModel(PamhyrID):
|
||||
"""
|
||||
if self._status is None:
|
||||
return
|
||||
if self._status.is_loading():
|
||||
return
|
||||
|
||||
self._owner_scenario = self._status.scenario_id
|
||||
self._status.modified()
|
||||
@@ -297,6 +301,15 @@ class SQLSubModel(PamhyrID):
|
||||
"""
|
||||
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
|
||||
def _db_update_to_0_2_0_set_node_pid(cls, execute, table, nodes):
|
||||
els = execute(
|
||||
@@ -311,6 +324,14 @@ class SQLSubModel(PamhyrID):
|
||||
if node_id == -1:
|
||||
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(
|
||||
f"UPDATE {table} " +
|
||||
f"SET node = {nodes[node_id]} " +
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -97,6 +97,9 @@ class PamhyrModelDict(SQLSubModel):
|
||||
Nothing
|
||||
|
||||
"""
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
for key in self._dict:
|
||||
self._dict[key]\
|
||||
._data_traversal(predicate, modifier, data)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -100,6 +100,9 @@ class PamhyrModelList(SQLSubModel):
|
||||
Nothing
|
||||
|
||||
"""
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
for el in self._lst:
|
||||
el._data_traversal(predicate, modifier, data)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -107,6 +107,9 @@ class PamhyrModelList(SQLSubModel):
|
||||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
for el in self._lst:
|
||||
el._data_traversal(predicate, modifier, data)
|
||||
|
||||
@@ -168,7 +171,7 @@ class PamhyrModelList(SQLSubModel):
|
||||
lambda x: x[1],
|
||||
filter(
|
||||
lambda x: x[0] in indexes,
|
||||
enumerate(self._lst)
|
||||
enumerate(self.lst)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -0,0 +1,775 @@
|
||||
# WeatherParameters.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from tools import (
|
||||
trace, timer,
|
||||
old_pamhyr_date_to_timestamp,
|
||||
date_iso_to_timestamp,
|
||||
date_dmy_to_timestamp,
|
||||
)
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Data(SQLSubModel):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self,
|
||||
data0, data1,
|
||||
id: int = -1,
|
||||
types=[float, float],
|
||||
status=None,
|
||||
owner_scenario=-1):
|
||||
super(Data, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._types = types
|
||||
self._data = [data0, data1]
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE weather_parameters_data{ext} (
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
ind INTEGER NOT NULL,
|
||||
data0 TEXT NOT NULL,
|
||||
data1 TEXT NOT NULL,
|
||||
wp INTEGER,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(wp) REFERENCES weather_parameters(pamhyr_id),
|
||||
PRIMARY KEY(pamhyr_id, scenario)
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
|
||||
if major == "0" and (int(minor) < 2 or
|
||||
(int(minor) == 2 and int(release) <= 7)):
|
||||
if not cls.is_table_exists(execute, "air_temperature_data"):
|
||||
cls._db_create(execute)
|
||||
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
wp = data["wp"]
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
values = execute(
|
||||
"SELECT pamhyr_id, deleted, " +
|
||||
"data0, data1, scenario " +
|
||||
"FROM weather_parameters_data " +
|
||||
f"WHERE wp = {wp._pamhyr_id} " +
|
||||
f"AND scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
|
||||
"ORDER BY ind ASC"
|
||||
)
|
||||
|
||||
for v in values:
|
||||
it = iter(v)
|
||||
|
||||
pid = next(it)
|
||||
deleted = next(it)
|
||||
data0 = wp._types[0](next(it))
|
||||
data1 = wp._types[1](next(it))
|
||||
owner_scenario = next(it)
|
||||
|
||||
nd = cls(
|
||||
data0, data1,
|
||||
id=pid,
|
||||
types=wp._types,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
nd.set_as_deleted()
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(nd)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
pid = self._pamhyr_id
|
||||
ind = data["ind"]
|
||||
data0 = self._db_format(str(self[0]))
|
||||
data1 = self._db_format(str(self[1]))
|
||||
wp = data["wp"]
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"weather_parameters_data (pamhyr_id, deleted, ind, " +
|
||||
"data0, data1, wp, scenario) " +
|
||||
f"VALUES ({pid}, {self._db_format(self.is_deleted())}, " +
|
||||
f"{ind}, '{self._db_format(data0)}', {self._db_format(data1)}, " +
|
||||
f"{wp._pamhyr_id}, {self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self._types[key](self._data[key])
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
self._data[key] = self._types[key](value)
|
||||
|
||||
def cloned(self):
|
||||
return Data(
|
||||
self[0], self[1],
|
||||
types=self._types,
|
||||
status=self._status
|
||||
)
|
||||
|
||||
|
||||
class WeatherParametersDefault(SQLSubModel):
|
||||
def __init__(self, type: str, value: float = 0.0,
|
||||
id: int = -1, status=None, owner_scenario=-1):
|
||||
super(WeatherParametersDefault, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = type
|
||||
self._value = float(value)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, type, value, scenario " +
|
||||
"FROM weather_parameters_default " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
)
|
||||
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
type = next(it)
|
||||
value = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
wp_default = cls(
|
||||
type=type,
|
||||
value=value,
|
||||
id=pid,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(wp_default)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"weather_parameters_default(" +
|
||||
"pamhyr_id, type, value, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, '{self._db_format(self._type)}', {self._value}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
return self._type
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self._value
|
||||
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
self._value = float(value)
|
||||
self.modified()
|
||||
|
||||
|
||||
class WeatherParameters(SQLSubModel):
|
||||
_sub_classes = [Data]
|
||||
|
||||
def __init__(self, id: int = -1,
|
||||
name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(WeatherParameters, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._name = name
|
||||
self._type = ""
|
||||
self._reach = None
|
||||
self._begin_section = None
|
||||
self._end_section = None
|
||||
self._data = []
|
||||
self._header = []
|
||||
self._types = [float, float]
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE weather_parameters{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
name TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
reach INTEGER,
|
||||
begin_section INTEGER,
|
||||
end_section INTEGER,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id),
|
||||
FOREIGN KEY(begin_section)
|
||||
REFERENCES geometry_profileXYZ(pamhyr_id),
|
||||
FOREIGN KEY(end_section)
|
||||
REFERENCES geometry_profileXYZ(pamhyr_id),
|
||||
PRIMARY KEY(pamhyr_id, scenario)
|
||||
)
|
||||
""")
|
||||
|
||||
execute(f"""
|
||||
CREATE TABLE weather_parameters_default{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
type TEXT NOT NULL,
|
||||
value FLOAT NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
primary KEY(pamhyr_id, scenario)
|
||||
)
|
||||
""")
|
||||
|
||||
if ext == "_tmp":
|
||||
return True
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _get_ctor_from_type(cls, t):
|
||||
from Model.WeatherParameters.WeatherParametersTypes import (
|
||||
NotDefined, WeatherParam, AirTemperature, SpecificHumidity,
|
||||
GlobalRadiation, ReferenceWindSpeed, GroundwaterTemperature,
|
||||
GroundwaterFlowRate, Albedo, ShadingCoefficient, CloudCoverFraction
|
||||
)
|
||||
|
||||
res = NotDefined
|
||||
if t == "WP":
|
||||
res = WeatherParam
|
||||
elif t == "AT":
|
||||
res = AirTemperature
|
||||
elif t == "SH":
|
||||
res = SpecificHumidity
|
||||
elif t == "GR":
|
||||
res = GlobalRadiation
|
||||
elif t == "RWS":
|
||||
res = ReferenceWindSpeed
|
||||
elif t == "GT":
|
||||
res = GroundwaterTemperature
|
||||
elif t == "GFR":
|
||||
res = GroundwaterFlowRate
|
||||
elif t == "ALB":
|
||||
res = Albedo
|
||||
elif t == "SC":
|
||||
res = ShadingCoefficient
|
||||
elif t == "CCF":
|
||||
res = CloudCoverFraction
|
||||
else:
|
||||
res = NotDefined
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and (int(minor) < 2 or
|
||||
(int(minor) == 2 and int(release) <= 7)):
|
||||
if not cls.is_table_exists(execute, "air_temperature"):
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if not cls.is_table_exists(execute, "weather_parameters_default"):
|
||||
execute(f"""
|
||||
CREATE TABLE weather_parameters_default(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
type TEXT NOT NULL,
|
||||
value FLOAT NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
primary KEY(pamhyr_id, scenario)
|
||||
)
|
||||
""")
|
||||
|
||||
if not created:
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
edges = data["edges"]
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, name, type, " +
|
||||
"reach, begin_section, end_section, scenario " +
|
||||
"FROM weather_parameters " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
)
|
||||
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
deleted = next(it)
|
||||
name = next(it)
|
||||
t = next(it)
|
||||
reach = next(it)
|
||||
b_section = next(it)
|
||||
e_section = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
ctor = cls._get_ctor_from_type(t)
|
||||
wp = ctor(
|
||||
id=pid, name=name,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
wp.reach = None
|
||||
wp._begin_section = None
|
||||
wp._end_section = None
|
||||
|
||||
if reach not in (-1, None):
|
||||
wp.reach = next(
|
||||
(edge for edge in edges if edge.id == reach), None
|
||||
)
|
||||
profiles = (
|
||||
wp.reach.reach.profiles
|
||||
if wp.reach is not None else []
|
||||
)
|
||||
wp._begin_section = next(
|
||||
(profile for profile in profiles
|
||||
if profile.id == b_section), None
|
||||
)
|
||||
wp._end_section = next(
|
||||
(profile for profile in profiles
|
||||
if profile.id == e_section), None
|
||||
)
|
||||
|
||||
data["wp"] = wp
|
||||
wp._data = Data._db_load(execute, data=data)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(wp)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
data["wp"] = self
|
||||
|
||||
execute(
|
||||
"DELETE FROM weather_parameters_data " +
|
||||
f"WHERE wp = {self._pamhyr_id} " +
|
||||
f"AND scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
reach = None
|
||||
begin_section = None
|
||||
end_section = None
|
||||
|
||||
if self._reach is not None:
|
||||
reach = self._reach._pamhyr_id
|
||||
begin_section = self._begin_section._pamhyr_id
|
||||
end_section = self._end_section._pamhyr_id
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"weather_parameters(" +
|
||||
"pamhyr_id, deleted, name, type, " +
|
||||
"reach, begin_section, end_section, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"'{self._db_format(self._name)}', " +
|
||||
f"'{self._db_format(self._type)}', {reach}, " +
|
||||
f"{begin_section}, {end_section}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
ind = 0
|
||||
for d in self._data:
|
||||
data["ind"] = ind
|
||||
|
||||
d._db_save(execute, data)
|
||||
|
||||
ind += 1
|
||||
|
||||
return True
|
||||
|
||||
def _data_traversal(self,
|
||||
predicate=lambda obj, data: True,
|
||||
modifier=lambda obj, data: None,
|
||||
data={}):
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
for d in self._data:
|
||||
d._data_traversal(predicate, modifier, data)
|
||||
|
||||
def __len__(self):
|
||||
return len(
|
||||
list(
|
||||
filter(
|
||||
lambda el: not el.is_deleted(),
|
||||
self._data
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def compatibility(cls):
|
||||
return ["liquid", "solid", "suspenssion"]
|
||||
|
||||
@classmethod
|
||||
def time_convert(cls, data):
|
||||
if type(data) is str:
|
||||
if data.count("-") == 2:
|
||||
return date_iso_to_timestamp(data)
|
||||
if data.count("/") == 2:
|
||||
return date_dmy_to_timestamp(data)
|
||||
if data.count(":") == 3:
|
||||
return old_pamhyr_date_to_timestamp(data)
|
||||
if data.count(":") == 2:
|
||||
return old_pamhyr_date_to_timestamp("00:" + data)
|
||||
if data.count(".") == 1:
|
||||
return round(float(data))
|
||||
|
||||
return int(data)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
if self._name == "":
|
||||
return f"LC #{self.id}"
|
||||
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._name = name
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
return self._type
|
||||
|
||||
@property
|
||||
def reach(self):
|
||||
return self._reach
|
||||
|
||||
@reach.setter
|
||||
def reach(self, reach):
|
||||
self._reach = reach
|
||||
self._begin_section = None
|
||||
self._end_section = None
|
||||
|
||||
if reach is not None:
|
||||
profiles = reach.reach.profiles
|
||||
if profiles:
|
||||
self._begin_section = profiles[0]
|
||||
self._end_section = profiles[-1]
|
||||
|
||||
self.modified()
|
||||
|
||||
def has_reach(self):
|
||||
return self._reach is not None
|
||||
|
||||
@property
|
||||
def begin_rk(self):
|
||||
if self._begin_section is None:
|
||||
return 0
|
||||
|
||||
return self._begin_section.rk
|
||||
|
||||
@property
|
||||
def begin_section(self):
|
||||
return self._begin_section
|
||||
|
||||
@begin_section.setter
|
||||
def begin_section(self, section):
|
||||
self._begin_section = section
|
||||
self.modified()
|
||||
|
||||
@property
|
||||
def end_rk(self):
|
||||
if self._end_section is None:
|
||||
return 0
|
||||
|
||||
return self._end_section.rk
|
||||
|
||||
@property
|
||||
def end_section(self):
|
||||
return self._end_section
|
||||
|
||||
@end_section.setter
|
||||
def end_section(self, section):
|
||||
self._end_section = section
|
||||
self.modified()
|
||||
|
||||
def cloned_for(self, reach, begin_section, end_section):
|
||||
new = type(self)(name=self._name, status=self._status)
|
||||
new._reach = reach
|
||||
new._begin_section = begin_section
|
||||
new._end_section = end_section
|
||||
new._data = [data.cloned() for data in self.data]
|
||||
new.modified()
|
||||
return new
|
||||
|
||||
@property
|
||||
def header(self):
|
||||
return self._header.copy()
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return list(
|
||||
filter(
|
||||
lambda el: not el.is_deleted(),
|
||||
self._data
|
||||
)
|
||||
)
|
||||
|
||||
def get_type_column(self, column):
|
||||
if 0 <= column < 2:
|
||||
return self._types[column]
|
||||
return None
|
||||
|
||||
@property
|
||||
def _default_0(self):
|
||||
return self._types[0](0)
|
||||
|
||||
@property
|
||||
def _default_1(self):
|
||||
return self._types[1](0.0)
|
||||
|
||||
def is_define(self):
|
||||
return self._data is not None
|
||||
|
||||
def new_from_data(self, header, data):
|
||||
new_0 = self._default_0
|
||||
new_1 = self._default_1
|
||||
|
||||
def convert(column, value, default):
|
||||
if value.strip() == "":
|
||||
return default
|
||||
return self._types[column](value.replace(",", "."))
|
||||
|
||||
if len(header) != 0:
|
||||
for i in [0, 1]:
|
||||
for j in range(len(header)):
|
||||
if self._header[i] == header[j] and j < len(data):
|
||||
if i == 0:
|
||||
new_0 = convert(i, data[j], new_0)
|
||||
else:
|
||||
new_1 = convert(i, data[j], new_1)
|
||||
else:
|
||||
if len(data) > 0:
|
||||
new_0 = convert(0, data[0], new_0)
|
||||
if len(data) > 1:
|
||||
new_1 = convert(1, data[1], new_1)
|
||||
|
||||
return Data(new_0, new_1, status=self._status)
|
||||
|
||||
def add(self, index: int):
|
||||
value = Data(self._default_0, self._default_1, status=self._status)
|
||||
self.insert(index, value)
|
||||
return value
|
||||
|
||||
def insert(self, index: int, value):
|
||||
visible_data = self.data
|
||||
if index < len(visible_data):
|
||||
index = self._data.index(visible_data[index])
|
||||
else:
|
||||
index = len(self._data)
|
||||
self._data.insert(index, value)
|
||||
self.modified()
|
||||
|
||||
def set_data_value(self, value, column, data):
|
||||
value[column] = self._types[column](data)
|
||||
self.modified()
|
||||
|
||||
def set_deleted(self, values, deleted):
|
||||
for value in values:
|
||||
if deleted:
|
||||
value.set_as_deleted()
|
||||
else:
|
||||
value.set_as_not_deleted()
|
||||
self.modified()
|
||||
|
||||
def reorder(self, values):
|
||||
values = iter(values)
|
||||
self._data = [
|
||||
value if value.is_deleted() else next(values)
|
||||
for value in self._data
|
||||
]
|
||||
self.modified()
|
||||
|
||||
def delete_i(self, indexes):
|
||||
self._data = list(
|
||||
map(
|
||||
lambda e: e[1],
|
||||
filter(
|
||||
lambda e: e[0] not in indexes,
|
||||
enumerate(self.data)
|
||||
)
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
|
||||
def set_as_deleted_i(self, indexes):
|
||||
for i in indexes:
|
||||
self._data[i].set_as_deleted()
|
||||
self.modified()
|
||||
|
||||
def set_as_not_deleted_i(self, indexes):
|
||||
for i in indexes:
|
||||
self._data[i].set_as_not_deleted()
|
||||
self.modified()
|
||||
|
||||
def delete(self, els):
|
||||
self._data = list(
|
||||
filter(
|
||||
lambda e: e not in els,
|
||||
self.data
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
|
||||
def sort(self, _reverse=False, key=None):
|
||||
if key is None:
|
||||
self._data.sort(reverse=_reverse)
|
||||
else:
|
||||
self._data.sort(reverse=_reverse, key=key)
|
||||
self.modified()
|
||||
|
||||
def get_i(self, index):
|
||||
return self.data[index]
|
||||
|
||||
def get_range(self, _range):
|
||||
lst = []
|
||||
for r in _range:
|
||||
lst.append(r)
|
||||
return lst
|
||||
|
||||
def _set_i_c_v(self, index, column, value):
|
||||
self.set_data_value(self.get_i(index), column, value)
|
||||
|
||||
def set_i_0(self, index: int, value):
|
||||
self._set_i_c_v(index, 0, value)
|
||||
|
||||
def set_i_1(self, index: int, value):
|
||||
self._set_i_c_v(index, 1, value)
|
||||
|
||||
@timer
|
||||
def convert(self, cls):
|
||||
new = cls(name=self.name, status=self._status)
|
||||
new.reach = self.reach
|
||||
new.begin_section = self.begin_section
|
||||
new.end_section = self.end_section
|
||||
|
||||
for i, _ in enumerate(self.data):
|
||||
new.add(i)
|
||||
|
||||
for i in [0, 1]:
|
||||
for j in [0, 1]:
|
||||
if self._header[i] == new.header[j]:
|
||||
for ind, v in self.data:
|
||||
try:
|
||||
new._set_i_c_v(ind, j, v[i])
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
|
||||
self.modified()
|
||||
return new
|
||||
|
||||
def move_up(self, index):
|
||||
if 0 < index < len(self):
|
||||
data = self.data
|
||||
data[index - 1], data[index] = data[index], data[index - 1]
|
||||
self.reorder(data)
|
||||
|
||||
def move_down(self, index):
|
||||
if 0 <= index < len(self) - 1:
|
||||
data = self.data
|
||||
data[index], data[index + 1] = data[index + 1], data[index]
|
||||
self.reorder(data)
|
||||
@@ -0,0 +1,234 @@
|
||||
# WeatherParametersList.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from copy import copy
|
||||
from tools import trace, timer
|
||||
|
||||
from Model.Tools.PamhyrListExt import PamhyrModelList
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
|
||||
from Model.WeatherParameters.WeatherParameters import (
|
||||
WeatherParameters,
|
||||
WeatherParametersDefault,
|
||||
)
|
||||
from Model.WeatherParameters.WeatherParametersTypes import (
|
||||
NotDefined, WeatherParam, AirTemperature, SpecificHumidity,
|
||||
GlobalRadiation, ReferenceWindSpeed, GroundwaterTemperature,
|
||||
GroundwaterFlowRate, Albedo, ShadingCoefficient, CloudCoverFraction
|
||||
)
|
||||
|
||||
|
||||
class WeatherParametersList(PamhyrModelList):
|
||||
_sub_classes = [
|
||||
WeatherParameters,
|
||||
]
|
||||
_default_types = [
|
||||
"AT", "SH", "GR", "RWS", "GT", "GFR", "ALB", "SC", "CCF"
|
||||
]
|
||||
_default_values = {
|
||||
"AT": 20.0,
|
||||
"SH": 0.001,
|
||||
"GR": 10.0,
|
||||
"RWS": 1.0,
|
||||
"GT": 0.0,
|
||||
"GFR": 0.0,
|
||||
"ALB": 0.06,
|
||||
"SC": 0.15,
|
||||
"CCF": 0.5,
|
||||
}
|
||||
|
||||
def __init__(self, status=None):
|
||||
super(WeatherParametersList, self).__init__(status=status)
|
||||
self._default = []
|
||||
self._init_missing_default_values()
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = cls(status=data['status'])
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
new._lst = WeatherParameters._db_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
data['loaded_pid'] = set()
|
||||
new._default = WeatherParametersDefault._db_load(
|
||||
execute, data
|
||||
)
|
||||
new._init_missing_default_values()
|
||||
new._sort_default_values()
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
execute(
|
||||
"DELETE FROM weather_parameters " +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
execute(
|
||||
"DELETE FROM weather_parameters_data " +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
execute(
|
||||
"DELETE FROM weather_parameters_default " +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
for wp in self._lst:
|
||||
wp._db_save(execute, data=data)
|
||||
|
||||
for wp_default in self._default:
|
||||
wp_default._db_save(execute, data=data)
|
||||
|
||||
return True
|
||||
|
||||
def _data_traversal(self,
|
||||
predicate=lambda obj, data: True,
|
||||
modifier=lambda obj, data: None,
|
||||
data={}):
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
for el in self._lst:
|
||||
el._data_traversal(predicate, modifier, data)
|
||||
|
||||
for el in self._default:
|
||||
el._data_traversal(predicate, modifier, data)
|
||||
|
||||
def _init_missing_default_values(self):
|
||||
existing = [wp_default.type for wp_default in self.default]
|
||||
for type in self._default_types:
|
||||
if type not in existing:
|
||||
self._default.append(
|
||||
WeatherParametersDefault(
|
||||
type=type,
|
||||
value=self._default_values[type],
|
||||
status=self._status,
|
||||
)
|
||||
)
|
||||
|
||||
self._sort_default_values()
|
||||
|
||||
def _sort_default_values(self):
|
||||
self._default.sort(
|
||||
key=lambda wp_default: self._default_types.index(wp_default.type)
|
||||
if wp_default.type in self._default_types
|
||||
else len(self._default_types)
|
||||
)
|
||||
|
||||
def new(self, index, type="ND"):
|
||||
if type == "AT":
|
||||
n = AirTemperature(status=self._status)
|
||||
elif type == "SH":
|
||||
n = SpecificHumidity(status=self._status)
|
||||
elif type == "GR":
|
||||
n = GlobalRadiation(status=self._status)
|
||||
elif type == "RWS":
|
||||
n = ReferenceWindSpeed(status=self._status)
|
||||
elif type == "GT":
|
||||
n = GroundwaterTemperature(status=self._status)
|
||||
elif type == "GFR":
|
||||
n = GroundwaterFlowRate(status=self._status)
|
||||
elif type == "ALB":
|
||||
n = Albedo(status=self._status)
|
||||
elif type == "SC":
|
||||
n = ShadingCoefficient(status=self._status)
|
||||
elif type == "CCF":
|
||||
n = CloudCoverFraction(status=self._status)
|
||||
else:
|
||||
n = NotDefined(status=self._status)
|
||||
self._lst.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def split_reach(self, reach, profile, reach1, reach2):
|
||||
profiles = reach.reach.profiles
|
||||
split_index = profiles.index(profile)
|
||||
parts = [
|
||||
(
|
||||
reach1,
|
||||
0,
|
||||
split_index,
|
||||
dict(zip(
|
||||
profiles[:split_index + 1],
|
||||
reach1.reach.profiles
|
||||
))
|
||||
),
|
||||
(
|
||||
reach2,
|
||||
split_index,
|
||||
len(profiles) - 1,
|
||||
dict(zip(
|
||||
profiles[split_index:],
|
||||
reach2.reach.profiles
|
||||
))
|
||||
),
|
||||
]
|
||||
weather_parameters = [
|
||||
weather_parameter
|
||||
for weather_parameter in self.lst
|
||||
if weather_parameter.reach is reach
|
||||
]
|
||||
clones = []
|
||||
|
||||
for weather_parameter in weather_parameters:
|
||||
if (weather_parameter.begin_section not in profiles or
|
||||
weather_parameter.end_section not in profiles):
|
||||
continue
|
||||
|
||||
begin = profiles.index(weather_parameter.begin_section)
|
||||
end = profiles.index(weather_parameter.end_section)
|
||||
lower, upper = sorted((begin, end))
|
||||
reverse = begin > end
|
||||
|
||||
for new_reach, part_lower, part_upper, sections in parts:
|
||||
clipped_lower = max(lower, part_lower)
|
||||
clipped_upper = min(upper, part_upper)
|
||||
if clipped_lower >= clipped_upper:
|
||||
continue
|
||||
|
||||
begin_index = clipped_upper if reverse else clipped_lower
|
||||
end_index = clipped_lower if reverse else clipped_upper
|
||||
clones.append(weather_parameter.cloned_for(
|
||||
new_reach,
|
||||
sections[profiles[begin_index]],
|
||||
sections[profiles[end_index]]
|
||||
))
|
||||
|
||||
if clones:
|
||||
self._lst.extend(clones)
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def Weather_Parameters_List(self):
|
||||
return self.lst
|
||||
|
||||
@property
|
||||
def default(self):
|
||||
return self._default.copy()
|
||||
|
||||
def default_for_type(self, type):
|
||||
for wp_default in self.default:
|
||||
if wp_default.type == type:
|
||||
return wp_default
|
||||
return None
|
||||
@@ -0,0 +1,171 @@
|
||||
# LateralContributionTypes.py -- Pamhyr
|
||||
# Copyright (C) 2023-2025 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
|
||||
from Model.WeatherParameters.WeatherParameters import WeatherParameters
|
||||
|
||||
|
||||
class NotDefined(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(NotDefined, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "ND"
|
||||
self._header = ["x", "y"]
|
||||
|
||||
@property
|
||||
def _default_0(self):
|
||||
return 0.0
|
||||
|
||||
|
||||
class WeatherParam(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(WeatherParam, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "WP"
|
||||
self._header = ["time", "value"]
|
||||
self._types = [WeatherParam.time_convert, float]
|
||||
|
||||
@classmethod
|
||||
def compatibility(cls):
|
||||
return ["liquid"]
|
||||
|
||||
|
||||
class AirTemperature(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(AirTemperature, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "AT"
|
||||
self._header = ["time", "temperature"]
|
||||
self._types = [AirTemperature.time_convert, float]
|
||||
|
||||
|
||||
class SpecificHumidity(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(SpecificHumidity, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "SH"
|
||||
self._header = ["time", "humidity"]
|
||||
self._types = [SpecificHumidity.time_convert, float]
|
||||
|
||||
|
||||
class GlobalRadiation(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(GlobalRadiation, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "GR"
|
||||
self._header = ["time", "radiation"]
|
||||
self._types = [GlobalRadiation.time_convert, float]
|
||||
|
||||
|
||||
class ReferenceWindSpeed(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(ReferenceWindSpeed, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "RWS"
|
||||
self._header = ["time", "wind speed"]
|
||||
self._types = [ReferenceWindSpeed.time_convert, float]
|
||||
|
||||
|
||||
class GroundwaterTemperature(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(GroundwaterTemperature, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "GT"
|
||||
self._header = ["time", "temperature"]
|
||||
self._types = [GroundwaterTemperature.time_convert, float]
|
||||
|
||||
|
||||
class GroundwaterFlowRate(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(GroundwaterFlowRate, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "GFR"
|
||||
self._header = ["time", "discharge"]
|
||||
self._types = [GroundwaterFlowRate.time_convert, float]
|
||||
|
||||
|
||||
class Albedo(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(Albedo, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "ALB"
|
||||
self._header = ["time", "albedo"]
|
||||
self._types = [Albedo.time_convert, float]
|
||||
|
||||
|
||||
class ShadingCoefficient(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(ShadingCoefficient, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "SC"
|
||||
self._header = ["time", "shading coefficient"]
|
||||
self._types = [ShadingCoefficient.time_convert, float]
|
||||
|
||||
|
||||
class CloudCoverFraction(WeatherParameters):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(CloudCoverFraction, self).__init__(
|
||||
id=id, name=name, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._type = "CCF"
|
||||
self._header = ["time", "cloud cover fraction"]
|
||||
self._types = [CloudCoverFraction.time_convert, float]
|
||||
@@ -1,5 +1,5 @@
|
||||
# __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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
+114
-1
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -23,6 +23,8 @@ import tempfile
|
||||
from Model.Status import StudyStatus
|
||||
from Model.Study import Study
|
||||
from Model.River import River
|
||||
from Model.LateralContribution.LateralContributionTypes import LateralContrib
|
||||
from Model.HydraulicStructures.Basic.Types import DischargeWeir
|
||||
|
||||
|
||||
class StudyTestCase(unittest.TestCase):
|
||||
@@ -62,6 +64,31 @@ class StudyTestCase(unittest.TestCase):
|
||||
study = Study.new("foo", "bar")
|
||||
self.assertNotEqual(study.river, None)
|
||||
|
||||
def test_save_open_study_weather_parameters_default(self):
|
||||
study = Study.new("foo", "bar")
|
||||
defaults = study.river.weather_parameters.default
|
||||
|
||||
self.assertEqual(len(defaults), 9)
|
||||
self.assertEqual(
|
||||
[default.value for default in defaults],
|
||||
[20.0, 0.001, 10.0, 1.0, 0.0, 0.0, 0.06, 0.15, 0.5]
|
||||
)
|
||||
defaults[0].value = 12.5
|
||||
|
||||
dir = tempfile.mkdtemp()
|
||||
f = os.path.join(dir, "foo.pamhyr")
|
||||
|
||||
study.filename = f
|
||||
study.save()
|
||||
study.close()
|
||||
|
||||
study = Study.open(f)
|
||||
defaults = study.river.weather_parameters.default
|
||||
|
||||
self.assertEqual(len(defaults), 9)
|
||||
self.assertEqual(defaults[0].type, "AT")
|
||||
self.assertEqual(defaults[0].value, 12.5)
|
||||
|
||||
|
||||
class StudyScenarioTestCase(unittest.TestCase):
|
||||
def test_create_study(self):
|
||||
@@ -262,3 +289,89 @@ class RiverTestCase(unittest.TestCase):
|
||||
edges = river.edges()
|
||||
self.assertEqual(edges[0], e0)
|
||||
self.assertEqual(edges[1], e1)
|
||||
|
||||
def test_split_reach_splits_initial_conditions(self):
|
||||
status = StudyStatus()
|
||||
river = River(status=status)
|
||||
node1 = river.add_node()
|
||||
node2 = river.add_node(x=40.0)
|
||||
reach = river.add_edge(node1, node2)
|
||||
|
||||
profiles = []
|
||||
for index in range(5):
|
||||
profile = reach.reach.insert(index)
|
||||
profile.rk = index * 10.0
|
||||
profile.insert(0)
|
||||
profiles.append(profile)
|
||||
|
||||
initial_conditions = river.initial_conditions.get(reach)
|
||||
for index, profile in enumerate(profiles):
|
||||
data = initial_conditions.new_from_data(
|
||||
profile.rk,
|
||||
discharge=100.0 + index,
|
||||
elevation=10.0 + index,
|
||||
)
|
||||
initial_conditions.insert(index, data)
|
||||
|
||||
reach1, reach2 = river._split_reach(reach, profiles[2])
|
||||
conditions1 = river.initial_conditions.get(reach1).data
|
||||
conditions2 = river.initial_conditions.get(reach2).data
|
||||
|
||||
self.assertEqual(
|
||||
[data["discharge"] for data in conditions1],
|
||||
[100.0, 101.0, 102.0]
|
||||
)
|
||||
self.assertEqual(
|
||||
[data["discharge"] for data in conditions2],
|
||||
[102.0, 103.0, 104.0]
|
||||
)
|
||||
self.assertEqual(
|
||||
[data["section"] for data in conditions1],
|
||||
reach1.reach.profiles
|
||||
)
|
||||
self.assertEqual(
|
||||
[data["section"] for data in conditions2],
|
||||
reach2.reach.profiles
|
||||
)
|
||||
self.assertTrue(all(
|
||||
data._reach is reach1 for data in conditions1
|
||||
))
|
||||
self.assertTrue(all(
|
||||
data._reach is reach2 for data in conditions2
|
||||
))
|
||||
|
||||
def test_split_reach_keeps_partial_initial_conditions_in_scope(self):
|
||||
status = StudyStatus()
|
||||
river = River(status=status)
|
||||
node1 = river.add_node()
|
||||
node2 = river.add_node(x=40.0)
|
||||
reach = river.add_edge(node1, node2)
|
||||
|
||||
profiles = []
|
||||
for index in range(5):
|
||||
profile = reach.reach.insert(index)
|
||||
profile.rk = index * 10.0
|
||||
profile.insert(0)
|
||||
profiles.append(profile)
|
||||
|
||||
initial_conditions = river.initial_conditions.get(reach)
|
||||
for index in (1, 3):
|
||||
data = initial_conditions.new_from_data(
|
||||
profiles[index].rk,
|
||||
discharge=100.0 + index,
|
||||
elevation=10.0 + index,
|
||||
)
|
||||
initial_conditions.insert(len(initial_conditions.data), data)
|
||||
|
||||
reach1, reach2 = river._split_reach(reach, profiles[2])
|
||||
|
||||
self.assertEqual(
|
||||
[data["discharge"]
|
||||
for data in river.initial_conditions.get(reach1).data],
|
||||
[101.0]
|
||||
)
|
||||
self.assertEqual(
|
||||
[data["discharge"]
|
||||
for data in river.initial_conditions.get(reach2).data],
|
||||
[103.0]
|
||||
)
|
||||
@@ -55,7 +55,6 @@ class Modules(IterableFlag):
|
||||
RESERVOIR = auto()
|
||||
SEDIMENT_LAYER = auto()
|
||||
ADDITIONAL_FILES = auto()
|
||||
OUTPUT_RK = auto()
|
||||
GEOTIFF = auto()
|
||||
|
||||
# Results
|
||||
@@ -81,7 +80,6 @@ class Modules(IterableFlag):
|
||||
cls.ADDITIONAL_FILES,
|
||||
cls.RESULTS,
|
||||
cls.WINDOW_LIST,
|
||||
cls.OUTPUT_RK,
|
||||
cls.GEOTIFF
|
||||
]
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
+9
-3
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -25,6 +25,7 @@ from PyQt5.QtCore import QProcess
|
||||
|
||||
from Scripts.AScript import AScript
|
||||
from Model.Study import Study
|
||||
from View.RunSolver.Translate import RunSolverTranslate
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
@@ -75,7 +76,8 @@ class ScriptRun(AScript):
|
||||
os.path.dirname(study.filename),
|
||||
"_PAMHYR_",
|
||||
study.name.replace(" ", "_"),
|
||||
solver.name.replace(" ", "_")
|
||||
solver.name.replace(" ", "_"),
|
||||
study.status.scenario.workdir(),
|
||||
)
|
||||
os.makedirs(workdir, exist_ok=True)
|
||||
logger.info(f"Set working dir to {workdir}")
|
||||
@@ -88,12 +90,16 @@ class ScriptRun(AScript):
|
||||
|
||||
# Export and Run
|
||||
logger.info(f"~Export~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
|
||||
solver.export(study, workdir, qlog=self._q)
|
||||
ok = solver.export(study, workdir, qlog=self._q)
|
||||
|
||||
while self._q.qsize() != 0:
|
||||
s = self._q.get()
|
||||
logger.info(s)
|
||||
|
||||
if not ok:
|
||||
logger.warning(RunSolverTranslate()["export_failed"])
|
||||
return
|
||||
|
||||
if command == "run":
|
||||
logger.info(f"~Run~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
|
||||
solver.run(
|
||||
|
||||
@@ -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
|
||||
|
||||
import sys
|
||||
@@ -336,6 +353,3 @@ if __name__ == "__main__":
|
||||
print( 'Number of arguments:', len(sys.argv), 'arguments.')
|
||||
print( 'Argument List:', str(sys.argv))
|
||||
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
|
||||
|
||||
import sys
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -79,7 +79,7 @@ class AbstractSolver(object):
|
||||
def default_parameters(cls):
|
||||
lst = [
|
||||
("all_init_time", "000:00:00:00"),
|
||||
("all_final_time", "999:99:00:00"),
|
||||
("all_final_time", "10:00:00:00"),
|
||||
("all_timestep", "300.0"),
|
||||
]
|
||||
|
||||
|
||||
Loaded 100 of 364 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user