wolfhece 2.1.28__py3-none-any.whl → 2.1.29__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 +3 -3
- wolfhece/PyPalette.py +8 -0
- wolfhece/acceptability/acceptability.py +15 -11
- wolfhece/acceptability/func.py +104 -20
- wolfhece/apps/splashscreen.py +15 -1
- wolfhece/apps/version.py +1 -1
- wolfhece/libs/WolfOGL.c +2677 -1859
- wolfhece/libs/WolfOGL.pyx +17 -0
- wolfhece/libs/verify_license.cp310-win_amd64.pyd +0 -0
- wolfhece/libs/wolfogl.cp310-win_amd64.pyd +0 -0
- wolfhece/models/vulnerability.pal +25 -0
- wolfhece/wolf_array.py +1 -0
- {wolfhece-2.1.28.dist-info → wolfhece-2.1.29.dist-info}/METADATA +2 -1
- {wolfhece-2.1.28.dist-info → wolfhece-2.1.29.dist-info}/RECORD +17 -15
- {wolfhece-2.1.28.dist-info → wolfhece-2.1.29.dist-info}/WHEEL +1 -1
- {wolfhece-2.1.28.dist-info → wolfhece-2.1.29.dist-info}/entry_points.txt +0 -0
- {wolfhece-2.1.28.dist-info → wolfhece-2.1.29.dist-info}/top_level.txt +0 -0
wolfhece/PyDraw.py
CHANGED
@@ -7489,9 +7489,9 @@ class WolfMapViewer(wx.Frame):
|
|
7489
7489
|
self._set_active_bc()
|
7490
7490
|
|
7491
7491
|
#Print info in the status bar
|
7492
|
-
txt = 'Dx : {
|
7493
|
-
txt += ' ; Xmin : {
|
7494
|
-
txt += ' ; Xmax : {
|
7492
|
+
txt = 'Dx : {:.4f} ; Dy : {:.4f}'.format(self.active_array.dx, self.active_array.dy)
|
7493
|
+
txt += ' ; Xmin : {:.4f} ; Ymin : {:.4f}'.format(self.active_array.origx, self.active_array.origy)
|
7494
|
+
txt += ' ; Xmax : {:.4f} ; Ymax : {:.4f}'.format(self.active_array.origx + self.active_array.dx * float(self.active_array.nbx),
|
7495
7495
|
self.active_array.origy + self.active_array.dy * float(self.active_array.nby))
|
7496
7496
|
txt += ' ; Nx : {:d} ; Ny : {:d}'.format(self.active_array.nbx, self.active_array.nby)
|
7497
7497
|
|
wolfhece/PyPalette.py
CHANGED
@@ -333,6 +333,14 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
|
|
333
333
|
self.nb = i
|
334
334
|
self.values=self.values[0:i]
|
335
335
|
self.colors=self.colors[0:i,:]
|
336
|
+
else:
|
337
|
+
self.nb = i
|
338
|
+
oldvalues = self.values
|
339
|
+
oldcolors = self.colors
|
340
|
+
self.values = np.zeros(self.nb , dtype=float)
|
341
|
+
self.colors = np.zeros((self.nb,4) , dtype=int)
|
342
|
+
self.values[0:len(oldvalues)] = oldvalues
|
343
|
+
self.colors[0:len(oldcolors),:] = oldcolors
|
336
344
|
|
337
345
|
update = False
|
338
346
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
from .Parallels import parallel_gpd_clip, parallel_v2r, parallel_datamod
|
2
2
|
from .func import data_modification, compute_vulnerability, compute_vulnerability4scenario
|
3
|
-
from .func import match_vulnerability2sim, compute_acceptability, shp_to_raster
|
3
|
+
from .func import match_vulnerability2sim, compute_acceptability, shp_to_raster, clip_layer
|
4
4
|
from .func import Accept_Manager, cleaning_directory, EXTENT, Vulnerability_csv, compute_code
|
5
5
|
|
6
6
|
import pandas as pd
|
@@ -47,7 +47,7 @@ def Base_data_creation(main_dir:str = 'Data',
|
|
47
47
|
resolution:float = 1.,
|
48
48
|
number_procs:int = 8,
|
49
49
|
steps:list[int] | list[steps_base_data_creation] = [1,2,3,4,5,6,7],
|
50
|
-
|
50
|
+
Vuln_csv:str = 'Vulnerability.csv'):
|
51
51
|
"""
|
52
52
|
Create the databse.
|
53
53
|
|
@@ -79,7 +79,7 @@ def Base_data_creation(main_dir:str = 'Data',
|
|
79
79
|
CaPa_Walloon=CaPa_Walloon,
|
80
80
|
PICC_Walloon=PICC_Walloon,
|
81
81
|
CE_IGN_top10v=CE_IGN_top10v,
|
82
|
-
|
82
|
+
Vuln_csv=Vuln_csv)
|
83
83
|
|
84
84
|
if not manager.check_before_database_creation():
|
85
85
|
logging.error("The necessary files are missing - Verify logs for more information")
|
@@ -146,7 +146,9 @@ def Base_data_creation(main_dir:str = 'Data',
|
|
146
146
|
if 5 in steps or steps_base_data_creation.RASTERIZE_IGN in steps:
|
147
147
|
# ********************************************************************************************************************
|
148
148
|
# Step 5 : Rasaterize the IGN data "Course d'eau" to get the riverbed mask
|
149
|
-
|
149
|
+
LAYER_IGN = "CE_IGN_TOP10V"
|
150
|
+
clip_layer(layer=LAYER_IGN, file_path=manager.CE_IGN_TOP10V, Study_Area=manager.SA, output_dir=manager.TMP_IGNCE)
|
151
|
+
shp_to_raster(manager.TMP_IGNCE / (LAYER_IGN + '.gpkg'), manager.SA_MASKED_RIVER, resolution, manager=manager)
|
150
152
|
|
151
153
|
done.append(steps_base_data_creation.RASTERIZE_IGN)
|
152
154
|
|
@@ -204,7 +206,7 @@ def Base_data_creation(main_dir:str = 'Data',
|
|
204
206
|
Study_area,
|
205
207
|
resolution,
|
206
208
|
number_procs=number_procs,
|
207
|
-
|
209
|
+
Vuln_csv=Vuln_csv)
|
208
210
|
|
209
211
|
done.append(steps_base_data_creation.DATABASE_TO_RASTER)
|
210
212
|
|
@@ -216,7 +218,7 @@ def Database_to_raster(main_dir:str = 'Data',
|
|
216
218
|
Study_area:str = 'Bassin_Vesdre.shp',
|
217
219
|
resolution:float = 1.,
|
218
220
|
number_procs:int = 16,
|
219
|
-
|
221
|
+
Vuln_csv:str = 'Vulnerability.csv'):
|
220
222
|
"""
|
221
223
|
Convert the vector database to raster database based on their vulnerability values
|
222
224
|
|
@@ -235,7 +237,7 @@ def Database_to_raster(main_dir:str = 'Data',
|
|
235
237
|
The parallel processing is safe as each layer is processed independently.
|
236
238
|
"""
|
237
239
|
|
238
|
-
manager = Accept_Manager(main_dir, Study_area,
|
240
|
+
manager = Accept_Manager(main_dir, Study_area, Vuln_csv=Vuln_csv)
|
239
241
|
|
240
242
|
resolution = float(resolution)
|
241
243
|
|
@@ -258,7 +260,7 @@ def Vulnerability(main_dir:str = 'Data',
|
|
258
260
|
Study_area:str = 'Bassin_Vesdre.shp',
|
259
261
|
resolution:float = 1.,
|
260
262
|
steps:list[int] | list[steps_vulnerability] = [1,10,11,2,3],
|
261
|
-
|
263
|
+
Vuln_csv:str = 'Vulnerability.csv',
|
262
264
|
Intermediate_csv:str = 'Intermediate.csv'):
|
263
265
|
"""
|
264
266
|
Compute the vulnerability for the study area and the scenario, if needed.
|
@@ -289,7 +291,7 @@ def Vulnerability(main_dir:str = 'Data',
|
|
289
291
|
manager = Accept_Manager(main_dir,
|
290
292
|
Study_area,
|
291
293
|
scenario=scenario,
|
292
|
-
|
294
|
+
Vuln_csv=Vuln_csv,
|
293
295
|
Intermediate_csv=Intermediate_csv)
|
294
296
|
|
295
297
|
if not manager.check_before_vulnerability():
|
@@ -380,8 +382,6 @@ def Acceptability(main_dir:str = 'Vesdre',
|
|
380
382
|
|
381
383
|
# Load the vulnerability raster **for the scenario**
|
382
384
|
vulne = gdal.Open(str(manager.OUT_VULN))
|
383
|
-
# Convert to numpy array
|
384
|
-
vulne = vulne.GetRasterBand(1).ReadAsArray()
|
385
385
|
|
386
386
|
# Load the river mask
|
387
387
|
riv = gdal.Open(str(manager.OUT_MASKED_RIVER))
|
@@ -390,7 +390,11 @@ def Acceptability(main_dir:str = 'Vesdre',
|
|
390
390
|
geotrans = riv.GetGeoTransform()
|
391
391
|
proj = riv.GetProjection()
|
392
392
|
|
393
|
+
assert vulne.GetGeoTransform() == riv.GetGeoTransform(), "The geotransform of the two rasters is different"
|
394
|
+
assert vulne.GetProjection() == riv.GetProjection(), "The projection of the two rasters is different"
|
395
|
+
|
393
396
|
# Convert to numpy array
|
397
|
+
vulne = vulne.GetRasterBand(1).ReadAsArray()
|
394
398
|
riv = riv.GetRasterBand(1).ReadAsArray()
|
395
399
|
|
396
400
|
# Get the return periods available
|
wolfhece/acceptability/func.py
CHANGED
@@ -135,7 +135,7 @@ class Accept_Manager():
|
|
135
135
|
CE_IGN_top10v:str = 'CE_IGN_TOP10V/CE_IGN_TOP10V.shp',
|
136
136
|
EPU_Stations:str = 'AJOUT_PDET_EPU_DG03_STATIONS.shp',
|
137
137
|
Ponderation_csv:str = 'Ponderation.csv',
|
138
|
-
|
138
|
+
Vuln_csv:str = 'Vulnerability.csv',
|
139
139
|
Intermediate_csv:str = 'Intermediate.csv'
|
140
140
|
) -> None:
|
141
141
|
|
@@ -171,7 +171,7 @@ class Accept_Manager():
|
|
171
171
|
self.CE_IGN_TOP10V = self.IN_DATABASE / self._ce_ign_top10v
|
172
172
|
self.EPU_STATIONS = self.IN_EPU_STATIONS / EPU_Stations
|
173
173
|
|
174
|
-
self.VULNERABILITY_CSV = self.IN_CSV /
|
174
|
+
self.VULNERABILITY_CSV = self.IN_CSV / Vuln_csv
|
175
175
|
self.POINTS_CSV = self.IN_CSV / Intermediate_csv
|
176
176
|
self.PONDERATION_CSV = self.IN_CSV / Ponderation_csv
|
177
177
|
|
@@ -854,6 +854,53 @@ class Accept_Manager():
|
|
854
854
|
else:
|
855
855
|
return Modif_Type.COPY
|
856
856
|
|
857
|
+
def check_origin_shape(self) -> list[str]:
|
858
|
+
|
859
|
+
code = self.get_files_in_rasters_code()
|
860
|
+
vuln = self.get_files_in_rasters_vulne()
|
861
|
+
|
862
|
+
if len(code) == 0:
|
863
|
+
logging.error("The code rasters do not exist")
|
864
|
+
return False
|
865
|
+
|
866
|
+
if len(vuln) == 0:
|
867
|
+
logging.error("The vulnerability rasters do not exist")
|
868
|
+
return False
|
869
|
+
|
870
|
+
if len(code) != len(vuln):
|
871
|
+
logging.error("The number of code and vulnerability rasters do not match")
|
872
|
+
return False
|
873
|
+
|
874
|
+
# we take a reference raster
|
875
|
+
ref = gdal.Open(str(code[0]))
|
876
|
+
band_ref = ref.GetRasterBand(1)
|
877
|
+
proj_ref = ref.GetProjection()
|
878
|
+
geo_ref = ref.GetGeoTransform()
|
879
|
+
col_ref, row_ref = band_ref.XSize, band_ref.YSize
|
880
|
+
|
881
|
+
# we compare the reference raster with the others
|
882
|
+
diff = []
|
883
|
+
for cur in code + vuln + [self.SA_MASKED_RIVER]:
|
884
|
+
cur_ = gdal.Open(str(cur))
|
885
|
+
band_cur = cur_.GetRasterBand(1)
|
886
|
+
proj_cur = cur_.GetProjection()
|
887
|
+
geo_cur = cur_.GetGeoTransform()
|
888
|
+
col_cur, row_cur = band_cur.XSize, band_cur.YSize
|
889
|
+
|
890
|
+
if geo_ref != geo_cur:
|
891
|
+
logging.error("The geotransforms do not match {}".format(cur))
|
892
|
+
diff.append(cur)
|
893
|
+
|
894
|
+
if proj_ref != proj_cur:
|
895
|
+
logging.error("The projections do not match {}".format(cur))
|
896
|
+
diff.append(cur)
|
897
|
+
|
898
|
+
if col_ref != col_cur or row_ref != row_cur:
|
899
|
+
logging.error("The dimensions do not match {}".format(cur))
|
900
|
+
diff.append(cur)
|
901
|
+
|
902
|
+
return diff
|
903
|
+
|
857
904
|
|
858
905
|
def clip_layer(layer:str,
|
859
906
|
file_path:str,
|
@@ -1103,7 +1150,6 @@ def compute_vulnerability(manager:Accept_Manager):
|
|
1103
1150
|
# Create a JIT function to update the arrays
|
1104
1151
|
# Faster than the classical Python loop or Numpy
|
1105
1152
|
@nb.jit(nopython=True, boundscheck=False, inline='always')
|
1106
|
-
# @cuda.jit(device=True, inline=True)
|
1107
1153
|
def update_arrays_jit(tmp_vuln, array_vuln):
|
1108
1154
|
for i in range(tmp_vuln.shape[0]):
|
1109
1155
|
for j in range(tmp_vuln.shape[1]):
|
@@ -1113,11 +1159,14 @@ def compute_vulnerability(manager:Accept_Manager):
|
|
1113
1159
|
return array_vuln
|
1114
1160
|
|
1115
1161
|
@nb.jit(nopython=True, boundscheck=False, inline='always')
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1162
|
+
def update_arrays_jit_csr(row, col, locvuln, array_vuln):
|
1163
|
+
for k in range(len(row)-1):
|
1164
|
+
i = k
|
1165
|
+
j1 = row[k]
|
1166
|
+
j2 = row[k+1]
|
1167
|
+
for j in col[j1:j2]:
|
1168
|
+
if locvuln >= array_vuln[i, j]:
|
1169
|
+
array_vuln[i, j] = locvuln
|
1121
1170
|
|
1122
1171
|
return array_vuln
|
1123
1172
|
|
@@ -1135,7 +1184,7 @@ def compute_vulnerability(manager:Accept_Manager):
|
|
1135
1184
|
ii = ij_npz['row']
|
1136
1185
|
jj = ij_npz['col']
|
1137
1186
|
# We use the jit
|
1138
|
-
|
1187
|
+
update_arrays_jit_csr(ii, jj, locvuln, array_vuln)
|
1139
1188
|
|
1140
1189
|
else:
|
1141
1190
|
ds = gdal.OpenEx(str(rasters_vuln[i]), open_options=["SPARSE_OK=TRUE"])
|
@@ -1194,7 +1243,6 @@ def compute_code(manager:Accept_Manager):
|
|
1194
1243
|
# Create a JIT function to update the arrays
|
1195
1244
|
# Faster than the classical Python loop or Numpy
|
1196
1245
|
@nb.jit(nopython=True, boundscheck=False, inline='always')
|
1197
|
-
# @cuda.jit(device=True, inline=True)
|
1198
1246
|
def update_arrays_jit(tmp_code, loccode, array_code):
|
1199
1247
|
for i in range(tmp_code.shape[0]):
|
1200
1248
|
for j in range(tmp_code.shape[1]):
|
@@ -1204,11 +1252,14 @@ def compute_code(manager:Accept_Manager):
|
|
1204
1252
|
return array_code
|
1205
1253
|
|
1206
1254
|
@nb.jit(nopython=True, boundscheck=False, inline='always')
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1255
|
+
def update_arrays_jit_csr(row, col, loccode, array_code):
|
1256
|
+
for k in range(len(row)-1):
|
1257
|
+
i = k
|
1258
|
+
j1 = row[k]
|
1259
|
+
j2 = row[k+1]
|
1260
|
+
for j in col[j1:j2]:
|
1261
|
+
if loccode >= array_code[i, j]:
|
1262
|
+
array_code[i, j] = loccode
|
1212
1263
|
|
1213
1264
|
return array_code
|
1214
1265
|
|
@@ -1222,7 +1273,7 @@ def compute_code(manager:Accept_Manager):
|
|
1222
1273
|
ii = ij_npz['row']
|
1223
1274
|
jj = ij_npz['col']
|
1224
1275
|
# We use the jit
|
1225
|
-
|
1276
|
+
update_arrays_jit_csr(ii, jj, loccode, array_code)
|
1226
1277
|
|
1227
1278
|
else:
|
1228
1279
|
ds = gdal.OpenEx(str(rasters_code[i]), open_options=["SPARSE_OK=TRUE"])
|
@@ -1396,7 +1447,7 @@ def compute_acceptability(manager:Accept_Manager,
|
|
1396
1447
|
dataset.FlushCache()
|
1397
1448
|
dataset = None
|
1398
1449
|
|
1399
|
-
def shp_to_raster(vector_fn:str, raster_fn:str, pixel_size:float = 1
|
1450
|
+
def shp_to_raster(vector_fn:str, raster_fn:str, pixel_size:float = 1., manager:Accept_Manager = None):
|
1400
1451
|
"""
|
1401
1452
|
Convert a vector layer to a raster tiff file.
|
1402
1453
|
|
@@ -1413,12 +1464,23 @@ def shp_to_raster(vector_fn:str, raster_fn:str, pixel_size:float = 1.):
|
|
1413
1464
|
# Force the input to be a string
|
1414
1465
|
vector_fn = str(vector_fn)
|
1415
1466
|
raster_fn = str(raster_fn)
|
1467
|
+
|
1468
|
+
if manager is None:
|
1469
|
+
extent_fn = vector_fn
|
1470
|
+
logging.warning("The extent file is not provided, the extent will be the same as the vector file")
|
1471
|
+
else:
|
1472
|
+
extent_fn = str(manager.SA)
|
1473
|
+
logging.info("The extent file is provided")
|
1416
1474
|
|
1417
1475
|
NoData_value = 0 # np.nan is not necessary a good idea
|
1476
|
+
|
1418
1477
|
# Open the data sources and read the extents
|
1419
|
-
source_ds = ogr.Open(vector_fn)
|
1478
|
+
source_ds:ogr.DataSource = ogr.Open(vector_fn)
|
1420
1479
|
source_layer = source_ds.GetLayer()
|
1421
|
-
|
1480
|
+
|
1481
|
+
extent_ds:ogr.DataSource = ogr.Open(extent_fn)
|
1482
|
+
extent_layer = extent_ds.GetLayer()
|
1483
|
+
x_min, x_max, y_min, y_max = extent_layer.GetExtent()
|
1422
1484
|
|
1423
1485
|
x_min = float(int(x_min))
|
1424
1486
|
x_max = float(np.ceil(x_max))
|
@@ -1459,6 +1521,8 @@ def vector_to_raster(layer:str,
|
|
1459
1521
|
"""
|
1460
1522
|
Convert a vector layer to a raster tiff file
|
1461
1523
|
|
1524
|
+
FIXME: Test de vulerability value and return immedialty if it is 1 if attribute == "Vulne"
|
1525
|
+
|
1462
1526
|
:param layer: the layer name in the GDB file
|
1463
1527
|
:param vector_input: the path to the vector file
|
1464
1528
|
:param extent: the path to the extent file
|
@@ -1524,11 +1588,31 @@ def vector_to_raster(layer:str,
|
|
1524
1588
|
"ALL_TOUCHED=TRUE"])
|
1525
1589
|
|
1526
1590
|
if convert_to_sparse:
|
1591
|
+
SPARSITY_THRESHOLD = 0.02
|
1527
1592
|
# Convert the raster to a npz containing the row and col of the non-null values
|
1528
1593
|
array = band.ReadAsArray()
|
1529
1594
|
ij = np.nonzero(array)
|
1530
|
-
|
1595
|
+
|
1596
|
+
if len(ij[0]) < int(x_res * y_res * SPARSITY_THRESHOLD):
|
1597
|
+
i,j = convert_to_csr(ij[0], ij[1], y_res)
|
1598
|
+
np.savez_compressed(Path(out_file).with_suffix('.npz'), row=np.asarray(i, dtype=np.int32), col=np.asarray(j, dtype=np.int32))
|
1599
|
+
else:
|
1600
|
+
logging.info("The raster is not sparse enough to be converted to a CSR forma {}".format(layer))
|
1531
1601
|
|
1532
1602
|
target_ds = None
|
1533
1603
|
|
1534
1604
|
return 0
|
1605
|
+
|
1606
|
+
@nb.jit(nopython=True, boundscheck=False, inline='always')
|
1607
|
+
def convert_to_csr(i_indices, j_indices, num_rows):
|
1608
|
+
row_ptr = [0] * (num_rows + 1)
|
1609
|
+
col_idx = []
|
1610
|
+
|
1611
|
+
for i in range(len(i_indices)):
|
1612
|
+
row_ptr[i_indices[i] + 1] += 1
|
1613
|
+
col_idx.append(j_indices[i])
|
1614
|
+
|
1615
|
+
for i in range(1, len(row_ptr)):
|
1616
|
+
row_ptr[i] += row_ptr[i - 1]
|
1617
|
+
|
1618
|
+
return row_ptr, col_idx
|
wolfhece/apps/splashscreen.py
CHANGED
@@ -7,6 +7,13 @@ import wx
|
|
7
7
|
import time
|
8
8
|
from wx.adv import SplashScreen as SplashScreen,SPLASH_CENTRE_ON_SCREEN,SPLASH_TIMEOUT,Sound
|
9
9
|
|
10
|
+
# try:
|
11
|
+
# from ..libs import wolfogl
|
12
|
+
# except:
|
13
|
+
# print("** WolfOGL not found **")
|
14
|
+
# print("Without WolfOGL, the application will not work !")
|
15
|
+
# print("Please reinstall 'wolfhece' package -- pip install wolfhece")
|
16
|
+
|
10
17
|
class WolfLauncher(SplashScreen):
|
11
18
|
"""
|
12
19
|
Wolf Splashcreen
|
@@ -15,10 +22,17 @@ class WolfLauncher(SplashScreen):
|
|
15
22
|
done = False
|
16
23
|
|
17
24
|
def __init__(self, parent=None, play_sound=True):
|
18
|
-
|
25
|
+
|
19
26
|
if self.done:
|
20
27
|
return
|
21
28
|
|
29
|
+
# try:
|
30
|
+
# wolfogl.init()
|
31
|
+
# except Exception as e:
|
32
|
+
# print("Error initializing WolfOGL -- We must stop here !")
|
33
|
+
# print("Please reinstall 'wolfhece' package -- pip install wolfhece")
|
34
|
+
# exit()
|
35
|
+
|
22
36
|
mydir=dirname(__file__)
|
23
37
|
mybitmap = wx.Bitmap(name=join(mydir,".\\WolfPython2.png"), type=wx.BITMAP_TYPE_PNG)
|
24
38
|
|