mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Compare commits
52
Commits
terraz_dev
..
v1.2.5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fecd29666 | ||
|
|
71e1324a0f | ||
|
|
07cae542b0 | ||
|
|
b693f67b99 | ||
|
|
18a3d51d75 | ||
|
|
118a39bd5c | ||
|
|
2009e8223b | ||
|
|
bdaa38ea5c | ||
|
|
713732b1dd | ||
|
|
f053539cdd | ||
|
|
fc6916bb3e | ||
|
|
97c26cb4fb | ||
|
|
10c98bb96e | ||
|
|
7c2d9891d0 | ||
|
|
3c3ac1f1df | ||
|
|
80af278a0f | ||
|
|
f254eaee25 | ||
|
|
5adb0bdee5 | ||
|
|
64c99d46d4 | ||
|
|
0f0defb36f | ||
|
|
1e1ee67d4b | ||
|
|
5bc514c565 | ||
|
|
1da3461dfe | ||
|
|
dd5eecb1e2 | ||
|
|
d93917b081 | ||
|
|
a31e2127e7 | ||
|
|
a29df8f904 | ||
|
|
97ebf9324a | ||
|
|
0112ad63d9 | ||
|
|
bcbb440ad4 | ||
|
|
7ef3184699 | ||
|
|
5f6c823301 | ||
|
|
bc4557e21f | ||
|
|
f6e08f203c | ||
|
|
5dcbc6b4e1 | ||
|
|
ebe906fce0 | ||
|
|
911a2bbbff | ||
|
|
706a900c8e | ||
|
|
da03f39425 | ||
|
|
7d42c164fc | ||
|
|
1b2f98494b | ||
|
|
e7b63fe270 | ||
|
|
80ae4c36ad | ||
|
|
41cffd13e0 | ||
|
|
9270dd0ff1 | ||
|
|
ba8a50e0b9 | ||
|
|
fce034419d | ||
|
|
31fe765e51 | ||
|
|
b582e133a1 | ||
|
|
7c4c772f43 | ||
|
|
5fc4e3903a | ||
|
|
c07a863018 |
No files matched your search
+44
-13
@@ -31,6 +31,7 @@ stages:
|
||||
variables:
|
||||
MAGE_8_VERSION: "permalink/latest"
|
||||
ADISTS_VERSION: "permalink/latest"
|
||||
RUBAR_VERSION: "permalink/latest"
|
||||
|
||||
dl-mage8-doc:
|
||||
stage: downloads
|
||||
@@ -41,7 +42,7 @@ dl-mage8-doc:
|
||||
script:
|
||||
- mkdir -p doc
|
||||
- cd doc
|
||||
- curl -L -o mage8.pdf https://gitlab.irstea.fr/jean-baptiste.faure/mage/-/releases/$MAGE_8_VERSION/downloads/documents/Mage-8_Documentation.pdf
|
||||
- curl -L -o mage8.pdf https://forge.inrae.fr/river-hydraulics/mage/-/releases/$MAGE_8_VERSION/downloads/documents/Mage-8_Documentation.pdf
|
||||
artifacts:
|
||||
paths:
|
||||
- doc/mage8.pdf
|
||||
@@ -53,17 +54,13 @@ dl-mage8-linux:
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == 'ci-test' || $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
||||
script:
|
||||
- curl -L -o mage8.tgz https://gitlab.irstea.fr/jean-baptiste.faure/mage/-/releases/$MAGE_8_VERSION/downloads/packages/mage_linux.tgz
|
||||
- curl -L -o mage8.tgz https://forge.inrae.fr/river-hydraulics/mage/-/releases/$MAGE_8_VERSION/downloads/packages/mage_linux.tgz
|
||||
- mkdir -p mage8-linux
|
||||
- cd mage8-linux
|
||||
- tar xvf ../mage8.tgz
|
||||
artifacts:
|
||||
paths:
|
||||
- mage8-linux/mage
|
||||
- mage8-linux/mage_as7
|
||||
- mage8-linux/mage_extraire
|
||||
- mage8-linux/mailleurTT
|
||||
- mage8-linux/libbief.so
|
||||
|
||||
dl-mage8-windows:
|
||||
stage: downloads
|
||||
@@ -72,17 +69,13 @@ dl-mage8-windows:
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == 'ci-test' || $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
||||
script:
|
||||
- curl -L -o mage8.tgz https://gitlab.irstea.fr/jean-baptiste.faure/mage/-/releases/$MAGE_8_VERSION/downloads/packages/mage_windows.tgz
|
||||
- curl -L -o mage8.tgz https://forge.inrae.fr/river-hydraulics/mage/-/releases/$MAGE_8_VERSION/downloads/packages/mage_windows.tgz
|
||||
- mkdir -p mage8-windows
|
||||
- cd mage8-windows
|
||||
- tar xvf ../mage8.tgz
|
||||
artifacts:
|
||||
paths:
|
||||
- mage8-windows/mage.exe
|
||||
- mage8-windows/mage_as7.exe
|
||||
- mage8-windows/mage_extraire.exe
|
||||
- mage8-windows/mailleurTT.exe
|
||||
- mage8-windows/libbief.dll
|
||||
|
||||
dl-adists-linux:
|
||||
stage: downloads
|
||||
@@ -93,7 +86,7 @@ dl-adists-linux:
|
||||
script:
|
||||
- mkdir -p adists-linux
|
||||
- cd adists-linux
|
||||
- curl -L -o adists https://gitlab.irstea.fr/jean-baptiste.faure/adists/-/releases/$ADISTS_VERSION/downloads/executables/adists
|
||||
- curl -L -o adists https://forge.inrae.fr/river-hydraulics/adists/-/releases/$ADISTS_VERSION/downloads/executables/adists
|
||||
artifacts:
|
||||
paths:
|
||||
- adists-linux/adists
|
||||
@@ -107,11 +100,42 @@ dl-adists-windows:
|
||||
script:
|
||||
- mkdir -p adists-windows
|
||||
- cd adists-windows
|
||||
- curl -L -o adists.exe https://gitlab.irstea.fr/jean-baptiste.faure/adists/-/releases/$ADISTS_VERSION/downloads/executables/adists_win64.exe
|
||||
- curl -L -o adists.exe https://forge.inrae.fr/river-hydraulics/adists/-/releases/$ADISTS_VERSION/downloads/executables/adists_win64.exe
|
||||
artifacts:
|
||||
paths:
|
||||
- adists-windows/adists.exe
|
||||
|
||||
dl-rubar-linux:
|
||||
stage: downloads
|
||||
tags:
|
||||
- linux
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == 'ci-test' || $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
||||
script:
|
||||
- mkdir -p rubar-linux
|
||||
- cd rubar-linux
|
||||
- curl -L -o rubar.tgz https://forge.inrae.fr/river-hydraulics/rubarbe/-/releases/$RUBAR_VERSION/downloads/packages/rubar_linux.tgz
|
||||
- tar xf rubar.tgz
|
||||
artifacts:
|
||||
paths:
|
||||
- rubar-linux/rubarbe
|
||||
|
||||
dl-rubar-windows:
|
||||
stage: downloads
|
||||
tags:
|
||||
- linux
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == 'ci-test' || $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
||||
script:
|
||||
- mkdir -p rubar-windows
|
||||
- cd rubar-windows
|
||||
- curl -L -o rubar.tgz https://forge.inrae.fr/river-hydraulics/rubarbe/-/releases/$RUBAR_VERSION/downloads/packages/rubar_windows.tgz
|
||||
- tar xf rubar.tgz
|
||||
|
||||
artifacts:
|
||||
paths:
|
||||
- rubar-windows/rubarbe.exe
|
||||
|
||||
#############
|
||||
# CONFIGURE #
|
||||
#############
|
||||
@@ -274,6 +298,8 @@ build-linux:
|
||||
needs:
|
||||
- job: dl-adists-linux
|
||||
artifacts: true
|
||||
- job: dl-rubar-linux
|
||||
artifacts: true
|
||||
- job: dl-mage8-linux
|
||||
artifacts: true
|
||||
- job: dl-mage8-doc
|
||||
@@ -315,6 +341,9 @@ build-linux:
|
||||
# Copy adists
|
||||
- mkdir -p pamhyr/adists
|
||||
- cp -v ../adists-linux/* pamhyr/adists/
|
||||
# Copy rubar
|
||||
- mkdir -p pamhyr/rubar
|
||||
- cp -v ../rubar-linux/* pamhyr/rubar/
|
||||
# Copy Pamhyr
|
||||
- cp -r dist/pamhyr/* pamhyr/
|
||||
# Pamhyr script to force x11
|
||||
@@ -380,6 +409,8 @@ build-windows:
|
||||
artifacts: true
|
||||
- job: dl-adists-windows
|
||||
artifacts: true
|
||||
- job: dl-rubar-windows
|
||||
artifacts: true
|
||||
- job: dl-mage8-doc
|
||||
artifacts: true
|
||||
- job: set-version
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Pamhyr is a free and open source graphical user interface for 1D hydro-sedimentary
|
||||
modelling of rivers.
|
||||
|
||||

|
||||

|
||||
|
||||
## Features
|
||||
|
||||
@@ -20,9 +20,9 @@ modelling of rivers.
|
||||
+ Run Mage 8 on a study and visualize results
|
||||
|
||||
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
|
||||
@@ -30,11 +30,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)
|
||||
Binary file not shown.
Binary file not shown.
@@ -46,6 +46,10 @@ copy /y ..\mage8-windows\mage_extraire.exe pamhyr\mage8\
|
||||
copy /y ..\mage8-windows\mailleurTT.exe pamhyr\mage8\
|
||||
copy /y ..\mage8-windows\libbief.dll pamhyr\mage8\
|
||||
|
||||
rem rubar
|
||||
mkdir pamhyr\rubar
|
||||
copy /y ..\rubar-windows\rubarbe.exe pamhyr\rubar\
|
||||
|
||||
rem adists
|
||||
mkdir pamhyr\adists
|
||||
copy /y ..\adists-windows\adists.exe pamhyr\adists\
|
||||
|
||||
@@ -0,0 +1,317 @@
|
||||
# Internal.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 numpy import sign
|
||||
from copy import deepcopy
|
||||
|
||||
from tools import logger_color_red, logger_color_reset, logger_exception
|
||||
from Meshing.AMeshingTool import AMeshingTool
|
||||
|
||||
from Model.Geometry.ProfileXYZ import ProfileXYZ
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class InternalMeshing(AMeshingTool):
|
||||
def __init__(self):
|
||||
super(InternalMeshing, self).__init__()
|
||||
|
||||
###########
|
||||
# Meshing #
|
||||
###########
|
||||
|
||||
def meshing(self, reach,
|
||||
step: float = 50,
|
||||
limites=[-1, -1],
|
||||
linear: bool = True):
|
||||
if reach is None or len(reach.profiles) == 0:
|
||||
return reach
|
||||
|
||||
if limites[0] > limites[1]:
|
||||
lim = limites[1]
|
||||
limites[1] = limites[0]
|
||||
limites[0] = lim
|
||||
elif limites[0] == limites[1]:
|
||||
return reach
|
||||
|
||||
self.st_to_m(reach, limites)
|
||||
self.interpolate_transversal_step(reach,
|
||||
limites,
|
||||
step)
|
||||
self.purge_aligned_points(reach)
|
||||
|
||||
return reach
|
||||
|
||||
def st_to_m(self, reach, limites):
|
||||
|
||||
gl = reach.compute_guidelines()
|
||||
profiles = reach.profiles[limites[0]:limites[1]+1]
|
||||
|
||||
# we make sure that the lines are in the left-to-right order
|
||||
guide_list = [
|
||||
x.name
|
||||
for x in profiles[0].named_points()
|
||||
if x.name in gl[0]
|
||||
]
|
||||
|
||||
guide_list = ["un"] + guide_list + ["np"]
|
||||
max_values = [0] * (len(guide_list) - 1)
|
||||
max_values_index = [0] * (len(guide_list) - 1)
|
||||
# we work between each couple of guidelines
|
||||
for j, p in enumerate(profiles):
|
||||
for i in range(len(guide_list) - 1):
|
||||
index1 = p.named_point_index(guide_list[i])
|
||||
index2 = p.named_point_index(guide_list[i+1])
|
||||
if index2 - index1 > max_values[i]:
|
||||
max_values[i] = index2 - index1
|
||||
max_values_index[i] = j
|
||||
|
||||
for i in range(len(max_values)):
|
||||
for isect in range(max_values_index[i], len(profiles)-1):
|
||||
self.compl_sect(profiles[isect],
|
||||
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])
|
||||
|
||||
def interpolate_transversal_step(self,
|
||||
reach,
|
||||
limites,
|
||||
step):
|
||||
# calcul number of intermediate profiles
|
||||
np = []
|
||||
for i in range(limites[0], limites[1]):
|
||||
np.append(int(abs(reach.profiles[i+1].rk -
|
||||
reach.profiles[i].rk) / step) - 1)
|
||||
if np[-1] < 0:
|
||||
np[-1] = 0
|
||||
|
||||
d = [] # ratios
|
||||
p = [] # new profiles
|
||||
ptr = int(limites[0])
|
||||
for i in range(limites[1] - limites[0]):
|
||||
d = 1.0/float(np[i]+1)
|
||||
ptr0 = ptr
|
||||
for j in range(np[i]):
|
||||
p = ProfileXYZ(reach=reach, status=reach._status)
|
||||
# RATIO entre les deux sections initiales
|
||||
dj = float(j+1)*d
|
||||
ptr += 1 # next profile, original
|
||||
for k in range(len(reach.profiles[ptr0].points)):
|
||||
p.add()
|
||||
p.points[k].name = reach.profiles[ptr0].points[k].name
|
||||
p.points[k].x = reach.profiles[ptr0].points[k].x + \
|
||||
dj*(reach.profiles[ptr].points[k].x -
|
||||
reach.profiles[ptr0].points[k].x)
|
||||
p.points[k].y = reach.profiles[ptr0].points[k].y + \
|
||||
dj*(reach.profiles[ptr].points[k].y -
|
||||
reach.profiles[ptr0].points[k].y)
|
||||
p.points[k].z = reach.profiles[ptr0].points[k].z + \
|
||||
dj*(reach.profiles[ptr].points[k].z -
|
||||
reach.profiles[ptr0].points[k].z)
|
||||
p.rk = reach.profiles[ptr0].rk + \
|
||||
dj*(reach.profiles[ptr].rk -
|
||||
reach.profiles[ptr0].rk)
|
||||
p.name = f'interpol{p.rk}'
|
||||
reach.insert_profile(ptr, p)
|
||||
ptr += 1 # next profile, original
|
||||
|
||||
def compl_sect(self, sect1, sect2, tag1, tag2):
|
||||
# sect1: reference section
|
||||
# sect2: section to complete
|
||||
# start1 and 2: indices of the first point of the bed to complete
|
||||
# end = start + len
|
||||
# len1 and 2: number of intervals
|
||||
# len1: target len
|
||||
|
||||
start1 = sect1.named_point_index(tag1)
|
||||
start2 = sect2.named_point_index(tag1)
|
||||
|
||||
end1 = sect1.named_point_index(tag2)
|
||||
end2 = sect2.named_point_index(tag2)
|
||||
|
||||
len1 = end1 - start1
|
||||
len2 = end2 - start2
|
||||
|
||||
if len1 < len2:
|
||||
self.compl_sect(sect2, sect1, start2, start1,
|
||||
len2, len1, tag1, tag2)
|
||||
return
|
||||
elif len1 == len2:
|
||||
return
|
||||
|
||||
ltot1 = 0.0
|
||||
ltot2 = 0.0
|
||||
alpha = []
|
||||
beta = []
|
||||
# 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)
|
||||
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]
|
||||
if len2 < 1 or ltot2 < 0.0001:
|
||||
# unique point (copy len1 times)
|
||||
# we are at an edge of the profile
|
||||
for i in range(len1-len2):
|
||||
p = sect2.point(start2).copy()
|
||||
sect2.insert_point(start2, p)
|
||||
len2 += 1
|
||||
elif ltot1 < 0.0001:
|
||||
sect2.add_npoints(len1-len2)
|
||||
len2 = len1
|
||||
else: # regular case
|
||||
# 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
|
||||
|
||||
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]
|
||||
|
||||
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 tag2 != "np":
|
||||
sect2.point(start2+len2).name = tag2
|
||||
sect2.modified()
|
||||
|
||||
def update_rk(self, reach,
|
||||
step: float = 50,
|
||||
limites=[-1, -1],
|
||||
origin=0,
|
||||
directrices=['un', 'np'],
|
||||
lplan: bool = False,
|
||||
lm: int = 3,
|
||||
linear: bool = False,
|
||||
origin_value=0.0,
|
||||
orientation=0):
|
||||
if reach is None or len(reach.profiles) == 0:
|
||||
return reach
|
||||
|
||||
nprof = reach.number_profiles
|
||||
if origin >= nprof or origin < 0:
|
||||
logger.warning(
|
||||
f"Origin outside reach"
|
||||
)
|
||||
return reach
|
||||
|
||||
# orientation is the orintation of the bief:
|
||||
# 1: up -> downstream
|
||||
# 2: down -> upstream
|
||||
# else: keep current orientation
|
||||
if orientation == 1:
|
||||
sgn = 1.0
|
||||
elif orientation == 2:
|
||||
sgn = -1.0
|
||||
else:
|
||||
sgn = sign(reach.profiles[-1].rk - reach.profiles[0].rk)
|
||||
if abs(sgn) < 0.5:
|
||||
sgn = 1.0
|
||||
|
||||
reach.profiles[origin].rk = origin_value
|
||||
|
||||
if origin < nprof - 1:
|
||||
for i in range(origin+1, nprof):
|
||||
# 2D
|
||||
d1 = reach.profiles[i-1].named_point(
|
||||
directrices[0]
|
||||
).dist_2d(reach.profiles[i].named_point(directrices[0]))
|
||||
d2 = reach.profiles[i-1].named_point(
|
||||
directrices[1]
|
||||
).dist_2d(reach.profiles[i].named_point(directrices[1]))
|
||||
reach.profiles[i].rk = reach.profiles[i-1].rk \
|
||||
+ (sgn * (d1 + d2) / 2)
|
||||
if origin > 0:
|
||||
for i in reversed(range(0, origin)):
|
||||
# 2D
|
||||
d1 = reach.profiles[i+1].named_point(
|
||||
directrices[0]
|
||||
).dist_2d(reach.profiles[i].named_point(directrices[0]))
|
||||
d2 = reach.profiles[i+1].named_point(
|
||||
directrices[1]
|
||||
).dist_2d(reach.profiles[i].named_point(directrices[1]))
|
||||
reach.profiles[i].rk = reach.profiles[i+1].rk \
|
||||
- (sgn * (d1 + d2) / 2)
|
||||
|
||||
def purge_aligned_points(self, reach):
|
||||
for p in reach.profiles:
|
||||
p.purge_aligned_points()
|
||||
@@ -19,6 +19,7 @@
|
||||
import os
|
||||
import logging
|
||||
import tempfile
|
||||
from numpy import sign
|
||||
|
||||
from ctypes import (
|
||||
cdll,
|
||||
|
||||
@@ -45,7 +45,7 @@ class AddFile(SQLSubModel):
|
||||
self._path = path
|
||||
self._text = text
|
||||
|
||||
AddFile._id_cnt = max(id, AddFile._id_cnt+1)
|
||||
AddFile._id_cnt = max(self.id + 1, AddFile._id_cnt + 1)
|
||||
|
||||
def __getitem__(self, key):
|
||||
value = None
|
||||
|
||||
@@ -53,7 +53,8 @@ class BoundaryCondition(SQLSubModel):
|
||||
self._header = []
|
||||
self._types = [float, float]
|
||||
|
||||
BoundaryCondition._id_cnt = max(BoundaryCondition._id_cnt + 1, self.id)
|
||||
BoundaryCondition._id_cnt = max(BoundaryCondition._id_cnt + 1,
|
||||
self.id + 1)
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
|
||||
@@ -54,7 +54,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
self._types = [self.time_convert, float]
|
||||
|
||||
BoundaryConditionAdisTS._id_cnt = max(
|
||||
BoundaryConditionAdisTS._id_cnt + 1, self.id)
|
||||
BoundaryConditionAdisTS._id_cnt + 1, self.id + 1)
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
|
||||
@@ -53,7 +53,7 @@ class D90AdisTS(SQLSubModel):
|
||||
|
||||
D90AdisTS._id_cnt = max(
|
||||
D90AdisTS._id_cnt + 1,
|
||||
self.id
|
||||
self.id + 1
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -49,7 +49,7 @@ class D90AdisTSSpec(SQLSubModel):
|
||||
self._d90 = None
|
||||
self._enabled = True
|
||||
|
||||
D90AdisTSSpec._id_cnt = max(D90AdisTSSpec._id_cnt + 1, self.id)
|
||||
D90AdisTSSpec._id_cnt = max(D90AdisTSSpec._id_cnt + 1, self.id + 1)
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
|
||||
@@ -57,7 +57,7 @@ class DIFAdisTS(SQLSubModel):
|
||||
|
||||
DIFAdisTS._id_cnt = max(
|
||||
DIFAdisTS._id_cnt + 1,
|
||||
self.id
|
||||
self.id + 1
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -51,7 +51,7 @@ class DIFAdisTSSpec(SQLSubModel):
|
||||
self._c = None
|
||||
self._enabled = True
|
||||
|
||||
DIFAdisTSSpec._id_cnt = max(DIFAdisTSSpec._id_cnt + 1, self.id)
|
||||
DIFAdisTSSpec._id_cnt = max(DIFAdisTSSpec._id_cnt + 1, self.id + 1)
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
|
||||
@@ -41,7 +41,7 @@ class Friction(SQLSubModel):
|
||||
else:
|
||||
self.id = id
|
||||
|
||||
Friction._id_cnt = max(self.id, Friction._id_cnt+1)
|
||||
Friction._id_cnt = max(self.id + 1, Friction._id_cnt + 1)
|
||||
|
||||
self._name = name
|
||||
self._edge = None
|
||||
|
||||
@@ -228,3 +228,25 @@ class PointXYZ(Point, SQLSubModel):
|
||||
c = PointXYZ.distance(p3, p1)
|
||||
s = (a + b + c) / 2
|
||||
return (s*(s-a) * (s-b)*(s-c)) ** 0.5
|
||||
|
||||
def dist_from_seg(self, p1, p2):
|
||||
a2 = pow(PointXYZ.distance(self, p1), 2)
|
||||
b2 = pow(PointXYZ.distance(self, p2), 2)
|
||||
c2 = pow(PointXYZ.distance(p1, p2), 2)
|
||||
if c2 < 0.00000001:
|
||||
# si les deux points sont confondus
|
||||
d = 0.0
|
||||
else:
|
||||
d = np.sqrt(abs(a2 - pow((c2 - b2 + a2) / (2*np.sqrt(c2)), 2)))
|
||||
|
||||
return d
|
||||
|
||||
def copy(self):
|
||||
p = PointXYZ(self.x,
|
||||
self.y,
|
||||
self.z,
|
||||
self.name,
|
||||
self._profile,
|
||||
self._status)
|
||||
p.sl = self.sl
|
||||
return p
|
||||
@@ -44,7 +44,7 @@ class Profile(object):
|
||||
else:
|
||||
self.id = id
|
||||
|
||||
Profile._id_cnt = max(self.id, Profile._id_cnt+1)
|
||||
Profile._id_cnt = max(self.id + 1, Profile._id_cnt + 1)
|
||||
|
||||
self._num = int(num)
|
||||
self._code1 = int(code1)
|
||||
@@ -88,6 +88,25 @@ class Profile(object):
|
||||
def point(self, index):
|
||||
return self.points[index]
|
||||
|
||||
def named_point(self, name):
|
||||
if name == "un":
|
||||
return self.points[0]
|
||||
elif name == "np":
|
||||
return self.points[-1]
|
||||
else:
|
||||
return next((p for p in self.points if p.name == name), None)
|
||||
|
||||
def named_point_index(self, name):
|
||||
if name == "un":
|
||||
return 0
|
||||
elif name == "np":
|
||||
return len(self.points) - 1
|
||||
else:
|
||||
return next(
|
||||
(p for p in enumerate(self.points) if p[1].name == name),
|
||||
None
|
||||
)[0]
|
||||
|
||||
@property
|
||||
def reach(self):
|
||||
return self._reach
|
||||
@@ -206,7 +225,7 @@ class Profile(object):
|
||||
"""Insert point at index.
|
||||
|
||||
Args:
|
||||
index: The index of new profile.
|
||||
index: The index of new point.
|
||||
point: The point.
|
||||
|
||||
Returns:
|
||||
|
||||
@@ -882,3 +882,44 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
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):
|
||||
disti = 0.0
|
||||
i = 1
|
||||
for j in range(len(self.points)-1):
|
||||
distj = self.point(j).dist(self.point(j+1))
|
||||
if distj > disti:
|
||||
disti = distj
|
||||
i = j
|
||||
self.insert_point(i, self.point(i).copy())
|
||||
self.point(i+1).name = ''
|
||||
self.point(i+1).x = 0.5 * self.point(i).x + 0.5 * self.point(i+2).x
|
||||
self.point(i+1).y = 0.5 * self.point(i).y + 0.5 * self.point(i+2).y
|
||||
self.point(i+1).z = 0.5 * self.point(i).z + 0.5 * self.point(i+2).z
|
||||
|
||||
def copy(self):
|
||||
p = ProfileXYZ(name=self.name,
|
||||
rk=self.rk,
|
||||
reach=self.reach,
|
||||
nb_point=0,
|
||||
code1=0, code2=0,
|
||||
status=self.reach._status)
|
||||
for i, k in enumerate(self.points):
|
||||
p.insert_point(i, k.copy())
|
||||
|
||||
return p
|
||||
|
||||
def purge_aligned_points(self):
|
||||
|
||||
align = True
|
||||
while (align):
|
||||
align = False
|
||||
for i in range(1, self.number_points - 1):
|
||||
d = self.point(i).dist_from_seg(self.point(i-1),
|
||||
self.point(i+1))
|
||||
if d < 0.00001 and self.point(i).name == "":
|
||||
align = True
|
||||
self.delete_i([i])
|
||||
break
|
||||
@@ -52,7 +52,7 @@ class BasicHS(SQLSubModel):
|
||||
self._enabled = True
|
||||
self._data = []
|
||||
|
||||
BasicHS._id_cnt = max(BasicHS._id_cnt + 1, self.id)
|
||||
BasicHS._id_cnt = max(BasicHS._id_cnt + 1, self.id + 1)
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
|
||||
@@ -59,7 +59,7 @@ class HydraulicStructure(SQLSubModel):
|
||||
|
||||
HydraulicStructure._id_cnt = max(
|
||||
HydraulicStructure._id_cnt + 1,
|
||||
self.id
|
||||
self.id + 1
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -395,7 +395,10 @@ class InitialConditions(SQLSubModel):
|
||||
strickler = 25.0
|
||||
|
||||
if not compute_discharge:
|
||||
discharge = data_discharge[profile.rk]
|
||||
if profile.rk in data_discharge:
|
||||
discharge = data_discharge[profile.rk]
|
||||
else:
|
||||
discharge = 0.0
|
||||
else:
|
||||
discharge = (
|
||||
# ((width * 0.8)
|
||||
@@ -461,7 +464,10 @@ class InitialConditions(SQLSubModel):
|
||||
strickler = 25.0
|
||||
|
||||
if not compute_height:
|
||||
height = data_height[profile.rk]
|
||||
if profile.rk in data_height:
|
||||
height = data_height[profile.rk]
|
||||
else:
|
||||
height = 0.0
|
||||
else:
|
||||
if abs(incline) <= 0:
|
||||
height = 0.0
|
||||
@@ -513,7 +519,10 @@ class InitialConditions(SQLSubModel):
|
||||
for profile in profiles:
|
||||
|
||||
if not compute_discharge:
|
||||
d = data_discharge[profile.rk]
|
||||
if profile.rk in data_discharge:
|
||||
d = data_discharge[profile.rk]
|
||||
else:
|
||||
d = 0.0
|
||||
else:
|
||||
d = discharge
|
||||
elevation = interp(profile.rk,
|
||||
|
||||
@@ -58,7 +58,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||
|
||||
InitialConditionsAdisTS._id_cnt = max(
|
||||
InitialConditionsAdisTS._id_cnt + 1,
|
||||
self.id
|
||||
self.id + 1
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -53,7 +53,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||
self._rate = None
|
||||
self._enabled = True
|
||||
|
||||
ICAdisTSSpec._id_cnt = max(ICAdisTSSpec._id_cnt + 1, self.id)
|
||||
ICAdisTSSpec._id_cnt = max(ICAdisTSSpec._id_cnt + 1, self.id + 1)
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
|
||||
@@ -55,7 +55,7 @@ class LateralContribution(SQLSubModel):
|
||||
self._types = [float, float]
|
||||
|
||||
LateralContribution._id_cnt = max(
|
||||
LateralContribution._id_cnt + 1, self.id)
|
||||
LateralContribution._id_cnt + 1, self.id + 1)
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
|
||||
@@ -31,11 +31,12 @@ class Edge(object):
|
||||
self._status = status
|
||||
|
||||
if id == -1:
|
||||
type(self)._id_cnt += 1
|
||||
self.id = type(self)._id_cnt
|
||||
else:
|
||||
self.id = id
|
||||
|
||||
type(self)._id_cnt = max(self.id + 1, type(self)._id_cnt + 1)
|
||||
|
||||
self._name = name
|
||||
|
||||
self.node1 = node1
|
||||
|
||||
@@ -30,11 +30,12 @@ class Node(object):
|
||||
self._status = status
|
||||
|
||||
if id == -1:
|
||||
type(self)._id_cnt += 1
|
||||
self.id = type(self)._id_cnt
|
||||
else:
|
||||
self.id = id
|
||||
|
||||
type(self)._id_cnt = max(self.id + 1, type(self)._id_cnt + 1)
|
||||
|
||||
self._name = name
|
||||
self.pos = Point(x, y)
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class OutputRKAdists(SQLSubModel):
|
||||
self._enabled = True
|
||||
|
||||
OutputRKAdists._id_cnt = max(
|
||||
OutputRKAdists._id_cnt + 1, self.id)
|
||||
OutputRKAdists._id_cnt + 1, self.id + 1)
|
||||
|
||||
@property
|
||||
def reach(self):
|
||||
|
||||
@@ -54,7 +54,7 @@ class Pollutants(SQLSubModel):
|
||||
self._data = []
|
||||
|
||||
Pollutants._id_cnt = max(
|
||||
Pollutants._id_cnt + 1, self.id)
|
||||
Pollutants._id_cnt + 1, self.id + 1)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
||||
@@ -45,7 +45,7 @@ class REPLine(SQLSubModel):
|
||||
self._line = line
|
||||
self._solvers = solvers
|
||||
|
||||
REPLine._id_cnt = max(id, REPLine._id_cnt+1)
|
||||
REPLine._id_cnt = max(self.id + 1, REPLine._id_cnt + 1)
|
||||
|
||||
def __getitem__(self, key):
|
||||
value = None
|
||||
|
||||
@@ -42,7 +42,7 @@ class Reservoir(SQLSubModel):
|
||||
self._node = None
|
||||
self._data = []
|
||||
|
||||
Reservoir._id_cnt = max(Reservoir._id_cnt + 1, self.id)
|
||||
Reservoir._id_cnt = max(Reservoir._id_cnt + 1, self.id + 1)
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
@@ -97,7 +97,7 @@ class Reservoir(SQLSubModel):
|
||||
new_reservoir._node = next(
|
||||
filter(
|
||||
lambda n: n.id == node_id, data["nodes"]
|
||||
)
|
||||
), None
|
||||
)
|
||||
|
||||
new_data = []
|
||||
|
||||
@@ -77,6 +77,12 @@ class Reach(object):
|
||||
)
|
||||
)
|
||||
|
||||
self._profile_mask = list(
|
||||
map(
|
||||
lambda p: p.name[0:8] != 'interpol', self._profiles
|
||||
)
|
||||
)
|
||||
|
||||
def __len__(self):
|
||||
return len(self._profiles)
|
||||
|
||||
@@ -92,6 +98,10 @@ class Reach(object):
|
||||
def profiles(self):
|
||||
return self._profiles.copy()
|
||||
|
||||
@property
|
||||
def profile_mask(self):
|
||||
return self._profile_mask
|
||||
|
||||
def profile(self, id):
|
||||
return self._profiles[id]
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ class Layer(SQLSubModel):
|
||||
else:
|
||||
self.id = id
|
||||
|
||||
Layer._id_cnt = max(id, Layer._id_cnt+1)
|
||||
Layer._id_cnt = max(self.id + 1, Layer._id_cnt + 1)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@@ -277,18 +277,19 @@ class SedimentLayer(SQLSubModel):
|
||||
"FROM sedimentary_layer "
|
||||
)
|
||||
|
||||
for row in table:
|
||||
sl = cls(
|
||||
id=row[0],
|
||||
name=row[1],
|
||||
comment=row[2],
|
||||
status=data['status']
|
||||
)
|
||||
if table is not None:
|
||||
for row in table:
|
||||
sl = cls(
|
||||
id=row[0],
|
||||
name=row[1],
|
||||
comment=row[2],
|
||||
status=data['status']
|
||||
)
|
||||
|
||||
data["sl"] = sl.id
|
||||
sl._layers = Layer._db_load(execute, data)
|
||||
data["sl"] = sl.id
|
||||
sl._layers = Layer._db_load(execute, data)
|
||||
|
||||
new.append(sl)
|
||||
new.append(sl)
|
||||
|
||||
return new
|
||||
|
||||
|
||||
+203
-10
@@ -108,6 +108,187 @@ class AdisTS(CommandLineSolver):
|
||||
name = self._study.name
|
||||
return f"{name}.TRA"
|
||||
|
||||
def _export_ST(self, study, repertory, qlog, name="0"):
|
||||
files = []
|
||||
|
||||
if qlog is not None:
|
||||
qlog.put("Export ST file")
|
||||
|
||||
os.makedirs(os.path.join(repertory, "net"), exist_ok=True)
|
||||
|
||||
# Write header
|
||||
edges = study.river.enable_edges()
|
||||
for edge in edges:
|
||||
name = f"Reach_{edge.id + 1:>3}".replace(" ", "0")
|
||||
|
||||
with adists_file_open(
|
||||
os.path.join(repertory, "net", f"{name}.ST"),
|
||||
"w+"
|
||||
) as f:
|
||||
files.append(str(os.path.join("net", f"{name}.ST")))
|
||||
|
||||
cnt_num = 1
|
||||
for profile in edge.reach.profiles:
|
||||
self._export_ST_profile_header(
|
||||
f, files, profile, cnt_num
|
||||
)
|
||||
cnt_num += 1
|
||||
|
||||
# Points
|
||||
for point in profile.points:
|
||||
self._export_ST_point_line(
|
||||
f, files, point
|
||||
)
|
||||
|
||||
# Profile last line
|
||||
f.write(f" 999.9990 999.9990 999.9990\n")
|
||||
|
||||
def _export_ST_profile_header(self, wfile, files,
|
||||
profile, cnt):
|
||||
num = f"{cnt:>6}"
|
||||
c1 = f"{profile.code1:>6}"
|
||||
c2 = f"{profile.code2:>6}"
|
||||
t = f"{len(profile.points):>6}"
|
||||
rk = f"{profile.rk:>12f}"[0:12]
|
||||
pname = profile.name
|
||||
if profile.name == "":
|
||||
# Generate name from profile id prefixed with
|
||||
# 'p' (and replace space char with '0' char)
|
||||
pname = f"p{profile.id:>3}".replace(" ", "0")
|
||||
name = f"{pname:<19}"
|
||||
|
||||
# Generate sediment additional data if available
|
||||
sediment = ""
|
||||
if profile.sl is not None:
|
||||
if not any(filter(lambda f: ".GRA" in f, files)):
|
||||
files.append(self._gra_file)
|
||||
|
||||
# Number of layers
|
||||
nl = len(profile.sl)
|
||||
sediment = f" {nl:>3}"
|
||||
|
||||
# Layers data
|
||||
for layer in profile.sl.layers:
|
||||
sediment += (
|
||||
f" {layer.height:>10} {layer.d50:>10} " +
|
||||
f"{layer.sigma:>10} " +
|
||||
f"{layer.critical_constraint:>10}"
|
||||
)
|
||||
|
||||
# Profile header line
|
||||
wfile.write(f"{num}{c1}{c2}{t} {rk} {pname} {sediment}\n")
|
||||
|
||||
def _export_ST_point_line(self, wfile, files, point):
|
||||
x = f"{point.x:<12.4f}"[0:12]
|
||||
y = f"{point.y:<12.4f}"[0:12]
|
||||
z = f"{point.z:<12.4f}"[0:12]
|
||||
n = f"{point.name:<3}"
|
||||
|
||||
# Generate sediment additional data if available
|
||||
sediment = ""
|
||||
prev = point.z
|
||||
if point.sl is not None:
|
||||
# Number of layers
|
||||
nl = len(point.sl)
|
||||
sediment = f"{nl:>3}"
|
||||
|
||||
# Layers data
|
||||
for layer in point.sl.layers:
|
||||
prev = round(prev - layer.height, 5)
|
||||
sediment += (
|
||||
f" {prev:>10} {layer.d50:>10} " +
|
||||
f"{layer.sigma:>10} " +
|
||||
f"{layer.critical_constraint:>10}"
|
||||
)
|
||||
|
||||
# Point line
|
||||
wfile.write(f"{x} {y} {z} {n} {sediment}\n")
|
||||
|
||||
def _export_NET(self, study, repertory, qlog=None, name="0"):
|
||||
|
||||
if qlog is not None:
|
||||
qlog.put("Export NET file")
|
||||
|
||||
with adists_file_open(
|
||||
os.path.join(repertory, f"{name}.NET"), "w+") as f:
|
||||
edges = study.river.enable_edges()
|
||||
|
||||
for e in edges:
|
||||
name = f"Reach_{e.id + 1:>3}".replace(" ", "0")
|
||||
id = name
|
||||
|
||||
n1 = f"{e.node1.id:3}".replace(" ", "x")
|
||||
n2 = f"{e.node2.id:3}".replace(" ", "x")
|
||||
file = os.path.join("net", name + ".ST")
|
||||
|
||||
f.write(f"{id} {n1} {n2} {file}\n")
|
||||
|
||||
def _export_fake_INI(self, study, repertory, qlog=None, name="0"):
|
||||
if qlog is not None:
|
||||
qlog.put("Export fake INI file")
|
||||
|
||||
with adists_file_open(
|
||||
os.path.join(
|
||||
repertory, "Mage_fin.ini"
|
||||
), "w+"
|
||||
) as f:
|
||||
edges = study.river.enable_edges()
|
||||
for i, edge in enumerate(edges):
|
||||
lst = list(filter(
|
||||
lambda f: f.is_full_defined(),
|
||||
edge.frictions.frictions
|
||||
))
|
||||
rk_min = 9999999.9
|
||||
rk_max = -9999999.9
|
||||
coeff_min = -1.0
|
||||
coeff_max = -1.0
|
||||
for s in lst: # TODO optimise ?
|
||||
if s.begin_rk > rk_max:
|
||||
rk_max = s.begin_rk
|
||||
coeff_max = s.begin_strickler
|
||||
if s.begin_rk < rk_min:
|
||||
rk_min = s.begin_rk
|
||||
coeff_min = s.begin_strickler
|
||||
if s.end_rk > rk_max:
|
||||
rk_max = s.end_rk
|
||||
coeff_max = s.end_strickler
|
||||
if s.end_rk < rk_min:
|
||||
rk_min = s.end_rk
|
||||
coeff_min = s.end_strickler
|
||||
|
||||
print("min max", rk_min, rk_max)
|
||||
|
||||
def get_stricklers_from_rk(rk, lst):
|
||||
print("rk", rk)
|
||||
|
||||
coeff = None
|
||||
if rk > rk_max:
|
||||
coeff = coeff_max
|
||||
elif rk < rk_min:
|
||||
coeff = coeff_min
|
||||
else:
|
||||
for s in lst:
|
||||
if (rk >= s.begin_rk and rk <= s.end_rk or
|
||||
rk <= s.begin_rk and rk >= s.end_rk):
|
||||
coeff = s.begin_strickler # TODO: inerpolate
|
||||
break
|
||||
|
||||
# TODO interpolation if rk is not in frictons
|
||||
|
||||
if coeff is None:
|
||||
logger.error(
|
||||
"Study frictions are not fully defined"
|
||||
)
|
||||
return None
|
||||
|
||||
return coeff.minor, coeff.medium
|
||||
|
||||
for j, profile in enumerate(edge.reach.profiles):
|
||||
coef_min, coef_moy = get_stricklers_from_rk(profile.rk,
|
||||
lst)
|
||||
f.write(
|
||||
f" {i+1:3}{j+1:4}{' '*116}{coef_min:9}{coef_moy:9}\n")
|
||||
|
||||
def _export_REP_additional_lines(self, study, rep_file):
|
||||
lines = filter(
|
||||
lambda line: line.is_enabled(),
|
||||
@@ -129,7 +310,7 @@ class AdisTS(CommandLineSolver):
|
||||
), "w+"
|
||||
) as f:
|
||||
path = os.path.join("..", mage_rep, name)
|
||||
f.write(f"NET {path}.NET\n")
|
||||
f.write(f"NET {name}.NET\n")
|
||||
f.write(f"REP {path}.REP\n")
|
||||
|
||||
for file in files:
|
||||
@@ -138,13 +319,25 @@ class AdisTS(CommandLineSolver):
|
||||
|
||||
self._export_REP_additional_lines(study, f)
|
||||
|
||||
path_mage_net = os.path.join(os.path.abspath(
|
||||
os.path.join(repertory, os.pardir)
|
||||
), os.path.join(mage_rep, "net"))
|
||||
path_adists_net = os.path.join(repertory, "net")
|
||||
self._export_ST(study, repertory, qlog, name=name)
|
||||
self._export_NET(study, repertory, qlog, name=name)
|
||||
|
||||
if os.path.exists(path_mage_net):
|
||||
shutil.copytree(path_mage_net, path_adists_net, dirs_exist_ok=True)
|
||||
# fake mage_fin.ini:
|
||||
|
||||
path_mage = os.path.join(os.path.abspath(
|
||||
os.path.join(repertory, os.pardir)), mage_rep)
|
||||
self._export_fake_INI(study, path_mage,
|
||||
qlog, name=name)
|
||||
|
||||
# path_mage_net = os.path.join(os.path.abspath(
|
||||
# os.path.join(repertory, os.pardir)
|
||||
# ), os.path.join(mage_rep, "net"))
|
||||
# path_adists_net = os.path.join(repertory, "net")
|
||||
|
||||
# if os.path.exists(path_mage_net):
|
||||
# shutil.copytree(path_mage_net,
|
||||
# path_adists_net,
|
||||
# dirs_exist_ok=True)
|
||||
|
||||
@timer
|
||||
def export(self, study, repertory, qlog=None):
|
||||
@@ -197,7 +390,7 @@ class AdisTS(CommandLineSolver):
|
||||
_nodes_views = set()
|
||||
|
||||
def get_reach_name(self, reach):
|
||||
return f"Reach_{reach.id:>3}".replace(" ", "0")
|
||||
return f"Reach_{reach.id + 1:>3}".replace(" ", "0")
|
||||
|
||||
def get_node_name(self, node):
|
||||
"""Generate a 3 char name for node
|
||||
@@ -338,9 +531,9 @@ class AdisTSwc(AdisTS):
|
||||
) as f:
|
||||
for LC in POL_LC:
|
||||
reach = next(filter(
|
||||
lambda edge: edge.id == LC.edge, study.river.edges()
|
||||
lambda edge: edge.id == LC.edge, study.river.enable_edges()
|
||||
)) # .name
|
||||
reach_name = self.get_reach_name(self, reach)
|
||||
reach_name = self.get_reach_name(reach)
|
||||
f.write(f"${reach_name} {LC.begin_rk} {LC.end_rk}\n")
|
||||
f.write(f"*temps |débit massique (kg/s)\n")
|
||||
f.write(f"*---------++++++++++\n")
|
||||
|
||||
+333
-40
@@ -1,5 +1,5 @@
|
||||
# RubarBE.py -- Pamhyr
|
||||
# Copyright (C) 2024 INRAE
|
||||
# Copyright (C) 2024-2025 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -20,7 +20,7 @@ import os
|
||||
import logging
|
||||
import numpy as np
|
||||
|
||||
from tools import timer, trace, old_pamhyr_date_to_timestamp
|
||||
from tools import timer, trace, old_pamhyr_date_to_timestamp, logger_exception
|
||||
|
||||
from Solver.CommandLine import CommandLineSolver
|
||||
|
||||
@@ -39,7 +39,7 @@ class Rubar3(CommandLineSolver):
|
||||
self._type = "rubar3"
|
||||
|
||||
self._cmd_input = ""
|
||||
self._cmd_solver = "@path @input -o @output"
|
||||
self._cmd_solver = "@path @args @input"
|
||||
self._cmd_output = ""
|
||||
|
||||
@classmethod
|
||||
@@ -58,12 +58,12 @@ class Rubar3(CommandLineSolver):
|
||||
("rubarbe_iovis", "n"),
|
||||
("rubarbe_rep", "n"),
|
||||
("rubarbe_tinit", "000:00:00:00"),
|
||||
("rubarbe_tmax", "999:99:99:00"),
|
||||
("rubarbe_tmax", "000:01:00:00"), # 1 day
|
||||
("rubarbe_tiopdt", "000:00:00:00"),
|
||||
("rubarbe_dt", "5.0"),
|
||||
("rubarbe_ts", "999:99:99:00"),
|
||||
("rubarbe_dtsauv", "00:00:00:05"),
|
||||
("rubarbe_psave", "00:00:00:05"),
|
||||
("rubarbe_dtsauv", "00:00:05:00"),
|
||||
("rubarbe_psave", "00:00:05:00"),
|
||||
("rubarbe_fdeb1", "1"),
|
||||
("rubarbe_fdeb2", "10"),
|
||||
("rubarbe_fdeb3", "100"),
|
||||
@@ -73,8 +73,9 @@ class Rubar3(CommandLineSolver):
|
||||
("rubarbe_tf_4", "y"),
|
||||
("rubarbe_tf_5", "y"),
|
||||
("rubarbe_tf_6", "n"),
|
||||
("rubarbe_trased", "y"),
|
||||
("rubarbe_trased", "n"),
|
||||
("rubarbe_optfpc", "0"),
|
||||
# trased parameters
|
||||
("rubarbe_ros", "2650.0"),
|
||||
("rubarbe_dm", "0.1"),
|
||||
("rubarbe_segma", "1.0"),
|
||||
@@ -129,11 +130,11 @@ class Rubar3(CommandLineSolver):
|
||||
|
||||
def output_param(self):
|
||||
name = self._study.name
|
||||
return f"{name}"
|
||||
return f"profil.{name}"
|
||||
|
||||
def log_file(self):
|
||||
name = self._study.name
|
||||
return f"{name}"
|
||||
return f"geomac-i.{name}"
|
||||
|
||||
def export(self, study, repertory, qlog=None):
|
||||
self._study = study
|
||||
@@ -143,10 +144,12 @@ class Rubar3(CommandLineSolver):
|
||||
self._export_ts(study, repertory, qlog, name=name)
|
||||
self._export_geomac_i(study, repertory, qlog, name=name)
|
||||
self._export_mail(study, repertory, qlog, name=name)
|
||||
self._export_devers(study, repertory, qlog, name=name)
|
||||
self._export_condin(study, repertory, qlog, name=name)
|
||||
self._export_stricklers(study, repertory, qlog, name=name)
|
||||
self._export_hydro(study, repertory, qlog, name=name)
|
||||
self._export_condav(study, repertory, qlog, name=name)
|
||||
# self._export_abshyd(study, repertory, qlog, name=name)
|
||||
|
||||
return True
|
||||
|
||||
@@ -166,9 +169,8 @@ class Rubar3(CommandLineSolver):
|
||||
|
||||
it = iter(params)
|
||||
|
||||
line = 0
|
||||
while line < 29:
|
||||
param = next(it)
|
||||
param = next(it, None)
|
||||
while param is not None:
|
||||
name = param.name
|
||||
value = param.value
|
||||
|
||||
@@ -196,12 +198,12 @@ class Rubar3(CommandLineSolver):
|
||||
v2 = next(it).value
|
||||
v3 = next(it).value
|
||||
|
||||
f.write(f"{v2}{v3}")
|
||||
# f.write(f"{v2}{v3}")
|
||||
|
||||
# New line
|
||||
f.write(f"\n")
|
||||
|
||||
line += 1
|
||||
param = next(it, None)
|
||||
|
||||
def _export_ts(self, study, repertory, qlog, name="0"):
|
||||
if qlog is not None:
|
||||
@@ -277,19 +279,20 @@ class Rubar3(CommandLineSolver):
|
||||
|
||||
f.write(f"{ind:>4} {rk:>11.3f} {n_points:>4}\n")
|
||||
|
||||
for point in profile.points:
|
||||
station = profile.get_station()
|
||||
for i, point in enumerate(profile.points):
|
||||
label = point.name.lower()
|
||||
if label != "":
|
||||
if label[0] == "r":
|
||||
label = label[1].upper()
|
||||
else:
|
||||
label = label[1].upper()
|
||||
label = " "
|
||||
else:
|
||||
label = " "
|
||||
|
||||
y = point.y
|
||||
y = station[i]
|
||||
z = point.z
|
||||
dcs = 0.001
|
||||
dcs = 1.0
|
||||
scs = 1.0
|
||||
tmcs = 0.0
|
||||
|
||||
@@ -329,6 +332,50 @@ class Rubar3(CommandLineSolver):
|
||||
if ind % 3 != 0:
|
||||
f.write("\n")
|
||||
|
||||
def _export_abshyd(self, study, repertory, qlog, name="0"):
|
||||
if qlog is not None:
|
||||
qlog.put("Export ABSHYD file")
|
||||
|
||||
with open(
|
||||
os.path.join(
|
||||
repertory, f"abshyd.{name}"
|
||||
), "w+"
|
||||
) as f:
|
||||
reach_ind = 1
|
||||
for edge in study.river.enable_edges():
|
||||
reach = edge.reach
|
||||
lm = len(reach) + 1
|
||||
f.write(f"{lm:>13}\n")
|
||||
|
||||
ind = 1
|
||||
for mail in reach.inter_profiles_rk():
|
||||
f.write(f"{ind:>4} {mail:15.3f} {reach_ind:>4}\n")
|
||||
ind += 1
|
||||
|
||||
reach_ind += 1
|
||||
|
||||
def _export_devers(self, study, repertory, qlog, name="0"):
|
||||
if qlog is not None:
|
||||
qlog.put("Export DEVERS file")
|
||||
|
||||
with open(
|
||||
os.path.join(
|
||||
repertory, f"devers.{name}"
|
||||
), "w+"
|
||||
) as f:
|
||||
reach_ind = 1
|
||||
for edge in study.river.enable_edges():
|
||||
reach = edge.reach
|
||||
lm = len(reach) + 1
|
||||
f.write(f"{lm:>13}\n")
|
||||
|
||||
ind = 1
|
||||
for mail in reach.inter_profiles_rk():
|
||||
f.write(f"{ind:>4} {0.0:15.3f} {0.0:15.3f} {1.0:>15.3f}\n")
|
||||
ind += 1
|
||||
|
||||
reach_ind += 1
|
||||
|
||||
def _export_stricklers(self, study, repertory, qlog, name="0"):
|
||||
self._export_frot(study, repertory, qlog, name=name, version="")
|
||||
self._export_frot(study, repertory, qlog, name=name, version="2")
|
||||
@@ -347,25 +394,58 @@ class Rubar3(CommandLineSolver):
|
||||
lm = len(reach) + 1
|
||||
f.write(f"{lm:>6}\n")
|
||||
|
||||
def get_stricklers_from_rk(rk):
|
||||
return next(
|
||||
map(
|
||||
lambda s: (
|
||||
s.begin_strickler.medium if version == "2"
|
||||
else s.begin_strickler.minor
|
||||
),
|
||||
filter(
|
||||
lambda f: rk in f,
|
||||
edge.frictions.lst
|
||||
)
|
||||
lst = list(filter(
|
||||
lambda f: f.is_full_defined(),
|
||||
edge.frictions.frictions
|
||||
))
|
||||
|
||||
rk_min = 9999999.9
|
||||
rk_max = -9999999.9
|
||||
coeff_min = -1.0
|
||||
coeff_max = -1.0
|
||||
for s in lst: # TODO optimise ?
|
||||
if s.begin_rk > rk_max:
|
||||
rk_max = s.begin_rk
|
||||
coeff_max = s.begin_strickler
|
||||
if s.begin_rk < rk_min:
|
||||
rk_min = s.begin_rk
|
||||
coeff_min = s.begin_strickler
|
||||
if s.end_rk > rk_max:
|
||||
rk_max = s.end_rk
|
||||
coeff_max = s.end_strickler
|
||||
if s.end_rk < rk_min:
|
||||
rk_min = s.end_rk
|
||||
coeff_min = s.end_strickler
|
||||
|
||||
def get_stricklers_from_rk(rk, lst):
|
||||
|
||||
coeff = None
|
||||
if rk > rk_max:
|
||||
coeff = coeff_max
|
||||
elif rk < rk_min:
|
||||
coeff = coeff_min
|
||||
else:
|
||||
for s in lst:
|
||||
if (rk >= s.begin_rk and rk <= s.end_rk or
|
||||
rk <= s.begin_rk and rk >= s.end_rk):
|
||||
coeff = s.begin_strickler # TODO: inerpolate
|
||||
break
|
||||
|
||||
# TODO interpolation if rk is not in frictons
|
||||
|
||||
if coeff is None:
|
||||
logger.error(
|
||||
"Study frictions are not fully defined"
|
||||
)
|
||||
)
|
||||
return None
|
||||
|
||||
return coeff.medium if version == "2" else coeff.minor
|
||||
|
||||
ind = 1
|
||||
for mail in edge.reach.inter_profiles_rk():
|
||||
coef = get_stricklers_from_rk(mail)
|
||||
|
||||
f.write(f"{ind:>6} {coef:>12.5f}")
|
||||
coef = get_stricklers_from_rk(mail, lst)
|
||||
if coef is not None:
|
||||
f.write(f"{ind:>6} {coef:>12.5f}")
|
||||
|
||||
ind += 1
|
||||
f.write("\n")
|
||||
@@ -382,7 +462,7 @@ class Rubar3(CommandLineSolver):
|
||||
for edge in study.river.enable_edges():
|
||||
reach = edge.reach
|
||||
|
||||
f.write(f"0.0\n")
|
||||
f.write(f"{0.0}\n")
|
||||
|
||||
ics = study.river.initial_conditions.get(edge)
|
||||
data = self._export_condin_init_data(ics)
|
||||
@@ -391,7 +471,9 @@ class Rubar3(CommandLineSolver):
|
||||
first = profiles[0]
|
||||
last = profiles[-1]
|
||||
|
||||
# if first not in data or last not in data:
|
||||
if first.rk not in data or last.rk not in data:
|
||||
print(data)
|
||||
logger.error(
|
||||
"Study initial condition is not fully defined"
|
||||
)
|
||||
@@ -444,10 +526,10 @@ class Rubar3(CommandLineSolver):
|
||||
z = data[profile.rk][0]
|
||||
q = data[profile.rk][1]
|
||||
|
||||
# height = z - profile.z_min()
|
||||
height = z - profile.z_min()
|
||||
speed = profile.speed(q, z)
|
||||
|
||||
return z, speed
|
||||
return height, speed
|
||||
|
||||
def _export_hydro(self, study, repertory, qlog, name="0"):
|
||||
if qlog is not None:
|
||||
@@ -470,7 +552,7 @@ class Rubar3(CommandLineSolver):
|
||||
for bc in bcs:
|
||||
f.write(f"{len(bc)}\n")
|
||||
for d0, d1 in bc.data:
|
||||
f.write(f"{d0} {d1}\n")
|
||||
f.write(f"{d1} {d0}\n")
|
||||
|
||||
def _export_condav(self, study, repertory, qlog, name="0"):
|
||||
if qlog is not None:
|
||||
@@ -492,8 +574,219 @@ class Rubar3(CommandLineSolver):
|
||||
|
||||
for bc in bcs:
|
||||
f.write(f"{len(bc)}\n")
|
||||
for d0, d1 in bc.data:
|
||||
f.write(f"{d0} {d1}\n")
|
||||
if bc.bctype == "ZD":
|
||||
for d0, d1 in bc.data:
|
||||
f.write(f"{d1} {d0}\n")
|
||||
else:
|
||||
for d0, d1 in bc.data:
|
||||
f.write(f"{d0} {d1}\n")
|
||||
|
||||
def read_profil(self, study, fname, results, qlog=None, name="0"):
|
||||
logger.info(f"read: profil.{name}")
|
||||
with open(fname, "r") as f:
|
||||
reachs = []
|
||||
for i, edge in enumerate(study.river.enable_edges()):
|
||||
reach = edge.reach
|
||||
# Add results reach to reach list
|
||||
res_reach = results.river.add(i)
|
||||
reachs.append((res_reach, len(reach) + 1))
|
||||
|
||||
def read_data_line(f):
|
||||
line = f.readline().split()
|
||||
if len(line) > 3:
|
||||
return tuple(map(float, line))
|
||||
else:
|
||||
return (0.0, 0.0, 0.0, 0.0)
|
||||
|
||||
def set_and_compute_limites(reach, ind, z, q, s):
|
||||
reach.set(ind, timestamp, "Z", z)
|
||||
reach.set(ind, timestamp, "Q", q)
|
||||
reach.set(ind, timestamp, "V", s)
|
||||
|
||||
profile = reach.profile(ind)
|
||||
limits = profile.geometry.get_water_limits(z)
|
||||
reach.set(
|
||||
ind, timestamp, "water_limits", limits
|
||||
)
|
||||
|
||||
ts = set()
|
||||
timestamp = next(filter(
|
||||
lambda p: p.name == 'rubarbe_tinit',
|
||||
study.river.get_params(self._type).parameters
|
||||
)).value
|
||||
if timestamp.count(':') == 3:
|
||||
timestamp = old_pamhyr_date_to_timestamp(timestamp)
|
||||
ts.add(timestamp)
|
||||
|
||||
# add initial condition
|
||||
for r, edge in enumerate(study.river.enable_edges()):
|
||||
reach = edge.reach
|
||||
ics = study.river.initial_conditions.get(edge)
|
||||
q = ics.get_discharge()
|
||||
z = ics.get_elevation()
|
||||
k = 0
|
||||
for i, j in zip(z, q):
|
||||
v = reach.profiles[k].speed(i, j)
|
||||
set_and_compute_limites(reachs[r][0], k, i, j, v)
|
||||
k += 1
|
||||
|
||||
# start read
|
||||
|
||||
end = False
|
||||
while True:
|
||||
line = f.readline()
|
||||
if line == "":
|
||||
results.set("timestamps", ts)
|
||||
return
|
||||
|
||||
timestamp = float(line)
|
||||
ts.add(timestamp)
|
||||
|
||||
logger.info(f"read: profil.{name}: timestamp = {timestamp}")
|
||||
|
||||
for reach, lm in reachs:
|
||||
# First profile
|
||||
h, s, q, z = read_data_line(f)
|
||||
set_and_compute_limites(reach, 0, z+h, q, s)
|
||||
|
||||
# For each profile
|
||||
ind = 1
|
||||
ph, ps, pq, pz = read_data_line(f)
|
||||
while ind < lm - 2:
|
||||
h, s, q, z = read_data_line(f)
|
||||
set_and_compute_limites(
|
||||
reach, ind,
|
||||
(pz + z + ph + h) / 2,
|
||||
(pq + q) / 2,
|
||||
(ps + s) / 2
|
||||
)
|
||||
|
||||
ph = h
|
||||
ps = s
|
||||
pq = q
|
||||
pz = z
|
||||
ind += 1
|
||||
|
||||
# Last profile
|
||||
h, s, q, z = read_data_line(f)
|
||||
set_and_compute_limites(reach, ind, z+h, q, s)
|
||||
|
||||
@timer
|
||||
def write_bin(self, study, fname, results, qlog=None, name="0"):
|
||||
logger.info(f"write_bin: Start writing '{fname}' ...")
|
||||
|
||||
with open(fname, "wb") as f:
|
||||
def newline(j): return np.asarray([j], dtype=np.int32).tofile(f)
|
||||
def endline(j): return np.asarray([j], dtype=np.int32).tofile(f)
|
||||
|
||||
def write_int(i):
|
||||
newline(len(i)*4)
|
||||
np.array(i, dtype=np.int32).tofile(f)
|
||||
endline(len(i)*4)
|
||||
|
||||
def write_float(i):
|
||||
newline(len(i)*4)
|
||||
np.array(i, dtype=np.float32).tofile(f)
|
||||
endline(len(i)*4)
|
||||
|
||||
def write_float64(i):
|
||||
newline(len(i)*8)
|
||||
np.array(i, dtype=np.float64).tofile(f)
|
||||
endline(len(i)*8)
|
||||
|
||||
def write_float64(i):
|
||||
newline(len(i)*8)
|
||||
np.array(i, dtype=np.float64).tofile(f)
|
||||
endline(len(i)*8)
|
||||
|
||||
def write_data(npts, t, a, val):
|
||||
newline(npts*4 + 13)
|
||||
np.array(npts, dtype=np.int32).tofile(f)
|
||||
np.array(t, dtype=np.float64).tofile(f)
|
||||
np.array(bytearray(a.encode()), dtype=np.byte).tofile(f)
|
||||
np.array(val, dtype=np.float32).tofile(f)
|
||||
endline(npts*4 + 13)
|
||||
|
||||
ts_list = sorted(results.get("timestamps"))
|
||||
profiles = []
|
||||
for r in results.river.reachs:
|
||||
profiles += r.profiles
|
||||
|
||||
# Meta data (1st line)
|
||||
nb_reach = len(results.river)
|
||||
nb_profile = len(profiles)
|
||||
write_int([nb_reach, nb_profile, "82"])
|
||||
|
||||
# Reach information (2nd line)
|
||||
is1 = []
|
||||
is2 = []
|
||||
ltmp = []
|
||||
i = 1
|
||||
for r in results.river.reachs:
|
||||
j = i+len(r)-1
|
||||
ltmp += [i, j]
|
||||
is1.append(i)
|
||||
is2.append(j)
|
||||
i += i+len(r)
|
||||
write_int(ltmp)
|
||||
|
||||
# X (3rd line)
|
||||
rk = []
|
||||
for r in results.river.reachs:
|
||||
rk += r.geometry.get_rk()
|
||||
write_float(rk)
|
||||
|
||||
# Z and Y (4th line)
|
||||
# ltmp = []
|
||||
# for r in results.river.reachs:
|
||||
# for p in r.prifiles:
|
||||
# ltpm.append(p.rk)
|
||||
write_float(3*nb_profile*[0.0])
|
||||
|
||||
# Data
|
||||
|
||||
for timestamp in ts_list:
|
||||
q = list(
|
||||
map(
|
||||
lambda p: p.get_ts_key(timestamp, "Q"),
|
||||
profiles
|
||||
)
|
||||
)
|
||||
write_data(nb_profile, timestamp, "Q", q)
|
||||
z = list(
|
||||
map(
|
||||
lambda p: p.get_ts_key(timestamp, "Z"),
|
||||
profiles
|
||||
)
|
||||
)
|
||||
write_data(nb_profile, timestamp, "Z", z)
|
||||
logger.info(f"write_bin: ... end with {len(ts_list)} timestamps")
|
||||
|
||||
@timer
|
||||
def results(self, study, repertory, qlog=None, name="0"):
|
||||
results = Results(
|
||||
study=study,
|
||||
solver=self,
|
||||
repertory=repertory,
|
||||
name=name,
|
||||
)
|
||||
results_file = f"profil.{name}"
|
||||
|
||||
fname = os.path.join(repertory, results_file)
|
||||
if not os.path.isfile(fname):
|
||||
logger.warning(f"Result file {results_file} does not exist")
|
||||
return None
|
||||
try:
|
||||
self.read_profil(study, fname, results, qlog, name=name)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to read results")
|
||||
logger_exception(e)
|
||||
return None
|
||||
|
||||
fname = os.path.join(repertory, f"{name}.BIN")
|
||||
self.write_bin(study, fname, results, qlog, name)
|
||||
|
||||
return results
|
||||
|
||||
|
||||
class RubarBE(Rubar3):
|
||||
@@ -505,5 +798,5 @@ class RubarBE(Rubar3):
|
||||
self._type = "rubarbe"
|
||||
|
||||
self._cmd_input = ""
|
||||
self._cmd_solver = "@path @input -o @output"
|
||||
self._cmd_solver = "@path @args @input"
|
||||
self._cmd_output = ""
|
||||
@@ -34,7 +34,7 @@ solver_long_name = {
|
||||
# "mage_fake7": "Mage fake v7",
|
||||
"adistswc": "Adis-TS_WC",
|
||||
# "rubarbe": "RubarBE",
|
||||
# "rubar3": "Rubar3",
|
||||
"rubar3": "Rubar3",
|
||||
}
|
||||
|
||||
solver_type_list = {
|
||||
@@ -44,5 +44,5 @@ solver_type_list = {
|
||||
# "mage_fake7": MageFake7,
|
||||
"adistswc": AdisTSwc,
|
||||
# "rubarbe": RubarBE,
|
||||
# "rubar3": Rubar3,
|
||||
"rubar3": Rubar3,
|
||||
}
|
||||
@@ -55,7 +55,7 @@ class AboutWindow(PamhyrDialog):
|
||||
|
||||
label = self.get_label_text("label_version")
|
||||
label = label.replace("@version", version)
|
||||
label = label.replace("@codename", "(Adis-TS)")
|
||||
label = label.replace("@codename", "(Claude François)")
|
||||
self.set_label_text("label_version", label)
|
||||
|
||||
# Authors
|
||||
|
||||
@@ -211,3 +211,26 @@ class TableModel(PamhyrTableModel):
|
||||
)
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.update()
|
||||
|
||||
def read_from_file(self, file_name, bctype):
|
||||
|
||||
logger.debug(f"Import boundary conditions from {file_name}")
|
||||
data0 = []
|
||||
data1 = []
|
||||
if bctype == "ZD":
|
||||
mult = 1
|
||||
else:
|
||||
mult = 60
|
||||
with open(file_name, encoding="utf-8") as bc_file:
|
||||
for line in bc_file:
|
||||
if not (line.startswith("#") or
|
||||
line.startswith("*") or
|
||||
line.startswith("$")):
|
||||
line = line.split()
|
||||
if bctype == "ZD":
|
||||
data0.append(float(line[0]))
|
||||
else:
|
||||
data0.append(old_pamhyr_date_to_timestamp(line[0]))
|
||||
data1.append(line[1])
|
||||
|
||||
self.replace_data(data0, data1)
|
||||
@@ -30,10 +30,10 @@ from PyQt5.QtGui import (
|
||||
QKeySequence,
|
||||
)
|
||||
|
||||
from PyQt5 import QtCore
|
||||
from PyQt5 import QtCore, QtWidgets
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel, QCoreApplication,
|
||||
pyqtSlot, pyqtSignal,
|
||||
pyqtSlot, pyqtSignal, QSettings,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
@@ -198,6 +198,8 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||
self.find(QAction, "action_del").triggered.connect(self.delete)
|
||||
self.find(QAction, "action_sort").triggered.connect(self.sort)
|
||||
self.find(QAction, "action_import").triggered\
|
||||
.connect(self.import_from_file)
|
||||
self.find(QAction, "action_generate_uniform").triggered.connect(
|
||||
self.generate_uniform
|
||||
)
|
||||
@@ -293,6 +295,31 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
||||
self._table.sort(False)
|
||||
self.plot.update()
|
||||
|
||||
def import_from_file(self):
|
||||
options = QFileDialog.Options()
|
||||
settings = QSettings(QSettings.IniFormat,
|
||||
QSettings.UserScope, 'MyOrg', )
|
||||
options |= QFileDialog.DontUseNativeDialog
|
||||
|
||||
if self._data.bctype == "TD":
|
||||
file_types = [self._trad["file_hyd"]]
|
||||
if self._data.bctype == "TZ":
|
||||
file_types = [self._trad["file_lim"]]
|
||||
if self._data.bctype == "ZD":
|
||||
file_types = [self._trad["file_ava"]]
|
||||
file_types.append(self._trad["file_all"])
|
||||
|
||||
file_name, _ = QtWidgets.QFileDialog.getOpenFileName(
|
||||
self,
|
||||
self._trad["open_file"],
|
||||
"",
|
||||
";; ".join(file_types),
|
||||
options=options
|
||||
)
|
||||
|
||||
if file_name != "":
|
||||
self._table.read_from_file(file_name, self._data.bctype)
|
||||
|
||||
def move_up(self):
|
||||
row = self.index_selected_row()
|
||||
self._table.move_up(row)
|
||||
|
||||
@@ -35,6 +35,17 @@ class BCETranslate(BCTranslate):
|
||||
self._dict["Boundary Condition Options"] = _translate(
|
||||
"BoundaryCondition", "Boundary Condition Options")
|
||||
|
||||
self._dict["open_file"] = _translate(
|
||||
"BoundaryCondition", "Open a file")
|
||||
self._dict["file_hyd"] = _translate(
|
||||
"BoundaryCondition", "Mage hydrograph file (*.HYD)")
|
||||
self._dict["file_lim"] = _translate(
|
||||
"BoundaryCondition", "Mage limnigraph file (*.LIM)")
|
||||
self._dict["file_ava"] = _translate(
|
||||
"BoundaryCondition", "Mage rating curve file (*.AVA)")
|
||||
self._dict["file_all"] = _translate(
|
||||
"BoundaryCondition", "All files (*)")
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
"x": _translate("BoundaryCondition", "X"),
|
||||
"y": _translate("BoundaryCondition", "Y"),
|
||||
|
||||
@@ -38,7 +38,7 @@ from View.Frictions.UndoCommand import (
|
||||
SetNameCommand, SetBeginCommand, SetEndCommand,
|
||||
SetBeginStricklerCommand, SetEndStricklerCommand,
|
||||
AddCommand, DelCommand, SortCommand,
|
||||
MoveCommand, PasteCommand, DuplicateCommand,
|
||||
MoveCommand, PasteCommand, DuplicateCommand, ReplaceDataCommand,
|
||||
)
|
||||
|
||||
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||
@@ -99,7 +99,7 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
self.commitData.emit(self.sender())
|
||||
|
||||
|
||||
class TableModel(PamhyrTableModel):
|
||||
class FrictionTableModel(PamhyrTableModel):
|
||||
def _setup_lst(self):
|
||||
self._lst = self._data.frictions
|
||||
self._study = self._opt_data
|
||||
@@ -199,6 +199,18 @@ class TableModel(PamhyrTableModel):
|
||||
self.endRemoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def replace_data(self, new_data):
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
self._undo.push(
|
||||
ReplaceDataCommand(
|
||||
self._lst, new_data
|
||||
)
|
||||
)
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def sort(self, _reverse, parent=QModelIndex()):
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
@@ -252,3 +264,32 @@ class TableModel(PamhyrTableModel):
|
||||
def redo(self):
|
||||
self._undo.redo()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def read_from_file(self, file_name):
|
||||
|
||||
reach_id = self._study.river.enable_edges().index(self._data) + 1
|
||||
|
||||
logger.debug(f"Import frictions from {file_name}")
|
||||
data = []
|
||||
with open(file_name, encoding="utf-8") as rug_file:
|
||||
for line in rug_file:
|
||||
if line.upper().startswith("K"):
|
||||
if int(line[1:4]) == reach_id:
|
||||
data.append(line[4:].split())
|
||||
|
||||
new_data = []
|
||||
for d in data:
|
||||
new = None
|
||||
minor = float(d[2])
|
||||
medium = float(d[3])
|
||||
for s in self._study.river.stricklers.stricklers:
|
||||
if s.minor == minor and s.medium == medium:
|
||||
new = s
|
||||
break
|
||||
if new is None:
|
||||
new = self._study.river.stricklers.new(len(
|
||||
self._study.river.stricklers))
|
||||
new.minor = minor
|
||||
new.medium = medium
|
||||
new_data.append([self._data, float(d[0]), float(d[1]), new, new])
|
||||
self.replace_data(new_data)
|
||||
@@ -143,6 +143,42 @@ class AddCommand(QUndoCommand):
|
||||
self._frictions.insert(self._index, self._new)
|
||||
|
||||
|
||||
class ReplaceDataCommand(QUndoCommand):
|
||||
def __init__(self, frictions, new_data):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._frictions = frictions
|
||||
self._new_data = new_data
|
||||
self._old_rows = list(range(len(frictions)))
|
||||
self._new_rows = list(range(len(new_data)))
|
||||
self._new = []
|
||||
|
||||
self._old_friction = []
|
||||
for row in self._old_rows:
|
||||
self._old_friction.append((row, self._frictions.lst[row]))
|
||||
|
||||
def undo(self):
|
||||
self._frictions.delete_i(self._new_rows)
|
||||
for row, el in self._old_friction:
|
||||
self._frictions.insert(row, el)
|
||||
|
||||
def redo(self):
|
||||
if len(self._new) == 0:
|
||||
self._frictions.delete_i(self._old_rows)
|
||||
for row in self._new_rows:
|
||||
new = self._frictions.new(row)
|
||||
d = self._new_data[row]
|
||||
new.edge = d[0]
|
||||
new.begin_rk = d[1]
|
||||
new.end_rk = d[2]
|
||||
new.begin_strickler = d[3]
|
||||
new.end_strickler = d[4]
|
||||
self._new.append((row, new))
|
||||
else:
|
||||
for row, el in self._new:
|
||||
self._frictions.insert(row, el)
|
||||
|
||||
|
||||
class DelCommand(QUndoCommand):
|
||||
def __init__(self, frictions, rows):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
@@ -26,10 +26,11 @@ from PyQt5.QtGui import (
|
||||
QKeySequence,
|
||||
)
|
||||
|
||||
from PyQt5 import QtWidgets
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel,
|
||||
QCoreApplication, QModelIndex, pyqtSlot,
|
||||
QRect,
|
||||
QRect, QSettings,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
@@ -46,7 +47,7 @@ from View.Frictions.UndoCommand import (
|
||||
)
|
||||
|
||||
from View.Frictions.Table import (
|
||||
TableModel, ComboBoxDelegate
|
||||
FrictionTableModel, ComboBoxDelegate
|
||||
)
|
||||
|
||||
from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
||||
@@ -106,7 +107,7 @@ class FrictionsWindow(PamhyrWindow):
|
||||
)
|
||||
|
||||
table = self.find(QTableView, f"tableView")
|
||||
self._table = TableModel(
|
||||
self._table = FrictionTableModel(
|
||||
table_view=table,
|
||||
table_headers=self._trad.get_dict("table_headers"),
|
||||
editable_headers=[
|
||||
@@ -157,6 +158,8 @@ class FrictionsWindow(PamhyrWindow):
|
||||
self.plot_2.draw()
|
||||
|
||||
def setup_connections(self):
|
||||
self.find(QAction, "action_import").triggered\
|
||||
.connect(self.import_from_file)
|
||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||
self.find(QAction, "action_del").triggered.connect(self.delete)
|
||||
self.find(QAction, "action_sort").triggered.connect(self.sort)
|
||||
@@ -265,3 +268,22 @@ class FrictionsWindow(PamhyrWindow):
|
||||
parent=self
|
||||
)
|
||||
strick.show()
|
||||
|
||||
def import_from_file(self):
|
||||
options = QFileDialog.Options()
|
||||
settings = QSettings(QSettings.IniFormat,
|
||||
QSettings.UserScope, 'MyOrg', )
|
||||
options |= QFileDialog.DontUseNativeDialog
|
||||
|
||||
file_types = [self._trad["file_rug"], self._trad["file_all"]]
|
||||
|
||||
file_name, _ = QtWidgets.QFileDialog.getOpenFileName(
|
||||
self,
|
||||
self._trad["open_file"],
|
||||
"",
|
||||
";; ".join(file_types),
|
||||
options=options
|
||||
)
|
||||
|
||||
if file_name != "":
|
||||
self._table.read_from_file(file_name)
|
||||
@@ -38,6 +38,10 @@ class FrictionsTranslate(MainTranslate):
|
||||
self._dict["Edit frictions"] = _translate(
|
||||
"Frictions", "Edit frictions"
|
||||
)
|
||||
self._dict["file_rug"] = _translate(
|
||||
"Frictions", "Mage initial frictions file (*.RUG *.rug)")
|
||||
self._dict["file_all"] = _translate(
|
||||
"Frictions", "All files (*)")
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
# "name": self._dict["name"],
|
||||
|
||||
@@ -23,12 +23,12 @@ from PyQt5.QtGui import (
|
||||
)
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel,
|
||||
Qt, QVariant, QAbstractTableModel, QItemSelectionModel,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QComboBox, QUndoStack, QShortcut,
|
||||
QDoubleSpinBox,
|
||||
QDoubleSpinBox, QRadioButton,
|
||||
)
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class MeshingDialog(PamhyrDialog):
|
||||
self._space_step = 50.0
|
||||
self._lplan = False
|
||||
self._lm = "3"
|
||||
self._linear = False
|
||||
self._linear = True
|
||||
self._begin_cs = -1
|
||||
self._end_cs = -1
|
||||
self._begin_dir = "un"
|
||||
@@ -71,7 +71,7 @@ class MeshingDialog(PamhyrDialog):
|
||||
self._origin = self._reach.profile(0)
|
||||
|
||||
self._init_default_values_profiles()
|
||||
self._init_default_values_guidelines()
|
||||
# self._init_default_values_guidelines()
|
||||
|
||||
self.set_double_spin_box(
|
||||
"doubleSpinBox_space_step",
|
||||
@@ -83,14 +83,24 @@ class MeshingDialog(PamhyrDialog):
|
||||
else:
|
||||
self.set_radio_button("radioButton_spline", True)
|
||||
|
||||
self.find(QRadioButton, "radioButton_spline").setEnabled(False)
|
||||
self.find(QRadioButton, "radioButton_linear").setEnabled(False)
|
||||
|
||||
def _init_default_values_profiles(self):
|
||||
profiles = self.profiles
|
||||
|
||||
self.combobox_add_items("comboBox_begin_rk", profiles)
|
||||
self.combobox_add_items("comboBox_end_rk", profiles)
|
||||
|
||||
self.set_combobox_text("comboBox_begin_rk", profiles[0])
|
||||
self.set_combobox_text("comboBox_end_rk", profiles[-1])
|
||||
r = self.parent.tableView\
|
||||
.selectionModel()\
|
||||
.selectedRows()
|
||||
if len(r) <= 1:
|
||||
self.set_combobox_text("comboBox_begin_rk", profiles[0])
|
||||
self.set_combobox_text("comboBox_end_rk", profiles[-1])
|
||||
else:
|
||||
self.set_combobox_text("comboBox_begin_rk", profiles[r[0].row()])
|
||||
self.set_combobox_text("comboBox_end_rk", profiles[r[-1].row()])
|
||||
|
||||
@property
|
||||
def profiles(self):
|
||||
@@ -167,8 +177,8 @@ class MeshingDialog(PamhyrDialog):
|
||||
self._begin_cs = self.profiles.index(p1)
|
||||
self._end_cs = self.profiles.index(p2)
|
||||
|
||||
self._begin_dir = self.get_combobox_text("comboBox_begin_gl")
|
||||
self._end_dir = self.get_combobox_text("comboBox_end_gl")
|
||||
# self._begin_dir = self.get_combobox_text("comboBox_begin_gl")
|
||||
# self._end_dir = self.get_combobox_text("comboBox_end_gl")
|
||||
|
||||
super().accept()
|
||||
|
||||
|
||||
@@ -28,8 +28,6 @@ from PyQt5.QtWidgets import (
|
||||
from Model.Geometry import Reach
|
||||
from Model.Except import exception_message_box
|
||||
|
||||
from Meshing.Mage import MeshingWithMage
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
@@ -240,7 +238,7 @@ class MeshingCommand(QUndoCommand):
|
||||
self._mesher = mesher
|
||||
self._command = command
|
||||
|
||||
self._profiles = reach.profiles.copy()
|
||||
self._profiles = [p.copy() for p in reach.profiles]
|
||||
self._profiles.reverse()
|
||||
|
||||
self._new_profiles = None
|
||||
@@ -264,7 +262,7 @@ class MeshingCommand(QUndoCommand):
|
||||
**self._data
|
||||
)
|
||||
|
||||
self._new_profiles = self._reach.profiles.copy()
|
||||
self._new_profiles = [p.copy() for p in self._reach.profiles]
|
||||
self._new_profiles.reverse()
|
||||
else:
|
||||
self._reach.purge()
|
||||
|
||||
+30
-16
@@ -32,6 +32,7 @@ from PyQt5.QtGui import (
|
||||
from PyQt5.QtCore import (
|
||||
QModelIndex, Qt, QSettings, pyqtSlot,
|
||||
QItemSelectionModel, QCoreApplication, QSize,
|
||||
QItemSelection, QItemSelectionRange,
|
||||
)
|
||||
from PyQt5.QtWidgets import (
|
||||
QApplication, QMainWindow, QFileDialog, QCheckBox,
|
||||
@@ -49,9 +50,7 @@ from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
||||
|
||||
from View.SelectReach.Window import SelectReachWindow
|
||||
|
||||
from Meshing.Mage import (
|
||||
MeshingWithMage, MeshingWithMageMailleurTT
|
||||
)
|
||||
from Meshing.Internal import InternalMeshing
|
||||
|
||||
from View.Geometry.Table import GeometryReachTableModel
|
||||
from View.Geometry.PlotXY import PlotXY
|
||||
@@ -288,6 +287,13 @@ class GeometryWindow(PamhyrWindow):
|
||||
self.tableView.model().blockSignals(False)
|
||||
|
||||
def edit_meshing(self):
|
||||
|
||||
rows = list(
|
||||
set(
|
||||
(i.row() for i in self.tableView.selectedIndexes())
|
||||
)
|
||||
)
|
||||
selected_rk = [self._reach.profile(r).rk for r in rows]
|
||||
try:
|
||||
dlg = MeshingDialog(
|
||||
reach=self._reach,
|
||||
@@ -298,8 +304,6 @@ class GeometryWindow(PamhyrWindow):
|
||||
data = {
|
||||
"step": dlg.space_step,
|
||||
"limites": [dlg.begin_cs, dlg.end_cs],
|
||||
"directrices": [dlg.begin_dir, dlg.end_dir],
|
||||
"lplan": dlg.lplan,
|
||||
"linear": dlg.linear,
|
||||
}
|
||||
self._edit_meshing(data)
|
||||
@@ -307,18 +311,31 @@ class GeometryWindow(PamhyrWindow):
|
||||
logger_exception(e)
|
||||
return
|
||||
|
||||
ind = []
|
||||
for i in range(self._reach.number_profiles):
|
||||
if self._reach.profile(i).rk in selected_rk:
|
||||
ind.append(i)
|
||||
self.tableView.setFocus()
|
||||
selection = self.tableView.selectionModel()
|
||||
index = QItemSelection()
|
||||
if len(ind) > 0:
|
||||
for i in ind:
|
||||
index.append(QItemSelectionRange(
|
||||
self.tableView.model().index(i, 0))
|
||||
)
|
||||
selection.select(
|
||||
index,
|
||||
QItemSelectionModel.Rows |
|
||||
QItemSelectionModel.ClearAndSelect |
|
||||
QItemSelectionModel.Select
|
||||
)
|
||||
|
||||
def _edit_meshing(self, data):
|
||||
try:
|
||||
mesher = MeshingWithMageMailleurTT()
|
||||
mesher = InternalMeshing()
|
||||
self._table.meshing(mesher, data)
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
raise ExternFileMissingError(
|
||||
module="mage",
|
||||
filename="MailleurTT",
|
||||
path=MeshingWithMageMailleurTT._path(),
|
||||
src_except=e
|
||||
)
|
||||
|
||||
def update_rk(self):
|
||||
try:
|
||||
@@ -341,14 +358,11 @@ class GeometryWindow(PamhyrWindow):
|
||||
|
||||
def _update_rk(self, data):
|
||||
try:
|
||||
mesher = MeshingWithMageMailleurTT()
|
||||
mesher = InternalMeshing()
|
||||
self._table.update_rk(mesher, data)
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
raise ExternFileMissingError(
|
||||
module="mage",
|
||||
filename="MailleurTT",
|
||||
path=MeshingWithMageMailleurTT._path(),
|
||||
src_except=e
|
||||
)
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ class InitialConditionTableModel(PamhyrTableModel):
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def import_from_results(self, index, results):
|
||||
def import_from_results(self, results):
|
||||
if results is None:
|
||||
logger.error("No results data")
|
||||
return
|
||||
@@ -281,6 +281,51 @@ class InitialConditionTableModel(PamhyrTableModel):
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def read_from_ini(self, file_name):
|
||||
|
||||
reach_id = self._data.river.enable_edges().index(self._reach) + 1
|
||||
|
||||
logger.debug(f"Import initial conditions from {file_name}")
|
||||
data = []
|
||||
with open(file_name, encoding="utf-8") as ini_file:
|
||||
for line in ini_file:
|
||||
if not (line.startswith("#") or
|
||||
line.startswith("*") or
|
||||
line.startswith("$")):
|
||||
line_split = line.split()
|
||||
formated = False
|
||||
if len(line_split[0]) > 3:
|
||||
formated = True
|
||||
elif len(line_split[2]) > 10:
|
||||
formated = True
|
||||
elif len(line_split[3]) > 11:
|
||||
formated = True
|
||||
elif len(line_split[4]) > 9:
|
||||
formated = True
|
||||
|
||||
if formated: # old PamHyr format
|
||||
if int(line[1:4]) == reach_id:
|
||||
data.append([line[31:40],
|
||||
line[10:20],
|
||||
line[20:31]])
|
||||
else:
|
||||
if int(line_split[0]) == reach_id:
|
||||
data.append([line_split[4],
|
||||
line_split[2],
|
||||
line_split[3]])
|
||||
|
||||
self._undo.push(
|
||||
ReplaceDataCommand(
|
||||
self._lst,
|
||||
list(
|
||||
map(
|
||||
lambda d: self._lst.new_from_data(*d),
|
||||
data
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def undo(self):
|
||||
self._undo.undo()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
@@ -220,6 +220,8 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||
def _update_plot(self):
|
||||
self.plot_1.draw()
|
||||
self.plot_2.draw()
|
||||
self.plot_1.idle()
|
||||
self.plot_2.idle()
|
||||
|
||||
def _propagated_update(self, key=Modules(0)):
|
||||
if Modules.GEOMETRY not in key:
|
||||
@@ -265,20 +267,29 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||
settings = QSettings(QSettings.IniFormat,
|
||||
QSettings.UserScope, 'MyOrg', )
|
||||
options |= QFileDialog.DontUseNativeDialog
|
||||
filename, _ = QtWidgets.QFileDialog.getOpenFileName(
|
||||
|
||||
file_types = [
|
||||
self._trad["file_bin"],
|
||||
self._trad["file_ini"],
|
||||
self._trad["file_all"],
|
||||
]
|
||||
file_name, _ = QtWidgets.QFileDialog.getOpenFileName(
|
||||
self,
|
||||
self._trad["open_file"],
|
||||
"",
|
||||
";; ".join(["Mage (*.BIN)"]),
|
||||
";; ".join(file_types),
|
||||
options=options
|
||||
)
|
||||
|
||||
if filename != "":
|
||||
size = os.stat(filename).st_size
|
||||
# self._table.import_geometry(0, filename)
|
||||
self._import_from_file(filename)
|
||||
if file_name != "":
|
||||
size = os.stat(file_name).st_size
|
||||
# self._table.import_geometry(0, file_name)
|
||||
if file_name[-4:] == ".BIN":
|
||||
self._import_from_bin_file(file_name)
|
||||
elif file_name[-4:].upper() == ".INI":
|
||||
self._import_from_ini_file(file_name)
|
||||
|
||||
def _import_from_file(self, file_name):
|
||||
def _import_from_bin_file(self, file_name):
|
||||
solver = Mage8("dummy")
|
||||
name = os.path.basename(file_name)\
|
||||
.replace(".BIN", "")
|
||||
@@ -305,9 +316,13 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||
|
||||
def _import_from_results(self, results):
|
||||
logger.debug(f"import from results: {results}")
|
||||
row = self.index_selected_row()
|
||||
self._table.import_from_results(results)
|
||||
self._update()
|
||||
|
||||
self._table.import_from_results(row, results)
|
||||
def _import_from_ini_file(self, file_name):
|
||||
logger.debug(f"import from INI file: {file_name}")
|
||||
self._table.read_from_ini(file_name)
|
||||
self._update()
|
||||
|
||||
def move_up(self):
|
||||
row = self.index_selected_row()
|
||||
|
||||
@@ -34,6 +34,15 @@ class ICTranslate(MainTranslate):
|
||||
self._dict["discharge"] = self._dict["unit_discharge"]
|
||||
self._dict["rk"] = self._dict["unit_rk"]
|
||||
|
||||
self._dict["open_file"] = _translate(
|
||||
"InitialCondition", "Open a file")
|
||||
self._dict["file_bin"] = _translate(
|
||||
"InitialCondition", "Mage results file (*.BIN)")
|
||||
self._dict["file_ini"] = _translate(
|
||||
"InitialCondition", "Mage initial conditions file (*.INI *.ini)")
|
||||
self._dict["file_all"] = _translate(
|
||||
"InitialCondition", "All files (*)")
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
# "name": _translate("InitialCondition", "Name"),
|
||||
"rk": self._dict["unit_rk"],
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
import logging
|
||||
import traceback
|
||||
|
||||
from tools import trace, timer
|
||||
from tools import trace, timer, old_pamhyr_date_to_timestamp
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel,
|
||||
@@ -38,7 +38,7 @@ from View.LateralContribution.UndoCommand import (
|
||||
SetNameCommand, SetEdgeCommand, SetTypeCommand,
|
||||
SetBeginCommand, SetEndCommand,
|
||||
AddCommand, DelCommand, SortCommand,
|
||||
MoveCommand, PasteCommand, DuplicateCommand,
|
||||
MoveCommand, PasteCommand, DuplicateCommand, ImportCommand,
|
||||
)
|
||||
|
||||
from Model.LateralContribution.LateralContributionTypes import (
|
||||
@@ -116,17 +116,20 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
def setModelData(self, editor, model, index):
|
||||
text = str(editor.currentText())
|
||||
|
||||
if self._mode == "rk":
|
||||
profiles = list(
|
||||
filter(
|
||||
lambda p: p.display_name() == text,
|
||||
self._data.reach.profiles
|
||||
)
|
||||
)
|
||||
|
||||
value = profiles[0].rk if len(profiles) > 0 else None
|
||||
else:
|
||||
if self._data is None:
|
||||
value = text
|
||||
else:
|
||||
if self._mode == "rk" and self._data.reach is not None:
|
||||
profiles = list(
|
||||
filter(
|
||||
lambda p: p.display_name() == text,
|
||||
self._data.reach.profiles
|
||||
)
|
||||
)
|
||||
|
||||
value = profiles[0].rk if len(profiles) > 0 else None
|
||||
else:
|
||||
value = text
|
||||
|
||||
model.setData(index, value)
|
||||
editor.close()
|
||||
@@ -293,3 +296,44 @@ class TableModel(PamhyrTableModel):
|
||||
|
||||
self.endMoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def read_from_lat(self, file_name):
|
||||
logger.debug(f"Import lateral contributions from {file_name}")
|
||||
data = []
|
||||
current_reach = -1
|
||||
with open(file_name, encoding="utf-8") as lat_file:
|
||||
for line in lat_file:
|
||||
if not (line.startswith("#") or
|
||||
line.startswith("*") or
|
||||
len(line) < 1):
|
||||
line = line.split()
|
||||
if line[0] == "$":
|
||||
current_reach = int(line[1]) - 1
|
||||
if (current_reach <= len(self._data.enable_edges()) and
|
||||
current_reach >= 0):
|
||||
data.append(
|
||||
[self._data.enable_edges()[current_reach],
|
||||
float(line[2]),
|
||||
float(line[3])
|
||||
]
|
||||
)
|
||||
else:
|
||||
if (current_reach <= len(self._data.enable_edges()) and
|
||||
current_reach >= 0):
|
||||
data[-1].append(
|
||||
[
|
||||
old_pamhyr_date_to_timestamp(line[0]),
|
||||
float(line[1])
|
||||
]
|
||||
)
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
self._undo.push(
|
||||
ImportCommand(
|
||||
self._lst, self._tab, data
|
||||
)
|
||||
)
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.layoutChanged.emit()
|
||||
@@ -28,6 +28,10 @@ from Model.LateralContribution.LateralContributionList import (
|
||||
LateralContributionList
|
||||
)
|
||||
|
||||
from Model.LateralContribution.LateralContributionTypes import (
|
||||
NotDefined, LateralContrib,
|
||||
)
|
||||
|
||||
|
||||
class SetNameCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, index, new_value):
|
||||
@@ -143,13 +147,13 @@ class DelCommand(QUndoCommand):
|
||||
self._tab = tab
|
||||
self._rows = rows
|
||||
|
||||
self._bc = []
|
||||
self._lc = []
|
||||
for row in rows:
|
||||
self._bc.append((row, self._lcs.get(self._tab, row)))
|
||||
self._bc.sort()
|
||||
self._lc.append((row, self._lcs.get(self._tab, row)))
|
||||
self._lc.sort()
|
||||
|
||||
def undo(self):
|
||||
for row, el in self._bc:
|
||||
for row, el in self._lc:
|
||||
self._lcs.insert(self._tab, row, el)
|
||||
|
||||
def redo(self):
|
||||
@@ -213,36 +217,73 @@ class MoveCommand(QUndoCommand):
|
||||
|
||||
|
||||
class PasteCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, row, bc):
|
||||
def __init__(self, lcs, tab, row, lc):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._row = row
|
||||
self._bc = deepcopy(bc)
|
||||
self._bc.reverse()
|
||||
self._lc = deepcopy(lc)
|
||||
self._lc.reverse()
|
||||
|
||||
def undo(self):
|
||||
self._lcs.delete(self._tab, self._bc)
|
||||
self._lcs.delete(self._tab, self._lc)
|
||||
|
||||
def redo(self):
|
||||
for bc in self._bc:
|
||||
self._lcs.insert(self._tab, self._row, bc)
|
||||
for lc in self._lc:
|
||||
self._lcs.insert(self._tab, self._row, lc)
|
||||
|
||||
|
||||
class ImportCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, data):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._tab = tab
|
||||
self._lcs = lcs
|
||||
self._data = data
|
||||
self._old_rows = list(range(len(self._lcs.get_tab(self._tab))))
|
||||
self._new_rows = list(range(len(self._data)))
|
||||
|
||||
self._new_lc = None
|
||||
self._old_lc = []
|
||||
for row in self._old_rows:
|
||||
self._old_lc.append((row, self._lcs.get(self._tab, row)))
|
||||
|
||||
def undo(self):
|
||||
self._lcs.delete_i(self._tab, self._new_rows)
|
||||
for row, el in self._old_lc:
|
||||
self._lcs.insert(self._tab, row, el)
|
||||
|
||||
def redo(self):
|
||||
self._lcs.delete_i(self._tab, self._old_rows)
|
||||
if self._new_lc is None:
|
||||
self._new_lc = []
|
||||
for row, data in enumerate(self._data):
|
||||
new = LateralContrib(status=self._lcs._status)
|
||||
new.edge = data[0]
|
||||
new.begin_rk = data[1]
|
||||
new.end_rk = data[2]
|
||||
for i, val in enumerate(data[3:]):
|
||||
new.insert(i, val)
|
||||
self._new_lc.append(new)
|
||||
|
||||
for row, el in enumerate(self._new_lc):
|
||||
self._lcs.insert(self._tab, row, el)
|
||||
|
||||
|
||||
class DuplicateCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, rows, bc):
|
||||
def __init__(self, lcs, tab, rows, lc):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._rows = rows
|
||||
self._bc = deepcopy(bc)
|
||||
self._bc.reverse()
|
||||
self._lc = deepcopy(lc)
|
||||
self._lc.reverse()
|
||||
|
||||
def undo(self):
|
||||
self._lcs.delete(self._tab, self._bc)
|
||||
self._lcs.delete(self._tab, self._lc)
|
||||
|
||||
def redo(self):
|
||||
for bc in self._lcs:
|
||||
self._lcs.insert(self._tab, self._rows[0], bc)
|
||||
for lc in self._lcs:
|
||||
self._lcs.insert(self._tab, self._rows[0], lc)
|
||||
@@ -22,6 +22,7 @@ from tools import trace, timer
|
||||
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
|
||||
from PyQt5 import QtWidgets
|
||||
from PyQt5.QtGui import (
|
||||
QKeySequence,
|
||||
)
|
||||
@@ -29,7 +30,7 @@ from PyQt5.QtGui import (
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel,
|
||||
QCoreApplication, QModelIndex, pyqtSlot,
|
||||
QRect,
|
||||
QRect, QSettings,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
@@ -153,6 +154,8 @@ class LateralContributionWindow(PamhyrWindow):
|
||||
)
|
||||
|
||||
def setup_connections(self):
|
||||
self.find(QAction, "action_import").triggered.connect(
|
||||
self.import_from_file)
|
||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||
self.find(QAction, "action_del").triggered.connect(self.delete)
|
||||
self.find(QAction, "action_edit").triggered.connect(self.edit)
|
||||
@@ -297,3 +300,26 @@ class LateralContributionWindow(PamhyrWindow):
|
||||
parent=self
|
||||
)
|
||||
win.show()
|
||||
|
||||
def import_from_file(self):
|
||||
options = QFileDialog.Options()
|
||||
settings = QSettings(QSettings.IniFormat,
|
||||
QSettings.UserScope, 'MyOrg', )
|
||||
options |= QFileDialog.DontUseNativeDialog
|
||||
|
||||
file_types = [
|
||||
self._trad["file_lat"],
|
||||
self._trad["file_all"],
|
||||
]
|
||||
|
||||
filename, _ = QtWidgets.QFileDialog.getOpenFileName(
|
||||
self,
|
||||
self._trad["open_file"],
|
||||
"",
|
||||
";; ".join(file_types),
|
||||
options=options
|
||||
)
|
||||
|
||||
if filename != "":
|
||||
tab = self.current_tab()
|
||||
self._table[tab].read_from_lat(filename)
|
||||
@@ -52,6 +52,11 @@ class LCTranslate(MainTranslate):
|
||||
self._dict["x"] = _translate("Geometry", "X (m)")
|
||||
self._dict["y"] = _translate("Geometry", "Y (m)")
|
||||
self._dict["z"] = _translate("Geometry", "Z (m)")
|
||||
self._dict["file_lat"] = _translate(
|
||||
"LateralContribution",
|
||||
"Mage lateral contributions file (*.LAT *.lat)")
|
||||
self._dict["file_all"] = _translate(
|
||||
"LateralContribution", "All files (*)")
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
"name": self._dict["name"],
|
||||
|
||||
+17
-6
@@ -30,6 +30,7 @@ from platformdirs import user_cache_dir
|
||||
|
||||
from Solver.AdisTS import AdisTS
|
||||
from Solver.Mage import Mage8
|
||||
from Solver.RubarBE import Rubar3
|
||||
from tools import logger_exception
|
||||
|
||||
from PyQt5 import QtGui
|
||||
@@ -194,10 +195,10 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
title = "(dbg) " if self.conf.debug else ""
|
||||
|
||||
if self._study is not None:
|
||||
title += f"Pamhyr2 - {self._study.name}"
|
||||
title += f"Pamhyr2 (Claude François) - {self._study.name}"
|
||||
self.setWindowTitle(title)
|
||||
else:
|
||||
title += "Pamhyr2"
|
||||
title += "Pamhyr2 (Claude François)"
|
||||
self.setWindowTitle(title)
|
||||
|
||||
def setup_tab(self):
|
||||
@@ -1414,7 +1415,10 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
if type(results) is str:
|
||||
logger.info(f"Open results from {os.path.dirname(results)}")
|
||||
|
||||
name = os.path.basename(results).replace(".BIN", "")
|
||||
if ".BIN" in results:
|
||||
name = os.path.basename(results).replace(".BIN", "")
|
||||
elif "profil." in results:
|
||||
name = os.path.basename(results).replace("profil.", "")
|
||||
|
||||
def reading_fn():
|
||||
self._tmp_results = solver.results(
|
||||
@@ -1545,7 +1549,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
dialog.setFileMode(QFileDialog.FileMode.ExistingFile)
|
||||
dialog.setDefaultSuffix(".BIN")
|
||||
# dialog.setFilter(dialog.filter() | QtCore.QDir.Hidden)
|
||||
dialog.setNameFilters(['Mage (*.BIN)'])
|
||||
dialog.setNameFilters(['Mage (*.BIN)', 'Rubar3 (profil.*)'])
|
||||
|
||||
if self._study.filename is not None:
|
||||
if self._last_solver is None:
|
||||
@@ -1559,9 +1563,16 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
|
||||
if dialog.exec_():
|
||||
file_name = dialog.selectedFiles()
|
||||
logger.info(f"Select results: {file_name}")
|
||||
logger.info(f"Select results: {file_name[0]}")
|
||||
|
||||
solver = None
|
||||
if ".BIN" in file_name[0]:
|
||||
solver = Mage8("Mage8")
|
||||
else:
|
||||
solver = Rubar3("Rubar3")
|
||||
|
||||
self.open_solver_results(
|
||||
Mage8("Mage"),
|
||||
solver,
|
||||
results=file_name[0]
|
||||
)
|
||||
|
||||
|
||||
@@ -475,7 +475,7 @@ class GraphWidget(QGraphicsView):
|
||||
def setup_scene(self, min_size, max_size, size):
|
||||
scene = QGraphicsScene(self)
|
||||
scene.setItemIndexMethod(QGraphicsScene.NoIndex)
|
||||
scene.setSceneRect(0, 0, 2000, 2000)
|
||||
scene.setSceneRect(0, 0, 6000, 6000)
|
||||
|
||||
self.setScene(scene)
|
||||
self.setCacheMode(QGraphicsView.CacheBackground)
|
||||
@@ -486,6 +486,7 @@ class GraphWidget(QGraphicsView):
|
||||
|
||||
self.scale(1, 1)
|
||||
self.previousScale = 1
|
||||
self.centerOn(1000.0, 1000.0)
|
||||
|
||||
if min_size:
|
||||
self.setMinimumSize(*min_size)
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
from View.Tools.PamhyrWindow import PamhyrDialog
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QRadioButton, QCheckBox, QVBoxLayout, QLabel,
|
||||
QRadioButton, QCheckBox, QVBoxLayout, QLabel, QFrame
|
||||
)
|
||||
|
||||
from View.Results.translate import ResultsTranslate
|
||||
@@ -43,6 +43,7 @@ class CustomExportDialog(PamhyrDialog):
|
||||
|
||||
self.setup_radio_buttons_x()
|
||||
self.setup_radio_buttons_res()
|
||||
self.setup_label()
|
||||
self.setup_envelop_box()
|
||||
self.setup_check_boxes()
|
||||
|
||||
@@ -87,6 +88,22 @@ class CustomExportDialog(PamhyrDialog):
|
||||
|
||||
layout.addStretch()
|
||||
|
||||
def setup_label(self):
|
||||
self._label = self.find(QLabel, "label_4")
|
||||
self._label.setFrameStyle(QFrame.StyledPanel)
|
||||
self._label.setStyleSheet('background-color: white')
|
||||
self.set_label()
|
||||
for r in self._radio:
|
||||
r[1].clicked.connect(self.set_label)
|
||||
|
||||
def set_label(self):
|
||||
if self._radio[0][1].isChecked():
|
||||
self._label.setText(self._parent.text_bief() + "\n" +
|
||||
self._parent.text_time())
|
||||
else:
|
||||
self._label.setText(self._parent.text_bief() + "\n" +
|
||||
self._parent.text_profile())
|
||||
|
||||
def setup_envelop_box(self):
|
||||
layout = self.find(QVBoxLayout, "verticalLayout_x")
|
||||
self._envelop = QCheckBox(
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
from View.Tools.PamhyrWindow import PamhyrDialog
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QRadioButton, QCheckBox, QVBoxLayout,
|
||||
QRadioButton, QCheckBox, QVBoxLayout, QLabel, QFrame
|
||||
)
|
||||
|
||||
from View.Results.translate import ResultsTranslate
|
||||
@@ -50,6 +50,7 @@ class CustomExportAdisDialog(PamhyrDialog):
|
||||
|
||||
self.setup_radio_buttons_x()
|
||||
self.setup_radio_buttons_pol()
|
||||
self.setup_label()
|
||||
self.setup_check_boxes()
|
||||
|
||||
self.value = None
|
||||
@@ -84,6 +85,22 @@ class CustomExportAdisDialog(PamhyrDialog):
|
||||
self._radio2[0][1].setChecked(True)
|
||||
layout.addStretch()
|
||||
|
||||
def setup_label(self):
|
||||
self._label = self.find(QLabel, "label_4")
|
||||
self._label.setFrameStyle(QFrame.StyledPanel)
|
||||
self._label.setStyleSheet('background-color: white')
|
||||
self.set_label()
|
||||
for r in self._radio:
|
||||
r[1].clicked.connect(self.set_label)
|
||||
|
||||
def set_label(self):
|
||||
if self._radio[0][1].isChecked():
|
||||
self._label.setText(self._parent.text_bief() + "\n" +
|
||||
self._parent.text_time())
|
||||
else:
|
||||
self._label.setText(self._parent.text_bief() + "\n" +
|
||||
self._parent.text_profile())
|
||||
|
||||
def setup_check_boxes(self):
|
||||
self._check = []
|
||||
layout = self.find(QVBoxLayout, "verticalLayout_y")
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
from View.Tools.PamhyrWindow import PamhyrDialog
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QRadioButton, QCheckBox, QVBoxLayout,
|
||||
QRadioButton, QCheckBox, QVBoxLayout, QLabel, QFrame
|
||||
)
|
||||
|
||||
from View.Results.CustomPlot.Translate import CustomPlotTranslate
|
||||
@@ -38,10 +38,12 @@ class CustomPlotValuesSelectionDialog(PamhyrDialog):
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self._parent = parent
|
||||
self._available_values_x = self._trad.get_dict("values_x")
|
||||
self._available_values_y = self._trad.get_dict("values_y")
|
||||
|
||||
self.setup_radio_buttons()
|
||||
self.setup_label()
|
||||
self.setup_envelop_box()
|
||||
self.setup_check_boxs()
|
||||
|
||||
@@ -62,6 +64,22 @@ class CustomPlotValuesSelectionDialog(PamhyrDialog):
|
||||
self._radio[0][1].setChecked(True)
|
||||
layout.addStretch()
|
||||
|
||||
def setup_label(self):
|
||||
self._label = self.find(QLabel, "label_3")
|
||||
self._label.setFrameStyle(QFrame.StyledPanel)
|
||||
self._label.setStyleSheet('background-color: white')
|
||||
self.set_label()
|
||||
for r in self._radio:
|
||||
r[1].clicked.connect(self.set_label)
|
||||
|
||||
def set_label(self):
|
||||
if self._radio[0][1].isChecked():
|
||||
self._label.setText(self._parent.text_bief() + "\n" +
|
||||
self._parent.text_time())
|
||||
else:
|
||||
self._label.setText(self._parent.text_bief() + "\n" +
|
||||
self._parent.text_profile())
|
||||
|
||||
def setup_envelop_box(self):
|
||||
self._envelop = []
|
||||
layout = self.find(QVBoxLayout, "verticalLayout_x")
|
||||
|
||||
@@ -116,7 +116,7 @@ class PlotAC(PamhyrPlot):
|
||||
|
||||
self.collection = self.canvas.axes.fill_between(
|
||||
x, z, water_z,
|
||||
where=z <= water_z,
|
||||
where=list(map(lambda x: x <= water_z, z)),
|
||||
color=self.color_plot_river_water_zone,
|
||||
alpha=0.7, interpolate=True
|
||||
)
|
||||
@@ -150,8 +150,17 @@ class PlotAC(PamhyrPlot):
|
||||
self.annotation = []
|
||||
self.cgl, self.igl = reach.geometry.compute_guidelines()
|
||||
|
||||
lcomplete = list(self.cgl)
|
||||
lincomplete = list(self.igl)
|
||||
# we make sure that the lines are in the left-to-right order
|
||||
lcomplete = [
|
||||
x.name
|
||||
for x in profile.geometry.named_points()
|
||||
if x.name in self.cgl
|
||||
]
|
||||
lincomplete = [
|
||||
x.name
|
||||
for x in profile.geometry.named_points()
|
||||
if x.name in self.igl
|
||||
]
|
||||
|
||||
self.color_complete_gl = self.colors
|
||||
self.color_incomplete_gl = 2 * ["grey"]
|
||||
@@ -171,7 +180,7 @@ class PlotAC(PamhyrPlot):
|
||||
]
|
||||
else:
|
||||
color = self.color_incomplete_gl[
|
||||
lincomplete.index(txt)
|
||||
lincomplete.index(txt) % len(self.color_incomplete_gl)
|
||||
]
|
||||
|
||||
annotation = self.canvas.axes.annotate(
|
||||
@@ -254,7 +263,7 @@ class PlotAC(PamhyrPlot):
|
||||
self.collection.remove()
|
||||
self.collection = self.canvas.axes.fill_between(
|
||||
x, z, water_z,
|
||||
where=z <= water_z,
|
||||
where=list(map(lambda x: x <= water_z, z)),
|
||||
color=self.color_plot_river_water_zone,
|
||||
alpha=0.7, interpolate=True
|
||||
)
|
||||
|
||||
@@ -23,6 +23,8 @@ from numpy import sqrt
|
||||
|
||||
from tools import timer, trace
|
||||
|
||||
from itertools import compress
|
||||
|
||||
from PyQt5.QtGui import (
|
||||
QKeySequence, QColor
|
||||
)
|
||||
@@ -51,8 +53,12 @@ class TableModel(PamhyrTableModel):
|
||||
self._lst = _river.reachs
|
||||
elif self._opt_data == "profile":
|
||||
self._lst = _river.reach(0).profiles
|
||||
# self._lst = list(filter(lambda x: x.name[0:8] != 'interpol',
|
||||
# _river.reach(0).profiles))
|
||||
elif self._opt_data == "raw_data":
|
||||
self._lst = _river.reach(0).profiles
|
||||
# self._lst = list(filter(lambda x: x.name[0:8] != 'interpol',
|
||||
# _river.reach(0).profiles))
|
||||
elif self._opt_data == "solver":
|
||||
self._lst = self._parent._solvers
|
||||
|
||||
|
||||
+75
-82
@@ -19,7 +19,7 @@
|
||||
import os
|
||||
import csv
|
||||
import logging
|
||||
import rasterio
|
||||
# import rasterio
|
||||
|
||||
from numpy import sqrt
|
||||
|
||||
@@ -288,16 +288,12 @@ class ResultsWindow(PamhyrWindow):
|
||||
super(ResultsWindow, self).closeEvent(event)
|
||||
|
||||
def _compute_status_label(self):
|
||||
# Timestamp
|
||||
ts = self._timestamps[self._slider_time.value()]
|
||||
|
||||
t0 = datetime.fromtimestamp(0)
|
||||
fts = str(
|
||||
datetime.fromtimestamp(ts) - t0
|
||||
)
|
||||
fts.replace("days", _translate("Results", "days"))\
|
||||
.replace("day", _translate("Results", "day"))
|
||||
return (self.text_bief() + " | " +
|
||||
self.text_profile() + " | " +
|
||||
self.text_time())
|
||||
|
||||
def text_bief(self):
|
||||
# Reach
|
||||
table = self.find(QTableView, f"tableView_reach")
|
||||
indexes = table.selectedIndexes()
|
||||
@@ -305,7 +301,16 @@ class ResultsWindow(PamhyrWindow):
|
||||
reach = self._study.river.enable_edges()[0]
|
||||
else:
|
||||
reach = self._study.river.enable_edges()[indexes[0].row()]
|
||||
return f"{self._trad['reach']}: {reach.name}"
|
||||
|
||||
def text_profile(self):
|
||||
# Reach
|
||||
table = self.find(QTableView, f"tableView_reach")
|
||||
indexes = table.selectedIndexes()
|
||||
if len(indexes) == 0:
|
||||
reach = self._study.river.enable_edges()[0]
|
||||
else:
|
||||
reach = self._study.river.enable_edges()[indexes[0].row()]
|
||||
# Profile
|
||||
table = self.find(QTableView, f"tableView_profile")
|
||||
indexes = table.selectedIndexes()
|
||||
@@ -315,10 +320,22 @@ class ResultsWindow(PamhyrWindow):
|
||||
profile = reach.reach.profile(indexes[0].row())
|
||||
|
||||
pname = profile.name if profile.name != "" else profile.rk
|
||||
return f"{self._trad['cross_section']}: {pname}"
|
||||
|
||||
return (f"{self._trad['reach']}: {reach.name} | " +
|
||||
f"{self._trad['cross_section']}: {pname} | " +
|
||||
f"{self._trad['unit_time_s']} : {fts} ({ts} sec)")
|
||||
def text_time(self):
|
||||
# Timestamp
|
||||
ts = self._timestamps[self._slider_time.value()]
|
||||
|
||||
t0 = datetime.fromtimestamp(0)
|
||||
fts = str(
|
||||
datetime.fromtimestamp(ts) - t0
|
||||
)
|
||||
fts = str(
|
||||
datetime.fromtimestamp(ts) - t0
|
||||
)
|
||||
fts.replace("days", _translate("Results", "days"))\
|
||||
.replace("day", _translate("Results", "day"))
|
||||
return f"{self._trad['time']} : {fts} ({ts} sec)"
|
||||
|
||||
def setup_statusbar(self):
|
||||
txt = self._compute_status_label()
|
||||
@@ -338,6 +355,8 @@ class ResultsWindow(PamhyrWindow):
|
||||
# "action_export": self.export_current,
|
||||
"action_Geo_tiff": self.import_geotiff
|
||||
}
|
||||
self.find(QAction, "action_Geo_tiff").setEnabled(False)
|
||||
self.find(QAction, "action_Geo_tiff").setVisible(False)
|
||||
|
||||
if len(self._results) > 1:
|
||||
self.find(QAction, "action_reload").setEnabled(False)
|
||||
@@ -494,7 +513,7 @@ class ResultsWindow(PamhyrWindow):
|
||||
table = self.find(QTableView, f"tableView_profile")
|
||||
indexes = table.selectedIndexes()
|
||||
if len(indexes) == 0:
|
||||
return 0
|
||||
return []
|
||||
|
||||
return [i.row() for i in indexes]
|
||||
|
||||
@@ -719,20 +738,29 @@ class ResultsWindow(PamhyrWindow):
|
||||
first_line.append(f"Profile: {pname}")
|
||||
val_dict = self._export_time(profile_id, y, solver_id)
|
||||
|
||||
with open(filename, 'w', newline='') as csvfile:
|
||||
writer = csv.writer(csvfile, delimiter=',',
|
||||
quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||
dict_x = self._trad.get_dict("values_x")
|
||||
header = []
|
||||
writer.writerow(first_line)
|
||||
for text in val_dict.keys():
|
||||
header.append(text)
|
||||
writer.writerow(header)
|
||||
for row in range(len(val_dict[dict_x[x]])):
|
||||
line = []
|
||||
for var in val_dict.keys():
|
||||
line.append(val_dict[var][row])
|
||||
writer.writerow(line)
|
||||
try:
|
||||
with open(filename, 'w', newline='') as csvfile:
|
||||
writer = csv.writer(csvfile, delimiter=',',
|
||||
quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||
dict_x = self._trad.get_dict("values_x")
|
||||
header = []
|
||||
writer.writerow(first_line)
|
||||
for text in val_dict.keys():
|
||||
header.append(text)
|
||||
writer.writerow(header)
|
||||
for row in range(len(val_dict[dict_x[x]])):
|
||||
line = []
|
||||
for var in val_dict.keys():
|
||||
line.append(val_dict[var][row])
|
||||
writer.writerow(line)
|
||||
self._timer.stop()
|
||||
except Exception as e:
|
||||
self.message_box(
|
||||
window_title=self._trad["Warning"],
|
||||
text=self._trad["mb_write_error"],
|
||||
informative_text=self._trad["mb_close_file"]
|
||||
)
|
||||
logger_exception(e)
|
||||
|
||||
def export_all(self, reach, directory, timestamps):
|
||||
name = reach.name
|
||||
@@ -745,17 +773,25 @@ class ResultsWindow(PamhyrWindow):
|
||||
f"reach_{name}.csv"
|
||||
)
|
||||
|
||||
with open(file_name, 'w', newline='') as csvfile:
|
||||
writer = csv.writer(csvfile, delimiter=',',
|
||||
quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||
ts = timestamps[0]
|
||||
writer.writerow(self._table["raw_data"]._headers)
|
||||
for row in range(self._table["raw_data"].rowCount()):
|
||||
line = []
|
||||
for column in range(self._table["raw_data"].columnCount()):
|
||||
index = self._table["raw_data"].index(row, column)
|
||||
line.append(self._table["raw_data"].data(index))
|
||||
writer.writerow(line)
|
||||
try:
|
||||
with open(file_name, 'w', newline='') as csvfile:
|
||||
writer = csv.writer(csvfile, delimiter=',',
|
||||
quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||
ts = timestamps[0]
|
||||
writer.writerow(self._table["raw_data"]._headers)
|
||||
for row in range(self._table["raw_data"].rowCount()):
|
||||
line = []
|
||||
for column in range(self._table["raw_data"].columnCount()):
|
||||
index = self._table["raw_data"].index(row, column)
|
||||
line.append(self._table["raw_data"].data(index))
|
||||
writer.writerow(line)
|
||||
except Exception as e:
|
||||
self.message_box(
|
||||
window_title=self._trad["Warning"],
|
||||
text=self._trad["mb_write_errore"],
|
||||
informative_text=self._trad["mb_close_file"]
|
||||
)
|
||||
logger_exception(e)
|
||||
|
||||
def export_current(self):
|
||||
self.file_dialog(
|
||||
@@ -1166,47 +1202,4 @@ class ResultsWindow(PamhyrWindow):
|
||||
self.update_table_selection_profile(profile_id)
|
||||
|
||||
def import_geotiff(self):
|
||||
options = QFileDialog.Options()
|
||||
settings = QSettings(QSettings.IniFormat,
|
||||
QSettings.UserScope, 'MyOrg', )
|
||||
options |= QFileDialog.DontUseNativeDialog
|
||||
|
||||
file_types = [
|
||||
self._trad["file_geotiff"],
|
||||
self._trad["file_all"],
|
||||
]
|
||||
|
||||
filename, _ = QFileDialog.getOpenFileName(
|
||||
self,
|
||||
self._trad["open_file"],
|
||||
"",
|
||||
";; ".join(file_types),
|
||||
options=options
|
||||
)
|
||||
|
||||
if filename != "":
|
||||
with rasterio.open(filename) as data:
|
||||
img = data.read()
|
||||
b = data.bounds[:]
|
||||
# b[0] left
|
||||
# b[1] bottom
|
||||
# b[2] right
|
||||
# b[3] top
|
||||
xlim = self.canvas.axes.get_xlim()
|
||||
ylim = self.canvas.axes.get_ylim()
|
||||
if b[2] > b[0] and b[1] < b[3]:
|
||||
self.canvas.axes.imshow(img.transpose((1, 2, 0)),
|
||||
extent=[b[0], b[2], b[1], b[3]])
|
||||
else:
|
||||
dlg = CoordinatesDialog(
|
||||
xlim,
|
||||
ylim,
|
||||
trad=self._trad,
|
||||
parent=self
|
||||
)
|
||||
if dlg.exec():
|
||||
self.canvas.axes.imshow(img.transpose((1, 2, 0)),
|
||||
extent=dlg.values)
|
||||
self.plot_xy.idle()
|
||||
self.canvas.axes.set_xlim(xlim)
|
||||
self.canvas.axes.set_ylim(ylim)
|
||||
return
|
||||
@@ -345,24 +345,29 @@ class ResultsWindowAdisTS(PamhyrWindow):
|
||||
super(ResultsWindowAdisTS, self).closeEvent(event)
|
||||
|
||||
def _compute_status_label(self):
|
||||
# Timestamp
|
||||
ts = self._timestamps[self._slider_time.value()]
|
||||
|
||||
t0 = datetime.fromtimestamp(0)
|
||||
fts = str(
|
||||
datetime.fromtimestamp(ts) - t0
|
||||
)
|
||||
fts.replace("days", _translate("Results", "days"))\
|
||||
.replace("day", _translate("Results", "day"))
|
||||
return (self.text_bief() + " | " +
|
||||
self.text_profile() + " | " +
|
||||
self.text_pollutant() + " | " +
|
||||
self.text_time())
|
||||
|
||||
def text_bief(self):
|
||||
# Reach
|
||||
table = self.find(QTableView, f"tableView_reach")
|
||||
indexes = table.selectedIndexes()
|
||||
if len(indexes) == 0:
|
||||
reach = self._study.river.edges()[0]
|
||||
reach = self._study.river.enable_edges()[0]
|
||||
else:
|
||||
reach = self._study.river.edges()[indexes[0].row()]
|
||||
reach = self._study.river.enable_edges()[indexes[0].row()]
|
||||
return f"{self._trad['reach']}: {reach.name}"
|
||||
|
||||
def text_profile(self):
|
||||
# Reach
|
||||
table = self.find(QTableView, f"tableView_reach")
|
||||
indexes = table.selectedIndexes()
|
||||
if len(indexes) == 0:
|
||||
reach = self._study.river.enable_edges()[0]
|
||||
else:
|
||||
reach = self._study.river.enable_edges()[indexes[0].row()]
|
||||
# Profile
|
||||
table = self.find(QTableView, f"tableView_profile")
|
||||
indexes = table.selectedIndexes()
|
||||
@@ -372,7 +377,24 @@ class ResultsWindowAdisTS(PamhyrWindow):
|
||||
profile = reach.reach.profile(indexes[0].row())
|
||||
|
||||
pname = profile.name if profile.name != "" else profile.rk
|
||||
return f"{self._trad['cross_section']}: {pname}"
|
||||
|
||||
def text_time(self):
|
||||
# Timestamp
|
||||
ts = self._timestamps[self._slider_time.value()]
|
||||
|
||||
t0 = datetime.fromtimestamp(0)
|
||||
fts = str(
|
||||
datetime.fromtimestamp(ts) - t0
|
||||
)
|
||||
fts = str(
|
||||
datetime.fromtimestamp(ts) - t0
|
||||
)
|
||||
fts.replace("days", _translate("Results", "days"))\
|
||||
.replace("day", _translate("Results", "day"))
|
||||
return f"{self._trad['time']} : {fts} ({ts} sec)"
|
||||
|
||||
def text_pollutant(self):
|
||||
# Pollutant
|
||||
table = self.find(QTableView, f"tableView_pollutants")
|
||||
indexes = table.selectedIndexes()
|
||||
@@ -381,10 +403,7 @@ class ResultsWindowAdisTS(PamhyrWindow):
|
||||
self._results.pollutants_list[i.row()+1] for i in indexes
|
||||
]
|
||||
|
||||
return (f"{self._trad['reach']}: {reach.name} | " +
|
||||
f"{self._trad['cross_section']}: {pname} | " +
|
||||
f"Pollutant: {', '.join(self.pollutant_label)} | " +
|
||||
f"{self._trad['unit_time_s']} : {fts} ({ts} sec)")
|
||||
return (f"Pollutant: {', '.join(self.pollutant_label)}")
|
||||
|
||||
def setup_statusbar(self):
|
||||
txt = self._compute_status_label()
|
||||
|
||||
@@ -59,6 +59,13 @@ class ResultsTranslate(MainTranslate):
|
||||
self._dict["ImageCoordinates"] = _translate(
|
||||
"Results", "Image coordinates"
|
||||
)
|
||||
self._dict["mb_write_error"] = _translate(
|
||||
"Results", "An error occured when writing to file"
|
||||
)
|
||||
self._dict["mb_close_file"] = _translate(
|
||||
"Results",
|
||||
"If the file is in use, close it and try again"
|
||||
)
|
||||
|
||||
self._sub_dict["table_headers_reach"] = {
|
||||
"name": _translate("Results", "Reach name"),
|
||||
|
||||
@@ -486,7 +486,8 @@ class SolverLogWindow(PamhyrWindow):
|
||||
if self._results is None:
|
||||
def reading_fn():
|
||||
self._results = self._solver.results(
|
||||
self._study, self._workdir, qlog=self._output
|
||||
self._study, self._workdir,
|
||||
qlog=self._output, name=self._study.name
|
||||
)
|
||||
|
||||
dlg = ReadingResultsDialog(reading_fn=reading_fn, parent=self)
|
||||
|
||||
@@ -82,7 +82,7 @@ class SelectSolverWindowAdisTS(PamhyrDialog):
|
||||
# solvers = self._config.solvers
|
||||
# solvers mage
|
||||
solvers = list(filter(
|
||||
lambda x: "mage" not in x._type, self._config.solvers
|
||||
lambda x: "adists" in x._type, self._config.solvers
|
||||
))
|
||||
solvers_name = list(
|
||||
map(
|
||||
@@ -92,7 +92,8 @@ class SelectSolverWindowAdisTS(PamhyrDialog):
|
||||
)
|
||||
|
||||
solvers_mage = list(filter(
|
||||
lambda x: "mage" in x._type.lower(), self._config.solvers
|
||||
lambda x: "mage" or "rubar" in x._type.lower(),
|
||||
self._config.solvers
|
||||
))
|
||||
solvers_mage_names = list(map(lambda x: x._name, solvers_mage))
|
||||
|
||||
|
||||
@@ -7,23 +7,13 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>194</width>
|
||||
<height>70</height>
|
||||
<height>126</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="4" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
@@ -64,6 +54,23 @@
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
||||
@@ -7,14 +7,24 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>414</width>
|
||||
<height>70</height>
|
||||
<height>132</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@@ -43,13 +53,10 @@
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="action_import"/>
|
||||
<addaction name="action_add"/>
|
||||
<addaction name="action_del"/>
|
||||
<addaction name="action_sort"/>
|
||||
@@ -149,6 +150,18 @@
|
||||
<string>Remove points to make the curve increasing</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_import">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>ressources/import.png</normaloff>ressources/import.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Import</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Import from file</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@@ -112,6 +112,18 @@
|
||||
<string>Sort points</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_import">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>ressources/import.png</normaloff>ressources/import.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Import</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Import from file</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="action_import"/>
|
||||
<addaction name="action_add"/>
|
||||
<addaction name="action_del"/>
|
||||
<addaction name="action_sort"/>
|
||||
@@ -107,6 +108,18 @@
|
||||
<string>Ctrl+E</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_import">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>ressources/import.png</normaloff>ressources/import.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Import</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Import from file</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Upstream height (m)</string>
|
||||
<string>Upstream elevation (m)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -70,7 +70,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Downstream height (m)</string>
|
||||
<string>Downstream elevation (m)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -97,6 +97,7 @@
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="action_import"/>
|
||||
<addaction name="action_add"/>
|
||||
<addaction name="action_del"/>
|
||||
<addaction name="action_edit"/>
|
||||
@@ -162,6 +163,18 @@
|
||||
<string>Sort by names</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_import">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>ressources/import.png</normaloff>ressources/import.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Import</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Import from file</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@@ -7,24 +7,14 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>520</width>
|
||||
<height>341</height>
|
||||
<height>245</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="3" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="1" column="0">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Parameters</string>
|
||||
@@ -79,7 +69,7 @@
|
||||
<string>Spline</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -88,6 +78,9 @@
|
||||
<property name="text">
|
||||
<string>Linear</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@@ -108,47 +101,14 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>Guideline used for distance computation</string>
|
||||
<item row="2" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Second guideline</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>First guideline</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="comboBox_end_gl">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="comboBox_begin_gl">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
|
||||
+46
-7
@@ -37,7 +37,7 @@ logger = logging.getLogger()
|
||||
|
||||
class Config(SQL):
|
||||
def __init__(self):
|
||||
self._version = '0.0.6'
|
||||
self._version = '0.0.7'
|
||||
self.filename = Config.filename()
|
||||
self.set_default_value()
|
||||
|
||||
@@ -101,6 +101,7 @@ class Config(SQL):
|
||||
# Add default solver
|
||||
posix = os.name == 'posix'
|
||||
ext = "" if posix else ".exe"
|
||||
path = os.path.join("@install_dir", "mage8", f"mage{ext}")
|
||||
|
||||
self.execute(f"""
|
||||
INSERT INTO solver VALUES (
|
||||
@@ -111,7 +112,7 @@ class Config(SQL):
|
||||
'', '', '',
|
||||
|
||||
'',
|
||||
'@install_dir/mage/mage{ext} @args @input',
|
||||
'{path} @args @input',
|
||||
''
|
||||
)
|
||||
""")
|
||||
@@ -135,16 +136,19 @@ class Config(SQL):
|
||||
if int(release) < 5:
|
||||
posix = os.name == 'posix'
|
||||
ext = "" if posix else ".exe"
|
||||
path = os.path.join("@install_dir", "mage8", f"mage{ext}")
|
||||
|
||||
self.execute(
|
||||
"UPDATE solver SET cmd_solver=" +
|
||||
f"'@install_dir/mage8/mage{ext} @args @input' "
|
||||
f"'{path} @args @input' "
|
||||
"WHERE name='default-mage'"
|
||||
)
|
||||
|
||||
if int(release) < 6:
|
||||
posix = os.name == 'posix'
|
||||
ext = "" if posix else ".exe"
|
||||
path = os.path.join("@install_dir",
|
||||
"adists", f"adists{ext}")
|
||||
|
||||
self.execute(f"""
|
||||
INSERT INTO solver VALUES (
|
||||
@@ -155,16 +159,41 @@ class Config(SQL):
|
||||
'', '', '',
|
||||
|
||||
'',
|
||||
'@install_dir/adists/adists{ext} @args @input',
|
||||
'{path} @args @input',
|
||||
''
|
||||
)
|
||||
""")
|
||||
self.execute(
|
||||
"UPDATE solver SET cmd_solver=" +
|
||||
f"'@install_dir/adists/adists{ext} @args @input' "
|
||||
f"'{path} @args @input' "
|
||||
"WHERE name='default-AdisTS'"
|
||||
)
|
||||
|
||||
if int(release) < 7:
|
||||
posix = os.name == 'posix'
|
||||
ext = "" if posix else ".exe"
|
||||
path = os.path.join("@install_dir",
|
||||
"rubar", f"rubarbe{ext}")
|
||||
|
||||
self.execute(f"""
|
||||
INSERT INTO solver VALUES (
|
||||
'rubar3',
|
||||
'default-Rubar3',
|
||||
'Default Pamhyr2 Rubar 3 version',
|
||||
|
||||
'', '', '',
|
||||
|
||||
'',
|
||||
'{path} @args @input',
|
||||
''
|
||||
)
|
||||
""")
|
||||
self.execute(
|
||||
"UPDATE solver SET cmd_solver=" +
|
||||
f"'{path} @args @input' "
|
||||
"WHERE name='default-Rubar3'"
|
||||
)
|
||||
|
||||
self.execute(
|
||||
f"UPDATE info SET value='{self._version}' " +
|
||||
"WHERE key='version'"
|
||||
@@ -327,14 +356,24 @@ class Config(SQL):
|
||||
ctor = solver_type_list["mage8"]
|
||||
new = ctor("default-mage")
|
||||
new._description = "Default Pamhyr2 mage 8 version"
|
||||
new._cmd_solver = f""""@install_dir/mage8/mage{ext}" @args @input"""
|
||||
path = os.path.join("@install_dir", "mage8", "mage")
|
||||
new._cmd_solver = f""""{path}{ext}" @args @input"""
|
||||
self._solvers.append(new)
|
||||
|
||||
# AdisTS
|
||||
ctor = solver_type_list["adistswc"]
|
||||
new = ctor("default-AdisTS")
|
||||
new._description = "Default Pamhyr2 AdisTS version"
|
||||
new._cmd_solver = f""""@install_dir/adists/adists{ext}" @args @input"""
|
||||
path = os.path.join("@install_dir", "adists", "adists")
|
||||
new._cmd_solver = f""""{path}{ext}" @args @input"""
|
||||
self._solvers.append(new)
|
||||
|
||||
# Rubar3
|
||||
ctor = solver_type_list["rubar3"]
|
||||
new = ctor("default-Rubar3")
|
||||
new._description = "Default Pamhyr2 Rubar 3 version"
|
||||
path = os.path.join("@install_dir", "rubar", f"rubarbe{ext}")
|
||||
new._cmd_solver = f""""{path}" @args @input"""
|
||||
self._solvers.append(new)
|
||||
|
||||
# Mage fake 7
|
||||
|
||||
+258
-134
File diff suppressed because it is too large.
Load diff
+4
-1
@@ -260,7 +260,10 @@ def date_dmy_to_timestamp(date: str):
|
||||
def old_pamhyr_date_to_timestamp(date: str):
|
||||
v = date.split(":")
|
||||
if len(v) != 4:
|
||||
return 0
|
||||
if len(v) == 1: # minutes
|
||||
return int(float(v[0]) * 60) # Minute to sec
|
||||
else:
|
||||
return 0
|
||||
|
||||
m = [
|
||||
(24 * 60 * 60), # Day to sec
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user