wolfhece 2.1.97__py3-none-any.whl → 2.1.99__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/PyParams.py CHANGED
@@ -344,14 +344,14 @@ class Wolf_Param(wx.Frame):
344
344
 
345
345
  return self.sizer is not None
346
346
 
347
- def ensure_prop(self, wxparent = None, show_in_active_if_default:bool = False):
347
+ def ensure_prop(self, wxparent = None, show_in_active_if_default:bool = False, height:int= 600):
348
348
  """ Ensure that the property grid is available """
349
349
 
350
350
  if self.wx_exists:
351
351
  if not self.has_prop:
352
352
  self._set_only_prop(wxparent)
353
353
  self.show_in_active_if_default = show_in_active_if_default
354
- self.prop.SetSizeHints(0,600)
354
+ self.prop.SetSizeHints(0,height)
355
355
 
356
356
  self.Populate()
357
357
 
@@ -1034,12 +1034,17 @@ class Wolf_Param(wx.Frame):
1034
1034
  page.Append(pg.IntProperty(label = param_name, name = locname, value = locvalue))
1035
1035
 
1036
1036
  elif param[key_Param.TYPE]==Type_Param.File:
1037
- page.Append(pg.FileProperty(label=param_name, name = locname, value = param[key_Param.VALUE]))
1037
+
1038
+ if param[key_Param.VALUE] is None:
1039
+ page.Append(pg.FileProperty(label=param_name, name = locname, value = ''))
1040
+ else:
1041
+ page.Append(pg.FileProperty(label=param_name, name = locname, value = param[key_Param.VALUE]))
1038
1042
 
1039
1043
  elif param[key_Param.TYPE]==Type_Param.Directory:
1040
- page.Append(pg.DirProperty(label = param_name, name = locname, value = locvalue))
1041
- # newobj.SetLabel(param_name)
1042
- # page.Append(newobj)
1044
+ if locvalue is None:
1045
+ page.Append(pg.DirProperty(label = param_name, name = locname, value = ''))
1046
+ else:
1047
+ page.Append(pg.DirProperty(label = param_name, name = locname, value = locvalue))
1043
1048
 
1044
1049
  elif param[key_Param.TYPE]==Type_Param.Color:
1045
1050
  page.Append(pg.ColourProperty(label = param_name, name = locname, value = locvalue))
@@ -1325,9 +1330,13 @@ class Wolf_Param(wx.Frame):
1325
1330
  # File management without wx
1326
1331
  # ---------------------------
1327
1332
 
1328
- def apply_changes_to_memory(self):
1333
+ def apply_changes_to_memory(self, verbosity:bool = True):
1329
1334
  """ Transfert des données en mémoire sans wx --> remplissage des dictionnaires """
1330
1335
 
1336
+ if self.prop is None:
1337
+ logging.debug("ERROR : wxPython is not running - Impossible to apply changes to memory")
1338
+ return
1339
+
1331
1340
  if self.prop.IsPageModified(0):
1332
1341
  #on boucle sur tous les paramètres pour les ajouter au dictionnaire si non présents
1333
1342
  for group in self.myparams_default.keys():
@@ -1339,7 +1348,8 @@ class Wolf_Param(wx.Frame):
1339
1348
  if not self._callback is None:
1340
1349
  self._callback()
1341
1350
  else:
1342
- wx.MessageDialog(self,'Nothing to do!')
1351
+ if verbosity:
1352
+ logging.warning(_('Nothing to do!'))
1343
1353
 
1344
1354
  def save_automatically_to_file(self):
