wolfhece 2.1.107__py3-none-any.whl → 2.1.109__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 +165 -14
- wolfhece/PyGui.py +1 -1
- wolfhece/PyVertex.py +17 -1
- wolfhece/PyVertexvectors.py +676 -112
- wolfhece/PyWMS.py +61 -1
- wolfhece/acceptability/acceptability.py +59 -51
- wolfhece/acceptability/acceptability_gui.py +1043 -153
- wolfhece/acceptability/func.py +83 -48
- wolfhece/apps/version.py +1 -1
- wolfhece/lazviewer/laz_viewer.py +22 -0
- wolfhece/matplotlib_fig.py +69 -20
- wolfhece/picc.py +2 -2
- wolfhece/pybridges.py +227 -87
- wolfhece/scenario/config_manager.py +25 -6
- wolfhece/wolf_array.py +94 -40
- wolfhece/wolf_texture.py +12 -3
- wolfhece/wolf_tiles.py +2 -0
- {wolfhece-2.1.107.dist-info → wolfhece-2.1.109.dist-info}/METADATA +2 -2
- {wolfhece-2.1.107.dist-info → wolfhece-2.1.109.dist-info}/RECORD +22 -22
- {wolfhece-2.1.107.dist-info → wolfhece-2.1.109.dist-info}/WHEEL +1 -1
- {wolfhece-2.1.107.dist-info → wolfhece-2.1.109.dist-info}/entry_points.txt +0 -0
- {wolfhece-2.1.107.dist-info → wolfhece-2.1.109.dist-info}/top_level.txt +0 -0
@@ -10,44 +10,81 @@ copying or distribution of this file, via any medium, is strictly prohibited.
|
|
10
10
|
from .acceptability import Base_data_creation, Database_to_raster, Vulnerability, Acceptability
|
11
11
|
from .acceptability import steps_base_data_creation, steps_vulnerability, steps_acceptability
|
12
12
|
from .func import Accept_Manager
|
13
|
-
from ..
|
13
|
+
from ..wolf_array import WolfArray, header_wolf
|
14
|
+
from ..scenario.config_manager import Config_Manager_2D_GPU
|
15
|
+
from ..PyDraw import WolfMapViewer, draw_type
|
16
|
+
from ..Results2DGPU import wolfres2DGPU
|
17
|
+
from ..PyGui import MapManager
|
18
|
+
|
14
19
|
import wx
|
15
|
-
import glob
|
16
20
|
import wx.lib.dialogs
|
17
21
|
import logging
|
18
22
|
import subprocess
|
19
23
|
import matplotlib
|
20
24
|
import shutil
|
25
|
+
import os
|
26
|
+
import geopandas as gpd
|
21
27
|
from matplotlib.figure import Figure
|
22
28
|
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
|
23
29
|
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar2Wx
|
24
|
-
import os
|
25
30
|
from pathlib import Path
|
31
|
+
from scipy.ndimage import label
|
32
|
+
import pandas as pd
|
26
33
|
from gettext import gettext as _
|
27
|
-
|
28
|
-
from
|
29
|
-
|
30
|
-
|
31
|
-
def read_result(fn) :
|
32
|
-
wolfres2DGPU_X= wolfres2DGPU(fn)
|
33
|
-
return wolfres2DGPU_X
|
34
|
+
import rasterio
|
35
|
+
from shapely.geometry import Polygon
|
36
|
+
import numpy as np
|
34
37
|
|
35
38
|
def nullvalue_for_hole(WA):
|
36
|
-
|
39
|
+
"""
|
40
|
+
Sets the null value for a WolfArray to 0 (as per the convention in the interpolation routine).
|
41
|
+
"""
|
37
42
|
WA.nullvalue = 0.
|
38
43
|
WA.set_nullvalue_in_mask()
|
39
44
|
|
40
|
-
def read_export_z_bin(fn_read, fn_write):
|
41
|
-
|
45
|
+
def read_export_z_bin(fn_read, fn_write, fn_laststep):
|
46
|
+
"""
|
47
|
+
Reads the free surface altitude from a GPU simulation and exports it in binary format.
|
48
|
+
Inputs:
|
49
|
+
- fn_read_simu: the simulation file to read.
|
50
|
+
- fn_laststep: the folder EXTRACTED_LAST_STEP defined in acceptability.
|
51
|
+
- fn_write: the path to save the output in binary format.
|
52
|
+
"""
|
53
|
+
fn_temp = os.path.join(fn_laststep, 'temp')
|
54
|
+
os.makedirs(fn_temp, exist_ok=True)
|
55
|
+
wolfres2DGPU_test = wolfres2DGPU(fn_read)
|
42
56
|
wolfres2DGPU_test.read_oneresult(-1)
|
43
57
|
wd = wolfres2DGPU_test.get_h_for_block(1)
|
44
58
|
top = wolfres2DGPU_test.get_top_for_block(1)
|
45
59
|
nullvalue_for_hole(wd)
|
46
60
|
nullvalue_for_hole(top)
|
47
61
|
wd.array = wd.array + top.array
|
62
|
+
fn_write = fn_write.with_suffix('.bin')
|
48
63
|
wd.write_all(fn_write)
|
64
|
+
shutil.rmtree(fn_temp)
|
49
65
|
|
66
|
+
def riverbed_trace(fn_read_simu, fn_output, threshold):
|
67
|
+
"""
|
68
|
+
Recognizes the riverbed trace based on a simulation, where water depth above a given threshold is considered part of the riverbed.
|
69
|
+
Inputs:
|
70
|
+
- fn_read_simu: the simulation file to read.
|
71
|
+
- fn_output: the location to save the riverbed trace as a .tiff file.
|
72
|
+
- threshold: the water depth threshold above which the areas are considered riverbed.
|
73
|
+
"""
|
74
|
+
wolfres2DGPU_test = wolfres2DGPU(fn_read_simu)
|
75
|
+
wolfres2DGPU_test.read_oneresult(-1)
|
76
|
+
wd = wolfres2DGPU_test.get_h_for_block(1)
|
77
|
+
wd.array[wd.array > 1000] = 0
|
78
|
+
wd.array[wd.array > threshold] = 1
|
79
|
+
wd.array[wd.array < threshold] = 0
|
80
|
+
wd.as_WolfArray()
|
81
|
+
wd.nodata=0
|
82
|
+
wd.write_all(Path(fn_output))
|
83
|
+
|
50
84
|
def empty_folder(folder):
|
85
|
+
"""
|
86
|
+
Empties the content of a directory if it exists.
|
87
|
+
"""
|
51
88
|
if os.path.exists(folder):
|
52
89
|
for files in os.listdir(folder):
|
53
90
|
fn = os.path.join(folder, files)
|
@@ -61,14 +98,242 @@ def empty_folder(folder):
|
|
61
98
|
else:
|
62
99
|
print("The folder does not exist.")
|
63
100
|
|
101
|
+
"""
|
102
|
+
This script performs two main operations:
|
103
|
+
|
104
|
+
1. Subtraction of two raster TIFF files:
|
105
|
+
- Identifies areas with building traces by subtracting the `bathymetry.tif` from simulations
|
106
|
+
(corresponding to 'MNT_muret_bati') from `MNT` (DEM).
|
107
|
+
|
108
|
+
2. For the identified building areas (from step 1):
|
109
|
+
- Replace the values with those from the `MNT` (ground level), ensuring it reflects the terrain, not bathymetry values.
|
110
|
+
|
111
|
+
Final Output:
|
112
|
+
- 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.
|
113
|
+
|
114
|
+
Note: the computations are perfomed with tifs .tif rasters but should be translated to .bin files in the acceptability routine
|
115
|
+
"""
|
116
|
+
|
117
|
+
#----------------------------------------------------------------------------------------------------------
|
118
|
+
|
119
|
+
#1 - Soustraction bathymetry.tif (from simulations) - DEM (MNT, cfr "projet tuilage") ---------------------
|
120
|
+
|
121
|
+
def soustraction(fn_a,fn_b,fn_result):
|
122
|
+
with rasterio.open(fn_a) as src_a, rasterio.open(fn_b) as src_b:
|
123
|
+
if (
|
124
|
+
src_a.width != src_b.width or
|
125
|
+
src_a.height != src_b.height or
|
126
|
+
src_a.transform != src_b.transform or
|
127
|
+
src_a.crs != src_b.crs
|
128
|
+
):
|
129
|
+
logging.error(f"{fn_a} and {fn_b} do not have the same properties, please edit them.")
|
130
|
+
|
131
|
+
|
132
|
+
data_a = src_a.read(1)
|
133
|
+
data_b = src_b.read(1)
|
134
|
+
|
135
|
+
#(A - B)
|
136
|
+
data_diff = data_a - data_b
|
137
|
+
nodata_value = src_a.nodata if src_a.nodata == src_b.nodata else None
|
138
|
+
if nodata_value is not None:
|
139
|
+
data_diff[(data_a == nodata_value) | (data_b == nodata_value)] = nodata_value
|
140
|
+
|
141
|
+
data_diff[data_diff > 5000] = 0
|
142
|
+
labeled, n = label(data_diff)
|
143
|
+
# Remove small objects
|
144
|
+
threshold = 5
|
145
|
+
sizes = np.bincount(labeled.ravel())
|
146
|
+
idx_small = np.where(sizes <= threshold)[0]
|
147
|
+
data_diff[np.isin(labeled, idx_small)] = 0
|
148
|
+
|
149
|
+
out_meta = src_a.meta.copy()
|
150
|
+
out_meta.update({
|
151
|
+
"dtype": "float32",
|
152
|
+
"driver": "GTiff"
|
153
|
+
})
|
154
|
+
|
155
|
+
with rasterio.open(fn_result, "w", **out_meta) as dst:
|
156
|
+
dst.write(data_diff, 1)
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
#2 - DEM (MNT) value in the buildings traces ------------------------------------------------------------------
|
161
|
+
def mask_creation_data(mask_file, ground_file, output_file):
|
162
|
+
with rasterio.open(mask_file) as mask_src:
|
163
|
+
mask = mask_src.read(1)
|
164
|
+
mask_meta = mask_src.meta
|
64
165
|
|
166
|
+
indices = np.where(mask > 0)
|
167
|
+
|
168
|
+
with rasterio.open(ground_file) as bathy_src:
|
169
|
+
bathy = bathy_src.read(1)
|
170
|
+
|
171
|
+
mask[indices] = bathy[indices]
|
172
|
+
mask[mask <= 0] = 275
|
173
|
+
|
174
|
+
output_meta = mask_meta.copy()
|
175
|
+
output_meta.update({"dtype": 'float32'})
|
176
|
+
|
177
|
+
with rasterio.open(output_file, "w", **output_meta) as dst:
|
178
|
+
dst.write(mask, 1)
|
179
|
+
|
180
|
+
WA_mask = WolfArray(output_file)
|
181
|
+
WA_mask.write_all(Path(Path(output_file).parent / "MNT_computed_with_mask.bin"))
|
182
|
+
|
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)
|
186
|
+
mask_creation_data(fn_where_buildings, fn_mtn_cropped, fn_mask_final)
|
187
|
+
|
188
|
+
#--------------------------------------------------------------------------------------------------------------
|
189
|
+
|
190
|
+
def get_transform_and_crs(tif_file):
|
191
|
+
"""
|
192
|
+
For TIFF file manipulation, reads the CRS and the transform, and returns them.
|
193
|
+
"""
|
194
|
+
|
195
|
+
with rasterio.open(tif_file) as src:
|
196
|
+
transform = src.transform
|
197
|
+
crs = src.crs
|
198
|
+
return transform, crs
|
199
|
+
|
200
|
+
def create_shapefile_from_prop_tif(fn_tif, shapefile_path):
|
201
|
+
"""
|
202
|
+
Creates a shapefile of the study area based on the extent of an input TIFF file.
|
203
|
+
Inputs:
|
204
|
+
- fn_tif: the path to the input TIFF file.
|
205
|
+
- shapefile_path: the location to save the output shapefile.
|
206
|
+
"""
|
207
|
+
_,_,width,height,_,_ = get_header_info(fn_tif)
|
208
|
+
transform, crs = get_transform_and_crs(fn_tif)
|
209
|
+
top_left = transform * (0, 0)
|
210
|
+
bottom_left = transform * (0, height)
|
211
|
+
top_right = transform * (width, 0)
|
212
|
+
bottom_right = transform * (width, height)
|
213
|
+
|
214
|
+
rectangle = Polygon([top_left, top_right, bottom_right, bottom_left, top_left])
|
215
|
+
gdf = gpd.GeoDataFrame({'geometry': [rectangle]})
|
216
|
+
gdf.set_crs(crs, allow_override=True, inplace=True)
|
217
|
+
gdf.to_file(shapefile_path)
|
218
|
+
|
219
|
+
def get_header_info(fn):
|
220
|
+
"""
|
221
|
+
Reads the headers from the file at path 'fn'.
|
222
|
+
"""
|
223
|
+
class_header = header_wolf()
|
224
|
+
class_header.read_txt_header(fn)
|
225
|
+
dx,dy = class_header.dx, class_header.dy
|
226
|
+
nbx,nby = class_header.nbx, class_header.nby
|
227
|
+
X,Y = class_header.origx, class_header.origy
|
228
|
+
return dx,dy,nbx,nby,X,Y
|
229
|
+
|
230
|
+
def get_header_comparison(list_fn):
|
231
|
+
"""
|
232
|
+
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.
|
233
|
+
"""
|
234
|
+
|
235
|
+
header_infos = [get_header_info(fn) for fn in list_fn]
|
236
|
+
variable_names = ["dx", "dy", "nbx", "nby", "X", "Y"]
|
237
|
+
for idx, name in enumerate(variable_names):
|
238
|
+
values = [header[idx] for header in header_infos]
|
239
|
+
if len(set(values)) > 1:
|
240
|
+
comp = False
|
241
|
+
else:
|
242
|
+
comp = True
|
243
|
+
return comp
|
244
|
+
|
245
|
+
|
246
|
+
def display_info_header(self_dx, self_nbxy, self_O, fn):
|
247
|
+
"""
|
248
|
+
Displays the header at the path 'fn', and update the values displayed in the acceptability window.
|
249
|
+
"""
|
250
|
+
dx,dy,nbx,nby,X,Y= get_header_info(fn)
|
251
|
+
self_dx.SetLabel(f"({dx},{dy})")
|
252
|
+
self_nbxy.SetLabel(f"({nbx},{nby})")
|
253
|
+
self_O.SetLabel(f"({X},{Y})")
|
254
|
+
return dx,dy,nbx,nby,X,Y
|
255
|
+
|
256
|
+
def vanish_info_header(self_dx, self_nbxy, self_O):
|
257
|
+
self_dx.SetLabel("")
|
258
|
+
self_nbxy.SetLabel("")
|
259
|
+
self_O.SetLabel("")
|
260
|
+
|
261
|
+
def update_info_header(self_dx, self_nbxy, self_O, fn):
|
262
|
+
"""
|
263
|
+
Upate the displayed header values by reading the simulations headers if exist.
|
264
|
+
"""
|
265
|
+
if not os.path.exists(fn):
|
266
|
+
os.makedirs(fn)
|
267
|
+
|
268
|
+
tif_files = [f for f in os.listdir(fn) if f.lower().endswith('.tif')]
|
269
|
+
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) :
|
272
|
+
dx,dy,nbx,nby,X,Y = display_info_header(self_dx, self_nbxy, self_O, tif_list_fn[0])
|
273
|
+
return dx,dy,nbx,nby,X,Y
|
274
|
+
else:
|
275
|
+
logging.error("The interpolated files have different headers. Please fix it.")
|
276
|
+
return False, False, False, False, False, False
|
277
|
+
else :
|
278
|
+
vanish_info_header(self_dx, self_nbxy, self_O)
|
279
|
+
return False, False, False, False, False, False
|
280
|
+
|
281
|
+
def search_for_modif_bath_and_copy(main_gpu, from_path, path_vuln):
|
282
|
+
"""
|
283
|
+
When loading gpu simulations for last step extraction, search for modified bath_ topography file, according to
|
284
|
+
the structure coded in the scenarios manager. If they exist, their extent is copied to CHANGE_VULNE, called vuln_ and
|
285
|
+
MNTmodifs_, to enable the user to modify it later. In addition, returns True if such files exist and False if they do not.
|
286
|
+
"""
|
287
|
+
found_bath = False
|
288
|
+
scen_manager = Config_Manager_2D_GPU(main_gpu, create_ui_if_wx=False)
|
289
|
+
curtree = scen_manager.get_tree(from_path)
|
290
|
+
curdicts = scen_manager.get_dicts(curtree)
|
291
|
+
all_tif_bath = [scen_manager._select_tif_partname(curdict, 'bath_') for curdict in curdicts]
|
292
|
+
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) :
|
294
|
+
found_bath = True
|
295
|
+
for tif_file in all_tif_bath:
|
296
|
+
found_bath = True
|
297
|
+
with rasterio.open(tif_file) as src:
|
298
|
+
#vuln_ files
|
299
|
+
metadata = src.meta.copy()
|
300
|
+
metadata.update(dtype=rasterio.uint8, count=1, nodata=0)
|
301
|
+
data = np.ones((metadata['height'], metadata['width']), dtype=rasterio.uint8)
|
302
|
+
output_file = path_vuln / tif_file.name.replace('bath_', 'vuln_')
|
303
|
+
with rasterio.open(output_file, 'w', **metadata) as dst:
|
304
|
+
dst.write(data, 1)
|
305
|
+
#MNTmodifs_ files
|
306
|
+
metadata.update(dtype=rasterio.float32, count=1, nodata=0)
|
307
|
+
data = np.ones((metadata['height'], metadata['width']), dtype=rasterio.float32)
|
308
|
+
output_file = path_vuln / tif_file.name.replace('bath_', 'MNTmodifs_')
|
309
|
+
with rasterio.open(output_file, 'w', **metadata) as dst:
|
310
|
+
dst.write(data, 1)
|
311
|
+
|
312
|
+
return found_bath
|
313
|
+
|
314
|
+
def mapviewer_display(list_path):
|
315
|
+
""" Load the output in the mapviewer on WOLF """
|
316
|
+
results = " and ".join(Path(path).name for path in list_path)
|
317
|
+
dlg = wx.MessageDialog(None, _(f'Do you want to load {results} in the mapviewer ?'), _('Load file'), wx.YES_NO)
|
318
|
+
ret = dlg.ShowModal()
|
319
|
+
dlg.Destroy()
|
320
|
+
if ret != wx.ID_YES:
|
321
|
+
return
|
322
|
+
|
323
|
+
mapviewer = WolfMapViewer(title="OUTPUT Acceptability manager")
|
324
|
+
for path in list_path:
|
325
|
+
myarray = WolfArray(path)
|
326
|
+
newid = Path(path).name
|
327
|
+
mapviewer.add_object('array', newobj=myarray, id=newid)
|
328
|
+
logging.info("Press F5 to refresh the mapviewer.")
|
329
|
+
mapviewer.Refresh()
|
65
330
|
|
66
331
|
class AcceptabilityGui(wx.Frame):
|
67
332
|
""" The main frame for the vulnerability/acceptability computation """
|
68
333
|
|
69
334
|
def __init__(self, parent=None, width=1024, height=500):
|
70
335
|
|
71
|
-
super(wx.Frame, self).__init__(parent, title='Acceptability', size=(width, height))
|
336
|
+
super(wx.Frame, self).__init__(parent, title='Acceptability score manager', size=(width, height))
|
72
337
|
|
73
338
|
self._manager = None
|
74
339
|
self._mapviewer = None
|
@@ -86,79 +351,260 @@ class AcceptabilityGui(wx.Frame):
|
|
86
351
|
raise TypeError("The mapviewer must be a WolfMapViewer")
|
87
352
|
|
88
353
|
self._mapviewer = value
|
354
|
+
|
355
|
+
def OnHoverEnter(self, event):
|
356
|
+
"""Dynamic colour layout 1"""
|
357
|
+
self._but_creation.SetBackgroundColour(wx.Colour(100,100,100))
|
358
|
+
self._but_creation.Refresh()
|
359
|
+
event.Skip()
|
360
|
+
|
361
|
+
def OnHoverLeave(self, event):
|
362
|
+
"""Dynamic colour layout 2"""
|
363
|
+
self._but_creation.SetBackgroundColour(wx.Colour(150,150,150))
|
364
|
+
self._but_creation.Refresh()
|
365
|
+
event.Skip()
|
366
|
+
|
367
|
+
def layout(self, self_fct):
|
368
|
+
"""Update the layers for the main buttons"""
|
369
|
+
font = self_fct.GetFont()
|
370
|
+
font.SetWeight(wx.FONTWEIGHT_BOLD)
|
371
|
+
self_fct.SetFont(font)
|
372
|
+
self_fct.SetBackgroundColour(wx.Colour(150,150,150))
|
373
|
+
self_fct.Bind(wx.EVT_ENTER_WINDOW, self.OnHoverEnter)
|
374
|
+
self_fct.Bind(wx.EVT_LEAVE_WINDOW, self.OnHoverLeave)
|
375
|
+
|
376
|
+
def on_button_click(self, event):
|
377
|
+
self.PopupMenu(self.menu)
|
378
|
+
|
379
|
+
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
|
382
|
+
a no-overflow simulation, allowing the code to create the trace."""
|
383
|
+
menu_id = event.GetId()
|
384
|
+
if menu_id == 1:
|
385
|
+
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,
|
388
|
+
wildcard="TIFF files (*.tiff)|*.tiff")
|
89
389
|
|
90
|
-
|
390
|
+
if dlg.ShowModal() == wx.ID_OK:
|
391
|
+
selected_file = Path(dlg.GetPath())
|
392
|
+
copied_file = self._manager.OUT_SCEN_DIR / "copy_file"
|
393
|
+
shutil.copy(selected_file, copied_file)
|
394
|
+
logging.info(f"File copied to: {copied_file}")
|
395
|
+
|
396
|
+
new_name = self._manager.OUT_MASKED_RIVER_S
|
397
|
+
|
398
|
+
with wx.MessageDialog(self, f"Modified riverbed imported and called Masked_River_extent_scenarios.tiff.",
|
399
|
+
"File imported.", wx.OK | wx.ICON_INFORMATION) as dlg:
|
400
|
+
dlg.ShowModal()
|
401
|
+
|
402
|
+
if new_name.exists():
|
403
|
+
new_name.unlink()
|
404
|
+
|
405
|
+
copied_file.rename(new_name)
|
406
|
+
logging.info(f"File renamed to: {new_name}")
|
407
|
+
else:
|
408
|
+
logging.info('No file selected. Please try again.')
|
409
|
+
|
410
|
+
elif menu_id == 2: #No file, so need to create
|
411
|
+
logging.info("Option 2 : pointing to simulation with low discharge (no overflows!).")
|
412
|
+
|
413
|
+
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}")
|
418
|
+
fn_output = self._manager.OUT_MASKED_RIVER_S
|
419
|
+
dlg = wx.TextEntryDialog(self, "What water depth threshold (in meters) should be used to define the riverbed trace, above which\n"
|
420
|
+
"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
|
+
|
422
|
+
if dlg.ShowModal() == wx.ID_OK:
|
423
|
+
while True:
|
424
|
+
try:
|
425
|
+
valeur = dlg.GetValue()
|
426
|
+
threshold = float(valeur)
|
427
|
+
if threshold < 1e-5 or threshold > 150:
|
428
|
+
wx.MessageBox(
|
429
|
+
"Error: The value must be positive > 0 and reasonable. Please, try again.",
|
430
|
+
"Error", wx.OK | wx.ICON_ERROR
|
431
|
+
)
|
432
|
+
break
|
433
|
+
wx.MessageBox(
|
434
|
+
f"Threshold accepted. Considering riverbed where water depth > {threshold}[m]. Please wait.",
|
435
|
+
"Succeed", wx.OK | wx.ICON_INFORMATION
|
436
|
+
)
|
437
|
+
riverbed_trace(selected_folder, fn_output, threshold)
|
438
|
+
logging.info("File created.")
|
439
|
+
with wx.MessageDialog(
|
440
|
+
self,
|
441
|
+
"Masked_River_extent_scenarios.tiff successfully created.",
|
442
|
+
"File created.", wx.OK | wx.ICON_INFORMATION
|
443
|
+
) as dlg_success:
|
444
|
+
dlg_success.ShowModal()
|
445
|
+
break
|
446
|
+
except ValueError:
|
447
|
+
wx.MessageBox(
|
448
|
+
"Error: Invalid entry. Please enter a valid number (positive > 0, reasonable, using with DOT as a decimal separator).",
|
449
|
+
"Error", wx.OK | wx.ICON_ERROR
|
450
|
+
)
|
451
|
+
break
|
452
|
+
|
453
|
+
else:
|
454
|
+
logging.info("Cancelled.")
|
455
|
+
dlg.Destroy()
|
456
|
+
else:
|
457
|
+
logging.info("No folder (or wrong one) selected. Please try again (must be simul_gpu_results).")
|
458
|
+
|
459
|
+
def layout_listbox(self, self_fct):
|
460
|
+
"""Changes the layout for the listbox : light grey."""
|
461
|
+
self_fct.SetBackgroundColour(wx.Colour(220, 220, 220))
|
91
462
|
|
463
|
+
def InitUI(self):
|
464
|
+
self.gpu_bathy = None
|
465
|
+
|
92
466
|
sizer_hor_main = wx.BoxSizer(wx.HORIZONTAL)
|
93
|
-
|
94
467
|
sizer_vert1 = wx.BoxSizer(wx.VERTICAL)
|
95
|
-
|
96
468
|
sizer_hor_threads = wx.BoxSizer(wx.HORIZONTAL)
|
97
469
|
sizer_hor1 = wx.BoxSizer(wx.HORIZONTAL)
|
98
470
|
sizer_hor1_1 = wx.BoxSizer(wx.HORIZONTAL)
|
99
471
|
sizer_hor2 = wx.BoxSizer(wx.HORIZONTAL)
|
100
472
|
sizer_hor3 = wx.BoxSizer(wx.HORIZONTAL)
|
101
473
|
sizer_hor4 = wx.BoxSizer(wx.HORIZONTAL)
|
474
|
+
sizer_hor_scen = wx.BoxSizer(wx.HORIZONTAL)
|
102
475
|
|
103
476
|
# 1st LINE
|
104
477
|
panel = wx.Panel(self)
|
105
478
|
self._but_maindir = wx.Button(panel, label='Main Directory')
|
479
|
+
self._but_maindir.SetFont(wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
|
106
480
|
self._but_maindir.Bind(wx.EVT_BUTTON, self.OnMainDir)
|
107
|
-
|
481
|
+
|
108
482
|
self._listbox_studyarea = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
|
483
|
+
self.layout_listbox(self._listbox_studyarea)
|
109
484
|
self._listbox_studyarea.Bind(wx.EVT_LISTBOX, self.OnStudyArea)
|
110
485
|
self._listbox_studyarea.SetToolTip("Choose the study area")
|
111
486
|
|
112
487
|
self._listbox_scenario = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
|
488
|
+
self.layout_listbox(self._listbox_scenario)
|
113
489
|
self._listbox_scenario.Bind(wx.EVT_LISTBOX, self.OnScenario)
|
114
490
|
self._listbox_scenario.SetToolTip("Choose the scenario")
|
491
|
+
|
492
|
+
# 2nd LINE
|
493
|
+
self._but_checkfiles = wx.Button(panel, label='Check directories\n structure')
|
494
|
+
self._but_checkfiles.Bind(wx.EVT_BUTTON, self.OnCheckFiles)
|
495
|
+
self._listbox_scenario.SetToolTip("Check if the folder is correctly structured")
|
496
|
+
|
497
|
+
sizer_hor1_1.Add(self._but_checkfiles, 1, wx.ALL | wx.EXPAND, 0)
|
498
|
+
|
499
|
+
# Hydrodynamic part
|
500
|
+
self._but_checksim = wx.Button(panel, label='Check existing interpolated\n free surfaces')
|
501
|
+
self._but_checksim.Bind(wx.EVT_BUTTON, self.OnHydrodynInput)
|
115
502
|
|
503
|
+
sizer_hor1_1.Add(self._but_checksim, 1, wx.ALL | wx.EXPAND, 0)
|
504
|
+
|
505
|
+
self._but_loadgpu = wx.Button(panel, label='Load and extract\n gpu simulations')
|
506
|
+
self._but_loadgpu.Bind(wx.EVT_BUTTON, self.OnLoadingSimu)
|
507
|
+
sizer_hor1_1.Add(self._but_loadgpu, 1, wx.ALL | wx.EXPAND, 0)
|
508
|
+
|
116
509
|
|
117
|
-
|
118
|
-
self.
|
119
|
-
|
120
|
-
self.
|
121
|
-
self._nb_process.SetToolTip("Number of threads to use")
|
510
|
+
self._check_listbox = wx.CheckListBox(panel, choices=[], style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
|
511
|
+
self.layout_listbox(self._check_listbox)
|
512
|
+
self.sims = {}
|
513
|
+
sizer_hor1_1.Add(self._check_listbox, 1, wx.ALL | wx.EXPAND, 0) #ajouter!! sinon s'affiche pas
|
122
514
|
|
123
|
-
|
124
|
-
|
515
|
+
self._but_DEM = wx.Button(panel, label='Check DEM inputs\n for interpolation')
|
516
|
+
self._but_DEM.Bind(wx.EVT_BUTTON, self.OnDEM)
|
517
|
+
sizer_hor1_1.Add(self._but_DEM, 1, wx.ALL | wx.EXPAND, 0)
|
518
|
+
|
519
|
+
self._but_extrinterp = wx.Button(panel, label='Reading and interpolating\n free surface')
|
520
|
+
self._but_extrinterp.Bind(wx.EVT_BUTTON, self.OnInterpolation)
|
521
|
+
sizer_hor1_1.Add(self._but_extrinterp, 1, wx.ALL | wx.EXPAND, 0)
|
125
522
|
|
126
523
|
sizer_hor1.Add(self._but_maindir, 2, wx.ALL | wx.EXPAND, 0)
|
127
524
|
sizer_hor1.Add(self._listbox_studyarea, 1, wx.ALL | wx.EXPAND, 0)
|
128
525
|
sizer_hor1.Add(self._listbox_scenario, 1, wx.ALL | wx.EXPAND, 0)
|
129
526
|
|
130
|
-
# 2nd LINE
|
131
|
-
self._but_checkfiles = wx.Button(panel, label='Check directories structure')
|
132
|
-
self._but_checkfiles.Bind(wx.EVT_BUTTON, self.OnCheckFiles)
|
133
|
-
|
134
|
-
sizer_hor1_1.Add(self._but_checkfiles, 1, wx.ALL | wx.EXPAND, 0)
|
135
527
|
|
136
|
-
#
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
528
|
+
#3rd line
|
529
|
+
sizer_hor_threads = wx.BoxSizer(wx.HORIZONTAL)
|
530
|
+
text_dx = wx.StaticText(panel, label='Resolution (dx,dy) [m]:')
|
531
|
+
self.input_dx = wx.StaticText(panel)
|
532
|
+
self.input_dx.SetMinSize((60, -1))
|
533
|
+
text_nbxy = wx.StaticText(panel, label='(nbx, nby):')
|
534
|
+
self.input_nbxy = wx.StaticText(panel)
|
535
|
+
self.input_nbxy.SetMinSize((70, -1))
|
536
|
+
text_O = wx.StaticText(panel, label='Origin (X,Y):')
|
537
|
+
self.input_O = wx.StaticText(panel)
|
538
|
+
self.input_O.SetMinSize((160, -1))
|
539
|
+
text_threads = wx.StaticText(panel, label='Number of threads:')
|
540
|
+
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 use")
|
141
542
|
|
142
|
-
self.
|
143
|
-
self.
|
144
|
-
|
145
|
-
sizer_hor1_1.Add(self._but_checkfiles, 1, wx.ALL | wx.EXPAND, 0)
|
543
|
+
self._but_sacreation = wx.Button(panel, label='SA creation')
|
544
|
+
self._but_sacreation.Bind(wx.EVT_BUTTON, self.OnSAcreation)
|
146
545
|
|
147
|
-
|
546
|
+
sizer_hor_threads.Add(text_dx, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
547
|
+
sizer_hor_threads.Add(self.input_dx, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
548
|
+
sizer_hor_threads.Add(text_nbxy, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
549
|
+
sizer_hor_threads.Add(self.input_nbxy, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
550
|
+
sizer_hor_threads.Add(text_O, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
551
|
+
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
|
+
sizer_hor_threads.Add(text_threads, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
554
|
+
sizer_hor_threads.Add(self._nb_process, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
555
|
+
|
556
|
+
# 3 last lines + scenarios
|
557
|
+
#--------------------------
|
148
558
|
self._but_creation = wx.Button(panel, label='DataBase Creation')
|
559
|
+
self.layout(self._but_creation)
|
149
560
|
self._but_creation.Bind(wx.EVT_BUTTON, self.OnCreation)
|
150
|
-
|
561
|
+
|
151
562
|
self._steps_db = wx.CheckListBox(panel, choices=steps_base_data_creation.get_list_names(), style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
|
152
563
|
|
153
564
|
self._but_vulnerability = wx.Button(panel, label='Vulnerability')
|
154
|
-
self.
|
565
|
+
self.layout(self._but_vulnerability)
|
566
|
+
self._but_vulnerability.Bind(wx.EVT_BUTTON, self.OnVulnerability)
|
567
|
+
step_Vuln_without_withoutscenarios = [item for item in steps_vulnerability.get_list_names() if item != 'APPLY_SCENARIOSVULN - 4']
|
568
|
+
self._steps_vulnerability = wx.CheckListBox(panel, choices=step_Vuln_without_withoutscenarios, style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
|
569
|
+
|
570
|
+
|
571
|
+
# Scenarios specifics --
|
572
|
+
self._but_checkscenario = wx.Button(panel, label='Check existing scenarios')
|
573
|
+
self._but_checkscenario.Bind(wx.EVT_BUTTON, self.OnCheckScenario)
|
574
|
+
|
575
|
+
|
576
|
+
self._but_upriverbed = wx.Button(panel, label="Update riverbed")
|
577
|
+
self._but_upriverbed.Bind(wx.EVT_BUTTON, self.on_button_click)
|
155
578
|
|
156
|
-
self.
|
579
|
+
self.menu = wx.Menu()
|
580
|
+
self.menu.Append(1, "File of riverbed trace exists.")
|
581
|
+
self.menu.Append(2, "Point to a low discharge simulation and calculate the riverbed trace.")
|
582
|
+
self.menu.Bind(wx.EVT_MENU, self.on_menu_click)
|
583
|
+
|
584
|
+
self._but_toggle_scen = wx.ToggleButton(panel, label="Accounting for scenarios")
|
585
|
+
self.toggle_state = False
|
586
|
+
self._but_toggle_scen.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle)
|
587
|
+
|
588
|
+
sizer_hor_scen.Add(self._but_checkscenario, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
589
|
+
sizer_hor_scen.Add(self._but_upriverbed, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
590
|
+
sizer_hor_scen.Add(self._but_toggle_scen, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
|
591
|
+
|
592
|
+
self._but_toggle_resamp = wx.ToggleButton(panel, label="Resampling [m]:")
|
593
|
+
self.toggle_resamp_state = False
|
594
|
+
self._but_toggle_resamp.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggleResampling)
|
595
|
+
sizer_hor_scen.Add(self._but_toggle_resamp, flag=wx.ALIGN_CENTER | wx.TOP)
|
596
|
+
self._but_resampling = wx.SpinCtrl(panel, value="100", min=1, max=1000)
|
597
|
+
sizer_hor_scen.Add(self._but_resampling, flag=wx.ALIGN_CENTER | wx.TOP)
|
598
|
+
|
599
|
+
#--
|
157
600
|
|
158
601
|
self._but_acceptability = wx.Button(panel, label='Acceptability')
|
602
|
+
self.layout(self._but_acceptability)
|
159
603
|
self._but_acceptability.Bind(wx.EVT_BUTTON, self.OnAcceptability)
|
160
604
|
|
161
|
-
|
605
|
+
step_without_withoutscenarios = [item for item in steps_acceptability.get_list_names() if item != 'COMPUTE_WITH_SCENARIOS - 5']
|
606
|
+
step_without_withoutscenarios = [item for item in step_without_withoutscenarios if item != 'RESAMPLING - 6']
|
607
|
+
self._steps_acceptability = wx.CheckListBox(panel, choices=step_without_withoutscenarios, style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
|
162
608
|
|
163
609
|
sizer_hor2.Add(self._but_creation, 1, wx.ALL | wx.EXPAND, 0)
|
164
610
|
sizer_hor2.Add(self._steps_db, 1, wx.ALL | wx.EXPAND, 0)
|
@@ -169,13 +615,14 @@ class AcceptabilityGui(wx.Frame):
|
|
169
615
|
sizer_hor4.Add(self._but_acceptability, 1, wx.ALL | wx.EXPAND, 0)
|
170
616
|
sizer_hor4.Add(self._steps_acceptability, 1, wx.ALL | wx.EXPAND, 0)
|
171
617
|
|
172
|
-
|
618
|
+
#Lines order
|
619
|
+
sizer_vert1.Add(sizer_hor1, 1, wx.EXPAND, 0)
|
173
620
|
sizer_vert1.Add(sizer_hor1_1, 1, wx.EXPAND, 0)
|
174
621
|
sizer_vert1.Add(sizer_hor_threads, 0, wx.EXPAND, 0)
|
175
622
|
sizer_vert1.Add(sizer_hor2, 1, wx.EXPAND, 0)
|
623
|
+
sizer_vert1.Add(sizer_hor_scen, 1, wx.EXPAND, 0)
|
176
624
|
sizer_vert1.Add(sizer_hor3, 1, wx.EXPAND, 0)
|
177
625
|
sizer_vert1.Add(sizer_hor4, 1, wx.EXPAND, 0)
|
178
|
-
|
179
626
|
# ------
|
180
627
|
|
181
628
|
sizer_vert2 = wx.BoxSizer(wx.VERTICAL)
|
@@ -200,6 +647,10 @@ class AcceptabilityGui(wx.Frame):
|
|
200
647
|
|
201
648
|
self._figure = Figure(figsize=(5, 4), dpi=100)
|
202
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
|
+
|
203
654
|
self._canvas = FigureCanvas(panel, -1, self._figure)
|
204
655
|
self._toolbar = NavigationToolbar2Wx(self._canvas)
|
205
656
|
self._toolbar.Realize()
|
@@ -208,7 +659,7 @@ class AcceptabilityGui(wx.Frame):
|
|
208
659
|
sizer_vert3.Add(self._toolbar, 0, wx.LEFT | wx.EXPAND, 0)
|
209
660
|
|
210
661
|
# ------
|
211
|
-
|
662
|
+
|
212
663
|
sizer_hor_main.Add(sizer_vert1, 1, wx.EXPAND, 0)
|
213
664
|
sizer_hor_main.Add(sizer_vert2, 1, wx.EXPAND, 0)
|
214
665
|
sizer_hor_main.Add(sizer_vert3, 1, wx.EXPAND, 0)
|
@@ -216,10 +667,22 @@ class AcceptabilityGui(wx.Frame):
|
|
216
667
|
panel.SetSizer(sizer_hor_main)
|
217
668
|
panel.Layout()
|
218
669
|
|
670
|
+
#Disabled if Main Directory + SA + Scenario not selected
|
219
671
|
self._but_acceptability.Enable(False)
|
220
672
|
self._but_vulnerability.Enable(False)
|
221
673
|
self._but_creation.Enable(False)
|
222
|
-
|
674
|
+
self._but_checkfiles.Enable(False)
|
675
|
+
self._but_DEM.Enable(False)
|
676
|
+
self._but_extrinterp.Enable(False)
|
677
|
+
self._but_loadgpu.Enable(False)
|
678
|
+
self._but_toggle_scen.Enable(False)
|
679
|
+
self._but_toggle_resamp.Enable(False)
|
680
|
+
self._but_upriverbed.Enable(False)
|
681
|
+
self._but_checkscenario.Enable(False)
|
682
|
+
self._but_checksim.Enable(False)
|
683
|
+
self._but_sacreation.Enable(False)
|
684
|
+
self._but_creation.Enable(False)
|
685
|
+
|
223
686
|
def OnSims(self, e:wx.ListEvent):
|
224
687
|
""" Load sim into the mapviewer """
|
225
688
|
pass
|
@@ -266,14 +729,14 @@ class AcceptabilityGui(wx.Frame):
|
|
266
729
|
logging.error("No main directory selected -- Nothing to check")
|
267
730
|
return
|
268
731
|
|
269
|
-
paths_FilledWD = self._manager.
|
732
|
+
paths_FilledWD = self._manager.get_sims_files_for_scenario()
|
270
733
|
|
271
734
|
if len(paths_FilledWD) == 0 :
|
272
|
-
logging.info("There are no interpolated free surface files.
|
273
|
-
dialog = wx.MessageDialog(None, "There are no interpolated free surface files.
|
735
|
+
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",
|
274
737
|
wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION)
|
275
738
|
|
276
|
-
dialog.SetYesNoLabels("Use
|
739
|
+
dialog.SetYesNoLabels("Use the ones in the Scenario_baseline", "Load other simulations")
|
277
740
|
response = dialog.ShowModal()
|
278
741
|
|
279
742
|
if response == wx.ID_YES:
|
@@ -282,104 +745,274 @@ class AcceptabilityGui(wx.Frame):
|
|
282
745
|
if len(paths_FilledWD_base) == 0 :
|
283
746
|
logging.info("Cannot select files in the _baseline folder.")
|
284
747
|
else:
|
285
|
-
self._manager.copy_tif_files(paths_FilledWD_base, self._manager.
|
748
|
+
self._manager.copy_tif_files(paths_FilledWD_base, self._manager.IN_SA_INTERP)
|
286
749
|
|
287
750
|
elif response == wx.ID_NO:
|
288
751
|
logging.info("Decision of loading simulations.")
|
289
|
-
with wx.MessageDialog(self, f"Please use the '
|
752
|
+
with wx.MessageDialog(self, f"Please use the 'Load gpu simulations folder' button of the manager and follow the instructions.", "Redirecting",
|
290
753
|
wx.OK | wx.ICON_INFORMATION) as dlg:
|
291
754
|
dlg.ShowModal()
|
292
755
|
else:
|
293
|
-
|
756
|
+
logging.info("Cancelled")
|
294
757
|
|
295
758
|
dialog.Destroy()
|
296
759
|
|
297
760
|
else:
|
761
|
+
name_paths_FilledWD = []
|
762
|
+
|
298
763
|
for names in paths_FilledWD:
|
299
764
|
logging.info(f"Interpolated free surface file found: {names.name}.")
|
765
|
+
name_paths_FilledWD.append(names.name)
|
300
766
|
with wx.MessageDialog(self,
|
301
|
-
f"{len(paths_FilledWD)} files of interpolated free surface found in the folder
|
767
|
+
f"{len(paths_FilledWD)} files of interpolated free surface found in the folder : {name_paths_FilledWD}. If you want to change them, click on the 'Load gpu simulations folder button.",
|
302
768
|
"Information",
|
303
769
|
style=wx.OK | wx.ICON_INFORMATION) as dlg:
|
304
770
|
dlg.ShowModal()
|
771
|
+
#display_info_header(self.input_dx, self.input_nbxy, self.input_O, paths_FilledWD[0].with_suffix(".tif"))
|
772
|
+
update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
|
305
773
|
|
306
|
-
def
|
774
|
+
def OnLoadingSimu(self,e):
|
307
775
|
""" Link between acceptability and simulations
|
308
776
|
-Either the last steps of the steady simulations for the scenarios already exist : only have to point towards them, then the free surfaces are filled
|
309
777
|
-Or they dont exist and need to be done outside this manager
|
310
778
|
"""
|
311
|
-
|
312
|
-
dlg = wx.DirDialog(None, "Please select the
|
779
|
+
|
780
|
+
dlg = wx.DirDialog(None, "Please select the scenario manager folder of the scenario manager (containing the scenarios, the folder discharge, the scripts.py...)", style=wx.DD_DEFAULT_STYLE)
|
313
781
|
if dlg.ShowModal() == wx.ID_OK:
|
314
|
-
|
315
|
-
logging.info(f"Selected folder : {
|
782
|
+
main_gpu = Path(dlg.GetPath())
|
783
|
+
logging.info(f"Selected folder for GPU result : {main_gpu}")
|
784
|
+
dlg = wx.DirDialog(None, "Please select the simulations folder (containing the sim_ folders) of the specific hydraulic scenario.", defaultPath=str(main_gpu), style=wx.DD_DEFAULT_STYLE)
|
785
|
+
if dlg.ShowModal() == wx.ID_OK:
|
786
|
+
hydraulic_scen = Path(dlg.GetPath())
|
787
|
+
logging.info(f"Selected hydraulic scenario : {hydraulic_scen}")
|
788
|
+
else:
|
789
|
+
logging.error('No hydraulic scenario selected.')
|
316
790
|
else:
|
317
|
-
logging.
|
791
|
+
logging.error('No folder found / selected. Please try again.')
|
318
792
|
|
319
|
-
|
793
|
+
self._check_listbox.Clear()
|
794
|
+
self.sims = {}
|
320
795
|
path_LastSteps = Path(self._manager.IN_SA_EXTRACTED)
|
321
796
|
empty_folder(path_LastSteps)
|
322
|
-
|
797
|
+
|
798
|
+
#self.datadir_gpu_sim = main-gpu
|
799
|
+
for subdir in hydraulic_scen.iterdir():
|
323
800
|
if subdir.is_dir() and subdir.name.startswith("sim_"):
|
324
|
-
sims[subdir.name] = subdir
|
325
|
-
|
326
|
-
logging.info(
|
801
|
+
self.sims[subdir.name] = subdir
|
802
|
+
else:
|
803
|
+
logging.info('No folder sim_ found / selected. Please try again.')
|
804
|
+
self.datadir_simulations = hydraulic_scen
|
805
|
+
self.file_paths = {Path(sim).name: Path(sim) for sim in sorted(self.sims.keys())}
|
806
|
+
self._check_listbox.Set(sorted(sim for sim in self.sims.keys()))
|
807
|
+
|
808
|
+
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
|
+
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
|
+
|
812
|
+
found_bath = search_for_modif_bath_and_copy(Path(main_gpu), Path(hydraulic_scen.parent), self._manager.IN_CH_SA_SC)
|
813
|
+
if found_bath :
|
814
|
+
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
|
+
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
|
+
self.gpu_bathy = hydraulic_scen.parent / "__bathymetry.tif"
|
818
|
+
self._but_extrinterp.Enable(True)
|
819
|
+
self._but_DEM.Enable(True)
|
820
|
+
with wx.MessageDialog(self,
|
821
|
+
message,
|
822
|
+
"Information",
|
823
|
+
style=wx.OK | wx.ICON_INFORMATION) as dlg:
|
824
|
+
dlg.ShowModal()
|
825
|
+
|
826
|
+
def OnDEM(self,e):
|
827
|
+
"""Import and create the inputs for the interpolation routine holes.exe (name including 'MNT_...' and 'MNT_..._with_mask'.
|
828
|
+
See function MTN_And_mask_creation_all"""
|
829
|
+
if not hasattr(self, 'file_paths'):
|
830
|
+
with wx.MessageDialog(self,
|
831
|
+
f"Please, first load gpu simulations via the previous button.",
|
832
|
+
"Attention",
|
833
|
+
style=wx.OK | wx.ICON_ERROR) as dlg:
|
834
|
+
dlg.ShowModal()
|
835
|
+
return
|
836
|
+
path = self._manager.IN_SA_DEM
|
837
|
+
names_inDEM = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
|
838
|
+
if len(names_inDEM) != 0 :
|
839
|
+
dialog = wx.MessageDialog(None, f"The DEM_FILES folder is not empty and contains the files {names_inDEM}. ", "Confirmation", wx.YES_NO | wx.ICON_QUESTION)
|
840
|
+
dialog.SetYesNoLabels("Delete and reload", "Keep and leave")
|
841
|
+
response = dialog.ShowModal()
|
842
|
+
if response == wx.ID_YES:
|
843
|
+
for file_name in names_inDEM:
|
844
|
+
file_path = os.path.join(path, file_name)
|
845
|
+
os.remove(file_path)
|
846
|
+
logging.info("Files in DEM_FILES deleted.")
|
847
|
+
else :
|
848
|
+
logging.info("No update of DEM_FILES.")
|
849
|
+
return
|
850
|
+
|
851
|
+
|
852
|
+
#DEM and masked DEM creation
|
853
|
+
with wx.FileDialog(self, "Please select the DEM file in .tif format (without modifications).", wildcard="TIFF files (*.tif)|*.tif",
|
854
|
+
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as dlg:
|
855
|
+
if dlg.ShowModal() == wx.ID_OK:
|
856
|
+
path_DEM_base = dlg.GetPath()
|
857
|
+
logging.info("DEM file selected.")
|
327
858
|
|
328
|
-
|
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
|
+
|
897
|
+
|
898
|
+
def OnInterpolation(self,e):
|
899
|
+
"""Interpolates the last extracted time steps present in LAST_STEP_EXTRACTED using the fast marching
|
900
|
+
interpolation routine holes.exe, by creating a batch file
|
901
|
+
while performing multiple checks on the required input files."""
|
902
|
+
if not hasattr(self, 'file_paths'):
|
903
|
+
with wx.MessageDialog(self,
|
904
|
+
f"Please, first load gpu simulations via the previous button.",
|
905
|
+
"Attention",
|
906
|
+
style=wx.OK | wx.ICON_ERROR) as dlg:
|
907
|
+
dlg.ShowModal()
|
908
|
+
return
|
909
|
+
|
910
|
+
checked_indices = self._check_listbox.GetCheckedItems()
|
911
|
+
checked_items = [self._check_listbox.GetString(index) for index in checked_indices]
|
912
|
+
selected_paths = [self.file_paths[item] for item in checked_items]
|
913
|
+
path_simulations = self.datadir_simulations
|
914
|
+
|
915
|
+
path_LastSteps = Path(self._manager.IN_SA_EXTRACTED)
|
916
|
+
fn_write = None
|
917
|
+
dx,dy,nbx,nby,X,Y = False, False, False, False, False, False
|
918
|
+
for sim_ in selected_paths:
|
919
|
+
if sim_.name.startswith("sim_"):
|
920
|
+
self.sims[sim_.name] = sim_
|
921
|
+
fn_read = Path(path_simulations/ sim_ / "simul_gpu_results")
|
922
|
+
logging.info(f"Found simulation folder: {sim_}")
|
923
|
+
parts = sim_.name.split("sim_")
|
329
924
|
if len(parts) > 1:
|
330
925
|
name = parts[1]
|
331
|
-
fn_write = Path(path_LastSteps /
|
332
|
-
|
926
|
+
fn_write = Path(path_LastSteps / name )
|
927
|
+
dx,dy,nbx,nby,X,Y = display_info_header(self.input_dx, self.input_nbxy, self.input_O, fn_write.with_suffix(".bin"))
|
928
|
+
read_export_z_bin(fn_read, fn_write, path_LastSteps)
|
333
929
|
else:
|
334
930
|
logging.info(f"Please, ensure your simulations are named with the return period, e.g sim_T4")
|
335
|
-
|
336
931
|
else:
|
337
932
|
logging.info('No folder found / selected. Please try again...')
|
338
|
-
|
339
|
-
|
340
|
-
path_Interp = Path(self._manager.IN_SA_INTERP)
|
341
|
-
bat_file_path = os.path.join(self._manager.IN_SCEN_DIR, "process_files.bat")
|
342
|
-
if os.path.exists(bat_file_path):
|
343
|
-
logging.info(f"The file {bat_file_path} already exists and will be replaced.")
|
344
|
-
os.remove(bat_file_path)
|
345
|
-
path_code = os.path.join(self._manager.IN_WATER_DEPTH, "holes.exe")
|
933
|
+
else:
|
934
|
+
logging.error('No simulation selected! Please select some in the checkbox.')
|
346
935
|
|
347
936
|
C = None
|
348
937
|
D = None
|
349
|
-
|
350
938
|
for file in os.listdir(Path(self._manager.IN_SA_DEM)):
|
351
939
|
file_path = Path(self._manager.IN_SA_DEM) / file
|
352
|
-
|
353
940
|
if file_path.is_file() and file.startswith("MNT_") and file_path.suffix == ".bin":
|
354
941
|
if "mask" not in file:
|
355
942
|
D = file_path
|
356
943
|
else:
|
357
|
-
C = file_path
|
358
|
-
|
944
|
+
C = file_path
|
359
945
|
if D == None:
|
360
|
-
logging.info("DEM (.bin) not found. The file must begins by '
|
946
|
+
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",
|
950
|
+
style=wx.OK | wx.ICON_INFORMATION) as dlg:
|
951
|
+
dlg.ShowModal()
|
952
|
+
return
|
361
953
|
|
362
954
|
if C == None:
|
363
|
-
logging.info("DEM mask (.bin) not found. The file must begins by '
|
955
|
+
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",
|
959
|
+
style=wx.OK | wx.ICON_INFORMATION) as dlg:
|
960
|
+
dlg.ShowModal()
|
961
|
+
return
|
364
962
|
|
365
|
-
|
366
|
-
|
963
|
+
if not get_header_comparison([fn_write.with_suffix(".bin"), C, D]):
|
964
|
+
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",
|
968
|
+
style=wx.OK | wx.ICON_INFORMATION) as dlg:
|
969
|
+
dlg.ShowModal()
|
970
|
+
return
|
367
971
|
|
972
|
+
checked_names = self._check_listbox.GetCheckedStrings()
|
973
|
+
if not checked_names:
|
974
|
+
logging.info("No items selected. Adding all paths.")
|
975
|
+
checked_paths = list(self.file_paths.values())
|
976
|
+
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
|
+
else:
|
978
|
+
logging.info("Adding only the selected simulations.")
|
979
|
+
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)) when you press OK, please wait."
|
368
981
|
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
982
|
+
if len(self.file_paths) == 0 :
|
983
|
+
with wx.MessageDialog(self, f"No files in EXTRACTED_LAST_STEP_WD. Please provide some or use the 'Load gpu simulation' button.",
|
984
|
+
"OK", wx.OK | wx.ICON_INFORMATION) as dlg:
|
985
|
+
dlg.ShowModal()
|
986
|
+
else :
|
987
|
+
path_Interp = Path(self._manager.IN_SA_INTERP)
|
988
|
+
path_bat_file = os.path.join(self._manager.IN_SCEN_DIR, "process_files.bat")
|
989
|
+
|
990
|
+
if os.path.exists(path_bat_file):
|
991
|
+
logging.info(f"The file {path_bat_file} already exists and will be replaced.")
|
992
|
+
os.remove(path_bat_file)
|
993
|
+
path_code = os.path.join(self._manager.IN_WATER_DEPTH, "holes.exe")
|
994
|
+
|
995
|
+
A=[]
|
996
|
+
for path in checked_paths:
|
997
|
+
parts = path.name.split("sim_")
|
998
|
+
A.extend([os.path.join(path_LastSteps, g) for g in os.listdir(path_LastSteps) if g.endswith(f"{parts[1]}.bin")])
|
999
|
+
B = [os.path.join(path_Interp, os.path.splitext(os.path.basename(f))[0]) for f in A]
|
1000
|
+
if not A or not B or not C or not D:
|
1001
|
+
logging.info("Missing files.")
|
1002
|
+
with wx.MessageDialog(self, f"The interpolation cannot go on, as some files are missing (see logs): please check the DEM_FILES or the EXTRACTED_LAST_STEP_WD folders.",
|
1003
|
+
"Missing files.", wx.OK | wx.ICON_INFORMATION) as dlg:
|
1004
|
+
dlg.ShowModal()
|
1005
|
+
with open(path_bat_file, "w") as bat_file:
|
1006
|
+
for a, b in zip(A, B):
|
1007
|
+
line = f'"{path_code}" filling in="{a}" out="{b}" mask="{C}" dem="{D}"\n'
|
1008
|
+
bat_file.write(line)
|
1009
|
+
logging.info(message_info)
|
1010
|
+
with wx.MessageDialog(self, message_info,
|
378
1011
|
"Redirecting", wx.OK | wx.ICON_INFORMATION) as dlg:
|
379
1012
|
dlg.ShowModal()
|
380
|
-
|
381
1013
|
empty_folder(self._manager.IN_SA_INTERP)
|
382
|
-
|
1014
|
+
path_bat_file = os.path.join(self._manager.IN_SCEN_DIR, "process_files.bat")
|
1015
|
+
subprocess.run([path_bat_file], check=True)
|
383
1016
|
|
384
1017
|
renamed_files = []
|
385
1018
|
path_fichier=self._manager.IN_SA_INTERP
|
@@ -388,7 +1021,7 @@ class AcceptabilityGui(wx.Frame):
|
|
388
1021
|
new_name = file.stem.split("_h")[0].replace(".bin", "") + ".tif"
|
389
1022
|
file.rename(file.with_name(new_name))
|
390
1023
|
renamed_files.append(new_name)
|
391
|
-
#
|
1024
|
+
#deleting the other
|
392
1025
|
for file in path_fichier.glob("*.tif"):
|
393
1026
|
if "_combl" in file.name or file.name not in renamed_files:
|
394
1027
|
file.unlink()
|
@@ -396,17 +1029,66 @@ class AcceptabilityGui(wx.Frame):
|
|
396
1029
|
with wx.MessageDialog(self, f"Filling completed. Created files : {renamed_files}",
|
397
1030
|
"Redirecting", wx.OK | wx.ICON_INFORMATION) as dlg:
|
398
1031
|
dlg.ShowModal()
|
399
|
-
|
1032
|
+
update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
|
1033
|
+
|
400
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()
|
401
1082
|
|
402
1083
|
def OnMainDir(self, e):
|
403
|
-
|
1084
|
+
"""Selects the main directory to be read."""
|
1085
|
+
vanish_info_header(self.input_dx,self.input_nbxy,self.input_O)
|
404
1086
|
with wx.DirDialog(self, "Choose the main directory containing the data (folders INPUT, TEMP and OUTPUT):",
|
405
1087
|
style=wx.DD_DEFAULT_STYLE
|
406
1088
|
) as dlg:
|
407
1089
|
|
408
1090
|
if dlg.ShowModal() == wx.ID_OK:
|
409
|
-
self._manager = Accept_Manager(dlg.GetPath()
|
1091
|
+
self._manager = Accept_Manager(dlg.GetPath())
|
410
1092
|
|
411
1093
|
self._listbox_studyarea.Clear()
|
412
1094
|
self._listbox_studyarea.InsertItems(self._manager.get_list_studyareas(), 0)
|
@@ -420,6 +1102,16 @@ class AcceptabilityGui(wx.Frame):
|
|
420
1102
|
self._but_acceptability.Enable(True)
|
421
1103
|
self._but_vulnerability.Enable(True)
|
422
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
|
+
|
423
1115
|
else:
|
424
1116
|
logging.error(f"Missing files: {ret}")
|
425
1117
|
with wx.MessageDialog(self, f"Missing files: \n{ret}", "Error", wx.OK | wx.ICON_ERROR) as dlg:
|
@@ -430,10 +1122,9 @@ class AcceptabilityGui(wx.Frame):
|
|
430
1122
|
|
431
1123
|
def OnStudyArea(self, e):
|
432
1124
|
""" Change the study area """
|
433
|
-
|
434
1125
|
if self._manager is None:
|
435
1126
|
return
|
436
|
-
|
1127
|
+
vanish_info_header(self.input_dx,self.input_nbxy,self.input_O)
|
437
1128
|
study_area:str = self._manager.get_list_studyareas(with_suffix=True)[e.GetSelection()]
|
438
1129
|
self._manager.change_studyarea(study_area)
|
439
1130
|
|
@@ -459,106 +1150,305 @@ class AcceptabilityGui(wx.Frame):
|
|
459
1150
|
|
460
1151
|
self._listbox_returnperiods.Clear()
|
461
1152
|
rt = self._manager.get_return_periods()
|
1153
|
+
self._listbox_sims.Clear()
|
462
1154
|
if len(rt) != 0 :
|
463
1155
|
self._listbox_returnperiods.InsertItems([str(crt) for crt in rt],0)
|
464
1156
|
self._listbox_sims.Clear()
|
465
1157
|
sims = [str(self._manager.get_filepath_for_return_period(currt).name) for currt in rt]
|
466
1158
|
self._listbox_sims.InsertItems(sims, 0)
|
467
1159
|
ponds = self._manager.get_ponderations()
|
468
|
-
if isinstance(ponds,
|
1160
|
+
if isinstance(ponds, pd.DataFrame):
|
469
1161
|
self._axes.clear()
|
470
|
-
ponds.plot(ax=self._axes, kind='bar')
|
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)
|
471
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
|
+
|
472
1176
|
|
473
1177
|
def OnCreation(self, e):
|
474
1178
|
""" Create the database """
|
475
|
-
|
476
1179
|
if self._manager is None:
|
477
1180
|
return
|
478
1181
|
|
479
|
-
|
480
|
-
|
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
|
+
)
|
1220
|
+
def OnToggle(self,e):
|
1221
|
+
"""Creates a toggle button to be activated if the scenarios vuln_ have to be taken into account."""
|
1222
|
+
self.toggle_state = False
|
1223
|
+
if self._but_toggle_scen.GetValue():
|
1224
|
+
logging.info("Activating the scenario button.")
|
1225
|
+
self._but_toggle_scen.SetBackgroundColour(wx.Colour(175, 175, 175))
|
1226
|
+
self._but_toggle_scen_state = True
|
1227
|
+
tif_files = [file for file in Path(self._manager.IN_CH_SA_SC).glob("*.tif") if file.name.startswith("vuln_")]
|
1228
|
+
if not tif_files:
|
1229
|
+
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 and extract gpu simulations' and edit it, or directly introduce your 'vuln_' files.",
|
481
1231
|
"Information",
|
482
1232
|
wx.OK | wx.ICON_INFORMATION
|
483
1233
|
)
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
1234
|
+
logging.info("Desactivating the scenario button.")
|
1235
|
+
self._but_toggle_scen.SetValue(False)
|
1236
|
+
self._but_toggle_scen.SetBackgroundColour(wx.NullColour)
|
1237
|
+
self._but_toggle_scen_state = False
|
1238
|
+
else :
|
1239
|
+
self.toggle_state = True
|
1240
|
+
else:
|
1241
|
+
self._but_toggle_scen.SetBackgroundColour(wx.NullColour)
|
1242
|
+
self.toggle_state = False
|
1243
|
+
logging.info("Desactivating the scenario button.")
|
1244
|
+
|
1245
|
+
def OnToggleResampling(self,e):
|
1246
|
+
"""Creates a toggle button for the acceptability resampling to be activated."""
|
1247
|
+
self.toggle_resamp_state = False
|
1248
|
+
toggle = self._but_toggle_resamp
|
1249
|
+
if toggle.GetValue():
|
1250
|
+
self._but_toggle_resamp.SetBackgroundColour(wx.Colour(175, 175, 175))
|
1251
|
+
self.toggle_resamp_state = True
|
1252
|
+
logging.info("Resampling activated")
|
1253
|
+
current_res = self._but_resampling.GetValue()
|
1254
|
+
resolution = self.input_dx.GetLabel()
|
1255
|
+
if resolution != '':
|
1256
|
+
values = resolution.strip("()").split(",")
|
1257
|
+
dx = float(values[0])
|
1258
|
+
#selection of size
|
1259
|
+
if current_res < dx:
|
1260
|
+
wx.MessageBox(
|
1261
|
+
"The resampling size cannot be inferior to the resolution. Please select another resampling size.",
|
1262
|
+
"Attention",
|
1263
|
+
wx.OK | wx.ICON_ERROR
|
1264
|
+
)
|
1265
|
+
self.toggle_resamp_state = False
|
1266
|
+
self._but_toggle_resamp.SetValue(False)
|
1267
|
+
self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
|
1268
|
+
logging.info("Resampling disactivated because of a bad resampling size.")
|
1269
|
+
else :
|
1270
|
+
logging.info(f"Allowed resampling value : {current_res}[m].")
|
1271
|
+
else:
|
1272
|
+
self.toggle_resamp_state = False
|
1273
|
+
self._but_toggle_resamp.SetValue(False)
|
1274
|
+
self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
|
1275
|
+
logging.info("No simulations in INTERP_WD.")
|
1276
|
+
|
1277
|
+
|
1278
|
+
else:
|
1279
|
+
self.toggle_resamp_state = False
|
1280
|
+
self._but_toggle_resamp.SetValue(False)
|
1281
|
+
self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
|
1282
|
+
logging.info("Resampling disactivated")
|
1283
|
+
|
1284
|
+
def OnCheckScenario(self,e):
|
1285
|
+
"""Checks if scenarios exist in CHANGE_VULNE."""
|
1286
|
+
tif_files = list(Path(self._manager.IN_CH_SA_SC).glob("vuln_*.tif"))
|
1287
|
+
logging.info("checking the scenarios for vulnerability and acceptability.")
|
1288
|
+
if not tif_files:
|
491
1289
|
wx.MessageBox(
|
492
|
-
"
|
1290
|
+
"No files 'vuln_' found in CHANGE_VULNE.",
|
493
1291
|
"Information",
|
494
1292
|
wx.OK | wx.ICON_INFORMATION
|
495
1293
|
)
|
496
|
-
else :
|
1294
|
+
else :
|
497
1295
|
wx.MessageBox(
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
)
|
502
|
-
|
1296
|
+
f"There exist vuln_ file(s) in CHANGE_VULNE: {', '.join([tif_file.name for tif_file in tif_files])}",
|
1297
|
+
"Information", wx.OK | wx.ICON_INFORMATION)
|
1298
|
+
|
503
1299
|
def OnVulnerability(self, e):
|
504
1300
|
""" Run the vulnerability """
|
505
1301
|
|
506
1302
|
if self._manager is None:
|
507
1303
|
return
|
508
|
-
|
1304
|
+
path = [self._manager.OUT_VULN]
|
509
1305
|
steps = list(self._steps_vulnerability.GetCheckedStrings())
|
510
|
-
steps = [int(cur.split('-')[1]) for cur in steps]
|
511
|
-
|
512
|
-
if
|
513
|
-
logging.error("No steps selected. By default every steps will be performed.")
|
514
|
-
Vulnerability(str(self._manager.main_dir),
|
515
|
-
scenario=str(self._manager.scenario),
|
516
|
-
Study_area=str(self._manager.Study_area),
|
517
|
-
steps=[1,10,11,2,3])
|
1306
|
+
steps = [int(cur.split('-')[1]) for cur in steps]
|
1307
|
+
resolution,_,_,_,_,_ =update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
|
1308
|
+
if resolution == '':
|
518
1309
|
wx.MessageBox(
|
519
|
-
"
|
520
|
-
"
|
521
|
-
wx.OK | wx.
|
1310
|
+
f"There are no files in INTERP_WD lease, use first the buttons at the second line.",
|
1311
|
+
"Attention",
|
1312
|
+
wx.OK | wx.ICON_ERROR
|
522
1313
|
)
|
523
|
-
|
524
1314
|
else :
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
)
|
534
|
-
|
1315
|
+
message_supp = "."
|
1316
|
+
if len(steps) == 0:
|
1317
|
+
steps = [1,10,11,2,3]
|
1318
|
+
if self.toggle_state == True :
|
1319
|
+
message_supp = " AND scenario(s) vuln_ taken into account"
|
1320
|
+
steps = [1,10,11,2,3,4]
|
1321
|
+
if self._manager.OUT_VULN.exists:
|
1322
|
+
message_supp = " FOR scenario(s) (vuln_ taken into account)"
|
1323
|
+
logging.info("Attention - The manager ONLY computes Vulnerability_scenario, as Vulnerability_baseline already computed.")
|
1324
|
+
steps=[4]
|
1325
|
+
else :
|
1326
|
+
logging.info("Attention - The manager computes also Vulnerability_baseline, as Vulnerability_scenario needs it as input.")
|
1327
|
+
path = [self._manager.OUT_VULN_Stif]
|
1328
|
+
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
|
+
dialog.SetYesNoLabels("Done, continue", "Not done, stop")
|
1330
|
+
response = dialog.ShowModal()
|
1331
|
+
if response == wx.ID_NO:
|
1332
|
+
return
|
1333
|
+
|
1334
|
+
logging.info("No steps selected. By default every steps will be performed" + message_supp)
|
1335
|
+
Vulnerability(str(self._manager.main_dir),
|
1336
|
+
scenario=str(self._manager.scenario),
|
1337
|
+
Study_area=str(self._manager.Study_area),
|
1338
|
+
resolution=resolution,
|
1339
|
+
steps=steps)
|
1340
|
+
wx.MessageBox(
|
1341
|
+
"Vulnerability computed with every steps" + message_supp,
|
1342
|
+
"Information",
|
1343
|
+
wx.OK | wx.ICON_INFORMATION
|
1344
|
+
)
|
1345
|
+
else :
|
1346
|
+
if self.toggle_state == True :
|
1347
|
+
steps.append(4)
|
1348
|
+
message_supp = " AND scenario(s) vuln_ taken into account"
|
1349
|
+
if self._manager.OUT_VULN.exists:
|
1350
|
+
message_supp = " FOR scenario(s) (vuln_ taken into account)"
|
1351
|
+
logging.info("Attention - The manager ONLY computes Vulnerability_scenario, as Vulnerability_baseline already computed.")
|
1352
|
+
steps=[4]
|
1353
|
+
else :
|
1354
|
+
logging.info("Attention - The manager computes also Vulnerability_baseline, as Vulnerability_scenario needs it as input.")
|
1355
|
+
|
1356
|
+
path = [self._manager.OUT_VULN_Stif]
|
1357
|
+
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
|
+
dialog.SetYesNoLabels("Done, continue", "Not done, stop")
|
1359
|
+
response = dialog.ShowModal()
|
1360
|
+
if response == wx.ID_NO:
|
1361
|
+
return
|
1362
|
+
|
1363
|
+
Vulnerability(self._manager.main_dir,
|
1364
|
+
scenario=self._manager.scenario,
|
1365
|
+
Study_area=self._manager.Study_area,
|
1366
|
+
resolution=resolution,
|
1367
|
+
steps=steps)
|
1368
|
+
wx.MessageBox(
|
1369
|
+
"Vulnerability computed with the selected steps" + message_supp,
|
1370
|
+
"Information",
|
1371
|
+
wx.OK | wx.ICON_INFORMATION
|
1372
|
+
)
|
1373
|
+
mapviewer_display(path)
|
1374
|
+
|
535
1375
|
def OnAcceptability(self, e):
|
536
1376
|
""" Run the acceptability """
|
537
|
-
|
538
1377
|
if self._manager is None:
|
539
1378
|
return
|
1379
|
+
|
1380
|
+
river_trace = self._manager.wich_river_trace()
|
1381
|
+
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 )
|
1383
|
+
return
|
1384
|
+
|
1385
|
+
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 )
|
1387
|
+
return
|
540
1388
|
|
541
1389
|
steps = list(self._steps_acceptability.GetCheckedStrings())
|
542
1390
|
steps = [int(cur.split('-')[1]) for cur in steps]
|
543
|
-
|
1391
|
+
message_supp = "."
|
1392
|
+
resampling=100
|
1393
|
+
path = [self._manager.OUT_ACCEPT]
|
544
1394
|
if len(steps) == 0:
|
545
|
-
|
1395
|
+
steps = [1,2,3,4]
|
1396
|
+
if self.toggle_state == True :
|
1397
|
+
steps = [1,2,3,4,5]
|
1398
|
+
message_supp = " AND scenario(s) vuln_ taken into account"
|
1399
|
+
path = [self._manager.OUT_ACCEPT_Stif]
|
1400
|
+
if self._manager.OUT_ACCEPT.exists:
|
1401
|
+
steps = [x for x in steps if x != 4]
|
1402
|
+
logging.info('Acceptability_baseline not computed because it already exists.')
|
1403
|
+
message_supp = " FOR scenario(s) vuln_ taken into account"
|
1404
|
+
|
1405
|
+
if river_trace == self._manager.OUT_MASKED_RIVER : message_supp=message_supp +" WITH the _baseline riverbed trace."
|
1406
|
+
if river_trace == self._manager.OUT_MASKED_RIVER_S :message_supp+= " WITH the _scenarios riverbed trace."
|
1407
|
+
if self.toggle_resamp_state == True :
|
1408
|
+
steps.append(6)
|
1409
|
+
resampling = self._but_resampling.GetValue()
|
1410
|
+
resolution = self.input_dx.GetLabel()
|
1411
|
+
if resolution != '':
|
1412
|
+
values = resolution.strip("()").split(",")
|
1413
|
+
resolution = float(values[0])
|
1414
|
+
|
1415
|
+
message_supp+= f" It has been created for the resolution {resolution}m and the resampling size {resampling}m."
|
1416
|
+
|
1417
|
+
logging.info("No steps selected. By default every steps will be performed.")
|
546
1418
|
Acceptability(self._manager.main_dir,
|
547
1419
|
scenario=self._manager.scenario,
|
548
1420
|
Study_area=self._manager.Study_area,
|
549
|
-
|
1421
|
+
resample_size=resampling,
|
1422
|
+
steps=steps)
|
550
1423
|
wx.MessageBox(
|
551
|
-
"Acceptability computed with every steps
|
1424
|
+
"Acceptability computed with every steps" + message_supp,
|
552
1425
|
"Information",
|
553
1426
|
wx.OK | wx.ICON_INFORMATION
|
554
1427
|
)
|
555
1428
|
else :
|
1429
|
+
if self.toggle_state == True :
|
1430
|
+
steps.append(5)
|
1431
|
+
message_supp = " AND scenario(s) vuln_ taken into account"
|
1432
|
+
if self._manager.OUT_ACCEPT.exists:
|
1433
|
+
steps = [x for x in steps if x != 4]
|
1434
|
+
logging.info('Acceptability_baseline not computed because it already exists.')
|
1435
|
+
message_supp = "FOR scenario(s) (vuln_taken into account)"
|
1436
|
+
path = [self._manager.OUT_ACCEPT_Stif]
|
1437
|
+
river_trace = self._manager.wich_river_trace()
|
1438
|
+
if river_trace == self._manager.OUT_MASKED_RIVER : message_supp =message_supp + " WITH the _baseline riverbed trace."
|
1439
|
+
if river_trace == self._manager.OUT_MASKED_RIVER_S : message_supp =message_supp + " WITH the _scenarios riverbed trace."
|
1440
|
+
if self.toggle_resamp_state == True :
|
1441
|
+
resampling = self._but_resampling.GetValue()
|
1442
|
+
steps.append(6)
|
1443
|
+
|
556
1444
|
Acceptability(self._manager.main_dir,
|
557
1445
|
scenario=self._manager.scenario,
|
558
1446
|
Study_area=self._manager.Study_area,
|
1447
|
+
resample_size=resampling,
|
559
1448
|
steps=steps)
|
560
1449
|
wx.MessageBox(
|
561
|
-
"Acceptability computed with the selected steps
|
1450
|
+
"Acceptability computed with the selected steps" + message_supp,
|
562
1451
|
"Information",
|
563
1452
|
wx.OK | wx.ICON_INFORMATION
|
564
|
-
)
|
1453
|
+
)
|
1454
|
+
mapviewer_display(path)
|