wolfhece 2.1.25__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 CHANGED
@@ -24,6 +24,7 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
24
24
  nb:int
25
25
  colors:np.array
26
26
  colorsflt:np.array
27
+ colorsuint8:np.array
27
28
 
28
29
  def __init__(self, parent=None, title=_('Colormap'),w=100,h=500,nseg=1024):
29
30
 
@@ -45,17 +46,32 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
45
46
  LinearSegmentedColormap.__init__(self,'wolf',{},nseg)
46
47
  self.set_bounds()
47
48
 
49
+ @property
50
+ def colormin_uint8(self):
51
+ return self.colormin.astype(np.uint8)*255
52
+
53
+ @property
54
+ def colormax_uint8(self):
55
+ return self.colormax.astype(np.uint8)*255
56
+
48
57
  def get_colors_f32(self):
49
58
 
50
59
  colors = self.colorsflt[:,:3].astype(np.float32)
51
60
 
52
61
  return colors
62
+
63
+ def get_colors_uint8(self):
64
+
65
+ colors = self.colorsflt[:,:3].astype(np.uint8) * 255
66
+
67
+ return colors
53
68
 
54
69
  def set_bounds(self):
55
70
  self.set_under(tuple(self.colormin))
56
71
  self.set_over(tuple(self.colormax))
57
72
 
58
- def get_rgba(self,x):
73
+ def get_rgba(self, x:np.ndarray):
74
+ """Récupération de la couleur en fonction de la valeur x"""
59
75
 
60
76
  dval=self.values[-1]-self.values[0]
61
77
  if dval==0.:
@@ -63,23 +79,24 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
63
79
  xloc = (x-self.values[0])/dval
64
80
 
65
81
  if self.interval_cst:
66
- rgba = np.ones((xloc.shape[0],xloc.shape[1],4))
82
+ rgba = np.ones((xloc.shape[0],xloc.shape[1],4), dtype=np.uint8)
67
83
 
68
84
  ij = np.where(xloc<0.)
69
- rgba[ij[0],ij[1]] = self.colormin
85
+ rgba[ij[0],ij[1]] = self.colormin_uint8
70
86
  ij = np.where(xloc>=1.)
71
- rgba[ij[0],ij[1]] = self.colormax
87
+ rgba[ij[0],ij[1]] = self.colormax_uint8
72
88
 
73
89
  for i in range(self.nb-1):
74
90
  val1 = (self.values[i]-self.values[0])/dval
75
91
  val2 = (self.values[i+1]-self.values[0])/dval
76
- c1 = self.colorsflt[i]
92
+ # c1 = self.colorsflt[i]
93
+ c1 = self.colorsuint8[i]
77
94
  ij = np.where((xloc>=val1) & (xloc<val2))
78
95
  rgba[ij[0],ij[1]] = c1
79
96
 
80
97
  return rgba
81
98
  else:
82
- return self(xloc)
99
+ return self(xloc, bytes=True)
83
100
 
84
101
  def export_palette_matplotlib(self,name):
85
102
  cmaps = OrderedDict()
@@ -110,7 +127,7 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
110
127
 
111
128
  return self.nb,self.values,self._segmentdata,self.colorsflt
112
129
 
113
- def distribute_values(self, minval=-99999, maxval=-99999, step=0, wx_permitted=True):
130
+ def distribute_values(self, minval:float=-99999, maxval:float=-99999, step=0, wx_permitted=True):
114
131
  """ Distribution des valeurs de la palette
115
132
 
116
133
  :param minval: valeur minimale
@@ -460,8 +477,7 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
460
477
  self.colors[curcol,1] = colors[curcol,1]
461
478
  self.colors[curcol,2] = colors[curcol,2]
462
479
  self.colors[curcol,3] = colors[curcol,3]
463
-
464
-
480
+
465
481
  self.fill_segmentdata()
466
482
 
467
483
  def defaultgray(self):
@@ -469,7 +485,6 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
469
485
  self.nb=2
470
486
  self.values = np.asarray([0.,1.])
471
487
  self.colors = np.asarray([[0,0,0,255],[255,255,255,255]],dtype=np.int32)
472
- self.colorsflt = np.asarray([[0.,0.,0.,1.],[1.,1.,1.,1.]],dtype=np.float64)
473
488
 
474
489
  self.fill_segmentdata()
475
490
 
@@ -477,6 +492,7 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
477
492
  """Mise à jour de la palatte de couleurs"""
478
493
 
479
494
  self.colorsflt = self.colors.astype(float)/255.
495
+ self.colorsuint8 = self.colors.astype(np.uint8)
480
496
 
481
497
  dval=self.values[-1]-self.values[0]
482
498
 
@@ -1,4 +1,5 @@
1
- from .func import gpd_clip, data_modification, vector_to_raster, Comp_Vulnerability, match_vuln_modrec, VulMod, shp_to_raster
1
+ from .func import clip_layer, data_modification, vector_to_raster, compute_vulnerability, match_vulnerability2sim, compute_acceptability, shp_to_raster, Accept_Manager
2
+ import geopandas as gpd
2
3
  import multiprocessing
3
4
  from functools import partial
4
5
  import os
@@ -7,7 +8,7 @@ from pathlib import Path
7
8
  def parallel_gpd_clip(layer:list[str],
8
9
  file_path:str,
9
10
  Study_Area:str,
10
- output_gpkg:str,
11
+ output_dir:str,
11
12
  number_procs:int = 1):
12
13
  """
