wolfhece 2.1.120__py3-none-any.whl → 2.1.121__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 +4 -3
- wolfhece/acceptability/acceptability.py +17 -13
- wolfhece/acceptability/acceptability_gui.py +517 -526
- wolfhece/acceptability/func.py +46 -58
- wolfhece/apps/version.py +1 -1
- wolfhece/wolfresults_2D.py +9 -6
- {wolfhece-2.1.120.dist-info → wolfhece-2.1.121.dist-info}/METADATA +1 -1
- {wolfhece-2.1.120.dist-info → wolfhece-2.1.121.dist-info}/RECORD +11 -11
- {wolfhece-2.1.120.dist-info → wolfhece-2.1.121.dist-info}/WHEEL +0 -0
- {wolfhece-2.1.120.dist-info → wolfhece-2.1.121.dist-info}/entry_points.txt +0 -0
- {wolfhece-2.1.120.dist-info → wolfhece-2.1.121.dist-info}/top_level.txt +0 -0
@@ -1,8 +1,8 @@
|
|
1
1
|
"""
|
2
2
|
Author: University of Liege, HECE
|
3
|
-
Date:
|
3
|
+
Date: 2025
|
4
4
|
|
5
|
-
Copyright (c)
|
5
|
+
Copyright (c) 2025 University of Liege. All rights reserved.
|
6
6
|
|
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.
|
@@ -24,6 +24,7 @@ import matplotlib
|
|
24
24
|
import shutil
|
25
25
|
import os
|
26
26
|
import geopandas as gpd
|
27
|
+
import matplotlib.pyplot as plt
|
27
28
|
from matplotlib.figure import Figure
|
28
29
|
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
|
29
30
|
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar2Wx
|
@@ -40,7 +41,7 @@ def nullvalue_for_hole(WA):
|
|
40
41
|
Sets the null value for a WolfArray to 0 (as per the convention in the interpolation routine).
|
41
42
|
"""
|
42
43
|
WA.nullvalue = 0.
|
43
|
-
WA.set_nullvalue_in_mask()
|
44
|
+
WA.set_nullvalue_in_mask()
|
44
45
|
|
45
46
|
def read_export_z_bin(fn_read, fn_write, fn_laststep):
|
46
47
|
"""
|
@@ -58,15 +59,15 @@ def read_export_z_bin(fn_read, fn_write, fn_laststep):
|
|
58
59
|
top = wolfres2DGPU_test.get_top_for_block(1)
|
59
60
|
nullvalue_for_hole(wd)
|
60
61
|
nullvalue_for_hole(top)
|
61
|
-
wd.array = wd.array + top.array
|
62
|
+
wd.array = wd.array + top.array
|
62
63
|
fn_write = fn_write.with_suffix('.bin')
|
63
64
|
wd.write_all(fn_write)
|
64
65
|
shutil.rmtree(fn_temp)
|
65
|
-
|
66
|
+
|
66
67
|
def riverbed_trace(fn_read_simu, fn_output, threshold):
|
67
68
|
"""
|
68
|
-
Recognizes the riverbed trace based on a simulation, where water depth above a given threshold is considered part of the riverbed.
|
69
|
-
Inputs:
|
69
|
+
Recognizes the riverbed trace based on a simulation, where water depth above a given threshold is considered part of the riverbed.
|
70
|
+
Inputs:
|
70
71
|
- fn_read_simu: the simulation file to read.
|
71
72
|
- fn_output: the location to save the riverbed trace as a .tiff file.
|
72
73
|
- threshold: the water depth threshold above which the areas are considered riverbed.
|
@@ -79,7 +80,7 @@ def riverbed_trace(fn_read_simu, fn_output, threshold):
|
|
79
80
|
wd.array[wd.array < threshold] = 0
|
80
81
|
wd.as_WolfArray()
|
81
82
|
wd.nodata=0
|
82
|
-
wd.write_all(Path(fn_output))
|
83
|
+
wd.write_all(Path(fn_output))
|
83
84
|
|
84
85
|
def empty_folder(folder):
|
85
86
|
"""
|
@@ -90,9 +91,9 @@ def empty_folder(folder):
|
|
90
91
|
fn = os.path.join(folder, files)
|
91
92
|
try:
|
92
93
|
if os.path.isfile(fn) or os.path.islink(fn):
|
93
|
-
os.unlink(fn)
|
94
|
+
os.unlink(fn)
|
94
95
|
elif os.path.isdir(fn):
|
95
|
-
shutil.rmtree(fn)
|
96
|
+
shutil.rmtree(fn)
|
96
97
|
except Exception as e:
|
97
98
|
print(f"Error when deleting file {fn}: {e}")
|
98
99
|
else:
|
@@ -117,7 +118,7 @@ Note: the computations are perfomed with tifs .tif rasters but should be transla
|
|
117
118
|
#----------------------------------------------------------------------------------------------------------
|
118
119
|
|
119
120
|
#1 - Soustraction bathymetry.tif (from simulations) - DEM (MNT, cfr "projet tuilage") ---------------------
|
120
|
-
|
121
|
+
|
121
122
|
def soustraction(fn_a,fn_b,fn_result):
|
122
123
|
with rasterio.open(fn_a) as src_a, rasterio.open(fn_b) as src_b:
|
123
124
|
if (
|
@@ -127,36 +128,35 @@ def soustraction(fn_a,fn_b,fn_result):
|
|
127
128
|
src_a.crs != src_b.crs
|
128
129
|
):
|
129
130
|
logging.error(f"{fn_a} and {fn_b} do not have the same properties, please edit them.")
|
131
|
+
|
130
132
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
133
|
+
data_a = src_a.read(1)
|
134
|
+
data_b = src_b.read(1)
|
135
|
+
|
135
136
|
#(A - B)
|
136
137
|
data_diff = data_a - data_b
|
137
138
|
nodata_value = src_a.nodata if src_a.nodata == src_b.nodata else None
|
138
139
|
if nodata_value is not None:
|
139
140
|
data_diff[(data_a == nodata_value) | (data_b == nodata_value)] = nodata_value
|
140
|
-
|
141
|
+
|
141
142
|
data_diff[data_diff > 5000] = 0
|
142
143
|
labeled, n = label(data_diff)
|
143
144
|
# Remove small objects
|
144
|
-
threshold = 5
|
145
|
+
threshold = 5
|
145
146
|
sizes = np.bincount(labeled.ravel())
|
146
|
-
idx_small = np.where(sizes <= threshold)[0]
|
147
|
-
data_diff[np.isin(labeled, idx_small)] = 0
|
148
|
-
|
147
|
+
idx_small = np.where(sizes <= threshold)[0]
|
148
|
+
data_diff[np.isin(labeled, idx_small)] = 0
|
149
|
+
|
149
150
|
out_meta = src_a.meta.copy()
|
150
151
|
out_meta.update({
|
151
|
-
"dtype": "float32",
|
152
|
+
"dtype": "float32",
|
152
153
|
"driver": "GTiff"
|
153
154
|
})
|
154
155
|
|
155
156
|
with rasterio.open(fn_result, "w", **out_meta) as dst:
|
156
157
|
dst.write(data_diff, 1)
|
157
|
-
|
158
|
-
|
159
|
-
|
158
|
+
|
159
|
+
|
160
160
|
#2 - DEM (MNT) value in the buildings traces ------------------------------------------------------------------
|
161
161
|
def mask_creation_data(mask_file, ground_file, output_file):
|
162
162
|
with rasterio.open(mask_file) as mask_src:
|
@@ -170,23 +170,46 @@ def mask_creation_data(mask_file, ground_file, output_file):
|
|
170
170
|
|
171
171
|
mask[indices] = bathy[indices]
|
172
172
|
mask[mask <= 0] = 275
|
173
|
-
|
173
|
+
|
174
174
|
output_meta = mask_meta.copy()
|
175
175
|
output_meta.update({"dtype": 'float32'})
|
176
176
|
|
177
177
|
with rasterio.open(output_file, "w", **output_meta) as dst:
|
178
178
|
dst.write(mask, 1)
|
179
|
-
|
179
|
+
|
180
180
|
WA_mask = WolfArray(output_file)
|
181
181
|
WA_mask.write_all(Path(Path(output_file).parent / "MNT_computed_with_mask.bin"))
|
182
182
|
|
183
183
|
def MTN_And_mask_creation_all(fn_bathy, fn_mtn_cropped, fn_where_buildings, fn_mask_final):
|
184
|
-
#couper_raster()
|
185
|
-
soustraction(fn_bathy, fn_mtn_cropped, fn_where_buildings)
|
184
|
+
#couper_raster()
|
185
|
+
soustraction(fn_bathy, fn_mtn_cropped, fn_where_buildings)
|
186
186
|
mask_creation_data(fn_where_buildings, fn_mtn_cropped, fn_mask_final)
|
187
|
-
|
187
|
+
|
188
188
|
#--------------------------------------------------------------------------------------------------------------
|
189
189
|
|
190
|
+
def create_INPUT_TEMP_OUTPUT_forScenario(maindir, study_area, scenario, simu_gpu):
|
191
|
+
"""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),
|
192
|
+
if not used, indicate None to ignore it."""
|
193
|
+
base_pathwd = Path(maindir) / "INPUT" / "WATER_DEPTH" / study_area / scenario
|
194
|
+
subfolders = ["DEM_FILES", "INTERP_WD", "EXTRACTED_LAST_STEP_WD"]
|
195
|
+
os.makedirs(base_pathwd, exist_ok=True)
|
196
|
+
for folder in subfolders:
|
197
|
+
os.makedirs(os.path.join(base_pathwd, folder), exist_ok=True)
|
198
|
+
base_pathch = Path(maindir) / "INPUT" / "CHANGE_VULNE" / study_area / scenario
|
199
|
+
os.makedirs(base_pathch, exist_ok=True)
|
200
|
+
|
201
|
+
if simu_gpu != None:
|
202
|
+
path_bat_gpu = Path(simu_gpu) / "bathymetry.tif"
|
203
|
+
if path_bat_gpu.exists():
|
204
|
+
create_shapefile_from_prop_tif(path_bat_gpu, Path(maindir) / "INPUT" / "STUDY_AREA" / f"{study_area}.shp")
|
205
|
+
logging.info("Study area file created in INPUT/STUDY_AREA.")
|
206
|
+
else :
|
207
|
+
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.")
|
208
|
+
|
209
|
+
Accept_Manager(main_dir=maindir, Study_area=study_area, scenario=scenario)
|
210
|
+
logging.info(f"Files created in INPUT, TEMP and OUTPUT for the study area named '{study_area}', and the scenario named '{scenario}'")
|
211
|
+
return
|
212
|
+
|
190
213
|
def get_transform_and_crs(tif_file):
|
191
214
|
"""
|
192
215
|
For TIFF file manipulation, reads the CRS and the transform, and returns them.
|
@@ -205,17 +228,17 @@ def create_shapefile_from_prop_tif(fn_tif, shapefile_path):
|
|
205
228
|
- shapefile_path: the location to save the output shapefile.
|
206
229
|
"""
|
207
230
|
_,_,width,height,_,_ = get_header_info(fn_tif)
|
208
|
-
transform, crs = get_transform_and_crs(fn_tif)
|
231
|
+
transform, crs = get_transform_and_crs(fn_tif)
|
209
232
|
top_left = transform * (0, 0)
|
210
233
|
bottom_left = transform * (0, height)
|
211
234
|
top_right = transform * (width, 0)
|
212
235
|
bottom_right = transform * (width, height)
|
213
|
-
|
236
|
+
|
214
237
|
rectangle = Polygon([top_left, top_right, bottom_right, bottom_left, top_left])
|
215
238
|
gdf = gpd.GeoDataFrame({'geometry': [rectangle]})
|
216
239
|
gdf.set_crs(crs, allow_override=True, inplace=True)
|
217
240
|
gdf.to_file(shapefile_path)
|
218
|
-
|
241
|
+
|
219
242
|
def get_header_info(fn):
|
220
243
|
"""
|
221
244
|
Reads the headers from the file at path 'fn'.
|
@@ -235,8 +258,8 @@ def get_header_comparison(list_fn):
|
|
235
258
|
header_infos = [get_header_info(fn) for fn in list_fn]
|
236
259
|
variable_names = ["dx", "dy", "nbx", "nby", "X", "Y"]
|
237
260
|
for idx, name in enumerate(variable_names):
|
238
|
-
values = [header[idx] for header in header_infos]
|
239
|
-
if len(set(values)) > 1:
|
261
|
+
values = [header[idx] for header in header_infos]
|
262
|
+
if len(set(values)) > 1:
|
240
263
|
comp = False
|
241
264
|
else:
|
242
265
|
comp = True
|
@@ -250,13 +273,13 @@ def display_info_header(self_dx, self_nbxy, self_O, fn):
|
|
250
273
|
dx,dy,nbx,nby,X,Y= get_header_info(fn)
|
251
274
|
self_dx.SetLabel(f"({dx},{dy})")
|
252
275
|
self_nbxy.SetLabel(f"({nbx},{nby})")
|
253
|
-
self_O.SetLabel(f"({X},{Y})")
|
276
|
+
self_O.SetLabel(f"({X},{Y})")
|
254
277
|
return dx,dy,nbx,nby,X,Y
|
255
|
-
|
278
|
+
|
256
279
|
def vanish_info_header(self_dx, self_nbxy, self_O):
|
257
280
|
self_dx.SetLabel("")
|
258
281
|
self_nbxy.SetLabel("")
|
259
|
-
self_O.SetLabel("")
|
282
|
+
self_O.SetLabel("")
|
260
283
|
|
261
284
|
def update_info_header(self_dx, self_nbxy, self_O, fn):
|
262
285
|
"""
|
@@ -264,11 +287,11 @@ def update_info_header(self_dx, self_nbxy, self_O, fn):
|
|
264
287
|
"""
|
265
288
|
if not os.path.exists(fn):
|
266
289
|
os.makedirs(fn)
|
267
|
-
|
290
|
+
|
268
291
|
tif_files = [f for f in os.listdir(fn) if f.lower().endswith('.tif')]
|
269
292
|
tif_list_fn = [os.path.join(fn, tif_file) for tif_file in tif_files]
|
270
|
-
if tif_files:
|
271
|
-
if get_header_comparison(tif_list_fn) :
|
293
|
+
if tif_files:
|
294
|
+
if get_header_comparison(tif_list_fn) :
|
272
295
|
dx,dy,nbx,nby,X,Y = display_info_header(self_dx, self_nbxy, self_O, tif_list_fn[0])
|
273
296
|
return dx,dy,nbx,nby,X,Y
|
274
297
|
else:
|
@@ -276,8 +299,8 @@ def update_info_header(self_dx, self_nbxy, self_O, fn):
|
|
276
299
|
return False, False, False, False, False, False
|
277
300
|
else :
|
278
301
|
vanish_info_header(self_dx, self_nbxy, self_O)
|
279
|
-
return False, False, False, False, False, False
|
280
|
-
|
302
|
+
return False, False, False, False, False, False
|
303
|
+
|
281
304
|
def search_for_modif_bath_and_copy(main_gpu, from_path, path_vuln):
|
282
305
|
"""
|
283
306
|
When loading gpu simulations for last step extraction, search for modified bath_ topography file, according to
|
@@ -290,9 +313,9 @@ def search_for_modif_bath_and_copy(main_gpu, from_path, path_vuln):
|
|
290
313
|
curdicts = scen_manager.get_dicts(curtree)
|
291
314
|
all_tif_bath = [scen_manager._select_tif_partname(curdict, 'bath_') for curdict in curdicts]
|
292
315
|
all_tif_bath = [curel for curlist in all_tif_bath if len(curlist)>0 for curel in curlist if curel.name.startswith('bath_')]
|
293
|
-
if len(all_tif_bath) :
|
316
|
+
if len(all_tif_bath) :
|
294
317
|
found_bath = True
|
295
|
-
for tif_file in all_tif_bath:
|
318
|
+
for tif_file in all_tif_bath:
|
296
319
|
found_bath = True
|
297
320
|
with rasterio.open(tif_file) as src:
|
298
321
|
#vuln_ files
|
@@ -308,7 +331,7 @@ def search_for_modif_bath_and_copy(main_gpu, from_path, path_vuln):
|
|
308
331
|
output_file = path_vuln / tif_file.name.replace('bath_', 'MNTmodifs_')
|
309
332
|
with rasterio.open(output_file, 'w', **metadata) as dst:
|
310
333
|
dst.write(data, 1)
|
311
|
-
|
334
|
+
|
312
335
|
return found_bath
|
313
336
|
|
314
337
|
def mapviewer_display(list_path):
|
@@ -319,7 +342,7 @@ def mapviewer_display(list_path):
|
|
319
342
|
dlg.Destroy()
|
320
343
|
if ret != wx.ID_YES:
|
321
344
|
return
|
322
|
-
|
345
|
+
|
323
346
|
mapviewer = WolfMapViewer(title="OUTPUT Acceptability manager")
|
324
347
|
for path in list_path:
|
325
348
|
myarray = WolfArray(path)
|
@@ -351,74 +374,74 @@ class AcceptabilityGui(wx.Frame):
|
|
351
374
|
raise TypeError("The mapviewer must be a WolfMapViewer")
|
352
375
|
|
353
376
|
self._mapviewer = value
|
354
|
-
|
377
|
+
|
355
378
|
def OnHoverEnter(self, event):
|
356
379
|
"""Dynamic colour layout 1"""
|
357
|
-
self._but_creation.SetBackgroundColour(wx.Colour(100,100,100))
|
380
|
+
self._but_creation.SetBackgroundColour(wx.Colour(100,100,100))
|
358
381
|
self._but_creation.Refresh()
|
359
382
|
event.Skip()
|
360
383
|
|
361
384
|
def OnHoverLeave(self, event):
|
362
385
|
"""Dynamic colour layout 2"""
|
363
|
-
self._but_creation.SetBackgroundColour(wx.Colour(150,150,150))
|
386
|
+
self._but_creation.SetBackgroundColour(wx.Colour(150,150,150))
|
364
387
|
self._but_creation.Refresh()
|
365
388
|
event.Skip()
|
366
|
-
|
389
|
+
|
367
390
|
def layout(self, self_fct):
|
368
391
|
"""Update the layers for the main buttons"""
|
369
392
|
font = self_fct.GetFont()
|
370
393
|
font.SetWeight(wx.FONTWEIGHT_BOLD)
|
371
394
|
self_fct.SetFont(font)
|
372
|
-
self_fct.SetBackgroundColour(wx.Colour(150,150,150))
|
395
|
+
self_fct.SetBackgroundColour(wx.Colour(150,150,150))
|
373
396
|
self_fct.Bind(wx.EVT_ENTER_WINDOW, self.OnHoverEnter)
|
374
397
|
self_fct.Bind(wx.EVT_LEAVE_WINDOW, self.OnHoverLeave)
|
375
|
-
|
398
|
+
|
376
399
|
def on_button_click(self, event):
|
377
400
|
self.PopupMenu(self.menu)
|
378
401
|
|
379
402
|
def on_menu_click(self, event):
|
380
|
-
"""Two options for the 'Update Riverbed' button: either the new riverbed trace
|
381
|
-
file already exists and the user selects it, or it does not exist, and the user points to
|
403
|
+
"""Two options for the 'Update Riverbed' button: either the new riverbed trace
|
404
|
+
file already exists and the user selects it, or it does not exist, and the user points to
|
382
405
|
a no-overflow simulation, allowing the code to create the trace."""
|
383
406
|
menu_id = event.GetId()
|
384
|
-
if menu_id == 1:
|
407
|
+
if menu_id == 1:
|
385
408
|
logging.info("Option 1 : the file exists, pointing towards it.")
|
386
|
-
dlg = wx.FileDialog(None, "Please select the .tiff file with the NEW trace of the riverbed.",
|
387
|
-
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST,
|
409
|
+
dlg = wx.FileDialog(None, "Please select the .tiff file with the NEW trace of the riverbed.",
|
410
|
+
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST,
|
388
411
|
wildcard="TIFF files (*.tiff)|*.tiff")
|
389
412
|
|
390
413
|
if dlg.ShowModal() == wx.ID_OK:
|
391
|
-
selected_file = Path(dlg.GetPath())
|
414
|
+
selected_file = Path(dlg.GetPath())
|
392
415
|
copied_file = self._manager.OUT_SCEN_DIR / "copy_file"
|
393
416
|
shutil.copy(selected_file, copied_file)
|
394
417
|
logging.info(f"File copied to: {copied_file}")
|
395
|
-
|
418
|
+
|
396
419
|
new_name = self._manager.OUT_MASKED_RIVER_S
|
397
|
-
|
420
|
+
|
398
421
|
with wx.MessageDialog(self, f"Modified riverbed imported and called Masked_River_extent_scenarios.tiff.",
|
399
422
|
"File imported.", wx.OK | wx.ICON_INFORMATION) as dlg:
|
400
423
|
dlg.ShowModal()
|
401
|
-
|
424
|
+
|
402
425
|
if new_name.exists():
|
403
426
|
new_name.unlink()
|
404
|
-
|
427
|
+
|
405
428
|
copied_file.rename(new_name)
|
406
429
|
logging.info(f"File renamed to: {new_name}")
|
407
430
|
else:
|
408
431
|
logging.info('No file selected. Please try again.')
|
409
|
-
|
432
|
+
|
410
433
|
elif menu_id == 2: #No file, so need to create
|
411
434
|
logging.info("Option 2 : pointing to simulation with low discharge (no overflows!).")
|
412
|
-
|
435
|
+
|
413
436
|
with wx.DirDialog(self, "Please select a simul_gpu_results folder of a simulation with low discharges (no overflows).", style=wx.DD_DEFAULT_STYLE) as dir_dlg:
|
414
|
-
if dir_dlg.ShowModal() == wx.ID_OK:
|
415
|
-
selected_folder = Path(dir_dlg.GetPath())
|
416
|
-
if os.path.basename(selected_folder) == "simul_gpu_results" :
|
417
|
-
logging.info(f"Selected folder: {selected_folder}")
|
437
|
+
if dir_dlg.ShowModal() == wx.ID_OK:
|
438
|
+
selected_folder = Path(dir_dlg.GetPath())
|
439
|
+
if os.path.basename(selected_folder) == "simul_gpu_results" :
|
440
|
+
logging.info(f"Selected folder: {selected_folder}")
|
418
441
|
fn_output = self._manager.OUT_MASKED_RIVER_S
|
419
442
|
dlg = wx.TextEntryDialog(self, "What water depth threshold (in meters) should be used to define the riverbed trace, above which\n"
|
420
443
|
"the water depth is considered part of the riverbed? Use a dot as a decimal separator (e.g 0.3).", "Type a water depth threshold in [m] (e.g 0.3)", "")
|
421
|
-
|
444
|
+
|
422
445
|
if dlg.ShowModal() == wx.ID_OK:
|
423
446
|
while True:
|
424
447
|
try:
|
@@ -452,17 +475,19 @@ class AcceptabilityGui(wx.Frame):
|
|
452
475
|
|
453
476
|
else:
|
454
477
|
logging.info("Cancelled.")
|
455
|
-
dlg.Destroy()
|
478
|
+
dlg.Destroy()
|
456
479
|
else:
|
457
480
|
logging.info("No folder (or wrong one) selected. Please try again (must be simul_gpu_results).")
|
458
|
-
|
481
|
+
|
482
|
+
|
459
483
|
def layout_listbox(self, self_fct):
|
460
484
|
"""Changes the layout for the listbox : light grey."""
|
461
485
|
self_fct.SetBackgroundColour(wx.Colour(220, 220, 220))
|
462
486
|
|
463
487
|
def InitUI(self):
|
464
488
|
self.gpu_bathy = None
|
465
|
-
|
489
|
+
self.maindir = None
|
490
|
+
|
466
491
|
sizer_hor_main = wx.BoxSizer(wx.HORIZONTAL)
|
467
492
|
sizer_vert1 = wx.BoxSizer(wx.VERTICAL)
|
468
493
|
sizer_hor_threads = wx.BoxSizer(wx.HORIZONTAL)
|
@@ -473,129 +498,132 @@ class AcceptabilityGui(wx.Frame):
|
|
473
498
|
sizer_hor4 = wx.BoxSizer(wx.HORIZONTAL)
|
474
499
|
sizer_hor_scen = wx.BoxSizer(wx.HORIZONTAL)
|
475
500
|
|
476
|
-
# 1st LINE
|
501
|
+
# 1st LINE - Loading acceptability folder
|
477
502
|
panel = wx.Panel(self)
|
478
503
|
self._but_maindir = wx.Button(panel, label='Main Directory')
|
504
|
+
self._but_maindir.SetToolTip("To indicate where the main acceptability\n folder is located.")
|
479
505
|
self._but_maindir.SetFont(wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
|
480
506
|
self._but_maindir.Bind(wx.EVT_BUTTON, self.OnMainDir)
|
481
|
-
|
507
|
+
|
482
508
|
self._listbox_studyarea = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
|
483
509
|
self.layout_listbox(self._listbox_studyarea)
|
484
510
|
self._listbox_studyarea.Bind(wx.EVT_LISTBOX, self.OnStudyArea)
|
485
|
-
self._listbox_studyarea.SetToolTip("Choose the study area")
|
511
|
+
self._listbox_studyarea.SetToolTip("Choose the study area existed in the folder.")
|
486
512
|
|
487
513
|
self._listbox_scenario = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
|
488
|
-
self.layout_listbox(self._listbox_scenario)
|
514
|
+
self.layout_listbox(self._listbox_scenario)
|
489
515
|
self._listbox_scenario.Bind(wx.EVT_LISTBOX, self.OnScenario)
|
490
|
-
self._listbox_scenario.SetToolTip("Choose the scenario")
|
491
|
-
|
492
|
-
|
493
|
-
self._but_checkfiles = wx.Button(panel, label='Check
|
516
|
+
self._listbox_scenario.SetToolTip("Choose the acceptability scenario.")
|
517
|
+
|
518
|
+
sizer_ver_small = wx.BoxSizer(wx.VERTICAL)
|
519
|
+
self._but_checkfiles = wx.Button(panel, label='Check structure')
|
494
520
|
self._but_checkfiles.Bind(wx.EVT_BUTTON, self.OnCheckFiles)
|
495
|
-
self.
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
# Hydrodynamic part
|
500
|
-
self._but_checksim = wx.Button(panel, label='Check existing interpolated\n free surfaces')
|
521
|
+
self._but_checkfiles.SetToolTip("Checks if the folder is correctly structured\n with INPUT, TEMP, OUTPUT.")
|
522
|
+
self._but_checksim = wx.Button(panel, label='Check simulations')
|
523
|
+
self._but_checksim.SetToolTip("Displays the loaded simulations, interpolated in INTERP_WD.")
|
501
524
|
self._but_checksim.Bind(wx.EVT_BUTTON, self.OnHydrodynInput)
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
self.
|
525
|
+
|
526
|
+
self._but_checkpond= wx.Button(panel, label='Check ponderation')
|
527
|
+
self._but_checkpond.Bind(wx.EVT_BUTTON, self.OnCheckPond)
|
528
|
+
self._but_checkpond.SetToolTip("Displays a graph of the computed weighting coefficient\n of the final acceptability computations.")
|
529
|
+
|
530
|
+
# 2nd LINE - Hydrodynamic part
|
531
|
+
self._but_loadgpu = wx.Button(panel, label='Load new\n hydraulic scenarios')
|
532
|
+
self._but_loadgpu.SetToolTip("To load or change the hydraulic simulations")
|
533
|
+
self._but_loadgpu.SetFont(wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
|
506
534
|
self._but_loadgpu.Bind(wx.EVT_BUTTON, self.OnLoadingSimu)
|
507
535
|
sizer_hor1_1.Add(self._but_loadgpu, 1, wx.ALL | wx.EXPAND, 0)
|
508
|
-
|
536
|
+
|
509
537
|
|
510
538
|
self._check_listbox = wx.CheckListBox(panel, choices=[], style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
|
511
|
-
self.layout_listbox(self._check_listbox)
|
539
|
+
self.layout_listbox(self._check_listbox)
|
512
540
|
self.sims = {}
|
513
541
|
sizer_hor1_1.Add(self._check_listbox, 1, wx.ALL | wx.EXPAND, 0) #ajouter!! sinon s'affiche pas
|
514
542
|
|
515
543
|
self._but_DEM = wx.Button(panel, label='Check DEM inputs\n for interpolation')
|
544
|
+
self._but_DEM.SetToolTip("To display the existing DEM input for the interpolation of the simulated free surfaces.")
|
516
545
|
self._but_DEM.Bind(wx.EVT_BUTTON, self.OnDEM)
|
517
546
|
sizer_hor1_1.Add(self._but_DEM, 1, wx.ALL | wx.EXPAND, 0)
|
518
|
-
|
547
|
+
|
519
548
|
self._but_extrinterp = wx.Button(panel, label='Reading and interpolating\n free surface')
|
549
|
+
self._but_extrinterp.SetToolTip("To read the simulation, and created the hydraulic input for\n acceptability (interpolated simulated free surfaces)")
|
520
550
|
self._but_extrinterp.Bind(wx.EVT_BUTTON, self.OnInterpolation)
|
521
551
|
sizer_hor1_1.Add(self._but_extrinterp, 1, wx.ALL | wx.EXPAND, 0)
|
522
552
|
|
523
553
|
sizer_hor1.Add(self._but_maindir, 2, wx.ALL | wx.EXPAND, 0)
|
524
554
|
sizer_hor1.Add(self._listbox_studyarea, 1, wx.ALL | wx.EXPAND, 0)
|
525
555
|
sizer_hor1.Add(self._listbox_scenario, 1, wx.ALL | wx.EXPAND, 0)
|
526
|
-
|
556
|
+
sizer_hor1.Add(sizer_ver_small, 0, wx.ALL | wx.EXPAND, 5)
|
527
557
|
|
528
558
|
#3rd line
|
529
559
|
sizer_hor_threads = wx.BoxSizer(wx.HORIZONTAL)
|
530
560
|
text_dx = wx.StaticText(panel, label='Resolution (dx,dy) [m]:')
|
531
561
|
self.input_dx = wx.StaticText(panel)
|
532
|
-
self.input_dx.SetMinSize((
|
562
|
+
self.input_dx.SetMinSize((80, -1))
|
533
563
|
text_nbxy = wx.StaticText(panel, label='(nbx, nby):')
|
534
564
|
self.input_nbxy = wx.StaticText(panel)
|
535
|
-
self.input_nbxy.SetMinSize((
|
565
|
+
self.input_nbxy.SetMinSize((90, -1))
|
536
566
|
text_O = wx.StaticText(panel, label='Origin (X,Y):')
|
537
567
|
self.input_O = wx.StaticText(panel)
|
538
|
-
self.input_O.SetMinSize((
|
568
|
+
self.input_O.SetMinSize((170, -1))
|
539
569
|
text_threads = wx.StaticText(panel, label='Number of threads:')
|
540
570
|
self._nb_process = wx.SpinCtrl(panel, value=str(os.cpu_count()), min=1, max=os.cpu_count())
|
541
|
-
self._nb_process.SetToolTip("Number of threads to
|
542
|
-
|
543
|
-
self._but_sacreation = wx.Button(panel, label='SA creation')
|
544
|
-
self._but_sacreation.Bind(wx.EVT_BUTTON, self.OnSAcreation)
|
545
|
-
|
571
|
+
self._nb_process.SetToolTip("Number of threads to be used in the computations.")
|
572
|
+
|
546
573
|
sizer_hor_threads.Add(text_dx, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
547
574
|
sizer_hor_threads.Add(self.input_dx, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
548
575
|
sizer_hor_threads.Add(text_nbxy, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
549
576
|
sizer_hor_threads.Add(self.input_nbxy, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
550
577
|
sizer_hor_threads.Add(text_O, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
551
578
|
sizer_hor_threads.Add(self.input_O, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
552
|
-
sizer_hor_threads.Add(self._but_sacreation, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2)
|
553
579
|
sizer_hor_threads.Add(text_threads, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
554
580
|
sizer_hor_threads.Add(self._nb_process, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
555
|
-
|
581
|
+
|
556
582
|
# 3 last lines + scenarios
|
557
583
|
#--------------------------
|
558
584
|
self._but_creation = wx.Button(panel, label='DataBase Creation')
|
559
|
-
self.layout(self._but_creation)
|
585
|
+
self.layout(self._but_creation)
|
560
586
|
self._but_creation.Bind(wx.EVT_BUTTON, self.OnCreation)
|
561
|
-
|
587
|
+
|
562
588
|
self._steps_db = wx.CheckListBox(panel, choices=steps_base_data_creation.get_list_names(), style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
|
563
589
|
|
564
590
|
self._but_vulnerability = wx.Button(panel, label='Vulnerability')
|
565
|
-
self.layout(self._but_vulnerability)
|
566
|
-
self._but_vulnerability.Bind(wx.EVT_BUTTON, self.OnVulnerability)
|
591
|
+
self.layout(self._but_vulnerability)
|
592
|
+
self._but_vulnerability.Bind(wx.EVT_BUTTON, self.OnVulnerability)
|
567
593
|
step_Vuln_without_withoutscenarios = [item for item in steps_vulnerability.get_list_names() if item != 'APPLY_SCENARIOSVULN - 4']
|
568
594
|
self._steps_vulnerability = wx.CheckListBox(panel, choices=step_Vuln_without_withoutscenarios, style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
|
569
|
-
|
570
|
-
|
595
|
+
|
571
596
|
# Scenarios specifics --
|
572
597
|
self._but_checkscenario = wx.Button(panel, label='Check existing scenarios')
|
598
|
+
self._but_checkscenario.SetToolTip("To display the scenario to be taken into account in CHANGE_VULNE.")
|
573
599
|
self._but_checkscenario.Bind(wx.EVT_BUTTON, self.OnCheckScenario)
|
574
|
-
|
575
|
-
|
600
|
+
|
576
601
|
self._but_upriverbed = wx.Button(panel, label="Update riverbed")
|
602
|
+
self._but_upriverbed.SetToolTip("To create the raster of the riverbed trace.")
|
577
603
|
self._but_upriverbed.Bind(wx.EVT_BUTTON, self.on_button_click)
|
578
604
|
|
579
605
|
self.menu = wx.Menu()
|
580
606
|
self.menu.Append(1, "File of riverbed trace exists.")
|
581
607
|
self.menu.Append(2, "Point to a low discharge simulation and calculate the riverbed trace.")
|
582
608
|
self.menu.Bind(wx.EVT_MENU, self.on_menu_click)
|
583
|
-
|
609
|
+
|
584
610
|
self._but_toggle_scen = wx.ToggleButton(panel, label="Accounting for scenarios")
|
611
|
+
self._but_toggle_scen.SetToolTip("To be activated to surimpose the vuln_ files, \n and so to take into account scenarios")
|
585
612
|
self.toggle_state = False
|
586
613
|
self._but_toggle_scen.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle)
|
587
|
-
|
614
|
+
|
588
615
|
sizer_hor_scen.Add(self._but_checkscenario, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
589
616
|
sizer_hor_scen.Add(self._but_upriverbed, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
590
617
|
sizer_hor_scen.Add(self._but_toggle_scen, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
591
|
-
|
618
|
+
|
592
619
|
self._but_toggle_resamp = wx.ToggleButton(panel, label="Resampling [m]:")
|
620
|
+
self._but_toggle_resamp.SetToolTip("To compute the final raster with a coarser resolution than the original one.")
|
593
621
|
self.toggle_resamp_state = False
|
594
622
|
self._but_toggle_resamp.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggleResampling)
|
595
623
|
sizer_hor_scen.Add(self._but_toggle_resamp, flag=wx.ALIGN_CENTER | wx.TOP)
|
596
624
|
self._but_resampling = wx.SpinCtrl(panel, value="100", min=1, max=1000)
|
597
625
|
sizer_hor_scen.Add(self._but_resampling, flag=wx.ALIGN_CENTER | wx.TOP)
|
598
|
-
|
626
|
+
|
599
627
|
#--
|
600
628
|
|
601
629
|
self._but_acceptability = wx.Button(panel, label='Acceptability')
|
@@ -616,6 +644,10 @@ class AcceptabilityGui(wx.Frame):
|
|
616
644
|
sizer_hor4.Add(self._steps_acceptability, 1, wx.ALL | wx.EXPAND, 0)
|
617
645
|
|
618
646
|
#Lines order
|
647
|
+
sizer_ver_small.Add(self._but_checkfiles, 0, wx.ALL | wx.EXPAND, 1)
|
648
|
+
sizer_ver_small.Add(self._but_checksim, 0, wx.ALL | wx.EXPAND, 1)
|
649
|
+
sizer_ver_small.Add(self._but_checkpond, 0, wx.ALL | wx.EXPAND, 1)
|
650
|
+
|
619
651
|
sizer_vert1.Add(sizer_hor1, 1, wx.EXPAND, 0)
|
620
652
|
sizer_vert1.Add(sizer_hor1_1, 1, wx.EXPAND, 0)
|
621
653
|
sizer_vert1.Add(sizer_hor_threads, 0, wx.EXPAND, 0)
|
@@ -623,49 +655,8 @@ class AcceptabilityGui(wx.Frame):
|
|
623
655
|
sizer_vert1.Add(sizer_hor_scen, 1, wx.EXPAND, 0)
|
624
656
|
sizer_vert1.Add(sizer_hor3, 1, wx.EXPAND, 0)
|
625
657
|
sizer_vert1.Add(sizer_hor4, 1, wx.EXPAND, 0)
|
626
|
-
# ------
|
627
|
-
|
628
|
-
sizer_vert2 = wx.BoxSizer(wx.VERTICAL)
|
629
|
-
|
630
|
-
self._listbox_returnperiods = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
|
631
|
-
self._listbox_returnperiods.SetToolTip("All available return periods in the database")
|
632
|
-
|
633
|
-
self._listbox_sims = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
|
634
|
-
self._listbox_sims.SetToolTip("All available simulations in the database")
|
635
|
-
|
636
|
-
self._listbox_sims.Bind(wx.EVT_LISTBOX, self.OnSims)
|
637
|
-
self._listbox_sims.Bind(wx.EVT_LISTBOX_DCLICK, self.OnSimsDBLClick)
|
638
|
-
|
639
|
-
sizer_vert2.Add(self._listbox_returnperiods, 1, wx.EXPAND, 0)
|
640
|
-
sizer_vert2.Add(self._listbox_sims, 1, wx.EXPAND, 0)
|
641
|
-
|
642
|
-
# ------
|
643
|
-
|
644
|
-
sizer_vert3 = wx.BoxSizer(wx.VERTICAL)
|
645
|
-
|
646
|
-
matplotlib.use('WXAgg')
|
647
|
-
|
648
|
-
self._figure = Figure(figsize=(5, 4), dpi=100)
|
649
|
-
self._axes = self._figure.add_subplot(111)
|
650
|
-
self._axes.set_ylabel("Weighting coefficients")
|
651
|
-
self._axes.set_xlabel("Return period")
|
652
|
-
self._axes.grid(axis='y', linestyle='--', alpha=0.7)
|
653
|
-
|
654
|
-
self._canvas = FigureCanvas(panel, -1, self._figure)
|
655
|
-
self._toolbar = NavigationToolbar2Wx(self._canvas)
|
656
|
-
self._toolbar.Realize()
|
657
|
-
|
658
|
-
sizer_vert3.Add(self._canvas, 1, wx.EXPAND, 0)
|
659
|
-
sizer_vert3.Add(self._toolbar, 0, wx.LEFT | wx.EXPAND, 0)
|
660
658
|
|
661
|
-
|
662
|
-
|
663
|
-
sizer_hor_main.Add(sizer_vert1, 1, wx.EXPAND, 0)
|
664
|
-
sizer_hor_main.Add(sizer_vert2, 1, wx.EXPAND, 0)
|
665
|
-
sizer_hor_main.Add(sizer_vert3, 1, wx.EXPAND, 0)
|
666
|
-
|
667
|
-
panel.SetSizer(sizer_hor_main)
|
668
|
-
panel.Layout()
|
659
|
+
sizer_hor_main.Add(sizer_vert1, proportion=1, flag=wx.EXPAND, border=0)
|
669
660
|
|
670
661
|
#Disabled if Main Directory + SA + Scenario not selected
|
671
662
|
self._but_acceptability.Enable(False)
|
@@ -674,15 +665,19 @@ class AcceptabilityGui(wx.Frame):
|
|
674
665
|
self._but_checkfiles.Enable(False)
|
675
666
|
self._but_DEM.Enable(False)
|
676
667
|
self._but_extrinterp.Enable(False)
|
677
|
-
self._but_loadgpu.Enable(False)
|
678
668
|
self._but_toggle_scen.Enable(False)
|
679
669
|
self._but_toggle_resamp.Enable(False)
|
680
670
|
self._but_upriverbed.Enable(False)
|
671
|
+
self._but_checkpond.Enable(False)
|
681
672
|
self._but_checkscenario.Enable(False)
|
682
673
|
self._but_checksim.Enable(False)
|
683
|
-
self._but_sacreation.Enable(False)
|
684
674
|
self._but_creation.Enable(False)
|
685
|
-
|
675
|
+
self._but_loadgpu.Enable(False)
|
676
|
+
|
677
|
+
panel.SetSizer(sizer_hor_main)
|
678
|
+
panel.Layout()
|
679
|
+
|
680
|
+
|
686
681
|
def OnSims(self, e:wx.ListEvent):
|
687
682
|
""" Load sim into the mapviewer """
|
688
683
|
pass
|
@@ -707,122 +702,297 @@ class AcceptabilityGui(wx.Frame):
|
|
707
702
|
logging.error("No main directory selected -- Nothing to check")
|
708
703
|
return
|
709
704
|
|
710
|
-
|
711
|
-
|
712
|
-
if
|
713
|
-
logging.
|
714
|
-
with wx.MessageDialog(self, "
|
715
|
-
dlg.ShowModal()
|
716
|
-
else:
|
717
|
-
logging.error(f"Missing files: {ret}")
|
718
|
-
with wx.MessageDialog(self, f"Missing files: \n{ret}", "Error", wx.OK | wx.ICON_ERROR) as dlg:
|
705
|
+
i=self._manager.check_inputs()
|
706
|
+
|
707
|
+
if i == False :
|
708
|
+
logging.error(f"Missing files in INPUT. Please provide them by following the right structure.")
|
709
|
+
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:
|
719
710
|
dlg.ShowModal()
|
711
|
+
return
|
712
|
+
else :
|
713
|
+
if (self._manager._study_area == None) or (self._manager._scenario == None):
|
714
|
+
logging.error(f"No study area and/or scenario selected, no check of TEMP and OUTPUT.")
|
715
|
+
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:
|
716
|
+
dlg.ShowModal()
|
717
|
+
else:
|
718
|
+
logging.info(f"The folder is well structured.")
|
719
|
+
t=self._manager.check_temporary()
|
720
|
+
o=self._manager.check_outputs()
|
721
|
+
with wx.MessageDialog(self, f"Main directory is checked.\nINPUT is well structured, and TEMP and OUTPUT have been checked. If folders were missing, they have been created\nMain directory at {self.maindir}", "Checking", wx.OK | wx.ICON_INFORMATION) as dlg:
|
722
|
+
dlg.ShowModal()
|
720
723
|
|
721
|
-
|
724
|
+
|
722
725
|
def OnHydrodynInput(self,e):
|
723
726
|
""" A test to check if the FILLED water depths files exist.
|
724
727
|
-If YES : the code can go on
|
725
728
|
-If NO : either need to be computed, either the code will use the baseline ones
|
726
729
|
"""
|
727
|
-
|
730
|
+
|
728
731
|
if self._manager is None:
|
729
732
|
logging.error("No main directory selected -- Nothing to check")
|
730
733
|
return
|
731
734
|
|
732
735
|
paths_FilledWD = self._manager.get_sims_files_for_scenario()
|
733
|
-
|
736
|
+
|
734
737
|
if len(paths_FilledWD) == 0 :
|
735
738
|
logging.info("There are no interpolated free surface files.")
|
736
|
-
dialog = wx.MessageDialog(None, "There are no interpolated free surface files. Please choose an action.", "Choose an option",
|
739
|
+
dialog = wx.MessageDialog(None, "There are no interpolated free surface files. Please choose an action.", "Checking- Choose an option",
|
737
740
|
wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION)
|
738
|
-
|
739
|
-
dialog.SetYesNoLabels("Use the ones in the
|
740
|
-
response = dialog.ShowModal()
|
741
|
+
|
742
|
+
dialog.SetYesNoLabels("Use the ones in the scenario_baseline (assumption)", "Load other simulations")
|
743
|
+
response = dialog.ShowModal()
|
741
744
|
|
742
745
|
if response == wx.ID_YES:
|
743
746
|
logging.info("Decision of using baseline simulations.")
|
744
747
|
paths_FilledWD_base = self._manager.get_sims_files_for_baseline()
|
745
748
|
if len(paths_FilledWD_base) == 0 :
|
746
|
-
logging.info("Cannot select files in the _baseline folder.")
|
749
|
+
logging.info("Cannot select files in the _baseline folder (no files or no folder!).")
|
747
750
|
else:
|
748
751
|
self._manager.copy_tif_files(paths_FilledWD_base, self._manager.IN_SA_INTERP)
|
749
|
-
|
752
|
+
|
750
753
|
elif response == wx.ID_NO:
|
751
754
|
logging.info("Decision of loading simulations.")
|
752
|
-
with wx.MessageDialog(self, f"Please use the 'Load gpu simulations folder' button of the manager and follow the instructions.", "Redirecting",
|
753
|
-
wx.OK | wx.ICON_INFORMATION) as dlg:
|
755
|
+
with wx.MessageDialog(self, f"Please use the 'Load gpu simulations folder' button of the manager and follow the instructions.", "Redirecting",
|
756
|
+
wx.OK | wx.ICON_INFORMATION) as dlg:
|
754
757
|
dlg.ShowModal()
|
755
758
|
else:
|
756
759
|
logging.info("Cancelled")
|
757
|
-
|
758
|
-
dialog.Destroy()
|
759
|
-
|
760
|
+
|
761
|
+
dialog.Destroy()
|
762
|
+
|
760
763
|
else:
|
761
764
|
name_paths_FilledWD = []
|
762
|
-
|
765
|
+
|
763
766
|
for names in paths_FilledWD:
|
764
|
-
logging.info(f"Interpolated free surface file found: {names.name}.")
|
767
|
+
logging.info(f"Interpolated free surface file(s) found: {names.name}. \n Reminder : the names of the simulations MUST be 'T.' or 'Q.' with '.' the return period.")
|
765
768
|
name_paths_FilledWD.append(names.name)
|
766
|
-
with wx.MessageDialog(self,
|
767
|
-
f"{len(paths_FilledWD)}
|
768
|
-
"Information",
|
769
|
+
with wx.MessageDialog(self,
|
770
|
+
f"{len(paths_FilledWD)} file(s) of interpolated free surface found in the folder : {name_paths_FilledWD}.",
|
771
|
+
"Information",
|
769
772
|
style=wx.OK | wx.ICON_INFORMATION) as dlg:
|
770
773
|
dlg.ShowModal()
|
771
|
-
#display_info_header(self.input_dx, self.input_nbxy, self.input_O, paths_FilledWD[0].with_suffix(".tif"))
|
772
774
|
update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
|
775
|
+
|
776
|
+
def OnCheckPond(self,e):
|
777
|
+
ponds = self._manager.get_ponderations()
|
778
|
+
if isinstance(ponds, pd.DataFrame):
|
779
|
+
logging.info(f"Plotting the coefficients graph.")
|
780
|
+
ponds.plot(kind='bar', color='gray', edgecolor='black')
|
781
|
+
plt.ylabel("Weighting coefficients [-]")
|
782
|
+
plt.xlabel("Return period [years]")
|
783
|
+
plt.grid(axis='y', linestyle='--', alpha=0.7)
|
784
|
+
plt.show()
|
785
|
+
else:
|
786
|
+
with wx.MessageDialog(self,
|
787
|
+
"No coefficients computed, because no return period found in the interpolated simulation folder. Try after loading gpu simulations",
|
788
|
+
"Checking",
|
789
|
+
style=wx.OK | wx.ICON_INFORMATION) as dlg:
|
790
|
+
dlg.ShowModal()
|
791
|
+
|
792
|
+
|
793
|
+
def OnMainDir(self, e):
|
794
|
+
"""Selects the main directory to be read."""
|
795
|
+
vanish_info_header(self.input_dx,self.input_nbxy,self.input_O)
|
796
|
+
|
797
|
+
with wx.DirDialog(self, "Choose the main directory containing the data (folders INPUT, TEMP and OUTPUT):",
|
798
|
+
style=wx.DD_DEFAULT_STYLE
|
799
|
+
) as dlg:
|
800
|
+
|
801
|
+
if dlg.ShowModal() == wx.ID_OK:
|
802
|
+
self._manager = Accept_Manager(dlg.GetPath())
|
803
|
+
self.maindir=dlg.GetPath()
|
804
|
+
folders = ["INPUT", "TEMP", "OUTPUT"]
|
805
|
+
|
806
|
+
if all(os.path.isdir(os.path.join(self.maindir, folder)) for folder in folders) == False:
|
807
|
+
logging.info("Folder not loaded (incorrect structure).")
|
808
|
+
wx.MessageBox(
|
809
|
+
f"Missing folders among INPUT, TEMP and OUTPUT. Please organize correctly this folder.",
|
810
|
+
"Error",
|
811
|
+
wx.OK | wx.ICON_ERROR
|
812
|
+
)
|
813
|
+
return
|
814
|
+
|
815
|
+
self._but_acceptability.Enable(True)
|
816
|
+
self._but_vulnerability.Enable(True)
|
817
|
+
self._but_creation.Enable(True)
|
818
|
+
self._but_checkfiles.Enable(True)
|
819
|
+
self._but_toggle_scen.Enable(True)
|
820
|
+
self._but_toggle_resamp.Enable(True)
|
821
|
+
self._but_upriverbed.Enable(True)
|
822
|
+
self._but_checkscenario.Enable(True)
|
823
|
+
self._but_checkpond.Enable(True)
|
824
|
+
self._but_checksim.Enable(True)
|
825
|
+
self._but_loadgpu.Enable(True)
|
826
|
+
|
827
|
+
self._listbox_scenario.Clear()
|
828
|
+
studyareas = self._manager.get_list_studyareas()
|
829
|
+
if len(studyareas) == 0 :
|
830
|
+
logging.info("Folder loaded but no study areas found in the folder (INPUT/STUDY_AREA). Please use the button to load hydraulic simulations in the manager.")
|
831
|
+
return
|
832
|
+
self._listbox_studyarea.Clear()
|
833
|
+
self._listbox_studyarea.InsertItems(studyareas, 0)
|
834
|
+
|
835
|
+
logging.info("All the files are present")
|
836
|
+
else:
|
837
|
+
return
|
838
|
+
|
839
|
+
def OnStudyArea(self, e):
|
840
|
+
""" Change the study area """
|
841
|
+
if self._manager is None:
|
842
|
+
return
|
843
|
+
vanish_info_header(self.input_dx,self.input_nbxy,self.input_O)
|
844
|
+
self._listbox_scenario.Clear()
|
845
|
+
study_area:str = self._manager.get_list_studyareas(with_suffix=True)[e.GetSelection()]
|
846
|
+
|
847
|
+
self._manager.change_studyarea(study_area)
|
848
|
+
|
849
|
+
sc = self._manager.get_list_scenarios()
|
850
|
+
if len(sc)!=0:
|
851
|
+
self._listbox_scenario.InsertItems(sc, 0)
|
852
|
+
else :
|
853
|
+
logging.error("No scenario available associated with this study area.")
|
854
|
+
|
855
|
+
if self.mapviewer is not None:
|
856
|
+
tmp_path = self._manager.IN_STUDY_AREA / study_area
|
857
|
+
|
858
|
+
from ..PyDraw import draw_type
|
859
|
+
if not tmp_path.stem in self.mapviewer.get_list_keys(drawing_type=draw_type.VECTORS):
|
860
|
+
self.mapviewer.add_object('vector', filename=str(tmp_path), id=tmp_path.stem)
|
861
|
+
self.mapviewer.Refresh()
|
773
862
|
|
863
|
+
def OnScenario(self, e):
|
864
|
+
""" Change the scenario """
|
865
|
+
if self._manager is None:
|
866
|
+
return
|
867
|
+
scenario = self._manager.get_list_scenarios()[e.GetSelection()]
|
868
|
+
|
869
|
+
self._manager.change_scenario(scenario)
|
870
|
+
create_INPUT_TEMP_OUTPUT_forScenario(self.maindir, self._manager.Study_area, self._manager.scenario, None)
|
871
|
+
update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
|
872
|
+
|
873
|
+
def OnCreation(self, e):
|
874
|
+
""" Create the database """
|
875
|
+
if self._manager is None:
|
876
|
+
return
|
877
|
+
|
878
|
+
dx,_,_,_,_,_ = update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
|
879
|
+
resolution = dx
|
880
|
+
if resolution == '':
|
881
|
+
wx.MessageBox(
|
882
|
+
f"There are no files in INTERP_WD lease, use first the buttons at the second line.",
|
883
|
+
"Attention",
|
884
|
+
wx.OK | wx.ICON_ERROR
|
885
|
+
)
|
886
|
+
else :
|
887
|
+
steps = list(self._steps_db.GetCheckedStrings())
|
888
|
+
steps = [int(cur.split('-')[1]) for cur in steps]
|
889
|
+
|
890
|
+
if len(steps) != 0:
|
891
|
+
|
892
|
+
wx.MessageBox(
|
893
|
+
f"The database will now be created, with a resolution of {dx}. This process may take some time, and the window may temporarily stop responding.",
|
894
|
+
"Information",
|
895
|
+
wx.OK | wx.ICON_INFORMATION
|
896
|
+
)
|
897
|
+
Base_data_creation(self._manager.main_dir,
|
898
|
+
Study_area=self._manager.Study_area,
|
899
|
+
number_procs=self._nb_process.GetValue(),
|
900
|
+
resolution=dx,
|
901
|
+
steps=steps)
|
902
|
+
|
903
|
+
wx.MessageBox(
|
904
|
+
"The database is created with the selected steps.",
|
905
|
+
"Information",
|
906
|
+
wx.OK | wx.ICON_INFORMATION
|
907
|
+
)
|
908
|
+
else :
|
909
|
+
wx.MessageBox(
|
910
|
+
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.",
|
911
|
+
"Information",
|
912
|
+
wx.OK | wx.ICON_INFORMATION
|
913
|
+
)
|
914
|
+
Base_data_creation(self._manager.main_dir,
|
915
|
+
Study_area=self._manager.Study_area,
|
916
|
+
number_procs=self._nb_process.GetValue(),
|
917
|
+
resolution=dx)
|
918
|
+
wx.MessageBox(
|
919
|
+
"The database is created for every steps.",
|
920
|
+
"Information",
|
921
|
+
wx.OK | wx.ICON_INFORMATION
|
922
|
+
)
|
923
|
+
|
774
924
|
def OnLoadingSimu(self,e):
|
775
925
|
""" Link between acceptability and simulations
|
776
|
-
-
|
777
|
-
-
|
926
|
+
-Load a hydraulic scenarios from the scenario manager
|
927
|
+
-Create scenario and study area if needed.
|
778
928
|
"""
|
779
|
-
|
780
|
-
dlg = wx.DirDialog(None, "Please select the scenario manager folder
|
929
|
+
|
930
|
+
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)
|
781
931
|
if dlg.ShowModal() == wx.ID_OK:
|
782
|
-
main_gpu = Path(dlg.GetPath())
|
783
|
-
|
784
|
-
|
932
|
+
main_gpu = Path(dlg.GetPath())
|
933
|
+
study_area = main_gpu.name
|
934
|
+
logging.info(f"Selected folder for GPU result such as the STUDY AREA is {study_area}")
|
935
|
+
dlg = wx.DirDialog(None, "Please select the scenarios folder (containing the 'simulations' folder) of the specific HYDRAULIC SCENARIO.", defaultPath=str(main_gpu), style=wx.DD_DEFAULT_STYLE)
|
785
936
|
if dlg.ShowModal() == wx.ID_OK:
|
786
|
-
|
787
|
-
|
937
|
+
scenario = Path(dlg.GetPath())
|
938
|
+
hydraulic_scen=scenario.joinpath("simulations")
|
939
|
+
scenario=scenario.name
|
940
|
+
logging.info(f"Selected hydraulic scenario : {scenario}")
|
941
|
+
create_INPUT_TEMP_OUTPUT_forScenario(self.maindir, study_area, scenario, main_gpu)
|
942
|
+
self._manager.change_studyarea(study_area+'.shp')
|
943
|
+
self._manager.change_scenario(scenario)
|
944
|
+
|
945
|
+
|
946
|
+
|
947
|
+
self._listbox_studyarea.Clear()
|
948
|
+
self._listbox_studyarea.InsertItems(self._manager.get_list_studyareas(), 0)
|
949
|
+
self._listbox_scenario.Clear()
|
950
|
+
self._listbox_scenario.InsertItems(self._manager.get_list_scenarios(), 0)
|
951
|
+
|
952
|
+
#Blue color of selection even if not directly clicked :
|
953
|
+
index_to_select = self._listbox_scenario.FindString(scenario)
|
954
|
+
if index_to_select != wx.NOT_FOUND:
|
955
|
+
self._listbox_scenario.SetSelection(index_to_select)
|
956
|
+
self._listbox_scenario.SetItemBackgroundColour(index_to_select, wx.Colour(0, 120, 215))
|
957
|
+
|
958
|
+
index_to_select = self._listbox_studyarea.FindString(study_area)
|
959
|
+
if index_to_select != wx.NOT_FOUND:
|
960
|
+
self._listbox_studyarea.SetSelection(index_to_select)
|
961
|
+
self._listbox_studyarea.SetItemBackgroundColour(index_to_select, wx.Colour(0, 120, 215))
|
962
|
+
self._listbox_studyarea.Refresh()
|
963
|
+
self._listbox_scenario.Refresh()
|
964
|
+
|
788
965
|
else:
|
789
966
|
logging.error('No hydraulic scenario selected.')
|
790
967
|
else:
|
791
968
|
logging.error('No folder found / selected. Please try again.')
|
792
|
-
|
793
969
|
self._check_listbox.Clear()
|
794
970
|
self.sims = {}
|
795
|
-
path_LastSteps = Path(self._manager.IN_SA_EXTRACTED)
|
796
|
-
empty_folder(path_LastSteps)
|
797
|
-
|
798
|
-
#self.datadir_gpu_sim = main-gpu
|
799
971
|
for subdir in hydraulic_scen.iterdir():
|
800
972
|
if subdir.is_dir() and subdir.name.startswith("sim_"):
|
801
|
-
self.sims[subdir.name] = subdir
|
973
|
+
self.sims[subdir.name] = subdir
|
802
974
|
else:
|
803
975
|
logging.info('No folder sim_ found / selected. Please try again.')
|
804
976
|
self.datadir_simulations = hydraulic_scen
|
805
977
|
self.file_paths = {Path(sim).name: Path(sim) for sim in sorted(self.sims.keys())}
|
806
978
|
self._check_listbox.Set(sorted(sim for sim in self.sims.keys()))
|
807
|
-
|
979
|
+
|
808
980
|
logging.info(f"GPU simulations loaded in the checkbox.\n\nPlease select the ones you want to interpolate and use the button 'Reading and interpolating free surface'.")
|
809
|
-
|
810
981
|
message = "GPU simulations loaded in the checkbox\n\nPlease select the ones you want to interpolate and use the button 'Reading and interpolating free surface'."
|
811
|
-
|
982
|
+
|
812
983
|
found_bath = search_for_modif_bath_and_copy(Path(main_gpu), Path(hydraulic_scen.parent), self._manager.IN_CH_SA_SC)
|
813
984
|
if found_bath :
|
814
985
|
message+= "\nIn addition, modification files for bathymetry (bath_) have been found in the gpu simulations, a copy has been made for a change in the vulnerability and DEM (see vuln_ and MNTmodifs_ in CHANGE_VULNE). Please edit them."
|
815
986
|
logging.info(f"Modification files for bathymetry (bath_) have been found in the gpu simulations, a copy has been made for a change in the vulnerability and DEM (see vuln_ and MNTmodifs_ in CHANGE_VULNE). Please edit them.")
|
816
|
-
|
817
987
|
self.gpu_bathy = hydraulic_scen.parent / "__bathymetry.tif"
|
818
988
|
self._but_extrinterp.Enable(True)
|
819
989
|
self._but_DEM.Enable(True)
|
820
|
-
with wx.MessageDialog(self,
|
821
|
-
message,
|
822
|
-
"Information",
|
990
|
+
with wx.MessageDialog(self,
|
991
|
+
message,
|
992
|
+
"Information",
|
823
993
|
style=wx.OK | wx.ICON_INFORMATION) as dlg:
|
824
994
|
dlg.ShowModal()
|
825
|
-
|
995
|
+
|
826
996
|
def OnDEM(self,e):
|
827
997
|
"""Import and create the inputs for the interpolation routine holes.exe (name including 'MNT_...' and 'MNT_..._with_mask'.
|
828
998
|
See function MTN_And_mask_creation_all"""
|
@@ -847,71 +1017,80 @@ class AcceptabilityGui(wx.Frame):
|
|
847
1017
|
else :
|
848
1018
|
logging.info("No update of DEM_FILES.")
|
849
1019
|
return
|
850
|
-
|
851
|
-
|
852
|
-
#DEM and masked DEM creation
|
1020
|
+
|
853
1021
|
with wx.FileDialog(self, "Please select the DEM file in .tif format (without modifications).", wildcard="TIFF files (*.tif)|*.tif",
|
854
1022
|
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as dlg:
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
dialog = wx.MessageDialog(None, f"Please modify the 'MNTmodifs_' files in INPUT\CHANGE_VULNE\... as in the hydraulic scenario you want to study.", "Confirmation", wx.YES_NO | wx.ICON_QUESTION)
|
861
|
-
dialog.SetYesNoLabels("Done, continue", "Not done, stop")
|
862
|
-
response = dialog.ShowModal()
|
863
|
-
|
864
|
-
if response == wx.ID_NO:
|
865
|
-
logging.info("No modifications, process stopped.")
|
866
|
-
else :
|
867
|
-
if os.path.exists(self._manager.IN_CH_SA_SC):
|
868
|
-
existence=False
|
869
|
-
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_")
|
870
|
-
if existence == True :
|
871
|
-
logging.info(f"Scenarios have been applied to DEM see {self._manager.IN_CH_SA_SC_MNT_tif}.")
|
872
|
-
self._manager.translate_vrt2tif(self._manager.IN_CH_SA_SC_MNT_VRT, self._manager.IN_CH_SA_SC_MNT_tif)
|
873
|
-
WA_mask = WolfArray(self._manager.IN_CH_SA_SC_MNT_tif.with_suffix('.tif'))
|
874
|
-
WA_mask.write_all(Path(self._manager.IN_SA_DEM / "MNT_loaded.bin"))
|
875
|
-
else :
|
876
|
-
logging.error(f"No MNTmodifs_ files in {self._manager.IN_CH_SA_SC}.")
|
877
|
-
else:
|
878
|
-
logging.error(f"Path {self._manager.IN_CH_SA_SC} does not exist.")
|
879
|
-
|
880
|
-
#self._manager.IN_CH_SA_SC_MNT_tif ou fn_mnt_cropped : ground + riverbed
|
881
|
-
fn_wherebuildings_buffer = self._manager.IN_CH_SA_SC_MNT_tif.parent / "buffer_wherebuilding.tif"
|
882
|
-
fn_mask = self._manager.IN_SA_DEM / "MNT_computed_with_mask.tif"
|
883
|
-
MTN_And_mask_creation_all(self.gpu_bathy, self._manager.IN_CH_SA_SC_MNT_tif.with_suffix('.tif'), fn_wherebuildings_buffer, fn_mask)
|
884
|
-
if fn_wherebuildings_buffer.exists():
|
885
|
-
fn_wherebuildings_buffer.unlink()
|
886
|
-
if fn_mask.exists():
|
887
|
-
fn_mask.unlink()
|
888
|
-
dlg = wx.MessageDialog(self,
|
889
|
-
"DEM files created in INPUT\WATER_DEPTH\...\DEM_FILES.",
|
890
|
-
"Success.",
|
891
|
-
wx.OK | wx.ICON_INFORMATION)
|
892
|
-
dlg.ShowModal()
|
893
|
-
dlg.Destroy()
|
894
|
-
return
|
895
|
-
|
896
|
-
|
1023
|
+
result = dlg.ShowModal()
|
1024
|
+
if result != wx.ID_OK:
|
1025
|
+
return
|
897
1026
|
|
1027
|
+
path_DEM_base = dlg.GetPath()
|
1028
|
+
logging.info("DEM file selected.")
|
1029
|
+
|
1030
|
+
#DEM and masked DEM creation
|
1031
|
+
path = self._manager.IN_CH_SA_SC
|
1032
|
+
names_inCHVUL_MNTmodifs = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) and f.startswith("MNTmodifs_")]
|
1033
|
+
#path_MNT_computed is the path to the DEM with the MNTmodifs if exist, or the given true DEM if not
|
1034
|
+
path_MNT_computed = Path(path_DEM_base)
|
1035
|
+
if len(names_inCHVUL_MNTmodifs) !=0:
|
1036
|
+
path_MNT_computed = Path(self._manager.IN_CH_SA_SC_MNT_tif.with_suffix('.tif'))
|
1037
|
+
dialog = wx.MessageDialog(None, f"Please modify the 'MNTmodifs_' files in INPUT\CHANGE_VULNE\... as in the hydraulic scenario you want to study. They are: {names_inCHVUL_MNTmodifs}", "Confirmation", wx.YES_NO | wx.ICON_QUESTION)
|
1038
|
+
dialog.SetYesNoLabels("Done, continue", "Not done, stop")
|
1039
|
+
response = dialog.ShowModal()
|
1040
|
+
|
1041
|
+
if response == wx.ID_NO:
|
1042
|
+
logging.info("No modifications done in MNTmodifs_ files, process stopped.")
|
1043
|
+
return
|
1044
|
+
|
1045
|
+
#else :
|
1046
|
+
if os.path.exists(self._manager.IN_CH_SA_SC):
|
1047
|
+
existence=False
|
1048
|
+
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_")
|
1049
|
+
if existence :
|
1050
|
+
self._manager.translate_vrt2tif(self._manager.IN_CH_SA_SC_MNT_VRT, self._manager.IN_CH_SA_SC_MNT_tif)
|
1051
|
+
logging.info(f"Scenarios have been applied to DEM see {self._manager.IN_CH_SA_SC_MNT_tif}.tif.")
|
1052
|
+
WA_mask = WolfArray(self._manager.IN_CH_SA_SC_MNT_tif.with_suffix('.tif'))
|
1053
|
+
WA_mask.write_all(Path(self._manager.IN_SA_DEM / "MNT_loaded.bin"))
|
1054
|
+
else :
|
1055
|
+
logging.info(f"No MNTmodifs_ files in {self._manager.IN_CH_SA_SC}. The given file {path_DEM_base} has not been modified")
|
1056
|
+
WA_mask = WolfArray(path_DEM_base)
|
1057
|
+
WA_mask.write_all(Path(self._manager.IN_SA_DEM / "MNT_loaded.bin"))
|
1058
|
+
else:
|
1059
|
+
logging.error(f"Path {self._manager.IN_CH_SA_SC} does not exist.")
|
1060
|
+
|
1061
|
+
#self._manager.IN_CH_SA_SC_MNT_tif ou fn_mnt_cropped : ground + riverbed
|
1062
|
+
fn_wherebuildings_buffer = self._manager.IN_CH_SA_SC / "buffer_wherebuilding.tif"
|
1063
|
+
fn_mask = self._manager.IN_SA_DEM / "MNT_computed_with_mask.tif"
|
1064
|
+
MTN_And_mask_creation_all(self.gpu_bathy, path_MNT_computed, fn_wherebuildings_buffer, fn_mask)
|
1065
|
+
if fn_wherebuildings_buffer.exists():
|
1066
|
+
fn_wherebuildings_buffer.unlink()
|
1067
|
+
if fn_mask.exists():
|
1068
|
+
fn_mask.unlink()
|
1069
|
+
dlg = wx.MessageDialog(self,
|
1070
|
+
"DEM files created in INPUT\WATER_DEPTH\...\DEM_FILES.",
|
1071
|
+
"Success.",
|
1072
|
+
wx.OK | wx.ICON_INFORMATION)
|
1073
|
+
dlg.ShowModal()
|
1074
|
+
dlg.Destroy()
|
1075
|
+
return
|
1076
|
+
|
898
1077
|
def OnInterpolation(self,e):
|
899
|
-
"""Interpolates the last extracted time steps present in LAST_STEP_EXTRACTED using the fast marching
|
1078
|
+
"""Interpolates the last extracted time steps present in LAST_STEP_EXTRACTED using the fast marching
|
900
1079
|
interpolation routine holes.exe, by creating a batch file
|
901
1080
|
while performing multiple checks on the required input files."""
|
902
1081
|
if not hasattr(self, 'file_paths'):
|
903
|
-
with wx.MessageDialog(self,
|
904
|
-
f"Please, first load gpu simulations via the previous button.",
|
905
|
-
"Attention",
|
1082
|
+
with wx.MessageDialog(self,
|
1083
|
+
f"Please, first load gpu simulations via the previous button.",
|
1084
|
+
"Attention",
|
906
1085
|
style=wx.OK | wx.ICON_ERROR) as dlg:
|
907
1086
|
dlg.ShowModal()
|
908
1087
|
return
|
909
|
-
|
1088
|
+
|
910
1089
|
checked_indices = self._check_listbox.GetCheckedItems()
|
911
1090
|
checked_items = [self._check_listbox.GetString(index) for index in checked_indices]
|
912
1091
|
selected_paths = [self.file_paths[item] for item in checked_items]
|
913
1092
|
path_simulations = self.datadir_simulations
|
914
|
-
|
1093
|
+
|
915
1094
|
path_LastSteps = Path(self._manager.IN_SA_EXTRACTED)
|
916
1095
|
fn_write = None
|
917
1096
|
dx,dy,nbx,nby,X,Y = False, False, False, False, False, False
|
@@ -931,8 +1110,8 @@ class AcceptabilityGui(wx.Frame):
|
|
931
1110
|
else:
|
932
1111
|
logging.info('No folder found / selected. Please try again...')
|
933
1112
|
else:
|
934
|
-
logging.error('No simulation selected! Please select some in the checkbox.')
|
935
|
-
|
1113
|
+
logging.error('No simulation selected! Please select some in the checkbox.')
|
1114
|
+
|
936
1115
|
C = None
|
937
1116
|
D = None
|
938
1117
|
for file in os.listdir(Path(self._manager.IN_SA_DEM)):
|
@@ -941,44 +1120,44 @@ class AcceptabilityGui(wx.Frame):
|
|
941
1120
|
if "mask" not in file:
|
942
1121
|
D = file_path
|
943
1122
|
else:
|
944
|
-
C = file_path
|
1123
|
+
C = file_path
|
945
1124
|
if D == None:
|
946
1125
|
logging.info("DEM (.bin) not found in DEM_FILES. The file must begins by 'MNT_' and CANNOT include the word 'mask'")
|
947
|
-
with wx.MessageDialog(self,
|
948
|
-
f"DEM (.bin) not found in DEM_FILES. The file must begins by 'MNT_' and CANNOT include the word 'mask'",
|
949
|
-
"Missing file",
|
1126
|
+
with wx.MessageDialog(self,
|
1127
|
+
f"DEM (.bin) not found in DEM_FILES. The file must begins by 'MNT_' and CANNOT include the word 'mask'",
|
1128
|
+
"Missing file",
|
950
1129
|
style=wx.OK | wx.ICON_INFORMATION) as dlg:
|
951
1130
|
dlg.ShowModal()
|
952
1131
|
return
|
953
|
-
|
1132
|
+
|
954
1133
|
if C == None:
|
955
1134
|
logging.info("DEM mask (.bin) not found in DEM_FILES. The file must begins by 'MNT_' and MUST include the word 'mask'")
|
956
|
-
with wx.MessageDialog(self,
|
957
|
-
f"DEM mask (.bin) not found in DEM_FILES. The file must begins by 'MNT_' and MUST include the word 'mask'",
|
958
|
-
"Missing file",
|
1135
|
+
with wx.MessageDialog(self,
|
1136
|
+
f"DEM mask (.bin) not found in DEM_FILES. The file must begins by 'MNT_' and MUST include the word 'mask'",
|
1137
|
+
"Missing file",
|
959
1138
|
style=wx.OK | wx.ICON_INFORMATION) as dlg:
|
960
1139
|
dlg.ShowModal()
|
961
1140
|
return
|
962
|
-
|
1141
|
+
|
963
1142
|
if not get_header_comparison([fn_write.with_suffix(".bin"), C, D]):
|
964
1143
|
logging.info("Files in DEM_FILES do not have the same properties as the simulations files. Please, fix them.")
|
965
|
-
with wx.MessageDialog(self,
|
966
|
-
f"Files in DEM_FILES do not have the same properties as the simulations files. Please, fix them.",
|
967
|
-
"Error in DEM_FILES files",
|
1144
|
+
with wx.MessageDialog(self,
|
1145
|
+
f"Files in DEM_FILES do not have the same properties as the simulations files. Please, fix them.",
|
1146
|
+
"Error in DEM_FILES files",
|
968
1147
|
style=wx.OK | wx.ICON_INFORMATION) as dlg:
|
969
1148
|
dlg.ShowModal()
|
970
1149
|
return
|
971
|
-
|
1150
|
+
|
972
1151
|
checked_names = self._check_listbox.GetCheckedStrings()
|
973
1152
|
if not checked_names:
|
974
1153
|
logging.info("No items selected. Adding all paths.")
|
975
|
-
checked_paths = list(self.file_paths.values())
|
1154
|
+
checked_paths = list(self.file_paths.values())
|
976
1155
|
message_info = "No simulations were checked in the box; so the computations will consider all of them. The interpolation of the given free surface will begin when you press OK, please wait."
|
977
1156
|
else:
|
978
1157
|
logging.info("Adding only the selected simulations.")
|
979
1158
|
checked_paths = [self.file_paths[name] for name in checked_names]
|
980
|
-
message_info = "The interpolation of the given free surface will begin (for the selected simulation(s))
|
981
|
-
|
1159
|
+
message_info = "The interpolation of the given free surface will begin (for the selected simulation(s)), please wait."
|
1160
|
+
|
982
1161
|
if len(self.file_paths) == 0 :
|
983
1162
|
with wx.MessageDialog(self, f"No files in EXTRACTED_LAST_STEP_WD. Please provide some or use the 'Load gpu simulation' button.",
|
984
1163
|
"OK", wx.OK | wx.ICON_INFORMATION) as dlg:
|
@@ -986,15 +1165,15 @@ class AcceptabilityGui(wx.Frame):
|
|
986
1165
|
else :
|
987
1166
|
path_Interp = Path(self._manager.IN_SA_INTERP)
|
988
1167
|
path_bat_file = os.path.join(self._manager.IN_SCEN_DIR, "process_files.bat")
|
989
|
-
|
1168
|
+
|
990
1169
|
if os.path.exists(path_bat_file):
|
991
1170
|
logging.info(f"The file {path_bat_file} already exists and will be replaced.")
|
992
1171
|
os.remove(path_bat_file)
|
993
|
-
path_code = os.path.join(self._manager.IN_WATER_DEPTH, "holes.exe")
|
994
|
-
|
1172
|
+
path_code = os.path.join(self._manager.IN_WATER_DEPTH, "holes.exe")
|
1173
|
+
|
995
1174
|
A=[]
|
996
1175
|
for path in checked_paths:
|
997
|
-
parts = path.name.split("sim_")
|
1176
|
+
parts = path.name.split("sim_")
|
998
1177
|
A.extend([os.path.join(path_LastSteps, g) for g in os.listdir(path_LastSteps) if g.endswith(f"{parts[1]}.bin")])
|
999
1178
|
B = [os.path.join(path_Interp, os.path.splitext(os.path.basename(f))[0]) for f in A]
|
1000
1179
|
if not A or not B or not C or not D:
|
@@ -1007,20 +1186,18 @@ class AcceptabilityGui(wx.Frame):
|
|
1007
1186
|
line = f'"{path_code}" filling in="{a}" out="{b}" mask="{C}" dem="{D} avoid_last=1"\n'
|
1008
1187
|
bat_file.write(line)
|
1009
1188
|
logging.info(message_info)
|
1010
|
-
|
1011
|
-
"Redirecting", wx.OK | wx.ICON_INFORMATION) as dlg:
|
1012
|
-
dlg.ShowModal()
|
1189
|
+
|
1013
1190
|
empty_folder(self._manager.IN_SA_INTERP)
|
1014
1191
|
path_bat_file = os.path.join(self._manager.IN_SCEN_DIR, "process_files.bat")
|
1015
1192
|
subprocess.run([path_bat_file], check=True)
|
1016
|
-
|
1193
|
+
|
1017
1194
|
renamed_files = []
|
1018
1195
|
path_fichier=self._manager.IN_SA_INTERP
|
1019
1196
|
for file in path_fichier.glob("*.tif"):
|
1020
|
-
if "_h" in file.name:
|
1197
|
+
if "_h" in file.name:
|
1021
1198
|
new_name = file.stem.split("_h")[0].replace(".bin", "") + ".tif"
|
1022
1199
|
file.rename(file.with_name(new_name))
|
1023
|
-
renamed_files.append(new_name)
|
1200
|
+
renamed_files.append(new_name)
|
1024
1201
|
#deleting the other
|
1025
1202
|
for file in path_fichier.glob("*.tif"):
|
1026
1203
|
if "_combl" in file.name or file.name not in renamed_files:
|
@@ -1030,229 +1207,43 @@ class AcceptabilityGui(wx.Frame):
|
|
1030
1207
|
"Redirecting", wx.OK | wx.ICON_INFORMATION) as dlg:
|
1031
1208
|
dlg.ShowModal()
|
1032
1209
|
update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
def OnSAcreation(self,e):
|
1037
|
-
"""Creates the shapefile for the study area based on the extent of the provided simulations. A pre-existing shapefile is required;
|
1038
|
-
the menu will display existing ones and the one to be replaced. A placeholder shapefile must be placed if this is the first run."""
|
1039
|
-
update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
|
1040
|
-
logging.info("The study area shapefile will be generated in the INPUT STUDY_AREA, based on the simulations present INTERP_WD, whose properties are displayed on the left.")
|
1041
|
-
with wx.MessageDialog(self, f"The study area shapefile will be generated in the INPUT STUDY_AREA, based on the simulations present INTERP_WD, whose properties are displayed on the left.",
|
1042
|
-
"SA creation", wx.OK | wx.ICON_INFORMATION) as dlg:
|
1043
|
-
dlg.ShowModal()
|
1044
|
-
path_fichier=self._manager.IN_SA_INTERP
|
1045
|
-
tif_files = [f for f in os.listdir(path_fichier) if f.lower().endswith('.tif')]
|
1046
|
-
tif_list_fn = [os.path.join(path_fichier, tif_file) for tif_file in tif_files]
|
1047
|
-
if tif_files:
|
1048
|
-
if get_header_comparison(tif_list_fn) :
|
1049
|
-
display_info_header(self.input_dx, self.input_nbxy, self.input_O, tif_list_fn[0])
|
1050
|
-
else:
|
1051
|
-
logging.error("The interpolated files have different headers. Please fix it.")
|
1052
|
-
|
1053
|
-
#dlg = wx.TextEntryDialog(None, "What is the name of the study area (please, use underscore '_' for space if required, for example Bassin_Vesdre):", "Input", "")
|
1054
|
-
#if dlg.ShowModal() == wx.ID_OK:
|
1055
|
-
# name_shp = dlg.GetValue()
|
1056
|
-
#dlg.Destroy()
|
1057
|
-
|
1058
|
-
shp_files = [f for f in os.listdir(Path(self._manager.IN_STUDY_AREA)) if f.endswith('.shp')]
|
1059
|
-
if shp_files:
|
1060
|
-
dlg = wx.MultiChoiceDialog(None, "Which Study Area shapefile to replace?", "Choose Shapefile", shp_files)
|
1061
|
-
if dlg.ShowModal() == wx.ID_OK:
|
1062
|
-
selections = dlg.GetSelections()
|
1063
|
-
if selections:
|
1064
|
-
name_shp = shp_files[selections[0]]
|
1065
|
-
name_shp = Path(self._manager.IN_STUDY_AREA) / name_shp
|
1066
|
-
create_shapefile_from_prop_tif(tif_list_fn[0], name_shp)
|
1067
|
-
logging.info("Study area file created.")
|
1068
|
-
with wx.MessageDialog(self, f"Study area file created.",
|
1069
|
-
"Information", wx.OK | wx.ICON_INFORMATION) as dlg:
|
1070
|
-
dlg.ShowModal()
|
1071
|
-
|
1072
|
-
else:
|
1073
|
-
logging.info("No study area files to be replaced.")
|
1074
|
-
with wx.MessageDialog(self, f"There is no study area shapefile to replace. It must exist at least one, that will be replaced at this stage.",
|
1075
|
-
"Information", wx.OK | wx.ICON_INFORMATION) as dlg:
|
1076
|
-
dlg.ShowModal()
|
1077
|
-
else :
|
1078
|
-
logging.info("No interpolated files.")
|
1079
|
-
with wx.MessageDialog(self, f"There are no files in INTERP_WD, please generate them via the previous buttons line.",
|
1080
|
-
"Attention", wx.OK | wx.ICON_ERROR) as dlg:
|
1081
|
-
dlg.ShowModal()
|
1082
|
-
|
1083
|
-
def OnMainDir(self, e):
|
1084
|
-
"""Selects the main directory to be read."""
|
1085
|
-
vanish_info_header(self.input_dx,self.input_nbxy,self.input_O)
|
1086
|
-
with wx.DirDialog(self, "Choose the main directory containing the data (folders INPUT, TEMP and OUTPUT):",
|
1087
|
-
style=wx.DD_DEFAULT_STYLE
|
1088
|
-
) as dlg:
|
1089
|
-
|
1090
|
-
if dlg.ShowModal() == wx.ID_OK:
|
1091
|
-
self._manager = Accept_Manager(dlg.GetPath())
|
1092
|
-
|
1093
|
-
self._listbox_studyarea.Clear()
|
1094
|
-
self._listbox_studyarea.InsertItems(self._manager.get_list_studyareas(), 0)
|
1095
|
-
|
1096
|
-
self._listbox_scenario.Clear()
|
1097
|
-
|
1098
|
-
ret = self._manager.check_files()
|
1099
|
-
|
1100
|
-
if ret == "":
|
1101
|
-
logging.info("All the files are present")
|
1102
|
-
self._but_acceptability.Enable(True)
|
1103
|
-
self._but_vulnerability.Enable(True)
|
1104
|
-
self._but_creation.Enable(True)
|
1105
|
-
self._but_checkfiles.Enable(True)
|
1106
|
-
self._but_loadgpu.Enable(True)
|
1107
|
-
self._but_toggle_scen.Enable(True)
|
1108
|
-
self._but_toggle_resamp.Enable(True)
|
1109
|
-
self._but_upriverbed.Enable(True)
|
1110
|
-
self._but_checkscenario.Enable(True)
|
1111
|
-
self._but_sacreation.Enable(True)
|
1112
|
-
self._but_checksim.Enable(True)
|
1113
|
-
|
1114
|
-
|
1115
|
-
else:
|
1116
|
-
logging.error(f"Missing files: {ret}")
|
1117
|
-
with wx.MessageDialog(self, f"Missing files: \n{ret}", "Error", wx.OK | wx.ICON_ERROR) as dlg:
|
1118
|
-
dlg.ShowModal()
|
1119
|
-
|
1120
|
-
else:
|
1121
|
-
return
|
1122
|
-
|
1123
|
-
def OnStudyArea(self, e):
|
1124
|
-
""" Change the study area """
|
1125
|
-
if self._manager is None:
|
1126
|
-
return
|
1127
|
-
vanish_info_header(self.input_dx,self.input_nbxy,self.input_O)
|
1128
|
-
study_area:str = self._manager.get_list_studyareas(with_suffix=True)[e.GetSelection()]
|
1129
|
-
self._manager.change_studyarea(study_area)
|
1130
|
-
|
1131
|
-
self._listbox_scenario.Clear()
|
1132
|
-
sc = self._manager.get_list_scenarios()
|
1133
|
-
self._listbox_scenario.InsertItems(sc, 0)
|
1134
|
-
|
1135
|
-
if self.mapviewer is not None:
|
1136
|
-
tmp_path = self._manager.IN_STUDY_AREA / study_area
|
1137
|
-
|
1138
|
-
from ..PyDraw import draw_type
|
1139
|
-
if not tmp_path.stem in self.mapviewer.get_list_keys(drawing_type=draw_type.VECTORS):
|
1140
|
-
self.mapviewer.add_object('vector', filename=str(tmp_path), id=tmp_path.stem)
|
1141
|
-
self.mapviewer.Refresh()
|
1142
|
-
|
1143
|
-
def OnScenario(self, e):
|
1144
|
-
""" Change the scenario """
|
1145
|
-
if self._manager is None:
|
1146
|
-
return
|
1147
|
-
|
1148
|
-
scenario = self._manager.get_list_scenarios()[e.GetSelection()]
|
1149
|
-
self._manager.change_scenario(scenario)
|
1150
|
-
|
1151
|
-
self._listbox_returnperiods.Clear()
|
1152
|
-
rt = self._manager.get_return_periods()
|
1153
|
-
self._listbox_sims.Clear()
|
1154
|
-
if len(rt) != 0 :
|
1155
|
-
self._listbox_returnperiods.InsertItems([str(crt) for crt in rt],0)
|
1156
|
-
self._listbox_sims.Clear()
|
1157
|
-
sims = [str(self._manager.get_filepath_for_return_period(currt).name) for currt in rt]
|
1158
|
-
self._listbox_sims.InsertItems(sims, 0)
|
1159
|
-
ponds = self._manager.get_ponderations()
|
1160
|
-
if isinstance(ponds, pd.DataFrame):
|
1161
|
-
self._axes.clear()
|
1162
|
-
ponds.plot(ax=self._axes, kind='bar', color='gray', edgecolor='black')
|
1163
|
-
self._axes.set_ylabel("Weighting coefficients [-]")
|
1164
|
-
self._axes.set_xlabel("Return period [years]")
|
1165
|
-
self._axes.grid(axis='y', linestyle='--', alpha=0.7)
|
1166
|
-
self._canvas.draw()
|
1167
|
-
else:
|
1168
|
-
self._axes.clear()
|
1169
|
-
self._axes.set_ylabel("Weighting coefficients [-]")
|
1170
|
-
self._axes.set_xlabel("Return period [years]")
|
1171
|
-
self._axes.grid(axis='y', linestyle='--', alpha=0.7)
|
1172
|
-
self._canvas.draw()
|
1173
|
-
|
1174
|
-
update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
|
1175
|
-
|
1176
|
-
|
1177
|
-
def OnCreation(self, e):
|
1178
|
-
""" Create the database """
|
1179
|
-
if self._manager is None:
|
1180
|
-
return
|
1181
|
-
|
1182
|
-
dx,_,_,_,_,_ = update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
|
1183
|
-
resolution = dx
|
1184
|
-
if resolution == '':
|
1185
|
-
wx.MessageBox(
|
1186
|
-
f"There are no files in INTERP_WD lease, use first the buttons at the second line.",
|
1187
|
-
"Attention",
|
1188
|
-
wx.OK | wx.ICON_ERROR
|
1189
|
-
)
|
1190
|
-
else :
|
1191
|
-
steps = list(self._steps_db.GetCheckedStrings())
|
1192
|
-
steps = [int(cur.split('-')[1]) for cur in steps]
|
1193
|
-
|
1194
|
-
if len(steps) != 0:
|
1195
|
-
|
1196
|
-
wx.MessageBox(
|
1197
|
-
f"The database will now be created, with a resolution of {dx}. This process may take some time, and the window may temporarily stop responding.",
|
1198
|
-
"Information",
|
1199
|
-
wx.OK | wx.ICON_INFORMATION
|
1200
|
-
)
|
1201
|
-
Base_data_creation(self._manager.main_dir, number_procs=self._nb_process.GetValue(), resolution=dx, steps=steps)
|
1202
|
-
|
1203
|
-
wx.MessageBox(
|
1204
|
-
"The database is created with the selected steps.",
|
1205
|
-
"Information",
|
1206
|
-
wx.OK | wx.ICON_INFORMATION
|
1207
|
-
)
|
1208
|
-
else :
|
1209
|
-
wx.MessageBox(
|
1210
|
-
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.",
|
1211
|
-
"Information",
|
1212
|
-
wx.OK | wx.ICON_INFORMATION
|
1213
|
-
)
|
1214
|
-
Base_data_creation(self._manager.main_dir, number_procs=self._nb_process.GetValue(), resolution=dx)
|
1215
|
-
wx.MessageBox(
|
1216
|
-
"The database is created for every steps.",
|
1217
|
-
"Information",
|
1218
|
-
wx.OK | wx.ICON_INFORMATION
|
1219
|
-
)
|
1210
|
+
|
1220
1211
|
def OnToggle(self,e):
|
1221
1212
|
"""Creates a toggle button to be activated if the scenarios vuln_ have to be taken into account."""
|
1222
1213
|
self.toggle_state = False
|
1223
1214
|
if self._but_toggle_scen.GetValue():
|
1224
1215
|
logging.info("Activating the scenario button.")
|
1225
|
-
self._but_toggle_scen.SetBackgroundColour(wx.Colour(175, 175, 175))
|
1216
|
+
self._but_toggle_scen.SetBackgroundColour(wx.Colour(175, 175, 175))
|
1226
1217
|
self._but_toggle_scen_state = True
|
1227
1218
|
tif_files = [file for file in Path(self._manager.IN_CH_SA_SC).glob("*.tif") if file.name.startswith("vuln_")]
|
1228
1219
|
if not tif_files:
|
1229
1220
|
wx.MessageBox(
|
1230
|
-
"The scenario button cannot be activated because there is no change in vulnerability 'vuln_' in CHANGE_VULNE. Please reload the simulations containing 'bath_' files via 'Load
|
1221
|
+
"The scenario button cannot be activated because there is no change in vulnerability 'vuln_' in CHANGE_VULNE. Please reload the simulations containing 'bath_' files via 'Load new hydraulic scenario' and edit it, or directly introduce your 'vuln_' files.",
|
1231
1222
|
"Information",
|
1232
1223
|
wx.OK | wx.ICON_INFORMATION
|
1233
1224
|
)
|
1234
1225
|
logging.info("Desactivating the scenario button.")
|
1235
|
-
self._but_toggle_scen.SetValue(False)
|
1236
|
-
self._but_toggle_scen.SetBackgroundColour(wx.NullColour)
|
1226
|
+
self._but_toggle_scen.SetValue(False)
|
1227
|
+
self._but_toggle_scen.SetBackgroundColour(wx.NullColour)
|
1237
1228
|
self._but_toggle_scen_state = False
|
1238
1229
|
else :
|
1239
1230
|
self.toggle_state = True
|
1240
1231
|
else:
|
1241
|
-
self._but_toggle_scen.SetBackgroundColour(wx.NullColour)
|
1232
|
+
self._but_toggle_scen.SetBackgroundColour(wx.NullColour)
|
1242
1233
|
self.toggle_state = False
|
1243
1234
|
logging.info("Desactivating the scenario button.")
|
1244
|
-
|
1235
|
+
|
1245
1236
|
def OnToggleResampling(self,e):
|
1246
1237
|
"""Creates a toggle button for the acceptability resampling to be activated."""
|
1247
1238
|
self.toggle_resamp_state = False
|
1248
1239
|
toggle = self._but_toggle_resamp
|
1249
|
-
if toggle.GetValue():
|
1250
|
-
self._but_toggle_resamp.SetBackgroundColour(wx.Colour(175, 175, 175))
|
1240
|
+
if toggle.GetValue():
|
1241
|
+
self._but_toggle_resamp.SetBackgroundColour(wx.Colour(175, 175, 175))
|
1251
1242
|
self.toggle_resamp_state = True
|
1252
1243
|
logging.info("Resampling activated")
|
1253
1244
|
current_res = self._but_resampling.GetValue()
|
1254
1245
|
resolution = self.input_dx.GetLabel()
|
1255
|
-
if resolution != '':
|
1246
|
+
if resolution != '':
|
1256
1247
|
values = resolution.strip("()").split(",")
|
1257
1248
|
dx = float(values[0])
|
1258
1249
|
#selection of size
|
@@ -1261,49 +1252,48 @@ class AcceptabilityGui(wx.Frame):
|
|
1261
1252
|
"The resampling size cannot be inferior to the resolution. Please select another resampling size.",
|
1262
1253
|
"Attention",
|
1263
1254
|
wx.OK | wx.ICON_ERROR
|
1264
|
-
)
|
1255
|
+
)
|
1265
1256
|
self.toggle_resamp_state = False
|
1266
|
-
self._but_toggle_resamp.SetValue(False)
|
1267
|
-
self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
|
1257
|
+
self._but_toggle_resamp.SetValue(False)
|
1258
|
+
self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
|
1268
1259
|
logging.info("Resampling disactivated because of a bad resampling size.")
|
1269
1260
|
else :
|
1270
1261
|
logging.info(f"Allowed resampling value : {current_res}[m].")
|
1271
1262
|
else:
|
1272
1263
|
self.toggle_resamp_state = False
|
1273
|
-
self._but_toggle_resamp.SetValue(False)
|
1274
|
-
self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
|
1264
|
+
self._but_toggle_resamp.SetValue(False)
|
1265
|
+
self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
|
1275
1266
|
logging.info("No simulations in INTERP_WD.")
|
1276
1267
|
|
1277
|
-
|
1268
|
+
|
1278
1269
|
else:
|
1279
1270
|
self.toggle_resamp_state = False
|
1280
|
-
self._but_toggle_resamp.SetValue(False)
|
1281
|
-
self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
|
1271
|
+
self._but_toggle_resamp.SetValue(False)
|
1272
|
+
self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
|
1282
1273
|
logging.info("Resampling disactivated")
|
1283
|
-
|
1274
|
+
|
1284
1275
|
def OnCheckScenario(self,e):
|
1285
1276
|
"""Checks if scenarios exist in CHANGE_VULNE."""
|
1286
|
-
tif_files =
|
1277
|
+
tif_files = self._manager.get_modifiedrasters()
|
1287
1278
|
logging.info("checking the scenarios for vulnerability and acceptability.")
|
1288
1279
|
if not tif_files:
|
1289
1280
|
wx.MessageBox(
|
1290
|
-
"No files 'vuln_' found in CHANGE_VULNE.",
|
1281
|
+
"No files 'vuln_' or 'MNTmodifs_' found in CHANGE_VULNE.",
|
1291
1282
|
"Information",
|
1292
1283
|
wx.OK | wx.ICON_INFORMATION
|
1293
1284
|
)
|
1294
|
-
else :
|
1285
|
+
else :
|
1295
1286
|
wx.MessageBox(
|
1296
|
-
f"There exist vuln_ file(s) in CHANGE_VULNE
|
1297
|
-
"Information", wx.OK | wx.ICON_INFORMATION)
|
1298
|
-
|
1287
|
+
f"There exist vuln_ file(s) in CHANGE_VULNE:\n {', '.join([tif_file for tif_file in tif_files])}",
|
1288
|
+
"Information", wx.OK | wx.ICON_INFORMATION)
|
1289
|
+
|
1299
1290
|
def OnVulnerability(self, e):
|
1300
1291
|
""" Run the vulnerability """
|
1301
|
-
|
1302
1292
|
if self._manager is None:
|
1303
1293
|
return
|
1304
1294
|
path = [self._manager.OUT_VULN]
|
1305
1295
|
steps = list(self._steps_vulnerability.GetCheckedStrings())
|
1306
|
-
steps = [int(cur.split('-')[1]) for cur in steps]
|
1296
|
+
steps = [int(cur.split('-')[1]) for cur in steps]
|
1307
1297
|
resolution,_,_,_,_,_ =update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
|
1308
1298
|
if resolution == '':
|
1309
1299
|
wx.MessageBox(
|
@@ -1312,7 +1302,7 @@ class AcceptabilityGui(wx.Frame):
|
|
1312
1302
|
wx.OK | wx.ICON_ERROR
|
1313
1303
|
)
|
1314
1304
|
else :
|
1315
|
-
message_supp = "."
|
1305
|
+
message_supp = "."
|
1316
1306
|
if len(steps) == 0:
|
1317
1307
|
steps = [1,10,11,2,3]
|
1318
1308
|
if self.toggle_state == True :
|
@@ -1324,13 +1314,13 @@ class AcceptabilityGui(wx.Frame):
|
|
1324
1314
|
steps=[4]
|
1325
1315
|
else :
|
1326
1316
|
logging.info("Attention - The manager computes also Vulnerability_baseline, as Vulnerability_scenario needs it as input.")
|
1327
|
-
path = [self._manager.OUT_VULN_Stif]
|
1317
|
+
path = [self._manager.OUT_VULN_Stif]
|
1328
1318
|
dialog = wx.MessageDialog(None, f"Please modify the 'vuln_' files in INPUT\CHANGE_VULNE\... as desired. Default value set to one. ", "Confirmation", wx.YES_NO | wx.ICON_QUESTION)
|
1329
1319
|
dialog.SetYesNoLabels("Done, continue", "Not done, stop")
|
1330
1320
|
response = dialog.ShowModal()
|
1331
1321
|
if response == wx.ID_NO:
|
1332
1322
|
return
|
1333
|
-
|
1323
|
+
|
1334
1324
|
logging.info("No steps selected. By default every steps will be performed" + message_supp)
|
1335
1325
|
Vulnerability(str(self._manager.main_dir),
|
1336
1326
|
scenario=str(self._manager.scenario),
|
@@ -1341,7 +1331,7 @@ class AcceptabilityGui(wx.Frame):
|
|
1341
1331
|
"Vulnerability computed with every steps" + message_supp,
|
1342
1332
|
"Information",
|
1343
1333
|
wx.OK | wx.ICON_INFORMATION
|
1344
|
-
)
|
1334
|
+
)
|
1345
1335
|
else :
|
1346
1336
|
if self.toggle_state == True :
|
1347
1337
|
steps.append(4)
|
@@ -1352,14 +1342,14 @@ class AcceptabilityGui(wx.Frame):
|
|
1352
1342
|
steps=[4]
|
1353
1343
|
else :
|
1354
1344
|
logging.info("Attention - The manager computes also Vulnerability_baseline, as Vulnerability_scenario needs it as input.")
|
1355
|
-
|
1356
|
-
path = [self._manager.OUT_VULN_Stif]
|
1345
|
+
|
1346
|
+
path = [self._manager.OUT_VULN_Stif]
|
1357
1347
|
dialog = wx.MessageDialog(None, f"Please modify the 'vuln_' files in INPUT\CHANGE_VULNE\... as desired. Default value set to one. ", "Confirmation", wx.YES_NO | wx.ICON_QUESTION)
|
1358
1348
|
dialog.SetYesNoLabels("Done, continue", "Not done, stop")
|
1359
1349
|
response = dialog.ShowModal()
|
1360
1350
|
if response == wx.ID_NO:
|
1361
1351
|
return
|
1362
|
-
|
1352
|
+
|
1363
1353
|
Vulnerability(self._manager.main_dir,
|
1364
1354
|
scenario=self._manager.scenario,
|
1365
1355
|
Study_area=self._manager.Study_area,
|
@@ -1369,21 +1359,21 @@ class AcceptabilityGui(wx.Frame):
|
|
1369
1359
|
"Vulnerability computed with the selected steps" + message_supp,
|
1370
1360
|
"Information",
|
1371
1361
|
wx.OK | wx.ICON_INFORMATION
|
1372
|
-
)
|
1362
|
+
)
|
1373
1363
|
mapviewer_display(path)
|
1374
|
-
|
1364
|
+
|
1375
1365
|
def OnAcceptability(self, e):
|
1376
1366
|
""" Run the acceptability """
|
1377
1367
|
if self._manager is None:
|
1378
1368
|
return
|
1379
|
-
|
1380
|
-
river_trace = self._manager.wich_river_trace()
|
1369
|
+
|
1370
|
+
river_trace = self._manager.wich_river_trace()
|
1381
1371
|
if self.toggle_state == True and not os.path.isfile(str(self._manager.OUT_VULN_Stif)) and not os.path.isfile(str(river_trace)) :
|
1382
|
-
wx.MessageBox("Necessary files are missing, please ensure the DataBase or Vulnerability steps were performed. ","Error", wx.OK | wx.ICON_ERROR )
|
1372
|
+
wx.MessageBox("Necessary files are missing, please ensure the DataBase or Vulnerability or Updating riverbed steps were performed. ","Error", wx.OK | wx.ICON_ERROR )
|
1383
1373
|
return
|
1384
|
-
|
1374
|
+
|
1385
1375
|
if self.toggle_state == False and not os.path.isfile(str(self._manager.OUT_VULN)) and not os.path.isfile(str(river_trace)) :
|
1386
|
-
wx.MessageBox("Necessary files are missing, please ensure the DataBase or Vulnerability steps were performed. ","Error", wx.OK | wx.ICON_ERROR )
|
1376
|
+
wx.MessageBox("Necessary files are missing, please ensure the DataBase or Vulnerability or Updating riverbed steps were performed. ","Error", wx.OK | wx.ICON_ERROR )
|
1387
1377
|
return
|
1388
1378
|
|
1389
1379
|
steps = list(self._steps_acceptability.GetCheckedStrings())
|
@@ -1401,19 +1391,19 @@ class AcceptabilityGui(wx.Frame):
|
|
1401
1391
|
steps = [x for x in steps if x != 4]
|
1402
1392
|
logging.info('Acceptability_baseline not computed because it already exists.')
|
1403
1393
|
message_supp = " FOR scenario(s) vuln_ taken into account"
|
1404
|
-
|
1394
|
+
|
1405
1395
|
if river_trace == self._manager.OUT_MASKED_RIVER : message_supp=message_supp +" WITH the _baseline riverbed trace."
|
1406
1396
|
if river_trace == self._manager.OUT_MASKED_RIVER_S :message_supp+= " WITH the _scenarios riverbed trace."
|
1407
1397
|
if self.toggle_resamp_state == True :
|
1408
1398
|
steps.append(6)
|
1409
|
-
resampling = self._but_resampling.GetValue()
|
1399
|
+
resampling = self._but_resampling.GetValue()
|
1410
1400
|
resolution = self.input_dx.GetLabel()
|
1411
|
-
if resolution != '':
|
1401
|
+
if resolution != '':
|
1412
1402
|
values = resolution.strip("()").split(",")
|
1413
1403
|
resolution = float(values[0])
|
1414
|
-
|
1404
|
+
|
1415
1405
|
message_supp+= f" It has been created for the resolution {resolution}m and the resampling size {resampling}m."
|
1416
|
-
|
1406
|
+
|
1417
1407
|
logging.info("No steps selected. By default every steps will be performed.")
|
1418
1408
|
Acceptability(self._manager.main_dir,
|
1419
1409
|
scenario=self._manager.scenario,
|
@@ -1434,18 +1424,19 @@ class AcceptabilityGui(wx.Frame):
|
|
1434
1424
|
logging.info('Acceptability_baseline not computed because it already exists.')
|
1435
1425
|
message_supp = "FOR scenario(s) (vuln_taken into account)"
|
1436
1426
|
path = [self._manager.OUT_ACCEPT_Stif]
|
1437
|
-
river_trace = self._manager.wich_river_trace()
|
1427
|
+
river_trace = self._manager.wich_river_trace()
|
1438
1428
|
if river_trace == self._manager.OUT_MASKED_RIVER : message_supp =message_supp + " WITH the _baseline riverbed trace."
|
1439
1429
|
if river_trace == self._manager.OUT_MASKED_RIVER_S : message_supp =message_supp + " WITH the _scenarios riverbed trace."
|
1440
1430
|
if self.toggle_resamp_state == True :
|
1441
1431
|
resampling = self._but_resampling.GetValue()
|
1442
1432
|
steps.append(6)
|
1443
|
-
|
1433
|
+
|
1444
1434
|
Acceptability(self._manager.main_dir,
|
1445
1435
|
scenario=self._manager.scenario,
|
1446
1436
|
Study_area=self._manager.Study_area,
|
1447
1437
|
resample_size=resampling,
|
1448
1438
|
steps=steps)
|
1439
|
+
|
1449
1440
|
wx.MessageBox(
|
1450
1441
|
"Acceptability computed with the selected steps" + message_supp,
|
1451
1442
|
"Information",
|