wolfhece 2.2.37__py3-none-any.whl → 2.2.39__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/Coordinates_operations.py +5 -0
- wolfhece/GraphNotebook.py +72 -1
- wolfhece/GraphProfile.py +1 -1
- wolfhece/MulticriteriAnalysis.py +1579 -0
- wolfhece/PandasGrid.py +62 -1
- wolfhece/PyCrosssections.py +194 -43
- wolfhece/PyDraw.py +891 -73
- wolfhece/PyGui.py +913 -72
- wolfhece/PyGuiHydrology.py +528 -74
- wolfhece/PyPalette.py +26 -4
- wolfhece/PyParams.py +33 -0
- wolfhece/PyPictures.py +2 -2
- wolfhece/PyVertex.py +32 -0
- wolfhece/PyVertexvectors.py +147 -75
- wolfhece/PyWMS.py +52 -36
- wolfhece/acceptability/acceptability.py +15 -8
- wolfhece/acceptability/acceptability_gui.py +507 -360
- wolfhece/acceptability/func.py +80 -183
- wolfhece/apps/version.py +1 -1
- wolfhece/compare_series.py +480 -0
- wolfhece/drawing_obj.py +12 -1
- wolfhece/hydrology/Catchment.py +228 -162
- wolfhece/hydrology/Internal_variables.py +43 -2
- wolfhece/hydrology/Models_characteristics.py +69 -67
- wolfhece/hydrology/Optimisation.py +893 -182
- wolfhece/hydrology/PyWatershed.py +267 -165
- wolfhece/hydrology/SubBasin.py +185 -140
- wolfhece/hydrology/climate_data.py +334 -0
- wolfhece/hydrology/constant.py +11 -0
- wolfhece/hydrology/cst_exchanges.py +76 -1
- wolfhece/hydrology/forcedexchanges.py +413 -49
- wolfhece/hydrology/hyetograms.py +2095 -0
- wolfhece/hydrology/read.py +65 -5
- wolfhece/hydrometry/kiwis.py +42 -26
- wolfhece/hydrometry/kiwis_gui.py +7 -2
- wolfhece/insyde_be/INBE_func.py +746 -0
- wolfhece/insyde_be/INBE_gui.py +1776 -0
- wolfhece/insyde_be/__init__.py +3 -0
- wolfhece/interpolating_raster.py +366 -0
- wolfhece/irm_alaro.py +1457 -0
- wolfhece/irm_qdf.py +889 -57
- wolfhece/lifewatch.py +6 -3
- wolfhece/picc.py +124 -8
- wolfhece/pyLandUseFlanders.py +146 -0
- wolfhece/pydownloader.py +2 -1
- wolfhece/pywalous.py +225 -31
- wolfhece/toolshydrology_dll.py +149 -0
- wolfhece/wolf_array.py +63 -25
- {wolfhece-2.2.37.dist-info → wolfhece-2.2.39.dist-info}/METADATA +3 -1
- {wolfhece-2.2.37.dist-info → wolfhece-2.2.39.dist-info}/RECORD +53 -42
- {wolfhece-2.2.37.dist-info → wolfhece-2.2.39.dist-info}/WHEEL +0 -0
- {wolfhece-2.2.37.dist-info → wolfhece-2.2.39.dist-info}/entry_points.txt +0 -0
- {wolfhece-2.2.37.dist-info → wolfhece-2.2.39.dist-info}/top_level.txt +0 -0
wolfhece/acceptability/func.py
CHANGED
@@ -14,10 +14,9 @@ from typing import Union, Literal
|
|
14
14
|
from ..PyVertexvectors import Zones, zone, vector, wolfvertex, getIfromRGB
|
15
15
|
from ..PyTranslate import _
|
16
16
|
from ..scenario. config_manager import Config_Manager_2D_GPU
|
17
|
-
from ..eikonal import inpaint_waterlevel, inpaint_array
|
18
|
-
|
19
17
|
import subprocess
|
20
18
|
import geopandas as gpd
|
19
|
+
|
21
20
|
import pandas as pd
|
22
21
|
import numpy as np
|
23
22
|
from osgeo import gdal, ogr, osr, gdalconst
|
@@ -31,6 +30,7 @@ from enum import Enum
|
|
31
30
|
import numba as nb
|
32
31
|
import shutil
|
33
32
|
|
33
|
+
|
34
34
|
ENGINE = 'pyogrio' # or 'Fiona -- Pyogrio is faster
|
35
35
|
EXTENT = '.gpkg'
|
36
36
|
class Modif_Type(Enum):
|
@@ -593,25 +593,17 @@ class Accept_Manager():
|
|
593
593
|
idx_h = [Path(cursim).name.find(".tif") for cursim in sims_modif]
|
594
594
|
|
595
595
|
# create the list of return periods -- only the numeric part
|
596
|
-
sims = [int(Path(cursim).
|
596
|
+
sims = [int(Path(cursim).stem[1:]) for i, cursim in enumerate(sims_modif)]
|
597
597
|
return sorted(sims)
|
598
598
|
|
599
|
-
def get_modifiedrasters(self):
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
folder = Path(self.IN_CH_SA_SC)
|
606
|
-
mnt_tiff_files = [str(file.name) for file in folder.rglob("*.tiff") if file.name.startswith('MNTmodifs_')]
|
607
|
-
mnt_tif_files = [str(file.name) for file in folder.rglob("*.tif") if file.name.startswith('MNTmodifs_')]
|
608
|
-
mnt_files = mnt_tiff_files + mnt_tif_files
|
609
|
-
|
610
|
-
return vuln_files + mnt_files
|
599
|
+
def get_modifiedrasters(self, name:str):
|
600
|
+
"""Returns the name_ files (either vuln_ or MNTmodifs_) in CHANGE_VULNE to analyse later on the type."""
|
601
|
+
folder = Path(self.IN_CH_SA_SC) #common folder
|
602
|
+
name_paths = [file for file in folder.rglob("*.tif*") if file.name.startswith(name)]
|
603
|
+
return name_paths
|
611
604
|
|
612
605
|
def get_ponderations(self) -> pd.DataFrame:
|
613
606
|
""" Get the ponderation data from available simulations """
|
614
|
-
|
615
607
|
rt = self.get_return_periods()
|
616
608
|
|
617
609
|
if len(rt)==0:
|
@@ -985,24 +977,61 @@ class Accept_Manager():
|
|
985
977
|
tiff_trees.append(curtree)
|
986
978
|
return tiff_trees
|
987
979
|
|
988
|
-
def select_name_tif(self, path_baseline: Path, folder_path: Path, name) -> list[Path]:
|
980
|
+
def select_name_tif(self, path_baseline: Path, folder_path: Path, name, filter_type = False) -> tuple[list[Path], list[Path]]:
|
989
981
|
"""
|
990
|
-
Collects
|
982
|
+
Collects all .tiff files starting with `name` from `folder_path` and appends them to a list.
|
983
|
+
Checks each file's data type against the baseline raster and renames files with a mismatched type,
|
984
|
+
(allowing it not to be surimposed as it does not begin by "vuln_" anymore).
|
985
|
+
|
986
|
+
:param path_baseline: Path to the baseline raster file.
|
987
|
+
:type path_baseline: pathlib.Path
|
988
|
+
:param folder_path: Path to the folder containing raster files to check.
|
989
|
+
:type folder_path: pathlib.Path
|
990
|
+
:param name: Prefix name to filter .tiff files in the folder.
|
991
|
+
:type name: str
|
992
|
+
:return: A tuple containing two lists:
|
993
|
+
- files: List of paths with matching data type.
|
994
|
+
- unused_files: List of paths renamed due to type mismatch.
|
995
|
+
:rtype: tuple[list[pathlib.Path], list[pathlib.Path]]
|
991
996
|
"""
|
997
|
+
|
992
998
|
files = []
|
993
|
-
|
999
|
+
unused_files = []
|
1000
|
+
|
1001
|
+
# Check type of base of assembly
|
1002
|
+
ds_base = gdal.Open(path_baseline.as_posix())
|
1003
|
+
type_base = gdal.GetDataTypeName(ds_base.GetRasterBand(1).DataType)
|
1004
|
+
ds_base = None
|
1005
|
+
|
994
1006
|
files.append(path_baseline.as_posix())
|
995
|
-
tiff_trees = Accept_Manager.tree_name_tif(folder_path, name)
|
996
1007
|
|
997
|
-
#
|
1008
|
+
#any files that begin by 'name'
|
1009
|
+
tiff_trees = Accept_Manager.tree_name_tif(folder_path, name)
|
998
1010
|
for tree in tiff_trees:
|
999
|
-
|
1000
|
-
|
1011
|
+
file_path = tree[-1]
|
1012
|
+
ds = gdal.Open(file_path.as_posix())
|
1013
|
+
file_type = gdal.GetDataTypeName(ds.GetRasterBand(1).DataType)
|
1014
|
+
ds = None
|
1015
|
+
#filter if not the same type and renaming
|
1016
|
+
if filter_type == True :
|
1017
|
+
if file_type != type_base:
|
1018
|
+
suffix_to_add = f"_{file_type}"
|
1019
|
+
new_name = file_path.parent / f"{file_path.name}{suffix_to_add}"
|
1020
|
+
if not file_path.stem.endswith(suffix_to_add):
|
1021
|
+
file_path.rename(new_name)
|
1022
|
+
unused_files.append(new_name)
|
1023
|
+
else:
|
1024
|
+
unused_files.append(file_path)
|
1025
|
+
else:
|
1026
|
+
files.append(file_path.as_posix())
|
1027
|
+
else:
|
1028
|
+
files.append(file_path.as_posix())
|
1029
|
+
return files, unused_files
|
1001
1030
|
|
1002
1031
|
def check_nodata(self, name, path_baseline):
|
1003
1032
|
""" Check nodata in a path """
|
1004
1033
|
from ..wolf_array import WOLF_ARRAY_FULL_INTEGER8
|
1005
|
-
list_tif = Accept_Manager.select_name_tif(self, path_baseline, self.IN_CH_SA_SC, name)
|
1034
|
+
list_tif, unused = Accept_Manager.select_name_tif(self, path_baseline, self.IN_CH_SA_SC, name)
|
1006
1035
|
for cur_lst in list_tif:
|
1007
1036
|
curarray:WolfArray = WolfArray(cur_lst)
|
1008
1037
|
if curarray.wolftype != WOLF_ARRAY_FULL_INTEGER8:
|
@@ -1018,14 +1047,19 @@ class Accept_Manager():
|
|
1018
1047
|
""" Create a vrt file from a path """
|
1019
1048
|
logging.info(_('Checking nodata values...'))
|
1020
1049
|
self.check_nodata(name, fn_baseline)
|
1021
|
-
list_tif = Accept_Manager.select_name_tif(self, fn_baseline, fn_scenario, name)
|
1050
|
+
list_tif, list_fail = Accept_Manager.select_name_tif(self, fn_baseline, fn_scenario, name, filter_type = True)
|
1051
|
+
if len(list_fail)>0:
|
1052
|
+
return False, list_fail
|
1022
1053
|
#création du fichier vrt - assembly/agglomération
|
1023
1054
|
if len(list_tif)>1:
|
1024
1055
|
logging.info(_('Creating .vrt from files (first based)...'))
|
1025
|
-
|
1026
|
-
|
1056
|
+
if name == "vuln_":
|
1057
|
+
create_vrt_from_diverged_files_first_based(list_tif, fn_vrt, Nodata = 127)
|
1058
|
+
else :
|
1059
|
+
create_vrt_from_diverged_files_first_based(list_tif, fn_vrt, Nodata = 99999.)
|
1060
|
+
return True, list_fail
|
1027
1061
|
else:
|
1028
|
-
return False
|
1062
|
+
return False, list_fail
|
1029
1063
|
|
1030
1064
|
|
1031
1065
|
def translate_vrt2tif(self, fn_VRT, fn_vuln_s):
|
@@ -1050,163 +1084,26 @@ class Accept_Manager():
|
|
1050
1084
|
|
1051
1085
|
logging.info("All the existing .tif files have been copied to the destination directory.")
|
1052
1086
|
|
1053
|
-
def wich_river_trace(self):
|
1087
|
+
def wich_river_trace(self, state_toggle_scen):
|
1054
1088
|
""" Searches for existing riverbed traces: if none ending with '_scenarios' are found, it selects the baseline trace."""
|
1055
1089
|
trace = None
|
1056
|
-
if
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1090
|
+
if state_toggle_scen == True :
|
1091
|
+
if os.path.exists(self.OUT_MASKED_RIVER_S):
|
1092
|
+
trace = self.OUT_MASKED_RIVER_S
|
1093
|
+
logging.info(_(f"Used river mask = {self.OUT_MASKED_RIVER_S}."))
|
1094
|
+
elif os.path.exists(self.OUT_MASKED_RIVER):
|
1095
|
+
trace = self.OUT_MASKED_RIVER
|
1096
|
+
logging.error(_(f"No scenario_ river mask, the used river mask will be the one of the baseline = {self.OUT_MASKED_RIVER}."))
|
1097
|
+
else :
|
1098
|
+
logging.error(_("No Masked_River_extent file. Please provide it (button 'Update riverbed trace')."))
|
1060
1099
|
else :
|
1061
|
-
|
1100
|
+
if os.path.exists(self.OUT_MASKED_RIVER_S):
|
1101
|
+
trace = self.OUT_MASKED_RIVER_S
|
1102
|
+
logging.info(_(f"Used river mask = {self.OUT_MASKED_RIVER_S}."))
|
1103
|
+
else :
|
1104
|
+
logging.error(_("No Masked_River_extent file. Please provide it (button 'Update riverbed trace')."))
|
1062
1105
|
return trace
|
1063
1106
|
|
1064
|
-
# Interpolation
|
1065
|
-
# -------------
|
1066
|
-
|
1067
|
-
def batch_creation_and_interpolation_fotran_holes(self, checked_paths:list[Path], iftest:bool) -> tuple[bool, list[str]]:
|
1068
|
-
"""Creates a batch file to launch holes.exe from the selected simulations and launches it.
|
1069
|
-
|
1070
|
-
- Every files in EXTRACTED_LAST_STEP are interpolated for tests (iftest==True).
|
1071
|
-
- Only the check simulations of the windows are interpolated for the GUI (iftest!=True).
|
1072
|
-
|
1073
|
-
:param checked_paths: list of paths to the checked simulations
|
1074
|
-
:param iftest: boolean to indicate if the function is called from the tests or not
|
1075
|
-
"""
|
1076
|
-
|
1077
|
-
path_LastSteps = Path(self.IN_SA_EXTRACTED)
|
1078
|
-
|
1079
|
-
# Identifying the DEM and its mask
|
1080
|
-
C = None # DEM mask
|
1081
|
-
D = None # DEM
|
1082
|
-
for file in os.listdir(Path(self.IN_SA_DEM)):
|
1083
|
-
file_path = Path(self.IN_SA_DEM) / file
|
1084
|
-
if file_path.is_file() and file.startswith("MNT_") and file_path.suffix == ".bin":
|
1085
|
-
if "mask" not in file:
|
1086
|
-
D = file_path
|
1087
|
-
else:
|
1088
|
-
C = file_path
|
1089
|
-
|
1090
|
-
if D is None:
|
1091
|
-
return logging.error(_("DEM (.bin) not found in DEM_FILES. The file must begins by 'MNT_' and CANNOT include the word 'mask'"))
|
1092
|
-
|
1093
|
-
if C is None:
|
1094
|
-
return logging.error(_("DEM mask (.bin) not found in DEM_FILES. The file must begins by 'MNT_' and MUST include the word 'mask'"))
|
1095
|
-
|
1096
|
-
path_Interp = Path(self.IN_SA_INTERP)
|
1097
|
-
path_bat_file = os.path.join(self.IN_SCEN_DIR, "process_files.bat")
|
1098
|
-
|
1099
|
-
if os.path.exists(path_bat_file):
|
1100
|
-
logging.info(f"The file {path_bat_file} already exists and will be replaced.")
|
1101
|
-
os.remove(path_bat_file)
|
1102
|
-
|
1103
|
-
path_code = os.path.join(self.IN_WATER_DEPTH, "holes.exe")
|
1104
|
-
|
1105
|
-
A, B = [], []
|
1106
|
-
if iftest:
|
1107
|
-
# no checked box in the tests
|
1108
|
-
A = [path_LastSteps / f for f in os.listdir(path_LastSteps) if f.endswith('.bin') and not f.endswith('.bin.txt')]
|
1109
|
-
|
1110
|
-
else :
|
1111
|
-
for path in checked_paths:
|
1112
|
-
parts = path.name.split("sim_")
|
1113
|
-
A.extend([path_LastSteps / g for g in os.listdir(path_LastSteps) if g.endswith(f"{parts[1]}.bin")])
|
1114
|
-
|
1115
|
-
B = [path_Interp / f.stem for f in A]
|
1116
|
-
|
1117
|
-
if not A or not B or not C or not D:
|
1118
|
-
return logging.error(_("Missing files."))
|
1119
|
-
|
1120
|
-
with open(path_bat_file, "w") as bat_file:
|
1121
|
-
for a, b in zip(A, B):
|
1122
|
-
line = f'"{path_code}" filling in="{a}" out="{b}" mask="{C}" dem="{D} avoid_last=1"\n'
|
1123
|
-
bat_file.write(line)
|
1124
|
-
|
1125
|
-
empty_folder(self.IN_SA_INTERP)
|
1126
|
-
path_bat_file = self.IN_SCEN_DIR / "process_files.bat"
|
1127
|
-
subprocess.run([path_bat_file], check=True)
|
1128
|
-
|
1129
|
-
renamed_files = []
|
1130
|
-
path_fichier = self.IN_SA_INTERP
|
1131
|
-
for file in path_fichier.glob("*.tif"):
|
1132
|
-
if "_h" in file.name:
|
1133
|
-
new_name = file.stem.split("_h")[0].replace(".bin", "") + ".tif"
|
1134
|
-
file.rename(file.with_name(new_name))
|
1135
|
-
renamed_files.append(new_name)
|
1136
|
-
|
1137
|
-
#deleting the other
|
1138
|
-
for file in path_fichier.glob("*.tif"):
|
1139
|
-
if "_combl" in file.name or file.name not in renamed_files:
|
1140
|
-
file.unlink()
|
1141
|
-
|
1142
|
-
return True, renamed_files
|
1143
|
-
|
1144
|
-
def batch_creation_and_interpolation_python_eikonal(self, checked_paths:list[Path], iftest:bool) -> tuple[bool, list[str]]:
|
1145
|
-
"""Creates a batch file to launch holes.exe from the selected simulations and launches it.
|
1146
|
-
|
1147
|
-
- Every files in EXTRACTED_LAST_STEP are interpolated for tests (iftest==True).
|
1148
|
-
- Only the check simulations of the windows are interpolated for the GUI (iftest!=True).
|
1149
|
-
|
1150
|
-
:param checked_paths: list of paths to the checked simulations
|
1151
|
-
:param iftest: boolean to indicate if the function is called from the tests or not
|
1152
|
-
"""
|
1153
|
-
|
1154
|
-
path_LastSteps = Path(self.IN_SA_EXTRACTED)
|
1155
|
-
|
1156
|
-
# Identifying the DEM and its mask
|
1157
|
-
C = None # DEM mask
|
1158
|
-
D = None # DEM
|
1159
|
-
for file in os.listdir(Path(self.IN_SA_DEM)):
|
1160
|
-
file_path = Path(self.IN_SA_DEM) / file
|
1161
|
-
if file_path.is_file() and file.startswith("MNT_") and file_path.suffix == ".bin":
|
1162
|
-
if "mask" not in file:
|
1163
|
-
D = file_path
|
1164
|
-
else:
|
1165
|
-
C = file_path
|
1166
|
-
|
1167
|
-
if D is None:
|
1168
|
-
return logging.error(_("DTM (.bin) not found in DTM_FILES. The file must begins by 'MNT_' and CANNOT include the word 'mask'"))
|
1169
|
-
|
1170
|
-
if C is None:
|
1171
|
-
return logging.error(_("DEM mask (.bin) not found in DEM_FILES. The file must begins by 'MNT_' and MUST include the word 'mask'"))
|
1172
|
-
|
1173
|
-
path_Interp = Path(self.IN_SA_INTERP)
|
1174
|
-
path_bat_file = os.path.join(self.IN_SCEN_DIR, "process_files.bat")
|
1175
|
-
|
1176
|
-
if os.path.exists(path_bat_file):
|
1177
|
-
logging.info(f"The file {path_bat_file} already exists and will be replaced.")
|
1178
|
-
os.remove(path_bat_file)
|
1179
|
-
|
1180
|
-
A, B = [], []
|
1181
|
-
if iftest:
|
1182
|
-
# no checked box in the tests
|
1183
|
-
A = [path_LastSteps / f for f in os.listdir(path_LastSteps) if f.endswith('.bin') and not f.endswith('.bin.txt')]
|
1184
|
-
|
1185
|
-
else :
|
1186
|
-
for path in checked_paths:
|
1187
|
-
parts = path.name.split("sim_")
|
1188
|
-
A.extend([path_LastSteps / g for g in os.listdir(path_LastSteps) if g.endswith(f"{parts[1]}.bin")])
|
1189
|
-
|
1190
|
-
B = [path_Interp / f.stem for f in A]
|
1191
|
-
|
1192
|
-
if not A or not B or not C or not D:
|
1193
|
-
return logging.error(_("Missing files."))
|
1194
|
-
|
1195
|
-
renamed_files = []
|
1196
|
-
for a, b in zip(A, B):
|
1197
|
-
wa_a = WolfArray(a)
|
1198
|
-
wa_c = WolfArray(C)
|
1199
|
-
wa_d = WolfArray(D)
|
1200
|
-
_t, _d, wh = inpaint_array(data = wa_a.array,
|
1201
|
-
where_compute = wa_c.array.data != wa_c.array.data[0,0],
|
1202
|
-
test = wa_d.array.data,
|
1203
|
-
ignore_last_patches= 1)
|
1204
|
-
|
1205
|
-
new_name = b.with_suffix(".tif")
|
1206
|
-
wa_a.write_all(new_name)
|
1207
|
-
renamed_files.append(new_name.name)
|
1208
|
-
|
1209
|
-
return True, renamed_files
|
1210
1107
|
|
1211
1108
|
def clip_layer(layer:str,
|
1212
1109
|
file_path:str,
|
@@ -1717,9 +1614,9 @@ def compute_acceptability(manager:Accept_Manager,
|
|
1717
1614
|
|
1718
1615
|
#logging.info(interval)
|
1719
1616
|
|
1720
|
-
points_accept = pd.read_csv(manager.POINTS_CSV)
|
1721
|
-
|
1722
|
-
if interval not in points_accept["Interval"]:
|
1617
|
+
points_accept = pd.read_csv(manager.POINTS_CSV)
|
1618
|
+
|
1619
|
+
if interval not in points_accept["Interval"].to_list():
|
1723
1620
|
logging.error(_("The return period {} is not in the intermediate.csv file -- Please update it").format(interval))
|
1724
1621
|
return None
|
1725
1622
|
|