wolfhece 2.1.27__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 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 : {: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),
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
 
@@ -44,7 +44,8 @@ def parallel_gpd_clip(layer:list[str],
44
44
  def parallel_v2r(manager:Accept_Manager,
45
45
  attribute:str,
46
46
  pixel:float,
47
- number_procs:int = 1):
47
+ number_procs:int = 1,
48
+ convert_to_sparse:bool = False):
48
49
  """
49
50
  Convert the vector layers to raster.
50
51
 
@@ -63,14 +64,17 @@ def parallel_v2r(manager:Accept_Manager,
63
64
  layers = manager.get_layers_in_codevulne()
64
65
 
65
66
  if number_procs == 1:
67
+ result_list=[]
66
68
  for curlayer in layers:
67
- vector_to_raster(curlayer, manager, attribute, pixel)
69
+ result_list.append(vector_to_raster(curlayer, manager, attribute, pixel,convert_to_sparse))
70
+
68
71
  else:
69
72
  pool = multiprocessing.Pool(processes=number_procs)
70
73
  prod_x=partial(vector_to_raster,
71
74
  manager=manager,
72
75
  attribute=attribute,
73
- pixel_size=pixel)
76
+ pixel_size=pixel,
77
+ convert_to_sparse=convert_to_sparse)
74
78
 
75
79
  result_list = pool.map(prod_x, layers)
76
80
 
@@ -1,5 +1,7 @@
1
1
  from .Parallels import parallel_gpd_clip, parallel_v2r, parallel_datamod
2
- from .func import data_modification, compute_vulnerability, compute_vulnerability4scenario, match_vulnerability2sim, compute_acceptability, shp_to_raster, Accept_Manager, cleaning_directory, EXTENT, Vulnerability_csv
2
+ from .func import data_modification, compute_vulnerability, compute_vulnerability4scenario
3
+ from .func import match_vulnerability2sim, compute_acceptability, shp_to_raster, clip_layer
4
+ from .func import Accept_Manager, cleaning_directory, EXTENT, Vulnerability_csv, compute_code
3
5
 
4
6
  import pandas as pd
5
7
  import os
@@ -31,6 +33,8 @@ class steps_vulnerability(Enum):
31
33
  Enum for the steps in the vulnerability computation
32
34
  """
33
35
  CREATE_RASTERS = 1
36
+ CREATE_RASTERS_VULN = 10
37
+ CREATE_RASTERS_CODE = 11
34
38
  APPLY_MODIFS = 2
35
39
  MATCH_SIMUL = 3
36
40
 
@@ -42,7 +46,8 @@ def Base_data_creation(main_dir:str = 'Data',
42
46
  CE_IGN_top10v:str = 'CE_IGN_TOP10V/CE_IGN_TOP10V.shp',
43
47
  resolution:float = 1.,
44
48
  number_procs:int = 8,
45
- steps:list[int] | list[steps_base_data_creation] = [1,2,3,4,5,6,7]):
49
+ steps:list[int] | list[steps_base_data_creation] = [1,2,3,4,5,6,7],
50
+ Vuln_csv:str = 'Vulnerability.csv'):
46
51
  """
47
52
  Create the databse.
48
53
 
@@ -73,7 +78,8 @@ def Base_data_creation(main_dir:str = 'Data',
73
78
  Original_gdb=Original_gdb,
74
79
  CaPa_Walloon=CaPa_Walloon,
75
80
  PICC_Walloon=PICC_Walloon,
76
- CE_IGN_top10v=CE_IGN_top10v)
81
+ CE_IGN_top10v=CE_IGN_top10v,
82
+ Vuln_csv=Vuln_csv)
77
83
 
78
84
  if not manager.check_before_database_creation():
79
85
  logging.error("The necessary files are missing - Verify logs for more information")
@@ -140,7 +146,9 @@ def Base_data_creation(main_dir:str = 'Data',
140
146
  if 5 in steps or steps_base_data_creation.RASTERIZE_IGN in steps:
141
147
  # ********************************************************************************************************************
142
148
  # Step 5 : Rasaterize the IGN data "Course d'eau" to get the riverbed mask
143
- shp_to_raster(manager.CE_IGN_TOP10V, manager.SA_MASKED_RIVER, resolution)
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)
144
152
 
145
153
  done.append(steps_base_data_creation.RASTERIZE_IGN)
146
154
 
@@ -194,7 +202,11 @@ def Base_data_creation(main_dir:str = 'Data',
194
202
  cleaning_directory(manager.TMP_RASTERS_CODE)
195
203
  cleaning_directory(manager.TMP_RASTERS_VULNE)
196
204
 
197
- Database_to_raster(main_dir, Study_area, resolution, number_procs=number_procs)
205
+ Database_to_raster(main_dir,
206
+ Study_area,
207
+ resolution,
208
+ number_procs=number_procs,
209
+ Vuln_csv=Vuln_csv)
198
210
 
199
211
  done.append(steps_base_data_creation.DATABASE_TO_RASTER)
200
212
 
@@ -205,7 +217,8 @@ def Base_data_creation(main_dir:str = 'Data',
205
217
  def Database_to_raster(main_dir:str = 'Data',
206
218
  Study_area:str = 'Bassin_Vesdre.shp',
207
219
  resolution:float = 1.,
208
- number_procs:int = 16):
220
+ number_procs:int = 16,
221
+ Vuln_csv:str = 'Vulnerability.csv'):
209
222
  """
210
223
  Convert the vector database to raster database based on their vulnerability values
211
224
 
