wolfhece 2.2.38__py3-none-any.whl → 2.2.40__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.
Files changed (50) hide show
  1. wolfhece/Coordinates_operations.py +5 -0
  2. wolfhece/GraphNotebook.py +72 -1
  3. wolfhece/GraphProfile.py +1 -1
  4. wolfhece/MulticriteriAnalysis.py +1579 -0
  5. wolfhece/PandasGrid.py +62 -1
  6. wolfhece/PyCrosssections.py +194 -43
  7. wolfhece/PyDraw.py +891 -73
  8. wolfhece/PyGui.py +913 -72
  9. wolfhece/PyGuiHydrology.py +528 -74
  10. wolfhece/PyPalette.py +26 -4
  11. wolfhece/PyParams.py +33 -0
  12. wolfhece/PyPictures.py +2 -2
  13. wolfhece/PyVertex.py +25 -0
  14. wolfhece/PyVertexvectors.py +94 -28
  15. wolfhece/PyWMS.py +52 -36
  16. wolfhece/acceptability/acceptability.py +15 -8
  17. wolfhece/acceptability/acceptability_gui.py +507 -360
  18. wolfhece/acceptability/func.py +80 -183
  19. wolfhece/apps/version.py +1 -1
  20. wolfhece/compare_series.py +480 -0
  21. wolfhece/drawing_obj.py +12 -1
  22. wolfhece/hydrology/Catchment.py +228 -162
  23. wolfhece/hydrology/Internal_variables.py +43 -2
  24. wolfhece/hydrology/Models_characteristics.py +69 -67
  25. wolfhece/hydrology/Optimisation.py +893 -182
  26. wolfhece/hydrology/PyWatershed.py +267 -165
  27. wolfhece/hydrology/SubBasin.py +185 -140
  28. wolfhece/hydrology/cst_exchanges.py +76 -1
  29. wolfhece/hydrology/forcedexchanges.py +413 -49
  30. wolfhece/hydrology/read.py +65 -5
  31. wolfhece/hydrometry/kiwis.py +14 -7
  32. wolfhece/insyde_be/INBE_func.py +746 -0
  33. wolfhece/insyde_be/INBE_gui.py +1776 -0
  34. wolfhece/insyde_be/__init__.py +3 -0
  35. wolfhece/interpolating_raster.py +366 -0
  36. wolfhece/irm_alaro.py +1457 -0
  37. wolfhece/irm_qdf.py +889 -57
  38. wolfhece/lazviewer/laz_viewer.py +4 -1
  39. wolfhece/lifewatch.py +6 -3
  40. wolfhece/picc.py +124 -8
  41. wolfhece/pyLandUseFlanders.py +146 -0
  42. wolfhece/pydownloader.py +35 -1
  43. wolfhece/pywalous.py +225 -31
  44. wolfhece/toolshydrology_dll.py +149 -0
  45. wolfhece/wolf_array.py +63 -25
  46. {wolfhece-2.2.38.dist-info → wolfhece-2.2.40.dist-info}/METADATA +3 -1
  47. {wolfhece-2.2.38.dist-info → wolfhece-2.2.40.dist-info}/RECORD +50 -41
  48. {wolfhece-2.2.38.dist-info → wolfhece-2.2.40.dist-info}/WHEEL +0 -0
  49. {wolfhece-2.2.38.dist-info → wolfhece-2.2.40.dist-info}/entry_points.txt +0 -0
  50. {wolfhece-2.2.38.dist-info → wolfhece-2.2.40.dist-info}/top_level.txt +0 -0
@@ -7,80 +7,36 @@ Copyright (c) 2025 University of Liege. All rights reserved.
7
7
  This script and its content are protected by copyright law. Unauthorized
8
8
  copying or distribution of this file, via any medium, is strictly prohibited.
9
9
  """
10
- import wx
11
- import numpy as np
12
- import logging
13
- import subprocess
14
- import shutil
15
- import os
16
- import geopandas as gpd
17
- import pandas as pd
18
- import matplotlib.pyplot as plt
19
- from matplotlib.figure import Figure
20
10
  from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
21
11
  from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar2Wx
12
+ from matplotlib.figure import Figure
13
+ from osgeo import gdal, osr
22
14
  from pathlib import Path
23
15
  from scipy.ndimage import label
24
- from gettext import gettext as _
25
- import rasterio
26
16
  from shapely.geometry import Polygon
17
+ import geopandas as gpd
18
+ import logging
19
+ import matplotlib.pyplot as plt
20
+ import numpy as np
21
+ import os
22
+ import pandas as pd
23
+ import shutil
24
+ import textwrap
25
+ import wx
27
26
 
27
+ from ..interpolating_raster import interpolating_raster
28
+ from ..PyDraw import WolfMapViewer, draw_type
29
+ from ..PyGui import MapManager
30
+ from ..PyTranslate import _
31
+ from ..Results2DGPU import wolfres2DGPU
32
+ from ..scenario.config_manager import Config_Manager_2D_GPU
33
+ from ..wolf_array import WolfArray, header_wolf
28
34
  from .acceptability import Base_data_creation, Database_to_raster, Vulnerability, Acceptability
29
35
  from .acceptability import steps_base_data_creation, steps_vulnerability, steps_acceptability
30
36
  from .func import Accept_Manager
31
- from ..wolf_array import WolfArray, header_wolf
32
- from ..scenario.config_manager import Config_Manager_2D_GPU
33
- from ..PyDraw import WolfMapViewer, draw_type
34
- from ..Results2DGPU import wolfres2DGPU
35
- from ..PyGui import MapManager
36
-
37
- BATHYMETRY_FOR_SIMULATION = "__bathymetry_after_scripts.tif"
38
-
39
- def nullvalue_for_hole(WA):
40
- """
41
- Sets the null value for a WolfArray to 0 (as per the convention in the interpolation routine).
42
- """
43
- WA.nullvalue = 0.
44
- WA.set_nullvalue_in_mask()
45
-
46
- def read_export_z_bin(fn_read, fn_write, fn_laststep, type_extraction):
47
- """
48
- Reads the free surface altitude from a GPU simulation and exports it in binary format.
49
- Inputs:
50
- - fn_read_simu: the simulation file to read.
51
- - fn_laststep: the folder EXTRACTED_LAST_STEP defined in acceptability.
52
- - fn_write: the path to save the output in binary format.
53
- """
54
37
 
55
- if type_extraction == "last_step":
56
- # fn_temp = os.path.join(fn_laststep, 'temp')
57
- # os.makedirs(fn_temp, exist_ok=True)
58
- wolfres2DGPU_test = wolfres2DGPU(fn_read)
59
- #changer ici + vérifier si bien SF ou WD (comparer ;) )
60
- wolfres2DGPU_test.read_oneresult(-1)
61
- wd = wolfres2DGPU_test.get_h_for_block(1)
62
- top = wolfres2DGPU_test.get_top_for_block(1)
63
- nullvalue_for_hole(wd)
64
- nullvalue_for_hole(top)
65
- wd.array = wd.array + top.array
66
- fn_write = fn_write.with_suffix('.bin')
67
- wd.write_all(fn_write)
68
- # shutil.rmtree(fn_temp)
69
-
70
- if type_extraction == "danger_map":
71
- # fn_temp = os.path.join(fn_laststep, 'temp')
72
- # os.makedirs(fn_temp, exist_ok=True)
73
- wolfres2DGPU_last = wolfres2DGPU(fn_read)
74
- wolfres2DGPU_last.read_oneresult(-1)
75
- danger_map_h = wolfres2DGPU(fn_read).danger_map_only_h(0,-1,1)
76
- top = wolfres2DGPU_last.get_top_for_block(1)
77
- nullvalue_for_hole(danger_map_h)
78
- nullvalue_for_hole(top)
79
- danger_map_h.array[danger_map_h.array != 0] += top.array[danger_map_h.array != 0]
80
- fn_write = fn_write.with_suffix('.bin')
81
- danger_map_h.write_all(fn_write)
82
- # shutil.rmtree(fn_temp)
83
38
 
39
+ BATHYMETRY_FOR_SIMULATION = "__bathymetry_after_scripts.tif"
84
40
 
85
41
  def riverbed_trace(fn_read_simu, fn_output, threshold, type_extraction):
86
42
  """
@@ -90,8 +46,6 @@ def riverbed_trace(fn_read_simu, fn_output, threshold, type_extraction):
90
46
  - fn_output: the location to save the riverbed trace as a .tiff file.
91
47
  - threshold: the water depth threshold above which the areas are considered riverbed.
