wolfhece 2.1.7__py3-none-any.whl → 2.1.8__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 +11 -3
- wolfhece/apps/version.py +1 -1
- wolfhece/multiprojects.py +166 -3
- wolfhece/pybridges.py +1 -0
- wolfhece/pypolygons_scen.py +306 -30
- {wolfhece-2.1.7.dist-info → wolfhece-2.1.8.dist-info}/METADATA +1 -1
- {wolfhece-2.1.7.dist-info → wolfhece-2.1.8.dist-info}/RECORD +10 -10
- {wolfhece-2.1.7.dist-info → wolfhece-2.1.8.dist-info}/WHEEL +1 -1
- {wolfhece-2.1.7.dist-info → wolfhece-2.1.8.dist-info}/entry_points.txt +0 -0
- {wolfhece-2.1.7.dist-info → wolfhece-2.1.8.dist-info}/top_level.txt +0 -0
wolfhece/PyParams.py
CHANGED
@@ -944,7 +944,11 @@ class Wolf_Param(wx.Frame):
|
|
944
944
|
except:
|
945
945
|
logging.debug("String type will be conserved! -- {}".format(value_param))
|
946
946
|
|
947
|
-
|
947
|
+
if type(value_param) != int:
|
948
|
+
logging.warning("Parameters -- EnumProperty -- Value {} is not an integer".format(value_param))
|
949
|
+
logging.debug("EnumProperty value must be an integer")
|
950
|
+
|
951
|
+
page.AppendIn(parent, pg.EnumProperty(param_name, name=locname, labels=list_keys, values=list_values, value=int(value_param))) # force value to 'int' type
|
948
952
|
else:
|
949
953
|
self._insert_with_type_based_on_value(page, group, param, prefix)
|
950
954
|
|
@@ -1055,8 +1059,12 @@ class Wolf_Param(wx.Frame):
|
|
1055
1059
|
value_param = int(value_param)
|
1056
1060
|
except:
|
1057
1061
|
logging.debug("String type will be conserved! -- {}".format(value_param))
|
1058
|
-
|
1059
|
-
|
1062
|
+
|
1063
|
+
if type(value_param) != int:
|
1064
|
+
logging.warning("Parameters -- EnumProperty -- Value {} is not an integer".format(value_param))
|
1065
|
+
logging.debug("EnumProperty value must be an integer")
|
1066
|
+
|
1067
|
+
page.Append(pg.EnumProperty(label= param_name, name= locname, labels= list_keys, values= list_values, value= int(value_param)))
|
1060
1068
|
|
1061
1069
|
else:
|
1062
1070
|
# Pas de chaîne JSON mais un commentaire complet
|
wolfhece/apps/version.py
CHANGED
wolfhece/multiprojects.py
CHANGED
@@ -80,7 +80,103 @@ class Wolf2D_Project(Project):
|
|
80
80
|
self.poly = None
|
81
81
|
self.poly_values = None
|
82
82
|
|
83
|
-
|
83
|
+
@classmethod
|
84
|
+
def from_existing(cls, sims:dict[str, Union[str, Wolfresults_2D, wolfres2DGPU]]):
|
85
|
+
"""
|
86
|
+
Create a MultiProjects object from a dictionary of simulations
|
87
|
+
|
88
|
+
:param sims: dict[str, Union[str, Wolfresults_2D, wolfres2DGPU]] -- dictionary of simulations to add
|
89
|
+
"""
|
90
|
+
|
91
|
+
newmp = cls(to_read=False)
|
92
|
+
newmp.add_simulations(sims)
|
93
|
+
|
94
|
+
return newmp
|
95
|
+
|
96
|
+
def __str__(self) -> str:
|
97
|
+
"""
|
98
|
+
Return string representation
|
99
|
+
"""
|
100
|
+
|
101
|
+
ret = f'Project : {Path(self.wdir)}\n'
|
102
|
+
ret += 'Key : Simulations : Type\n'
|
103
|
+
for curkey, cursim in self.mysims.items():
|
104
|
+
ret+=f'{curkey} : {cursim.filename} : {"GPU" if isinstance(cursim, wolfres2DGPU) else "CPU"}\n'
|
105
|
+
|
106
|
+
return ret
|
107
|
+
|
108
|
+
def __getitem__(self, key: tuple[str, str]):
|
109
|
+
|
110
|
+
return self.get_simulation(key)
|
111
|
+
|
112
|
+
def pop(self, key: str):
|
113
|
+
"""
|
114
|
+
Remove a simulation from the project
|
115
|
+
|
116
|
+
:param key: str -- key of the simulation to remove
|
117
|
+
"""
|
118
|
+
|
119
|
+
if key in self.mysims.keys():
|
120
|
+
self.mysims.pop(key)
|
121
|
+
|
122
|
+
def add(self,
|
123
|
+
key:str,
|
124
|
+
value:Union[Wolfresults_2D, wolfres2DGPU, str],
|
125
|
+
epsilon:float=None,
|
126
|
+
force_read:bool = False):
|
127
|
+
"""
|
128
|
+
Add a key-value pair to the project
|
129
|
+
|
130
|
+
:param key: str -- key of the simulation to add
|
131
|
+
:param value: Wolfresults_2D, wolfres2DGPU, str -- simulation to add
|
132
|
+
:param epsilon: float -- epsilon value to use for the simulation
|
133
|
+
:param force_read: bool -- force reading the last step of the simulation
|
134
|
+
|
135
|
+
"""
|
136
|
+
|
137
|
+
if epsilon is None:
|
138
|
+
epsilon = self.epsilon
|
139
|
+
|
140
|
+
if isinstance(value, str):
|
141
|
+
|
142
|
+
locpath = Path(self.wdir) / value
|
143
|
+
if locpath.exists():
|
144
|
+
|
145
|
+
if 'simul_gpu_results' in locpath.name or (locpath / 'simul_gpu_results').exists():
|
146
|
+
#GPU
|
147
|
+
self.mysims[key] = wolfres2DGPU(locpath, epsilon=self.epsilon, idx=key)
|
148
|
+
else:
|
149
|
+
#CPU
|
150
|
+
self.mysims[key] = Wolfresults_2D(locpath, epsilon=self.epsilon, idx=key)
|
151
|
+
|
152
|
+
else:
|
153
|
+
logging.warning(f'File {locpath} does not exist !')
|
154
|
+
|
155
|
+
elif isinstance(value, wolfres2DGPU):
|
156
|
+
|
157
|
+
self.mysims[key] = value
|
158
|
+
|
159
|
+
elif isinstance(value, Wolfresults_2D):
|
160
|
+
|
161
|
+
self.mysims[key] = value
|
162
|
+
|
163
|
+
if force_read:
|
164
|
+
self.mysims[key].read_oneresult()
|
165
|
+
|
166
|
+
def add_simulations(self,
|
167
|
+
sims_to_add:dict[str, Union[str, Wolfresults_2D, wolfres2DGPU]],
|
168
|
+
epsilon:float=None,
|
169
|
+
force_read:bool = False):
|
170
|
+
"""
|
171
|
+
Add multiple simulations to the project
|
172
|
+
|
173
|
+
:param sims_to_add: dict[str, Union[str, Wolfresults_2D, wolfres2DGPU]] -- dictionary of simulations to add
|
174
|
+
"""
|
175
|
+
|
176
|
+
for key, value in sims_to_add.items():
|
177
|
+
self.add(key, value, epsilon, force_read)
|
178
|
+
|
179
|
+
def load_simulations(self, epsilon:float, verbose:bool=False):
|
84
180
|
"""
|
85
181
|
Load all simulations in current project
|
86
182
|
"""
|
@@ -92,6 +188,7 @@ class Wolf2D_Project(Project):
|
|
92
188
|
for key,val in sims_wolf2d.items():
|
93
189
|
if verbose:
|
94
190
|
print(key)
|
191
|
+
logging.info(f'Loading simulation {key} : {val[key_Param.VALUE]}')
|
95
192
|
|
96
193
|
cursim = self.mysims[key] = Wolfresults_2D(join(self.wdir, val[key_Param.VALUE]), eps=epsilon, idx=key)
|
97
194
|
cursim.plotted=True
|
@@ -102,6 +199,7 @@ class Wolf2D_Project(Project):
|
|
102
199
|
for key,val in sims_gpu2d.items():
|
103
200
|
if verbose:
|
104
201
|
print(key)
|
202
|
+
logging.info(f'Loading simulation {key} : {val[key_Param.VALUE]}')
|
105
203
|
|
106
204
|
cursim = self.mysims[key] = wolfres2DGPU(Path(join(self.wdir, val[key_Param.VALUE])), eps=epsilon, idx=key)
|
107
205
|
cursim.plotted=True
|
@@ -128,6 +226,23 @@ class Wolf2D_Project(Project):
|
|
128
226
|
for cursim in self.mysims.values():
|
129
227
|
cursim.read_oneresult()
|
130
228
|
|
229
|
+
def get_simulation(self, key:Union[str,int]) -> Union[Wolfresults_2D, wolfres2DGPU]:
|
230
|
+
"""
|
231
|
+
Get simulation by key
|
232
|
+
|
233
|
+
:param key: str or int -- key of the simulation to get or index of the simulation to get
|
234
|
+
"""
|
235
|
+
|
236
|
+
if isinstance(key,int):
|
237
|
+
if key >=0 and key <len(self.mysims):
|
238
|
+
return self.mysims[self.mysims.keys()[key]]
|
239
|
+
|
240
|
+
elif isinstance(key,str):
|
241
|
+
if key in self.mysims.keys():
|
242
|
+
return self.mysims[key]
|
243
|
+
|
244
|
+
return None
|
245
|
+
|
131
246
|
def get_simulations(self) -> list:
|
132
247
|
"""
|
133
248
|
Return a python list of simulations
|
@@ -274,15 +389,58 @@ class Wolf2D_Project(Project):
|
|
274
389
|
|
275
390
|
class MultiProjects():
|
276
391
|
"""Manager of multiple project files"""
|
392
|
+
|
277
393
|
def __init__(self, wdir='') -> None:
|
278
394
|
|
279
395
|
self.projects:dict[str, Wolf2D_Project]={}
|
280
396
|
self.wdir=wdir
|
281
397
|
|
398
|
+
def __getitem__(self, key:Union[str,int]) -> Project:
|
399
|
+
"""
|
400
|
+
Get project by key
|
401
|
+
"""
|
402
|
+
|
403
|
+
return self.get_project(key)
|
404
|
+
|
405
|
+
def get_one_simulation(self, key_project:str, key_sim:str) -> Union[Wolfresults_2D, wolfres2DGPU]:
|
406
|
+
"""
|
407
|
+
Get one simulation by key in a project
|
408
|
+
"""
|
409
|
+
|
410
|
+
if key_project in self.projects.keys():
|
411
|
+
return self.projects[key_project].get_simulation(key_sim)
|
412
|
+
|
413
|
+
return None
|
414
|
+
|
415
|
+
def get_same_simulation_in_projects(self, key_sim:str) -> dict[str, Union[Wolfresults_2D, wolfres2DGPU]]:
|
416
|
+
"""
|
417
|
+
Get simulation by key in all projects
|
418
|
+
"""
|
419
|
+
|
420
|
+
allsims = {}
|
421
|
+
for curkey, curproj in self.projects.items():
|
422
|
+
cursim = curproj.get_simulation(key_sim)
|
423
|
+
if cursim is not None:
|
424
|
+
allsims[curkey + ' - ' + key_sim] = cursim
|
425
|
+
|
426
|
+
return allsims
|
427
|
+
|
428
|
+
def __str__(self) -> str:
|
429
|
+
"""
|
430
|
+
Return string representation
|
431
|
+
"""
|
432
|
+
|
433
|
+
ret = 'Key : Directory\n'
|
434
|
+
for curkey,curproj in self.projects.items():
|
435
|
+
ret+=f'{curkey} : {Path(curproj.wdir)}\n'
|
436
|
+
|
437
|
+
return ret
|
438
|
+
|
282
439
|
def add(self, project:Project, key=str, whichtype=project_type.GENERIC):
|
283
440
|
"""
|
284
441
|
Add project to dict
|
285
442
|
"""
|
443
|
+
|
286
444
|
if isinstance(project,str):
|
287
445
|
if exists(project):
|
288
446
|
pass
|
@@ -300,6 +458,7 @@ class MultiProjects():
|
|
300
458
|
"""
|
301
459
|
Récupération d'un projet sur base du nom ou d'une position
|
302
460
|
"""
|
461
|
+
|
303
462
|
if isinstance(key,int):
|
304
463
|
if key >=0 and key <len(self.projects):
|
305
464
|
return self.projects[self.projects.keys()[key]]
|
@@ -309,11 +468,12 @@ class MultiProjects():
|
|
309
468
|
return self.projects[key]
|
310
469
|
|
311
470
|
return None
|
312
|
-
|
471
|
+
|
313
472
|
def read(self, filepath:str):
|
314
473
|
"""
|
315
474
|
Read from file
|
316
475
|
"""
|
476
|
+
|
317
477
|
if exists(filepath):
|
318
478
|
with open(filepath,'r') as f:
|
319
479
|
self.projects = json.load(f)
|
@@ -322,6 +482,7 @@ class MultiProjects():
|
|
322
482
|
"""
|
323
483
|
Write to file
|
324
484
|
"""
|
485
|
+
|
325
486
|
with open(filepath,'w') as f:
|
326
487
|
json.dump(self.projects,f)
|
327
488
|
|
@@ -329,6 +490,7 @@ class MultiProjects():
|
|
329
490
|
"""
|
330
491
|
Load all simulations in projects
|
331
492
|
"""
|
493
|
+
|
332
494
|
for keyp,valp in self.projects.items():
|
333
495
|
print(keyp)
|
334
496
|
valp.load_simulations(epsilon, verbose)
|
@@ -337,11 +499,12 @@ class MultiProjects():
|
|
337
499
|
"""
|
338
500
|
Update all simulations in projects
|
339
501
|
"""
|
502
|
+
|
340
503
|
for keyp,valp in self.projects.items():
|
341
504
|
print(keyp)
|
342
505
|
valp.update_simulations(epsilon, verbose)
|
343
506
|
|
344
|
-
def get_simulations_list(self, which_project=None) -> list:
|
507
|
+
def get_simulations_list(self, which_project:Union[str, list[str]]=None) -> list:
|
345
508
|
"""
|
346
509
|
Return a python list of simulations
|
347
510
|
|
wolfhece/pybridges.py
CHANGED
@@ -31,6 +31,7 @@ class stored_values_unk(Enum):
|
|
31
31
|
UNORM = (5, views_2D.UNORM.value)
|
32
32
|
FROUDE = (6, views_2D.FROUDE.value)
|
33
33
|
WATERLEVEL = (7, views_2D.WATERLEVEL.value)
|
34
|
+
WATERSTAGE = (7, views_2D.WATERLEVEL.value)
|
34
35
|
TOPOGRAPHY = (8, views_2D.TOPOGRAPHY.value)
|
35
36
|
HEAD = (-1, _('Difference of waterlevel (up-down)'))
|
36
37
|
DIFFERENCE_Z_UP_DOWN = (-1, _('Difference of waterlevel (up-down)'))
|
wolfhece/pypolygons_scen.py
CHANGED
@@ -7,20 +7,151 @@ from typing import Literal, Union
|
|
7
7
|
import matplotlib.pyplot as plt
|
8
8
|
from enum import Enum
|
9
9
|
import logging
|
10
|
+
from pathlib import Path
|
10
11
|
|
11
12
|
from .PyTranslate import _
|
12
13
|
from .PyVertexvectors import Zones, zone, vector, vectorproperties, getIfromRGB
|
13
14
|
from .drawing_obj import Element_To_Draw
|
14
15
|
from .PyTranslate import _
|
15
|
-
from .wolfresults_2D import views_2D
|
16
|
+
from .wolfresults_2D import views_2D, Wolfresults_2D
|
17
|
+
from .Results2DGPU import wolfres2DGPU
|
16
18
|
from .pybridges import stored_values_pos,stored_values_unk, parts_values, operators, stored_values_coords
|
17
19
|
|
20
|
+
from zipfile import ZIP_DEFLATED, ZipFile
|
21
|
+
|
22
|
+
class ZipFileWrapper(ZipFile):
|
23
|
+
def open(self, name="data", mode="r", pwd=None, **kwargs):
|
24
|
+
return super().open(name=name, mode=mode, pwd=pwd, **kwargs)
|
25
|
+
|
26
|
+
def read(self):
|
27
|
+
return super().read(name="data")
|
28
|
+
|
18
29
|
class Extracting_Zones(Zones):
|
30
|
+
"""
|
31
|
+
Classe permettant de récupérer les valeurs à l'intérieur des polygones
|
32
|
+
définis dans plusieurs zones.
|
33
|
+
|
34
|
+
Ces polygones ne sont pas nécessairement ordonnés ou relatifs au lit mineur.
|
35
|
+
|
36
|
+
"""
|
19
37
|
|
20
38
|
def __init__(self, filename='', ox: float = 0, oy: float = 0, tx: float = 0, ty: float = 0, parent=None, is2D=True, idx: str = '', plotted: bool = True, mapviewer=None, need_for_wx: bool = False) -> None:
|
21
39
|
super().__init__(filename, ox, oy, tx, ty, parent, is2D, idx, plotted, mapviewer, need_for_wx)
|
22
|
-
|
23
|
-
self.
|
40
|
+
|
41
|
+
self.parts:dict = None
|
42
|
+
self.linked:Union[dict, list] = None
|
43
|
+
|
44
|
+
def cache_data(self, outputfile:str):
|
45
|
+
"""
|
46
|
+
Serialize the values in a file
|
47
|
+
"""
|
48
|
+
self._serialize_values(outputfile)
|
49
|
+
|
50
|
+
def load_data(self, inputfile:str):
|
51
|
+
"""
|
52
|
+
Deserialize the values from a file
|
53
|
+
"""
|
54
|
+
self._deserialize_values(inputfile)
|
55
|
+
|
56
|
+
def _serialize_values(self, outputfile:str):
|
57
|
+
"""
|
58
|
+
Serialize the values in a file
|
59
|
+
"""
|
60
|
+
|
61
|
+
import json
|
62
|
+
from codecs import getwriter
|
63
|
+
from typing import IO
|
64
|
+
|
65
|
+
class NumpyArrayEncoder(json.JSONEncoder):
|
66
|
+
def default(self, obj):
|
67
|
+
if isinstance(obj, np.integer):
|
68
|
+
return int(obj)
|
69
|
+
elif isinstance(obj, np.floating):
|
70
|
+
return float(obj)
|
71
|
+
elif isinstance(obj, np.ndarray):
|
72
|
+
return obj.tolist()
|
73
|
+
elif obj == Wolfresults_2D:
|
74
|
+
return 'CPU'
|
75
|
+
elif obj == wolfres2DGPU:
|
76
|
+
return 'GPU'
|
77
|
+
|
78
|
+
return json.JSONEncoder.default(self, obj)
|
79
|
+
|
80
|
+
def _json_dump_bytes(fp: IO, obj):
|
81
|
+
StreamWriter = getwriter("utf-8")
|
82
|
+
return json.dump(fp=StreamWriter(fp), obj=obj, cls=NumpyArrayEncoder, indent=4)
|
83
|
+
|
84
|
+
def json_dump_zip(fp: IO, obj):
|
85
|
+
with ZipFileWrapper(fp, mode="w", compression=ZIP_DEFLATED, compresslevel=9) as zip_file:
|
86
|
+
with zip_file.open(mode="w") as _fp:
|
87
|
+
_json_dump_bytes(fp=_fp, obj=obj)
|
88
|
+
|
89
|
+
|
90
|
+
with open(outputfile, 'wb') as f:
|
91
|
+
|
92
|
+
json_dump_zip(fp = f, obj = {'linked' : self.linked, 'values': self.parts})
|
93
|
+
|
94
|
+
|
95
|
+
def _deserialize_values(self, inputfile:str):
|
96
|
+
"""
|
97
|
+
Deserialize the values from a file
|
98
|
+
"""
|
99
|
+
|
100
|
+
import json
|
101
|
+
from codecs import getwriter
|
102
|
+
from typing import IO
|
103
|
+
|
104
|
+
def json_load_zip(fp: IO):
|
105
|
+
with ZipFileWrapper(fp, mode="r") as zip_file:
|
106
|
+
return json.load(zip_file)
|
107
|
+
|
108
|
+
inputfile = Path(inputfile)
|
109
|
+
if not inputfile.exists():
|
110
|
+
logging.error(_('File {0} does not exist').format(inputfile))
|
111
|
+
return
|
112
|
+
|
113
|
+
with open(inputfile, 'rb') as f:
|
114
|
+
data = json_load_zip(f) #json.load(f)
|
115
|
+
|
116
|
+
tmp_linked = data['linked']
|
117
|
+
if isinstance(tmp_linked, dict):
|
118
|
+
self.linked = {}
|
119
|
+
for curkey, curgroup in tmp_linked.items():
|
120
|
+
self.linked[curkey] = [(curlink[0], Wolfresults_2D if curlink[1] == 'CPU' else wolfres2DGPU) for curlink in curgroup]
|
121
|
+
|
122
|
+
tmp_values = data['values']
|
123
|
+
self.parts = {}
|
124
|
+
|
125
|
+
for cuzone, curparts in tmp_values.items():
|
126
|
+
self.parts[cuzone] = {}
|
127
|
+
|
128
|
+
for curproj, curdict in curparts.items():
|
129
|
+
self.parts[cuzone][curproj] = {}
|
130
|
+
for curpoly, curval in curdict.items():
|
131
|
+
self.parts[cuzone][curproj][curpoly] = {}
|
132
|
+
for curgroup, curarray in curval.items():
|
133
|
+
locdict = self.parts[cuzone][curproj][curpoly][curgroup] = {}
|
134
|
+
|
135
|
+
for cursim, curnparray in curarray.items():
|
136
|
+
locdict[cursim] = np.array([np.array([ tuple(lst1), np.array(lst2, dtype= np.int32)], dtype=object ) for lst1, lst2 in curnparray], dtype=object)
|
137
|
+
|
138
|
+
elif isinstance(tmp_linked, list):
|
139
|
+
self.linked = [(curlink[0], Wolfresults_2D if curlink[1] == 'CPU' else wolfres2DGPU) for curlink in tmp_linked]
|
140
|
+
|
141
|
+
tmp_values = data['values']
|
142
|
+
self.parts = {}
|
143
|
+
|
144
|
+
for cuzone, curparts in tmp_values.items():
|
145
|
+
self.parts[cuzone] = {}
|
146
|
+
|
147
|
+
for curpoly, curval in curparts.items():
|
148
|
+
self.parts[cuzone][curpoly] = {}
|
149
|
+
for curgroup, curarray in curval.items():
|
150
|
+
locdict = self.parts[cuzone][curpoly][curgroup] = {}
|
151
|
+
|
152
|
+
for cursim, curnparray in curarray.items():
|
153
|
+
locdict[cursim] = np.array([np.array([ tuple(lst1), np.array(lst2, dtype= np.int32)], dtype=object ) for lst1, lst2 in curnparray], dtype=object)
|
154
|
+
|
24
155
|
|
25
156
|
def find_values_inside_parts(self, linked_arrays):
|
26
157
|
"""
|
@@ -45,13 +176,14 @@ class Extracting_Zones(Zones):
|
|
45
176
|
|
46
177
|
self.linked = [(curlink.idx, type(curlink)) for curlink in linked_arrays]
|
47
178
|
|
179
|
+
self.parts = {}
|
48
180
|
for curzone in self.myzones:
|
49
|
-
|
50
181
|
if isinstance(linked_arrays, dict):
|
51
182
|
locparts = self.parts[curzone.myname] = {}
|
52
183
|
for curkey, curgroup in linked_arrays.items():
|
53
184
|
locparts[curkey] = curzone.get_all_values_linked_polygon(curgroup, key_idx_names='name', getxy=True)
|
54
|
-
|
185
|
+
|
186
|
+
elif isinstance(linked_arrays, list):
|
55
187
|
self.parts[curzone.myname] = curzone.get_all_values_linked_polygon(linked_arrays, key_idx_names='name', getxy=True)
|
56
188
|
|
57
189
|
def _get_heads(self,
|
@@ -228,6 +360,14 @@ class Extracting_Zones(Zones):
|
|
228
360
|
|
229
361
|
class Polygons_Analyze(Zones):
|
230
362
|
"""
|
363
|
+
Classe permettant de récupérer les valeurs à l'intérieur des polygones
|
364
|
+
définis dans la dernière zone d'une fichier .vecz.
|
365
|
+
|
366
|
+
Ce fichier est typiquement le résultat de la création de polygones
|
367
|
+
sur base de parallèles via l'interface graphique.
|
368
|
+
|
369
|
+
Utile notamment dans l'analyse de modélisations 2D (CPU et/ou GPU).
|
370
|
+
|
231
371
|
"""
|
232
372
|
|
233
373
|
def __init__(self, myfile='', ds:float=5., ox: float = 0, oy: float = 0, tx: float = 0, ty: float = 0, parent=None, is2D=True, wx_exists:bool = False):
|
@@ -235,13 +375,15 @@ class Polygons_Analyze(Zones):
|
|
235
375
|
|
236
376
|
self.myname = splitext(basename(myfile))[0]
|
237
377
|
|
238
|
-
self.linked =
|
378
|
+
self.linked:Union[dict,list] = None # type is depending on the type of linked arrays
|
379
|
+
self.river_values:dict = None
|
239
380
|
|
240
381
|
self.riverbed = self.get_zone(0).myvectors[1]
|
241
382
|
self.riverbed.prepare_shapely()
|
242
383
|
|
243
384
|
self.polygons_zone:zone
|
244
385
|
self.polygons_zone = self.get_zone(-1)
|
386
|
+
|
245
387
|
self.polygons_curvi = {}
|
246
388
|
for curvert in self.polygons_zone.myvectors:
|
247
389
|
self.polygons_curvi[curvert.myname] = curvert.myvertices[0].z
|
@@ -249,41 +391,130 @@ class Polygons_Analyze(Zones):
|
|
249
391
|
for vec in self.polygons_zone.myvectors:
|
250
392
|
vec.myprop.used=False # cache les polygones pour ne pas surcharger l'affichage éventuel
|
251
393
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
394
|
+
def cache_data(self, outputfile:str):
|
395
|
+
"""
|
396
|
+
Serialize the values in a json file -- zipped
|
397
|
+
"""
|
398
|
+
|
399
|
+
self._serialize_values(outputfile)
|
400
|
+
|
401
|
+
def load_data(self, inputfile:str):
|
402
|
+
"""
|
403
|
+
Deserialize the values from a json file -- zipped
|
404
|
+
"""
|
405
|
+
|
406
|
+
self._deserialize_values(inputfile)
|
257
407
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
408
|
+
def _serialize_values(self, outputfile:str):
|
409
|
+
"""
|
410
|
+
Serialize the values in a file
|
411
|
+
"""
|
412
|
+
|
413
|
+
import json
|
414
|
+
from codecs import getwriter
|
415
|
+
from typing import IO
|
416
|
+
|
417
|
+
class NumpyArrayEncoder(json.JSONEncoder):
|
418
|
+
def default(self, obj):
|
419
|
+
if isinstance(obj, np.integer):
|
420
|
+
return int(obj)
|
421
|
+
elif isinstance(obj, np.floating):
|
422
|
+
return float(obj)
|
423
|
+
elif isinstance(obj, np.ndarray):
|
424
|
+
return obj.tolist()
|
425
|
+
elif obj == Wolfresults_2D:
|
426
|
+
return 'CPU'
|
427
|
+
elif obj == wolfres2DGPU:
|
428
|
+
return 'GPU'
|
429
|
+
|
430
|
+
return json.JSONEncoder.default(self, obj)
|
431
|
+
|
432
|
+
def _json_dump_bytes(fp: IO, obj):
|
433
|
+
StreamWriter = getwriter("utf-8")
|
434
|
+
return json.dump(fp=StreamWriter(fp), obj=obj, cls=NumpyArrayEncoder, indent=4)
|
435
|
+
|
436
|
+
def json_dump_zip(fp: IO, obj):
|
437
|
+
with ZipFileWrapper(fp, mode="w", compression=ZIP_DEFLATED, compresslevel=9) as zip_file:
|
438
|
+
with zip_file.open(mode="w") as _fp:
|
439
|
+
_json_dump_bytes(fp=_fp, obj=obj)
|
440
|
+
|
441
|
+
|
442
|
+
with open(outputfile, 'wb') as f:
|
443
|
+
|
444
|
+
json_dump_zip(fp = f, obj = {'linked' : self.linked, 'values': self.river_values})
|
445
|
+
|
446
|
+
|
447
|
+
def _deserialize_values(self, inputfile:str):
|
448
|
+
"""
|
449
|
+
Deserialize the values from a file
|
450
|
+
"""
|
451
|
+
|
452
|
+
import json
|
453
|
+
from codecs import getwriter
|
454
|
+
from typing import IO
|
455
|
+
|
456
|
+
def json_load_zip(fp: IO):
|
457
|
+
with ZipFileWrapper(fp, mode="r") as zip_file:
|
458
|
+
return json.load(zip_file)
|
459
|
+
|
460
|
+
inputfile = Path(inputfile)
|
461
|
+
if not inputfile.exists():
|
462
|
+
logging.error(_('File {0} does not exist').format(inputfile))
|
463
|
+
return
|
464
|
+
|
465
|
+
with open(inputfile, 'rb') as f:
|
466
|
+
data = json_load_zip(f) #json.load(f)
|
467
|
+
|
468
|
+
tmp_linked = data['linked']
|
469
|
+
if isinstance(tmp_linked, dict):
|
470
|
+
self.linked = {}
|
471
|
+
for curkey, curgroup in tmp_linked.items():
|
472
|
+
self.linked[curkey] = [(curlink[0], Wolfresults_2D if curlink[1] == 'CPU' else wolfres2DGPU) for curlink in curgroup]
|
473
|
+
|
474
|
+
tmp_values = data['values']
|
475
|
+
self.river_values = {}
|
476
|
+
for curproj, curdict in tmp_values.items():
|
477
|
+
self.river_values[curproj] = {}
|
478
|
+
for curpoly, curval in curdict.items():
|
479
|
+
self.river_values[curproj][curpoly] = {}
|
480
|
+
for curgroup, curarray in curval.items():
|
481
|
+
locdict = self.river_values[curproj][curpoly][curgroup] = {}
|
482
|
+
|
483
|
+
for cursim, curnparray in curarray.items():
|
484
|
+
locdict[cursim] = np.array([np.array([ tuple(lst1), np.array(lst2, dtype= np.int32)], dtype=object ) for lst1, lst2 in curnparray], dtype=object)
|
485
|
+
|
486
|
+
elif isinstance(tmp_linked, list):
|
487
|
+
self.linked = [(curlink[0], Wolfresults_2D if curlink[1] == 'CPU' else wolfres2DGPU) for curlink in tmp_linked]
|
488
|
+
|
489
|
+
tmp_values = data['values']
|
490
|
+
self.river_values = {}
|
491
|
+
for curpoly, curval in tmp_values.items():
|
492
|
+
self.river_values[curpoly] = {}
|
493
|
+
for curgroup, curarray in curval.items():
|
494
|
+
locdict = self.river_values[curpoly][curgroup] = {}
|
495
|
+
|
496
|
+
for cursim, curnparray in curarray.items():
|
497
|
+
locdict[cursim] = np.array([np.array([ tuple(lst1), np.array(lst2, dtype= np.int32)], dtype=object ) for lst1, lst2 in curnparray], dtype=object)
|
263
498
|
|
264
|
-
# def withdrawal(self):
|
265
|
-
# """
|
266
|
-
# Mise en retrait
|
267
|
-
# """
|
268
|
-
# self.centralpart.withdrawal()
|
269
499
|
|
270
500
|
def compute_distance(self, poly:LineString):
|
271
501
|
"""
|
272
502
|
Compute the curvilinear distance along a support polyline
|
273
503
|
"""
|
504
|
+
|
274
505
|
for curvert in self.polygons_zone.myvectors:
|
506
|
+
# Centre du polygone
|
275
507
|
centerx = np.sum(np.asarray([cur.x for cur in curvert.myvertices[:4]]))/4.
|
276
508
|
centery = np.sum(np.asarray([cur.y for cur in curvert.myvertices[:4]]))/4.
|
509
|
+
|
277
510
|
self.polygons_curvi[curvert.myname] = poly.project(Point([centerx,centery]))
|
278
511
|
|
279
|
-
def find_values_inside_parts(self, linked_arrays,
|
512
|
+
def find_values_inside_parts(self, linked_arrays:Union[dict,list]):
|
280
513
|
"""
|
281
|
-
Récupère les valeurs à l'intérieur
|
282
|
-
- des parties du pont (amont, centrale, aval)
|
283
|
-
- de la discrétisation rivière en polygones
|
514
|
+
Récupère les valeurs à l'intérieur des polygones - dernière zone du fichier
|
284
515
|
|
285
|
-
|
286
|
-
- dictionnaire dont la clé est le nom (ou l'index) du polygone dans la zone
|
516
|
+
Stockage :
|
517
|
+
- dictionnaire dont la clé est le nom (ou l'index) du polygone dans la zone
|
287
518
|
- chaque entrée est un dictionnaire dont la clé 'values' contient un dictionnaire pour chaque matrice du projet
|
288
519
|
- chaque élément de ce sous-dictionnaire est un tuple contenant toutes les valeurs utiles
|
289
520
|
|
@@ -292,11 +523,17 @@ class Polygons_Analyze(Zones):
|
|
292
523
|
***
|
293
524
|
|
294
525
|
"""
|
295
|
-
|
526
|
+
|
527
|
+
if isinstance(linked_arrays, dict):
|
528
|
+
|
296
529
|
self.linked={}
|
297
530
|
|
298
|
-
|
299
|
-
|
531
|
+
for curkey, curgroup in linked_arrays.items():
|
532
|
+
self.linked[curkey] = [(curlink.idx, type(curlink)) for curlink in curgroup]
|
533
|
+
|
534
|
+
elif isinstance(linked_arrays, list):
|
535
|
+
|
536
|
+
self.linked = [(curlink.idx, type(curlink)) for curlink in linked_arrays]
|
300
537
|
|
301
538
|
# récupération des valeurs danbs les polygones "rivière"
|
302
539
|
curzone = self.polygons_zone
|
@@ -305,12 +542,15 @@ class Polygons_Analyze(Zones):
|
|
305
542
|
self.river_values={}
|
306
543
|
for curkey, curgroup in linked_arrays.items():
|
307
544
|
self.river_values[curkey] = curzone.get_all_values_linked_polygon(curgroup, key_idx_names='name')
|
545
|
+
|
308
546
|
elif isinstance(linked_arrays, list):
|
547
|
+
|
309
548
|
self.river_values = curzone.get_all_values_linked_polygon(linked_arrays, key_idx_names='name')
|
310
549
|
|
311
550
|
def _get_river_heads(self,
|
312
551
|
which_group=None):
|
313
552
|
"""Compute Head"""
|
553
|
+
|
314
554
|
head = {}
|
315
555
|
|
316
556
|
z = self.get_river_values(stored_values_unk.WATERLEVEL, which_group)
|
@@ -403,6 +643,11 @@ class Polygons_Analyze(Zones):
|
|
403
643
|
which_value:Union[stored_values_unk,stored_values_pos],
|
404
644
|
which_group=None,
|
405
645
|
operator:operators=operators.MEDIAN) -> dict:
|
646
|
+
"""
|
647
|
+
Get values for the river polygons with an operator
|
648
|
+
|
649
|
+
operator : MEDIAN, MIN, MAX, PERCENTILE95, PERCENTILE5, ALL
|
650
|
+
"""
|
406
651
|
|
407
652
|
def extract_info(vals):
|
408
653
|
vals_ret={}
|
@@ -440,6 +685,32 @@ class Polygons_Analyze(Zones):
|
|
440
685
|
|
441
686
|
return vals_ret
|
442
687
|
|
688
|
+
def get_s_values(self,
|
689
|
+
which_value:Union[stored_values_unk,stored_values_pos]=stored_values_unk.WATERLEVEL,
|
690
|
+
which_group:str=None,
|
691
|
+
which_sim:str=None,
|
692
|
+
operator:operators=operators.MEDIAN):
|
693
|
+
""" Get the values of the river polygons for a specific simulation """
|
694
|
+
|
695
|
+
s=[]
|
696
|
+
val=[]
|
697
|
+
|
698
|
+
myval = self.get_river_values_op(which_value, which_group, operator)
|
699
|
+
|
700
|
+
for curkey, curval in myval.items():
|
701
|
+
if len(curval)>0 and which_sim in curval.keys():
|
702
|
+
val.append(curval[which_sim])
|
703
|
+
s.append(self.polygons_curvi[curkey])
|
704
|
+
|
705
|
+
# Tri des valeurs selon l'absisse curviligne
|
706
|
+
ret = sorted(zip(s, val))
|
707
|
+
|
708
|
+
# Séparation des listes triées
|
709
|
+
s, val = zip(*ret)
|
710
|
+
|
711
|
+
return s, val
|
712
|
+
|
713
|
+
|
443
714
|
def plot_unk(self,
|
444
715
|
figax = None,
|
445
716
|
which_value:Union[stored_values_unk,stored_values_pos]=stored_values_unk.WATERLEVEL,
|
@@ -448,6 +719,7 @@ class Polygons_Analyze(Zones):
|
|
448
719
|
options:dict=None,
|
449
720
|
label=True,
|
450
721
|
show=False):
|
722
|
+
""" Plot the values of the river polygons """
|
451
723
|
|
452
724
|
if figax is None:
|
453
725
|
fig,ax = plt.subplots(1,1)
|
@@ -528,6 +800,7 @@ class Polygons_Analyze(Zones):
|
|
528
800
|
which_group=None,
|
529
801
|
operator:operators=operators.MEDIAN,
|
530
802
|
show=False):
|
803
|
+
""" Plot the waterline """
|
531
804
|
|
532
805
|
fig,ax = self.plot_unk(figax, stored_values_unk.TOPOGRAPHY, which_group, operator, options={'color':'black', 'linewidth':2}, label=False, show=False)
|
533
806
|
figax=(fig,ax)
|
@@ -547,6 +820,7 @@ class Polygons_Analyze(Zones):
|
|
547
820
|
which_group=None,
|
548
821
|
operator:operators=operators.MEDIAN,
|
549
822
|
show=False):
|
823
|
+
""" Plot the bed elevation """
|
550
824
|
|
551
825
|
fig,ax = self.plot_unk(figax, stored_values_unk.TOPOGRAPHY, which_group, operator, options={'color':'black', 'linewidth':2}, label=False, show=False)
|
552
826
|
|
@@ -563,6 +837,7 @@ class Polygons_Analyze(Zones):
|
|
563
837
|
which_group=None,
|
564
838
|
operator:operators=operators.MEDIAN,
|
565
839
|
show=False):
|
840
|
+
""" Plot the water stage /water level """
|
566
841
|
|
567
842
|
fig,ax = self.plot_unk(figax, stored_values_unk.WATERLEVEL, which_group, operator, options={'color':'blue', 'linewidth':2}, show=False)
|
568
843
|
|
@@ -579,6 +854,7 @@ class Polygons_Analyze(Zones):
|
|
579
854
|
which_group=None,
|
580
855
|
operator:operators=operators.MEDIAN,
|
581
856
|
show=False):
|
857
|
+
""" Plot the water head """
|
582
858
|
|
583
859
|
fig,ax = self.plot_unk(figax, stored_values_unk.HEAD, which_group, operator, options={'color':'blue', 'linewidth':2}, show=False)
|
584
860
|
|
@@ -11,7 +11,7 @@ wolfhece/PyGui.py,sha256=VKE785z9XLIWNbxqpyEceLK_wtmPJyq6A_M_qX_94Lg,104772
|
|
11
11
|
wolfhece/PyGuiHydrology.py,sha256=wKhR-KthPRyzJ887NmsozmUpm2CIQIwO3IbYORCYjrE,7290
|
12
12
|
wolfhece/PyHydrographs.py,sha256=GKK8U0byI45H9O_e4LAOOi7Aw0Tg7Q0Lx322stPg5IQ,3453
|
13
13
|
wolfhece/PyPalette.py,sha256=_Nm2Lc4UxYlZgK8ifZDioG8a0at8oiteYC0x_4XugFc,24384
|
14
|
-
wolfhece/PyParams.py,sha256=
|
14
|
+
wolfhece/PyParams.py,sha256=963fkDSEadlLLxe7WM4Nl6nLOeZsOWSFmfg7hIsWPU4,96785
|
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
|
@@ -34,13 +34,13 @@ wolfhece/import_ascfiles.py,sha256=jg4urcLdSgFS1Knvh7AVGJqM44qc_uYDNrR568tMh-A,4
|
|
34
34
|
wolfhece/ins.py,sha256=0aU1mo4tYbw64Gwzrqbh-NCTH1tukmk0mpPHjRPHZXU,12661
|
35
35
|
wolfhece/irm_qdf.py,sha256=749SlAXiN1oXp5tfBJoPNJWxydQlY55K0qvIM5YexlM,15436
|
36
36
|
wolfhece/ismember.py,sha256=fkLvaH9fhx-p0QrlEzqa6ySO-ios3ysjAgXVXzLgSpY,2482
|
37
|
-
wolfhece/multiprojects.py,sha256=
|
37
|
+
wolfhece/multiprojects.py,sha256=tHrAdOBoEEsuNS8hV7udbvduOZLj_NqF3ee5hSDBhN8,20903
|
38
38
|
wolfhece/picc.py,sha256=KKPNk1BEe7QBzo2icIsdsxUopJ1LXYTomfdfeG2gCeA,7419
|
39
39
|
wolfhece/pyGui1D.py,sha256=pzLWXQ_w3Y_yI846w1GklFO9h5lWZOqiUzg1BUPkuRI,121616
|
40
|
-
wolfhece/pybridges.py,sha256=
|
40
|
+
wolfhece/pybridges.py,sha256=4PRSsWngDmQnlVuN2tJj0C_HT1h47ExH9QTUPs_Wxlg,57215
|
41
41
|
wolfhece/pydike.py,sha256=G4jfSZaAHHr4VWEJqnXSvEswXvlOz1yhbhQ6uu3AqyM,1943
|
42
42
|
wolfhece/pylogging.py,sha256=i9Zugx3t9dPc7nBwcP20L_R4_k_WawpAQsvbZU8l9Hg,4230
|
43
|
-
wolfhece/pypolygons_scen.py,sha256=
|
43
|
+
wolfhece/pypolygons_scen.py,sha256=Zqr_vs--QEKRSxG-SfduqSR0aPT5rM3BRxmXTOSh2Iw,37146
|
44
44
|
wolfhece/pyshields.py,sha256=YS6VVjjzoA-ZR6YRccqjMcW3McNqNLoQODC6TNNkmPw,22983
|
45
45
|
wolfhece/pyviews.py,sha256=hYdyrEvWF48dGBDOLIwmC28C0L8I28U4ohXk9nltF94,9666
|
46
46
|
wolfhece/pywalous.py,sha256=GRS5TKoVT0J-3PBqMdlyFRHrqkdYC-uHgDPcMjoDEZw,18674
|
@@ -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=
|
69
|
+
wolfhece/apps/version.py,sha256=PDHOsWyysK2-MjO9X84FVTmdBAJq_uSXODfI01muO7E,387
|
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
|
@@ -264,8 +264,8 @@ wolfhece/sounds/sonsw2.wav,sha256=pFLVt6By0_EPQNt_3KfEZ9a1uSuYTgQSX1I_Zurv9Rc,11
|
|
264
264
|
wolfhece/ui/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
265
265
|
wolfhece/ui/wolf_multiselection_collapsiblepane.py,sha256=yGbU_JsF56jsmms0gh7mxa7tbNQ_SxqhpAZxhm-mTy4,14860
|
266
266
|
wolfhece/ui/wolf_times_selection_comparison_models.py,sha256=wCxGRnE3kzEkWlWA6-3X8ADOFux_B0a5QWJ2GnXTgJw,4709
|
267
|
-
wolfhece-2.1.
|
268
|
-
wolfhece-2.1.
|
269
|
-
wolfhece-2.1.
|
270
|
-
wolfhece-2.1.
|
271
|
-
wolfhece-2.1.
|
267
|
+
wolfhece-2.1.8.dist-info/METADATA,sha256=na4Fmpn_XCY_8wAgiMs1m3YfEMKwUNC7mZ33W2JzU70,2281
|
268
|
+
wolfhece-2.1.8.dist-info/WHEEL,sha256=cpQTJ5IWu9CdaPViMhC9YzF8gZuS5-vlfoFihTBC86A,91
|
269
|
+
wolfhece-2.1.8.dist-info/entry_points.txt,sha256=AIu1KMswrdsqNq_2jPtrRIU4tLjuTnj2dCY-pxIlshw,276
|
270
|
+
wolfhece-2.1.8.dist-info/top_level.txt,sha256=EfqZXMVCn7eILUzx9xsEu2oBbSo9liWPFWjIHik0iCI,9
|
271
|
+
wolfhece-2.1.8.dist-info/RECORD,,
|
File without changes
|
File without changes
|