wolfhece 2.1.124__py3-none-any.whl → 2.1.126__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.
@@ -41,7 +41,7 @@ def nullvalue_for_hole(WA):
41
41
  Sets the null value for a WolfArray to 0 (as per the convention in the interpolation routine).
42
42
  """
43
43
  WA.nullvalue = 0.
44
- WA.set_nullvalue_in_mask()
44
+ WA.set_nullvalue_in_mask()
45
45
 
46
46
  def read_export_z_bin(fn_read, fn_write, fn_laststep):
47
47
  """
@@ -59,15 +59,15 @@ def read_export_z_bin(fn_read, fn_write, fn_laststep):
59
59
  top = wolfres2DGPU_test.get_top_for_block(1)
60
60
  nullvalue_for_hole(wd)
61
61
  nullvalue_for_hole(top)
62
- wd.array = wd.array + top.array
62
+ wd.array = wd.array + top.array
63
63
  fn_write = fn_write.with_suffix('.bin')
64
64
  wd.write_all(fn_write)
65
65
  shutil.rmtree(fn_temp)
66
-
66
+
67
67
  def riverbed_trace(fn_read_simu, fn_output, threshold):
68
68
  """
69
- Recognizes the riverbed trace based on a simulation, where water depth above a given threshold is considered part of the riverbed.
70
- 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:
71
71
  - fn_read_simu: the simulation file to read.
72
72
  - fn_output: the location to save the riverbed trace as a .tiff file.
73
73
  - threshold: the water depth threshold above which the areas are considered riverbed.
@@ -80,7 +80,7 @@ def riverbed_trace(fn_read_simu, fn_output, threshold):
80
80
  wd.array[wd.array < threshold] = 0
81
81
  wd.as_WolfArray()
82
82
  wd.nodata=0
83
- wd.write_all(Path(fn_output))
83
+ wd.write_all(Path(fn_output))
84
84
 
85
85
  def empty_folder(folder):
86
86
  """
@@ -91,9 +91,9 @@ def empty_folder(folder):
91
91
  fn = os.path.join(folder, files)
92
92
  try:
93
93
  if os.path.isfile(fn) or os.path.islink(fn):
94
- os.unlink(fn)
94
+ os.unlink(fn)
95
95
  elif os.path.isdir(fn):
96
- shutil.rmtree(fn)
96
+ shutil.rmtree(fn)
97
97
  except Exception as e:
98
98
  print(f"Error when deleting file {fn}: {e}")
99
99
  else:
@@ -118,7 +118,7 @@ Note: the computations are perfomed with tifs .tif rasters but should be transla
118
118
  #----------------------------------------------------------------------------------------------------------
119
119
 
120
120
  #1 - Soustraction bathymetry.tif (from simulations) - DEM (MNT, cfr "projet tuilage") ---------------------
121
-
121
+
122
122
  def soustraction(fn_a,fn_b,fn_result):
123
123
  with rasterio.open(fn_a) as src_a, rasterio.open(fn_b) as src_b:
124
124
  if (
@@ -128,35 +128,35 @@ def soustraction(fn_a,fn_b,fn_result):
128
128
  src_a.crs != src_b.crs
129
129
  ):
130
130
  logging.error(f"{fn_a} and {fn_b} do not have the same properties, please edit them.")
131
-
132
131
 
133
- data_a = src_a.read(1)
134
- data_b = src_b.read(1)
135
-
132
+
133
+ data_a = src_a.read(1)
134
+ data_b = src_b.read(1)
135
+
136
136
  #(A - B)
137
137
  data_diff = data_a - data_b
138
138
  nodata_value = src_a.nodata if src_a.nodata == src_b.nodata else None
139
139
  if nodata_value is not None:
140
140
  data_diff[(data_a == nodata_value) | (data_b == nodata_value)] = nodata_value
141
-
141
+
142
142
  data_diff[data_diff > 5000] = 0
143
143
  labeled, n = label(data_diff)
144
144
  # Remove small objects
145
- threshold = 5
145
+ threshold = 5
146
146
  sizes = np.bincount(labeled.ravel())
147
- idx_small = np.where(sizes <= threshold)[0]
148
- data_diff[np.isin(labeled, idx_small)] = 0
149
-
147
+ idx_small = np.where(sizes <= threshold)[0]
148
+ data_diff[np.isin(labeled, idx_small)] = 0
149
+
150
150
  out_meta = src_a.meta.copy()
151
151
  out_meta.update({
152
- "dtype": "float32",
152
+ "dtype": "float32",
153
153
  "driver": "GTiff"
154
154
  })
155
155
 
156
156
  with rasterio.open(fn_result, "w", **out_meta) as dst:
157
157
  dst.write(data_diff, 1)
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:
@@ -169,35 +169,35 @@ def mask_creation_data(mask_file, ground_file, output_file):
169
169
  bathy = bathy_src.read(1)
170
170
 
171
171
  mask[indices] = bathy[indices]
172
- mask[mask <= 0] = 275
173
-
172
+ mask[mask <= 0] = 9999.
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
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),
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
192
  if not used, indicate None to ignore it."""
193
- base_pathwd = Path(maindir) / "INPUT" / "WATER_DEPTH" / study_area / scenario
193
+ base_pathwd = Path(maindir) / "INPUT" / "WATER_DEPTH" / study_area / scenario
194
194
  subfolders = ["DEM_FILES", "INTERP_WD", "EXTRACTED_LAST_STEP_WD"]
195
195
  os.makedirs(base_pathwd, exist_ok=True)
196
196
  for folder in subfolders:
197
197
  os.makedirs(os.path.join(base_pathwd, folder), exist_ok=True)
198
- base_pathch = Path(maindir) / "INPUT" / "CHANGE_VULNE" / study_area / scenario
198
+ base_pathch = Path(maindir) / "INPUT" / "CHANGE_VULNE" / study_area / scenario
199
199
  os.makedirs(base_pathch, exist_ok=True)
200
-
200
+
201
201
  if simu_gpu != None:
202
202
  path_bat_gpu = Path(simu_gpu) / "bathymetry.tif"
203
203
  if path_bat_gpu.exists():
@@ -228,17 +228,17 @@ def create_shapefile_from_prop_tif(fn_tif, shapefile_path):
228
228
  - shapefile_path: the location to save the output shapefile.
229
229
  """
230
230
  _,_,width,height,_,_ = get_header_info(fn_tif)
231
- transform, crs = get_transform_and_crs(fn_tif)
231
+ transform, crs = get_transform_and_crs(fn_tif)
232
232
  top_left = transform * (0, 0)
233
233
  bottom_left = transform * (0, height)
234
234
  top_right = transform * (width, 0)
235
235
  bottom_right = transform * (width, height)
236
-
236
+
237
237
  rectangle = Polygon([top_left, top_right, bottom_right, bottom_left, top_left])
238
238
  gdf = gpd.GeoDataFrame({'geometry': [rectangle]})
239
239
  gdf.set_crs(crs, allow_override=True, inplace=True)
240
240
  gdf.to_file(shapefile_path)
241
-
241
+
242
242
  def get_header_info(fn):
