wolfhece 2.1.19__py3-none-any.whl → 2.1.21__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.
@@ -0,0 +1,179 @@
1
+ import wx
2
+ import logging
3
+
4
+
5
+ from . import Parser, Expression
6
+
7
+ class Calculator(wx.Frame):
8
+
9
+ def __init__(self, mapviewer=None):
10
+
11
+ from ..PyDraw import WolfMapViewer, draw_type, WolfArray
12
+
13
+ super(Calculator, self).__init__(None, title='Calculator', size=(500, 300))
14
+
15
+ self._memory = {}
16
+
17
+ self._parser = Parser()
18
+ self._parsed_command:Expression = None
19
+
20
+ self._mapviewer:WolfMapViewer = mapviewer
21
+ self._last_command = None
22
+
23
+ keys = '()C<789/456*123-.0=+'
24
+ self._btns:list[list[wx.Button]] = [[wx.Button(self, label=c) for c in keys[i:i+4]] for i in range(0,20,4)]
25
+
26
+ self._disp = wx.TextCtrl(self, style=wx.TE_RIGHT|wx.TE_RICH2|wx.TE_MULTILINE)
27
+
28
+ self._comment = wx.TextCtrl(self, style=wx.TE_RIGHT|wx.TE_RICH2|wx.TE_MULTILINE)
29
+ self.memory = wx.TextCtrl(self, style=wx.TE_RIGHT|wx.TE_RICH2|wx.TE_MULTILINE)
30
+ self.btn_reset_memory = wx.Button(self, label='Reset Memory')
31
+
32
+ self.Bind(wx.EVT_BUTTON, lambda v: self.bt_press(v.EventObject.Label))
33
+
34
+ self._btns[-1][-2].SetDefault()
35
+
36
+ self.Bind(wx.EVT_CHAR_HOOK, self.char_press)
37
+ self.btn_reset_memory.Bind(wx.EVT_BUTTON, lambda v: self._memory.clear())
38
+
39
+ self.SetSizer(self.pack([self._disp] + [self.pack(x) for x in self._btns] + [self.pack([self._comment, self.btn_reset_memory, self.memory])], orient=wx.VERTICAL))
40
+
41
+ self._disp.SetFocus()
42
+
43
+ self.Show()
44
+
45
+ def pack(self, items, orient=wx.HORIZONTAL):
46
+ """ Pack items in a sizer """
47
+ sizer = wx.BoxSizer(orient)
48
+ sizer.AddMany((i, 1, wx.EXPAND|wx.ALL, 0) for i in items)
49
+ return sizer
50
+
51
+ @property
52
+ def command(self) -> str:
53
+ return self._disp.Value
54
+
55
+ @command.setter
56
+ def command(self, value):
57
+ self._disp.Value = str(value)
58
+ self._disp.SetInsertionPointEnd()
59
+
60
+ @property
61
+ def comment(self) -> str:
62
+ return self._comment.Value
63
+
64
+ @comment.setter
65
+ def comment(self, value):
66
+ self._comment.Value = str(value)
67
+
68
+ def check_command(self) -> bool:
69
+ """ Check if the command is valid """
70
+
71
+ from ..PyDraw import draw_type
72
+
73
+ if '\n' in self.command:
74
+ self.evaluate_multilines()
75
+ return False
76
+ else:
77
+
78
+ self._parsed_command = self._parser.parse(self.command)
79
+
80
+ symbols = self._parsed_command.symbols()
81
+ variables = self._parsed_command.variables()
82
+ functions = self._parsed_command.functions
83
+
84
+ if self._mapviewer is not None:
85
+ id_arrays = self._mapviewer.get_list_keys(drawing_type=draw_type.ARRAYS,
86
+ checked_state=None)
87
+
88
+ for id_array in id_arrays:
89
+ self._memory[id_array] = self._mapviewer.get_obj_from_id(id_array, drawtype=draw_type.ARRAYS)
90
+
91
+ if len(variables) > 0:
92
+ for var in variables:
93
+ if var not in self._memory:
94
+ self.comment = f'Variable {var} not defined'
95
+ return False
96
+
97
+ return True
98
+
99
+ def evaluate_multilines(self):
100
+ """ Evaluate multiline commands """
101
+
102
+ self._last_command = self.command
103
+
104
+ commands = self.command.split('\n')
105
+
106
+ ret = []
107
+ for command in commands:
108
+ self.command = command
109
+ ret.append(str(self.evaluate(mem_last_command=False)))
110
+
111
+ self.command = '\n'.join(ret)
112
+
113
+
114
+ def evaluate(self, mem_last_command=True):
115
+ """ Evaluate the command """
116
+ from ..PyDraw import WolfArray, draw_type
117
+
118
+ if mem_last_command:
119
+ self._last_command = self.command
120
+
121
+ ret = self.check_command()
122
+
123
+ if ret:
124
+ args = {var:self._memory[var] for var in self._parsed_command.variables()}
125
+ res = self._parsed_command.evaluate(args)
126
+
127
+ if isinstance(res, dict):
128
+
129
+ comment = 'Storing\n'
130
+
131
+ for key, value in res.items():
132
+ self._memory[key] = value
133
+ comment += f'{key} = {value}\n'
134
+
135
+ self.comment = comment
136
+ self.command = ''
137
+
138
+ elif isinstance(res, str|int|float):
139
+ self.command = res
140
+
141
+ elif isinstance(res, WolfArray):
142
+
143
+ ids = self._mapviewer.get_list_keys(drawing_type=draw_type.ARRAYS, checked_state=None)
144
+ id = self.command
145
+ while id in ids:
146
+ id += '_'
147
+
148
+ self._mapviewer.add_object('array', newobj=res, id = id)
149
+ self.command = ''
150
+
151
+ return res
152
+
153
+ def char_press(self, e:wx.KeyEvent):
154
+ """ Handle key press """
155
+
156
+ egal = '='
157
+ egal_code = [ord(egal)]
158
+
159
+ unicodekey = e.GetUnicodeKey()
160
+ key = e.GetKeyCode()
161
+
162
+ ctrl = e.ControlDown()
163
+ alt = e.AltDown()
164
+ shift= e.ShiftDown()
165
+
166
+ if unicodekey in egal_code:
167
+ if not shift :
168
+ self.evaluate()
169
+ return
170
+
171
+ e.Skip()
172
+
173
+ def bt_press(self, key):
174
+ """ Handle button press """
175
+ if key == 'C': self._disp.Value = ''
176
+ elif key == '<': self.command =self._last_command
177
+ elif key == '=': self.evaluate()
178
+ else : self._disp.Value += key
179
+
wolfhece/wolf_array.py CHANGED
@@ -30,7 +30,7 @@ from scipy.interpolate import interp2d, griddata
30
30
  from scipy.ndimage import laplace, label, sum_labels
