wolfhece 2.1.23__py3-none-any.whl → 2.1.27__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/PyPalette.py +26 -10
- wolfhece/acceptability/Parallels.py +106 -0
- wolfhece/acceptability/__init__.py +3 -0
- wolfhece/acceptability/acceptability.py +477 -0
- wolfhece/acceptability/acceptability1.py +211 -0
- wolfhece/acceptability/acceptability_gui.py +318 -0
- wolfhece/acceptability/cli.py +150 -0
- wolfhece/acceptability/func.py +1427 -0
- wolfhece/apps/version.py +1 -1
- wolfhece/cli.py +5 -0
- wolfhece/libs/WolfOGL.c +16164 -2680
- wolfhece/libs/WolfOGL.pyx +357 -0
- wolfhece/libs/wolfogl.cp310-win_amd64.pyd +0 -0
- wolfhece/pyviews.py +3 -3
- wolfhece/wolf_array.py +406 -157
- wolfhece/wolfresults_2D.py +2 -2
- {wolfhece-2.1.23.dist-info → wolfhece-2.1.27.dist-info}/METADATA +2 -1
- {wolfhece-2.1.23.dist-info → wolfhece-2.1.27.dist-info}/RECORD +21 -16
- {wolfhece-2.1.23.dist-info → wolfhece-2.1.27.dist-info}/entry_points.txt +4 -1
- wolfhece/libs/wolfogl.cp39-win_amd64.pyd +0 -0
- wolfhece/libs/wolfpy.cp39-win_amd64.pyd +0 -0
- {wolfhece-2.1.23.dist-info → wolfhece-2.1.27.dist-info}/WHEEL +0 -0
- {wolfhece-2.1.23.dist-info → wolfhece-2.1.27.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,211 @@
|
|
1
|
+
# import pandas as pd
|
2
|
+
# import Parallels
|
3
|
+
# import os
|
4
|
+
# import func
|
5
|
+
# from osgeo import gdal
|
6
|
+
# import fiona
|
7
|
+
# import glob
|
8
|
+
# import numpy as np
|
9
|
+
# import geopandas as gpd
|
10
|
+
|
11
|
+
# def Vulnerability2(main_dir, resolution):
|
12
|
+
# os.chdir(main_dir)
|
13
|
+
# print("STEP2: convert vectors to raster based on their vulnerability values")
|
14
|
+
# layer = fiona.listlayers(os.getcwd()+"//TEMP//DATABASES//SA_database_final_V.gpkg")
|
15
|
+
# database = os.getcwd()+"//TEMP//DATABASES//SA_database_final_V.gpkg"
|
16
|
+
# extent = os.getcwd()+"//INPUT//STUDY_AREA//Bassin_SA.shp"
|
17
|
+
# pixel=resolution
|
18
|
+
# attribute = "Vulne"
|
19
|
+
# parallel_v2r(layer, database, extent, attribute, pixel)
|
20
|
+
# attribute = "Code"
|
21
|
+
# parallel_v2r(layer, database, extent, attribute, pixel)
|
22
|
+
|
23
|
+
# def base_data_creation(main_dir, Original_gdb, Study_Area, CaPa_Walloon, PICC_Walloon):
|
24
|
+
# #Change the directory
|
25
|
+
# os.chdir(main_dir)
|
26
|
+
# # Step 1, Clip GDB data
|
27
|
+
# file_path=os.getcwd()+"//INPUT//DATABASE//"+str(Original_gdb)
|
28
|
+
# Study_Area=os.getcwd()+"//INPUT//STUDY_AREA//"+str(Study_Area)
|
29
|
+
# data_type="OpenfileGDB"
|
30
|
+
# number_procs = 8
|
31
|
+
# output_gpkg = os.getcwd()+"//TEMP//DATABASES//SA_database.gpkg"
|
32
|
+
# paths = pd.read_csv(os.getcwd()+"//INPUT//CSVs//Vulnerability_matrix_new1.csv", sep=",", encoding='latin-1')
|
33
|
+
# paths["subfolder"]=None
|
34
|
+
# x, y = paths.shape
|
35
|
+
# for i in range(x):
|
36
|
+
# a=paths["Path"][i].split('/')
|
37
|
+
# paths["subfolder"][i]=a[1]
|
38
|
+
# layers = paths["subfolder"].to_list()
|
39
|
+
# Parallels.parallel_gpd_clip(layers, file_path, Study_Area, output_gpkg, data_type, number_procs)
|
40
|
+
# # Step 2, Clip Cadaster data
|
41
|
+
# file_path=os.getcwd()+"//INPUT//DATABASE//"+str(CaPa_Walloon)
|
42
|
+
# data_type='GPKG'
|
43
|
+
# number_procs = 8
|
44
|
+
# output_gpkg = os.getcwd()+"//TEMP//DATABASES//SA_CaPa.gpkg"
|
45
|
+
# layers = ["CaBu", "CaPa"]
|
46
|
+
# Parallels.parallel_gpd_clip(layers, file_path, Study_Area, output_gpkg, data_type, number_procs)
|
47
|
+
# # Step 3, Clip PICC data
|
48
|
+
# file_path=os.getcwd()+"//INPUT//DATABASE//"+str(PICC_Walloon)
|
49
|
+
# data_type='OpenfileGDB'
|
50
|
+
# number_procs = 8
|
51
|
+
# output_gpkg = os.getcwd()+"//TEMP//DATABASES//SA_PICC.gpkg"
|
52
|
+
# layers=['CONSTR_BATIEMPRISE']
|
53
|
+
# Parallels.parallel_gpd_clip(layers, file_path, Study_Area, output_gpkg, data_type, number_procs)
|
54
|
+
# #Step 4, create database based on changes in report
|
55
|
+
# input_database=os.getcwd()+"//TEMP//DATABASES//SA_database.gpkg"
|
56
|
+
# layers = fiona.listlayers(os.getcwd()+"//TEMP//DATABASES//SA_database.gpkg")
|
57
|
+
# walous = ["WALOUS_2018_LB72_112", "WALOUS_2018_LB72_31", "WALOUS_2018_LB72_32", "WALOUS_2018_LB72_331",
|
58
|
+
# "WALOUS_2018_LB72_332", "WALOUS_2018_LB72_333", "WALOUS_2018_LB72_34"]
|
59
|
+
# data_type="GPKG"
|
60
|
+
# PICC = gpd.read_file(os.getcwd()+"//TEMP//DATABASES//SA_PICC.gpkg", driver="GPKG", layer = 'CONSTR_BATIEMPRISE')
|
61
|
+
# CaPa = gpd.read_file(os.getcwd()+"//TEMP//DATABASES//SA_CaPa.gpkg", driver='GPKG', layer= 'CaPa')
|
62
|
+
# output_database = os.getcwd()+"//TEMP//DATABASES//SA_database_final.gpkg"
|
63
|
+
# for i in range(len(layers)):
|
64
|
+
# print(i)
|
65
|
+
# func.data_modification(input_database, data_type, layers[i], walous, output_database, PICC, CaPa)
|
66
|
+
# func.shp_to_raster(os.getcwd()+"//INPUT//DATABASE//CE_IGN_TOP10V/CE_IGN_TOP10V.shp", os.getcwd()+"//TEMP//DATABASES//CE_IGN_TOP10V.tiff")
|
67
|
+
# #Pre-processing for Vulnerability
|
68
|
+
# layers = fiona.listlayers(os.getcwd()+"//TEMP//DATABASES//SA_database_final.gpkg")
|
69
|
+
# paths = pd.read_csv(os.getcwd()+"//INPUT//CSVs//Vulnerability_matrix_new1.csv", sep=",", encoding='latin-1')
|
70
|
+
# paths[["name", "name1"]] = paths["Path"].str.split("/", expand=True)
|
71
|
+
# names = paths["name1"].to_list()
|
72
|
+
# list_shp = list(set(names).difference(layers))
|
73
|
+
# print("Excluded layers due to no features in shapefiles:")
|
74
|
+
# print(list_shp)
|
75
|
+
# paths1 =paths[~paths["name1"].isin(list_shp)]
|
76
|
+
# a,b = paths1.shape
|
77
|
+
# print("STEP1: Saving the database for Vulnerability with attributes Vulne and Code")
|
78
|
+
# for i in range(a):
|
79
|
+
# shp = gpd.read_file(os.getcwd()+"//TEMP//DATABASES//SA_database_final.gpkg",
|
80
|
+
# driver='GPKG',
|
81
|
+
# layer=paths1["name1"][i])
|
82
|
+
# x, y = shp.shape
|
83
|
+
# if x > 0:
|
84
|
+
# shp["Path"] = paths["name1"][i]
|
85
|
+
# shp["Vulne"] = paths["Vulne"][i]
|
86
|
+
# shp["Code"] = paths["Code"][i]
|
87
|
+
# shp = shp[["geometry", "Path", "Vulne","Code"]]
|
88
|
+
# shp.to_file(os.getcwd()+"//TEMP//DATABASES//SA_database_final_V.gpkg",
|
89
|
+
# driver='GPKG',
|
90
|
+
# layer=paths["name1"][i])
|
91
|
+
# print("STEP2: convert vectors to raster based on their vulnerability values")
|
92
|
+
# layer = fiona.listlayers(os.getcwd()+"//TEMP//DATABASES//SA_database_final_V.gpkg")
|
93
|
+
# database = os.getcwd()+"//TEMP//DATABASES//SA_database_final_V.gpkg"
|
94
|
+
# extent = os.getcwd()+"//INPUT//STUDY_AREA//Bassin_SA.shp"
|
95
|
+
# attribute = "Vulne"
|
96
|
+
# Parallels.parallel_v2r(layer, database, extent, attribute)
|
97
|
+
# attribute = "Code"
|
98
|
+
# Parallels.parallel_v2r(layer, database, extent, attribute)
|
99
|
+
# #
|
100
|
+
# def Vulnerability(main_dir,sc,AOI):
|
101
|
+
# print("Starting VULNERABILITY computations at 1 m resolution")
|
102
|
+
# os.chdir(main_dir)
|
103
|
+
# # layers = fiona.listlayers(os.getcwd()+"//TEMP//DATABASES//SA_database_final.gpkg")
|
104
|
+
# # # load the paths from csv with Vulne values
|
105
|
+
# # paths = pd.read_csv(os.getcwd()+"//INPUT//CSVs//Vulnerability_matrix_new1.csv", sep=",", encoding='latin-1')
|
106
|
+
# # paths[["name", "name1"]] = paths["Path"].str.split("/", expand=True)
|
107
|
+
# # #names = paths["name1"].to_list()
|
108
|
+
# # # loop for loading all shapefiles with the names matching with vulnerability matrix
|
109
|
+
# # names = paths["name1"].to_list()
|
110
|
+
# # list_shp = list(set(names).difference(layers))
|
111
|
+
# # print("Excluded layers due to no features in shapefiles:")
|
112
|
+
# # print(list_shp)
|
113
|
+
# # paths1 =paths[~paths["name1"].isin(list_shp)]
|
114
|
+
# # a,b = paths1.shape
|
115
|
+
# # print("STEP1: Saving the database for Vulnerability with attributes Vulne and Code")
|
116
|
+
# # for i in range(a):
|
117
|
+
# # shp = gpd.read_file(os.getcwd()+"//TEMP//DATABASES//SA_database_final.gpkg",
|
118
|
+
# # driver='GPKG',
|
119
|
+
# # layer=paths1["name1"][i])
|
120
|
+
# # x, y = shp.shape
|
121
|
+
# # if x > 0:
|
122
|
+
# # shp["Path"] = paths["name1"][i]
|
123
|
+
# # shp["Vulne"] = paths["Vulne"][i]
|
124
|
+
# # shp["Code"] = paths["Code"][i]
|
125
|
+
# # shp = shp[["geometry", "Path", "Vulne","Code"]]
|
126
|
+
# # shp.to_file(os.getcwd()+"//TEMP//DATABASES//SA_database_final_V.gpkg",
|
127
|
+
# # driver='GPKG',
|
128
|
+
# # layer=paths["name1"][i])
|
129
|
+
# # print("STEP2: convert vectors to raster based on their vulnerability values")
|
130
|
+
# # layer = fiona.listlayers(os.getcwd()+"//TEMP//DATABASES//SA_database_final_V.gpkg")
|
131
|
+
# # database = os.getcwd()+"//TEMP//DATABASES//SA_database_final_V.gpkg"
|
132
|
+
# # extent = os.getcwd()+"//INPUT//STUDY_AREA//Bassin_SA.shp"
|
133
|
+
# # attribute = "Vulne"
|
134
|
+
# # Parallels.parallel_v2r(layer, database, extent, attribute)
|
135
|
+
# # attribute = "Code"
|
136
|
+
# # Parallels.parallel_v2r(layer, database, extent, attribute)
|
137
|
+
# bu = glob.glob(os.getcwd()+"//INPUT//REMOVED_BUILDINGS//Scenario"+str(sc)+"//*.shp")
|
138
|
+
# if len(bu)>0:
|
139
|
+
# bu_PICC = os.getcwd()+"//INPUT//REMOVED_BUILDINGS//Scenario"+str(sc)+"//Removed_Buildings_PICC.shp"
|
140
|
+
# bu_CaBu = os.getcwd()+"//INPUT//REMOVED_BUILDINGS//Scenario"+str(sc)+"//Removed_Buildings_CaBu.shp"
|
141
|
+
# func.shp_to_raster(bu_PICC, os.getcwd()+"//TEMP//REMOVED_BUILDINGS//Scenario"+str(sc)+"//Removed_Buildings_PICC.tiff")
|
142
|
+
# func.shp_to_raster(bu_CaBu, os.getcwd()+"//TEMP//REMOVED_BUILDINGS//Scenario"+str(sc)+"//Removed_Buildings_CaBu.tiff")
|
143
|
+
# else:
|
144
|
+
# print("No buildings were removed in water depth analysis OR No shapefiles in INPUT/REMOVED_BUILDINGS/Scenario"+str(sc))
|
145
|
+
# print("STEP3: Generate Vulnerability rasters 1m")
|
146
|
+
# attribute="Vulne"
|
147
|
+
# Output_tiff = os.getcwd()+"//TEMP//VULNERABILITY//Scenario"+str(sc)+"//Vulnerability_SA.tiff"
|
148
|
+
# func.Comp_Vulnerability(Output_tiff, attribute,sc)
|
149
|
+
# attribute = "Code"
|
150
|
+
# Output_tiff = os.getcwd()+"//TEMP//VULNERABILITY//Scenario"+str(sc)+"//Vulnerability_Code_SA.tiff"
|
151
|
+
# print(Output_tiff)
|
152
|
+
# func.Comp_Vulnerability(Output_tiff, attribute,sc)
|
153
|
+
# print("STEP4: Save Vulnerability files for the area of interest")
|
154
|
+
# func.match_vuln_modrec(os.getcwd() + "//TEMP//DATABASES//CE_IGN_TOP10V/CE_IGN_TOP10V.tiff",
|
155
|
+
# os.getcwd() + "//TEMP//Masked/River_extent.tiff", os.getcwd()+"//INPUT//WATER_DEPTH//Scenario"+str(sc)+"//T1000.tif")
|
156
|
+
# func.match_vuln_modrec(os.getcwd() + "//TEMP//VULNERABILITY//Scenario"+str(sc)+"//Vulnerability_SA.tiff",
|
157
|
+
# os.getcwd() + "//OUTPUT//VULNERABILITY//Scenario"+str(sc)+"Vulnerability_"+str(AOI)+".tiff", os.getcwd()+"//INPUT//WATER_DEPTH//Scenario"+str(sc)+"//T1000.tif")
|
158
|
+
# func.match_vuln_modrec(os.getcwd() + "//TEMP//VULNERABILITY//Scenario"+str(sc)+"//Vulnerability_Code_SA.tiff",
|
159
|
+
# os.getcwd() + "//OUTPUT//VULNERABILITY//Scenario"+str(sc)+"//Vulnerability_Code"+str(AOI)+".tiff", os.getcwd()+"//INPUT//WATER_DEPTH//Scenario"+str(sc)+"//T1000.tif")
|
160
|
+
|
161
|
+
# def Vulnerability2(main_dir, attribute):
|
162
|
+
# os.chdir(main_dir)
|
163
|
+
# Output_tiff = os.getcwd()+"//OUTPUT//VULNERABILITY//Vulnerability_Code.tiff"
|
164
|
+
# func.Comp_Vulnerability(Output_tiff, attribute)
|
165
|
+
# #func.match_vuln_modrec(os.getcwd() + "//TEMP//DATABASES//CE_IGN_TOP10V/CE_IGN_TOP10V.tiff",
|
166
|
+
# # os.getcwd() + "//TEMP//Masked/River_extent.tiff")
|
167
|
+
# #func.match_vuln_modrec(os.getcwd() + "//OUTPUT//VULNERABILITY//Vulnerability.tiff",
|
168
|
+
# # os.getcwd() + "//TEMP//Masked/Vulnerability_extent.tiff")
|
169
|
+
# #func.match_vuln_modrec(os.getcwd() + "//OUTPUT//VULNERABILITY//Vulnerability_Code.tiff",
|
170
|
+
# # os.getcwd() + "//TEMP//Masked/Vulnerability_Code_extent.tiff")
|
171
|
+
|
172
|
+
# def acceptability(main_dir,area_of_interest):
|
173
|
+
# os.chdir(main_dir)
|
174
|
+
# Vulne = gdal.Open(os.getcwd() + "//TEMP//Masked/Vulnerability_extent.tiff")
|
175
|
+
# Vulne = Vulne.GetRasterBand(1).ReadAsArray()
|
176
|
+
# riv = gdal.Open(os.getcwd() + "//TEMP//Masked/River_extent.tiff")
|
177
|
+
# riv = riv.GetRasterBand(1).ReadAsArray()
|
178
|
+
# list1 = ["2", "5", "15", "25", "50", "100", "1000"]
|
179
|
+
# # sample for saving the raster
|
180
|
+
# # mod1 = rasterio.open("G://00_GT_Resilience//Simulations_Theux//Scen_"+str(scen)+"//Theux_1.3K_sim_T1000_h.tif")
|
181
|
+
# Qfile = pd.read_csv(os.getcwd() + "//INPUT//CSVs//Book2.csv")
|
182
|
+
# # run vul-mod for 4 return intervals
|
183
|
+
# x = glob.glob(os.getcwd() + "//INPUT//WATER_DEPTH//*.tiff")
|
184
|
+
# Area_interest = area_of_interest
|
185
|
+
# for i in range(len(list1)):
|
186
|
+
# mod = gdal.Open(x[i])
|
187
|
+
# mod = mod.GetRasterBand(1).ReadAsArray()
|
188
|
+
# mod[mod == 0] = np.nan
|
189
|
+
# mod[riv == 1] = np.nan
|
190
|
+
# func.VulMod(Qfile, mod, Vulne, list1[i], Area_interest)
|
191
|
+
# ax=locals()
|
192
|
+
# list1=["2","5", "15","25", "50", "100", "1000"]
|
193
|
+
# qs= glob.glob(os.getcwd()+"//TEMP//Q_files//*.tiff")
|
194
|
+
# for i in range(len(list1)):
|
195
|
+
# ax["vm"+str(i)] = gdal.Open(qs[i])
|
196
|
+
# ax["vm"+str(i)] = ax["vm"+str(i)].GetRasterBand(1).ReadAsArray()
|
197
|
+
# #Remove nans from other Q files for final acceptability computation
|
198
|
+
# for i in range(len(list1)-1):
|
199
|
+
# ax["vm"+str(i)+str(1)] = np.nan_to_num(ax["vm"+str(i)], nan=0)
|
200
|
+
# ax["vm"+str(i)+str(1)][np.isnan(ax["vm"+str(len(list1))])] = np.nan
|
201
|
+
# pond = pd.read_csv(os.getcwd()+"//INPUT//CSVs//Ponderation.csv")
|
202
|
+
# comb = vm6*float(pond.iloc[6,1]) + vm51*float(pond.iloc[5,1]) + vm41*float(pond.iloc[4,1]) + vm31*float(pond.iloc[3,1]) + vm21*float(pond.iloc[2,1]) + vm11*float(pond.iloc[1,1]) +vm01*float(pond.iloc[0,1])
|
203
|
+
# dst_filename = os.getcwd()+"//OUTPUT//ACCEPTABILITY//Acceptability"+str(area_of_interest)+".tiff"
|
204
|
+
# y_pixels, x_pixels = comb.shape # number of pixels in x
|
205
|
+
# driver = gdal.GetDriverByName('GTiff')
|
206
|
+
# dataset = driver.Create(dst_filename, x_pixels, y_pixels, gdal.GDT_Float32, 1, options=["COMPRESS=LZW"])
|
207
|
+
# dataset.GetRasterBand(1).WriteArray(comb.astype(np.float32))
|
208
|
+
# input_raster = os.getcwd()+"//OUTPUT//ACCEPTABILITY//Acceptability"+str(area_of_interest)+".tiff"
|
209
|
+
# output_raster = os.getcwd()+"//OUTPUT//ACCEPTABILITY//Acceptability"+str(area_of_interest)+"_100m.tiff"
|
210
|
+
# Agg = gdal.Warp(output_raster, input_raster, xRes=100, yRes=100, resampleAlg='Average')
|
211
|
+
# Agg = None
|
@@ -0,0 +1,318 @@
|
|
1
|
+
from .acceptability import Base_data_creation, Database_to_raster, Vulnerability, Acceptability
|
2
|
+
from .func import Accept_Manager
|
3
|
+
|
4
|
+
import wx
|
5
|
+
import logging
|
6
|
+
import matplotlib
|
7
|
+
from matplotlib.figure import Figure
|
8
|
+
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
|
9
|
+
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar2Wx
|
10
|
+
class AcceptabilityGui(wx.Frame):
|
11
|
+
|
12
|
+
def __init__(self, parent=None, width=1024, height=500):
|
13
|
+
|
14
|
+
super(wx.Frame, self).__init__(parent, title='Acceptability', size=(width, height))
|
15
|
+
|
16
|
+
self._manager = None
|
17
|
+
self._mapviewer = None
|
18
|
+
|
19
|
+
self.InitUI()
|
20
|
+
|
21
|
+
@property
|
22
|
+
def mapviewer(self):
|
23
|
+
return self._mapviewer
|
24
|
+
|
25
|
+
@mapviewer.setter
|
26
|
+
def mapviewer(self, value):
|
27
|
+
from ..PyDraw import WolfMapViewer
|
28
|
+
|
29
|
+
if not isinstance(value, WolfMapViewer):
|
30
|
+
raise TypeError("The mapviewer must be a WolfMapViewer")
|
31
|
+
|
32
|
+
self._mapviewer = value
|
33
|
+
|
34
|
+
def InitUI(self):
|
35
|
+
|
36
|
+
sizer_hor_main = wx.BoxSizer(wx.HORIZONTAL)
|
37
|
+
|
38
|
+
sizer_vert1 = wx.BoxSizer(wx.VERTICAL)
|
39
|
+
|
40
|
+
sizer_hor1 = wx.BoxSizer(wx.HORIZONTAL)
|
41
|
+
sizer_hor1_1 = wx.BoxSizer(wx.HORIZONTAL)
|
42
|
+
sizer_hor2 = wx.BoxSizer(wx.HORIZONTAL)
|
43
|
+
sizer_hor3 = wx.BoxSizer(wx.HORIZONTAL)
|
44
|
+
sizer_hor4 = wx.BoxSizer(wx.HORIZONTAL)
|
45
|
+
|
46
|
+
panel = wx.Panel(self)
|
47
|
+
|
48
|
+
self._but_maindir = wx.Button(panel, label='Main Directory')
|
49
|
+
self._but_maindir.Bind(wx.EVT_BUTTON, self.OnMainDir)
|
50
|
+
|
51
|
+
self._listbox_studyarea = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
|
52
|
+
self._listbox_studyarea.Bind(wx.EVT_LISTBOX, self.OnStudyArea)
|
53
|
+
self._listbox_studyarea.SetToolTip("Choose the study area")
|
54
|
+
|
55
|
+
self._listbox_scenario = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
|
56
|
+
self._listbox_scenario.Bind(wx.EVT_LISTBOX, self.OnScenario)
|
57
|
+
self._listbox_scenario.SetToolTip("Choose the scenario")
|
58
|
+
|
59
|
+
sizer_hor1.Add(self._but_maindir, 2, wx.ALL | wx.EXPAND, 0)
|
60
|
+
sizer_hor1.Add(self._listbox_studyarea, 1, wx.ALL | wx.EXPAND, 0)
|
61
|
+
sizer_hor1.Add(self._listbox_scenario, 1, wx.ALL | wx.EXPAND, 0)
|
62
|
+
|
63
|
+
self._but_checkfiles = wx.Button(panel, label='Check Files')
|
64
|
+
self._but_checkfiles.Bind(wx.EVT_BUTTON, self.OnCheckFiles)
|
65
|
+
|
66
|
+
sizer_hor1_1.Add(self._but_checkfiles, 1, wx.ALL | wx.EXPAND, 0)
|
67
|
+
|
68
|
+
self._but_creation = wx.Button(panel, label='DataBase Creation')
|
69
|
+
self._but_creation.Bind(wx.EVT_BUTTON, self.OnCreation)
|
70
|
+
|
71
|
+
self._but_vulnerability = wx.Button(panel, label='Vulnerability')
|
72
|
+
self._but_vulnerability.Bind(wx.EVT_BUTTON, self.OnVulnerability)
|
73
|
+
|
74
|
+
self._but_vulnerability1 = wx.Button(panel, label='only Phase 1')
|
75
|
+
self._but_vulnerability1.Bind(wx.EVT_BUTTON, self.OnVulnerability1)
|
76
|
+
|
77
|
+
self._but_vulnerability2 = wx.Button(panel, label='only Phase 2')
|
78
|
+
self._but_vulnerability2.Bind(wx.EVT_BUTTON, self.OnVulnerability2)
|
79
|
+
|
80
|
+
self._but_vulnerability3 = wx.Button(panel, label='only Phase 3')
|
81
|
+
self._but_vulnerability3.Bind(wx.EVT_BUTTON, self.OnVulnerability3)
|
82
|
+
|
83
|
+
self._but_acceptability = wx.Button(panel, label='Acceptability')
|
84
|
+
self._but_acceptability.Bind(wx.EVT_BUTTON, self.OnAcceptability)
|
85
|
+
|
86
|
+
sizer_hor2.Add(self._but_creation, 1, wx.ALL | wx.EXPAND, 0)
|
87
|
+
|
88
|
+
sizer_hor3.Add(self._but_vulnerability, 3, wx.ALL | wx.EXPAND, 0)
|
89
|
+
sizer_hor3.Add(self._but_vulnerability1, 1, wx.ALL | wx.EXPAND, 0)
|
90
|
+
sizer_hor3.Add(self._but_vulnerability2, 1, wx.ALL | wx.EXPAND, 0)
|
91
|
+
sizer_hor3.Add(self._but_vulnerability3, 1, wx.ALL | wx.EXPAND, 0)
|
92
|
+
|
93
|
+
sizer_hor4.Add(self._but_acceptability, 1, wx.ALL | wx.EXPAND, 0)
|
94
|
+
|
95
|
+
sizer_vert1.Add(sizer_hor1, 2, wx.EXPAND, 0)
|
96
|
+
sizer_vert1.Add(sizer_hor1_1, 1, wx.EXPAND, 0)
|
97
|
+
sizer_vert1.Add(sizer_hor2, 1, wx.EXPAND, 0)
|
98
|
+
sizer_vert1.Add(sizer_hor3, 1, wx.EXPAND, 0)
|
99
|
+
sizer_vert1.Add(sizer_hor4, 1, wx.EXPAND, 0)
|
100
|
+
|
101
|
+
# ------
|
102
|
+
|
103
|
+
sizer_vert2 = wx.BoxSizer(wx.VERTICAL)
|
104
|
+
|
105
|
+
self._listbox_returnperiods = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
|
106
|
+
self._listbox_returnperiods.SetToolTip("All available return periods in the database")
|
107
|
+
|
108
|
+
self._listbox_sims = wx.ListBox(panel, choices=[], style=wx.LB_SINGLE)
|
109
|
+
self._listbox_sims.SetToolTip("All available simulations in the database")
|
110
|
+
|
111
|
+
self._listbox_sims.Bind(wx.EVT_LISTBOX, self.OnSims)
|
112
|
+
self._listbox_sims.Bind(wx.EVT_LISTBOX_DCLICK, self.OnSimsDBLClick)
|
113
|
+
|
114
|
+
sizer_vert2.Add(self._listbox_returnperiods, 1, wx.EXPAND, 0)
|
115
|
+
sizer_vert2.Add(self._listbox_sims, 1, wx.EXPAND, 0)
|
116
|
+
|
117
|
+
# ------
|
118
|
+
|
119
|
+
sizer_vert3 = wx.BoxSizer(wx.VERTICAL)
|
120
|
+
|
121
|
+
matplotlib.use('WXAgg')
|
122
|
+
|
123
|
+
self._figure = Figure(figsize=(5, 4), dpi=100)
|
124
|
+
self._axes = self._figure.add_subplot(111)
|
125
|
+
self._canvas = FigureCanvas(panel, -1, self._figure)
|
126
|
+
self._toolbar = NavigationToolbar2Wx(self._canvas)
|
127
|
+
self._toolbar.Realize()
|
128
|
+
|
129
|
+
sizer_vert3.Add(self._canvas, 1, wx.EXPAND, 0)
|
130
|
+
sizer_vert3.Add(self._toolbar, 0, wx.LEFT | wx.EXPAND, 0)
|
131
|
+
|
132
|
+
# ------
|
133
|
+
|
134
|
+
sizer_hor_main.Add(sizer_vert1, 1, wx.EXPAND, 0)
|
135
|
+
sizer_hor_main.Add(sizer_vert2, 1, wx.EXPAND, 0)
|
136
|
+
sizer_hor_main.Add(sizer_vert3, 1, wx.EXPAND, 0)
|
137
|
+
|
138
|
+
panel.SetSizer(sizer_hor_main)
|
139
|
+
panel.Layout()
|
140
|
+
|
141
|
+
self._but_acceptability.Enable(False)
|
142
|
+
self._but_vulnerability.Enable(False)
|
143
|
+
self._but_vulnerability1.Enable(False)
|
144
|
+
self._but_vulnerability2.Enable(False)
|
145
|
+
self._but_vulnerability3.Enable(False)
|
146
|
+
self._but_creation.Enable(False)
|
147
|
+
|
148
|
+
def OnSims(self, e:wx.ListEvent):
|
149
|
+
""" Load sim into the mapviewer """
|
150
|
+
pass
|
151
|
+
|
152
|
+
def OnSimsDBLClick(self, e:wx.ListEvent):
|
153
|
+
""" Load sim into the mapviewer """
|
154
|
+
if self.mapviewer is None:
|
155
|
+
return
|
156
|
+
|
157
|
+
from ..PyDraw import draw_type
|
158
|
+
|
159
|
+
idx_sim = e.GetSelection()
|
160
|
+
tmppath = self._manager.get_filepath_for_return_period(self._manager.get_return_periods()[idx_sim])
|
161
|
+
if tmppath.stem not in self.mapviewer.get_list_keys(drawing_type=draw_type.ARRAYS):
|
162
|
+
self.mapviewer.add_object('array', filename=str(tmppath), id=tmppath.stem)
|
163
|
+
self.mapviewer.Refresh()
|
164
|
+
|
165
|
+
def OnCheckFiles(self, e):
|
166
|
+
""" Check the files """
|
167
|
+
|
168
|
+
if self._manager is None:
|
169
|
+
logging.error("No main directory selected -- Nothing to check")
|
170
|
+
return
|
171
|
+
|
172
|
+
ret = self._manager.check_files()
|
173
|
+
|
174
|
+
if ret == "":
|
175
|
+
logging.info("All files are present")
|
176
|
+
with wx.MessageDialog(self, "All files are present in the INPUT directory", "Info", wx.OK | wx.ICON_INFORMATION) as dlg:
|
177
|
+
dlg.ShowModal()
|
178
|
+
else:
|
179
|
+
logging.error(f"Missing files: {ret}")
|
180
|
+
with wx.MessageDialog(self, f"Missing files: \n{ret}", "Error", wx.OK | wx.ICON_ERROR) as dlg:
|
181
|
+
dlg.ShowModal()
|
182
|
+
|
183
|
+
def OnMainDir(self, e):
|
184
|
+
|
185
|
+
with wx.DirDialog(self, "Choose the main directory containing the data:",
|
186
|
+
style=wx.DD_DEFAULT_STYLE
|
187
|
+
) as dlg:
|
188
|
+
|
189
|
+
if dlg.ShowModal() == wx.ID_OK:
|
190
|
+
self._manager = Accept_Manager(dlg.GetPath(), Study_area=None)
|
191
|
+
|
192
|
+
self._listbox_studyarea.Clear()
|
193
|
+
self._listbox_studyarea.InsertItems(self._manager.get_list_studyareas(), 0)
|
194
|
+
|
195
|
+
self._listbox_scenario.Clear()
|
196
|
+
|
197
|
+
ret = self._manager.check_files()
|
198
|
+
|
199
|
+
if ret == "":
|
200
|
+
logging.info("All files are present")
|
201
|
+
self._but_acceptability.Enable(True)
|
202
|
+
self._but_vulnerability.Enable(True)
|
203
|
+
self._but_vulnerability1.Enable(True)
|
204
|
+
self._but_vulnerability2.Enable(True)
|
205
|
+
self._but_vulnerability3.Enable(True)
|
206
|
+
self._but_creation.Enable(True)
|
207
|
+
else:
|
208
|
+
logging.error(f"Missing files: {ret}")
|
209
|
+
with wx.MessageDialog(self, f"Missing files: \n{ret}", "Error", wx.OK | wx.ICON_ERROR) as dlg:
|
210
|
+
dlg.ShowModal()
|
211
|
+
|
212
|
+
else:
|
213
|
+
return
|
214
|
+
|
215
|
+
def OnStudyArea(self, e):
|
216
|
+
""" Change the study area """
|
217
|
+
|
218
|
+
if self._manager is None:
|
219
|
+
return
|
220
|
+
|
221
|
+
study_area:str = self._manager.get_list_studyareas(with_suffix=True)[e.GetSelection()]
|
222
|
+
self._manager.change_studyarea(study_area)
|
223
|
+
|
224
|
+
self._listbox_scenario.Clear()
|
225
|
+
self._listbox_scenario.InsertItems(self._manager.get_list_scenarios(), 0)
|
226
|
+
|
227
|
+
if self.mapviewer is not None:
|
228
|
+
tmp_path = self._manager.IN_STUDY_AREA / study_area
|
229
|
+
|
230
|
+
from ..PyDraw import draw_type
|
231
|
+
if not tmp_path.stem in self.mapviewer.get_list_keys(drawing_type=draw_type.VECTORS):
|
232
|
+
self.mapviewer.add_object('vector', filename=str(tmp_path), id=tmp_path.stem)
|
233
|
+
self.mapviewer.Refresh()
|
234
|
+
|
235
|
+
def OnScenario(self, e):
|
236
|
+
""" Change the scenario """
|
237
|
+
|
238
|
+
if self._manager is None:
|
239
|
+
return
|
240
|
+
|
241
|
+
scenario = self._manager.get_list_scenarios()[e.GetSelection()]
|
242
|
+
self._manager.change_scenario(scenario)
|
243
|
+
|
244
|
+
self._listbox_returnperiods.Clear()
|
245
|
+
rt = self._manager.get_return_periods()
|
246
|
+
self._listbox_returnperiods.InsertItems([str(crt) for crt in rt],0)
|
247
|
+
|
248
|
+
self._listbox_sims.Clear()
|
249
|
+
sims = [str(self._manager.get_filepath_for_return_period(currt).name) for currt in rt]
|
250
|
+
self._listbox_sims.InsertItems(sims, 0)
|
251
|
+
|
252
|
+
ponds = self._manager.get_ponderations()
|
253
|
+
|
254
|
+
self._axes.clear()
|
255
|
+
ponds.plot(ax=self._axes, kind='bar')
|
256
|
+
self._canvas.draw()
|
257
|
+
|
258
|
+
def OnCreation(self, e):
|
259
|
+
""" Create the database """
|
260
|
+
|
261
|
+
if self._manager is None:
|
262
|
+
return
|
263
|
+
|
264
|
+
Base_data_creation(self._manager.main_dir, number_procs=1)
|
265
|
+
|
266
|
+
def OnVulnerability(self, e):
|
267
|
+
""" Run the vulnerability """
|
268
|
+
|
269
|
+
if self._manager is None:
|
270
|
+
return
|
271
|
+
|
272
|
+
Vulnerability(self._manager.main_dir,
|
273
|
+
scenario=self._manager.scenario,
|
274
|
+
Study_area=self._manager.Study_area,
|
275
|
+
steps=[1,2,3])
|
276
|
+
|
277
|
+
def OnVulnerability1(self, e):
|
278
|
+
""" Run the vulnerability - Phase 1"""
|
279
|
+
|
280
|
+
if self._manager is None:
|
281
|
+
return
|
282
|
+
|
283
|
+
Vulnerability(self._manager.main_dir,
|
284
|
+
scenario=self._manager.scenario,
|
285
|
+
Study_area=self._manager.Study_area,
|
286
|
+
steps=[1])
|
287
|
+
|
288
|
+
def OnVulnerability2(self, e):
|
289
|
+
""" Run the vulnerability - Phase 2"""
|
290
|
+
|
291
|
+
if self._manager is None:
|
292
|
+
return
|
293
|
+
|
294
|
+
Vulnerability(self._manager.main_dir,
|
295
|
+
scenario=self._manager.scenario,
|
296
|
+
Study_area=self._manager.Study_area,
|
297
|
+
steps=[2])
|
298
|
+
|
299
|
+
def OnVulnerability3(self, e):
|
300
|
+
""" Run the vulnerability - Phase 3"""
|
301
|
+
|
302
|
+
if self._manager is None:
|
303
|
+
return
|
304
|
+
|
305
|
+
Vulnerability(self._manager.main_dir,
|
306
|
+
scenario=self._manager.scenario,
|
307
|
+
Study_area=self._manager.Study_area,
|
308
|
+
steps=[3])
|
309
|
+
|
310
|
+
def OnAcceptability(self, e):
|
311
|
+
""" Run the acceptability """
|
312
|
+
|
313
|
+
if self._manager is None:
|
314
|
+
return
|
315
|
+
|
316
|
+
Acceptability(self._manager.main_dir,
|
317
|
+
scenario=self._manager.scenario,
|
318
|
+
Study_area=self._manager.Study_area)
|