1345
1355
  """
wolfhece/PyVertex.py CHANGED
@@ -40,11 +40,18 @@ from .wolf_texture import Text_Image_Texture
40
40
  def getRGBfromI(rgbint:int):
41
41
  """ Convert integer to RGB """
42
42
 
43
- blue = rgbint & 255
44
- green = (rgbint >> 8) & 255
45
- red = (rgbint >> 16) & 255
46
- return red, green, blue
47
-
43
+ if isinstance(rgbint, tuple):
44
+ return rgbint[0], rgbint[1], rgbint[2]
45
+ elif isinstance(rgbint, list):
46
+ return rgbint[0], rgbint[1], rgbint[2]
47
+ elif isinstance(rgbint, int):
48
+ blue = rgbint & 255
49
+ green = (rgbint >> 8) & 255
50
+ red = (rgbint >> 16) & 255
51
+ return red, green, blue
52
+ else:
53
+ logging.error('Error in getRGBfromI')
54
+ return 0, 0, 0
48
55
 
49
56
  def getIfromRGB(rgb:Union[list, tuple]):
50
57
  """ Convert RGB to integer """
@@ -15,10 +15,10 @@ import triangle.tri
15
15
  import wx
16
16
  import wx._dataview
17
17
  from wx.dataview import *
18
- from wx.core import BoxSizer, FlexGridSizer, TreeItemId
18
+ from wx.core import BoxSizer, TreeItemId
19
19
  from OpenGL.GL import *
20
20
  from shapely.geometry import LineString, MultiLineString,Point,MultiPoint,Polygon,JOIN_STYLE, MultiPolygon
21
- from shapely.ops import nearest_points,substring, split, polygonize
21
+ from shapely.ops import nearest_points
22
22
  from shapely import delaunay_triangles, prepare, is_prepared, destroy_prepared
23
23
  import pygltflib
24
24
  from scipy.interpolate import interp1d
@@ -37,13 +37,13 @@ from typing import Union, Literal
37
37
  from pathlib import Path
38
38
  import triangle
39
39
 
40
+
41
+
40
42
  from .wolf_texture import genericImagetexture
41
- from .textpillow import Font_Priority
42
43
  from .PyTranslate import _
43
44
  from .CpGrid import CpGrid
44
45
  from .PyVertex import wolfvertex,getIfromRGB,getRGBfromI, cloud_vertices
45
- from .PyParams import Wolf_Param, key_Param, Type_Param, new_json, new_infos_incr
46
- from .lazviewer.laz_viewer import myviewer
46
+ from .PyParams import Wolf_Param, Type_Param, new_json
47
47
  from .wolf_texture import Text_Image_Texture,Text_Infos
48
48
  from .drawing_obj import Element_To_Draw
49
49
 
@@ -927,6 +927,7 @@ if :\n \
927
927
  else:
928
928
  return 'Arial'
929
929
 
930
+
930
931
  class vector:
931
932
  """
932
933
  Objet de gestion d'informations vectorielles
@@ -1861,22 +1862,22 @@ class vector:
1861
1862
 
1862
1863
  self._reset_listogl()
1863
1864
 
1864
- def get_s2d(self):
1865
+ def get_s2d(self) -> np.ndarray:
1865
1866
  """
1866
1867
  calcul et retour des positions curvilignes 2D
1867
1868
  """
1868
- s2d=np.zeros[self.nbvertices]
1869
- for k in range(1,self.nbvertices+1):
1869
+ s2d=np.zeros(self.nbvertices)
1870
+ for k in range(1,self.nbvertices):
1870
1871
  s2d[k]=s2d[k-1]+self.myvertices[k-1].dist2D(self.myvertices[k])
1871
1872
 
1872
1873
  return s2d
1873
1874
 
1874
- def get_s3d(self):
1875
+ def get_s3d(self) -> np.ndarray:
1875
1876
  """
1876
1877
  calcul et retour des positions curvilignes 3D
1877
1878
  """
1878
- s3d=np.zeros[self.nbvertices]
1879
- for k in range(1,self.nbvertices+1):
1879
+ s3d=np.zeros(self.nbvertices)
1880
+ for k in range(1,self.nbvertices):
1880
1881
  s3d[k]=s3d[k-1]+self.myvertices[k-1].dist3D(self.myvertices[k])
1881
1882
 
1882
1883
  return s3d