92
48
  """
93
-
94
-
95
49
  if type_extraction == "last_step":
96
50
  wolfres2DGPU_test = wolfres2DGPU(fn_read_simu)
97
51
  wolfres2DGPU_test.read_oneresult(-1)
@@ -104,7 +58,7 @@ def riverbed_trace(fn_read_simu, fn_output, threshold, type_extraction):
104
58
  wd.write_all(Path(fn_output))
105
59
 
106
60
  if type_extraction=="danger_map":
107
- wd = wolfres2DGPU(fn_read_simu) .danger_map_only_h(0,-1,1)
61
+ wd = wolfres2DGPU(fn_read_simu).danger_map_only_h(0,-1,1)
108
62
  wd.array[wd.array > 1000] = 0
109
63
  wd.array[wd.array > threshold] = 1
110
64
  wd.array[wd.array < threshold] = 0
@@ -130,103 +84,16 @@ def empty_folder(folder):
130
84
  else:
131
85
  print("The folder does not exist.")
132
86
 
133
- """
134
- This script performs two main operations:
135
-
136
- 1. Subtraction of two raster TIFF files:
137
- - Identifies areas with building traces by subtracting the `bathymetry.tif` from simulations
138
- (corresponding to 'MNT_muret_bati') from `MNT` (DEM).
139
-
140
- 2. For the identified building areas (from step 1):
141
- - Replace the values with those from the `MNT` (ground level), ensuring it reflects the terrain, not bathymetry values.
142
-
143
- Final Output:
144
- - The mask should highlight building traces with corresponding DEM (`MNT`) values ("ground") inside, and its name must start with "MNT_" and include "mask" in it.
145
-
146
- Note: the computations are perfomed with tifs .tif rasters but should be translated to .bin files in the acceptability routine
147
- """
148
-
149
- #----------------------------------------------------------------------------------------------------------
150
-
151
- #1 - Soustraction bathymetry.tif (from simulations) - DEM (MNT, cfr "projet tuilage") ---------------------
152
-
153
- def soustraction(fn_a,fn_b,fn_result):
154
- with rasterio.open(fn_a) as src_a, rasterio.open(fn_b) as src_b:
155
- if (
156
- src_a.width != src_b.width or
157
- src_a.height != src_b.height or
158
- src_a.transform != src_b.transform or
159
- src_a.crs != src_b.crs
160
- ):
161
- logging.error(f"{fn_a} and {fn_b} do not have the same properties, please edit them.")
162
-
163
-
164
- data_a = src_a.read(1)
165
- data_b = src_b.read(1)
166
-
167
- #(A - B)
168
- data_diff = data_a - data_b
169
- nodata_value = src_a.nodata if src_a.nodata == src_b.nodata else None
170
- if nodata_value is not None:
171
- data_diff[(data_a == nodata_value) | (data_b == nodata_value)] = nodata_value
172
-
173
- data_diff[data_diff > 5000] = 0
174
- labeled, n = label(data_diff)
175
- # Remove small objects
176
- threshold = 5
177
- sizes = np.bincount(labeled.ravel())
178
- idx_small = np.where(sizes <= threshold)[0]
179
- data_diff[np.isin(labeled, idx_small)] = 0
180
-
181
- out_meta = src_a.meta.copy()
182
- out_meta.update({
183
- "dtype": "float32",
184
- "driver": "GTiff"
185
- })
186
-
187
- with rasterio.open(fn_result, "w", **out_meta) as dst:
188
- dst.write(data_diff, 1)
189
-
190
-
191
- #2 - DEM (MNT) value in the buildings traces ------------------------------------------------------------------
192
- def mask_creation_data(mask_file, ground_file, output_file):
193
- with rasterio.open(mask_file) as mask_src:
194
- mask = mask_src.read(1).astype('float32')
195
- mask_meta = mask_src.meta
196
-
197
- indices = np.where(mask > 0)
198
-
199
- with rasterio.open(ground_file) as bathy_src:
200
- bathy = bathy_src.read(1)
201
-
202
- mask[indices] = bathy[indices]
203
- mask[mask <= 0] = 99999.
204
-
205
- output_meta = mask_meta.copy()
206
- output_meta.update({"dtype": 'float32'})
207
-
208
- with rasterio.open(output_file, "w", **output_meta) as dst:
209
- dst.write(mask, 1)
210
-
211
- WA_mask = WolfArray(output_file)
212
- WA_mask.write_all(Path(Path(output_file).parent / "MNT_computed_with_mask.bin"))
213
-
214
- def MNT_and_mask_creation_all(fn_bathy, fn_mtn_cropped, fn_where_buildings, fn_mask_final):
215
- #couper_raster()
216
- soustraction(fn_bathy, fn_mtn_cropped, fn_where_buildings)
217
- mask_creation_data(fn_where_buildings, fn_mtn_cropped, fn_mask_final)
218
-
219
- #--------------------------------------------------------------------------------------------------------------
220
-
221
87
  def create_INPUT_TEMP_OUTPUT_forScenario(maindir, study_area, scenario, simu_gpu):
222
88
  """Creates folder for a new study area or/and scenario. The last argument simu_gpu is used when loading simulation (indicates path to the simulation folder),
223
89
  if not used, indicate None to ignore it."""
224
- base_pathwd = Path(maindir) / "INPUT" / "WATER_DEPTH" / study_area.stem / scenario
90
+ study_area = Path(study_area).stem
91
+ base_pathwd = Path(maindir) / "INPUT" / "WATER_DEPTH" / study_area / scenario
225
92
  subfolders = ["DEM_FILES", "INTERP_WD", "EXTRACTED_LAST_STEP_WD"]
226
93
  os.makedirs(base_pathwd, exist_ok=True)
227
94
  for folder in subfolders:
228
95
  os.makedirs(os.path.join(base_pathwd, folder), exist_ok=True)
229
- base_pathch = Path(maindir) / "INPUT" / "CHANGE_VULNE" / study_area.stem / scenario
96
+ base_pathch = Path(maindir) / "INPUT" / "CHANGE_VULNE" / study_area / scenario
230
97
  os.makedirs(base_pathch, exist_ok=True)
231
98
 
232
99
  if simu_gpu != None:
@@ -235,7 +102,7 @@ def create_INPUT_TEMP_OUTPUT_forScenario(maindir, study_area, scenario, simu_gpu
235
102
  create_shapefile_from_prop_tif(path_bat_gpu, Path(maindir) / "INPUT" / "STUDY_AREA" / f"{study_area}.shp")
236
103
  logging.info(_("Study area file created in INPUT/STUDY_AREA."))
237
104
  else :
238
- logging.error(f"Error in the study area creation : no bathymetry.tif file in the given simulation folder {simu_gpu}. Please provide it in this folder and try again.")
105
+ logging.error(_(f"Error in the study area creation : no bathymetry.tif file in the given simulation folder {simu_gpu}. Please provide it in this folder and try again."))
239
106
 
240
107
  Accept_Manager(main_dir=maindir, Study_area=study_area, scenario=scenario)
241
108
  logging.info(_(f"Files created in INPUT, TEMP and OUTPUT for the study area named '{study_area}', and the scenario named '{scenario}'"))
@@ -243,32 +110,38 @@ def create_INPUT_TEMP_OUTPUT_forScenario(maindir, study_area, scenario, simu_gpu
243
110
 
244
111
  def get_transform_and_crs(tif_file):
245
112
  """
246
- For TIFF file manipulation, reads the CRS and the transform, and returns them.
113
+ For TIFF file manipulation, reads the CRS and the geotransform, and returns them.
247
114
  """
248
-
249
- with rasterio.open(tif_file) as src:
250
- transform = src.transform
251
- crs = src.crs
115
+ ds = gdal.Open(tif_file)
116
+ transform = ds.GetGeoTransform()
117
+ crs_wkt = ds.GetProjection()
118
+ crs = osr.SpatialReference()
119
+ crs.ImportFromWkt(crs_wkt)
252
120
  return transform, crs
253
121
 
254
122
  def create_shapefile_from_prop_tif(fn_tif, shapefile_path):
255
- """
256
- Creates a shapefile of the study area based on the extent of an input TIFF file.
257
- Inputs:
258
- - fn_tif: the path to the input TIFF file.
259
- - shapefile_path: the location to save the output shapefile.
260
- """
261
- _,_,width,height,_,_ = get_header_info(fn_tif)
262
- transform, crs = get_transform_and_crs(fn_tif)
263
- top_left = transform * (0, 0)
264
- bottom_left = transform * (0, height)
265
- top_right = transform * (width, 0)
266
- bottom_right = transform * (width, height)
123
+ unused, unused, width, height, unused, unused = get_header_info(fn_tif)
124
+ ds = gdal.Open(fn_tif)
125
+ width = ds.RasterXSize
126
+ height = ds.RasterYSize
127
+ gt = ds.GetGeoTransform()
128
+
129
+ originX, pixelWidth, unused, originY, unused, pixelHeight = gt
130
+
131
+ top_left = (originX, originY)
132
+ top_right = (originX + width * pixelWidth, originY)
133
+ bottom_left = (originX, originY + height * pixelHeight)
134
+ bottom_right = (originX + width * pixelWidth, originY + height * pixelHeight)
267
135
 
268
136
  rectangle = Polygon([top_left, top_right, bottom_right, bottom_left, top_left])
269
- gdf = gpd.GeoDataFrame({'geometry': [rectangle]})
270
- gdf.set_crs(crs, allow_override=True, inplace=True)
137
+
138
+ sr = osr.SpatialReference()
139
+ sr.ImportFromWkt(ds.GetProjection())
140
+ crs_wkt = sr.ExportToWkt()
141
+
142
+ gdf = gpd.GeoDataFrame({'geometry': [rectangle]}, crs=crs_wkt)
271
143
  gdf.to_file(shapefile_path)
144
+ ds = None
272
145
 
273
146
  def get_header_info(fn):
274
147
  """
@@ -285,7 +158,6 @@ def get_header_comparison(list_fn):
285
158
  """
286
159
  Reads the headers from the files in list_fn and compares them. The result 'comp' is True if the headers are identical, and False otherwise.
287
160
  """
288
-
289
161
  header_infos = [get_header_info(fn) for fn in list_fn]
290
162
  variable_names = ["dx", "dy", "nbx", "nby", "X", "Y"]
291
163
  for idx, name in enumerate(variable_names):
@@ -296,7 +168,6 @@ def get_header_comparison(list_fn):
296
168
  comp = True
297
169
  return comp
298
170
 
299
-
300
171
  def display_info_header(self_dx, self_nbxy, self_O, fn):
301
172
  """
302
173
  Displays the header at the path 'fn', and update the values displayed in the acceptability window.
@@ -326,12 +197,47 @@ def update_info_header(self_dx, self_nbxy, self_O, fn):
326
197
  dx,dy,nbx,nby,X,Y = display_info_header(self_dx, self_nbxy, self_O, tif_list_fn[0])
327
198
  return dx,dy,nbx,nby,X,Y
328
199
  else:
329
- logging.error("The interpolated files have different headers. Please fix it.")
200
+ logging.error(_("The interpolated files have different headers. Please fix it."))
330
201
  return False, False, False, False, False, False
331
202
  else :
332
203
  vanish_info_header(self_dx, self_nbxy, self_O)
333
204
  return False, False, False, False, False, False
334
205
 
206
+ def create_vuln_file(tif_file, path_vuln):
207
+ src_ds = gdal.Open(str(tif_file))
208
+ driver = gdal.GetDriverByName("GTiff")
209
+
210
+ xsize = src_ds.RasterXSize
211
+ ysize = src_ds.RasterYSize
212
+ geotransform = src_ds.GetGeoTransform()
213
+ projection = src_ds.GetProjection()
214
+
215
+ # lire le raster source
216
+ src_band = src_ds.GetRasterBand(1)
217
+ src_data = src_band.ReadAsArray()
218
+ src_nodata = src_band.GetNoDataValue()
219
+
220
+ # préparer le tableau de sortie (1 partout)
221
+ data = np.ones((ysize, xsize), dtype=np.uint8)
222
+
223
+ # mettre 127 là où le raster source est nodata
224
+ if src_nodata is not None:
225
+ mask = src_data == src_nodata
226
+ data[mask] = 127
227
+
228
+ # créer le raster vuln_
229
+ output_file = path_vuln / tif_file.name.replace("bath_", "vuln_")
230
+ dst_ds = driver.Create(str(output_file), xsize, ysize, 1, gdal.GDT_Byte)
231
+ dst_ds.SetGeoTransform(geotransform)
232
+ dst_ds.SetProjection(projection)
233
+
234
+ band = dst_ds.GetRasterBand(1)
235
+ band.WriteArray(data)
236
+ band.SetNoDataValue(127)
237
+
238
+ dst_ds = None
239
+ src_ds = None
240
+
335
241
  def search_for_modif_bath_and_copy(main_gpu, from_path, path_vuln):
336
242
  """
337
243
  When loading gpu simulations for last step extraction, search for modified bath_ topography file, according to
@@ -348,22 +254,30 @@ def search_for_modif_bath_and_copy(main_gpu, from_path, path_vuln):
348
254
  found_bath = True
349
255
  for tif_file in all_tif_bath:
350
256
  found_bath = True