31
31
  import pygltflib
32
32
  from shapely.geometry import Point, LineString, MultiLineString
33
- from shapely.ops import linemerge, substring
33
+ from shapely.ops import linemerge, substring, polygonize_full
34
34
  from os.path import dirname,basename,join
35
35
  import logging
36
36
  from typing import Literal
@@ -7376,7 +7376,13 @@ class WolfArray(Element_To_Draw, header_wolf):
7376
7376
 
7377
7377
  curlist['done'][loci, locj] = 1
7378
7378
 
7379
- def suxsuy_contour(self, filename:str='', abs:bool=False) -> tuple[list[int,int], list[int,int], vector, bool]:
7379
+ def suxsuy_contour(self,
7380
+ filename:str='',
7381
+ abs:bool=False,
7382
+ one_vec_if_ml:bool = True) -> tuple[list[int,int],
7383
+ list[int,int],
7384
+ vector | zone,
7385
+ bool]:
7380
7386
  """
7381
7387
  The borders are computed on basis of the current *mask*
7382
7388
 
@@ -7406,31 +7412,6 @@ class WolfArray(Element_To_Draw, header_wolf):
7406
7412
  translx += self.translx
7407
7413
  transly += self.transly
7408
7414
 
7409
- # for i in range(self.nbx-1):
7410
- # for j in range(self.nby-1):
7411
- # x1 = float(i+1) * dx + translx
7412
- # y1 = float(j+1) * dy + transly
7413
- # if self.array.mask[i, j] ^ self.array.mask[i + 1, j]: # ^ == xor
7414
-
7415
- # # There's a vertical border between the cells (i,j) and
7416
- # # (i+1,j).
7417
-
7418
- # # Remember vertical borders are (by convention) located
7419
- # # on the left side of a cell.
7420
- # # Moreover, (i,j) are counted in numpy coordinates
7421
- # # (0-based) but the saved files follow Fortran convention
7422
- # # (1-based), so we add +1 to both i,j before storing.
7423
-
7424
- # indicesX.append([i+2, j+1]) # +2, +1 pour être en accord avec le standard de numérotation Fortran
7425
- # locls.append(LineString([[x1,y1-dy],[x1,y1]]))
7426
-
7427
- # if self.array.mask[i, j] ^ self.array.mask[i, j +1]:
7428
- # # See vertical border's explanation above (and replace
7429
- # # with horizontal).
7430
-
7431
- # indicesY.append([i+1,j+2]) # +1, +2 pour être en accord avec le standard de numérotation Fortran
7432
- # locls.append(LineString([[x1-dx,y1],[x1,y1]]))
7433
-
7434
7415
  horiz = np.where(self.array.mask[0:self.nbx-1,0:self.nby-1] ^ self.array.mask[1:self.nbx,0:self.nby-1])
7435
7416
  vert = np.where(self.array.mask[0:self.nbx-1,0:self.nby-1] ^ self.array.mask[0:self.nbx-1,1:self.nby])
7436
7417
 
@@ -7462,33 +7443,47 @@ class WolfArray(Element_To_Draw, header_wolf):
7462
7443
  contourgen.add_vertex(wolfvertex(x,y))
7463
7444
 
7464
7445
  elif contour.geom_type == 'MultiLineString':
7465
- interior=True
7466
- # Multiple vectors --> combine
7467
-
7468
- # searching the longest LineString -> external contour
7469
- contour:MultiLineString
7470
- lenghts=[mygeom.length for mygeom in contour.geoms]
7471
- ind = np.argmax(lenghts)
7446
+ if one_vec_if_ml:
7447
+ interior=True
7448
+ # Multiple vectors --> combine
7449
+
7450
+ # searching the longest LineString -> external contour
7451
+ contour:MultiLineString
7452
+ lenghts=[mygeom.length for mygeom in contour.geoms]
7453
+ ind = np.argmax(lenghts)
7454
+
7455
+ xyall=[np.column_stack([np.asarray(mygeom.coords),np.zeros(len(mygeom.coords))]) for mygeom in contour.geoms]
7456
+
7457
+ # coordinates of the longest LineString
7458
+ xy = xyall[ind]
7459
+
7460
+ for i in range(len(xyall)):
7461
+ if i!=ind:
7462
+ # Concatenate local LineString to the external contour + 2 connection segments
7463
+ # Z coordinate is set to 1. -> will be used to check it after and change "in_use" property
7464
+ xy=np.concatenate([xy,
7465
+ np.asarray([xyall[i][0,0],xyall[i][0,1],1.]).reshape([1,3]),
7466
+ xyall[i][1:],
7467
+ np.asarray([xy[0,0],xy[0,1],1.]).reshape([1,3])])
7468
+
7469
+ nb = len(xy)
7470
+ contourgen = vector(name='external border')
7471
+ for x,y,z in xy:
7472
+ contourgen.add_vertex(wolfvertex(x,y,z))
7473
+ contourgen.myvertices[-1].in_use = z == 0. # the new vertex is related to a connection segment --> ignore for numerical precision in intersection operations/calculations
7474
+ else:
7475
+ contourgen = zone(name = 'contour')
7472
7476
 
7473
- xyall=[np.column_stack([np.asarray(mygeom.coords),np.zeros(len(mygeom.coords))]) for mygeom in contour.geoms]
7477
+ for cur_ls in contour.geoms:
7478
+ xy = np.asarray(cur_ls.coords)
7479
+ nb = len(xy)
7474
7480
 
7475
- # coordinates of the longest LineString
7476
- xy = xyall[ind]
7481
+ cur_vec = vector(name='external border')
7482
+ for x,y in xy:
7483
+ cur_vec.add_vertex(wolfvertex(x,y))
7477
7484
 
7478
- for i in range(len(xyall)):
7479
- if i!=ind:
7480
- # Concatenate local LineString to the external contour + 2 connection segments
7481
- # Z coordinate is set to 1. -> will be used to check it after and change "in_use" property
7482
- xy=np.concatenate([xy,
7483
- np.asarray([xyall[i][0,0],xyall[i][0,1],1.]).reshape([1,3]),
7484
- xyall[i][1:],
7485
- np.asarray([xy[0,0],xy[0,1],1.]).reshape([1,3])])
7485
+ contourgen.add_vector(cur_vec, forceparent=True)
7486
7486
 
7487
- nb = len(xy)
7488
- contourgen = vector(name='external border')
7489
- for x,y,z in xy:
7490
- contourgen.add_vertex(wolfvertex(x,y,z))
7491
- contourgen.myvertices[-1].in_use = z == 0. # the new vertex is related to a connection segment --> ignore for numerical precision in intersection operations/calculations
7492
7487
  else:
7493
7488
  contourgen = None
7494
7489
  err = _(f"Unsupported Shapely contour result: {contour.geom_type}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wolfhece
3
- Version: 2.1.19
3
+ Version: 2.1.21
4
4
  Author-email: Pierre Archambeau <pierre.archambeau@uliege.be>
5
5
  License: AGPL-v3 License
6
6
  Project-URL: Homepage, https://uee.uliege.be/hece
@@ -13,6 +13,7 @@ Classifier: Topic :: Scientific/Engineering :: Physics
13
13
  Requires-Python: <3.11,>=3.10
14
14
  Description-Content-Type: text/markdown
15
15
  Requires-Dist: wxpython
16
+ Requires-Dist: triangle
16
17
  Requires-Dist: numpy
17
18
  Requires-Dist: pyopengl
18
19
  Requires-Dist: pandas
@@ -6,7 +6,7 @@ wolfhece/ManageParams.py,sha256=Wgt5Zh7QBtyiwTAltPHunSLqt4XuVuRH76GTUrXabS4,219
6
6
  wolfhece/Model1D.py,sha256=-cMz-ePSYzrKVVDidiDOz6cojEZ3y6u9gIb7RPwT6Y8,476593
7
7
  wolfhece/PyConfig.py,sha256=oGSL1WsLM9uinlNP4zGBLK3uHPmBfduUi7R-VtWuRFA,8034
8
8
  wolfhece/PyCrosssections.py,sha256=f4dNYRUGZKePruaaBiTcn5vlrw8TFTj9XwTDrdiF_uU,112450
9
- wolfhece/PyDraw.py,sha256=YlgDQm0xiJP0uWLCpLVFhjH9YPl3O7JyO-2tLYlqxqw,384535
9
+ wolfhece/PyDraw.py,sha256=eZCDOZsiZ9dVFtfeg4Cxep_HHMcyo11kGMK7a4xge-E,384933
10
10
  wolfhece/PyGui.py,sha256=fqy8f3tLt7myJskVvspTQ_ZO7kaiSNKmcfFLrfr4w7M,103174
11
11
  wolfhece/PyGuiHydrology.py,sha256=r8kcY2eGAQzSwVtLpyMUiBL5xBpMBsi7ovs0PgStGWw,14648
12
12
  wolfhece/PyHydrographs.py,sha256=GKK8U0byI45H9O_e4LAOOi7Aw0Tg7Q0Lx322stPg5IQ,3453
@@ -15,7 +15,7 @@ wolfhece/PyParams.py,sha256=Aj8kcT044abwBYU_OiEcJWcyNVqxYithNfbzdHyI-QA,97072
15
15
  wolfhece/PyPictures.py,sha256=-mJB0JL2YYiEK3D7_ssDkvYiMWK4ve9kXhozQXNeSx8,2216
16
16
  wolfhece/PyTranslate.py,sha256=4appkmNeHHZLFmUtaA_k5_5QL-5ymxnbVN4R2OblmtE,622
17
17
  wolfhece/PyVertex.py,sha256=dHTjyYYTn0F_NWerlAOBKHV79RUzEEtMJMldQtVc1Cs,40092
18
- wolfhece/PyVertexvectors.py,sha256=4K0T74MUH-ycX79hFa2618vKVTu9qOSh49hlbKrydMg,224123
18
+ wolfhece/PyVertexvectors.py,sha256=YcLs8xwmD3UqGDxfjzRedZolLN3SCHotoXxzP2U4HkU,226029
19
19
  wolfhece/PyWMS.py,sha256=pV7JdzbreQGXCg3E6PwllchEUYu2YiPZEIua2ppJorA,4304
20
20
  wolfhece/RatingCurve.py,sha256=f6IGLS5aJBJD_t_k903m_yRZ60MzKNKanzD6njXZxa8,22200
21
21
  wolfhece/RatingCurveData.py,sha256=5UvnIm89BwqjnEbLCcY3CA8WoFd_xHJbooNy62fX5iY,57660
@@ -48,7 +48,7 @@ wolfhece/rain_SPWMI.py,sha256=YqsF-yFro3y_a6MfVRFfr-Rxi7NR1gl_i8VX7scmzes,13548
48
48
  wolfhece/test_Results2DGPU.py,sha256=NOJ_hFXrcLSQXS1dtsqXRQltqIZtDSHMz_EgAJ2_FHU,307
49
49
  wolfhece/textpillow.py,sha256=zEfLrKhfCDyMaVuQOUjHqz6MGKeQ4aewMxOsWi5-wKI,13832
50
50
  wolfhece/tools_mpl.py,sha256=q8Yc4aukPPiUcEzREvZRM_em67XqXaahdoaNt0DETfE,266
51
- wolfhece/wolf_array.py,sha256=8cYHIwul4VVkSXwGqPMLaEv8n3c5cC0Ozp5xdfupUsI,342928
51
+ wolfhece/wolf_array.py,sha256=uYyymkYRDOk43GK7Wn91IKCJ5CmjLiMIgXReRFTkzuc,342457
52
52
  wolfhece/wolf_hist.py,sha256=JpRXvzJLUP-RkSkvth3DQWglgTMFI2ZEUDb4RYOfeeI,3284
53
53
  wolfhece/wolf_texture.py,sha256=llQ7aV8scWXIkhpri9XjaPejzoBJsGfsln2ZnlRbFkU,16270
54
54
  wolfhece/wolf_tiles.py,sha256=F2JsJHdAP8fIffNJdG_J26bonCIRtIwMmxKFqdSCRDA,10088
@@ -66,7 +66,7 @@ wolfhece/apps/check_install.py,sha256=jrKR-njqnpIh6ZJqvP6KbDUPVCfwTNQj4glQhcyzs9
66
66
  wolfhece/apps/curvedigitizer.py,sha256=avWERHuVxPnJBOD_ibczwW_XG4vAenqWS8W1zjhBox8,4898
67
67
  wolfhece/apps/isocurrent.py,sha256=4XnNWPa8mYUK7V4zdDRFrHFIXNG2AN2og3TqWKKcqjY,3811
68
68
  wolfhece/apps/splashscreen.py,sha256=LkEVMK0eCc84NeCWD3CGja7fuQ_k1PrZdyqD3GQk_8c,2118
69
- wolfhece/apps/version.py,sha256=pxI-blXjVWz8Af7dvteh6caxvhN-mCRsq-_4uSmye8s,388
69
+ wolfhece/apps/version.py,sha256=vzfNBTFSbty1piUlbNtlxS283UUEd8VsyNhwhWSDzS0,388
70
70
  wolfhece/apps/wolf.py,sha256=gqfm-ZaUJqNsfCzmdtemSeqLw-GVdSVix-evg5WArJI,293
71
71
  wolfhece/apps/wolf2D.py,sha256=gWD9ee2-1pw_nUxjgRaJMuSe4kUT-RWhOeoTt_Lh1mM,267
72
72
  wolfhece/apps/wolf_logo.bmp,sha256=ruJ4MA51CpGO_AYUp_dB4SWKHelvhOvd7Q8NrVOjDJk,3126
@@ -212,6 +212,8 @@ wolfhece/mar/Interface_MAR_WOLF_objet.py,sha256=_PNOrZDr-7CR19x_XHqLB5Si2hk8e469
212
212
  wolfhece/mar/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
213
213
  wolfhece/mar/commontools.py,sha256=vCmoNI2sMOco6Y4KPpKb7WORq45qFU_lSxbKGV9oZ8A,53824
214
214
  wolfhece/mar/interface_MAR_WOLF.py,sha256=MWeXaHLDT4Eo9jZOAvz013lmpgGYT1v9VUYGAgBgSRU,21454
215
+ wolfhece/math_parser/__init__.py,sha256=mrD_uFDDZzvyxQkY8ESqcy1bvM7e3__Gi2b_vijvoo8,27977
216
+ wolfhece/math_parser/calculator.py,sha256=klFB2kMsC0VfQ5IoXBZ1xzn8jbSrJGzYJ7NTHgC_9vc,5707
215
217
  wolfhece/mesh2d/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
216
218
  wolfhece/mesh2d/bc_manager.py,sha256=OzN4NPlDniv9HsLTUQrJkBY6U_a3SkqNpvjIw0TcguI,52967
217
219
  wolfhece/mesh2d/cell_tracker.py,sha256=AR-Bty-QnrY1ni8Lwak2kU2UWMAJSBCF2ugl2YpfsB4,8660
@@ -268,8 +270,8 @@ wolfhece/sounds/sonsw2.wav,sha256=pFLVt6By0_EPQNt_3KfEZ9a1uSuYTgQSX1I_Zurv9Rc,11
268
270
  wolfhece/ui/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
269
271
  wolfhece/ui/wolf_multiselection_collapsiblepane.py,sha256=yGbU_JsF56jsmms0gh7mxa7tbNQ_SxqhpAZxhm-mTy4,14860
270
272
  wolfhece/ui/wolf_times_selection_comparison_models.py,sha256=wCxGRnE3kzEkWlWA6-3X8ADOFux_B0a5QWJ2GnXTgJw,4709
271
- wolfhece-2.1.19.dist-info/METADATA,sha256=nBRFLNjydXPkETNSMpS4ccjkMxDi8kgcghfRBWX9Vmg,2282
272
- wolfhece-2.1.19.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
273
- wolfhece-2.1.19.dist-info/entry_points.txt,sha256=AIu1KMswrdsqNq_2jPtrRIU4tLjuTnj2dCY-pxIlshw,276
274
- wolfhece-2.1.19.dist-info/top_level.txt,sha256=EfqZXMVCn7eILUzx9xsEu2oBbSo9liWPFWjIHik0iCI,9
275
- wolfhece-2.1.19.dist-info/RECORD,,
273
+ wolfhece-2.1.21.dist-info/METADATA,sha256=ANQmVNuOvZofxG3nqK3bG02bjcuvPb9e1KhL1pqroUQ,2307
274
+ wolfhece-2.1.21.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
275
+ wolfhece-2.1.21.dist-info/entry_points.txt,sha256=AIu1KMswrdsqNq_2jPtrRIU4tLjuTnj2dCY-pxIlshw,276
276
+ wolfhece-2.1.21.dist-info/top_level.txt,sha256=EfqZXMVCn7eILUzx9xsEu2oBbSo9liWPFWjIHik0iCI,9
277
+ wolfhece-2.1.21.dist-info/RECORD,,