243
243
  """
244
244
  Reads the headers from the file at path 'fn'.
@@ -258,8 +258,8 @@ def get_header_comparison(list_fn):
258
258
  header_infos = [get_header_info(fn) for fn in list_fn]
259
259
  variable_names = ["dx", "dy", "nbx", "nby", "X", "Y"]
260
260
  for idx, name in enumerate(variable_names):
261
- values = [header[idx] for header in header_infos]
262
- if len(set(values)) > 1:
261
+ values = [header[idx] for header in header_infos]
262
+ if len(set(values)) > 1:
263
263
  comp = False
264
264
  else:
265
265
  comp = True
@@ -273,13 +273,13 @@ def display_info_header(self_dx, self_nbxy, self_O, fn):
273
273
  dx,dy,nbx,nby,X,Y= get_header_info(fn)
274
274
  self_dx.SetLabel(f"({dx},{dy})")
275
275
  self_nbxy.SetLabel(f"({nbx},{nby})")
276
- self_O.SetLabel(f"({X},{Y})")
276
+ self_O.SetLabel(f"({X},{Y})")
277
277
  return dx,dy,nbx,nby,X,Y
278
-
278
+
279
279
  def vanish_info_header(self_dx, self_nbxy, self_O):
280
280
  self_dx.SetLabel("")
281
281
  self_nbxy.SetLabel("")
282
- self_O.SetLabel("")
282
+ self_O.SetLabel("")
283
283
 
284
284
  def update_info_header(self_dx, self_nbxy, self_O, fn):
285
285
  """
@@ -287,11 +287,11 @@ def update_info_header(self_dx, self_nbxy, self_O, fn):
287
287
  """
288
288
  if not os.path.exists(fn):
289
289
  os.makedirs(fn)
290
-
290
+
291
291
  tif_files = [f for f in os.listdir(fn) if f.lower().endswith('.tif')]
292
292
  tif_list_fn = [os.path.join(fn, tif_file) for tif_file in tif_files]
293
- if tif_files:
294
- if get_header_comparison(tif_list_fn) :
293
+ if tif_files:
294
+ if get_header_comparison(tif_list_fn) :
295
295
  dx,dy,nbx,nby,X,Y = display_info_header(self_dx, self_nbxy, self_O, tif_list_fn[0])
296
296
  return dx,dy,nbx,nby,X,Y
297
297
  else:
@@ -299,8 +299,8 @@ def update_info_header(self_dx, self_nbxy, self_O, fn):
299
299
  return False, False, False, False, False, False
300
300
  else :
301
301
  vanish_info_header(self_dx, self_nbxy, self_O)
302
- return False, False, False, False, False, False
303
-
302
+ return False, False, False, False, False, False
303
+
304
304
  def search_for_modif_bath_and_copy(main_gpu, from_path, path_vuln):
305
305
  """
306
306
  When loading gpu simulations for last step extraction, search for modified bath_ topography file, according to
@@ -313,9 +313,9 @@ def search_for_modif_bath_and_copy(main_gpu, from_path, path_vuln):
313
313
  curdicts = scen_manager.get_dicts(curtree)
314
314
  all_tif_bath = [scen_manager._select_tif_partname(curdict, 'bath_') for curdict in curdicts]
315
315
  all_tif_bath = [curel for curlist in all_tif_bath if len(curlist)>0 for curel in curlist if curel.name.startswith('bath_')]
316
- if len(all_tif_bath) :
316
+ if len(all_tif_bath) :
317
317
  found_bath = True
318
- for tif_file in all_tif_bath:
318
+ for tif_file in all_tif_bath:
319
319
  found_bath = True
320
320
  with rasterio.open(tif_file) as src:
321
321
  #vuln_ files
@@ -331,7 +331,7 @@ def search_for_modif_bath_and_copy(main_gpu, from_path, path_vuln):
331
331
  output_file = path_vuln / tif_file.name.replace('bath_', 'MNTmodifs_')
332
332
  with rasterio.open(output_file, 'w', **metadata) as dst:
333
333
  dst.write(data, 1)
334
-
334
+
335
335
  return found_bath
336
336
 
337
337
  def mapviewer_display(list_path):
@@ -342,7 +342,7 @@ def mapviewer_display(list_path):
342
342
  dlg.Destroy()
343
343
  if ret != wx.ID_YES:
344
344
  return
345
-
345
+
346
346
  mapviewer = WolfMapViewer(title="OUTPUT Acceptability manager")
347
347
  for path in list_path:
348
348
  myarray = WolfArray(path)
@@ -374,74 +374,74 @@ class AcceptabilityGui(wx.Frame):
374
374
  raise TypeError("The mapviewer must be a WolfMapViewer")
375
375
 
376
376
  self._mapviewer = value
377
-
377
+
378
378
  def OnHoverEnter(self, event):
379
379
  """Dynamic colour layout 1"""
380
- self._but_creation.SetBackgroundColour(wx.Colour(100,100,100))
380
+ self._but_creation.SetBackgroundColour(wx.Colour(100,100,100))
381
381
  self._but_creation.Refresh()
382
382
  event.Skip()
383
383
 
384
384
  def OnHoverLeave(self, event):
385
385
  """Dynamic colour layout 2"""
386
- self._but_creation.SetBackgroundColour(wx.Colour(150,150,150))
386
+ self._but_creation.SetBackgroundColour(wx.Colour(150,150,150))
387
387
  self._but_creation.Refresh()
388
388
  event.Skip()
389
-
389
+
390
390
  def layout(self, self_fct):
391
391
  """Update the layers for the main buttons"""
392
392
  font = self_fct.GetFont()
393
393
  font.SetWeight(wx.FONTWEIGHT_BOLD)
394
394
  self_fct.SetFont(font)
395
- self_fct.SetBackgroundColour(wx.Colour(150,150,150))
395
+ self_fct.SetBackgroundColour(wx.Colour(150,150,150))
396
396
  self_fct.Bind(wx.EVT_ENTER_WINDOW, self.OnHoverEnter)
397
397
  self_fct.Bind(wx.EVT_LEAVE_WINDOW, self.OnHoverLeave)
398
-
398
+
399
399
  def on_button_click(self, event):
400
400
  self.PopupMenu(self.menu)
401
401
 