@@ -224,7 +237,7 @@ def Database_to_raster(main_dir:str = 'Data',
224
237
  The parallel processing is safe as each layer is processed independently.
225
238
  """
226
239
 
227
- manager = Accept_Manager(main_dir, Study_area)
240
+ manager = Accept_Manager(main_dir, Study_area, Vuln_csv=Vuln_csv)
228
241
 
229
242
  resolution = float(resolution)
230
243
 
@@ -238,7 +251,7 @@ def Database_to_raster(main_dir:str = 'Data',
238
251
 
239
252
  attributes = ["Vulne", "Code"]
240
253
  for cur_attrib in attributes:
241
- parallel_v2r(manager, cur_attrib, resolution, number_procs)
254
+ parallel_v2r(manager, cur_attrib, resolution, number_procs, convert_to_sparse=True)
242
255
 
243
256
  manager.restore_dir()
244
257
 
@@ -246,7 +259,9 @@ def Vulnerability(main_dir:str = 'Data',
246
259
  scenario:str = 'Scenario1',
247
260
  Study_area:str = 'Bassin_Vesdre.shp',
248
261
  resolution:float = 1.,
249
- steps:list[int] | list[steps_vulnerability] = [1,2,3]):
262
+ steps:list[int] | list[steps_vulnerability] = [1,10,11,2,3],
263
+ Vuln_csv:str = 'Vulnerability.csv',
264
+ Intermediate_csv:str = 'Intermediate.csv'):
250
265
  """
251
266
  Compute the vulnerability for the study area and the scenario, if needed.
252
267
 
@@ -273,7 +288,11 @@ def Vulnerability(main_dir:str = 'Data',
273
288
 
274
289
  """
275
290
 
276
- manager = Accept_Manager(main_dir, Study_area, scenario=scenario)
291
+ manager = Accept_Manager(main_dir,
292
+ Study_area,
293
+ scenario=scenario,
294
+ Vuln_csv=Vuln_csv,
295
+ Intermediate_csv=Intermediate_csv)
277
296
 
278
297
  if not manager.check_before_vulnerability():
279
298
  logging.error("The necessary files are missing - Verify logs for more information")
@@ -292,7 +311,13 @@ def Vulnerability(main_dir:str = 'Data',
292
311
 
293
312
  cleaning_directory(manager.TMP_SCEN_DIR)
294
313
 
295
- compute_vulnerability(manager)
314
+ if 10 in steps or steps_vulnerability.CREATE_RASTERS_VULN in steps:
315
+ compute_vulnerability(manager)
316
+ done.append(steps_vulnerability.CREATE_RASTERS_VULN)
317
+
318
+ if 11 in steps or steps_vulnerability.CREATE_RASTERS_CODE in steps:
319
+ compute_code(manager)
320
+ done.append(steps_vulnerability.CREATE_RASTERS_CODE)
296
321
 
297
322
  done.append(steps_vulnerability.CREATE_RASTERS)
298
323
 
@@ -343,17 +368,20 @@ def Vulnerability(main_dir:str = 'Data',
343
368
 
344
369
  def Acceptability(main_dir:str = 'Vesdre',
345
370
  scenario:str = 'Scenario1',
346
- Study_area:str = 'Bassin_Vesdre.shp'):
371
+ Study_area:str = 'Bassin_Vesdre.shp',
372
+ coeff_auto:bool = True,
373
+ Ponderation_csv:str = 'Ponderation.csv'):
347
374
  """ Compute acceptability for the scenario """
348
375
 
349
- manager = Accept_Manager(main_dir, Study_area, scenario=scenario)
376
+ manager = Accept_Manager(main_dir,
377
+ Study_area,
378
+ scenario=scenario,
379
+ Ponderation_csv=Ponderation_csv)
350
380
 
351
381
  manager.change_dir()
352
382
 
353
383
  # Load the vulnerability raster **for the scenario**
354
384
  vulne = gdal.Open(str(manager.OUT_VULN))
355
- # Convert to numpy array
356
- vulne = vulne.GetRasterBand(1).ReadAsArray()
357
385
 
358
386
  # Load the river mask
359
387
  riv = gdal.Open(str(manager.OUT_MASKED_RIVER))
@@ -362,7 +390,11 @@ def Acceptability(main_dir:str = 'Vesdre',
362
390
  geotrans = riv.GetGeoTransform()
363
391
  proj = riv.GetProjection()
364
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
+
365
396
  # Convert to numpy array
397
+ vulne = vulne.GetRasterBand(1).ReadAsArray()
366
398
  riv = riv.GetRasterBand(1).ReadAsArray()
367
399
 
368
400
  # Get the return periods available
@@ -446,10 +478,19 @@ def Acceptability(main_dir:str = 'Vesdre',
446
478
  # pond.set_index("Interval", inplace=True)
447
479
 
448
480
  # Get ponderations for the return periods
449
- pond = manager.get_ponderations()
481
+ if coeff_auto:
482
+ pond = manager.get_ponderations()
483
+ assert pond["Ponderation"].sum() > 0.999999 and pond["Ponderation"].sum()<1.0000001, "The sum of the ponderations is not equal to 1"
484
+
485
+ elif manager.is_valid_ponderation_csv:
486
+ pond = pd.read_csv(manager.PONDERATION_CSV)
487
+ pond.set_index("Interval", inplace=True)
488
+ else:
489
+ logging.error("The ponderation file is missing")
490
+ logging.info("Please provide the ponderation file or set 'coeff_auto' to True")
491
+ return
450
492
 
451
493
  assert len(pond) == len(return_periods), "The number of ponderations is not equal to the number of return periods"
452
- assert pond["Ponderation"].sum() > 0.999999 and pond["Ponderation"].sum()<1.0000001, "The sum of the ponderations is not equal to 1"
453
494
 
454
495
  # Initialize the combined acceptability matrix -- Ponderate mean of the local acceptability
455
496
  comb = np.zeros(q_dict["vm{}".format(return_periods[-1])].shape)