wolfhece 2.1.98__py3-none-any.whl → 2.1.99__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 +489 -25
- wolfhece/PyParams.py +18 -8
- wolfhece/PyVertex.py +12 -5
- wolfhece/PyVertexvectors.py +25 -14
- wolfhece/Results2DGPU.py +23 -7
- wolfhece/analyze_vect.py +177 -0
- wolfhece/apps/version.py +1 -1
- wolfhece/matplotlib_fig.py +1980 -0
- wolfhece/scenario/config_manager.py +190 -82
- wolfhece/wolf_array.py +6 -6
- wolfhece/wolfresults_2D.py +35 -4
- {wolfhece-2.1.98.dist-info → wolfhece-2.1.99.dist-info}/METADATA +1 -1
- {wolfhece-2.1.98.dist-info → wolfhece-2.1.99.dist-info}/RECORD +16 -14
- {wolfhece-2.1.98.dist-info → wolfhece-2.1.99.dist-info}/WHEEL +1 -1
- {wolfhece-2.1.98.dist-info → wolfhece-2.1.99.dist-info}/entry_points.txt +0 -0
- {wolfhece-2.1.98.dist-info → wolfhece-2.1.99.dist-info}/top_level.txt +0 -0
@@ -153,12 +153,20 @@ class InitialConditions_scenario():
|
|
153
153
|
|
154
154
|
if (dir / IC_scenario.WATERDEPTH.value).exists():
|
155
155
|
self.h = np.load(dir / IC_scenario.WATERDEPTH.value)
|
156
|
+
else:
|
157
|
+
logging.warning(_('No waterdepth file found !'))
|
156
158
|
if (dir / IC_scenario.DISCHARGE_X.value).exists():
|
157
159
|
self.qx = np.load(dir / IC_scenario.DISCHARGE_X.value)
|
160
|
+
else:
|
161
|
+
logging.warning(_('No discharge x file found !'))
|
158
162
|
if (dir / IC_scenario.DISCHARGE_Y.value).exists():
|
159
163
|
self.qy = np.load(dir / IC_scenario.DISCHARGE_Y.value)
|
164
|
+
else:
|
165
|
+
logging.warning(_('No discharge y file found !'))
|
160
166
|
if (dir /IC_scenario.BATHYMETRY.value).exists():
|
161
167
|
self.bathy = np.load(dir / IC_scenario.BATHYMETRY.value)
|
168
|
+
else:
|
169
|
+
logging.warning(_('No bathymetry file found !'))
|
162
170
|
|
163
171
|
@property
|
164
172
|
def z_elevation(self) -> np.ndarray:
|
@@ -231,6 +239,15 @@ class Config_Manager_2D_GPU:
|
|
231
239
|
|
232
240
|
self.load_data()
|
233
241
|
|
242
|
+
def _test_ui(self):
|
243
|
+
""" Test if the UI is available """
|
244
|
+
|
245
|
+
if self._ui is not None:
|
246
|
+
if self._ui._frame.IsShown():
|
247
|
+
return True
|
248
|
+
|
249
|
+
return False
|
250
|
+
|
234
251
|
def load_data(self):
|
235
252
|
""" Chargement/Rechargement des données """
|
236
253
|
self.configs = {}
|
@@ -418,7 +435,7 @@ class Config_Manager_2D_GPU:
|
|
418
435
|
_flatten(self.configs, self._flat_configs)
|
419
436
|
|
420
437
|
|
421
|
-
def check_prefix(self, list_tif:list[Path]) ->
|
438
|
+
def check_prefix(self, list_tif:list[Path]) -> str:
|
422
439
|
""" Check if all files have the right prefix """
|
423
440
|
|
424
441
|
logging.info(_('Checking if prefix of all files are right...\n'))
|
@@ -450,7 +467,7 @@ class Config_Manager_2D_GPU:
|
|
450
467
|
loclog += _('Did you mean "bath_" ?') + '\n'
|
451
468
|
break
|
452
469
|
|
453
|
-
tests = ['infil_', 'infl_', 'nfil_', 'ifil_', 'infiltration_']
|
470
|
+
tests = ['infil_', 'infl_', 'nfil_', 'ifil_', 'infiltration_', 'infli_']
|
454
471
|
for test in tests:
|
455
472
|
if curtif.name.lower().startswith(test):
|
456
473
|
loclog += _('Did you mean "infil_" ?') + '\n'
|
@@ -458,7 +475,9 @@ class Config_Manager_2D_GPU:
|
|
458
475
|
|
459
476
|
logging.warning(loclog)
|
460
477
|
|
461
|
-
|
478
|
+
log += loclog
|
479
|
+
|
480
|
+
return log
|
462
481
|
|
463
482
|
def check_consistency(self) -> str:
|
464
483
|
"""
|
@@ -505,7 +524,7 @@ class Config_Manager_2D_GPU:
|
|
505
524
|
# Analyze files
|
506
525
|
# -------------
|
507
526
|
|
508
|
-
def _find_files_subdirs(self, wd:Path, curdict:dict):
|
527
|
+
def _find_files_subdirs(self, wd:Path, curdict:dict, erase_cache:bool = True):
|
509
528
|
""" Recherche des fichiers de simulation/scenario dans un répertoire """
|
510
529
|
|
511
530
|
# create list for all extensions
|
@@ -517,6 +536,14 @@ class Config_Manager_2D_GPU:
|
|
517
536
|
for curel in scandir(wd):
|
518
537
|
if curel.is_file():
|
519
538
|
if not curel.name.startswith('__'):
|
539
|
+
if curel.name.startswith('cache_'):
|
540
|
+
if erase_cache:
|
541
|
+
# Delete cache file if exists. Normally, it should not exist as it is created by WOLF as temporary file.
|
542
|
+
# It will be recreated by WOLF if necessary and destroyed at the end of the process.
|
543
|
+
# The presence of this file is a sign that the simulation creation process was not completed.
|
544
|
+
Path(curel).unlink()
|
545
|
+
continue
|
546
|
+
|
520
547
|
parts=splitext(curel)
|
521
548
|
|
522
549
|
if len(parts)==2:
|
@@ -555,14 +582,14 @@ class Config_Manager_2D_GPU:
|
|
555
582
|
# test if it is a results directory
|
556
583
|
self._test_is_results(curdict)
|
557
584
|
|
558
|
-
def _recursive_find_files(self, wd:Path, curdict:dict):
|
585
|
+
def _recursive_find_files(self, wd:Path, curdict:dict, erase_cache:bool = True):
|
559
586
|
""" Recherche récursive des fichiers de simulation/scenario dans les répertoires dont la structure a été traduite en dictionnaire """
|
560
587
|
if len(curdict.keys())>0:
|
561
588
|
for k in curdict.keys():
|
562
589
|
self._recursive_find_files(k, curdict[k])
|
563
590
|
|
564
591
|
if not '__' in wd.name:
|
565
|
-
self._find_files_subdirs(wd, curdict)
|
592
|
+
self._find_files_subdirs(wd, curdict, erase_cache)
|
566
593
|
|
567
594
|
def _prefill_dict(self, curdict:dict):
|
568
595
|
""" Création des listes pour toutes les extensions """
|
@@ -809,7 +836,7 @@ class Config_Manager_2D_GPU:
|
|
809
836
|
new_zones.add_zone(new_zone)
|
810
837
|
|
811
838
|
curarray = WolfArray(curtif)
|
812
|
-
curarray.nullify_border(width=1)
|
839
|
+
curarray.nullify_border(width=1) # Force a null value border --> necessary to avoid artefacts in the contour as no test is done on the border
|
813
840
|
sux, sux, curvect, interior = curarray.suxsuy_contour()
|
814
841
|
new_zone.add_vector(curvect, forceparent=True)
|
815
842
|
curvect.set_legend_to_centroid(curtif.name)
|
@@ -848,88 +875,108 @@ class Config_Manager_2D_GPU:
|
|
848
875
|
if (from_path / curin).exists():
|
849
876
|
translate_vrt2tif(from_path / curin, from_path / curout)
|
850
877
|
|
851
|
-
def
|
852
|
-
"""
|
878
|
+
def apply_scripts_bath_mann_inf(self, from_path:Path):
|
879
|
+
""" Apply all scripts """
|
853
880
|
|
854
|
-
|
855
|
-
# import des modules
|
856
|
-
imported_modules = import_files(from_path.glob('*.py'))
|
881
|
+
filenames = ['__bathymetry.tif', '__manning.tif', '__infiltration.tif']
|
857
882
|
|
858
|
-
|
883
|
+
# check if present on disk
|
884
|
+
if not all([(from_path / curfile).exists() for curfile in filenames]):
|
885
|
+
logging.error(_('At least one of the files is missing !'))
|
886
|
+
|
887
|
+
for curfile in filenames:
|
888
|
+
if not (from_path / curfile).exists():
|
889
|
+
logging.error(_(f'{curfile} is missing !'))
|
890
|
+
return
|
891
|
+
|
892
|
+
arrays = [WolfArray(from_path / curfile) for curfile in filenames]
|
893
|
+
|
894
|
+
self._apply_scripts_update_topo_maning_inf(from_path, arrays[0], arrays[1], arrays[2])
|
895
|
+
|
896
|
+
# write the files
|
897
|
+
arrays[0].write_all(from_path / '__bathymetry_after_scripts.tif')
|
898
|
+
arrays[1].write_all(from_path / '__manning_after_scripts.tif')
|
899
|
+
arrays[2].write_all(from_path / '__infiltration_after_scripts.tif')
|
900
|
+
|
901
|
+
def _import_scripts(self, from_path:Path, which) -> list[types.ModuleType]:
|
902
|
+
""" List all modules in structure and import them.
|
903
|
+
|
904
|
+
As multiple files with a same name can be found in the structure,
|
905
|
+
a copy of the file is made in the same folder with a unique name
|
906
|
+
and then imported.
|
907
|
+
|
908
|
+
So, if a file is required in the script, the relative import can be used.
|
909
|
+
If we cache the file in an other folder, the relative import will not work.
|
910
|
+
|
911
|
+
After the import, the copied files are deleted.
|
912
|
+
"""
|
859
913
|
|
860
|
-
def _list_modules(self, from_path:Path):
|
861
|
-
""" List all modules in structure """
|
862
914
|
import shutil
|
863
915
|
|
916
|
+
assert isinstance(from_path, Path), _('Bad type for from_path !')
|
917
|
+
|
864
918
|
curtree = self.get_tree(from_path)
|
865
919
|
curdicts = self.get_dicts(curtree)
|
866
920
|
|
867
921
|
# tous les fichiers .py -> list of lists
|
868
|
-
all_py = [curpy for curdict in curdicts for curpy in curdict[GPU_2D_file_extensions.PY.value][
|
922
|
+
all_py = [curpy for curdict in curdicts for curpy in curdict[GPU_2D_file_extensions.PY.value][which]]
|
869
923
|
|
870
|
-
# make a copy in
|
871
|
-
|
872
|
-
|
924
|
+
# make a copy in a cache file in the same folder but with a unique name
|
925
|
+
to_import = []
|
926
|
+
for idx, cur_py in enumerate(all_py):
|
927
|
+
cur_py:Path
|
928
|
+
cur_dir = cur_py.parent
|
929
|
+
cached_name = 'cache_py_' + cur_py.stem + str(idx) + '.py'
|
930
|
+
shutil.copy(cur_py, cur_dir / cached_name)
|
931
|
+
to_import.append(cur_dir / cached_name)
|
873
932
|
|
874
|
-
|
875
|
-
for curfile in cache_dir.glob('*.py'):
|
876
|
-
curfile.unlink()
|
933
|
+
imported_mod = import_files(to_import)
|
877
934
|
|
878
|
-
#
|
879
|
-
for
|
880
|
-
|
935
|
+
# #del all caches files
|
936
|
+
# for cur_py in to_import:
|
937
|
+
# cur_py.unlink()
|
938
|
+
|
939
|
+
return imported_mod
|
940
|
+
|
941
|
+
def _import_scripts_topo_manning(self, from_path:Path) -> list[types.ModuleType]:
|
942
|
+
""" import all topo and manning scripts from a path """
|
881
943
|
|
882
|
-
return self.
|
944
|
+
return self._import_scripts(from_path, WOLF_UPDATE)
|
883
945
|
|
884
946
|
def _apply_scripts_update_topo_maning_inf(self,
|
885
|
-
|
947
|
+
modules:list[types.ModuleType] | Path | str,
|
886
948
|
array_bat:WolfArray,
|
887
949
|
array_mann:WolfArray,
|
888
950
|
array_inf:WolfArray):
|
889
951
|
""" Apply all scripts from a list of modules """
|
890
952
|
|
891
|
-
|
953
|
+
if isinstance(modules, str):
|
954
|
+
modules = Path(modules)
|
955
|
+
|
956
|
+
if isinstance(modules, Path):
|
957
|
+
modules = self._import_scripts_topo_manning(modules)
|
892
958
|
|
893
|
-
for curmod in
|
959
|
+
for curmod in modules:
|
894
960
|
instmod = curmod.Update_Sim_Scenario()
|
895
961
|
instmod.update_topobathy(array_bat)
|
896
962
|
instmod.update_manning(array_mann)
|
897
963
|
instmod.update_infiltration(array_inf)
|
898
964
|
|
899
965
|
def _import_scripts_bc(self, from_path:Path) -> list[types.ModuleType]:
|
900
|
-
"""
|
901
|
-
import shutil
|
902
|
-
|
903
|
-
curtree = self.get_tree(from_path)
|
904
|
-
curdicts = self.get_dicts(curtree)
|
905
|
-
|
906
|
-
# tous les fichiers .py -> list of lists
|
907
|
-
all_py = [curpy for curdict in curdicts for curpy in curdict[GPU_2D_file_extensions.PY.value][WOLF_BC]]
|
966
|
+
""" Import all BC's scripts from a path """
|
908
967
|
|
909
|
-
|
910
|
-
cache_dir.mkdir(exist_ok=True)
|
968
|
+
return self._import_scripts(from_path, WOLF_BC)
|
911
969
|
|
912
|
-
|
913
|
-
|
914
|
-
curfile.unlink()
|
915
|
-
|
916
|
-
# make a copy of all files in the cache folder
|
917
|
-
cache_py = []
|
918
|
-
for idx, cur_py in enumerate(all_py):
|
919
|
-
shutil.copy(cur_py, cache_dir / f'{idx}.py')
|
920
|
-
cache_py.append(cache_dir / f'{idx}.py')
|
921
|
-
|
922
|
-
# import des modules
|
923
|
-
imported_modules = import_files(cache_py)
|
924
|
-
|
925
|
-
return imported_modules
|
970
|
+
def _apply_scripts_bc(self, modules:list[types.ModuleType] | Path | str, sim:SimpleSimulation):
|
971
|
+
""" Apply all scripts from a list of modules """
|
926
972
|
|
973
|
+
if isinstance(modules, str):
|
974
|
+
modules = Path(modules)
|
927
975
|
|
928
|
-
|
929
|
-
|
976
|
+
if isinstance(modules, Path):
|
977
|
+
modules = self._import_scripts_bc(modules)
|
930
978
|
|
931
979
|
for curmod in modules:
|
932
|
-
|
933
980
|
curmod.Impose_BC_Scenario().impose_bc(sim)
|
934
981
|
|
935
982
|
|
@@ -946,9 +993,11 @@ class Config_Manager_2D_GPU:
|
|
946
993
|
def load_ic(self, path:Path) -> InitialConditions_scenario:
|
947
994
|
""" Load initial conditions from a path """
|
948
995
|
|
996
|
+
path = Path(path)
|
997
|
+
|
949
998
|
low_keys = [Path(curkey).name.lower() for curkey in self.configs.keys()]
|
950
999
|
if INITIAL_CONDITIONS in low_keys:
|
951
|
-
return InitialConditions_scenario(self.workingdir / INITIAL_CONDITIONS / path)
|
1000
|
+
return InitialConditions_scenario(self.workingdir / INITIAL_CONDITIONS / path.stem.replace('sim_', ''))
|
952
1001
|
else:
|
953
1002
|
return None
|
954
1003
|
|
@@ -1111,7 +1160,6 @@ class Config_Manager_2D_GPU:
|
|
1111
1160
|
infiltration.array.data[:,:] = 0
|
1112
1161
|
|
1113
1162
|
# applying Python scrpitps on ARRAYS
|
1114
|
-
# self._apply_scripts_update_topo_maning_inf(self._import_scripts_topo_manning(dir), bat, man, infiltration)
|
1115
1163
|
self._apply_scripts_update_topo_maning_inf(dir, bat, man, infiltration)
|
1116
1164
|
|
1117
1165
|
# save arrays on disk
|
@@ -1143,11 +1191,15 @@ class Config_Manager_2D_GPU:
|
|
1143
1191
|
cursim.nap[cursim.bathymetry != 99999.] = 1
|
1144
1192
|
|
1145
1193
|
if curic is None:
|
1194
|
+
curic:InitialConditions_scenario
|
1195
|
+
# No global initial conditions
|
1146
1196
|
if not preserve_ic:
|
1197
|
+
# reset initial conditions
|
1147
1198
|
cursim.h = np.zeros((self._header.nbx, self._header.nby), dtype=np.float32)
|
1148
1199
|
cursim.qx = np.zeros((self._header.nbx, self._header.nby), dtype=np.float32)
|
1149
1200
|
cursim.qy = np.zeros((self._header.nbx, self._header.nby), dtype=np.float32)
|
1150
1201
|
else:
|
1202
|
+
# Using initial conditions from disk - sim directory
|
1151
1203
|
if (curdir / 'h.npy').exists():
|
1152
1204
|
cursim.h = np.load(curdir / 'h.npy')
|
1153
1205
|
else:
|
@@ -1161,19 +1213,21 @@ class Config_Manager_2D_GPU:
|
|
1161
1213
|
else:
|
1162
1214
|
cursim.qy = np.zeros((self._header.nbx, self._header.nby), dtype=np.float32)
|
1163
1215
|
else:
|
1164
|
-
if
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1216
|
+
if not preserve_ic:
|
1217
|
+
# Using global initial conditions if available
|
1218
|
+
if curic.h is not None:
|
1219
|
+
cursim.h = curic.h
|
1220
|
+
else:
|
1221
|
+
cursim.h = np.zeros((self._header.nbx, self._header.nby), dtype=np.float32)
|
1222
|
+
if curic.qx is not None:
|
1223
|
+
cursim.qx = curic.qx
|
1224
|
+
else:
|
1225
|
+
cursim.qx = np.zeros((self._header.nbx, self._header.nby), dtype=np.float32)
|
1172
1226
|
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1227
|
+
if curic.qy is not None:
|
1228
|
+
cursim.qy = curic.qy
|
1229
|
+
else:
|
1230
|
+
cursim.qy = np.zeros((self._header.nbx, self._header.nby), dtype=np.float32)
|
1177
1231
|
|
1178
1232
|
cursim.infiltration_zones = np.asarray(infiltration.array.data, dtype=np.int32)
|
1179
1233
|
|
@@ -1199,7 +1253,7 @@ class Config_Manager_2D_GPU:
|
|
1199
1253
|
cursim._param_report_period = SimulationDuration.from_seconds(3600)
|
1200
1254
|
|
1201
1255
|
# applying Python scrpitps on SIMULATION --> Boundary conditions
|
1202
|
-
self._apply_scripts_bc(
|
1256
|
+
self._apply_scripts_bc(dir, cursim)
|
1203
1257
|
|
1204
1258
|
# cursim.h[cursim.infiltration_zones > 0] = .5
|
1205
1259
|
|
@@ -1276,8 +1330,17 @@ class Config_Manager_2D_GPU:
|
|
1276
1330
|
""" Transfer IC from one sim to another """
|
1277
1331
|
|
1278
1332
|
ic1 = self.load_ic(dir1)
|
1333
|
+
|
1334
|
+
if ic1 is None:
|
1335
|
+
logging.error(_('No IC found in {} !'.format(dir1)))
|
1336
|
+
return
|
1337
|
+
|
1279
1338
|
ic2 = self.load_ic(dir2)
|
1280
1339
|
|
1340
|
+
if ic2 is None:
|
1341
|
+
logging.error(_('No IC found in {} !'.format(dir2)))
|
1342
|
+
return
|
1343
|
+
|
1281
1344
|
ic2.qx = ic1.qx
|
1282
1345
|
ic2.qy = ic1.qy
|
1283
1346
|
ic2.set_h_from_z(ic1.z_elevation)
|
@@ -1401,6 +1464,10 @@ class UI_Manager_2D_GPU():
|
|
1401
1464
|
self._translate_vrt.Bind(wx.EVT_BUTTON,self.ontranslatevrt2tif)
|
1402
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'))
|
1403
1466
|
|
1467
|
+
self._apply_scripts = wx.Button(self._frame,label = _('Apply scripts on bathymetry, manning and infiltration'))
|
1468
|
+
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\n\n - bathymetry.py\n - manning.py\n - infiltration.py'))
|
1470
|
+
|
1404
1471
|
self._create_vec = wx.Button(self._frame,label = _('Search spatial coverage from current level'))
|
1405
1472
|
self._create_vec.Bind(wx.EVT_BUTTON,self.oncreatevec)
|
1406
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"'))
|
@@ -1417,9 +1484,9 @@ class UI_Manager_2D_GPU():
|
|
1417
1484
|
self._createsim.Bind(wx.EVT_BUTTON,self.oncreate_simulation)
|
1418
1485
|
self._createsim.SetToolTip(_('Create simulation(s) from selected hydrographs'))
|
1419
1486
|
|
1420
|
-
self._transfer_ic = wx.Button(self._frame,label = _('Transfer initial conditions'))
|
1487
|
+
self._transfer_ic = wx.Button(self._frame,label = _('Transfer global initial conditions'))
|
1421
1488
|
self._transfer_ic.Bind(wx.EVT_BUTTON,self.ontransfer_ic)
|
1422
|
-
self._transfer_ic.SetToolTip(_('Transfer initial conditions from a simulation to another'))
|
1489
|
+
self._transfer_ic.SetToolTip(_('Transfer global initial conditions from a simulation to another\n\nThe directory {} must exist !\n\nAnd subdirectories related to the discharges must also be present.\n\nIf not, firstly, extract global IC with ALT+DCLICK on simulations.'.format(INITIAL_CONDITIONS)))
|
1423
1490
|
|
1424
1491
|
self._extract_tif = wx.Button(self._frame,label = _('Extract .tif files for all selected scenarios'))
|
1425
1492
|
self._extract_tif.Bind(wx.EVT_BUTTON,self.onextract_tif)
|
@@ -1458,9 +1525,10 @@ class UI_Manager_2D_GPU():
|
|
1458
1525
|
sizer_buttons.Add(self._reload,1,wx.EXPAND)
|
1459
1526
|
sizer_buttons.Add(self._create_void_infil,1,wx.EXPAND)
|
1460
1527
|
sizer_buttons.Add(self._create_void_scripts,1,wx.EXPAND)
|
1528
|
+
sizer_buttons.Add(self._check_prefix,1,wx.EXPAND)
|
1461
1529
|
sizer_buttons.Add(self._create_vrt,1,wx.EXPAND)
|
1462
1530
|
sizer_buttons.Add(self._translate_vrt,1,wx.EXPAND)
|
1463
|
-
sizer_buttons.Add(self.
|
1531
|
+
sizer_buttons.Add(self._apply_scripts,1,wx.EXPAND)
|
1464
1532
|
sizer_buttons.Add(self._checkconsistency,1,wx.EXPAND)
|
1465
1533
|
sizer_buttons.Add(self._create_vec,1,wx.EXPAND)
|
1466
1534
|
sizer_buttons.Add(self.listsims,1,wx.EXPAND)
|
@@ -1508,16 +1576,21 @@ class UI_Manager_2D_GPU():
|
|
1508
1576
|
|
1509
1577
|
self._parent.filter_independent = self.filter.GetValue()
|
1510
1578
|
|
1579
|
+
def reload(self):
|
1580
|
+
""" Reload the structure """
|
1581
|
+
|
1582
|
+
self._parent.load_data()
|
1583
|
+
|
1511
1584
|
def onupdate_structure(self,e:wx.MouseEvent):
|
1512
1585
|
""" Mise à jour de la structure """
|
1513
1586
|
|
1514
|
-
self.
|
1587
|
+
self.reload()
|
1515
1588
|
|
1516
1589
|
def oncreate_void_infil(self, e:wx.MouseEvent):
|
1517
1590
|
""" Création d'un fichier d'infiltration vide """
|
1518
1591
|
|
1519
1592
|
self._parent.create_void_infil()
|
1520
|
-
self.
|
1593
|
+
self.reload()
|
1521
1594
|
|
1522
1595
|
def oncreate_void_scripts(self,e:wx.MouseEvent):
|
1523
1596
|
""" Création d'un script vide """
|
@@ -1570,7 +1643,7 @@ class UI_Manager_2D_GPU():
|
|
1570
1643
|
|
1571
1644
|
bc_void(file_bc)
|
1572
1645
|
|
1573
|
-
self.
|
1646
|
+
self.reload()
|
1574
1647
|
|
1575
1648
|
def oncreatevrt(self,e:wx.MouseEvent):
|
1576
1649
|
""" Création d'un fichier vrt """
|
@@ -1582,6 +1655,8 @@ class UI_Manager_2D_GPU():
|
|
1582
1655
|
self._parent.create_vrt(mydata['path'])
|
1583
1656
|
logging.info(_('... done !'))
|
1584
1657
|
|
1658
|
+
self.reload()
|
1659
|
+
|
1585
1660
|
def oncreatevec(self,e:wx.MouseEvent):
|
1586
1661
|
""" Création d'un fichier vec """
|
1587
1662
|
|
@@ -1612,6 +1687,8 @@ class UI_Manager_2D_GPU():
|
|
1612
1687
|
|
1613
1688
|
dlg.Destroy()
|
1614
1689
|
|
1690
|
+
self.reload()
|
1691
|
+
|
1615
1692
|
def ontranslatevrt2tif(self,e:wx.MouseEvent):
|
1616
1693
|
""" Traduction d'un fichier vrt en tif """
|
1617
1694
|
|
@@ -1626,10 +1703,38 @@ class UI_Manager_2D_GPU():
|
|
1626
1703
|
else:
|
1627
1704
|
mydata = self._treelist.GetItemData(self._selected_item)
|
1628
1705
|
|
1706
|
+
if not 'path' in mydata:
|
1707
|
+
logging.error(_('Please select a scenario to analyze !'))
|
1708
|
+
return
|
1709
|
+
|
1629
1710
|
# création du fichier vrt
|
1630
1711
|
self._parent.translate_vrt2tif(mydata['path'])
|
1631
1712
|
logging.info(_('... done !'))
|
1632
1713
|
|
1714
|
+
def onapply_scripts(self,e:wx.MouseEvent):
|
1715
|
+
""" Application des scripts sur les fichiers tif """
|
1716
|
+
|
1717
|
+
logging.info(_('Applying scripts ...'))
|
1718
|
+
if self._selected_item is None or self._selected_item == self._treelist.GetRootItem():
|
1719
|
+
logging.info(_('No item selected ! -- using root item'))
|
1720
|
+
with wx.MessageDialog(None, _('No item selected ! -- using root item'), _('Warning'), wx.OK | wx.CANCEL | wx.ICON_WARNING) as dlg:
|
1721
|
+
ret = dlg.ShowModal()
|
1722
|
+
if ret != wx.ID_OK:
|
1723
|
+
return
|
1724
|
+
mydata = self._parent.configs
|
1725
|
+
else:
|
1726
|
+
mydata = self._treelist.GetItemData(self._selected_item)
|
1727
|
+
|
1728
|
+
if not 'path' in mydata:
|
1729
|
+
logging.error(_('Please select a scenario to analyze !'))
|
1730
|
+
return
|
1731
|
+
|
1732
|
+
# application des scripts
|
1733
|
+
self._parent.apply_scripts_bath_mann_inf(mydata['path'])
|
1734
|
+
|
1735
|
+
self.reload()
|
1736
|
+
logging.info(_('... done !'))
|
1737
|
+
|
1633
1738
|
def oncheck_prefix(self,e:wx.MouseEvent):
|
1634
1739
|
""" Vérification des préfixes des fichiers tif """
|
1635
1740
|
|
@@ -1693,6 +1798,8 @@ class UI_Manager_2D_GPU():
|
|
1693
1798
|
for cursim in sims:
|
1694
1799
|
self._parent.extract_tif(cursim['path'], wdir)
|
1695
1800
|
|
1801
|
+
self.reload()
|
1802
|
+
|
1696
1803
|
logging.info(_('... done !'))
|
1697
1804
|
|
1698
1805
|
def ontransfer_ic(self, e:wx.MouseEvent):
|
@@ -1716,6 +1823,7 @@ class UI_Manager_2D_GPU():
|
|
1716
1823
|
|
1717
1824
|
self._parent.transfer_ic(Path(wdir), Path(wdir2))
|
1718
1825
|
|
1826
|
+
self.reload()
|
1719
1827
|
|
1720
1828
|
def oncreate_simulation(self, e:wx.MouseEvent):
|
1721
1829
|
""" Creation d'une simulation """
|
@@ -1765,7 +1873,7 @@ class UI_Manager_2D_GPU():
|
|
1765
1873
|
|
1766
1874
|
allsims = self._parent.create_simulation(Path(path), hydro, destroy_if_exists, preserve_ic)
|
1767
1875
|
|
1768
|
-
self.
|
1876
|
+
self.reload()
|
1769
1877
|
|
1770
1878
|
if allsims is None:
|
1771
1879
|
logging.error(_('No simulation created !'))
|
@@ -2042,7 +2150,7 @@ class UI_Manager_2D_GPU():
|
|
2042
2150
|
res_path = mydata['path'] / 'simul_gpu_results'
|
2043
2151
|
if res_path.exists():
|
2044
2152
|
sim = SimpleSimulation.load(mydata['path'])
|
2045
|
-
destpath = self._parent.workingdir /
|
2153
|
+
destpath = self._parent.workingdir / INITIAL_CONDITIONS / mydata['path'].name.replace('sim_', '')
|
2046
2154
|
sim.write_initial_condition_from_record(res_path, None, destpath)
|
2047
2155
|
|
2048
2156
|
if self._parent.filter_independent:
|
@@ -2173,7 +2281,7 @@ class UI_Manager_2D_GPU():
|
|
2173
2281
|
|
2174
2282
|
waterdepth = icpath / 'h.npy'
|
2175
2283
|
waterdepth = np.load(waterdepth)
|
2176
|
-
np.save(icpath / '
|
2284
|
+
np.save(icpath / '_h_before_filtering.npy', waterdepth)
|
2177
2285
|
|
2178
2286
|
# labellisation
|
2179
2287
|
labeled_array = waterdepth.copy()
|
@@ -2197,14 +2305,14 @@ class UI_Manager_2D_GPU():
|
|
2197
2305
|
qx = icpath / 'qx.npy'
|
2198
2306
|
if qx.exists():
|
2199
2307
|
qx = np.load(qx)
|
2200
|
-
np.save(icpath / '
|
2308
|
+
np.save(icpath / '_qx_before_filtering.npy', qx)
|
2201
2309
|
qx[newh==0.]=0.
|
2202
2310
|
np.save(icpath / 'qx.npy', qx)
|
2203
2311
|
|
2204
2312
|
qy = icpath / 'qy.npy'
|
2205
2313
|
if qy.exists():
|
2206
2314
|
qy = np.load(qy)
|
2207
|
-
np.save(icpath / '
|
2315
|
+
np.save(icpath / '_qy_before_filtering.npy', qy)
|
2208
2316
|
qy[newh==0.]=0.
|
2209
2317
|
np.save(icpath / 'qy.npy', qy)
|
2210
2318
|
|
wolfhece/wolf_array.py
CHANGED
@@ -49,19 +49,19 @@ from copy import deepcopy
|
|
49
49
|
from enum import Enum
|
50
50
|
|
51
51
|
try:
|
52
|
-
from
|
52
|
+
from .PyTranslate import _
|
53
53
|
except ImportError as e:
|
54
54
|
print(e)
|
55
|
-
raise Exception(_('Error importing
|
55
|
+
raise Exception(_('Error importing modules'))
|
56
56
|
|
57
57
|
try:
|
58
|
-
from
|
58
|
+
from osgeo import gdal
|
59
59
|
except ImportError as e:
|
60
60
|
print(e)
|
61
|
-
raise Exception(_('Error importing
|
61
|
+
raise Exception(_('Error importing GDAL library'))
|
62
62
|
|
63
63
|
try:
|
64
|
-
from .
|
64
|
+
from .Coordinates_operations import reproject_and_resample_raster
|
65
65
|
except ImportError as e:
|
66
66
|
print(e)
|
67
67
|
raise Exception(_('Error importing modules'))
|
@@ -7525,7 +7525,7 @@ class WolfArray(Element_To_Draw, header_wolf):
|
|
7525
7525
|
if update_min_max:
|
7526
7526
|
self.mypal.distribute_values(self.array.min(), self.array.max())
|
7527
7527
|
|
7528
|
-
def write_all(self, newpath:str = None, EPSG:int = 31370):
|
7528
|
+
def write_all(self, newpath:str | Path = None, EPSG:int = 31370):
|
7529
7529
|
"""
|
7530
7530
|
Ecriture de tous les fichiers d'un Wolf array
|
7531
7531
|
|
wolfhece/wolfresults_2D.py
CHANGED
@@ -12,6 +12,7 @@ import sys
|
|
12
12
|
import wx
|
13
13
|
from os.path import dirname, exists, join, splitext
|
14
14
|
from math import floor
|
15
|
+
from pathlib import Path
|
15
16
|
|
16
17
|
import numpy.ma as ma
|
17
18
|
import numpy as np
|
@@ -51,7 +52,6 @@ except Exception as ex:
|
|
51
52
|
|
52
53
|
from importlib.util import find_spec
|
53
54
|
s = find_spec('wolfhece.libs.wolfpy')
|
54
|
-
from pathlib import Path
|
55
55
|
|
56
56
|
# Not too sure about this find_spec. If the root
|
57
57
|
# directory is not the good one, the import search may
|
@@ -747,7 +747,6 @@ class Props_Res_2D(wx.Frame):
|
|
747
747
|
""" Load default palette """
|
748
748
|
|
749
749
|
import glob
|
750
|
-
from pathlib import Path
|
751
750
|
|
752
751
|
# list of all .pal file in model directory
|
753
752
|
|
@@ -2303,6 +2302,25 @@ class Wolfresults_2D(Element_To_Draw):
|
|
2303
2302
|
self.myops = None
|
2304
2303
|
self._active_blocks = 0
|
2305
2304
|
|
2305
|
+
@property
|
2306
|
+
def all_dt(self):
|
2307
|
+
#FIXME : defined in GPU version --> to be implemented for CPU version
|
2308
|
+
pass
|
2309
|
+
|
2310
|
+
@property
|
2311
|
+
def all_mostly_dry_mesh(self):
|
2312
|
+
#FIXME : defined in GPU version --> to be implemented for CPU version
|
2313
|
+
pass
|
2314
|
+
|
2315
|
+
@property
|
2316
|
+
def all_clock_time(self):
|
2317
|
+
#FIXME : defined in GPU version --> to be implemented for CPU version
|
2318
|
+
pass
|
2319
|
+
|
2320
|
+
@property
|
2321
|
+
def all_wet_meshes(self):
|
2322
|
+
#FIXME : defined in GPU version --> to be implemented for CPU version
|
2323
|
+
pass
|
2306
2324
|
|
2307
2325
|
def set_opacity(self, alpha:float):
|
2308
2326
|
""" Set the transparency of the array """
|
@@ -4435,9 +4453,9 @@ class Wolfresults_2D(Element_To_Draw):
|
|
4435
4453
|
def export_as(self,
|
4436
4454
|
outdir:str,
|
4437
4455
|
fields:list[views_2D],
|
4438
|
-
which:Literal['geotiff', 'shape'],
|
4456
|
+
which:Literal['geotiff', 'shape', 'numpy'],
|
4439
4457
|
multiband:bool=True):
|
4440
|
-
""" Export as geotiff or shapefile """
|
4458
|
+
""" Export as geotiff or shapefile or numpy """
|
4441
4459
|
|
4442
4460
|
oldview = self.get_currentview()
|
4443
4461
|
old_plotted = self.plotted
|
@@ -4470,6 +4488,19 @@ class Wolfresults_2D(Element_To_Draw):
|
|
4470
4488
|
[key.value for key,arr in arrays.items()],
|
4471
4489
|
shape_mask)
|
4472
4490
|
|
4491
|
+
elif which=='numpy':
|
4492
|
+
for curfield, curarray in arrays.items():
|
4493
|
+
if curfield == views_2D.TOPOGRAPHY:
|
4494
|
+
curarray.write_all(Path(outdir) / 'bathymetry.npy')
|
4495
|
+
elif curfield == views_2D.WATERDEPTH:
|
4496
|
+
curarray.write_all(Path(outdir) / 'h.npy')
|
4497
|
+
elif curfield == views_2D.QX:
|
4498
|
+
curarray.write_all(Path(outdir) / 'qx.npy')
|
4499
|
+
elif curfield == views_2D.QY:
|
4500
|
+
curarray.write_all(Path(outdir) / 'qy.npy')
|
4501
|
+
else:
|
4502
|
+
curarray.write_all(Path(outdir) / (curfield.value + '.npy'))
|
4503
|
+
|
4473
4504
|
self.plotted = old_plotted
|
4474
4505
|
self.set_currentview(oldview)
|
4475
4506
|
|