402
402
  def on_menu_click(self, event):
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
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
405
405
  a no-overflow simulation, allowing the code to create the trace."""
406
406
  menu_id = event.GetId()
407
- if menu_id == 1:
407
+ if menu_id == 1:
408
408
  logging.info("Option 1 : the file exists, pointing towards it.")
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,
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,
411
411
  wildcard="TIFF files (*.tiff)|*.tiff")
412
412
 
413
413
  if dlg.ShowModal() == wx.ID_OK:
414
- selected_file = Path(dlg.GetPath())
414
+ selected_file = Path(dlg.GetPath())
415
415
  copied_file = self._manager.OUT_SCEN_DIR / "copy_file"
416
416
  shutil.copy(selected_file, copied_file)
417
417
  logging.info(f"File copied to: {copied_file}")
418
-
418
+
419
419
  new_name = self._manager.OUT_MASKED_RIVER_S
420
-
420
+
421
421
  with wx.MessageDialog(self, f"Modified riverbed imported and called Masked_River_extent_scenarios.tiff.",
422
422
  "File imported.", wx.OK | wx.ICON_INFORMATION) as dlg:
423
423
  dlg.ShowModal()
424
-
424
+
425
425
  if new_name.exists():
426
426
  new_name.unlink()
427
-
427
+
428
428
  copied_file.rename(new_name)
429
429
  logging.info(f"File renamed to: {new_name}")
430
430
  else:
431
431
  logging.info('No file selected. Please try again.')
432
-
432
+
433
433
  elif menu_id == 2: #No file, so need to create
434
434
  logging.info("Option 2 : pointing to simulation with low discharge (no overflows!).")
435
-
435
+
436
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:
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}")
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}")
441
441
  fn_output = self._manager.OUT_MASKED_RIVER_S
442
442
  dlg = wx.TextEntryDialog(self, "What water depth threshold (in meters) should be used to define the riverbed trace, above which\n"
443
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)", "")
444
-
444
+
445
445
  if dlg.ShowModal() == wx.ID_OK:
446
446
  while True:
447
447
  try:
@@ -475,11 +475,11 @@ class AcceptabilityGui(wx.Frame):
475
475
 
476
476
  else:
477
477
  logging.info("Cancelled.")
478
- dlg.Destroy()
478
+ dlg.Destroy()
479
479
  else:
480
480
  logging.info("No folder (or wrong one) selected. Please try again (must be simul_gpu_results).")
481
-
482
-
481
+
482
+
483
483
  def layout_listbox(self, self_fct):
484
484
  """Changes the layout for the listbox : light grey."""
485
485
  self_fct.SetBackgroundColour(wx.Colour(220, 220, 220))
@@ -487,7 +487,7 @@ class AcceptabilityGui(wx.Frame):
487
487
  def InitUI(self):
488
488
  self.gpu_bathy = None
489
489
  self.maindir = None
490
-
490
+
491
491
  sizer_hor_main = wx.BoxSizer(wx.HORIZONTAL)
492
492
  sizer_vert1 = wx.BoxSizer(wx.VERTICAL)
493
493
  sizer_hor_threads = wx.BoxSizer(wx.HORIZONTAL)
@@ -504,17 +504,17 @@ class AcceptabilityGui(wx.Frame):
504
504
  self._but_maindir.SetToolTip("To indicate where the main acceptability\n folder is located.")
505
505
  self._but_maindir.SetFont(wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
506
506
  self._but_maindir.Bind(wx.EVT_BUTTON, self.OnMainDir)
507
-
507
+
508
508
  self._listbox_studyarea = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
509
509
  self.layout_listbox(self._listbox_studyarea)
510
510
  self._listbox_studyarea.Bind(wx.EVT_LISTBOX, self.OnStudyArea)
511
511
  self._listbox_studyarea.SetToolTip("Choose the study area existed in the folder.")
512
512
 
513
513
  self._listbox_scenario = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
514
- self.layout_listbox(self._listbox_scenario)
514
+ self.layout_listbox(self._listbox_scenario)
515
515
  self._listbox_scenario.Bind(wx.EVT_LISTBOX, self.OnScenario)
516
516
  self._listbox_scenario.SetToolTip("Choose the acceptability scenario.")
517
-
517
+
518
518
  sizer_ver_small = wx.BoxSizer(wx.VERTICAL)
519
519
  self._but_checkfiles = wx.Button(panel, label='Check structure')
520
520
  self._but_checkfiles.Bind(wx.EVT_BUTTON, self.OnCheckFiles)
@@ -522,21 +522,21 @@ class AcceptabilityGui(wx.Frame):
522
522
  self._but_checksim = wx.Button(panel, label='Check simulations')
523
523
  self._but_checksim.SetToolTip("Displays the loaded simulations, interpolated in INTERP_WD.")
524
524
  self._but_checksim.Bind(wx.EVT_BUTTON, self.OnHydrodynInput)
525
-
525
+
526
526
  self._but_checkpond= wx.Button(panel, label='Check ponderation')
527
527
  self._but_checkpond.Bind(wx.EVT_BUTTON, self.OnCheckPond)
528
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
529
+
530
+ # 2nd LINE - Hydrodynamic part
531
531
  self._but_loadgpu = wx.Button(panel, label='Load new\n hydraulic scenarios')
532
532
  self._but_loadgpu.SetToolTip("To load or change the hydraulic simulations")
533
533
  self._but_loadgpu.SetFont(wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
534
534
  self._but_loadgpu.Bind(wx.EVT_BUTTON, self.OnLoadingSimu)
535
535
  sizer_hor1_1.Add(self._but_loadgpu, 1, wx.ALL | wx.EXPAND, 0)
536
-
536
+
537
537
 
538
538
  self._check_listbox = wx.CheckListBox(panel, choices=[], style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
539
- self.layout_listbox(self._check_listbox)
539
+ self.layout_listbox(self._check_listbox)
540
540
  self.sims = {}
541
541
  sizer_hor1_1.Add(self._check_listbox, 1, wx.ALL | wx.EXPAND, 0) #ajouter!! sinon s'affiche pas
542
542
 
@@ -544,7 +544,7 @@ class AcceptabilityGui(wx.Frame):
544
544
  self._but_DEM.SetToolTip("To display the existing DEM input for the interpolation of the simulated free surfaces.")
545
545
  self._but_DEM.Bind(wx.EVT_BUTTON, self.OnDEM)
546
546
  sizer_hor1_1.Add(self._but_DEM, 1, wx.ALL | wx.EXPAND, 0)
547
-
547
+
548
548
  self._but_extrinterp = wx.Button(panel, label='Reading and interpolating\n free surface')
549
549
  self._but_extrinterp.SetToolTip("To read the simulation, and created the hydraulic input for\n acceptability (interpolated simulated free surfaces)")
550
550
  self._but_extrinterp.Bind(wx.EVT_BUTTON, self.OnInterpolation)
@@ -569,7 +569,7 @@ class AcceptabilityGui(wx.Frame):
569
569
  text_threads = wx.StaticText(panel, label='Number of threads:')
570
570
  self._nb_process = wx.SpinCtrl(panel, value=str(os.cpu_count()), min=1, max=os.cpu_count())
571
571
  self._nb_process.SetToolTip("Number of threads to be used in the computations.")
572
-
572
+
573
573
  sizer_hor_threads.Add(text_dx, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
574
574
  sizer_hor_threads.Add(self.input_dx, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
575
575
  sizer_hor_threads.Add(text_nbxy, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
@@ -578,26 +578,26 @@ class AcceptabilityGui(wx.Frame):
578
578
  sizer_hor_threads.Add(self.input_O, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
579
579
  sizer_hor_threads.Add(text_threads, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
580
580
  sizer_hor_threads.Add(self._nb_process, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
581
-
581
+
582
582
  # 3 last lines + scenarios
583
583
  #--------------------------
584
584
  self._but_creation = wx.Button(panel, label='DataBase Creation')
585
- self.layout(self._but_creation)
585
+ self.layout(self._but_creation)
586
586
  self._but_creation.Bind(wx.EVT_BUTTON, self.OnCreation)
587
-
587
+
588
588
  self._steps_db = wx.CheckListBox(panel, choices=steps_base_data_creation.get_list_names(), style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
589
589
 
590
590
  self._but_vulnerability = wx.Button(panel, label='Vulnerability')
591
- self.layout(self._but_vulnerability)
592
- 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)
593
593
  step_Vuln_without_withoutscenarios = [item for item in steps_vulnerability.get_list_names() if item != 'APPLY_SCENARIOSVULN - 4']
594
594
  self._steps_vulnerability = wx.CheckListBox(panel, choices=step_Vuln_without_withoutscenarios, style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
595
-
595
+
596
596
  # Scenarios specifics --
597
597
  self._but_checkscenario = wx.Button(panel, label='Check existing scenarios')
598
598
  self._but_checkscenario.SetToolTip("To display the scenario to be taken into account in CHANGE_VULNE.")
599
599
  self._but_checkscenario.Bind(wx.EVT_BUTTON, self.OnCheckScenario)
600
-
600
+
601
601
  self._but_upriverbed = wx.Button(panel, label="Update riverbed")
602
602
  self._but_upriverbed.SetToolTip("To create the raster of the riverbed trace.")
603
603
  self._but_upriverbed.Bind(wx.EVT_BUTTON, self.on_button_click)
@@ -606,16 +606,16 @@ class AcceptabilityGui(wx.Frame):
606
606
  self.menu.Append(1, "File of riverbed trace exists.")
607
607
  self.menu.Append(2, "Point to a low discharge simulation and calculate the riverbed trace.")
608
608
  self.menu.Bind(wx.EVT_MENU, self.on_menu_click)
609
-
609
+
610
610
  self._but_toggle_scen = wx.ToggleButton(panel, label="Accounting for scenarios")
611
611
  self._but_toggle_scen.SetToolTip("To be activated to surimpose the vuln_ files, \n and so to take into account scenarios")
612
612
  self.toggle_state = False
613
613
  self._but_toggle_scen.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle)
614
-
614
+
615
615
  sizer_hor_scen.Add(self._but_checkscenario, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
616
616
  sizer_hor_scen.Add(self._but_upriverbed, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
617
617
  sizer_hor_scen.Add(self._but_toggle_scen, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
618
-
618
+
619
619
  self._but_toggle_resamp = wx.ToggleButton(panel, label="Resampling [m]:")
620
620
  self._but_toggle_resamp.SetToolTip("To compute the final raster with a coarser resolution than the original one.")
621
621
  self.toggle_resamp_state = False
@@ -623,7 +623,7 @@ class AcceptabilityGui(wx.Frame):
623
623
  sizer_hor_scen.Add(self._but_toggle_resamp, flag=wx.ALIGN_CENTER | wx.TOP)
624
624
  self._but_resampling = wx.SpinCtrl(panel, value="100", min=1, max=1000)
625
625
  sizer_hor_scen.Add(self._but_resampling, flag=wx.ALIGN_CENTER | wx.TOP)
626
-
626
+
627
627
  #--
628
628
 
629
629
  self._but_acceptability = wx.Button(panel, label='Acceptability')
@@ -647,7 +647,7 @@ class AcceptabilityGui(wx.Frame):
647
647
  sizer_ver_small.Add(self._but_checkfiles, 0, wx.ALL | wx.EXPAND, 1)
648
648
  sizer_ver_small.Add(self._but_checksim, 0, wx.ALL | wx.EXPAND, 1)
649
649
  sizer_ver_small.Add(self._but_checkpond, 0, wx.ALL | wx.EXPAND, 1)
650
-
650
+
651
651
  sizer_vert1.Add(sizer_hor1, 1, wx.EXPAND, 0)
652
652
  sizer_vert1.Add(sizer_hor1_1, 1, wx.EXPAND, 0)
653
653
  sizer_vert1.Add(sizer_hor_threads, 0, wx.EXPAND, 0)
@@ -673,11 +673,11 @@ class AcceptabilityGui(wx.Frame):
673
673
  self._but_checksim.Enable(False)
674
674
  self._but_creation.Enable(False)
675
675
  self._but_loadgpu.Enable(False)
676
-
676
+
677
677
  panel.SetSizer(sizer_hor_main)
678
678
  panel.Layout()
679
-
680
-
679
+
680
+
681
681
  def OnSims(self, e:wx.ListEvent):
682
682
  """ Load sim into the mapviewer """
683
683
  pass
@@ -703,7 +703,7 @@ class AcceptabilityGui(wx.Frame):
703
703
  return
704
704
 
705
705
  i=self._manager.check_inputs()
706
-
706
+
707
707
  if i == False :
708
708
  logging.error(f"Missing files in INPUT. Please provide them by following the right structure.")
709
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:
@@ -721,26 +721,26 @@ class AcceptabilityGui(wx.Frame):
721
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
722
  dlg.ShowModal()
723
723
 
724
-
724
+
725
725
  def OnHydrodynInput(self,e):
726
726
  """ A test to check if the FILLED water depths files exist.