351
- with rasterio.open(tif_file) as src:
352
- #vuln_ files
353
- metadata = src.meta.copy()
354
- metadata.update(dtype=rasterio.uint8, count=1, nodata=0)
355
- data = np.ones((metadata['height'], metadata['width']), dtype=rasterio.uint8)
356
- output_file = path_vuln / tif_file.name.replace('bath_', 'vuln_')
357
- with rasterio.open(output_file, 'w', **metadata) as dst:
358
- dst.write(data, 1)
359
- #MNTmodifs_ files
360
- metadata.update(dtype=rasterio.float32, count=1, nodata=0)
361
- data = np.ones((metadata['height'], metadata['width']), dtype=rasterio.float32)
362
- output_file = path_vuln / tif_file.name.replace('bath_', 'MNTmodifs_')
363
- with rasterio.open(output_file, 'w', **metadata) as dst:
364
- dst.write(data, 1)
365
-
366
- return found_bath
257
+ src_ds = gdal.Open(str(tif_file))
258
+ driver = gdal.GetDriverByName("GTiff")
259
+
260
+ xsize = src_ds.RasterXSize
261
+ ysize = src_ds.RasterYSize
262
+ geotransform = src_ds.GetGeoTransform()
263
+ projection = src_ds.GetProjection()
264
+
265
+ # vuln_ file
266
+ create_vuln_file(tif_file,path_vuln)
267
+
268
+ # MNTmodifs_ file
269
+ output_file = path_vuln / tif_file.name.replace("bath_", "MNTmodifs_")
270
+ dst_ds = driver.Create(str(output_file), xsize, ysize, 1, gdal.GDT_Float32)
271
+ dst_ds.SetGeoTransform(geotransform)
272
+ dst_ds.SetProjection(projection)
273
+ data = np.ones((ysize, xsize), dtype=np.float32)
274
+ dst_ds.GetRasterBand(1).WriteArray(data)
275
+ dst_ds.GetRasterBand(1).SetNoDataValue(0)
276
+ dst_ds = None
277
+
278
+ src_ds = None
279
+
280
+ return found_bath
367
281
 
368
282
  def mapviewer_display(list_path, mapviewer=None):
369
283
  """ Load the output in the mapviewer on WOLF """
@@ -385,7 +299,6 @@ def mapviewer_display(list_path, mapviewer=None):
385
299
 
386
300
  class AcceptabilityGui(wx.Frame):
387
301
  """ The main frame for the vulnerability/acceptability computation """
388
-
389
302
  def __init__(self, parent=None, width=1024, height=500):
390
303
 
391
304
  super(wx.Frame, self).__init__(parent, title='Acceptability score manager', size=(width, height))
@@ -539,67 +452,78 @@ class AcceptabilityGui(wx.Frame):
539
452
  sizer_vert1 = wx.BoxSizer(wx.VERTICAL)
540
453
  sizer_hor_threads = wx.BoxSizer(wx.HORIZONTAL)
541
454
  sizer_hor1 = wx.BoxSizer(wx.HORIZONTAL)
542
- sizer_hor1_1 = wx.BoxSizer(wx.HORIZONTAL)
543
455
  sizer_hor2 = wx.BoxSizer(wx.HORIZONTAL)
544
456
  sizer_hor3 = wx.BoxSizer(wx.HORIZONTAL)
545
457
  sizer_hor4 = wx.BoxSizer(wx.HORIZONTAL)
458
+ sizer_hor5 = wx.BoxSizer(wx.HORIZONTAL)
546
459
  sizer_hor_scen = wx.BoxSizer(wx.HORIZONTAL)
547
460
 
548
461
  # 1st LINE - Loading acceptability folder
549
462
  panel = wx.Panel(self)
