wolfhece 2.1.98__py3-none-any.whl → 2.1.100__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 +506 -35
- wolfhece/PyParams.py +18 -8
- wolfhece/PyVertex.py +12 -5
- wolfhece/PyVertexvectors.py +27 -16
- wolfhece/Results2DGPU.py +23 -7
- wolfhece/acceptability/Parallels.py +2 -2
- wolfhece/acceptability/_add_path.py +23 -0
- wolfhece/acceptability/acceptability.py +594 -563
- wolfhece/acceptability/acceptability_gui.py +564 -331
- wolfhece/acceptability/cli.py +307 -120
- wolfhece/acceptability/func.py +1743 -1597
- wolfhece/analyze_vect.py +177 -0
- wolfhece/apps/version.py +1 -1
- wolfhece/bernoulli/losses.py +75 -22
- wolfhece/bernoulli/losses_jax.py +143 -0
- wolfhece/bernoulli/pipe.py +7 -2
- wolfhece/math_parser/__init__.py +4 -4
- wolfhece/math_parser/calculator.py +50 -9
- wolfhece/matplotlib_fig.py +1980 -0
- wolfhece/mesh2d/simple_2d.py +2399 -0
- wolfhece/mesh2d/wolf2dprev.py +1 -1
- wolfhece/pidcontroller.py +131 -0
- wolfhece/pywalous.py +7 -7
- wolfhece/scenario/config_manager.py +191 -83
- wolfhece/wolf_array.py +162 -109
- wolfhece/wolf_vrt.py +108 -7
- wolfhece/wolfresults_2D.py +109 -4
- wolfhece/xyz_file.py +91 -51
- {wolfhece-2.1.98.dist-info → wolfhece-2.1.100.dist-info}/METADATA +1 -1
- {wolfhece-2.1.98.dist-info → wolfhece-2.1.100.dist-info}/RECORD +33 -27
- {wolfhece-2.1.98.dist-info → wolfhece-2.1.100.dist-info}/WHEEL +1 -1
- {wolfhece-2.1.98.dist-info → wolfhece-2.1.100.dist-info}/entry_points.txt +0 -0
- {wolfhece-2.1.98.dist-info → wolfhece-2.1.100.dist-info}/top_level.txt +0 -0
@@ -1,331 +1,564 @@
|
|
1
|
-
"""
|
2
|
-
Author: University of Liege, HECE
|
3
|
-
Date: 2024
|
4
|
-
|
5
|
-
Copyright (c) 2024 University of Liege. All rights reserved.
|
6
|
-
|
7
|
-
This script and its content are protected by copyright law. Unauthorized
|
8
|
-
copying or distribution of this file, via any medium, is strictly prohibited.
|
9
|
-
"""
|
10
|
-
|
11
|
-
from .acceptability import
|
12
|
-
from .
|
13
|
-
from .
|
14
|
-
|
15
|
-
import
|
16
|
-
import
|
17
|
-
import
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
import
|
22
|
-
from
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
self.
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
self.
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
self.
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
self.
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
self.
|
129
|
-
|
130
|
-
|
131
|
-
self.
|
132
|
-
self.
|
133
|
-
|
134
|
-
self.
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
self.
|
149
|
-
self.
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
panel.
|
162
|
-
|
163
|
-
|
164
|
-
self.
|
165
|
-
|
166
|
-
self.
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
self.
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
1
|
+
"""
|
2
|
+
Author: University of Liege, HECE
|
3
|
+
Date: 2024
|
4
|
+
|
5
|
+
Copyright (c) 2024 University of Liege. All rights reserved.
|
6
|
+
|
7
|
+
This script and its content are protected by copyright law. Unauthorized
|
8
|
+
copying or distribution of this file, via any medium, is strictly prohibited.
|
9
|
+
"""
|
10
|
+
from .acceptability import Base_data_creation, Database_to_raster, Vulnerability, Acceptability
|
11
|
+
from .acceptability import steps_base_data_creation, steps_vulnerability, steps_acceptability
|
12
|
+
from .func import Accept_Manager
|
13
|
+
from ..scenario.config_manager import Config_Manager_2D_GPU
|
14
|
+
import wx
|
15
|
+
import glob
|
16
|
+
import wx.lib.dialogs
|
17
|
+
import logging
|
18
|
+
import subprocess
|
19
|
+
import matplotlib
|
20
|
+
import shutil
|
21
|
+
from matplotlib.figure import Figure
|
22
|
+
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
|
23
|
+
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar2Wx
|
24
|
+
import os
|
25
|
+
from pathlib import Path
|
26
|
+
from gettext import gettext as _
|
27
|
+
|
28
|
+
from wolfhece.Results2DGPU import wolfres2DGPU
|
29
|
+
from pathlib import Path
|
30
|
+
|
31
|
+
def read_result(fn) :
|
32
|
+
wolfres2DGPU_X= wolfres2DGPU(fn)
|
33
|
+
return wolfres2DGPU_X
|
34
|
+
|
35
|
+
def nullvalue_for_hole(WA):
|
36
|
+
#WolfArray
|
37
|
+
WA.nullvalue = 0.
|
38
|
+
WA.set_nullvalue_in_mask()
|
39
|
+
|
40
|
+
def read_export_z_bin(fn_read, fn_write):
|
41
|
+
wolfres2DGPU_test = read_result(fn_read)
|
42
|
+
wolfres2DGPU_test.read_oneresult(-1)
|
43
|
+
wd = wolfres2DGPU_test.get_h_for_block(1)
|
44
|
+
top = wolfres2DGPU_test.get_top_for_block(1)
|
45
|
+
nullvalue_for_hole(wd)
|
46
|
+
nullvalue_for_hole(top)
|
47
|
+
wd.array = wd.array + top.array
|
48
|
+
wd.write_all(fn_write)
|
49
|
+
|
50
|
+
def empty_folder(folder):
|
51
|
+
if os.path.exists(folder):
|
52
|
+
for files in os.listdir(folder):
|
53
|
+
fn = os.path.join(folder, files)
|
54
|
+
try:
|
55
|
+
if os.path.isfile(fn) or os.path.islink(fn):
|
56
|
+
os.unlink(fn)
|
57
|
+
elif os.path.isdir(fn):
|
58
|
+
shutil.rmtree(fn)
|
59
|
+
except Exception as e:
|
60
|
+
print(f"Error when deleting file {fn}: {e}")
|
61
|
+
else:
|
62
|
+
print("The folder does not exist.")
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
class AcceptabilityGui(wx.Frame):
|
67
|
+
""" The main frame for the vulnerability/acceptability computation """
|
68
|
+
|
69
|
+
def __init__(self, parent=None, width=1024, height=500):
|
70
|
+
|
71
|
+
super(wx.Frame, self).__init__(parent, title='Acceptability', size=(width, height))
|
72
|
+
|
73
|
+
self._manager = None
|
74
|
+
self._mapviewer = None
|
75
|
+
self.InitUI()
|
76
|
+
|
77
|
+
@property
|
78
|
+
def mapviewer(self):
|
79
|
+
return self._mapviewer
|
80
|
+
|
81
|
+
@mapviewer.setter
|
82
|
+
def mapviewer(self, value):
|
83
|
+
from ..PyDraw import WolfMapViewer
|
84
|
+
|
85
|
+
if not isinstance(value, WolfMapViewer):
|
86
|
+
raise TypeError("The mapviewer must be a WolfMapViewer")
|
87
|
+
|
88
|
+
self._mapviewer = value
|
89
|
+
|
90
|
+
def InitUI(self):
|
91
|
+
|
92
|
+
sizer_hor_main = wx.BoxSizer(wx.HORIZONTAL)
|
93
|
+
|
94
|
+
sizer_vert1 = wx.BoxSizer(wx.VERTICAL)
|
95
|
+
|
96
|
+
sizer_hor_threads = wx.BoxSizer(wx.HORIZONTAL)
|
97
|
+
sizer_hor1 = wx.BoxSizer(wx.HORIZONTAL)
|
98
|
+
sizer_hor1_1 = wx.BoxSizer(wx.HORIZONTAL)
|
99
|
+
sizer_hor2 = wx.BoxSizer(wx.HORIZONTAL)
|
100
|
+
sizer_hor3 = wx.BoxSizer(wx.HORIZONTAL)
|
101
|
+
sizer_hor4 = wx.BoxSizer(wx.HORIZONTAL)
|
102
|
+
|
103
|
+
# 1st LINE
|
104
|
+
panel = wx.Panel(self)
|
105
|
+
self._but_maindir = wx.Button(panel, label='Main Directory')
|
106
|
+
self._but_maindir.Bind(wx.EVT_BUTTON, self.OnMainDir)
|
107
|
+
|
108
|
+
self._listbox_studyarea = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
|
109
|
+
self._listbox_studyarea.Bind(wx.EVT_LISTBOX, self.OnStudyArea)
|
110
|
+
self._listbox_studyarea.SetToolTip("Choose the study area")
|
111
|
+
|
112
|
+
self._listbox_scenario = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
|
113
|
+
self._listbox_scenario.Bind(wx.EVT_LISTBOX, self.OnScenario)
|
114
|
+
self._listbox_scenario.SetToolTip("Choose the scenario")
|
115
|
+
|
116
|
+
|
117
|
+
# 3nd LINE
|
118
|
+
self._text_process = wx.StaticText(panel, label='Number of threads:')
|
119
|
+
|
120
|
+
self._nb_process = wx.SpinCtrl(panel, value=str(os.cpu_count()), min=1, max=os.cpu_count())
|
121
|
+
self._nb_process.SetToolTip("Number of threads to use")
|
122
|
+
|
123
|
+
sizer_hor_threads.Add(self._text_process, 1, wx.ALL | wx.EXPAND, 0)
|
124
|
+
sizer_hor_threads.Add(self._nb_process, 1, wx.ALL | wx.EXPAND, 0)
|
125
|
+
|
126
|
+
sizer_hor1.Add(self._but_maindir, 2, wx.ALL | wx.EXPAND, 0)
|
127
|
+
sizer_hor1.Add(self._listbox_studyarea, 1, wx.ALL | wx.EXPAND, 0)
|
128
|
+
sizer_hor1.Add(self._listbox_scenario, 1, wx.ALL | wx.EXPAND, 0)
|
129
|
+
|
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
|
+
|
136
|
+
# Hydrodynamic part
|
137
|
+
self._but_checkfiles = wx.Button(panel, label='Check input water depths')
|
138
|
+
self._but_checkfiles.Bind(wx.EVT_BUTTON, self.OnHydrodynInput)
|
139
|
+
|
140
|
+
sizer_hor1_1.Add(self._but_checkfiles, 1, wx.ALL | wx.EXPAND, 0)
|
141
|
+
|
142
|
+
self._but_checkfiles = wx.Button(panel, label='Change / Load water depths results')
|
143
|
+
self._but_checkfiles.Bind(wx.EVT_BUTTON, self.OnLastStepBin)
|
144
|
+
|
145
|
+
sizer_hor1_1.Add(self._but_checkfiles, 1, wx.ALL | wx.EXPAND, 0)
|
146
|
+
|
147
|
+
#Other lines with functions of algorithm
|
148
|
+
self._but_creation = wx.Button(panel, label='DataBase Creation')
|
149
|
+
self._but_creation.Bind(wx.EVT_BUTTON, self.OnCreation)
|
150
|
+
|
151
|
+
self._steps_db = wx.CheckListBox(panel, choices=steps_base_data_creation.get_list_names(), style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
|
152
|
+
|
153
|
+
self._but_vulnerability = wx.Button(panel, label='Vulnerability')
|
154
|
+
self._but_vulnerability.Bind(wx.EVT_BUTTON, self.OnVulnerability)
|
155
|
+
|
156
|
+
self._steps_vulnerability = wx.CheckListBox(panel, choices=steps_vulnerability.get_list_names(), style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
|
157
|
+
|
158
|
+
self._but_acceptability = wx.Button(panel, label='Acceptability')
|
159
|
+
self._but_acceptability.Bind(wx.EVT_BUTTON, self.OnAcceptability)
|
160
|
+
|
161
|
+
self._steps_acceptability = wx.CheckListBox(panel, choices=steps_acceptability.get_list_names(), style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
|
162
|
+
|
163
|
+
sizer_hor2.Add(self._but_creation, 1, wx.ALL | wx.EXPAND, 0)
|
164
|
+
sizer_hor2.Add(self._steps_db, 1, wx.ALL | wx.EXPAND, 0)
|
165
|
+
|
166
|
+
sizer_hor3.Add(self._but_vulnerability, 1, wx.ALL | wx.EXPAND, 0)
|
167
|
+
sizer_hor3.Add(self._steps_vulnerability, 1, wx.ALL | wx.EXPAND, 0)
|
168
|
+
|
169
|
+
sizer_hor4.Add(self._but_acceptability, 1, wx.ALL | wx.EXPAND, 0)
|
170
|
+
sizer_hor4.Add(self._steps_acceptability, 1, wx.ALL | wx.EXPAND, 0)
|
171
|
+
|
172
|
+
sizer_vert1.Add(sizer_hor1, 2, wx.EXPAND, 0)
|
173
|
+
sizer_vert1.Add(sizer_hor1_1, 1, wx.EXPAND, 0)
|
174
|
+
sizer_vert1.Add(sizer_hor_threads, 0, wx.EXPAND, 0)
|
175
|
+
sizer_vert1.Add(sizer_hor2, 1, wx.EXPAND, 0)
|
176
|
+
sizer_vert1.Add(sizer_hor3, 1, wx.EXPAND, 0)
|
177
|
+
sizer_vert1.Add(sizer_hor4, 1, wx.EXPAND, 0)
|
178
|
+
|
179
|
+
# ------
|
180
|
+
|
181
|
+
sizer_vert2 = wx.BoxSizer(wx.VERTICAL)
|
182
|
+
|
183
|
+
self._listbox_returnperiods = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
|
184
|
+
self._listbox_returnperiods.SetToolTip("All available return periods in the database")
|
185
|
+
|
186
|
+
self._listbox_sims = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
|
187
|
+
self._listbox_sims.SetToolTip("All available simulations in the database")
|
188
|
+
|
189
|
+
self._listbox_sims.Bind(wx.EVT_LISTBOX, self.OnSims)
|
190
|
+
self._listbox_sims.Bind(wx.EVT_LISTBOX_DCLICK, self.OnSimsDBLClick)
|
191
|
+
|
192
|
+
sizer_vert2.Add(self._listbox_returnperiods, 1, wx.EXPAND, 0)
|
193
|
+
sizer_vert2.Add(self._listbox_sims, 1, wx.EXPAND, 0)
|
194
|
+
|
195
|
+
# ------
|
196
|
+
|
197
|
+
sizer_vert3 = wx.BoxSizer(wx.VERTICAL)
|
198
|
+
|
199
|
+
matplotlib.use('WXAgg')
|
200
|
+
|
201
|
+
self._figure = Figure(figsize=(5, 4), dpi=100)
|
202
|
+
self._axes = self._figure.add_subplot(111)
|
203
|
+
self._canvas = FigureCanvas(panel, -1, self._figure)
|
204
|
+
self._toolbar = NavigationToolbar2Wx(self._canvas)
|
205
|
+
self._toolbar.Realize()
|
206
|
+
|
207
|
+
sizer_vert3.Add(self._canvas, 1, wx.EXPAND, 0)
|
208
|
+
sizer_vert3.Add(self._toolbar, 0, wx.LEFT | wx.EXPAND, 0)
|
209
|
+
|
210
|
+
# ------
|
211
|
+
|
212
|
+
sizer_hor_main.Add(sizer_vert1, 1, wx.EXPAND, 0)
|
213
|
+
sizer_hor_main.Add(sizer_vert2, 1, wx.EXPAND, 0)
|
214
|
+
sizer_hor_main.Add(sizer_vert3, 1, wx.EXPAND, 0)
|
215
|
+
|
216
|
+
panel.SetSizer(sizer_hor_main)
|
217
|
+
panel.Layout()
|
218
|
+
|
219
|
+
self._but_acceptability.Enable(False)
|
220
|
+
self._but_vulnerability.Enable(False)
|
221
|
+
self._but_creation.Enable(False)
|
222
|
+
|
223
|
+
def OnSims(self, e:wx.ListEvent):
|
224
|
+
""" Load sim into the mapviewer """
|
225
|
+
pass
|
226
|
+
|
227
|
+
def OnSimsDBLClick(self, e:wx.ListEvent):
|
228
|
+
""" Load sim into the mapviewer """
|
229
|
+
if self.mapviewer is None:
|
230
|
+
return
|
231
|
+
|
232
|
+
from ..PyDraw import draw_type
|
233
|
+
|
234
|
+
idx_sim = e.GetSelection()
|
235
|
+
tmppath = self._manager.get_filepath_for_return_period(self._manager.get_return_periods()[idx_sim])
|
236
|
+
if tmppath.stem not in self.mapviewer.get_list_keys(drawing_type=draw_type.ARRAYS):
|
237
|
+
self.mapviewer.add_object('array', filename=str(tmppath), id=tmppath.stem)
|
238
|
+
self.mapviewer.Refresh()
|
239
|
+
|
240
|
+
def OnCheckFiles(self, e):
|
241
|
+
""" Check the files """
|
242
|
+
|
243
|
+
if self._manager is None:
|
244
|
+
logging.error("No main directory selected -- Nothing to check")
|
245
|
+
return
|
246
|
+
|
247
|
+
ret = self._manager.check_files()
|
248
|
+
|
249
|
+
if ret == "":
|
250
|
+
logging.info("The folder is well structured")
|
251
|
+
with wx.MessageDialog(self, "The folder is well structured", "Info", wx.OK | wx.ICON_INFORMATION) as dlg:
|
252
|
+
dlg.ShowModal()
|
253
|
+
else:
|
254
|
+
logging.error(f"Missing files: {ret}")
|
255
|
+
with wx.MessageDialog(self, f"Missing files: \n{ret}", "Error", wx.OK | wx.ICON_ERROR) as dlg:
|
256
|
+
dlg.ShowModal()
|
257
|
+
|
258
|
+
|
259
|
+
def OnHydrodynInput(self,e):
|
260
|
+
""" A test to check if the FILLED water depths files exist.
|
261
|
+
-If YES : the code can go on
|
262
|
+
-If NO : either need to be computed, either the code will use the baseline ones
|
263
|
+
"""
|
264
|
+
|
265
|
+
if self._manager is None:
|
266
|
+
logging.error("No main directory selected -- Nothing to check")
|
267
|
+
return
|
268
|
+
|
269
|
+
paths_FilledWD = self._manager.get_sims_files_for_baseline()
|
270
|
+
|
271
|
+
if len(paths_FilledWD) == 0 :
|
272
|
+
logging.info("There are no interpolated free surface files. Need for them to go on the acceptability computations.")
|
273
|
+
dialog = wx.MessageDialog(None, "There are no interpolated free surface files. Need for them to go on the acceptability computations. Please choose an action.", "Choose an option",
|
274
|
+
wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION)
|
275
|
+
|
276
|
+
dialog.SetYesNoLabels("Use _baseline simulations", "Load simulations")
|
277
|
+
response = dialog.ShowModal()
|
278
|
+
|
279
|
+
if response == wx.ID_YES:
|
280
|
+
logging.info("Decision of using baseline simulations.")
|
281
|
+
paths_FilledWD_base = self._manager.get_sims_files_for_baseline()
|
282
|
+
if len(paths_FilledWD_base) == 0 :
|
283
|
+
logging.info("Cannot select files in the _baseline folder.")
|
284
|
+
else:
|
285
|
+
self._manager.copy_tif_files(paths_FilledWD_base, self._manager.IN_SCEN_DIR)
|
286
|
+
|
287
|
+
elif response == wx.ID_NO:
|
288
|
+
logging.info("Decision of loading simulations.")
|
289
|
+
with wx.MessageDialog(self, f"Please use the 'Change / Load water depths results' button of the manager and follow the instructions.", "Redirecting",
|
290
|
+
wx.OK | wx.ICON_INFORMATION) as dlg:
|
291
|
+
dlg.ShowModal()
|
292
|
+
else:
|
293
|
+
print("Cancelled")
|
294
|
+
|
295
|
+
dialog.Destroy()
|
296
|
+
|
297
|
+
else:
|
298
|
+
for names in paths_FilledWD:
|
299
|
+
logging.info(f"Interpolated free surface file found: {names.name}.")
|
300
|
+
with wx.MessageDialog(self,
|
301
|
+
f"{len(paths_FilledWD)} files of interpolated free surface found in the folder (see logs window). If you want to change it, click the 'Change/ Load' water depths results?",
|
302
|
+
"Information",
|
303
|
+
style=wx.OK | wx.ICON_INFORMATION) as dlg:
|
304
|
+
dlg.ShowModal()
|
305
|
+
|
306
|
+
def OnLastStepBin(self,e):
|
307
|
+
""" Link between acceptability and simulations
|
308
|
+
-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
|
+
-Or they dont exist and need to be done outside this manager
|
310
|
+
"""
|
311
|
+
|
312
|
+
dlg = wx.DirDialog(None, "Please select the simulation folder that contains the folders 'sim_' to use.", style=wx.DD_DEFAULT_STYLE)
|
313
|
+
if dlg.ShowModal() == wx.ID_OK:
|
314
|
+
datadir = Path(dlg.GetPath())
|
315
|
+
logging.info(f"Selected folder : {datadir}")
|
316
|
+
else:
|
317
|
+
logging.info('No folder found / selected. Please try again..')
|
318
|
+
|
319
|
+
sims = {}
|
320
|
+
path_LastSteps = Path(self._manager.IN_SA_EXTRACTED)
|
321
|
+
empty_folder(path_LastSteps)
|
322
|
+
for subdir in datadir.iterdir():
|
323
|
+
if subdir.is_dir() and subdir.name.startswith("sim_"):
|
324
|
+
sims[subdir.name] = subdir
|
325
|
+
fn_read = Path(subdir / "simul_gpu_results")
|
326
|
+
logging.info(f"Found simulation folder: {subdir}")
|
327
|
+
|
328
|
+
parts = subdir.name.split("sim_")
|
329
|
+
if len(parts) > 1:
|
330
|
+
name = parts[1]
|
331
|
+
fn_write = Path(path_LastSteps / (name + '.bin'))
|
332
|
+
read_export_z_bin(fn_read, fn_write)
|
333
|
+
else:
|
334
|
+
logging.info(f"Please, ensure your simulations are named with the return period, e.g sim_T4")
|
335
|
+
|
336
|
+
else:
|
337
|
+
logging.info('No folder found / selected. Please try again...')
|
338
|
+
|
339
|
+
End = False
|
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")
|
346
|
+
|
347
|
+
C = None
|
348
|
+
D = None
|
349
|
+
|
350
|
+
for file in os.listdir(Path(self._manager.IN_SA_DEM)):
|
351
|
+
file_path = Path(self._manager.IN_SA_DEM) / file
|
352
|
+
|
353
|
+
if file_path.is_file() and file.startswith("MNT_") and file_path.suffix == ".bin":
|
354
|
+
if "mask" not in file:
|
355
|
+
D = file_path
|
356
|
+
else:
|
357
|
+
C = file_path
|
358
|
+
|
359
|
+
if D == None:
|
360
|
+
logging.info("DEM (.bin) not found. The file must begins by 'MNT' and CANNOT include 'mask'")
|
361
|
+
|
362
|
+
if C == None:
|
363
|
+
logging.info("DEM mask (.bin) not found. The file must begins by 'MNT' and must include 'mask'")
|
364
|
+
|
365
|
+
A = [os.path.join(path_LastSteps, f) for f in os.listdir(path_LastSteps) if f.endswith(".bin")]
|
366
|
+
B = [os.path.join(path_Interp, os.path.splitext(os.path.basename(f))[0]) for f in A]
|
367
|
+
|
368
|
+
|
369
|
+
with open(bat_file_path, "w") as bat_file:
|
370
|
+
for a, b in zip(A, B):
|
371
|
+
line = f'"{path_code}" filling in="{a}" out="{b}" mask="{C}" dem="{D}"\n'
|
372
|
+
bat_file.write(line)
|
373
|
+
End = True
|
374
|
+
|
375
|
+
if End == True :
|
376
|
+
logging.info("Please wait for the filling computations. A message will appear to notify you when operations are completed.")
|
377
|
+
with wx.MessageDialog(self, f"The interpolation of the given free surface will begin when you press OK, please wait.",
|
378
|
+
"Redirecting", wx.OK | wx.ICON_INFORMATION) as dlg:
|
379
|
+
dlg.ShowModal()
|
380
|
+
|
381
|
+
empty_folder(self._manager.IN_SA_INTERP)
|
382
|
+
subprocess.run([bat_file_path], check=True)
|
383
|
+
|
384
|
+
renamed_files = []
|
385
|
+
path_fichier=self._manager.IN_SA_INTERP
|
386
|
+
for file in path_fichier.glob("*.tif"):
|
387
|
+
if "_h" in file.name:
|
388
|
+
new_name = file.stem.split("_h")[0].replace(".bin", "") + ".tif"
|
389
|
+
file.rename(file.with_name(new_name))
|
390
|
+
renamed_files.append(new_name)
|
391
|
+
#delete the other
|
392
|
+
for file in path_fichier.glob("*.tif"):
|
393
|
+
if "_combl" in file.name or file.name not in renamed_files:
|
394
|
+
file.unlink()
|
395
|
+
logging.info("Filling completed.")
|
396
|
+
with wx.MessageDialog(self, f"Filling completed. Created files : {renamed_files}",
|
397
|
+
"Redirecting", wx.OK | wx.ICON_INFORMATION) as dlg:
|
398
|
+
dlg.ShowModal()
|
399
|
+
|
400
|
+
|
401
|
+
|
402
|
+
def OnMainDir(self, e):
|
403
|
+
|
404
|
+
with wx.DirDialog(self, "Choose the main directory containing the data (folders INPUT, TEMP and OUTPUT):",
|
405
|
+
style=wx.DD_DEFAULT_STYLE
|
406
|
+
) as dlg:
|
407
|
+
|
408
|
+
if dlg.ShowModal() == wx.ID_OK:
|
409
|
+
self._manager = Accept_Manager(dlg.GetPath(), Study_area=None)
|
410
|
+
|
411
|
+
self._listbox_studyarea.Clear()
|
412
|
+
self._listbox_studyarea.InsertItems(self._manager.get_list_studyareas(), 0)
|
413
|
+
|
414
|
+
self._listbox_scenario.Clear()
|
415
|
+
|
416
|
+
ret = self._manager.check_files()
|
417
|
+
|
418
|
+
if ret == "":
|
419
|
+
logging.info("All the files are present")
|
420
|
+
self._but_acceptability.Enable(True)
|
421
|
+
self._but_vulnerability.Enable(True)
|
422
|
+
self._but_creation.Enable(True)
|
423
|
+
else:
|
424
|
+
logging.error(f"Missing files: {ret}")
|
425
|
+
with wx.MessageDialog(self, f"Missing files: \n{ret}", "Error", wx.OK | wx.ICON_ERROR) as dlg:
|
426
|
+
dlg.ShowModal()
|
427
|
+
|
428
|
+
else:
|
429
|
+
return
|
430
|
+
|
431
|
+
def OnStudyArea(self, e):
|
432
|
+
""" Change the study area """
|
433
|
+
|
434
|
+
if self._manager is None:
|
435
|
+
return
|
436
|
+
|
437
|
+
study_area:str = self._manager.get_list_studyareas(with_suffix=True)[e.GetSelection()]
|
438
|
+
self._manager.change_studyarea(study_area)
|
439
|
+
|
440
|
+
self._listbox_scenario.Clear()
|
441
|
+
sc = self._manager.get_list_scenarios()
|
442
|
+
self._listbox_scenario.InsertItems(sc, 0)
|
443
|
+
|
444
|
+
if self.mapviewer is not None:
|
445
|
+
tmp_path = self._manager.IN_STUDY_AREA / study_area
|
446
|
+
|
447
|
+
from ..PyDraw import draw_type
|
448
|
+
if not tmp_path.stem in self.mapviewer.get_list_keys(drawing_type=draw_type.VECTORS):
|
449
|
+
self.mapviewer.add_object('vector', filename=str(tmp_path), id=tmp_path.stem)
|
450
|
+
self.mapviewer.Refresh()
|
451
|
+
|
452
|
+
def OnScenario(self, e):
|
453
|
+
""" Change the scenario """
|
454
|
+
if self._manager is None:
|
455
|
+
return
|
456
|
+
|
457
|
+
scenario = self._manager.get_list_scenarios()[e.GetSelection()]
|
458
|
+
self._manager.change_scenario(scenario)
|
459
|
+
|
460
|
+
self._listbox_returnperiods.Clear()
|
461
|
+
rt = self._manager.get_return_periods()
|
462
|
+
if len(rt) != 0 :
|
463
|
+
self._listbox_returnperiods.InsertItems([str(crt) for crt in rt],0)
|
464
|
+
self._listbox_sims.Clear()
|
465
|
+
sims = [str(self._manager.get_filepath_for_return_period(currt).name) for currt in rt]
|
466
|
+
self._listbox_sims.InsertItems(sims, 0)
|
467
|
+
ponds = self._manager.get_ponderations()
|
468
|
+
if isinstance(ponds, list):
|
469
|
+
self._axes.clear()
|
470
|
+
ponds.plot(ax=self._axes, kind='bar')
|
471
|
+
self._canvas.draw()
|
472
|
+
|
473
|
+
def OnCreation(self, e):
|
474
|
+
""" Create the database """
|
475
|
+
|
476
|
+
if self._manager is None:
|
477
|
+
return
|
478
|
+
|
479
|
+
wx.MessageBox(
|
480
|
+
"The database will now be created. This process may take some time, and the window may temporarily stop responding.",
|
481
|
+
"Information",
|
482
|
+
wx.OK | wx.ICON_INFORMATION
|
483
|
+
)
|
484
|
+
|
485
|
+
steps = list(self._steps_db.GetCheckedStrings())
|
486
|
+
steps = [int(cur.split('-')[1]) for cur in steps]
|
487
|
+
|
488
|
+
if len(steps) != 0:
|
489
|
+
Base_data_creation(self._manager.main_dir, number_procs=self._nb_process.GetValue(), steps=steps)
|
490
|
+
|
491
|
+
wx.MessageBox(
|
492
|
+
"The database is created with the selected steps.",
|
493
|
+
"Information",
|
494
|
+
wx.OK | wx.ICON_INFORMATION
|
495
|
+
)
|
496
|
+
else :
|
497
|
+
wx.MessageBox(
|
498
|
+
"No database created because no steps were selected.",
|
499
|
+
"Attention",
|
500
|
+
wx.OK | wx.ICON_INFORMATION
|
501
|
+
)
|
502
|
+
|
503
|
+
def OnVulnerability(self, e):
|
504
|
+
""" Run the vulnerability """
|
505
|
+
|
506
|
+
if self._manager is None:
|
507
|
+
return
|
508
|
+
|
509
|
+
steps = list(self._steps_vulnerability.GetCheckedStrings())
|
510
|
+
steps = [int(cur.split('-')[1]) for cur in steps]
|
511
|
+
|
512
|
+
if len(steps) == 0:
|
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])
|
518
|
+
wx.MessageBox(
|
519
|
+
"Vulnerability computed with every steps.",
|
520
|
+
"Information",
|
521
|
+
wx.OK | wx.ICON_INFORMATION
|
522
|
+
)
|
523
|
+
|
524
|
+
else :
|
525
|
+
Vulnerability(self._manager.main_dir,
|
526
|
+
scenario=self._manager.scenario,
|
527
|
+
Study_area=self._manager.Study_area,
|
528
|
+
steps=steps)
|
529
|
+
wx.MessageBox(
|
530
|
+
"Vulnerability computed with the selected steps.",
|
531
|
+
"Information",
|
532
|
+
wx.OK | wx.ICON_INFORMATION
|
533
|
+
)
|
534
|
+
|
535
|
+
def OnAcceptability(self, e):
|
536
|
+
""" Run the acceptability """
|
537
|
+
|
538
|
+
if self._manager is None:
|
539
|
+
return
|
540
|
+
|
541
|
+
steps = list(self._steps_acceptability.GetCheckedStrings())
|
542
|
+
steps = [int(cur.split('-')[1]) for cur in steps]
|
543
|
+
|
544
|
+
if len(steps) == 0:
|
545
|
+
logging.error("No steps selected. By default every steps will be performed.")
|
546
|
+
Acceptability(self._manager.main_dir,
|
547
|
+
scenario=self._manager.scenario,
|
548
|
+
Study_area=self._manager.Study_area,
|
549
|
+
steps=[1,2,3,4,5])
|
550
|
+
wx.MessageBox(
|
551
|
+
"Acceptability computed with every steps.",
|
552
|
+
"Information",
|
553
|
+
wx.OK | wx.ICON_INFORMATION
|
554
|
+
)
|
555
|
+
else :
|
556
|
+
Acceptability(self._manager.main_dir,
|
557
|
+
scenario=self._manager.scenario,
|
558
|
+
Study_area=self._manager.Study_area,
|
559
|
+
steps=steps)
|
560
|
+
wx.MessageBox(
|
561
|
+
"Acceptability computed with the selected steps.",
|
562
|
+
"Information",
|
563
|
+
wx.OK | wx.ICON_INFORMATION
|
564
|
+
)
|