727
727
  -If YES : the code can go on
728
728
  -If NO : either need to be computed, either the code will use the baseline ones
729
729
  """
730
-
730
+
731
731
  if self._manager is None:
732
732
  logging.error("No main directory selected -- Nothing to check")
733
733
  return
734
734
 
735
735
  paths_FilledWD = self._manager.get_sims_files_for_scenario()
736
-
736
+
737
737
  if len(paths_FilledWD) == 0 :
738
738
  logging.info("There are no interpolated free surface files.")
739
- dialog = wx.MessageDialog(None, "There are no interpolated free surface files. Please choose an action.", "Checking- Choose an option",
739
+ dialog = wx.MessageDialog(None, "There are no interpolated free surface files. Please choose an action.", "Checking- Choose an option",
740
740
  wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION)
741
-
742
- dialog.SetYesNoLabels("Use the ones in the scenario_baseline (assumption)", "Load other simulations")
743
- response = dialog.ShowModal()
741
+
742
+ dialog.SetYesNoLabels("Use the ones in the scenario_baseline (assumption)", "Load other simulations")
743
+ response = dialog.ShowModal()
744
744
 
745
745
  if response == wx.ID_YES:
746
746
  logging.info("Decision of using baseline simulations.")
@@ -749,51 +749,51 @@ class AcceptabilityGui(wx.Frame):
749
749
  logging.info("Cannot select files in the _baseline folder (no files or no folder!).")
750
750
  else:
751
751
  self._manager.copy_tif_files(paths_FilledWD_base, self._manager.IN_SA_INTERP)
752
-
752
+
753
753
  elif response == wx.ID_NO:
754
754
  logging.info("Decision of loading simulations.")
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:
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:
757
757
  dlg.ShowModal()
758
758
  else:
759
759
  logging.info("Cancelled")
760
-
761
- dialog.Destroy()
762
-
760
+
761
+ dialog.Destroy()
762
+
763
763
  else:
764
764
  name_paths_FilledWD = []
765
-
765
+
766
766
  for names in paths_FilledWD:
767
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.")
768
768
  name_paths_FilledWD.append(names.name)
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
+ with wx.MessageDialog(self,
770
+ f"{len(paths_FilledWD)} file(s) of interpolated free surface found in the folder : {name_paths_FilledWD}.",
771
+ "Information",
772
772
  style=wx.OK | wx.ICON_INFORMATION) as dlg:
773
773
  dlg.ShowModal()
774
774
  update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
775
-
775
+
776
776
  def OnCheckPond(self,e):
777
777
  ponds = self._manager.get_ponderations()
778
778
  if isinstance(ponds, pd.DataFrame):
779
779
  logging.info(f"Plotting the coefficients graph.")
780
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)
781
+ plt.ylabel("Weighting coefficients [-]")
782
+ plt.xlabel("Return period [years]")
783
+ plt.grid(axis='y', linestyle='--', alpha=0.7)
784
784
  plt.show()
785
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",
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
789
  style=wx.OK | wx.ICON_INFORMATION) as dlg:
790
790
  dlg.ShowModal()
791
791
 
792
-
792
+
793
793
  def OnMainDir(self, e):
794
794
  """Selects the main directory to be read."""
795
795
  vanish_info_header(self.input_dx,self.input_nbxy,self.input_O)
796
-
796
+
797
797
  with wx.DirDialog(self, "Choose the main directory containing the data (folders INPUT, TEMP and OUTPUT):",
798
798
  style=wx.DD_DEFAULT_STYLE
799
799
  ) as dlg:
@@ -831,7 +831,7 @@ class AcceptabilityGui(wx.Frame):
831
831
  return
832
832
  self._listbox_studyarea.Clear()
833
833
  self._listbox_studyarea.InsertItems(studyareas, 0)
834
-
834
+
835
835
  logging.info("All the files are present")
836
836
  else:
837
837
  return
@@ -843,7 +843,7 @@ class AcceptabilityGui(wx.Frame):
843
843
  vanish_info_header(self.input_dx,self.input_nbxy,self.input_O)
844
844
  self._listbox_scenario.Clear()
845
845
  study_area:str = self._manager.get_list_studyareas(with_suffix=True)[e.GetSelection()]
846
-
846
+
847
847
  self._manager.change_studyarea(study_area)
848
848
 
849
849
  sc = self._manager.get_list_scenarios()
@@ -851,7 +851,7 @@ class AcceptabilityGui(wx.Frame):
851
851
  self._listbox_scenario.InsertItems(sc, 0)
852
852
  else :
853
853
  logging.error("No scenario available associated with this study area.")
854
-
854
+
855
855
  if self.mapviewer is not None:
856
856
  tmp_path = self._manager.IN_STUDY_AREA / study_area
857
857
 
@@ -865,16 +865,16 @@ class AcceptabilityGui(wx.Frame):
865
865
  if self._manager is None:
866
866
  return
867
867
  scenario = self._manager.get_list_scenarios()[e.GetSelection()]
868
-
868
+
869
869
  self._manager.change_scenario(scenario)
870
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
-
871
+ update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
872
+
873
873
  def OnCreation(self, e):
874
874
  """ Create the database """
875
875
  if self._manager is None:
876
876
  return
877
-
877
+
878
878
  dx,_,_,_,_,_ = update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
879
879
  resolution = dx
880
880
  if resolution == '':
@@ -883,23 +883,23 @@ class AcceptabilityGui(wx.Frame):
883
883
  "Attention",
884
884
  wx.OK | wx.ICON_ERROR
885
885
  )
886
- else :
886
+ else :
887
887
  steps = list(self._steps_db.GetCheckedStrings())
888
888
  steps = [int(cur.split('-')[1]) for cur in steps]
889
-
889
+
890
890
  if len(steps) != 0:
891
-
891
+
892
892
  wx.MessageBox(
893
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
894
  "Information",
895
895
  wx.OK | wx.ICON_INFORMATION
896
896
  )
897
- Base_data_creation(self._manager.main_dir,
897
+ Base_data_creation(self._manager.main_dir,
898
898
  Study_area=self._manager.Study_area,
899
- number_procs=self._nb_process.GetValue(),
900
- resolution=dx,
899
+ number_procs=self._nb_process.GetValue(),
900
+ resolution=dx,
901
901
  steps=steps)
902
-
902
+
903
903
  wx.MessageBox(
904
904
  "The database is created with the selected steps.",
905
905
  "Information",
@@ -911,25 +911,25 @@ class AcceptabilityGui(wx.Frame):
911
911
  "Information",
912
912
  wx.OK | wx.ICON_INFORMATION
913
913
  )
914
- Base_data_creation(self._manager.main_dir,
914
+ Base_data_creation(self._manager.main_dir,
915
915
  Study_area=self._manager.Study_area,
916
- number_procs=self._nb_process.GetValue(),
916
+ number_procs=self._nb_process.GetValue(),
917
917
  resolution=dx)
918
918
  wx.MessageBox(
919
919
  "The database is created for every steps.",
920
920
  "Information",
921
921
  wx.OK | wx.ICON_INFORMATION
922
922
  )
923
-
923
+
924
924
  def OnLoadingSimu(self,e):
925
925
  """ Link between acceptability and simulations