@@ -2200,7 +2201,7 @@ class vector:
2200
2201
  myvec=vector(name=curlabel,parentzone=myzone)
2201
2202
  myzone.add_vector(myvec)
2202
2203
 
2203
- ds = min(curarray.dx,curarray.dy)
2204
+ ds = curarray.get_dxdy_min()
2204
2205
 
2205
2206
  pts = self._refine2D(ds)
2206
2207
 
@@ -2224,12 +2225,12 @@ class vector:
2224
2225
 
2225
2226
  if filter_null:
2226
2227
  for curpt in self.myvertices:
2227
- locval = curarray.get_value(curpt.x, curpt.y, nullvalue=-9999)
2228
+ locval = curarray.get_value(curpt.x, curpt.y, nullvalue=-99999)
2228
2229
  if locval !=-99999:
2229
2230
  myvec.add_vertex(wolfvertex(curpt.x, curpt.y, locval))
2230
2231
  else:
2231
2232
  for curpt in self.myvertices:
2232
- locval = curarray.get_value(curpt.x, curpt.y, nullvalue=-9999)
2233
+ locval = curarray.get_value(curpt.x, curpt.y, nullvalue=-99999)
2233
2234
  myvec.add_vertex(wolfvertex(curpt.x, curpt.y, locval))
2234
2235
 
2235
2236
  return myzone
@@ -2238,8 +2239,8 @@ class vector:
2238
2239
  """
2239
2240
  Graphique Matplolib de valeurs dans les matrices liées
2240
2241
  """
2241
- from .wolf_array import WolfArray
2242
- from .wolfresults_2D import Wolfresults_2D
2242
+ # from .wolf_array import WolfArray
2243
+ # from .wolfresults_2D import Wolfresults_2D
2243
2244
 
2244
2245
  colors=['red','blue','green']
2245
2246
 
@@ -2265,10 +2266,7 @@ class vector:
2265
2266
  for curlabel, curarray in linked_arrays.items():
2266
2267
  if curarray.plotted:
2267
2268
 
2268
- if isinstance(curarray, WolfArray):
2269
- ds = min(curarray.dx,curarray.dy)
2270
- elif isinstance(curarray, Wolfresults_2D):
2271
- ds = min(curarray[0].dx,curarray[0].dy)
2269
+ ds = curarray.get_dxdy_min()
2272
2270
 
2273
2271
  nb = int(np.ceil(length/ds*2))
2274
2272
 
@@ -2868,6 +2866,11 @@ class zone:
2868
2866
  return self.myvectors[zone_names.index(keyvector)]
2869
2867
  return None
2870
2868
 
2869
+ @property
2870
+ def vector_names(self)->list[str]:
2871
+ """ Return the list of vector names """
2872
+ return [cur.myname for cur in self.myvectors]
2873
+
2871
2874
  def __getitem__(self, ndx:Union[int,str]) -> vector:
2872
2875
  """ Permet de retrouver un vecteur sur base de son index """
2873
2876
  return self.get_vector(ndx)
@@ -2875,7 +2878,7 @@ class zone:
2875
2878
  def export_shape(self, fn:str = ''):
2876
2879
  """ Export to shapefile using GDAL/OGR """
2877
2880
 
2878
- from osgeo import gdal, osr, gdalconst,ogr
2881
+ from osgeo import osr, ogr
2879
2882
 
2880
2883
  fn = str(fn)
2881
2884
 
@@ -4788,6 +4791,11 @@ class Zones(wx.Frame, Element_To_Draw):
4788
4791
  else:
4789
4792
  return self.get_zone(ndx)
4790
4793
 
4794
+ @property
4795
+ def zone_names(self) -> list[str]:
4796
+ """ Return the list of zone names """
4797
+ return [cur.myname for cur in self.myzones]
4798
+
4791
4799
  def import_dxf(self, fn, imported_elts=['POLYLINE','LWPOLYLINE','LINE']):
