wolfhece 2.1.77__py3-none-any.whl → 2.1.79__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.
@@ -1,328 +1,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
-
11
- from .acceptability import Base_data_creation, Database_to_raster, Vulnerability, Acceptability
12
- from .func import Accept_Manager
13
-
14
- import wx
15
- import logging
16
- import matplotlib
17
- from matplotlib.figure import Figure
18
- from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
19
- from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar2Wx
20
- class AcceptabilityGui(wx.Frame):
21
-
22
- def __init__(self, parent=None, width=1024, height=500):
23
-
24
- super(wx.Frame, self).__init__(parent, title='Acceptability', size=(width, height))
25
-
26
- self._manager = None
27
- self._mapviewer = None
28
-
29
- self.InitUI()
30
-
31
- @property
32
- def mapviewer(self):
33
- return self._mapviewer
34
-
35
- @mapviewer.setter
36
- def mapviewer(self, value):
37
- from ..PyDraw import WolfMapViewer
38
-
39
- if not isinstance(value, WolfMapViewer):
40
- raise TypeError("The mapviewer must be a WolfMapViewer")
41
-
42
- self._mapviewer = value
43
-
44
- def InitUI(self):
45
-
46
- sizer_hor_main = wx.BoxSizer(wx.HORIZONTAL)
47
-
48
- sizer_vert1 = wx.BoxSizer(wx.VERTICAL)
49
-
50
- sizer_hor1 = wx.BoxSizer(wx.HORIZONTAL)
51
- sizer_hor1_1 = wx.BoxSizer(wx.HORIZONTAL)
52
- sizer_hor2 = wx.BoxSizer(wx.HORIZONTAL)
53
- sizer_hor3 = wx.BoxSizer(wx.HORIZONTAL)
54
- sizer_hor4 = wx.BoxSizer(wx.HORIZONTAL)
55
-
56
- panel = wx.Panel(self)
57
-
58
- self._but_maindir = wx.Button(panel, label='Main Directory')
59
- self._but_maindir.Bind(wx.EVT_BUTTON, self.OnMainDir)
60
-
61
- self._listbox_studyarea = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
62
- self._listbox_studyarea.Bind(wx.EVT_LISTBOX, self.OnStudyArea)
63
- self._listbox_studyarea.SetToolTip("Choose the study area")
64
-
65
- self._listbox_scenario = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
66
- self._listbox_scenario.Bind(wx.EVT_LISTBOX, self.OnScenario)
67
- self._listbox_scenario.SetToolTip("Choose the scenario")
68
-
69
- sizer_hor1.Add(self._but_maindir, 2, wx.ALL | wx.EXPAND, 0)
70
- sizer_hor1.Add(self._listbox_studyarea, 1, wx.ALL | wx.EXPAND, 0)
71
- sizer_hor1.Add(self._listbox_scenario, 1, wx.ALL | wx.EXPAND, 0)
72
-
73
- self._but_checkfiles = wx.Button(panel, label='Check Files')
74
- self._but_checkfiles.Bind(wx.EVT_BUTTON, self.OnCheckFiles)
75
-
76
- sizer_hor1_1.Add(self._but_checkfiles, 1, wx.ALL | wx.EXPAND, 0)
77
-
78
- self._but_creation = wx.Button(panel, label='DataBase Creation')
79
- self._but_creation.Bind(wx.EVT_BUTTON, self.OnCreation)
80
-
81
- self._but_vulnerability = wx.Button(panel, label='Vulnerability')
82
- self._but_vulnerability.Bind(wx.EVT_BUTTON, self.OnVulnerability)
83
-
84
- self._but_vulnerability1 = wx.Button(panel, label='only Phase 1')
85
- self._but_vulnerability1.Bind(wx.EVT_BUTTON, self.OnVulnerability1)
86
-
87
- self._but_vulnerability2 = wx.Button(panel, label='only Phase 2')
88
- self._but_vulnerability2.Bind(wx.EVT_BUTTON, self.OnVulnerability2)
89
-
90
- self._but_vulnerability3 = wx.Button(panel, label='only Phase 3')
91
- self._but_vulnerability3.Bind(wx.EVT_BUTTON, self.OnVulnerability3)
92
-
93
- self._but_acceptability = wx.Button(panel, label='Acceptability')
94
- self._but_acceptability.Bind(wx.EVT_BUTTON, self.OnAcceptability)
95
-
96
- sizer_hor2.Add(self._but_creation, 1, wx.ALL | wx.EXPAND, 0)
97
-
98
- sizer_hor3.Add(self._but_vulnerability, 3, wx.ALL | wx.EXPAND, 0)
99
- sizer_hor3.Add(self._but_vulnerability1, 1, wx.ALL | wx.EXPAND, 0)
100
- sizer_hor3.Add(self._but_vulnerability2, 1, wx.ALL | wx.EXPAND, 0)
101
- sizer_hor3.Add(self._but_vulnerability3, 1, wx.ALL | wx.EXPAND, 0)
102
-
103
- sizer_hor4.Add(self._but_acceptability, 1, wx.ALL | wx.EXPAND, 0)
104
-
105
- sizer_vert1.Add(sizer_hor1, 2, wx.EXPAND, 0)
106
- sizer_vert1.Add(sizer_hor1_1, 1, wx.EXPAND, 0)
107
- sizer_vert1.Add(sizer_hor2, 1, wx.EXPAND, 0)
108
- sizer_vert1.Add(sizer_hor3, 1, wx.EXPAND, 0)
109
- sizer_vert1.Add(sizer_hor4, 1, wx.EXPAND, 0)
110
-
111
- # ------
112
-
113
- sizer_vert2 = wx.BoxSizer(wx.VERTICAL)
114
-
115
- self._listbox_returnperiods = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
116
- self._listbox_returnperiods.SetToolTip("All available return periods in the database")
117
-
118
- self._listbox_sims = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
119
- self._listbox_sims.SetToolTip("All available simulations in the database")
120
-
121
- self._listbox_sims.Bind(wx.EVT_LISTBOX, self.OnSims)
122
- self._listbox_sims.Bind(wx.EVT_LISTBOX_DCLICK, self.OnSimsDBLClick)
123
-
124
- sizer_vert2.Add(self._listbox_returnperiods, 1, wx.EXPAND, 0)
125
- sizer_vert2.Add(self._listbox_sims, 1, wx.EXPAND, 0)
126
-
127
- # ------
128
-
129
- sizer_vert3 = wx.BoxSizer(wx.VERTICAL)
130
-
131
- matplotlib.use('WXAgg')
132
-
133
- self._figure = Figure(figsize=(5, 4), dpi=100)
134
- self._axes = self._figure.add_subplot(111)
135
- self._canvas = FigureCanvas(panel, -1, self._figure)
136
- self._toolbar = NavigationToolbar2Wx(self._canvas)
137
- self._toolbar.Realize()
138
-
139
- sizer_vert3.Add(self._canvas, 1, wx.EXPAND, 0)
140
- sizer_vert3.Add(self._toolbar, 0, wx.LEFT | wx.EXPAND, 0)
141
-
142
- # ------
143
-
144
- sizer_hor_main.Add(sizer_vert1, 1, wx.EXPAND, 0)
145
- sizer_hor_main.Add(sizer_vert2, 1, wx.EXPAND, 0)
146
- sizer_hor_main.Add(sizer_vert3, 1, wx.EXPAND, 0)
147
-
148
- panel.SetSizer(sizer_hor_main)
149
- panel.Layout()
150
-
151
- self._but_acceptability.Enable(False)
152
- self._but_vulnerability.Enable(False)
153
- self._but_vulnerability1.Enable(False)
154
- self._but_vulnerability2.Enable(False)
155
- self._but_vulnerability3.Enable(False)
156
- self._but_creation.Enable(False)
157
-
158
- def OnSims(self, e:wx.ListEvent):
159
- """ Load sim into the mapviewer """
160
- pass
161
-
162
- def OnSimsDBLClick(self, e:wx.ListEvent):
163
- """ Load sim into the mapviewer """
164
- if self.mapviewer is None:
165
- return
166
-
167
- from ..PyDraw import draw_type
168
-
169
- idx_sim = e.GetSelection()
170
- tmppath = self._manager.get_filepath_for_return_period(self._manager.get_return_periods()[idx_sim])
171
- if tmppath.stem not in self.mapviewer.get_list_keys(drawing_type=draw_type.ARRAYS):
172
- self.mapviewer.add_object('array', filename=str(tmppath), id=tmppath.stem)
173
- self.mapviewer.Refresh()
174
-
175
- def OnCheckFiles(self, e):
176
- """ Check the files """
177
-
178
- if self._manager is None:
179
- logging.error("No main directory selected -- Nothing to check")
180
- return
181
-
182
- ret = self._manager.check_files()
183
-
184
- if ret == "":
185
- logging.info("All files are present")
186
- with wx.MessageDialog(self, "All files are present in the INPUT directory", "Info", wx.OK | wx.ICON_INFORMATION) as dlg:
187
- dlg.ShowModal()
188
- else:
189
- logging.error(f"Missing files: {ret}")
190
- with wx.MessageDialog(self, f"Missing files: \n{ret}", "Error", wx.OK | wx.ICON_ERROR) as dlg:
191
- dlg.ShowModal()
192
-
193
- def OnMainDir(self, e):
194
-
195
- with wx.DirDialog(self, "Choose the main directory containing the data:",
196
- style=wx.DD_DEFAULT_STYLE
197
- ) as dlg:
198
-
199
- if dlg.ShowModal() == wx.ID_OK:
200
- self._manager = Accept_Manager(dlg.GetPath(), Study_area=None)
201
-
202
- self._listbox_studyarea.Clear()
203
- self._listbox_studyarea.InsertItems(self._manager.get_list_studyareas(), 0)
204
-
205
- self._listbox_scenario.Clear()
206
-
207
- ret = self._manager.check_files()
208
-
209
- if ret == "":
210
- logging.info("All files are present")
211
- self._but_acceptability.Enable(True)
212
- self._but_vulnerability.Enable(True)
213
- self._but_vulnerability1.Enable(True)
214
- self._but_vulnerability2.Enable(True)
215
- self._but_vulnerability3.Enable(True)
216
- self._but_creation.Enable(True)
217
- else:
218
- logging.error(f"Missing files: {ret}")
219
- with wx.MessageDialog(self, f"Missing files: \n{ret}", "Error", wx.OK | wx.ICON_ERROR) as dlg:
220
- dlg.ShowModal()
221
-
222
- else:
223
- return
224
-
225
- def OnStudyArea(self, e):
226
- """ Change the study area """
227
-
228
- if self._manager is None:
229
- return
230
-
231
- study_area:str = self._manager.get_list_studyareas(with_suffix=True)[e.GetSelection()]
232
- self._manager.change_studyarea(study_area)
233
-
234
- self._listbox_scenario.Clear()
235
- self._listbox_scenario.InsertItems(self._manager.get_list_scenarios(), 0)
236
-
237
- if self.mapviewer is not None:
238
- tmp_path = self._manager.IN_STUDY_AREA / study_area
239
-
240
- from ..PyDraw import draw_type
241
- if not tmp_path.stem in self.mapviewer.get_list_keys(drawing_type=draw_type.VECTORS):
242
- self.mapviewer.add_object('vector', filename=str(tmp_path), id=tmp_path.stem)
243
- self.mapviewer.Refresh()
244
-
245
- def OnScenario(self, e):
246
- """ Change the scenario """
247
-
248
- if self._manager is None:
249
- return
250
-
251
- scenario = self._manager.get_list_scenarios()[e.GetSelection()]
252
- self._manager.change_scenario(scenario)
253
-
254
- self._listbox_returnperiods.Clear()
255
- rt = self._manager.get_return_periods()
256
- self._listbox_returnperiods.InsertItems([str(crt) for crt in rt],0)
257
-
258
- self._listbox_sims.Clear()
259
- sims = [str(self._manager.get_filepath_for_return_period(currt).name) for currt in rt]
260
- self._listbox_sims.InsertItems(sims, 0)
261
-
262
- ponds = self._manager.get_ponderations()
263
-
264
- self._axes.clear()
265
- ponds.plot(ax=self._axes, kind='bar')
266
- self._canvas.draw()
267
-
268
- def OnCreation(self, e):
269
- """ Create the database """
270
-
271
- if self._manager is None:
272
- return
273
-
274
- Base_data_creation(self._manager.main_dir, number_procs=1)
275
-
276
- def OnVulnerability(self, e):
277
- """ Run the vulnerability """
278
-
279
- if self._manager is None:
280
- return
281
-
282
- Vulnerability(self._manager.main_dir,
283
- scenario=self._manager.scenario,
284
- Study_area=self._manager.Study_area,
285
- steps=[1,2,3])
286
-
287
- def OnVulnerability1(self, e):
288
- """ Run the vulnerability - Phase 1"""
289
-
290
- if self._manager is None:
291
- return
292
-
293
- Vulnerability(self._manager.main_dir,
294
- scenario=self._manager.scenario,
295
- Study_area=self._manager.Study_area,
296
- steps=[1])
297
-
298
- def OnVulnerability2(self, e):
299
- """ Run the vulnerability - Phase 2"""
300
-
301
- if self._manager is None:
302
- return
303
-
304
- Vulnerability(self._manager.main_dir,
305
- scenario=self._manager.scenario,
306
- Study_area=self._manager.Study_area,
307
- steps=[2])
308
-
309
- def OnVulnerability3(self, e):
310
- """ Run the vulnerability - Phase 3"""
311
-
312
- if self._manager is None:
313
- return
314
-
315
- Vulnerability(self._manager.main_dir,
316
- scenario=self._manager.scenario,
317
- Study_area=self._manager.Study_area,
318
- steps=[3])
319
-
320
- def OnAcceptability(self, e):
321
- """ Run the acceptability """
322
-
323
- if self._manager is None:
324
- return
325
-
326
- Acceptability(self._manager.main_dir,
327
- scenario=self._manager.scenario,
328
- Study_area=self._manager.Study_area)
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 Base_data_creation, Database_to_raster, Vulnerability, Acceptability
12
+ from .acceptability import steps_base_data_creation, steps_vulnerability, steps_acceptability
13
+ from .func import Accept_Manager
14
+
15
+ import wx
16
+ import logging
17
+ import matplotlib
18
+ from matplotlib.figure import Figure
19
+ from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
20
+ from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar2Wx
21
+ import os
22
+ from gettext import gettext as _
23
+
24
+ class AcceptabilityGui(wx.Frame):
25
+ """ The main frame for the vulnerability/acceptability computation """
26
+
27
+ def __init__(self, parent=None, width=1024, height=500):
28
+
29
+ super(wx.Frame, self).__init__(parent, title='Acceptability', size=(width, height))
30
+
31
+ self._manager = None
32
+ self._mapviewer = None
33
+
34
+ self.InitUI()
35
+
36
+ @property
37
+ def mapviewer(self):
38
+ return self._mapviewer
39
+
40
+ @mapviewer.setter
41
+ def mapviewer(self, value):
42
+ from ..PyDraw import WolfMapViewer
43
+
44
+ if not isinstance(value, WolfMapViewer):
45
+ raise TypeError("The mapviewer must be a WolfMapViewer")
46
+
47
+ self._mapviewer = value
48
+
49
+ def InitUI(self):
50
+
51
+ sizer_hor_main = wx.BoxSizer(wx.HORIZONTAL)
52
+
53
+ sizer_vert1 = wx.BoxSizer(wx.VERTICAL)
54
+
55
+ sizer_hor_threads = wx.BoxSizer(wx.HORIZONTAL)
56
+ sizer_hor1 = wx.BoxSizer(wx.HORIZONTAL)
57
+ sizer_hor1_1 = wx.BoxSizer(wx.HORIZONTAL)
58
+ sizer_hor2 = wx.BoxSizer(wx.HORIZONTAL)
59
+ sizer_hor3 = wx.BoxSizer(wx.HORIZONTAL)
60
+ sizer_hor4 = wx.BoxSizer(wx.HORIZONTAL)
61
+
62
+ panel = wx.Panel(self)
63
+
64
+ self._but_maindir = wx.Button(panel, label='Main Directory')
65
+ self._but_maindir.Bind(wx.EVT_BUTTON, self.OnMainDir)
66
+
67
+ self._listbox_studyarea = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
68
+ self._listbox_studyarea.Bind(wx.EVT_LISTBOX, self.OnStudyArea)
69
+ self._listbox_studyarea.SetToolTip("Choose the study area")
70
+
71
+ self._listbox_scenario = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
72
+ self._listbox_scenario.Bind(wx.EVT_LISTBOX, self.OnScenario)
73
+ self._listbox_scenario.SetToolTip("Choose the scenario")
74
+
75
+
76
+ self._text_process = wx.StaticText(panel, label='Number of threads:')
77
+
78
+ self._nb_process = wx.SpinCtrl(panel, value=str(os.cpu_count()), min=1, max=os.cpu_count())
79
+ self._nb_process.SetToolTip("Number of threads to use")
80
+
81
+ sizer_hor_threads.Add(self._text_process, 1, wx.ALL | wx.EXPAND, 0)
82
+ sizer_hor_threads.Add(self._nb_process, 1, wx.ALL | wx.EXPAND, 0)
83
+
84
+ sizer_hor1.Add(self._but_maindir, 2, wx.ALL | wx.EXPAND, 0)
85
+ sizer_hor1.Add(self._listbox_studyarea, 1, wx.ALL | wx.EXPAND, 0)
86
+ sizer_hor1.Add(self._listbox_scenario, 1, wx.ALL | wx.EXPAND, 0)
87
+
88
+ self._but_checkfiles = wx.Button(panel, label='Check Files')
89
+ self._but_checkfiles.Bind(wx.EVT_BUTTON, self.OnCheckFiles)
90
+
91
+ sizer_hor1_1.Add(self._but_checkfiles, 1, wx.ALL | wx.EXPAND, 0)
92
+
93
+ self._but_creation = wx.Button(panel, label='DataBase Creation')
94
+ self._but_creation.Bind(wx.EVT_BUTTON, self.OnCreation)
95
+
96
+ self._steps_db = wx.CheckListBox(panel, choices=steps_base_data_creation.get_list_names(), style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
97
+
98
+ self._but_vulnerability = wx.Button(panel, label='Vulnerability')
99
+ self._but_vulnerability.Bind(wx.EVT_BUTTON, self.OnVulnerability)
100
+
101
+ self._steps_vulnerability = wx.CheckListBox(panel, choices=steps_vulnerability.get_list_names(), style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
102
+
103
+ self._but_acceptability = wx.Button(panel, label='Acceptability')
104
+ self._but_acceptability.Bind(wx.EVT_BUTTON, self.OnAcceptability)
105
+
106
+ self._steps_acceptability = wx.CheckListBox(panel, choices=steps_acceptability.get_list_names(), style=wx.LB_MULTIPLE | wx.CHK_CHECKED)
107
+
108
+ sizer_hor2.Add(self._but_creation, 1, wx.ALL | wx.EXPAND, 0)
109
+ sizer_hor2.Add(self._steps_db, 1, wx.ALL | wx.EXPAND, 0)
110
+
111
+ sizer_hor3.Add(self._but_vulnerability, 1, wx.ALL | wx.EXPAND, 0)
112
+ sizer_hor3.Add(self._steps_vulnerability, 1, wx.ALL | wx.EXPAND, 0)
113
+
114
+ sizer_hor4.Add(self._but_acceptability, 1, wx.ALL | wx.EXPAND, 0)
115
+ sizer_hor4.Add(self._steps_acceptability, 1, wx.ALL | wx.EXPAND, 0)
116
+
117
+ sizer_vert1.Add(sizer_hor1, 2, wx.EXPAND, 0)
118
+ sizer_vert1.Add(sizer_hor1_1, 1, wx.EXPAND, 0)
119
+ sizer_vert1.Add(sizer_hor_threads, 0, wx.EXPAND, 0)
120
+ sizer_vert1.Add(sizer_hor2, 1, wx.EXPAND, 0)
121
+ sizer_vert1.Add(sizer_hor3, 1, wx.EXPAND, 0)
122
+ sizer_vert1.Add(sizer_hor4, 1, wx.EXPAND, 0)
123
+
124
+ # ------
125
+
126
+ sizer_vert2 = wx.BoxSizer(wx.VERTICAL)
127
+
128
+ self._listbox_returnperiods = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
129
+ self._listbox_returnperiods.SetToolTip("All available return periods in the database")
130
+
131
+ self._listbox_sims = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
132
+ self._listbox_sims.SetToolTip("All available simulations in the database")
133
+
134
+ self._listbox_sims.Bind(wx.EVT_LISTBOX, self.OnSims)
135
+ self._listbox_sims.Bind(wx.EVT_LISTBOX_DCLICK, self.OnSimsDBLClick)
136
+
137
+ sizer_vert2.Add(self._listbox_returnperiods, 1, wx.EXPAND, 0)
138
+ sizer_vert2.Add(self._listbox_sims, 1, wx.EXPAND, 0)
139
+
140
+ # ------
141
+
142
+ sizer_vert3 = wx.BoxSizer(wx.VERTICAL)
143
+
144
+ matplotlib.use('WXAgg')
145
+
146
+ self._figure = Figure(figsize=(5, 4), dpi=100)
147
+ self._axes = self._figure.add_subplot(111)
148
+ self._canvas = FigureCanvas(panel, -1, self._figure)
149
+ self._toolbar = NavigationToolbar2Wx(self._canvas)
150
+ self._toolbar.Realize()
151
+
152
+ sizer_vert3.Add(self._canvas, 1, wx.EXPAND, 0)
153
+ sizer_vert3.Add(self._toolbar, 0, wx.LEFT | wx.EXPAND, 0)
154
+
155
+ # ------
156
+
157
+ sizer_hor_main.Add(sizer_vert1, 1, wx.EXPAND, 0)
158
+ sizer_hor_main.Add(sizer_vert2, 1, wx.EXPAND, 0)
159
+ sizer_hor_main.Add(sizer_vert3, 1, wx.EXPAND, 0)
160
+
161
+ panel.SetSizer(sizer_hor_main)
162
+ panel.Layout()
163
+
164
+ self._but_acceptability.Enable(False)
165
+ self._but_vulnerability.Enable(False)
166
+ self._but_creation.Enable(False)
167
+
168
+ def OnSims(self, e:wx.ListEvent):
169
+ """ Load sim into the mapviewer """
170
+ pass
171
+
172
+ def OnSimsDBLClick(self, e:wx.ListEvent):
173
+ """ Load sim into the mapviewer """
174
+ if self.mapviewer is None:
175
+ return
176
+
177
+ from ..PyDraw import draw_type
178
+
179
+ idx_sim = e.GetSelection()
180
+ tmppath = self._manager.get_filepath_for_return_period(self._manager.get_return_periods()[idx_sim])
181
+ if tmppath.stem not in self.mapviewer.get_list_keys(drawing_type=draw_type.ARRAYS):
182
+ self.mapviewer.add_object('array', filename=str(tmppath), id=tmppath.stem)
183
+ self.mapviewer.Refresh()
184
+
185
+ def OnCheckFiles(self, e):
186
+ """ Check the files """
187
+
188
+ if self._manager is None:
189
+ logging.error("No main directory selected -- Nothing to check")
190
+ return
191
+
192
+ ret = self._manager.check_files()
193
+
194
+ if ret == "":
195
+ logging.info("All files are present")
196
+ with wx.MessageDialog(self, "All files are present in the INPUT directory", "Info", wx.OK | wx.ICON_INFORMATION) as dlg:
197
+ dlg.ShowModal()
198
+ else:
199
+ logging.error(f"Missing files: {ret}")
200
+ with wx.MessageDialog(self, f"Missing files: \n{ret}", "Error", wx.OK | wx.ICON_ERROR) as dlg:
201
+ dlg.ShowModal()
202
+
203
+ def OnMainDir(self, e):
204
+
205
+ with wx.DirDialog(self, "Choose the main directory containing the data:",
206
+ style=wx.DD_DEFAULT_STYLE
207
+ ) as dlg:
208
+
209
+ if dlg.ShowModal() == wx.ID_OK:
210
+ self._manager = Accept_Manager(dlg.GetPath(), Study_area=None)
211
+
212
+ self._listbox_studyarea.Clear()
213
+ self._listbox_studyarea.InsertItems(self._manager.get_list_studyareas(), 0)
214
+
215
+ self._listbox_scenario.Clear()
216
+
217
+ ret = self._manager.check_files()
218
+
219
+ if ret == "":
220
+ logging.info("All files are present")
221
+ self._but_acceptability.Enable(True)
222
+ self._but_vulnerability.Enable(True)
223
+ self._but_creation.Enable(True)
224
+ else:
225
+ logging.error(f"Missing files: {ret}")
226
+ with wx.MessageDialog(self, f"Missing files: \n{ret}", "Error", wx.OK | wx.ICON_ERROR) as dlg:
227
+ dlg.ShowModal()
228
+
229
+ else:
230
+ return
231
+
232
+ def OnStudyArea(self, e):
233
+ """ Change the study area """
234
+
235
+ if self._manager is None:
236
+ return
237
+
238
+ study_area:str = self._manager.get_list_studyareas(with_suffix=True)[e.GetSelection()]
239
+ self._manager.change_studyarea(study_area)
240
+
241
+ self._listbox_scenario.Clear()
242
+ self._listbox_scenario.InsertItems(self._manager.get_list_scenarios(), 0)
243
+
244
+ if self.mapviewer is not None:
245
+ tmp_path = self._manager.IN_STUDY_AREA / study_area
246
+
247
+ from ..PyDraw import draw_type
248
+ if not tmp_path.stem in self.mapviewer.get_list_keys(drawing_type=draw_type.VECTORS):
249
+ self.mapviewer.add_object('vector', filename=str(tmp_path), id=tmp_path.stem)
250
+ self.mapviewer.Refresh()
251
+
252
+ def OnScenario(self, e):
253
+ """ Change the scenario """
254
+
255
+ if self._manager is None:
256
+ return
257
+
258
+ scenario = self._manager.get_list_scenarios()[e.GetSelection()]
259
+ self._manager.change_scenario(scenario)
260
+
261
+ self._listbox_returnperiods.Clear()
262
+ rt = self._manager.get_return_periods()
263
+ self._listbox_returnperiods.InsertItems([str(crt) for crt in rt],0)
264
+
265
+ self._listbox_sims.Clear()
266
+ sims = [str(self._manager.get_filepath_for_return_period(currt).name) for currt in rt]
267
+ self._listbox_sims.InsertItems(sims, 0)
268
+
269
+ ponds = self._manager.get_ponderations()
270
+
271
+ self._axes.clear()
272
+ ponds.plot(ax=self._axes, kind='bar')
273
+ self._canvas.draw()
274
+
275
+ def OnCreation(self, e):
276
+ """ Create the database """
277
+
278
+ if self._manager is None:
279
+ return
280
+
281
+ steps = list(self._steps_db.GetCheckedStrings())
282
+ steps = [int(cur.split('-')[1]) for cur in steps]
283
+
284
+ if len(steps) == 0:
285
+ logging.error("No steps selected")
286
+ return
287
+
288
+ nb = int(self._nb_process.GetValue())
289
+
290
+ if nb == 1:
291
+ logging.warning("Running in single thread")
292
+ logging.warning("This may take a long time")
293
+
294
+ Base_data_creation(self._manager.main_dir, number_procs=nb, steps=steps)
295
+
296
+
297
+ def OnVulnerability(self, e):
298
+ """ Run the vulnerability """
299
+
300
+ if self._manager is None:
301
+ return
302
+
303
+ steps = list(self._steps_vulnerability.GetCheckedStrings())
304
+ steps = [int(cur.split('-')[1]) for cur in steps]
305
+
306
+ if len(steps) == 0:
307
+ logging.error("No steps selected")
308
+ return
309
+
310
+ Vulnerability(self._manager.main_dir,
311
+ scenario=self._manager.scenario,
312
+ Study_area=self._manager.Study_area,
313
+ steps=steps)
314
+
315
+ def OnAcceptability(self, e):
316
+ """ Run the acceptability """
317
+
318
+ if self._manager is None:
319
+ return
320
+
321
+ steps = list(self._steps_acceptability.GetCheckedStrings())
322
+ steps = [int(cur.split('-')[1]) for cur in steps]
323
+
324
+ if len(steps) == 0:
325
+ logging.error("No steps selected")
326
+ return
327
+
328
+ Acceptability(self._manager.main_dir,
329
+ scenario=self._manager.scenario,
330
+ Study_area=self._manager.Study_area,
331
+ steps=steps)