wolfhece 2.1.100__py3-none-any.whl → 2.1.102__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wolfhece/PyDraw.py +207 -16
- wolfhece/PyGui.py +1039 -53
- wolfhece/Results2DGPU.py +37 -13
- wolfhece/acceptability/func.py +43 -32
- wolfhece/apps/version.py +1 -1
- wolfhece/bernoulli/losses.py +3 -3
- wolfhece/gpuview.py +4 -1
- wolfhece/libs/__init__.py +11 -10
- wolfhece/libs/wolfogl.cp310-win_amd64.pyd +0 -0
- wolfhece/math_parser/calculator.py +5 -4
- wolfhece/mesh2d/bc_manager.py +25 -2
- wolfhece/mesh2d/gpu_2d.py +647 -0
- wolfhece/mesh2d/simple_2d.py +581 -163
- wolfhece/mesh2d/wolf2dprev.py +4 -1
- wolfhece/scenario/check_scenario.py +11 -0
- wolfhece/scenario/config_manager.py +257 -53
- wolfhece/scenario/update_void.py +34 -3
- wolfhece/wolf_array.py +261 -79
- wolfhece/wolfresults_2D.py +53 -20
- {wolfhece-2.1.100.dist-info → wolfhece-2.1.102.dist-info}/METADATA +3 -1
- {wolfhece-2.1.100.dist-info → wolfhece-2.1.102.dist-info}/RECORD +24 -23
- {wolfhece-2.1.100.dist-info → wolfhece-2.1.102.dist-info}/WHEEL +1 -1
- {wolfhece-2.1.100.dist-info → wolfhece-2.1.102.dist-info}/entry_points.txt +0 -0
- {wolfhece-2.1.100.dist-info → wolfhece-2.1.102.dist-info}/top_level.txt +0 -0
wolfhece/mesh2d/wolf2dprev.py
CHANGED
@@ -8100,9 +8100,12 @@ class prev_infiltration():
|
|
8100
8100
|
|
8101
8101
|
sequence, nb_zones = self._infiltrations_chronology.shape
|
8102
8102
|
for zone in range(1,nb_zones):
|
8103
|
-
ax.plot(self._infiltrations_chronology[:, 0], self._infiltrations_chronology[:, zone], label=f'
|
8103
|
+
ax.plot(self._infiltrations_chronology[:, 0], self._infiltrations_chronology[:, zone], label=f'Zone {zone}')
|
8104
8104
|
|
8105
|
+
ax.set_xlabel(_('Time [s]'))
|
8106
|
+
ax.set_ylabel(_('Infiltration [$m^3/s$]'))
|
8105
8107
|
ax.legend()
|
8108
|
+
fig.tight_layout()
|
8106
8109
|
|
8107
8110
|
if show:
|
8108
8111
|
fig.show()
|
@@ -123,6 +123,17 @@ def import_files(module_files:Union[list[Path],list[str]]) -> list[types.ModuleT
|
|
123
123
|
sys.path.pop(0)
|
124
124
|
os.chdir(olddir)
|
125
125
|
|
126
|
+
# Test if some routines are missing
|
127
|
+
# if "impose_bc" in py_file.name:
|
128
|
+
# to_test = ['impose_bc']
|
129
|
+
|
130
|
+
# elif "update_void" in py_file.name:
|
131
|
+
# to_test = ['update_topobathy', 'update_manning', 'update_infiltration', 'update_roof']
|
132
|
+
|
133
|
+
# for routine in to_test:
|
134
|
+
# if not hasattr(module, routine):
|
135
|
+
# logging.warning(f'Le module {module} ne contient pas la routine {routine}.')
|
136
|
+
|
126
137
|
modules.append(module)
|
127
138
|
|
128
139
|
return modules
|
@@ -30,7 +30,7 @@ import types
|
|
30
30
|
|
31
31
|
from ..PyTranslate import _
|
32
32
|
from ..wolfresults_2D import Wolfresults_2D
|
33
|
-
from ..wolf_array import WolfArray, header_wolf, WOLF_ARRAY_FULL_INTEGER
|
33
|
+
from ..wolf_array import WolfArray, header_wolf, WOLF_ARRAY_FULL_INTEGER, WOLF_ARRAY_FULL_SINGLE
|
34
34
|
from .check_scenario import check_file_update, check_file_bc, import_files
|
35
35
|
from .update_void import create_new_file as update_void
|
36
36
|
from .imposebc_void import create_new_file as bc_void
|
@@ -56,7 +56,7 @@ except:
|
|
56
56
|
# mann_*.tif
|
57
57
|
# infil_*.tif
|
58
58
|
|
59
|
-
ACCEPTED_PREFIX = ['bath_', 'mann_', 'infil_']
|
59
|
+
ACCEPTED_PREFIX = ['bath_', 'mann_', 'infil_', 'roof_']
|
60
60
|
|
61
61
|
def delete_folder(pth:Path):
|
62
62
|
for sub in pth.iterdir():
|
@@ -202,14 +202,15 @@ class Config_Manager_2D_GPU:
|
|
202
202
|
Gestionnaire de configurations 2D - code GPU
|
203
203
|
"""
|
204
204
|
|
205
|
-
def __init__(self, workingdir:str = '', mapviewer:WolfMapViewer = None) -> None:
|
205
|
+
def __init__(self, workingdir:str = '', mapviewer:WolfMapViewer = None, python_venv:Path = None) -> None:
|
206
206
|
"""
|
207
207
|
Recherche de toutes les modélisation dans un répertoire et ses sous-répertoires
|
208
208
|
"""
|
209
209
|
self.wx_exists = wx.App.Get() is not None
|
210
210
|
|
211
|
-
self.workingdir =
|
212
|
-
self.
|
211
|
+
self.workingdir:Path = None
|
212
|
+
self.wolfgpu:Path = None
|
213
|
+
self._py_env:Path = python_venv
|
213
214
|
|
214
215
|
if workingdir == '':
|
215
216
|
if self.wx_exists:
|
@@ -228,6 +229,7 @@ class Config_Manager_2D_GPU:
|
|
228
229
|
logging.error(_('Directory does not exist !'))
|
229
230
|
return
|
230
231
|
|
232
|
+
self.find_wolfgpu()
|
231
233
|
self.workingdir = Path(workingdir)
|
232
234
|
self.mapviewer = mapviewer
|
233
235
|
|
@@ -239,6 +241,33 @@ class Config_Manager_2D_GPU:
|
|
239
241
|
|
240
242
|
self.load_data()
|
241
243
|
|
244
|
+
def find_wolfgpu(self):
|
245
|
+
""" Find the wolfgpu Path from wolfgpu package"""
|
246
|
+
|
247
|
+
import importlib.util
|
248
|
+
import sys
|
249
|
+
|
250
|
+
if self._py_env is None:
|
251
|
+
self._py_env = Path(sys.executable).parent
|
252
|
+
|
253
|
+
# Find wolfgpu.exe in script directory
|
254
|
+
candidate = self._py_env / 'wolfgpu.exe'
|
255
|
+
|
256
|
+
if candidate.exists():
|
257
|
+
self.wolfgpu = candidate
|
258
|
+
return
|
259
|
+
|
260
|
+
candidate = self._py_env / 'Scripts' / 'wolfgpu.exe'
|
261
|
+
|
262
|
+
if candidate.exists():
|
263
|
+
self.wolfgpu = candidate
|
264
|
+
return
|
265
|
+
else:
|
266
|
+
logging.error(_('WOLFGPU not found !'))
|
267
|
+
self.wolfgpu = None
|
268
|
+
self._py_env = None
|
269
|
+
|
270
|
+
|
242
271
|
def _test_ui(self):
|
243
272
|
""" Test if the UI is available """
|
244
273
|
|
@@ -442,7 +471,7 @@ class Config_Manager_2D_GPU:
|
|
442
471
|
|
443
472
|
logging.info(_('Number of tif files : {}'.format(len(list_tif))))
|
444
473
|
|
445
|
-
standard_files = ['bathymetry.tif', 'manning.tif', 'infiltration.tif', 'h.tif', 'qx.tif', 'qy.tif']
|
474
|
+
standard_files = ['bathymetry.tif', 'manning.tif', 'infiltration.tif', 'h.tif', 'qx.tif', 'qy.tif', 'roof.tif']
|
446
475
|
|
447
476
|
log = ''
|
448
477
|
for curtif in list_tif:
|
@@ -473,6 +502,12 @@ class Config_Manager_2D_GPU:
|
|
473
502
|
loclog += _('Did you mean "infil_" ?') + '\n'
|
474
503
|
break
|
475
504
|
|
505
|
+
tests = ['rof_', 'rooof_', 'rofo_', 'oof_', 'roff_']
|
506
|
+
for test in tests:
|
507
|
+
if curtif.name.lower().startswith(test):
|
508
|
+
loclog += _('Did you mean "roof_" ?') + '\n'
|
509
|
+
break
|
510
|
+
|
476
511
|
logging.warning(loclog)
|
477
512
|
|
478
513
|
log += loclog
|
@@ -583,7 +618,9 @@ class Config_Manager_2D_GPU:
|
|
583
618
|
self._test_is_results(curdict)
|
584
619
|
|
585
620
|
def _recursive_find_files(self, wd:Path, curdict:dict, erase_cache:bool = True):
|
586
|
-
""" Recherche récursive des fichiers de simulation/scenario dans les
|
621
|
+
""" Recherche récursive des fichiers de simulation/scenario dans les
|
622
|
+
répertoires dont la structure a été traduite en dictionnaire """
|
623
|
+
|
587
624
|
if len(curdict.keys())>0:
|
588
625
|
for k in curdict.keys():
|
589
626
|
self._recursive_find_files(k, curdict[k])
|
@@ -734,15 +771,19 @@ class Config_Manager_2D_GPU:
|
|
734
771
|
|
735
772
|
return curdict
|
736
773
|
|
737
|
-
def _select_tif_partname(self, curdict:dict, tifstr:Literal['bath_', 'mann_', 'infil_']):
|
774
|
+
def _select_tif_partname(self, curdict:dict, tifstr:Literal['bath_', 'mann_', 'infil_', 'roof_']):
|
738
775
|
""" Select tif files with a 'str' as name's prefix """
|
739
776
|
|
777
|
+
assert tifstr in ACCEPTED_PREFIX, _('Bad prefix !')
|
778
|
+
|
740
779
|
if tifstr == 'bath_':
|
741
780
|
forced_add = ['bathymetry.tif']
|
742
781
|
elif tifstr == 'mann_':
|
743
782
|
forced_add = ['manning.tif']
|
744
783
|
elif tifstr == 'infil_':
|
745
784
|
forced_add = ['infiltration.tif']
|
785
|
+
elif tifstr == 'roof_':
|
786
|
+
forced_add = ['roof.tif']
|
746
787
|
|
747
788
|
tif_list = [curtif for curtif in curdict[GPU_2D_file_extensions.TIF.value] \
|
748
789
|
if curtif.name.lower().startswith(tifstr) or \
|
@@ -764,13 +805,15 @@ class Config_Manager_2D_GPU:
|
|
764
805
|
all_tif_bath = [self._select_tif_partname(curdict, 'bath_') for curdict in curdicts]
|
765
806
|
all_tif_mann = [self._select_tif_partname(curdict, 'mann_') for curdict in curdicts]
|
766
807
|
all_tif_infil = [self._select_tif_partname(curdict, 'infil_') for curdict in curdicts]
|
808
|
+
all_tif_roof = [self._select_tif_partname(curdict, 'roof_') for curdict in curdicts]
|
767
809
|
|
768
810
|
# flatten list of lists
|
769
811
|
all_tif_bath = [curel for curlist in all_tif_bath if len(curlist)>0 for curel in curlist]
|
770
812
|
all_tif_mann = [curel for curlist in all_tif_mann if len(curlist)>0 for curel in curlist]
|
771
813
|
all_tif_infil = [curel for curlist in all_tif_infil if len(curlist)>0 for curel in curlist]
|
814
|
+
all_tif_roof = [curel for curlist in all_tif_roof if len(curlist)>0 for curel in curlist]
|
772
815
|
|
773
|
-
for cur_lst in [all_tif_bath, all_tif_mann, all_tif_infil]:
|
816
|
+
for cur_lst in [all_tif_bath, all_tif_mann, all_tif_infil, all_tif_roof]:
|
774
817
|
for cur_tif in cur_lst:
|
775
818
|
curarray:WolfArray = WolfArray(cur_tif)
|
776
819
|
if curarray.nullvalue != 99999.:
|
@@ -795,21 +838,31 @@ class Config_Manager_2D_GPU:
|
|
795
838
|
all_tif_bath = [self._select_tif_partname(curdict, 'bath_') for curdict in curdicts]
|
796
839
|
all_tif_mann = [self._select_tif_partname(curdict, 'mann_') for curdict in curdicts]
|
797
840
|
all_tif_infil = [self._select_tif_partname(curdict, 'infil_') for curdict in curdicts]
|
841
|
+
all_tif_roof = [self._select_tif_partname(curdict, 'roof_') for curdict in curdicts]
|
798
842
|
|
799
843
|
# flatten list of lists
|
800
844
|
all_tif_bath = [curel for curlist in all_tif_bath if len(curlist)>0 for curel in curlist]
|
801
845
|
all_tif_mann = [curel for curlist in all_tif_mann if len(curlist)>0 for curel in curlist]
|
802
846
|
all_tif_infil = [curel for curlist in all_tif_infil if len(curlist)>0 for curel in curlist]
|
847
|
+
all_tif_roof = [curel for curlist in all_tif_roof if len(curlist)>0 for curel in curlist]
|
803
848
|
|
804
849
|
# création du fichier vrt
|
805
850
|
create_vrt_from_files_first_based(all_tif_bath, from_path / '__bath_assembly.vrt')
|
806
851
|
create_vrt_from_files_first_based(all_tif_mann, from_path / '__mann_assembly.vrt')
|
852
|
+
|
807
853
|
if len(all_tif_infil)>0:
|
808
854
|
create_vrt_from_files_first_based(all_tif_infil, from_path / '__infil_assembly.vrt')
|
855
|
+
else:
|
856
|
+
logging.info(_('No infiltration files found ! -> no __infil_assembly.vrt file created !'))
|
857
|
+
|
858
|
+
if len(all_tif_roof)>0:
|
859
|
+
create_vrt_from_files_first_based(all_tif_roof, from_path / '__roof_assembly.vrt')
|
860
|
+
else:
|
861
|
+
logging.info(_('No roof files found ! -> no __roof_assembly.vrt file created !'))
|
809
862
|
|
810
863
|
def create_vec(self,
|
811
864
|
from_path:Path,
|
812
|
-
which:Literal['bath_', 'mann_', 'infil_'] = 'bath_') -> Zones:
|
865
|
+
which:Literal['bath_', 'mann_', 'infil_', 'roof_'] = 'bath_') -> Zones:
|
813
866
|
""" Create a vec file from a path """
|
814
867
|
|
815
868
|
assert which in ACCEPTED_PREFIX, _('Bad prefix !')
|
@@ -868,17 +921,18 @@ class Config_Manager_2D_GPU:
|
|
868
921
|
|
869
922
|
def translate_vrt2tif(self, from_path:Path):
|
870
923
|
""" Translate vrt to tif """
|
871
|
-
|
872
|
-
|
924
|
+
|
925
|
+
vrtin = ['__bath_assembly.vrt', '__mann_assembly.vrt', '__infil_assembly.vrt', '__roof_assembly.vrt']
|
926
|
+
fout = ['__bathymetry.tif' , '__manning.tif', '__infiltration.tif', '__roof.tif']
|
873
927
|
|
874
928
|
for curin, curout in zip(vrtin, fout):
|
875
929
|
if (from_path / curin).exists():
|
876
930
|
translate_vrt2tif(from_path / curin, from_path / curout)
|
877
931
|
|
878
|
-
def
|
932
|
+
def apply_scripts_bath_mann_inf_roof(self, from_path:Path):
|
879
933
|
""" Apply all scripts """
|
880
934
|
|
881
|
-
filenames = ['__bathymetry.tif', '__manning.tif', '__infiltration.tif']
|
935
|
+
filenames = ['__bathymetry.tif', '__manning.tif', '__infiltration.tif', '__roof.tif']
|
882
936
|
|
883
937
|
# check if present on disk
|
884
938
|
if not all([(from_path / curfile).exists() for curfile in filenames]):
|
@@ -891,12 +945,13 @@ class Config_Manager_2D_GPU:
|
|
891
945
|
|
892
946
|
arrays = [WolfArray(from_path / curfile) for curfile in filenames]
|
893
947
|
|
894
|
-
self.
|
948
|
+
self._apply_scripts_update_topo_maning_inf_roof(from_path, arrays[0], arrays[1], arrays[2], arrays[3])
|
895
949
|
|
896
950
|
# write the files
|
897
951
|
arrays[0].write_all(from_path / '__bathymetry_after_scripts.tif')
|
898
952
|
arrays[1].write_all(from_path / '__manning_after_scripts.tif')
|
899
953
|
arrays[2].write_all(from_path / '__infiltration_after_scripts.tif')
|
954
|
+
arrays[3].write_all(from_path / '__roof_after_scripts.tif')
|
900
955
|
|
901
956
|
def _import_scripts(self, from_path:Path, which) -> list[types.ModuleType]:
|
902
957
|
""" List all modules in structure and import them.
|
@@ -938,29 +993,59 @@ class Config_Manager_2D_GPU:
|
|
938
993
|
|
939
994
|
return imported_mod
|
940
995
|
|
941
|
-
def
|
996
|
+
def _import_scripts_topo_manning_inf_roof(self, from_path:Path) -> list[types.ModuleType]:
|
942
997
|
""" import all topo and manning scripts from a path """
|
943
998
|
|
944
999
|
return self._import_scripts(from_path, WOLF_UPDATE)
|
945
1000
|
|
946
|
-
def
|
1001
|
+
def _apply_scripts_update_topo_maning_inf_roof(self,
|
947
1002
|
modules:list[types.ModuleType] | Path | str,
|
948
1003
|
array_bat:WolfArray,
|
949
1004
|
array_mann:WolfArray,
|
950
|
-
array_inf:WolfArray
|
1005
|
+
array_inf:WolfArray,
|
1006
|
+
array_roof:WolfArray):
|
951
1007
|
""" Apply all scripts from a list of modules """
|
952
1008
|
|
953
1009
|
if isinstance(modules, str):
|
954
1010
|
modules = Path(modules)
|
955
1011
|
|
956
1012
|
if isinstance(modules, Path):
|
957
|
-
modules = self.
|
1013
|
+
modules = self._import_scripts_topo_manning_inf_roof(modules)
|
958
1014
|
|
959
1015
|
for curmod in modules:
|
960
1016
|
instmod = curmod.Update_Sim_Scenario()
|
961
|
-
|
962
|
-
|
963
|
-
|
1017
|
+
try:
|
1018
|
+
if not hasattr(instmod, "update_topobathy"):
|
1019
|
+
logging.info(_('No update_topobathy method found in the script {}!').format(curmod))
|
1020
|
+
else:
|
1021
|
+
instmod.update_topobathy(array_bat)
|
1022
|
+
except Exception as e:
|
1023
|
+
logging.error(_('An error occured during bathymetry script - {}!').format(e))
|
1024
|
+
|
1025
|
+
try:
|
1026
|
+
if not hasattr(instmod, "update_manning"):
|
1027
|
+
logging.info(_('No update_manning method found in the script {}!').format(curmod))
|
1028
|
+
else:
|
1029
|
+
instmod.update_manning(array_mann)
|
1030
|
+
except Exception as e:
|
1031
|
+
logging.error(_('An error occured during manning script - {}!').format(e))
|
1032
|
+
|
1033
|
+
try:
|
1034
|
+
if not hasattr(instmod, "update_infiltration"):
|
1035
|
+
logging.info(_('No update_infiltration method found in the script {}!').format(curmod))
|
1036
|
+
else:
|
1037
|
+
instmod.update_infiltration(array_inf)
|
1038
|
+
except Exception as e:
|
1039
|
+
logging.error(_('An error occured during infiltration script - {}!').format(e))
|
1040
|
+
|
1041
|
+
try:
|
1042
|
+
if not hasattr(instmod, "update_roof"):
|
1043
|
+
logging.info(_('No update_roof method found in the script {}!').format(curmod))
|
1044
|
+
else:
|
1045
|
+
instmod.update_roof(array_roof)
|
1046
|
+
except Exception as e:
|
1047
|
+
logging.error(_('An error occured during roof script - {}!').format(e))
|
1048
|
+
|
964
1049
|
|
965
1050
|
def _import_scripts_bc(self, from_path:Path) -> list[types.ModuleType]:
|
966
1051
|
""" Import all BC's scripts from a path """
|
@@ -977,7 +1062,10 @@ class Config_Manager_2D_GPU:
|
|
977
1062
|
modules = self._import_scripts_bc(modules)
|
978
1063
|
|
979
1064
|
for curmod in modules:
|
980
|
-
|
1065
|
+
try:
|
1066
|
+
curmod.Impose_BC_Scenario().impose_bc(sim)
|
1067
|
+
except Exception as e:
|
1068
|
+
logging.error(_('An error occured during BC script - {}!').format(e))
|
981
1069
|
|
982
1070
|
|
983
1071
|
def load_hydrograph(self, path:Path, toplot=True) -> tuple[Hydrograph_scenario, plt.Figure, plt.Axes]:
|
@@ -1059,11 +1147,30 @@ class Config_Manager_2D_GPU:
|
|
1059
1147
|
else:
|
1060
1148
|
logging.error(_("No 'bathymetry.tif' file found in the root directory !"))
|
1061
1149
|
|
1150
|
+
def create_void_roof(self):
|
1151
|
+
""" create void roof file """
|
1152
|
+
|
1153
|
+
if (self.workingdir / 'bathymetry.tif').exists():
|
1154
|
+
locheader = self.get_header()
|
1155
|
+
roof = WolfArray(srcheader=locheader, whichtype= WOLF_ARRAY_FULL_SINGLE)
|
1156
|
+
roof.array.data[:,:] = 99999.
|
1157
|
+
roof.nullvalue = 99999.
|
1158
|
+
roof.write_all(str(self.workingdir / 'roof.tif'))
|
1159
|
+
|
1160
|
+
if (self.workingdir / 'roof.tif').exists():
|
1161
|
+
logging.info(_('roof.tif created and set to 99999. ! -- Please edit it !'))
|
1162
|
+
else:
|
1163
|
+
logging.error(_("roof.tif not created ! -- Does 'bathymetry.tif' or any '.tif' file exist in the root directory ?"))
|
1164
|
+
else:
|
1165
|
+
logging.error(_("No 'bathymetry.tif' file found in the root directory !"))
|
1166
|
+
|
1167
|
+
|
1062
1168
|
def create_simulation(self,
|
1063
1169
|
dir:Path,
|
1064
1170
|
idx_hydros:list[int] = [-1],
|
1065
1171
|
delete_existing:bool = False,
|
1066
|
-
preserve_ic:bool=False
|
1172
|
+
preserve_ic:bool=False,
|
1173
|
+
callback = None) -> list[Path]:
|
1067
1174
|
""" Create a simulation from different hydrographs """
|
1068
1175
|
|
1069
1176
|
if isinstance(dir, str):
|
@@ -1159,17 +1266,32 @@ class Config_Manager_2D_GPU:
|
|
1159
1266
|
infiltration = WolfArray(srcheader=bat.get_header(), whichtype= WOLF_ARRAY_FULL_INTEGER)
|
1160
1267
|
infiltration.array.data[:,:] = 0
|
1161
1268
|
|
1269
|
+
# check for roof
|
1270
|
+
if exists(dir / '__roof.tif'):
|
1271
|
+
roof = WolfArray(str(dir / '__roof.tif'))
|
1272
|
+
if roof.wolftype != WOLF_ARRAY_FULL_SINGLE:
|
1273
|
+
logging.error(_('Roof .tif must be a full single array ! -- The array will be ignored !'))
|
1274
|
+
roof = WolfArray(srcheader=bat.get_header(), whichtype= WOLF_ARRAY_FULL_SINGLE)
|
1275
|
+
roof.array.data[:,:] = 99999.
|
1276
|
+
else:
|
1277
|
+
roof = WolfArray(srcheader=bat.get_header(), whichtype= WOLF_ARRAY_FULL_SINGLE)
|
1278
|
+
roof.array.data[:,:] = 99999.
|
1279
|
+
|
1162
1280
|
# applying Python scrpitps on ARRAYS
|
1163
|
-
self.
|
1281
|
+
self._apply_scripts_update_topo_maning_inf_roof(dir, bat, man, infiltration, roof)
|
1164
1282
|
|
1165
1283
|
# save arrays on disk
|
1166
1284
|
bat.write_all(str(dir / '__bathymetry_after_scripts.tif'))
|
1167
1285
|
man.write_all(str(dir / '__manning_after_scripts.tif'))
|
1168
1286
|
infiltration.write_all(str(dir / '__infiltration_after_scripts.tif'))
|
1287
|
+
roof.write_all(str(dir / '__roof_after_scripts.tif'))
|
1169
1288
|
|
1170
1289
|
# create simulation
|
1171
1290
|
allsims = []
|
1172
|
-
for curdir, curhydro, curic in zip(used_dirs, used_hydros, used_ic):
|
1291
|
+
for id_sim, (curdir, curhydro, curic) in enumerate(zip(used_dirs, used_hydros, used_ic)):
|
1292
|
+
|
1293
|
+
if callback is not None:
|
1294
|
+
callback(id_sim)
|
1173
1295
|
|
1174
1296
|
# instanciation de la simulation
|
1175
1297
|
cursim = SimpleSimulation(self._header.nbx, self._header.nby)
|
@@ -1231,6 +1353,13 @@ class Config_Manager_2D_GPU:
|
|
1231
1353
|
|
1232
1354
|
cursim.infiltration_zones = np.asarray(infiltration.array.data, dtype=np.int32)
|
1233
1355
|
|
1356
|
+
if roof.nbnotnull == 0:
|
1357
|
+
cursim.bridge_roof = None
|
1358
|
+
logging.info(_("No cells defined as roof ! -- Roof will be ignored !"))
|
1359
|
+
else:
|
1360
|
+
cursim.bridge_roof = roof.array.data
|
1361
|
+
logging.info(_("You have {} cells defined as roof").format(roof.nbnotnull))
|
1362
|
+
|
1234
1363
|
# add hydrograph
|
1235
1364
|
for idx, curline in curhydro.data.iterrows():
|
1236
1365
|
cursim.add_infiltration(float(idx), [float(cur) for cur in curline.values])
|
@@ -1263,25 +1392,35 @@ class Config_Manager_2D_GPU:
|
|
1263
1392
|
logging.info(cursim.check_errors())
|
1264
1393
|
logging.info(_('Simulation {} created !'.format(curdir)))
|
1265
1394
|
|
1266
|
-
|
1267
1395
|
with open(curdir / 'quickrun.bat', 'w', encoding='utf-8') as f:
|
1396
|
+
f.write("@echo off\n")
|
1397
|
+
f.write("\n")
|
1268
1398
|
f.write(str(curdir.drive) + '\n')
|
1269
1399
|
f.write('cd {}\n'.format(str(curdir.parent)))
|
1270
|
-
f.write(
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1400
|
+
f.write("\n")
|
1401
|
+
f.write("WOLFGPU_PARAMS=-quickrun " + str(curdir.name) + "\n")
|
1402
|
+
f.write("\n")
|
1403
|
+
f.write("where wolfgpu.exe\n")
|
1404
|
+
f.write("IF %ERRORLEVEL%==0 (\n")
|
1405
|
+
f.write("wolfgpu %WOLFGPU_PARAMS%\n")
|
1406
|
+
f.write("goto :end\n")
|
1407
|
+
f.write(")\n")
|
1408
|
+
f.write("\n")
|
1409
|
+
f.write("echo -------------------------------\n")
|
1410
|
+
f.write("echo ERROR !!!\n")
|
1411
|
+
f.write("echo -------------------------------\n")
|
1412
|
+
f.write("echo I can't find wolfgpu.exe.\n")
|
1413
|
+
f.write("echo It is normally installed in the 'Scripts' subdirectory of your python\n")
|
1414
|
+
f.write("echo directory (or environment).\n")
|
1415
|
+
f.write("echo This 'Scripts' subdirectory must be available on the PATH environment variable.\n")
|
1416
|
+
f.write("echo I am now going to try to run wolfgpu as a regular python module\n")
|
1417
|
+
f.write("echo -------------------------------\n")
|
1418
|
+
f.write("pause\n")
|
1419
|
+
f.write("python -m wolfgpu.cli %WOLFGPU_PARAMS%\n")
|
1420
|
+
f.write(":end\n")
|
1281
1421
|
|
1282
1422
|
allsims.append(curdir / 'quickrun.bat')
|
1283
1423
|
|
1284
|
-
|
1285
1424
|
logging.info(_('Simulation creation finished !'))
|
1286
1425
|
logging.warning(_('Do not forget to update/set the boundary conditions if not set by scripts !'))
|
1287
1426
|
|
@@ -1303,10 +1442,24 @@ class Config_Manager_2D_GPU:
|
|
1303
1442
|
with open(path, 'w', encoding='utf-8') as f:
|
1304
1443
|
f.write(batch)
|
1305
1444
|
|
1445
|
+
if self.wolfgpu is None:
|
1446
|
+
logging.warning('****************************************************')
|
1447
|
+
logging.warning(_('Wolfgpu.exe not found !'))
|
1448
|
+
logging.warning(_('It is normally installed in the "Scripts" subdirectory of your python directory (or environment).'))
|
1449
|
+
logging.warning(_('This "Scripts" subdirectory must be available on the PATH environment variable.'))
|
1450
|
+
logging.warning('****************************************************')
|
1451
|
+
else:
|
1452
|
+
logging.info('****************************************************')
|
1453
|
+
logging.info(_('Wolfgpu.exe found in {}!').format(self.wolfgpu))
|
1454
|
+
logging.info(_('You can now run the simulations !'))
|
1455
|
+
logging.info(_('Do not forget to activate your Python virtual environment if you are using one !'))
|
1456
|
+
logging.info('****************************************************')
|
1457
|
+
|
1306
1458
|
return batch
|
1307
1459
|
|
1308
1460
|
def run_batch(self, batch:Path):
|
1309
1461
|
""" run a batch file in a subprocess """
|
1462
|
+
|
1310
1463
|
if not batch.exists():
|
1311
1464
|
logging.error(_('Batch file {} does not exist !'.format(batch)))
|
1312
1465
|
return
|
@@ -1452,29 +1605,33 @@ class UI_Manager_2D_GPU():
|
|
1452
1605
|
self._create_void_infil.Bind(wx.EVT_BUTTON,self.oncreate_void_infil)
|
1453
1606
|
self._create_void_infil.SetToolTip(_('Create a void infiltration zones file based on bathymetry.tif'))
|
1454
1607
|
|
1608
|
+
self._create_void_roof = wx.Button(self._frame,label = _('Create .tif bridge/culvert roof elevation'))
|
1609
|
+
self._create_void_roof.Bind(wx.EVT_BUTTON,self.oncreate_void_roof)
|
1610
|
+
self._create_void_roof.SetToolTip(_('Create a void roof file based on bathymetry.tif'))
|
1611
|
+
|
1455
1612
|
self._create_void_scripts = wx.Button(self._frame,label = _('Create void scripts'))
|
1456
1613
|
self._create_void_scripts.Bind(wx.EVT_BUTTON,self.oncreate_void_scripts)
|
1457
1614
|
self._create_void_scripts.SetToolTip(_('Create void script files for topography, manning and infiltration'))
|
1458
1615
|
|
1459
1616
|
self._create_vrt = wx.Button(self._frame,label = _('Assembly .vrt to current level'))
|
1460
1617
|
self._create_vrt.Bind(wx.EVT_BUTTON,self.oncreatevrt)
|
1461
|
-
self._create_vrt.SetToolTip(_('Create a .vrt file from all bathymetry and
|
1618
|
+
self._create_vrt.SetToolTip(_('Create a .vrt file from all bathymetry, manning, infiltration and roof .tif files\nBe sure that all files are right named !\n\n - bathymetry must contain "bath"\n - manning must contain "mann"\n - infiltration must contain "infil"\n - roof must contain "roof"'))
|
1462
1619
|
|
1463
1620
|
self._translate_vrt = wx.Button(self._frame,label = _('Translate .vrt to .tif'))
|
1464
1621
|
self._translate_vrt.Bind(wx.EVT_BUTTON,self.ontranslatevrt2tif)
|
1465
|
-
self._translate_vrt.SetToolTip(_('Translate .vrt files to .tif files\n\n - __bath_assembly.vrt -> __bathymetry.tif\n - __mann_assembly.vrt -> __manning.tif\n - __infil_assembly.vrt -> __infiltration.tif'))
|
1622
|
+
self._translate_vrt.SetToolTip(_('Translate .vrt files to .tif files\n\n - __bath_assembly.vrt -> __bathymetry.tif\n - __mann_assembly.vrt -> __manning.tif\n - __infil_assembly.vrt -> __infiltration.tif\n - __roof_assembly.vrt -> __roof.tif'))
|
1466
1623
|
|
1467
|
-
self._apply_scripts = wx.Button(self._frame,label = _('Apply scripts on bathymetry, manning and
|
1624
|
+
self._apply_scripts = wx.Button(self._frame,label = _('Apply scripts on bathymetry, manning, infiltration and roof elevation'))
|
1468
1625
|
self._apply_scripts.Bind(wx.EVT_BUTTON,self.onapply_scripts)
|
1469
|
-
self._apply_scripts.SetToolTip(_('Apply scripts on bathymetry, manning and infiltration\n\n - bathymetry.tif\n - manning.tif\n - infiltration.tif\n\nThe scripts must be in the structure starting with parent directory and descending
|
1626
|
+
self._apply_scripts.SetToolTip(_('Apply scripts on bathymetry, manning and infiltration\n\n - bathymetry.tif\n - manning.tif\n - infiltration.tif\n - roof.tif\n\nThe scripts must be in the structure starting with parent directory and descending.'))
|
1470
1627
|
|
1471
1628
|
self._create_vec = wx.Button(self._frame,label = _('Search spatial coverage from current level'))
|
1472
1629
|
self._create_vec.Bind(wx.EVT_BUTTON,self.oncreatevec)
|
1473
|
-
self._create_vec.SetToolTip(_('Create a .vecz file (with contour and global bounds) from all bathymetry and manning .tif files\nBe sure that all files are right named !\n\n - bathymetry must contain "bath"\n - manning must contain "mann"\n - infiltration must contain "infil"'))
|
1630
|
+
self._create_vec.SetToolTip(_('Create a .vecz file (with contour and global bounds) from all bathymetry and manning .tif files\nBe sure that all files are right named !\n\n - bathymetry must contain "bath"\n - manning must contain "mann"\n - infiltration must contain "infil"\n - roof must contain "roof"'))
|
1474
1631
|
|
1475
1632
|
self._check_prefix = wx.Button(self._frame,label = _('Check prefix (tif files)'))
|
1476
1633
|
self._check_prefix.Bind(wx.EVT_BUTTON,self.oncheck_prefix)
|
1477
|
-
self._check_prefix.SetToolTip(_('Check prefix of .tif files\n\n - bath_*.tif\n - mann_*.tif\n - infil_*.tif\n\nThe prefix must be "bath_", "mann_" and "
|
1634
|
+
self._check_prefix.SetToolTip(_('Check prefix of .tif files\n\n - bath_*.tif\n - mann_*.tif\n - infil_*.tif\n - roof_*.tif\n\nThe prefix must be "bath_", "mann_", "infil_" and "roof_"'))
|
1478
1635
|
|
1479
1636
|
self._checkconsistency = wx.Button(self._frame,label = _('Check consistency'))
|
1480
1637
|
self._checkconsistency.Bind(wx.EVT_BUTTON,self.oncheck_consistency)
|
@@ -1524,6 +1681,7 @@ class UI_Manager_2D_GPU():
|
|
1524
1681
|
# buttons -> sizer
|
1525
1682
|
sizer_buttons.Add(self._reload,1,wx.EXPAND)
|
1526
1683
|
sizer_buttons.Add(self._create_void_infil,1,wx.EXPAND)
|
1684
|
+
sizer_buttons.Add(self._create_void_roof,1,wx.EXPAND)
|
1527
1685
|
sizer_buttons.Add(self._create_void_scripts,1,wx.EXPAND)
|
1528
1686
|
sizer_buttons.Add(self._check_prefix,1,wx.EXPAND)
|
1529
1687
|
sizer_buttons.Add(self._create_vrt,1,wx.EXPAND)
|
@@ -1592,6 +1750,12 @@ class UI_Manager_2D_GPU():
|
|
1592
1750
|
self._parent.create_void_infil()
|
1593
1751
|
self.reload()
|
1594
1752
|
|
1753
|
+
def oncreate_void_roof(self, e:wx.MouseEvent):
|
1754
|
+
""" Création d'un fichier de toit de pont vide """
|
1755
|
+
|
1756
|
+
self._parent.create_void_roof()
|
1757
|
+
self.reload()
|
1758
|
+
|
1595
1759
|
def oncreate_void_scripts(self,e:wx.MouseEvent):
|
1596
1760
|
""" Création d'un script vide """
|
1597
1761
|
|
@@ -1648,9 +1812,17 @@ class UI_Manager_2D_GPU():
|
|
1648
1812
|
def oncreatevrt(self,e:wx.MouseEvent):
|
1649
1813
|
""" Création d'un fichier vrt """
|
1650
1814
|
|
1815
|
+
if self._selected_item is None:
|
1816
|
+
logging.error(_('Please select a scenario to analyze by activating an elemnt in the tree list !'))
|
1817
|
+
return
|
1818
|
+
|
1651
1819
|
logging.info(_('Creating vrt ...'))
|
1652
1820
|
mydata = self._treelist.GetItemData(self._selected_item)
|
1653
1821
|
|
1822
|
+
if not 'path' in mydata:
|
1823
|
+
logging.error(_('Please select a scenario to analyze !'))
|
1824
|
+
return
|
1825
|
+
|
1654
1826
|
# création du fichier vrt
|
1655
1827
|
self._parent.create_vrt(mydata['path'])
|
1656
1828
|
logging.info(_('... done !'))
|
@@ -1660,6 +1832,10 @@ class UI_Manager_2D_GPU():
|
|
1660
1832
|
def oncreatevec(self,e:wx.MouseEvent):
|
1661
1833
|
""" Création d'un fichier vec """
|
1662
1834
|
|
1835
|
+
if self._selected_item is None:
|
1836
|
+
logging.error(_('Please select a scenario to analyze by activating an elemnt in the tree list !'))
|
1837
|
+
return
|
1838
|
+
|
1663
1839
|
logging.info(_('Creating vecz ...'))
|
1664
1840
|
mydata = self._treelist.GetItemData(self._selected_item)
|
1665
1841
|
|
@@ -1730,7 +1906,7 @@ class UI_Manager_2D_GPU():
|
|
1730
1906
|
return
|
1731
1907
|
|
1732
1908
|
# application des scripts
|
1733
|
-
self._parent.
|
1909
|
+
self._parent.apply_scripts_bath_mann_inf_roof(mydata['path'])
|
1734
1910
|
|
1735
1911
|
self.reload()
|
1736
1912
|
logging.info(_('... done !'))
|
@@ -1741,7 +1917,7 @@ class UI_Manager_2D_GPU():
|
|
1741
1917
|
logging.info(_('Checking prefix ...'))
|
1742
1918
|
if self._selected_item is None or self._selected_item == self._treelist.GetRootItem():
|
1743
1919
|
logging.info(_('No item selected ! -- using root item'))
|
1744
|
-
with wx.MessageDialog(None, _('No item selected ! -- using root item'), _('Warning'), wx.OK | wx.CANCEL | wx.ICON_WARNING) as dlg:
|
1920
|
+
with wx.MessageDialog(None, _('No item selected ! -- using root item ?'), _('Warning'), wx.OK | wx.CANCEL | wx.ICON_WARNING) as dlg:
|
1745
1921
|
ret = dlg.ShowModal()
|
1746
1922
|
if ret != wx.ID_OK:
|
1747
1923
|
return
|
@@ -1752,7 +1928,7 @@ class UI_Manager_2D_GPU():
|
|
1752
1928
|
# création du fichier vrt
|
1753
1929
|
log = self._parent.check_prefix(mydata['.tif']+mydata['.tiff'])
|
1754
1930
|
if log =='':
|
1755
|
-
self._txtctrl.WriteText(_("All is fine !"))
|
1931
|
+
self._txtctrl.WriteText("\n".join([_("All is fine !")]))
|
1756
1932
|
else:
|
1757
1933
|
self._txtctrl.WriteText(log)
|
1758
1934
|
|
@@ -1763,9 +1939,33 @@ class UI_Manager_2D_GPU():
|
|
1763
1939
|
|
1764
1940
|
log = self._parent.check_consistency()
|
1765
1941
|
if log =='':
|
1766
|
-
self._txtctrl.WriteText(_("All is fine !"))
|
1942
|
+
self._txtctrl.WriteText("\n\n".join([_("All is fine !")]))
|
1767
1943
|
else:
|
1768
|
-
self._txtctrl.WriteText(log)
|
1944
|
+
self._txtctrl.WriteText("\n\n".join([log]))
|
1945
|
+
|
1946
|
+
# Info on Python Environment and wolfgpu Path and version
|
1947
|
+
# -------------------------------------------------------
|
1948
|
+
|
1949
|
+
import sys
|
1950
|
+
# Python Environment
|
1951
|
+
self._txtctrl.write(_('\nPython Environment\n'))
|
1952
|
+
self._txtctrl.write('-------------------\n')
|
1953
|
+
self._txtctrl.write('Python version : {}\n'.format(sys.version))
|
1954
|
+
self._txtctrl.write('Python path : {}\n'.format(sys.executable))
|
1955
|
+
self._txtctrl.write('Python version info : {}\n'.format(sys.version_info))
|
1956
|
+
|
1957
|
+
# Test if wolfgpu.exe exists in script directory
|
1958
|
+
# wolfgpu Path and version
|
1959
|
+
self._txtctrl.write('\nWolfgpu Path and version\n')
|
1960
|
+
self._txtctrl.write('------------------------\n')
|
1961
|
+
|
1962
|
+
wolfgpu = self._parent.wolfgpu
|
1963
|
+
if wolfgpu.exists():
|
1964
|
+
self._txtctrl.write('Wolfgpu.exe found in : {}\n'.format(self._parent.wolfgpu.parent))
|
1965
|
+
else:
|
1966
|
+
self._txtctrl.write('Wolfgpu.exe not found !\n')
|
1967
|
+
self._parent.wolfgpu = None
|
1968
|
+
|
1769
1969
|
|
1770
1970
|
def choice_hydrograph(self) -> list[int]:
|
1771
1971
|
|
@@ -1871,7 +2071,11 @@ class UI_Manager_2D_GPU():
|
|
1871
2071
|
preserve_ic = ret == wx.ID_YES
|
1872
2072
|
dlg.Destroy()
|
1873
2073
|
|
1874
|
-
|
2074
|
+
pgbar = wx.ProgressDialog(_('Creating simulations ...'), _('Please wait ...'), maximum=len(hydro), parent=self._frame, style = wx.PD_APP_MODAL | wx.PD_AUTO_HIDE)
|
2075
|
+
|
2076
|
+
allsims = self._parent.create_simulation(Path(path), hydro, destroy_if_exists, preserve_ic, callback=pgbar.Update)
|
2077
|
+
|
2078
|
+
pgbar.Destroy()
|
1875
2079
|
|
1876
2080
|
self.reload()
|
1877
2081
|
|
@@ -1975,7 +2179,7 @@ class UI_Manager_2D_GPU():
|
|
1975
2179
|
try:
|
1976
2180
|
if curwp.Shown:
|
1977
2181
|
cursim.from_wolfparam(curwp)
|
1978
|
-
cursim.
|
2182
|
+
cursim._save_json()
|
1979
2183
|
except Exception as e:
|
1980
2184
|
self._wp[cursim] = None
|
1981
2185
|
logging.debug(_('Error while saving parameters for simulation {}'.format(cursim.path.name)))
|
@@ -1989,7 +2193,7 @@ class UI_Manager_2D_GPU():
|
|
1989
2193
|
try:
|
1990
2194
|
if curwp.Shown:
|
1991
2195
|
cursim.from_wolfparam(curwp)
|
1992
|
-
cursim.
|
2196
|
+
cursim._save_json()
|
1993
2197
|
except Exception as e:
|
1994
2198
|
self._wp[cursim] = None
|
1995
2199
|
logging.debug(_('Error while saving parameters for simulation {}'.format(cursim.path.name)))
|