4792
4800
  """
4793
4801
  Import d'un fichier DXF en tant qu'objets WOLF
@@ -5238,7 +5246,7 @@ class Zones(wx.Frame, Element_To_Draw):
5238
5246
  boxright.Add(self.getxyfromsz,0,wx.EXPAND) # Added
5239
5247
 
5240
5248
  self.butgetval = wx.Button(self,label=_('Get values (self or active array)'))
5241
- self.butgetval.SetToolTip(_("Get values of the attached/active array on each vertex of the active vector and update the editor"))
5249
+ self.butgetval.SetToolTip(_("Get values of the attached/active array (not working with 2D results) on each vertex of the active vector and update the editor"))
5242
5250
  self.butgetval.Bind(wx.EVT_BUTTON,self.Ongetvalues)
5243
5251
  boxright.Add(self.butgetval,0,wx.EXPAND)
5244
5252
 
wolfhece/Results2DGPU.py CHANGED
@@ -261,7 +261,7 @@ class wolfres2DGPU(Wolfresults_2D):
261
261
 
262
262
  curblock.origx = curblock.top.origx
263
263
  curblock.origy = curblock.top.origy
264
-
264
+
265
265
  except:
266
266
  logging.error(_('No spatial position (base_coord_x,base_coord_y) in parameters.json -- Results will not be spatially based'))
267
267
  return -2
@@ -397,7 +397,7 @@ class wolfres2DGPU(Wolfresults_2D):
397
397
  qy_np = qy_np.T
398
398
 
399
399
  curblock = self.myblocks[getkeyblock(1,False)]
400
-
400
+
401
401
  curblock.waterdepth.array.data[:,:] = curblock.waterdepth.nullvalue
402
402
  curblock.qx.array.data[:,:] = curblock.qx.nullvalue
403
403
  curblock.qy.array.data[:,:] = curblock.qy.nullvalue
@@ -405,16 +405,16 @@ class wolfres2DGPU(Wolfresults_2D):
405
405
  curblock.waterdepth.array.mask[:,:] = True
406
406
  curblock.qx.array.mask[:,:] = True
407
407
  curblock.qy.array.mask[:,:] = True
408
-
408
+
409
409
  if self.epsilon > 0.:
410
410
  # curblock.waterdepth.array=ma.masked_less_equal(wd_np.astype(np.float32).T, self.epsilon)
411
-
411
+
412
412
  ij = np.where(wd_np >= self.epsilon)
413
413
  curblock.waterdepth.array.data[ij] = wd_np[ij]
414
414
  curblock.waterdepth.array.mask[ij] = False
415
415
  else:
416
416
  # curblock.waterdepth.array=ma.masked_equal(wd_np.astype(np.float32).T, 0.)
417
-
417
+
418
418
  ij = np.where(wd_np > 0.)
419
419
  curblock.waterdepth.array.data[ij] = wd_np[ij]
420
420
  curblock.waterdepth.array.mask[ij] = False
@@ -463,11 +463,11 @@ class wolfres2DGPU(Wolfresults_2D):
463
463
  wd_np = wd_np.T
464
464
 
465
465
  curblock = self.myblocks[getkeyblock(1,False)]
466
-
466
+
467
467
  curblock.waterdepth.array.data[:,:] = curblock.waterdepth.nullvalue
468
468
 
469
469
  curblock.waterdepth.array.mask[:,:] = True
470
-
470
+
471
471
  if self.epsilon > 0.:
472
472
  ij = np.where(wd_np >= self.epsilon)
473
473
  curblock.waterdepth.array.data[ij] = wd_np[ij]
@@ -529,6 +529,22 @@ class wolfres2DGPU(Wolfresults_2D):
529
529
  else:
530
530
  return self.times, self.timesteps
531
531
 
532
+ @property
533
+ def all_dt(self):
534
+ return self._result_store.get_named_series(ResultType.LAST_DELTA_T)
535
+
536
+ @property
537
+ def all_mostly_dry_mesh(self):
538
+ return self._result_store.get_named_series(ResultType.NB_MOSTLY_DRY_MESHES)
539
+
540
+ @property
541
+ def all_clock_time(self):
542
+ return self._result_store.get_named_series(ResultType.CLOCK_T)
543
+
544
+ @property
545
+ def all_wet_meshes(self):
546
+ return self._result_store.get_named_series(ResultType.NB_WET_MESHES)
547
+
532
548
  # def read_previous(self):
533
549
  # """