926
926
  -Load a hydraulic scenarios from the scenario manager
927
927
  -Create scenario and study area if needed.
928
928
  """
929
-
929
+
930
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)
931
931
  if dlg.ShowModal() == wx.ID_OK:
932
- main_gpu = Path(dlg.GetPath())
932
+ main_gpu = Path(dlg.GetPath())
933
933
  study_area = main_gpu.name
934
934
  logging.info(f"Selected folder for GPU result such as the STUDY AREA is {study_area}")
935
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)
@@ -941,27 +941,27 @@ class AcceptabilityGui(wx.Frame):
941
941
  create_INPUT_TEMP_OUTPUT_forScenario(self.maindir, study_area, scenario, main_gpu)
942
942
  self._manager.change_studyarea(study_area+'.shp')
943
943
  self._manager.change_scenario(scenario)
944
-
945
-
946
-
944
+
945
+
946
+
947
947
  self._listbox_studyarea.Clear()
948
948
  self._listbox_studyarea.InsertItems(self._manager.get_list_studyareas(), 0)
949
949
  self._listbox_scenario.Clear()
950
950
  self._listbox_scenario.InsertItems(self._manager.get_list_scenarios(), 0)
951
-
951
+
952
952
  #Blue color of selection even if not directly clicked :
953
953
  index_to_select = self._listbox_scenario.FindString(scenario)
954
954
  if index_to_select != wx.NOT_FOUND:
955
955
  self._listbox_scenario.SetSelection(index_to_select)
956
- self._listbox_scenario.SetItemBackgroundColour(index_to_select, wx.Colour(0, 120, 215))
957
-
956
+ self._listbox_scenario.SetItemBackgroundColour(index_to_select, wx.Colour(0, 120, 215))
957
+
958
958
  index_to_select = self._listbox_studyarea.FindString(study_area)
959
959
  if index_to_select != wx.NOT_FOUND:
960
960
  self._listbox_studyarea.SetSelection(index_to_select)
961
- self._listbox_studyarea.SetItemBackgroundColour(index_to_select, wx.Colour(0, 120, 215))
961
+ self._listbox_studyarea.SetItemBackgroundColour(index_to_select, wx.Colour(0, 120, 215))
962
962
  self._listbox_studyarea.Refresh()
963
- self._listbox_scenario.Refresh()
964
-
963
+ self._listbox_scenario.Refresh()
964
+
965
965
  else:
966
966
  logging.error('No hydraulic scenario selected.')
967
967
  else:
@@ -970,16 +970,16 @@ class AcceptabilityGui(wx.Frame):
970
970
  self.sims = {}
971
971
  for subdir in hydraulic_scen.iterdir():
972
972
  if subdir.is_dir() and subdir.name.startswith("sim_"):
973
- self.sims[subdir.name] = subdir
973
+ self.sims[subdir.name] = subdir
974
974
  else:
975
975
  logging.info('No folder sim_ found / selected. Please try again.')
976
976
  self.datadir_simulations = hydraulic_scen
977
977
  self.file_paths = {Path(sim).name: Path(sim) for sim in sorted(self.sims.keys())}
978
978
  self._check_listbox.Set(sorted(sim for sim in self.sims.keys()))
979
-
979
+
980
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'.")
981
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'."
982
-
982
+
983
983
  found_bath = search_for_modif_bath_and_copy(Path(main_gpu), Path(hydraulic_scen.parent), self._manager.IN_CH_SA_SC)
984
984
  if found_bath :
985
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."
@@ -987,12 +987,12 @@ class AcceptabilityGui(wx.Frame):
987
987
  self.gpu_bathy = hydraulic_scen.parent / "__bathymetry.tif"
988
988
  self._but_extrinterp.Enable(True)
989
989
  self._but_DEM.Enable(True)
990
- with wx.MessageDialog(self,
991
- message,
992
- "Information",
990
+ with wx.MessageDialog(self,
991
+ message,
992
+ "Information",
993
993
  style=wx.OK | wx.ICON_INFORMATION) as dlg:
994
994
  dlg.ShowModal()
995
-
995
+
996
996
  def OnDEM(self,e):
997
997
  """Import and create the inputs for the interpolation routine holes.exe (name including 'MNT_...' and 'MNT_..._with_mask'.
998
998
  See function MTN_And_mask_creation_all"""
@@ -1017,7 +1017,7 @@ class AcceptabilityGui(wx.Frame):
1017
1017
  else :
1018
1018
  logging.info("No update of DEM_FILES.")
1019
1019
  return
1020
-
1020
+
1021
1021
  with wx.FileDialog(self, "Please select the DEM file in .tif format (without modifications).", wildcard="TIFF files (*.tif)|*.tif",
1022
1022
  style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as dlg:
1023
1023
  result = dlg.ShowModal()
@@ -1026,7 +1026,7 @@ class AcceptabilityGui(wx.Frame):
1026
1026
 
1027
1027
  path_DEM_base = dlg.GetPath()
1028
1028
  logging.info("DEM file selected.")
1029
-
1029
+
1030
1030
  #DEM and masked DEM creation
1031
1031
  path = self._manager.IN_CH_SA_SC
1032
1032
  names_inCHVUL_MNTmodifs = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) and f.startswith("MNTmodifs_")]
@@ -1037,11 +1037,11 @@ class AcceptabilityGui(wx.Frame):
1037
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
1038
  dialog.SetYesNoLabels("Done, continue", "Not done, stop")
1039
1039
  response = dialog.ShowModal()
1040
-
1040
+
1041
1041
  if response == wx.ID_NO:
1042
1042
  logging.info("No modifications done in MNTmodifs_ files, process stopped.")
1043
1043
  return
1044
-
1044
+
1045
1045
  #else :
1046
1046
  if os.path.exists(self._manager.IN_CH_SA_SC):
1047
1047
  existence=False
@@ -1073,24 +1073,24 @@ class AcceptabilityGui(wx.Frame):
1073
1073
  dlg.ShowModal()
1074
1074
  dlg.Destroy()
1075
1075
  return
1076
-
1076
+
1077
1077
  def OnInterpolation(self,e):
1078
- """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
1079
1079
  interpolation routine holes.exe, by creating a batch file
1080
1080
  while performing multiple checks on the required input files."""
1081
1081
  if not hasattr(self, 'file_paths'):
1082
- with wx.MessageDialog(self,
1083
- f"Please, first load gpu simulations via the previous button.",
1084
- "Attention",
1082
+ with wx.MessageDialog(self,
1083
+ f"Please, first load gpu simulations via the previous button.",
1084
+ "Attention",
1085
1085
  style=wx.OK | wx.ICON_ERROR) as dlg:
1086
1086
  dlg.ShowModal()
1087
1087
  return
1088
-
1088
+
1089
1089
  checked_indices = self._check_listbox.GetCheckedItems()
1090
1090
  checked_items = [self._check_listbox.GetString(index) for index in checked_indices]
1091
1091
  selected_paths = [self.file_paths[item] for item in checked_items]
1092
1092
  path_simulations = self.datadir_simulations
1093
-
1093
+
1094
1094
  path_LastSteps = Path(self._manager.IN_SA_EXTRACTED)
1095
1095
  fn_write = None
1096
1096
  dx,dy,nbx,nby,X,Y = False, False, False, False, False, False
@@ -1110,8 +1110,8 @@ class AcceptabilityGui(wx.Frame):
1110
1110
  else:
1111
1111
  logging.info('No folder found / selected. Please try again...')
1112
1112
  else:
1113
- logging.error('No simulation selected! Please select some in the checkbox.')
1114
-
1113
+ logging.error('No simulation selected! Please select some in the checkbox.')
1114
+
1115
1115
  C = None
1116
1116
  D = None
1117
1117
  for file in os.listdir(Path(self._manager.IN_SA_DEM)):
@@ -1120,44 +1120,44 @@ class AcceptabilityGui(wx.Frame):
1120
1120
  if "mask" not in file:
1121
1121
  D = file_path
1122
1122
  else:
1123
- C = file_path
1123
+ C = file_path
1124
1124
  if D == None:
1125
1125
  logging.info("DEM (.bin) not found in DEM_FILES. The file must begins by 'MNT_' and CANNOT include the word 'mask'")
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",
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",
1129
1129
  style=wx.OK | wx.ICON_INFORMATION) as dlg:
1130
1130
  dlg.ShowModal()
1131
1131
  return
1132
-
1132
+
1133
1133
  if C == None:
1134
1134
  logging.info("DEM mask (.bin) not found in DEM_FILES. The file must begins by 'MNT_' and MUST include the word 'mask'")
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",
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",
1138
1138
  style=wx.OK | wx.ICON_INFORMATION) as dlg:
1139
1139
  dlg.ShowModal()
1140
1140
  return
1141
-
1141
+
1142
1142
  if not get_header_comparison([fn_write.with_suffix(".bin"), C, D]):
1143
1143
  logging.info("Files in DEM_FILES do not have the same properties as the simulations files. Please, fix them.")
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",
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",
1147
1147
  style=wx.OK | wx.ICON_INFORMATION) as dlg:
1148
1148
  dlg.ShowModal()
1149
1149
  return
1150
-
1150
+
1151
1151
  checked_names = self._check_listbox.GetCheckedStrings()
1152
1152
  if not checked_names:
1153
1153
  logging.info("No items selected. Adding all paths.")
1154
- checked_paths = list(self.file_paths.values())
1154
+ checked_paths = list(self.file_paths.values())
1155
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."
1156
1156
  else:
1157
1157
  logging.info("Adding only the selected simulations.")
1158
1158
  checked_paths = [self.file_paths[name] for name in checked_names]
1159
1159
  message_info = "The interpolation of the given free surface will begin (for the selected simulation(s)), please wait."
1160
-
1160
+
1161
1161
  if len(self.file_paths) == 0 :
1162
1162
  with wx.MessageDialog(self, f"No files in EXTRACTED_LAST_STEP_WD. Please provide some or use the 'Load gpu simulation' button.",
1163
1163
  "OK", wx.OK | wx.ICON_INFORMATION) as dlg:
@@ -1165,15 +1165,15 @@ class AcceptabilityGui(wx.Frame):
1165
1165
  else :
1166
1166
  path_Interp = Path(self._manager.IN_SA_INTERP)
1167
1167
  path_bat_file = os.path.join(self._manager.IN_SCEN_DIR, "process_files.bat")
1168
-
1168
+
1169
1169
  if os.path.exists(path_bat_file):
1170
1170
  logging.info(f"The file {path_bat_file} already exists and will be replaced.")
1171
1171
  os.remove(path_bat_file)
1172
- path_code = os.path.join(self._manager.IN_WATER_DEPTH, "holes.exe")
1173
-
1172
+ path_code = os.path.join(self._manager.IN_WATER_DEPTH, "holes.exe")
1173
+
1174
1174
  A=[]
1175
1175
  for path in checked_paths:
1176
- parts = path.name.split("sim_")
1176
+ parts = path.name.split("sim_")
1177
1177
  A.extend([os.path.join(path_LastSteps, g) for g in os.listdir(path_LastSteps) if g.endswith(f"{parts[1]}.bin")])
1178
1178
  B = [os.path.join(path_Interp, os.path.splitext(os.path.basename(f))[0]) for f in A]
1179
1179
  if not A or not B or not C or not D:
@@ -1186,18 +1186,18 @@ class AcceptabilityGui(wx.Frame):
1186
1186
  line = f'"{path_code}" filling in="{a}" out="{b}" mask="{C}" dem="{D} avoid_last=1"\n'
1187
1187
  bat_file.write(line)
1188
1188
  logging.info(message_info)
1189
-
1189
+
1190
1190
  empty_folder(self._manager.IN_SA_INTERP)
1191
1191
  path_bat_file = os.path.join(self._manager.IN_SCEN_DIR, "process_files.bat")
1192
1192
  subprocess.run([path_bat_file], check=True)
1193
-
1193
+
1194
1194
  renamed_files = []
1195
1195
  path_fichier=self._manager.IN_SA_INTERP
1196
1196
  for file in path_fichier.glob("*.tif"):
1197
- if "_h" in file.name:
1197
+ if "_h" in file.name:
1198
1198
  new_name = file.stem.split("_h")[0].replace(".bin", "") + ".tif"
1199
1199
  file.rename(file.with_name(new_name))
1200
- renamed_files.append(new_name)
1200
+ renamed_files.append(new_name)
1201
1201
  #deleting the other
1202
1202
  for file in path_fichier.glob("*.tif"):
1203
1203
  if "_combl" in file.name or file.name not in renamed_files:
@@ -1207,13 +1207,13 @@ class AcceptabilityGui(wx.Frame):
1207
1207
  "Redirecting", wx.OK | wx.ICON_INFORMATION) as dlg:
1208
1208
  dlg.ShowModal()
1209
1209
  update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
1210
-
1210
+
1211
1211
  def OnToggle(self,e):
1212
1212
  """Creates a toggle button to be activated if the scenarios vuln_ have to be taken into account."""
1213
1213
  self.toggle_state = False
1214
1214
  if self._but_toggle_scen.GetValue():
1215
1215
  logging.info("Activating the scenario button.")
1216
- self._but_toggle_scen.SetBackgroundColour(wx.Colour(175, 175, 175))
1216
+ self._but_toggle_scen.SetBackgroundColour(wx.Colour(175, 175, 175))
1217
1217
  self._but_toggle_scen_state = True
1218
1218
  tif_files = [file for file in Path(self._manager.IN_CH_SA_SC).glob("*.tif") if file.name.startswith("vuln_")]
1219
1219
  if not tif_files:
@@ -1223,27 +1223,27 @@ class AcceptabilityGui(wx.Frame):
1223
1223
  wx.OK | wx.ICON_INFORMATION
1224
1224
  )
1225
1225
  logging.info("Desactivating the scenario button.")
1226
- self._but_toggle_scen.SetValue(False)
1227
- self._but_toggle_scen.SetBackgroundColour(wx.NullColour)
1226
+ self._but_toggle_scen.SetValue(False)
1227
+ self._but_toggle_scen.SetBackgroundColour(wx.NullColour)
1228
1228
  self._but_toggle_scen_state = False
1229
1229
  else :
1230
1230
  self.toggle_state = True
1231
1231
  else:
1232
- self._but_toggle_scen.SetBackgroundColour(wx.NullColour)
1232
+ self._but_toggle_scen.SetBackgroundColour(wx.NullColour)
1233
1233
  self.toggle_state = False
1234
1234
  logging.info("Desactivating the scenario button.")
1235
-
1235
+
1236
1236
  def OnToggleResampling(self,e):
1237
1237
  """Creates a toggle button for the acceptability resampling to be activated."""
1238
1238
  self.toggle_resamp_state = False
1239
1239
  toggle = self._but_toggle_resamp
1240
- if toggle.GetValue():
1241
- 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))
1242
1242
  self.toggle_resamp_state = True
1243
1243
  logging.info("Resampling activated")
1244
1244
  current_res = self._but_resampling.GetValue()
1245
1245
  resolution = self.input_dx.GetLabel()
1246
- if resolution != '':
1246
+ if resolution != '':
1247
1247
  values = resolution.strip("()").split(",")
1248
1248
  dx = float(values[0])
1249
1249
  #selection of size
@@ -1252,26 +1252,26 @@ class AcceptabilityGui(wx.Frame):
1252
1252
  "The resampling size cannot be inferior to the resolution. Please select another resampling size.",
1253
1253
  "Attention",
1254
1254
  wx.OK | wx.ICON_ERROR
1255
- )
1255
+ )
1256
1256
  self.toggle_resamp_state = False
1257
- self._but_toggle_resamp.SetValue(False)
1258
- self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
1257
+ self._but_toggle_resamp.SetValue(False)
1258
+ self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
1259
1259
  logging.info("Resampling disactivated because of a bad resampling size.")
1260
1260
  else :
1261
1261
  logging.info(f"Allowed resampling value : {current_res}[m].")
1262
1262
  else:
1263
1263
  self.toggle_resamp_state = False
1264
- self._but_toggle_resamp.SetValue(False)
1265
- self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
1264
+ self._but_toggle_resamp.SetValue(False)
1265
+ self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
1266
1266
  logging.info("No simulations in INTERP_WD.")
1267
1267
 
1268
-
1268
+
1269
1269
  else:
1270
1270
  self.toggle_resamp_state = False
1271
- self._but_toggle_resamp.SetValue(False)
1272
- self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
1271
+ self._but_toggle_resamp.SetValue(False)
1272
+ self._but_toggle_resamp.SetBackgroundColour(wx.NullColour)
1273
1273
  logging.info("Resampling disactivated")
1274
-
1274
+
1275
1275
  def OnCheckScenario(self,e):
1276
1276
  """Checks if scenarios exist in CHANGE_VULNE."""
1277
1277
  tif_files = self._manager.get_modifiedrasters()
@@ -1282,18 +1282,18 @@ class AcceptabilityGui(wx.Frame):
1282
1282
  "Information",
1283
1283
  wx.OK | wx.ICON_INFORMATION
1284
1284
  )
1285
- else :
1285
+ else :
1286
1286
  wx.MessageBox(
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
-
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
+
1290
1290
  def OnVulnerability(self, e):
1291
1291
  """ Run the vulnerability """
1292
1292
  if self._manager is None:
1293
1293
  return
1294
1294
  path = [self._manager.OUT_VULN]
1295
1295
  steps = list(self._steps_vulnerability.GetCheckedStrings())
1296
- steps = [int(cur.split('-')[1]) for cur in steps]
1296
+ steps = [int(cur.split('-')[1]) for cur in steps]
1297
1297
  resolution,_,_,_,_,_ =update_info_header(self.input_dx,self.input_nbxy,self.input_O,self._manager.IN_SA_INTERP)
1298
1298
  if resolution == '':
1299
1299
  wx.MessageBox(
@@ -1302,7 +1302,7 @@ class AcceptabilityGui(wx.Frame):
1302
1302
  wx.OK | wx.ICON_ERROR
1303
1303
  )
1304
1304
  else :
1305
- message_supp = "."
1305
+ message_supp = "."
1306
1306
  if len(steps) == 0:
1307
1307
  steps = [1,10,11,2,3]
1308
1308
  if self.toggle_state == True :
@@ -1314,13 +1314,13 @@ class AcceptabilityGui(wx.Frame):
1314
1314
  steps=[4]
1315
1315
  else :
1316
1316
  logging.info("Attention - The manager computes also Vulnerability_baseline, as Vulnerability_scenario needs it as input.")
1317
- path = [self._manager.OUT_VULN_Stif]
1317
+ path = [self._manager.OUT_VULN_Stif]
1318
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)
1319
1319
  dialog.SetYesNoLabels("Done, continue", "Not done, stop")
1320
1320
  response = dialog.ShowModal()
1321
1321
  if response == wx.ID_NO:
1322
1322
  return
1323
-
1323
+
1324
1324
  logging.info("No steps selected. By default every steps will be performed" + message_supp)
1325
1325
  Vulnerability(str(self._manager.main_dir),
1326
1326
  scenario=str(self._manager.scenario),
@@ -1331,7 +1331,7 @@ class AcceptabilityGui(wx.Frame):
1331
1331
  "Vulnerability computed with every steps" + message_supp,
1332
1332
  "Information",
1333
1333
  wx.OK | wx.ICON_INFORMATION
1334
- )
1334
+ )
1335
1335
  else :
1336
1336
  if self.toggle_state == True :
1337
1337
  steps.append(4)
@@ -1342,14 +1342,14 @@ class AcceptabilityGui(wx.Frame):
1342
1342
  steps=[4]
1343
1343
  else :
1344
1344
  logging.info("Attention - The manager computes also Vulnerability_baseline, as Vulnerability_scenario needs it as input.")
1345
-
1346
- path = [self._manager.OUT_VULN_Stif]
1345
+
1346
+ path = [self._manager.OUT_VULN_Stif]
1347
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)
1348
1348
  dialog.SetYesNoLabels("Done, continue", "Not done, stop")
1349
1349
  response = dialog.ShowModal()
1350
1350
  if response == wx.ID_NO:
1351
1351
  return
1352
-
1352
+
1353
1353
  Vulnerability(self._manager.main_dir,
1354
1354
  scenario=self._manager.scenario,
1355
1355
  Study_area=self._manager.Study_area,
@@ -1359,21 +1359,21 @@ class AcceptabilityGui(wx.Frame):
1359
1359
  "Vulnerability computed with the selected steps" + message_supp,
1360
1360
  "Information",
1361
1361
  wx.OK | wx.ICON_INFORMATION
1362
- )
1362
+ )
1363
1363
  mapviewer_display(path)
1364
-
1364
+
1365
1365
  def OnAcceptability(self, e):
1366
1366
  """ Run the acceptability """
1367
1367
  if self._manager is None:
1368
1368
  return
1369
-
1370
- river_trace = self._manager.wich_river_trace()
1369
+
1370
+ river_trace = self._manager.wich_river_trace()
1371
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)) :
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 )
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 )
1373
1373
  return
1374
-
1374
+
1375
1375
  if self.toggle_state == False and not os.path.isfile(str(self._manager.OUT_VULN)) and not os.path.isfile(str(river_trace)) :
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 )
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 )
1377
1377
  return
1378
1378
 
1379
1379
  steps = list(self._steps_acceptability.GetCheckedStrings())
@@ -1391,19 +1391,19 @@ class AcceptabilityGui(wx.Frame):
1391
1391
  steps = [x for x in steps if x != 4]
1392
1392
  logging.info('Acceptability_baseline not computed because it already exists.')
1393
1393
  message_supp = " FOR scenario(s) vuln_ taken into account"
1394
-
1394
+
1395
1395
  if river_trace == self._manager.OUT_MASKED_RIVER : message_supp=message_supp +" WITH the _baseline riverbed trace."
1396
1396
  if river_trace == self._manager.OUT_MASKED_RIVER_S :message_supp+= " WITH the _scenarios riverbed trace."
1397
1397
  if self.toggle_resamp_state == True :
1398
1398
  steps.append(6)
1399
- resampling = self._but_resampling.GetValue()
1399
+ resampling = self._but_resampling.GetValue()
1400
1400
  resolution = self.input_dx.GetLabel()
1401
- if resolution != '':
1401
+ if resolution != '':
1402
1402
  values = resolution.strip("()").split(",")
1403
1403
  resolution = float(values[0])
1404
-
1404
+
1405
1405
  message_supp+= f" It has been created for the resolution {resolution}m and the resampling size {resampling}m."
1406
-
1406
+
1407
1407
  logging.info("No steps selected. By default every steps will be performed.")
1408
1408
  Acceptability(self._manager.main_dir,
1409
1409
  scenario=self._manager.scenario,
@@ -1424,19 +1424,19 @@ class AcceptabilityGui(wx.Frame):
1424
1424
  logging.info('Acceptability_baseline not computed because it already exists.')
1425
1425
  message_supp = "FOR scenario(s) (vuln_taken into account)"
1426
1426
  path = [self._manager.OUT_ACCEPT_Stif]
1427
- river_trace = self._manager.wich_river_trace()
1427
+ river_trace = self._manager.wich_river_trace()
1428
1428
  if river_trace == self._manager.OUT_MASKED_RIVER : message_supp =message_supp + " WITH the _baseline riverbed trace."
1429
1429
  if river_trace == self._manager.OUT_MASKED_RIVER_S : message_supp =message_supp + " WITH the _scenarios riverbed trace."
1430
1430
  if self.toggle_resamp_state == True :
1431
1431
  resampling = self._but_resampling.GetValue()
1432
1432
  steps.append(6)
1433
-
1433
+
1434
1434
  Acceptability(self._manager.main_dir,
1435
1435
  scenario=self._manager.scenario,
1436
1436
  Study_area=self._manager.Study_area,
1437
1437
  resample_size=resampling,
1438
1438
  steps=steps)
1439
-
1439
+
1440
1440
  wx.MessageBox(
1441
1441
  "Acceptability computed with the selected steps" + message_supp,
1442
1442
  "Information",