550
- self._but_maindir = wx.Button(panel, label='Main Directory')
551
- self._but_maindir.SetToolTip("To indicate where the main acceptability\n folder is located.")
463
+ self._but_maindir = wx.Button(panel, label=_('Main Directory'))
464
+ self._but_maindir.SetToolTip(_("To indicate where the main acceptability\n folder is located."))
552
465
  self._but_maindir.SetFont(wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
553
466
  self._but_maindir.Bind(wx.EVT_BUTTON, self.OnMainDir)
554
467
 
555
468
  self._listbox_studyarea = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
556
469
  self.layout_listbox(self._listbox_studyarea)
557
470
  self._listbox_studyarea.Bind(wx.EVT_LISTBOX, self.OnStudyArea)
558
- self._listbox_studyarea.SetToolTip("Choose the study area existed in the folder.")
471
+ self._listbox_studyarea.SetToolTip(_("Choose the study area existed in the folder."))
559
472
 
560
473
  self._listbox_scenario = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
561
474
  self.layout_listbox(self._listbox_scenario)
562
475
  self._listbox_scenario.Bind(wx.EVT_LISTBOX, self.OnScenario)
563
- self._listbox_scenario.SetToolTip("Choose the acceptability scenario.")
476
+ self._listbox_scenario.SetToolTip(_("Choose the acceptability scenario."))
564
477
 
565
478
  sizer_ver_small = wx.BoxSizer(wx.VERTICAL)
566
- self._but_checkfiles = wx.Button(panel, label='Check structure')
479
+ self._but_checkfiles = wx.Button(panel, label=_('Check structure'))
567
480
  self._but_checkfiles.Bind(wx.EVT_BUTTON, self.OnCheckFiles)
568
- self._but_checkfiles.SetToolTip("Checks if the folder is correctly structured\n with INPUT, TEMP, OUTPUT.")
569
- self._but_checksim = wx.Button(panel, label='Check simulations')
570
- self._but_checksim.SetToolTip("Displays the loaded simulations, interpolated in INTERP_WD.")
481
+ self._but_checkfiles.SetToolTip(_("Checks if the folder is correctly structured\n with INPUT, TEMP, OUTPUT."))
482
+ self._but_checksim = wx.Button(panel, label=_('Check simulations'))
483
+ self._but_checksim.SetToolTip(_("Displays the loaded simulations, interpolated in INTERP_WD."))
571
484
  self._but_checksim.Bind(wx.EVT_BUTTON, self.OnHydrodynInput)
572
485
 
573
- self._but_checkpond= wx.Button(panel, label='Check ponderation')
486
+ self._but_checkpond= wx.Button(panel, label=_('Check ponderation'))
574
487
  self._but_checkpond.Bind(wx.EVT_BUTTON, self.OnCheckPond)
575
- self._but_checkpond.SetToolTip("Displays a graph of the computed weighting coefficient\n of the final acceptability computations.")
488
+ self._but_checkpond.SetToolTip(_("Displays a graph of the computed weighting coefficient\n of the final acceptability computations."))
576
489
 
577
490
  # 2nd LINE - Hydrodynamic part
578
- self._but_loadgpu = wx.Button(panel, label='Load new\n hydraulic scenarios')
579
- self._but_loadgpu.SetToolTip("To load or change the hydraulic simulations")
491
+ self._but_loadgpu = wx.ToggleButton(panel, label=_('Working with new\n hydraulic scenarios'))
492
+ self._but_loadgpu.SetToolTip(_("To load or change the hydraulic simulations"))
580
493
  self._but_loadgpu.SetFont(wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
581
- self._but_loadgpu.Bind(wx.EVT_BUTTON, self.OnLoadingSimu)
582
- sizer_hor1_1.Add(self._but_loadgpu, 1, wx.ALL | wx.EXPAND, 0)
583
-
494
+ self._but_loadgpu.Bind(wx.EVT_TOGGLEBUTTON, self.OnLoadingSimu)
495
+ sizer_hor2.Add(self._but_loadgpu, 1, wx.ALL | wx.EXPAND, 0)
584
496
 
585
497
  self._check_listbox = wx.CheckListBox(panel, choices=[], style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
586
498
  self.layout_listbox(self._check_listbox)
587
499
  self.sims = {}
588
- sizer_hor1_1.Add(self._check_listbox, 1, wx.ALL | wx.EXPAND, 0) #ajouter!! sinon s'affiche pas
500
+ sizer_hor2.Add(self._check_listbox, 1, wx.ALL | wx.EXPAND, 0) #ajouter!! sinon s'affiche pas
589
501
 
590
- self._but_DEM = wx.Button(panel, label='Check DEM inputs\n for interpolation')
591
- self._but_DEM.SetToolTip("To display the existing DEM input for the interpolation of the simulated free surfaces.")
592
- self._but_DEM.Bind(wx.EVT_BUTTON, self.OnDEM)
593
- sizer_hor1_1.Add(self._but_DEM, 1, wx.ALL | wx.EXPAND, 0)
594
-
595
- self._but_extrinterp = wx.Button(panel, label='Reading and interpolating\n free surface')
596
- self._but_extrinterp.SetToolTip("To read the simulation, and created the hydraulic input for\n acceptability (interpolated simulated free surfaces)")
597
- self._but_extrinterp.Bind(wx.EVT_BUTTON, self.on_button_click2)
502
+ self._but_danger = wx.Button(panel, label=_('Extract last step or\n compute danger map ▼'))
503
+ self._but_danger.SetToolTip(_("To create the danger maps of velocities and water depth. Please be patient."))
504
+ self._but_danger.Bind(wx.EVT_BUTTON, self.on_button_click2)
505
+ sizer_hor2.Add(self._but_danger, 1, wx.ALL | wx.EXPAND, 0)
506
+
598
507
  self.menu2 = wx.Menu()
599
- self.menu2.Append(1, "Interpolate the last step of the simulation.")
600
- self.menu2.Append(2, "Interpolate the danger map of the simulation.")
601
- self.menu2.Bind(wx.EVT_MENU, self.OnInterpolation)
602
- sizer_hor1_1.Add(self._but_extrinterp, 1, wx.ALL | wx.EXPAND, 0)
508
+ self.menu2.Append(1, _("Extract the last step of the simulation."))
509
+ self.menu2.Append(2, _("Compute the danger maps of the simulation."))
510
+ self.menu2.Bind(wx.EVT_MENU, self.OnDanger)
511
+
512
+ sizer_ver_small2 = wx.BoxSizer(wx.VERTICAL)
513
+ self._but_DEM = wx.Button(panel, label=_("Check DEM, DTM for interpolation"))
514
+ self._but_DEM.SetToolTip(_("To display the existing DEM input for the interpolation of the simulated free surfaces."))
515
+ self._but_DEM.Bind(wx.EVT_BUTTON, self.OnDEM)
516
+
517
+ self._but_MNTmodifs = wx.Button(panel, label=_("Check 'MNTmodifs_' scenarios"))
518
+ self._but_MNTmodifs.SetToolTip(_("To display the existing MNTmodifs_ scenario files for the DTM input of interpolation of the simulated free surfaces."))
519
+ self._but_MNTmodifs.Bind(wx.EVT_BUTTON, self.OnCheckMNTmodifs)
520
+
521
+ sizer_hor2.Add(sizer_ver_small2, 0, wx.ALL | wx.EXPAND, 5)
522
+
523
+ self._but_extrinterp = wx.Button(panel, label=_('Read and interpolate'))
524
+ self._but_extrinterp.SetToolTip(_("Reads and interpolates the danger maps computed (if not done, use previous buttons) of wolf gpu simulations."))
525
+ self._but_extrinterp.Bind(wx.EVT_BUTTON, self.OnInterpolation)
526
+ sizer_hor2.Add(self._but_extrinterp, 1, wx.ALL | wx.EXPAND, 0)
603
527
 
604
528
  sizer_hor1.Add(self._but_maindir, 2, wx.ALL | wx.EXPAND, 0)
605
529
  sizer_hor1.Add(self._listbox_studyarea, 1, wx.ALL | wx.EXPAND, 0)
@@ -608,19 +532,23 @@ class AcceptabilityGui(wx.Frame):
608
532
 
609
533
  #3rd line
610
534
  sizer_hor_threads = wx.BoxSizer(wx.HORIZONTAL)
611
- text_dx = wx.StaticText(panel, label='Resolution (dx,dy) [m]:')
535
+ text_dx = wx.StaticText(panel, label=_('Resolution (dx,dy) [m]:'))
612
536
  self.input_dx = wx.StaticText(panel)
613
537
  self.input_dx.SetMinSize((80, -1))
614
- text_nbxy = wx.StaticText(panel, label='(nbx, nby):')
538
+ text_nbxy = wx.StaticText(panel, label=_('(nbx, nby):'))
615
539
  self.input_nbxy = wx.StaticText(panel)
616
540
  self.input_nbxy.SetMinSize((90, -1))
617
- text_O = wx.StaticText(panel, label='Origin (X,Y):')
541
+ text_O = wx.StaticText(panel, label=_('Origin (X,Y):'))
618
542
  self.input_O = wx.StaticText(panel)
619
543
  self.input_O.SetMinSize((170, -1))
620
- text_threads = wx.StaticText(panel, label='Number of threads:')
544
+ text_threads = wx.StaticText(panel, label=_('Number of threads:'))
621
545
  self._nb_process = wx.SpinCtrl(panel, value=str(os.cpu_count()), min=1, max=os.cpu_count())
622
546
  self._nb_process.SetToolTip("Number of threads to be used in the computations.")
623
-
547
+ self._but_toggle_admin = wx.ToggleButton(panel, label=_('Admin mode'))
548
+ self._but_toggle_admin.SetToolTip("To activate admin mode. enter password.")
549
+ self.toggle_state_Admin = False
550
+ self._but_toggle_admin.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggleAdmin)
551
+
624
552
  sizer_hor_threads.Add(text_dx, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
625
553
  sizer_hor_threads.Add(self.input_dx, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
626
554
  sizer_hor_threads.Add(text_nbxy, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
@@ -629,37 +557,44 @@ class AcceptabilityGui(wx.Frame):
629
557
  sizer_hor_threads.Add(self.input_O, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
630
558
  sizer_hor_threads.Add(text_threads, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
631
559
  sizer_hor_threads.Add(self._nb_process, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
560
+ sizer_hor_threads.Add(self._but_toggle_admin, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
632
561
 
633
- # 3 last lines + scenarios
562
+ # 4,5,6th lines + scenarios
634
563
  #--------------------------
635
- self._but_creation = wx.Button(panel, label='DataBase Creation')
564
+ self._but_creation = wx.Button(panel, label=_('DataBase Creation'))
636
565
  self.layout(self._but_creation)
637
566
  self._but_creation.Bind(wx.EVT_BUTTON, self.OnCreation)
638
567
 
639
568
  self._steps_db = wx.CheckListBox(panel, choices=steps_base_data_creation.get_list_names(), style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
569
+ self._steps_db.Hide()
570
+ self._steps_db.SetForegroundColour(wx.Colour(170, 170, 170))
571
+ self._steps_db.SetBackgroundColour(wx.Colour(170, 170, 170))
640
572
 
641
- self._but_vulnerability = wx.Button(panel, label='Vulnerability')
573
+ self._but_vulnerability = wx.Button(panel, label=_('Vulnerability'))
642
574
  self.layout(self._but_vulnerability)
643
575
  self._but_vulnerability.Bind(wx.EVT_BUTTON, self.OnVulnerability)
644
576
  step_Vuln_without_withoutscenarios = [item for item in steps_vulnerability.get_list_names() if item != 'APPLY_SCENARIOSVULN - 4']
645
577
  self._steps_vulnerability = wx.CheckListBox(panel, choices=step_Vuln_without_withoutscenarios, style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
646
-
578
+ self._steps_vulnerability.Hide()
579
+ self._steps_vulnerability.SetForegroundColour(wx.Colour(170, 170, 170))
580
+ self._steps_vulnerability.SetBackgroundColour(wx.Colour(170, 170, 170))
581
+
647
582
  # Scenarios specifics --
648
- self._but_checkscenario = wx.Button(panel, label='Check existing scenarios')
649
- self._but_checkscenario.SetToolTip("To display the scenario to be taken into account in CHANGE_VULNE.")
583
+ self._but_checkscenario = wx.Button(panel, label=_("Check 'vuln_' scenarios"))
584
+ self._but_checkscenario.SetToolTip(_("To display the scenario to be taken into account in CHANGE_VULNE."))
650
585
  self._but_checkscenario.Bind(wx.EVT_BUTTON, self.OnCheckScenario)
651
586
 
652
- self._but_upriverbed = wx.Button(panel, label="Update riverbed")
653
- self._but_upriverbed.SetToolTip("To create the raster of the riverbed trace.")
587
+ self._but_upriverbed = wx.Button(panel, label=_("Update riverbed"))
588
+ self._but_upriverbed.SetToolTip(_("To create the raster of the riverbed trace."))
654
589
  self._but_upriverbed.Bind(wx.EVT_BUTTON, self.on_button_click)
655
590
 
656
591
  self.menu = wx.Menu()
657
- self.menu.Append(1, "File of riverbed trace exists.")
658
- self.menu.Append(2, "Point to a low discharge simulation and calculate the riverbed trace.")
592
+ self.menu.Append(1, _("File of riverbed trace exists."))
593
+ self.menu.Append(2, _("Point to a low discharge simulation and calculate the riverbed trace."))
659
594
  self.menu.Bind(wx.EVT_MENU, self.onRiverbed)
660
595
 
661
- self._but_toggle_scen = wx.ToggleButton(panel, label="Accounting for scenarios")
662
- self._but_toggle_scen.SetToolTip("To be activated to surimpose the vuln_ files, \n and so to take into account scenarios")
596
+ self._but_toggle_scen = wx.ToggleButton(panel, label=_("Accounting for scenarios"))
597
+ self._but_toggle_scen.SetToolTip(_("To be activated to surimpose the vuln_ files, \n and so to take into account scenarios"))
663
598
  self.toggle_state = False
664
599
  self._but_toggle_scen.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle)
665
600
 
@@ -667,8 +602,8 @@ class AcceptabilityGui(wx.Frame):
667
602
  sizer_hor_scen.Add(self._but_upriverbed, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
668
603
  sizer_hor_scen.Add(self._but_toggle_scen, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
669
604
 
670
- self._but_toggle_resamp = wx.ToggleButton(panel, label="Resampling [m]:")
671
- self._but_toggle_resamp.SetToolTip("To compute the final raster with a coarser resolution than the original one.")
605
+ self._but_toggle_resamp = wx.ToggleButton(panel, label=_("Resampling [m]:"))
606
+ self._but_toggle_resamp.SetToolTip(_("To compute the final raster with a coarser resolution than the original one."))
672
607
  self.toggle_resamp_state = False
673
608
  self._but_toggle_resamp.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggleResampling)
674
609
  sizer_hor_scen.Add(self._but_toggle_resamp, flag=wx.ALIGN_CENTER | wx.TOP)
@@ -677,22 +612,25 @@ class AcceptabilityGui(wx.Frame):
677
612
 
678
613
  #--
679
614
 
680
- self._but_acceptability = wx.Button(panel, label='Acceptability')
615
+ self._but_acceptability = wx.Button(panel, label=_('Acceptability'))
681
616
  self.layout(self._but_acceptability)
682
617
  self._but_acceptability.Bind(wx.EVT_BUTTON, self.OnAcceptability)
683
618
 
684
619
  step_without_withoutscenarios = [item for item in steps_acceptability.get_list_names() if item != 'COMPUTE_WITH_SCENARIOS - 5']
685
620
  step_without_withoutscenarios = [item for item in step_without_withoutscenarios if item != 'RESAMPLING - 6']
686
621
  self._steps_acceptability = wx.CheckListBox(panel, choices=step_without_withoutscenarios, style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
622
+ self._steps_acceptability.Hide()
623
+ self._steps_acceptability.SetForegroundColour(wx.Colour(170, 170, 170))
624
+ self._steps_acceptability.SetBackgroundColour(wx.Colour(170, 170, 170))
687
625
 
688
- sizer_hor2.Add(self._but_creation, 1, wx.ALL | wx.EXPAND, 0)
689
- sizer_hor2.Add(self._steps_db, 1, wx.ALL | wx.EXPAND, 0)
626
+ sizer_hor3.Add(self._but_creation, 1, wx.ALL | wx.EXPAND, 0)
627
+ sizer_hor3.Add(self._steps_db, 1, wx.ALL | wx.EXPAND, 0)
690
628
 
691
- sizer_hor3.Add(self._but_vulnerability, 1, wx.ALL | wx.EXPAND, 0)
692
- sizer_hor3.Add(self._steps_vulnerability, 1, wx.ALL | wx.EXPAND, 0)
629
+ sizer_hor4.Add(self._but_vulnerability, 1, wx.ALL | wx.EXPAND, 0)
630
+ sizer_hor4.Add(self._steps_vulnerability, 1, wx.ALL | wx.EXPAND, 0)
693
631
 
694
- sizer_hor4.Add(self._but_acceptability, 1, wx.ALL | wx.EXPAND, 0)
695
- sizer_hor4.Add(self._steps_acceptability, 1, wx.ALL | wx.EXPAND, 0)
632
+ sizer_hor5.Add(self._but_acceptability, 1, wx.ALL | wx.EXPAND, 0)
633
+ sizer_hor5.Add(self._steps_acceptability, 1, wx.ALL | wx.EXPAND, 0)
696
634
 
697
635
  #Lines order
698
636
  sizer_ver_small.Add(self._but_checkfiles, 0, wx.ALL | wx.EXPAND, 1)
@@ -700,12 +638,16 @@ class AcceptabilityGui(wx.Frame):
700
638
  sizer_ver_small.Add(self._but_checkpond, 0, wx.ALL | wx.EXPAND, 1)
701
639
 
702
640
  sizer_vert1.Add(sizer_hor1, 1, wx.EXPAND, 0)
703
- sizer_vert1.Add(sizer_hor1_1, 1, wx.EXPAND, 0)
704
- sizer_vert1.Add(sizer_hor_threads, 0, wx.EXPAND, 0)
705
641
  sizer_vert1.Add(sizer_hor2, 1, wx.EXPAND, 0)
706
- sizer_vert1.Add(sizer_hor_scen, 1, wx.EXPAND, 0)
642
+ sizer_vert1.Add(sizer_hor_threads, 0, wx.EXPAND, 0)
707
643
  sizer_vert1.Add(sizer_hor3, 1, wx.EXPAND, 0)
644
+ sizer_vert1.Add(sizer_hor_scen, 1, wx.EXPAND, 0)
645
+
708
646
  sizer_vert1.Add(sizer_hor4, 1, wx.EXPAND, 0)
647
+ sizer_vert1.Add(sizer_hor5, 1, wx.EXPAND, 0)
648
+
649
+ sizer_ver_small2.Add(self._but_MNTmodifs, 0, wx.ALL | wx.EXPAND, 1)
650
+ sizer_ver_small2.Add(self._but_DEM, 0, wx.ALL | wx.EXPAND, 1)
709
651
 
710
652
  sizer_hor_main.Add(sizer_vert1, proportion=1, flag=wx.EXPAND, border=0)
711
653
 
@@ -715,6 +657,7 @@ class AcceptabilityGui(wx.Frame):
715
657
  self._but_creation.Enable(False)
716
658
  self._but_checkfiles.Enable(False)
717
659
  self._but_DEM.Enable(False)
660
+ self._but_MNTmodifs.Enable(False)
718
661
  self._but_extrinterp.Enable(False)
719
662
  self._but_toggle_scen.Enable(False)
720
663
  self._but_toggle_resamp.Enable(False)
@@ -724,11 +667,11 @@ class AcceptabilityGui(wx.Frame):
724
667
  self._but_checksim.Enable(False)
725
668
  self._but_creation.Enable(False)
726
669
  self._but_loadgpu.Enable(False)
670
+ self._but_danger.Enable(False)
727
671
 
728
672
  panel.SetSizer(sizer_hor_main)
729
673
  panel.Layout()
730
674
 
731
-
732
675
  def OnSims(self, e:wx.ListEvent):
733
676
  """ Load sim into the mapviewer """
734
677
  pass
@@ -750,19 +693,19 @@ class AcceptabilityGui(wx.Frame):
750
693
  """ Check the files """
751
694
 
752
695
  if self._manager is None:
753
- logging.error("No main directory selected -- Nothing to check")
696
+ logging.error(_("No main directory selected -- Nothing to check"))
754
697
  return
755
698
 
756
699
  i=self._manager.check_inputs()
757
700
 
758
701
  if i == False :
759
- logging.error(f"Missing files in INPUT. Please provide them by following the right structure.")
702
+ logging.error(_(f"Missing files in INPUT. Please provide them by following the right structure."))
760
703
  with wx.MessageDialog(self, f"Missing files in INPUT. Inputs can not be created automatically : you must provide them.\n Please read the logs and terminal to see the missing ones.", "Error", wx.OK | wx.ICON_ERROR) as dlg:
761
704
  dlg.ShowModal()
762
705
  return
763
706
  else :
764
707
  if (self._manager._study_area is None) or (self._manager._scenario is None):
765
- logging.error(f"No study area and/or scenario selected, no check of TEMP and OUTPUT.")
708
+ logging.error(_(f"No study area and/or scenario selected, no check of TEMP and OUTPUT."))
766
709
  with wx.MessageDialog(self, f"INPUT is well structured, but TEMP and OUTPUT have not been checked because there is no study area and scenario selected.", "Checking", wx.OK | wx.ICON_INFORMATION) as dlg:
767
710
  dlg.ShowModal()
768
711
  else:
@@ -780,7 +723,7 @@ class AcceptabilityGui(wx.Frame):
780
723
  """
781
724
 
782
725
  if self._manager is None:
783
- logging.error("No main directory selected -- Nothing to check")
726
+ logging.error(_("No main directory selected -- Nothing to check"))
784
727
  return
785
728
 
786
729
  if self._manager.IN_SA_INTERP is None:
@@ -809,7 +752,7 @@ class AcceptabilityGui(wx.Frame):
809
752
 
810
753
  elif response == wx.ID_NO:
811
754
  logging.info(_("Decision of loading simulations."))
812
- with wx.MessageDialog(self, f"Please use the 'Load gpu simulations folder' button of the manager and follow the instructions.", "Redirecting",
755
+ with wx.MessageDialog(self, f"Please use the 'Working with new hydraulic scenarios' button of the manager and follow the instructions.", "Redirecting",
813
756
  wx.OK | wx.ICON_INFORMATION) as dlg:
814
757
  dlg.ShowModal()
815
758
  else:
@@ -833,7 +776,7 @@ class AcceptabilityGui(wx.Frame):
833
776
  def OnCheckPond(self,e):
834
777
 
835
778
  if self._manager is None:
836
- logging.error("No main directory selected -- Nothing to check")
779
+ logging.error(_("No main directory selected -- Nothing to check"))
837
780
  return
838
781
  if self._manager.IN_SA_INTERP is None:
839
782
  logging.error(_("No IN_SA_INTERP attribute found in the manager."))
@@ -907,13 +850,17 @@ class AcceptabilityGui(wx.Frame):
907
850
  self._but_vulnerability.Enable(True)
908
851
  self._but_creation.Enable(True)
909
852
  self._but_checkfiles.Enable(True)
910
- self._but_toggle_scen.Enable(True)
911
853
  self._but_toggle_resamp.Enable(True)
912
854
  self._but_upriverbed.Enable(True)
913
855
  self._but_checkscenario.Enable(True)
914
856
  self._but_checkpond.Enable(True)
915
857
  self._but_checksim.Enable(True)
916
858
  self._but_loadgpu.Enable(True)
859
+
860
+ #Must be False if come back :
861
+ self._but_DEM.Enable(False)
862
+ self._but_MNTmodifs.Enable(False)
863
+ self._but_extrinterp.Enable(False)
917
864
 
918
865
  self._listbox_scenario.Clear()
919
866
  studyareas = self._manager.get_list_studyareas()
@@ -939,7 +886,7 @@ class AcceptabilityGui(wx.Frame):
939
886
  if len(sc)!=0:
940
887
  self._listbox_scenario.InsertItems(sc, 0)
941
888
  else :
942
- logging.error("No scenario available associated with this study area.")
889
+ logging.error(_("No scenario available associated with this study area."))
943
890
 
944
891
  if self.mapviewer is not None:
945
892
  tmp_path = self._manager.IN_STUDY_AREA / study_area
@@ -948,13 +895,18 @@ class AcceptabilityGui(wx.Frame):
948
895
  if not tmp_path.stem in self.mapviewer.get_list_keys(drawing_type=draw_type.VECTORS):
949
896
  self.mapviewer.add_object('vector', filename=str(tmp_path), id=tmp_path.stem)
950
897
  self.mapviewer.Refresh()
898
+ self._but_DEM.Enable(False)
899
+ self._but_MNTmodifs.Enable(False)
900
+ self._but_extrinterp.Enable(False)
951
901
 
952
902
  def OnScenario(self, e):
953
903
  """ Change the scenario """
954
904
  if self._manager is None:
955
905
  return
956
906
  scenario = self._manager.get_list_scenarios()[e.GetSelection()]
957
-
907
+ self._but_DEM.Enable(True)
908
+ self._but_MNTmodifs.Enable(True)
909
+ self._but_extrinterp.Enable(True)
958
910
  self._manager.change_scenario(scenario)
959
911
  create_INPUT_TEMP_OUTPUT_forScenario(self.maindir, self._manager.Study_area, self._manager.scenario, None)
960
912
  update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
@@ -962,7 +914,7 @@ class AcceptabilityGui(wx.Frame):
962
914
  def OnCreation(self, e):
963
915
  """ Create the database """
964
916
  if self._manager is None:
965
- logging.error("No main directory selected -- Nothing to create")
917
+ logging.error(_("No main directory selected -- Nothing to create"))
966
918
  return
967
919
  if self._manager.IN_SA_INTERP is None:
968
920
  logging.error(_("No IN_SA_INTERP attribute found in the manager."))
@@ -970,7 +922,7 @@ class AcceptabilityGui(wx.Frame):
970
922
  dlg.ShowModal()
971
923
  return
972
924
 
973
- dx,_,_,_,_,_ = update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
925
+ dx,unused,unused,unused,unused,unused = update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
974
926
  resolution = dx
975
927
  if resolution == '':
976
928
  wx.MessageBox(
@@ -1002,7 +954,7 @@ class AcceptabilityGui(wx.Frame):
1002
954
  )
1003
955
  else :
1004
956
  wx.MessageBox(
1005
- f"No steps selected. The code for the DataBase creation will consider all steps by default, , with a resolution of {dx}. This process may take some time, and the window may temporarily stop responding.",
957
+ f"Resolution of {dx}. This process may take some time, and the window may temporarily stop responding.",
1006
958
  "Information",
1007
959
  wx.OK | wx.ICON_INFORMATION
1008
960
  )
@@ -1022,8 +974,9 @@ class AcceptabilityGui(wx.Frame):
1022
974
  -Create scenario and study area if needed.
1023
975
  """
1024
976
 
1025
- dlg = wx.DirDialog(None, "Please select the main scenario manager folder (containing the scenarios, the folder discharge, the scripts.py...), named after the STUDY AREA.", style=wx.DD_DEFAULT_STYLE)
977
+ dlg = wx.DirDialog(None, "Please select the main scenario manager folder (containing the scenarios, the folder discharge, the scripts.py...), named after the STUDY AREA.\n If you cancel, this button wont be activated or will be desactivated.", style=wx.DD_DEFAULT_STYLE)
1026
978
  if dlg.ShowModal() == wx.ID_OK:
979
+ self._but_loadgpu.SetValue(True)
1027
980
  main_gpu = Path(dlg.GetPath())
1028
981
  study_area = main_gpu.name
1029
982
  logging.info(_(f"Selected folder for GPU result such as the STUDY AREA is {study_area}"))
@@ -1037,8 +990,6 @@ class AcceptabilityGui(wx.Frame):
1037
990
  self._manager.change_studyarea(study_area+'.shp')
1038
991
  self._manager.change_scenario(scenario)
1039
992
 
1040
-
1041
-
1042
993
  self._listbox_studyarea.Clear()
1043
994
  self._listbox_studyarea.InsertItems(self._manager.get_list_studyareas(), 0)
1044
995
  self._listbox_scenario.Clear()
@@ -1058,10 +1009,12 @@ class AcceptabilityGui(wx.Frame):
1058
1009
  self._listbox_scenario.Refresh()
1059
1010
 
1060
1011
  else:
1061
- logging.error('No hydraulic scenario selected.')
1012
+ logging.error('No hydraulic scenario selected, toggle button desactivated.')
1013
+ self._but_loadgpu.SetValue(False)
1062
1014
  return
1063
1015
  else:
1064
1016
  logging.error('No folder found / selected. Please try again.')
1017
+ self._but_loadgpu.SetValue(False)
1065
1018
  return
1066
1019
 
1067
1020
  self._check_listbox.Clear()
@@ -1086,22 +1039,17 @@ class AcceptabilityGui(wx.Frame):
1086
1039
  self.gpu_bathy = hydraulic_scen.parent / BATHYMETRY_FOR_SIMULATION # this is the last bathymetry after the scripts have been run
1087
1040
  self._but_extrinterp.Enable(True)
1088
1041
  self._but_DEM.Enable(True)
1042
+ self._but_danger.Enable(True)
1043
+ self._but_MNTmodifs.Enable(True)
1089
1044
  with wx.MessageDialog(self,
1090
1045
  message,
1091
1046
  "Information",
1092
1047
  style=wx.OK | wx.ICON_INFORMATION) as dlg:
1093
1048
  dlg.ShowModal()
1094
-
1049
+
1095
1050
  def OnDEM(self,e):
1096
1051
  """Import and create the inputs for the interpolation routine (name including 'MNT_...' and 'MNT_..._with_mask'.
1097
1052
  See function MTN_And_mask_creation_all"""
1098
- if not hasattr(self, 'file_paths'):
1099
- with wx.MessageDialog(self,
1100
- f"Please, first load gpu simulations via the previous button.",
1101
- "Attention",
1102
- style=wx.OK | wx.ICON_ERROR) as dlg:
1103
- dlg.ShowModal()
1104
- return
1105
1053
  path = self._manager.IN_SA_DEM
1106
1054
  names_inDEM = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
1107
1055
  if len(names_inDEM) != 0 :
@@ -1117,7 +1065,15 @@ class AcceptabilityGui(wx.Frame):
1117
1065
  logging.info(_("No update of DEM_FILES."))
1118
1066
  return
1119
1067
 
1120
- with wx.FileDialog(self, "Please select the DEM file in .tif format (without modifications).", wildcard="TIFF files (*.tif)|*.tif",
1068
+ #Avec ajout BATHT_AFTER_SCRIPT
1069
+ if self.gpu_bathy == None:
1070
+ with wx.FileDialog(self, "Please select the bathymetry file of simulation, with all the modifications (e.g. '__bathymetry_after_scripts.tif') in .tif format.", wildcard="TIFF files (*.tif)|*.tif",
1071
+ style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as dlg:
1072
+ if dlg.ShowModal() != wx.ID_OK:
1073
+ return
1074
+ self.gpu_bathy = dlg.GetPath()
1075
+
1076
+ with wx.FileDialog(self, "Please select the DEM file in .tif format (without modifications, MNTmodifs_ will be used afterwards).", wildcard="TIFF files (*.tif)|*.tif",
1121
1077
  style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as dlg:
1122
1078
  result = dlg.ShowModal()
1123
1079
  if result != wx.ID_OK:
@@ -1130,6 +1086,7 @@ class AcceptabilityGui(wx.Frame):
1130
1086
  path = self._manager.IN_CH_SA_SC
1131
1087
  names_inCHVUL_MNTmodifs = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) and f.startswith("MNTmodifs_")]
1132
1088
  #path_MNT_computed is the path to the DEM with the MNTmodifs if exist, or the given true DEM if not
1089
+
1133
1090
  path_MNT_computed = Path(path_DEM_base)
1134
1091
  if len(names_inCHVUL_MNTmodifs) !=0:
1135
1092
  path_MNT_computed = Path(self._manager.IN_CH_SA_SC_MNT_tif.with_suffix('.tif'))
@@ -1141,26 +1098,27 @@ class AcceptabilityGui(wx.Frame):
1141
1098
  logging.info(_("No modifications done in MNTmodifs_ files, process stopped."))
1142
1099
  return
1143
1100
 
1144
- #else :
1145
1101
  if os.path.exists(self._manager.IN_CH_SA_SC):
1146
1102
  existence=False
1147
- existence = self._manager.create_vrtIfExists(Path(path_DEM_base), self._manager.IN_CH_SA_SC, self._manager.IN_CH_SA_SC_MNT_VRT, name="MNTmodifs_")
1148
- if existence :
1103
+ existence, fail = self._manager.create_vrtIfExists(Path(path_DEM_base), self._manager.IN_CH_SA_SC, self._manager.IN_CH_SA_SC_MNT_VRT, name="MNTmodifs_")
1104
+ if existence:
1149
1105
  self._manager.translate_vrt2tif(self._manager.IN_CH_SA_SC_MNT_VRT, self._manager.IN_CH_SA_SC_MNT_tif)
1150
1106
  logging.info(_(f"Scenarios have been applied to DEM see {self._manager.IN_CH_SA_SC_MNT_tif}.tif."))
1151
1107
  WA_mask = WolfArray(self._manager.IN_CH_SA_SC_MNT_tif.with_suffix('.tif'))
1152
- WA_mask.write_all(Path(self._manager.IN_SA_DEM / "MNT_loaded.bin"))
1108
+ WA_mask.write_all(Path(self._manager.IN_SA_DEM / "MNT_loaded.bin"))
1109
+
1153
1110
  else :
1154
1111
  logging.info(_(f"No MNTmodifs_ files in {self._manager.IN_CH_SA_SC}. The given file {path_DEM_base} has not been modified"))
1155
1112
  WA_mask = WolfArray(path_DEM_base)
1156
1113
  WA_mask.write_all(Path(self._manager.IN_SA_DEM / "MNT_loaded.bin"))
1157
1114
  else:
1158
- logging.error(f"Path {self._manager.IN_CH_SA_SC} does not exist.")
1115
+ logging.error(_(f"Path {self._manager.IN_CH_SA_SC} does not exist."))
1159
1116
 
1160
1117
  #self._manager.IN_CH_SA_SC_MNT_tif ou fn_mnt_cropped : ground + riverbed
1161
1118
  fn_wherebuildings_buffer = self._manager.IN_CH_SA_SC / "buffer_wherebuilding.tif"
1162
1119
  fn_mask = self._manager.IN_SA_DEM / "MNT_computed_with_mask.tif"
1163
- MNT_and_mask_creation_all(self.gpu_bathy, path_MNT_computed, fn_wherebuildings_buffer, fn_mask)
1120
+ _interpol = interpolating_raster()
1121
+ _interpol.MNT_and_mask_creation_all(self.gpu_bathy, path_MNT_computed, fn_wherebuildings_buffer, fn_mask)
1164
1122
  if fn_wherebuildings_buffer.exists():
1165
1123
  fn_wherebuildings_buffer.unlink()
1166
1124
  if fn_mask.exists():
@@ -1172,19 +1130,52 @@ class AcceptabilityGui(wx.Frame):
1172
1130
  dlg.ShowModal()
1173
1131
  dlg.Destroy()
1174
1132
  return
1175
-
1176
- def OnInterpolation(self,e):
1177
- """Interpolates the last extracted time steps present in LAST_STEP_EXTRACTED using the fast marching
1178
- interpolation routine, by creating a batch file
1179
- while performing multiple checks on the required input files."""
1133
+
1134
+ def OnDanger(self,e):
1135
+ """ Specific button to extract last step or to compute the wd danger map"""
1180
1136
  menu_id = e.GetId()
1137
+ param_danger = [0, -1, 1]
1181
1138
  if menu_id == 1:
1182
1139
  type_extraction = "last_step"
1183
1140
  logging.info(_("Option 1 : last step extraction and interpolation."))
1184
1141
  elif menu_id == 2:
1185
1142
  type_extraction = "danger_map"
1186
1143
  logging.info(_("Option 2 : danger map computation and interpolation."))
1187
-
1144
+ dlg = wx.TextEntryDialog(None,
1145
+ "Enter parameters as (e.g 0, -1, 1): from which step, until which step (-1 if latest step), by number of step",
1146
+ "Parameters", "0, -1, 1")
1147
+ if dlg.ShowModal() == wx.ID_OK:
1148
+ try:
1149
+ param_danger = [int(x.strip()) for x in dlg.GetValue().split(",")]
1150
+ except:
1151
+ wx.MessageBox("Invalid input. Use format: 0, -1, 1", "Error")
1152
+ dlg.Destroy()
1153
+
1154
+ else :
1155
+ return
1156
+
1157
+
1158
+ with wx.TextEntryDialog(
1159
+ self,
1160
+ "What threshold (in meters) do you want to apply to filter the water depth danger map?",
1161
+ "Water Depth Threshold",
1162
+ "0.01"
1163
+ ) as dlg:
1164
+ threshold = None
1165
+ if dlg.ShowModal() == wx.ID_OK:
1166
+ val = dlg.GetValue().strip().replace(',', '.')
1167
+ try:
1168
+ threshold = float(val)
1169
+ if threshold <= 0:
1170
+ wx.MessageBox("Please enter a strictly positive number.", "Invalid Value", wx.ICON_ERROR)
1171
+ threshold = None
1172
+ return
1173
+ except Exception:
1174
+ wx.MessageBox("Invalid input — please enter a number (e.g., 0.01).", "Error", wx.ICON_ERROR)
1175
+ threshold = None
1176
+ return
1177
+ else :
1178
+ return
1188
1179
  if not hasattr(self, 'file_paths'):
1189
1180
  with wx.MessageDialog(self,
1190
1181
  f"Please, first load gpu simulations via the previous button.",
@@ -1192,15 +1183,18 @@ class AcceptabilityGui(wx.Frame):
1192
1183
  style=wx.OK | wx.ICON_ERROR) as dlg:
1193
1184
  dlg.ShowModal()
1194
1185
  return
1195
-
1186
+ logging.info(_(f"Threshold for water depth selected : {threshold} [m]"))
1196
1187
  checked_indices = self._check_listbox.GetCheckedItems()
1197
1188
  checked_items = [self._check_listbox.GetString(index) for index in checked_indices]
1198
1189
  selected_paths = [self.file_paths[item] for item in checked_items]
1190
+ if not selected_paths:
1191
+ wx.MessageBox("No selection detected. Using all items in the list.", "Info", wx.ICON_INFORMATION)
1192
+ selected_items = list(self._check_listbox.GetStrings())
1193
+ selected_paths = [self.file_paths[item] for item in selected_items]
1199
1194
  path_simulations = self.datadir_simulations
1200
1195
 
1201
- path_LastSteps = Path(self._manager.IN_SA_EXTRACTED)
1202
- fn_write = None
1203
- dx,dy,nbx,nby,X,Y = False, False, False, False, False, False
1196
+ #dx,dy,nbx,nby,X,Y = False, False, False, False, False, False
1197
+ _interpol = interpolating_raster()
1204
1198
  for sim_ in selected_paths:
1205
1199
  if sim_.name.startswith("sim_"):
1206
1200
  self.sims[sim_.name] = sim_
@@ -1209,29 +1203,44 @@ class AcceptabilityGui(wx.Frame):
1209
1203
  parts = sim_.name.split("sim_")
1210
1204
  if len(parts) > 1:
1211
1205
  name = parts[1]
1212
- fn_write = Path(path_LastSteps / name )
1213
1206
  # dx,dy,nbx,nby,X,Y = display_info_header(self.input_dx, self.input_nbxy, self.input_O, fn_write.with_suffix(".bin"))
1214
- read_export_z_bin(fn_read, fn_write, path_LastSteps, type_extraction = type_extraction)
1207
+ _interpol.export_z_or_v_bin(fn_read, self._manager, name, type_hazard="z", type_extraction = type_extraction, param_danger = param_danger, threshold=threshold)
1208
+
1215
1209
  else:
1216
1210
  logging.info(_(f"Please, ensure your simulations are named with the return period, e.g sim_T4"))
1217
1211
  else:
1218
1212
  logging.info(_('No folder found / selected. Please try again...'))
1219
- else:
1220
- logging.error('No simulation selected! Please select some in the checkbox.')
1221
-
1222
- checked_names = self._check_listbox.GetCheckedStrings()
1223
- if not checked_names:
1224
- logging.info(_("No items selected. Adding all paths."))
1225
- checked_paths = list(self.file_paths.values())
1226
- else:
1227
- logging.info(_("Adding only the selected simulations."))
1228
- checked_paths = [self.file_paths[name] for name in checked_names]
1229
-
1230
- if len(self.file_paths) == 0 :
1231
- return logging.info(_("No files in EXTRACTED_LAST_STEP_WD. Please provide some or use the 'Load gpu simulation' button."))
1232
-
1233
- # interp_bool, renamed_files = self._manager.batch_creation_and_interpolation_fotran_holes(checked_paths, False)
1234
- interp_bool, renamed_files = self._manager.batch_creation_and_interpolation_python_eikonal(checked_paths, False)
1213
+
1214
+ with wx.MessageDialog(self,
1215
+ f"End of the process.",
1216
+ "Information",
1217
+ style=wx.OK | wx.ICON_INFORMATION) as dlg:
1218
+ dlg.ShowModal()
1219
+
1220
+ def OnInterpolation(self,e):
1221
+ """Interpolates the last extracted time steps present in LAST_STEP_EXTRACTED using the fast marching
1222
+ interpolation routine, by creating a batch file
1223
+ while performing multiple checks on the required input files."""
1224
+ if self._but_loadgpu.GetValue(): #if simulations have been loaded :
1225
+ checked_names = self._check_listbox.GetCheckedStrings()
1226
+ iftest = False
1227
+ if not checked_names:
1228
+ logging.info(_("No items selected. Adding all paths."))
1229
+ checked_paths = list(self.file_paths.values())
1230
+ else:
1231
+ logging.info(_("Adding only the selected simulations."))
1232
+ checked_paths = [self.file_paths[name] for name in checked_names]
1233
+
1234
+ if len(self.file_paths) == 0 :
1235
+ return logging.info(_("No files in EXTRACTED_LAST_STEP_WD. Please provide some or use the 'Load gpu simulation' button."))
1236
+
1237
+ else : #if interpoalting based on existing files :
1238
+ checked_paths = None
1239
+ iftest = True
1240
+
1241
+ _interpol = interpolating_raster()
1242
+ #interp_bool, renamed_files = _interpol.batch_creation_and_interpolation_fotran_holes(self._manager, checked_paths, False)
1243
+ interp_bool, renamed_files = _interpol.batch_creation_and_interpolation_python_eikonal(self._manager, checked_paths, iftest, True)
1235
1244
 
1236
1245
  if interp_bool:
1237
1246
  logging.info(_("Filling completed."))
@@ -1240,8 +1249,35 @@ class AcceptabilityGui(wx.Frame):
1240
1249
  dlg.ShowModal()
1241
1250
  update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
1242
1251
  else :
1243
- logging.error("Something went wrong for the interpolation.")
1252
+ logging.error(_("Something went wrong for the interpolation."))
1253
+
1254
+ def OnToggleAdmin(self, e):
1255
+ if self.toggle_state_Admin:
1256
+ self.toggle_state_Admin = False
1257
+ self._but_toggle_admin.SetBackgroundColour(wx.NullColour)
1258
+ self._steps_db.Hide()
1259
+ self._steps_vulnerability.Hide()
1260
+ self._steps_acceptability.Hide()
1261
+ return
1244
1262
 
1263
+ dlg = wx.TextEntryDialog(self, "Enter developer password:", "Authentication")
1264
+ if dlg.ShowModal() == wx.ID_OK:
1265
+ password = dlg.GetValue()
1266
+ if password == "LetMeIn#":
1267
+ self.toggle_state_Admin = True
1268
+ self._but_toggle_admin.SetBackgroundColour(wx.Colour(175, 175, 175))
1269
+
1270
+ self._steps_db.Show()
1271
+ self._steps_vulnerability.Show()
1272
+ self._steps_acceptability.Show()
1273
+
1274
+ else:
1275
+ wx.MessageBox("Wrong password.", "Error")
1276
+ self.toggle_state_Admin = False
1277
+ self._but_toggle_admin.SetBackgroundColour(wx.NullColour)
1278
+ dlg.Destroy()
1279
+ self.mapviewer.Refresh()
1280
+
1245
1281
  def OnToggle(self,e):
1246
1282
  """Creates a toggle button to be activated if the scenarios vuln_ have to be taken into account."""
1247
1283
  self.toggle_state = False
@@ -1299,28 +1335,128 @@ class AcceptabilityGui(wx.Frame):
1299
1335
  self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
1300
1336
  logging.info(_("No simulations in INTERP_WD."))
1301
1337
 
1302
-
1303
1338
  else:
1304
1339
  self.toggle_resamp_state = False
1305
1340
  self._but_toggle_resamp.SetValue(False)
1306
1341
  self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
1307
1342
  logging.info(_("Resampling disactivated"))
1343
+
1344
+ def check_and_convert_rasters(self, manager, prefix, type_file, numpy_type, nodata_value, message_supp=None):
1345
+ logging.info(_(f"Checking the scenarios for {prefix}."))
1346
+
1347
+ #tif_paths = self._manager.get_modifiedrasters(name=prefix)
1348
+ tif_paths = manager.get_modifiedrasters(name=prefix)
1349
+ good, bad, bad_paths = [], [], []
1350
+
1351
+ for f in tif_paths:
1352
+ ds = gdal.Open(f)
1353
+ if ds:
1354
+ file_type = gdal.GetDataTypeName(ds.GetRasterBand(1).DataType)
1355
+ ds = None
1356
+ if file_type == type_file:
1357
+ good.append(f.stem)
1358
+ else:
1359
+ suffix_to_add = f"_{file_type}"
1360
+ new_name = f.parent / f"{f.stem}{suffix_to_add}{f.suffix}"
1361
+ if not f.stem.endswith(suffix_to_add):
1362
+ f.rename(new_name)
1363
+ else:
1364
+ new_name = f
1365
+ bad.append(new_name.stem)
1366
+ bad_paths.append(new_name)
1367
+
1368
+ if bad:
1369
+ message_intro = (
1370
+ f"Detected {prefix} scenario files:\n"
1371
+ f"{', '.join([f.stem for f in tif_paths])}\n\n"
1372
+ f"However, wrong type in file(s): {', '.join(bad)}. "
1373
+ f"Its/Their type has been added to their name (expected {type_file}).\n\n"
1374
+ f"Do you want to try to convert them to {type_file} automatically?"
1375
+ )
1376
+
1377
+ dlg = wx.MessageDialog(None, message_intro, "Warning", wx.YES_NO | wx.ICON_WARNING)
1378
+ result = dlg.ShowModal()
1379
+ dlg.Destroy()
1380
+
1381
+ if result == wx.ID_YES:
1382
+ for path in bad_paths:
1383
+ with gdal.Open(path, gdal.GA_ReadOnly) as ds:
1384
+ band = ds.GetRasterBand(1)
1385
+ arr = band.ReadAsArray()
1386
+ nodata = band.GetNoDataValue()
1387
+ geotransform = ds.GetGeoTransform()
1388
+ projection = ds.GetProjection()
1389
+
1390
+ # SPÉCIAL POUR LE CAS int8
1391
+ if type_file == "Byte":
1392
+ mask_valid = np.ones_like(arr, dtype=bool)
1393
+ if nodata is not None:
1394
+ mask_valid = arr != nodata
1395
+
1396
+ valid_values = arr[mask_valid]
1397
+ if not np.all((valid_values >= 1) & (valid_values <= 5)):
1398
+ wx.MessageBox(
1399
+ f"Impossible to change the type to int8, there exist other type of data in the raster(s) !\n {message_supp}",
1400
+ "Error", wx.OK | wx.ICON_ERROR
1401
+ )
1402
+ return
1308
1403
 
1309
- def OnCheckScenario(self,e):
1310
- """Checks if scenarios exist in CHANGE_VULNE."""
1311
- tif_files = self._manager.get_modifiedrasters()
1312
- logging.info(_("checking the scenarios for vulnerability and acceptability."))
1313
- if not tif_files:
1314
- wx.MessageBox(
1315
- "No files 'vuln_' or 'MNTmodifs_' found in CHANGE_VULNE.",
1316
- "Information",
1317
- wx.OK | wx.ICON_INFORMATION
1318
- )
1319
- else :
1320
- wx.MessageBox(
1321
- f"There exist vuln_ file(s) in CHANGE_VULNE:\n {', '.join([tif_file for tif_file in tif_files])}",
1322
- "Information", wx.OK | wx.ICON_INFORMATION)
1404
+ arr_new = arr.astype(numpy_type)
1405
+ if nodata is not None:
1406
+ arr_new[arr == nodata] = nodata_value
1407
+ else:
1408
+ arr_new[arr_new < 1] = nodata_value #if nodata doesnt exist
1409
+
1410
+ dirname, filename = os.path.split(path)
1411
+ new_filename = filename.replace(prefix, f"{prefix}AUTO_").replace(".tif", f"_to_{type_file}.tif")
1412
+ old_filename = filename.replace(prefix, f"OLD_{prefix}")
1413
+ new_path = os.path.join(dirname, new_filename)
1414
+ old_path = os.path.join(dirname, old_filename)
1415
+
1416
+ os.rename(path, old_path)
1417
+ driver = gdal.GetDriverByName("GTiff")
1418
+ out_ds = driver.Create(new_path, arr.shape[1], arr.shape[0], 1,
1419
+ gdal.GetDataTypeByName(type_file))
1420
+ out_ds.SetGeoTransform(geotransform)
1421
+ out_ds.SetProjection(projection)
1422
+ out_band = out_ds.GetRasterBand(1)
1423
+ out_band.WriteArray(arr_new)
1424
+ out_band.SetNoDataValue(nodata_value)
1425
+ out_band.FlushCache()
1426
+ out_ds = None
1323
1427
 
1428
+ wx.MessageBox(
1429
+ f"Files converted to {type_file}. Previous ones renamed with 'OLD_...'.",
1430
+ "Information", wx.OK | wx.ICON_INFORMATION
1431
+ )
1432
+ else:
1433
+ wx.MessageBox(
1434
+ f"Detected {prefix} scenario files:\n{', '.join([f.stem for f in tif_paths])}\n Everything is fine.",
1435
+ "Information", wx.OK | wx.ICON_INFORMATION
1436
+ )
1437
+
1438
+ if prefix == "vuln_":
1439
+ self._but_toggle_scen.Enable(True)
1440
+
1441
+ def OnCheckMNTmodifs(self,e):
1442
+ """Checks if scenarios MNTmodifs_ exist in CHANGE_VULNE and test the type (float32)"""
1443
+ self.check_and_convert_rasters(self._manager, "MNTmodifs_", "Float32", np.float32, 99999.)
1444
+ return
1445
+
1446
+ def OnCheckScenario(self,e):
1447
+ """Checks if scenarios vuln_ exist in CHANGE_VULNE and test the type (int8)"""
1448
+ message_supp = textwrap.dedent(""" To change the type and null value as needed, via WOLF HECE GUI:
1449
+ 1. Load the problematic file (File > Add array, and point toward the name indicated above).
1450
+ 2. Ctrl + double click on the name in the Arrays tree on the left. a window should open.
1451
+ 3. Click on "Select all nodes" and then go to Operators. If "=99999", replace with "127" and click "Apply math operator".
1452
+ 4. Go to "Miscellaneous", set "Null value = 127", and click on "Apply Null Value".
1453
+ 5. Change other values (there exists value outside interval of vulnerability [1,5], change them to int8)!
1454
+ 6. (Optionnal) Go back to the main window, Ctrl + right click on the array to save it.
1455
+ 7. Right-click on the array > Duplicate > enter new name (with "vuln_...") and change the type to int8 before saving it.
1456
+ 8. DELETE THE PREVIOUS FILE, and retry the Vulnerability button.
1457
+ """)
1458
+ self.check_and_convert_rasters(self._manager, "vuln_", "Byte", np.int8, 127, message_supp=message_supp)
1459
+
1324
1460
  def OnVulnerability(self, e):
1325
1461
  """ Run the vulnerability """
1326
1462
  if self._manager is None:
@@ -1328,7 +1464,7 @@ class AcceptabilityGui(wx.Frame):
1328
1464
  path = [self._manager.OUT_VULN]
1329
1465
  steps = list(self._steps_vulnerability.GetCheckedStrings())
1330
1466
  steps = [int(cur.split('-')[1]) for cur in steps]
1331
- resolution,_,_,_,_,_ =update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
1467
+ resolution,unused,unused,unused,unused,unused =update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
1332
1468
  if resolution == '':
1333
1469
  wx.MessageBox(
1334
1470
  f"There are no files in INTERP_WD lease, use first the buttons at the second line.",
@@ -1339,11 +1475,10 @@ class AcceptabilityGui(wx.Frame):
1339
1475
  message_supp = "."
1340
1476
  if len(steps) == 0:
1341
1477
  steps = [1,10,11,2,3]
1342
- if self.toggle_state == True :
1343
- message_supp = " AND scenario(s) vuln_ taken into account"
1478
+ if self.toggle_state:
1479
+ message_supp = " with every steps AND scenario(s) vuln_ taken into account"
1344
1480
  steps = [1,10,11,2,3,4]
1345
1481
  if self._manager.OUT_VULN.exists:
1346
- message_supp = " FOR scenario(s) (vuln_ taken into account)"
1347
1482
  logging.info(_("Attention - The manager ONLY computes Vulnerability_scenario, as Vulnerability_baseline already computed."))
1348
1483
  steps=[4]
1349
1484
  else :
@@ -1355,23 +1490,17 @@ class AcceptabilityGui(wx.Frame):
1355
1490
  if response == wx.ID_NO:
1356
1491
  return
1357
1492
 
1358
- logging.info(_("No steps selected. By default every steps will be performed" + message_supp))
1359
- Vulnerability(str(self._manager.main_dir),
1493
+ logging.info(_("No steps selected. By default computations will be performed" + message_supp))
1494
+ check_fail = Vulnerability(str(self._manager.main_dir),
1360
1495
  scenario=str(self._manager.scenario),
1361
1496
  Study_area=str(self._manager.Study_area),
1362
1497
  resolution=resolution,
1363
1498
  steps=steps)
1364
- wx.MessageBox(
1365
- "Vulnerability computed with every steps" + message_supp,
1366
- "Information",
1367
- wx.OK | wx.ICON_INFORMATION
1368
- )
1369
1499
  else :
1370
- if self.toggle_state == True :
1500
+ if self.toggle_state:
1371
1501
  steps.append(4)
1372
- message_supp = " AND scenario(s) vuln_ taken into account"
1502
+ message_supp = " with the selected steps AND scenario(s) vuln_ taken into account"
1373
1503
  if self._manager.OUT_VULN.exists:
1374
- message_supp = " FOR scenario(s) (vuln_ taken into account)"
1375
1504
  logging.info(_("Attention - The manager ONLY computes Vulnerability_scenario, as Vulnerability_baseline already computed."))
1376
1505
  steps=[4]
1377
1506
  else :
@@ -1384,16 +1513,25 @@ class AcceptabilityGui(wx.Frame):
1384
1513
  if response == wx.ID_NO:
1385
1514
  return
1386
1515
 
1387
- Vulnerability(self._manager.main_dir,
1516
+ check_fail = Vulnerability(self._manager.main_dir,
1388
1517
  scenario=self._manager.scenario,
1389
1518
  Study_area=self._manager.Study_area,
1390
1519
  resolution=resolution,
1391
1520
  steps=steps)
1392
- wx.MessageBox(
1393
- "Vulnerability computed with the selected steps" + message_supp,
1394
- "Information",
1395
- wx.OK | wx.ICON_INFORMATION
1396
- )
1521
+
1522
+ if steps_vulnerability.APPLY_SCENARIOSVULN_BUG in check_fail :
1523
+ wx.MessageBox(
1524
+ "Vulnerability NOT computed for scenarios\n Some vuln_ files did not have the required type (int8). They were not taken into account (see renamed files ended by its type (e.g vuln_..._Float32.tif) in CHANGE_VULNE)",
1525
+ "Error",
1526
+ wx.OK | wx.ICON_ERROR
1527
+ )
1528
+ else:
1529
+ wx.MessageBox(
1530
+ "Vulnerability computed" + message_supp,
1531
+ "Information - Success",
1532
+ wx.OK | wx.ICON_INFORMATION
1533
+ )
1534
+
1397
1535
  mapviewer_display(path, self.mapviewer)
1398
1536
 
1399
1537
  def OnAcceptability(self, e):
@@ -1401,7 +1539,7 @@ class AcceptabilityGui(wx.Frame):
1401
1539
  if self._manager is None:
1402
1540
  return
1403
1541
 
1404
- river_trace = self._manager.wich_river_trace()
1542
+ river_trace = self._manager.wich_river_trace(self.toggle_state)
1405
1543
  if self.toggle_state == True and not os.path.isfile(str(self._manager.OUT_VULN_Stif)) and not os.path.isfile(str(river_trace)) :
1406
1544
  wx.MessageBox("Necessary files are missing, please ensure the DataBase or Vulnerability or Updating riverbed steps were performed. ","Error", wx.OK | wx.ICON_ERROR )
1407
1545
  return
@@ -1417,7 +1555,7 @@ class AcceptabilityGui(wx.Frame):
1417
1555
  path = [self._manager.OUT_ACCEPT]
1418
1556
  if len(steps) == 0:
1419
1557
  steps = [1,2,3,4]
1420
- if self.toggle_state == True :
1558
+ if self.toggle_state:
1421
1559
  steps = [1,2,3,4,5]
1422
1560
  message_supp = " AND scenario(s) vuln_ taken into account"
1423
1561
  path = [self._manager.OUT_ACCEPT_Stif]
@@ -1428,7 +1566,7 @@ class AcceptabilityGui(wx.Frame):
1428
1566
 
1429
1567
  if river_trace == self._manager.OUT_MASKED_RIVER : message_supp=message_supp +" WITH the _baseline riverbed trace."
1430
1568
  if river_trace == self._manager.OUT_MASKED_RIVER_S :message_supp+= " WITH the _scenarios riverbed trace."
1431
- if self.toggle_resamp_state == True :
1569
+ if self.toggle_resamp_state:
1432
1570
  steps.append(6)
1433
1571
  resampling = self._but_resampling.GetValue()
1434
1572
  resolution = self.input_dx.GetLabel()
@@ -1439,18 +1577,27 @@ class AcceptabilityGui(wx.Frame):
1439
1577
  message_supp+= f" It has been created for the resolution {resolution}m and the resampling size {resampling}m."
1440
1578
 
1441
1579
  logging.info(_("No steps selected. By default every steps will be performed."))
1442
- Acceptability(self._manager.main_dir,
1580
+ done = Acceptability(self._manager.main_dir,
1443
1581
  scenario=self._manager.scenario,
1444
1582
  Study_area=self._manager.Study_area,
1445
1583
  resample_size=resampling,
1446
1584
  steps=steps)
1447
- wx.MessageBox(
1448
- "Acceptability computed with every steps" + message_supp,
1585
+ if len(done) == 0:
1586
+ wx.MessageBox(
1587
+ "No acceptability computed with the selected steps" + message_supp,
1449
1588
  "Information",
1450
1589
  wx.OK | wx.ICON_INFORMATION
1451
1590
  )
1591
+ else :
1592
+
1593
+ wx.MessageBox(
1594
+ "Acceptability computed with the selected steps" + message_supp,
1595
+ "Information",
1596
+ wx.OK | wx.ICON_INFORMATION
1597
+ )
1598
+ mapviewer_display(path, self.mapviewer)
1452
1599
  else :
1453
- if self.toggle_state == True :
1600
+ if self.toggle_state:
1454
1601
  steps.append(5)
1455
1602
  message_supp = " AND scenario(s) vuln_ taken into account"
1456
1603
  if self._manager.OUT_ACCEPT.exists:
@@ -1458,10 +1605,10 @@ class AcceptabilityGui(wx.Frame):
1458
1605
  logging.info(_('Acceptability_baseline not computed because it already exists.'))
1459
1606
  message_supp = "FOR scenario(s) (vuln_taken into account)"
1460
1607
  path = [self._manager.OUT_ACCEPT_Stif]
1461
- river_trace = self._manager.wich_river_trace()
1608
+ river_trace = self._manager.wich_river_trace(self.toggle_state)
1462
1609
  if river_trace == self._manager.OUT_MASKED_RIVER : message_supp =message_supp + " WITH the _baseline riverbed trace."
1463
1610
  if river_trace == self._manager.OUT_MASKED_RIVER_S : message_supp =message_supp + " WITH the _scenarios riverbed trace."
1464
- if self.toggle_resamp_state == True :
1611
+ if self.toggle_resamp_state:
1465
1612
  resampling = self._but_resampling.GetValue()
1466
1613
  steps.append(6)
1467
1614
 
@@ -1478,7 +1625,7 @@ class AcceptabilityGui(wx.Frame):
1478
1625
  wx.OK | wx.ICON_INFORMATION
1479
1626
  )
1480
1627
  else :
1481
-
1628
+
1482
1629
  wx.MessageBox(
1483
1630
  "Acceptability computed with the selected steps" + message_supp,
1484
1631
  "Information",