534
550
  # Lecture du pas suivant
@@ -0,0 +1,177 @@
1
+
2
+ from pathlib import Path
3
+ import numpy as np
4
+ from shapely.geometry import Polygon, Point, LineString
5
+ from shapely import prepare, is_prepared, destroy_prepared
6
+
7
+ import wx
8
+ import logging
9
+ from tqdm import tqdm
10
+
11
+ from .PyTranslate import _
12
+ from .PyVertexvectors import Zones, zone, vector, wolfvertex
13
+ from .matplotlib_fig import Matplotlib_Figure as mpl_plot, Matplotlib_ax_properties as mpl_ax, Matplolib_line_properties as mpl_line, Matplotlib_figure_properties as mpl_fig
14
+ from .matplotlib_fig import PRESET_LAYOUTS
15
+ from .wolf_array import WolfArray
16
+ from .wolfresults_2D import Wolfresults_2D
17
+ from .Results2DGPU import wolfres2DGPU
18
+
19
+ class Compare_vectors():
20
+ """ Compare multiple vectors """
21
+
22
+ def __init__(self) -> None:
23
+
24
+ self.fig:mpl_plot = None
25
+
26
+ self._reference:vector = None
27
+ self._reference_ls:LineString = None
28
+ self._ref_s:np.ndarray = None
29
+ self._ref_obj:dict[str, WolfArray | wolfres2DGPU | Wolfresults_2D] = {}
30
+ self._ref_values:zone = None
31
+
32
+ self._to_compare:dict[vector, list[WolfArray | wolfres2DGPU | Wolfresults_2D]] = {}
33
+ self._compare_values:dict[vector, zone] = {}
34
+
35
+ @property
36
+ def layout(self):
37
+ """ Layout of the figure """
38
+ return self.fig.layout
39
+
40
+ @layout.setter
41
+ def layout(self, value:dict | tuple | list | str):
42
+ """ Set layout of the figure """
43
+ self.fig = mpl_plot(value)
44
+ self.fig.Show()
45
+
46
+ @property
47
+ def reference(self):
48
+ """ Reference vector """
49
+ return self._reference
50
+
51
+ @reference.setter
52
+ def reference(self, value:vector):
53
+ """ Set reference vector """
54
+ if not isinstance(value, vector):
55
+ logging.error(_('Reference must be a vector'))
56
+ return
57
+
58
+ self._reference = value
59
+ self._reference_ls = value.asshapely_ls()
60
+ prepare(self._reference_ls)
61
+ self._ref_s = self._reference.get_s2d()
62
+
63
+ def __del__(self):
64
+ """ Destructor """
65
+
66
+ if self._reference_ls is not None:
67
+ if is_prepared(self._reference_ls):
68
+ destroy_prepared(self._reference_ls)
69
+
70
+ def add_ref_values(self, values:WolfArray | wolfres2DGPU | Wolfresults_2D):
71
+ """ Add values to the reference vector """
72
+
73
+ self._ref_obj[values.idx] = values
74
+
75
+ def del_ref_values(self, which:int | str):
76
+ """ Pop values from the reference vector """
77
+
78
+ if isinstance(which, str):
79
+ if which in self._ref_obj:
80
+ self._ref_obj.pop(which)
81
+ elif isinstance(which, int):
82
+ if which < len(self._ref_obj):
83
+ self._ref_obj.pop(list(self._ref_obj.keys())[which])
84
+
85
+ def reset_ref_values(self):
86
+ """ Reset reference values """
87
+
88
+ self._ref_obj = {}
89
+
90
+ def get_ref_values(self):
91
+ """ Retrieve reference values """
92
+
93
+ self._ref_values = self.reference.get_values_linked(self._ref_obj)
94
+
95
+ def add_compare(self, support:vector, values:list[WolfArray | wolfres2DGPU | Wolfresults_2D] = None):
96
+ """ Add values to compare """
97
+
98
+ if not isinstance(support, vector):
99
+ logging.error(_('Support must be a vector'))
100
+ return
101
+
102
+ if values is not None:
103
+ if not isinstance(values, list):
104
+ values = [values]
105
+
106
+ if isinstance(values, list):
107
+ if not all(isinstance(x, WolfArray | wolfres2DGPU | Wolfresults_2D) for x in values):
108
+ logging.error(_('Values must be a list of WolfArray, Wolfresults_2D or Wolfres2DGPU'))
109
+ return
110
+
111
+ if support in self._to_compare:
112
+ self._to_compare[support] += values
113
+ else:
114
+ self._to_compare[support] = values
115
+
116
+ def reset_compare(self):
117
+ """ Reset comparison values """
118
+
119
+ self._to_compare = {}
120
+
121
+ def del_compare(self, which:int | str):
122
+ """ Pop values from the comparison vector """
123
+
124
+ if isinstance(which, str):
125
+ if which in self._to_compare:
126
+ self._to_compare.pop(which)
127
+ elif isinstance(which, int):
128
+ if which < len(self._to_compare):
129
+ self._to_compare.pop(list(self._to_compare.keys())[which])
130
+
131
+ def get_compare_values(self):
132
+ """ Retrieve comparison values """
133
+
134
+ for curvect in self._to_compare:
135
+ self._compare_values[curvect] = curvect.get_values_linked({cur.idx: cur for cur in self._to_compare[curvect]})
136
+
137
+ def plot_ref(self, axis:int = 0):
138
+ """ Plot reference vector """
139
+
140
+ if self.fig is None:
141
+ logging.error(_('No figure layout defined'))
142
+ return
143
+
144
+ for curvect in self._ref_values.myvectors:
145
+ xyz = curvect.asnparray3d()
146
+ x = [self._reference_ls.project(Point(x,y)) for x,y in xyz[:,0:2]]
147
+ y = xyz[:,2]
148
+
149
+ self.fig.plot(x=x, y=y, ax=axis, label=curvect.myname)
150
+
151
+ def plot_compare(self, axis:int = 0):
152
+ """ Plot comparison vectors along reference vector.
153
+
154
+ We must project comparison vectors on the reference vector and plot them.
155
+ """
156
+
157
+ if self.fig is None:
158
+ logging.error(_('No figure layout defined'))
159
+ return
160
+
161
+ for curvect in self._compare_values:
162
+ for curval in self._compare_values[curvect].myvectors:
163
+ xyz = curval.asnparray3d()
164
+ x = [self._reference_ls.project(Point(x,y)) for x,y in xyz[:,0:2]]
165
+ y = xyz[:,2]
166
+
167
+ self.fig.plot(x=x, y=y, ax=axis, label=curval.myname)
168
+
169
+ def set_x_bounds(self, smin:float, smax:float, axis:int = 0):
170
+ """ Set x bounds for the figure """
171
+
172
+ self.fig.set_x_bounds(smin, smax, axis)
173
+
174
+ def set_y_bounds(self, ymin:float, ymax:float, axis:int = 0):
175
+ """ Set y bounds for the figure """
176
+
177
+ self.fig.set_y_bounds(ymin, ymax, axis)
wolfhece/apps/version.py CHANGED
@@ -5,7 +5,7 @@ class WolfVersion():
5
5
 
6
6
  self.major = 2
7
7
  self.minor = 1
8
- self.patch = 97
8
+ self.patch = 99
9
9
 
10
10
  def __str__(self):
11
11