13
14
  Clip the layers to the study area.
@@ -19,31 +20,28 @@ def parallel_gpd_clip(layer:list[str],
19
20
  :param layer: List of layers to clip
20
21
  :param file_path: The path to the file
21
22
  :param Study_Area: The study area
22
- :param output_gpkg: The output geopackage
23
+ :param output_dir: The output directory where the clipped layers are stored
23
24
  :param number_procs: The number of processors to use
24
25
 
25
26
  """
26
27
  file_path = str(file_path)
27
28
  Study_Area = str(Study_Area)
28
- output_gpkg = str(output_gpkg)
29
+ output_dir = str(output_dir)
29
30
 
30
31
  if number_procs == 1:
31
32
 
32
33
  for curlayer in layer:
33
- gpd_clip(curlayer, file_path, Study_Area, output_gpkg)
34
+ clip_layer(curlayer, file_path, Study_Area, output_dir)
34
35
 
35
36
  else:
36
37
  pool = multiprocessing.Pool(processes=number_procs)
37
- prod_x=partial(gpd_clip,
38
+ prod_x=partial(clip_layer,
38
39
  file_path=file_path,
39
40
  Study_Area=Study_Area,
40
- geopackage=output_gpkg)
41
+ output_dir=output_dir)
41
42
  result_list = pool.map(prod_x, layer)
42
- print(result_list)
43
43
 
44
- def parallel_v2r(layers:list[str],
45
- study_area_database:Path,
46
- extent:Path,
44
+ def parallel_v2r(manager:Accept_Manager,
47
45
  attribute:str,
48
46
  pixel:float,
49
47
  number_procs:int = 1):
@@ -54,9 +52,7 @@ def parallel_v2r(layers:list[str],
54
52
 
55
53
  :remark: It is permitted to execute this function in multiprocessing because we write separate files.
56
54
 
57
- :param layers: List of layers to convert to raster.
58
- :param study_area_database: The Path to the study area
59
- :param extent: The extent of the study area
55
+ :param manager: The Accept_Manager object
60
56
  :param attribute: The attribute to convert to raster
61
57
  :param pixel: The pixel size of the raster
62
58
  :param number_procs: The number of processors to use
@@ -64,18 +60,47 @@ def parallel_v2r(layers:list[str],
64
60
  """
65
61
 
66
62
  attribute = str(attribute)
63
+ layers = manager.get_layers_in_codevulne()
67
64
 
68
65
  if number_procs == 1:
69
66
  for curlayer in layers:
70
- vector_to_raster(curlayer, study_area_database, extent, attribute, pixel)
67
+ vector_to_raster(curlayer, manager, attribute, pixel)
71
68
  else:
72
69
  pool = multiprocessing.Pool(processes=number_procs)
73
70
  prod_x=partial(vector_to_raster,
74
- vector_input=study_area_database,
75
- extent=extent,
71
+ manager=manager,
76
72
  attribute=attribute,
77
- pixel_size=pixel) # prod_x has only one argument x (y is fixed to 10)
73
+ pixel_size=pixel)
74
+
75
+ result_list = pool.map(prod_x, layers)
76
+
77
+ def parallel_datamod(manager:Accept_Manager,
78
+ picc:gpd.GeoDataFrame,
79
+ capa:gpd.GeoDataFrame,
80
+ number_procs:int = 1):
81
+ """
82
+ Apply the data modification to the layers.
83
+
84
+ Process the layers in parallel.
85
+
86
+ :remark: It is permitted to execute this function in multiprocessing because we write separate files.
87
+
88
+ :param manager: The Accept_Manager object
89
+ :param number_procs: The number of processors to use
90
+
91
+ """
92
+
93
+ layers = manager.get_layers_in_clipgdb()
94
+
95
+ if number_procs == 1:
96
+ for curlayer in layers:
97
+ data_modification(curlayer, manager, picc, capa)
98
+ else:
99
+ pool = multiprocessing.Pool(processes=number_procs)
100
+ prod_x=partial(data_modification,
101
+ manager=manager,
102
+ picc=picc,
103
+ capa=capa)
78
104
 
79
105
  result_list = pool.map(prod_x, layers)
80
- print(result_list)
81
106