wolfhece 2.2.17__py3-none-any.whl → 2.2.20__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/pydike.py CHANGED
@@ -10,63 +10,267 @@ copying or distribution of this file, via any medium, is strictly prohibited.
10
10
 
11
11
  import logging
12
12
 
13
+ import numpy as np
14
+ from shapely.geometry import Point, LineString
15
+
16
+ from.drawing_obj import Element_To_Draw
13
17
  from .PyVertexvectors import Triangulation, vector,Zones, zone
18
+ from .wolf_array import WolfArray, header_wolf
19
+
20
+ class SyntheticDike(Element_To_Draw):
21
+ """ Dike class for synthetic dikes based on a trace vector, width of the crest and lateral slopes.
22
+ """
23
+
24
+ def __init__(self, idx:str = '', plotted:bool = True, mapviewer = None, need_for_wx:bool = False):
25
+
26
+ super().__init__(idx, plotted, mapviewer, need_for_wx)
27
+
28
+ self._triangulation = None
29
+ self._zones = Zones()
30
+ newzone = zone(name='dike')
31
+
32
+ self._zones.add_zone(newzone, forceparent=True)
33
+
34
+ @property
35
+ def triangulation(self) -> Triangulation:
36
+ """ Return the triangulation of the dike """
37
+ return self._triangulation
38
+
39
+ @property
40
+ def zones(self) -> Zones:
41
+ """ Return the zones of the dike """
42
+ return self._zones
43
+
44
+ def create_from_slopes(self, trace:vector,
45
+ slope_up:float, slope_down:float,
46
+ width_up:float, width_down:float,
47
+ zmin:float, zmax:float, ds:float):
48
+
49
+ """ Create the dike triangulation based on the trace vector and the width of the dike.
50
+
51
+ :param trace: Trace vector of the dike
52
+ :param slope_up: Slope of the dike on the upstream side [slope = dz/dx]
53
+ :param slope_down: Slope of the dike on the downstream side [slope = dz/dx]
54
+ :param width_up: Width of the dike on the upstream side [m]
55
+ :param width_down: Width of the dike on the downstream side [m]
56
+ :param zmin: Minimum elevation of the dike [m]
57
+ :param zmax: Maximum elevation of the dike [m]
58
+ :param ds: Distance for rebinning [m]
59
+ """
60
+
61
+ assert ds > 0.0, "Distance for rebinning must be positive"
62
+ assert slope_up > 0.0, "Slope must be positive"
63
+ assert slope_down > 0.0, "Slope must be positive"
64
+ assert width_up >= 0.0, "Width must be positive"
65
+ assert width_down >= 0.0, "Width must be positive"
66
+ assert zmin < zmax, "zmin must be less than zmax"
67
+
68
+ myzone = self._zones.myzones[0]
69
+ myzone.myvectors = []
70
+
71
+ # Impose altimetry of the crest
72
+ trace.z = zmax
73
+
74
+ # add the trace vector to the zone
75
+ myzone.add_vector(trace, forceparent=True)
76
+
77
+ # CREST of the dike
78
+ # create parallel vectors to the trace vector - right and left
79
+
80
+ if width_up > 0.0:
81
+ distances_up = list(np.linspace(0, width_up, int(width_up/ds)+1, endpoint=True))[1:]
82
+ for curds in distances_up:
83
+ # create a new vector parallel to the trace vector
84
+ parup = trace.parallel_offset(curds, 'right')
85
+ myzone.add_vector(parup, 0, forceparent=True)
86
+ # impose altimetry of the dike
87
+ parup.z = zmax
88
+ else:
89
+ # no width on the upstream side -> use the trace vector
90
+ parup = trace
91
+
92
+ if width_down > 0.0:
93
+ distances_down = list(np.linspace(0, width_down, int(width_down/ds)+1, endpoint=True))[1:]
94
+ for curds in distances_down:
95
+ pardown = trace.parallel_offset(curds, 'left')
96
+ myzone.add_vector(pardown, forceparent=True)
97
+ # impose altimetry of the dike
98
+ pardown.z = zmax
99
+ else:
100
+ # no width on the downstream side -> use the trace vector
101
+ pardown = trace
102
+
103
+ # distances to the crest
104
+ distances_up = (zmax-zmin) / slope_up
105
+ distances_up = list(np.linspace(0, distances_up, int(distances_up/ds)+1, endpoint=True))[1:]
106
+ # distances_up.reverse()
107
+ # iterate over the distup basd on ds
108
+ for curds in distances_up:
109
+ # create a new vector parallel to the trace vector
110
+ parup_new = parup.parallel_offset(curds, 'right')
111
+ myzone.add_vector(parup_new, 0, forceparent=True)
112
+ # impose altimetry of the dike
113
+ parup_new.z = zmax - slope_up * curds
114
+
115
+ distances_down = (zmax-zmin) / slope_down
116
+ distances_down = list(np.linspace(0, distances_down, int(distances_down/ds)+1, endpoint=True))[1:]
117
+ for curds in distances_down:
118
+ pardown_new = pardown.parallel_offset(curds, 'left')
119
+ myzone.add_vector(pardown_new, forceparent=True) # append
120
+ # impose altimetry of the dike
121
+ pardown_new.z = zmax - slope_down * curds
122
+
123
+ # on dispose de multiples vecteurs dans la zone, orientés de l'amont vers l'aval
124
+ trace.update_lengths()
125
+
126
+ nb_along_trace = int(trace.length3D / ds) # nombre de points sur la trace
127
+
128
+ self._triangulation = myzone.create_multibin(nb_along_trace)
129
+
130
+ def create_from_shape(self, trace:vector, shape:vector, ds:float):
131
+ """ create the dike triangulation based on the trace vector and the shape vector
132
+
133
+ :param trace: Trace vector of the dike
134
+ :param shape: Transversal shape of the dike in (s,z) coordinates, s=0.0 is on the trace vector, elevations are relative to the trace vector
135
+ :param ds: Distance for rebinning [m]
136
+ """
137
+
138
+ myzone = self._zones.myzones[0]
139
+ myzone.myvectors = []
140
+
141
+ # add the trace vector to the zone
142
+ myzone.add_vector(trace, forceparent=True)
143
+
144
+ # get the shapely linestring of the trace -> projection
145
+ ref_ls = trace.linestring
146
+
147
+ # Create parallels of the crest according to the shape vector
148
+ # -----------------------------------------------------------
149
+
150
+ # get coordinates of the shape vector
151
+ shape_vertices = shape.xy
152
+
153
+ # Separate the upstream and downstream vertices
154
+ up_vertices = shape_vertices[shape_vertices[:, 0] > 0.0]
155
+ down_vertices = shape_vertices[shape_vertices[:, 0] < 0.0]
156
+
157
+ # reverse the order of downstream vertices
158
+ down_vertices = down_vertices[::-1]
159
+
160
+ # Altitude au droit de la trace
161
+ z_shape_trace = shape_vertices[shape_vertices[:, 0] == 0.0][0][1]
162
+
163
+ # UPSTREAM PART
164
+
165
+ # Loop over the upstream vertices
166
+ z_previous = z_shape_trace
167
+ s_previous = 0.0
168
+ distance_cum = 0.0 # useful for the cumulated distance -> parallel offset
169
+ for cur_sz in up_vertices:
170
+
171
+ ds_loc = cur_sz[0] - s_previous # distance between the two points in the shape
172
+ slope_loc = (z_previous - cur_sz[1]) / ds_loc # local slope of the shape
173
+
174
+ # rebin the distance
175
+ distances_up = list(np.linspace(0, ds_loc, int(ds_loc/ds)+1, endpoint=True))[1:]
176
+
177
+ deltaz_cum = 0.0 # Cumulated elevation difference
178
+
179
+ # iterate over the distup basd on ds
180
+ for curds in distances_up:
181
+ # create a new vector parallel to the trace vector
182
+ # need to add the cumulated distance to the current distance as we
183
+ parup = trace.parallel_offset(curds + distance_cum, 'right')
184
+
185
+ if parup is None:
186
+ logging.warning("No parallel vector found for distance %f", curds + distance_cum)
187
+ continue
188
+
189
+ myzone.add_vector(parup, 0, forceparent=True)
190
+
191
+ # local delta elevation
192
+ deltaz_loc = -slope_loc * curds - deltaz_cum # local difference
193
+
194
+ parup_z = []
195
+
196
+ # we need to interpolate the elevation according to the trace
197
+
198
+ # Iterate over the vertices
199
+ for vert in parup.myvertices:
200
+ # project the vertex on the previous trace
201
+ proj = ref_ls.project(Point(vert.x, vert.y), normalized=True)
202
+ # get the elevation of the trace at the projection point
203
+ z_loc = ref_ls.interpolate(proj, normalized= True).z
204
+ # add the local delta elevation
205
+ z_loc += deltaz_loc
206
+ parup_z.append(z_loc)
207
+
208
+ parup.z = parup_z
209
+ ref_ls = parup.linestring
210
+ deltaz_cum += deltaz_loc
211
+ z_previous = cur_sz[1]
212
+ s_previous = cur_sz[0] # update the elevation of the trace
213
+
214
+ distance_cum += distances_up[-1] # cumulate the distance
14
215
 
15
- class Dike(Triangulation,Zones):
216
+ # create downstream
217
+ ref_ls = trace.linestring
16
218
 
17
- def __init__(self, trace:vector, width:float, slopeup:float, slopedown:float, fn='', pts=..., tri=..., idx: str = '', plotted: bool = True, mapviewer=None, need_for_wx: bool = False) -> None:
219
+ z_previous = z_shape_trace
220
+ s_previous = 0.0
221
+ distance_cum = 0.0
222
+ # Loop over the downstream vertices
223
+ for cur_sz in down_vertices:
18
224
 
19
- super().__init__(fn, pts, tri, idx, plotted, mapviewer, need_for_wx)
225
+ ds_loc = -(cur_sz[0] - s_previous)
226
+ slope_loc = (z_previous - cur_sz[1]) / ds_loc
20
227
 
21
- self.slopeup = slopeup
22
- self.slopedown = slopedown
23
- self.width = width
24
- self.trace = trace
228
+ # rebin the distance
229
+ distances_down = list(np.linspace(0, ds_loc, int(ds_loc/ds)+1, endpoint=True))[1:]
25
230
 
26
- newzone = zone(name='dike',parent=self)
27
- self.add_zone(newzone)
28
- newzone.add_vector(trace)
231
+ deltaz_cum = 0.0
29
232
 
30
- def create(self,zmin,zmax,ds):
233
+ # iterate over the distup basd on ds
234
+ for curds in distances_down:
235
+ pardown = trace.parallel_offset(curds + distance_cum, 'left')
31
236
 
32
- myzone:zone
33
- myzone = self.myzones[0]
237
+ if pardown is None:
238
+ logging.warning("No parallel vector found for distance %f", curds + distance_cum)
239
+ continue
34
240
 
35
- parright = self.trace.parallel_offset(self.width/2.,'right')
36
- parleft = self.trace.parallel_offset(self.width/2.,'left')
241
+ myzone.add_vector(pardown, forceparent=True)
37
242
 
38
- myzone.add_vector(parright)
39
- myzone.add_vector(parleft,0)
243
+ # impose local elevation
244
+ deltaz_loc = -slope_loc * curds - deltaz_cum # local difference
40
245
 
41
- allpar = [parright,parleft, self.trace]
42
- for curpar in allpar:
43
- for curv in curpar.myvertices:
44
- curv.z=zmax
246
+ pardown_z = []
247
+ # we need to interpolate the elevation according to the trace
248
+ for vert in pardown.myvertices:
249
+ # project the vertex on the trace
250
+ proj = ref_ls.project(Point(vert.x, vert.y), normalized=True)
251
+ # get the elevation of the trace at the projection point
252
+ z_loc = ref_ls.interpolate(proj, normalized= True).z
253
+ # add the local delta elevation
254
+ z_loc += deltaz_loc
255
+ pardown_z.append(z_loc)
45
256
 
46
- distup = (zmax-zmin)/self.slopeup
47
- parup = parright.parallel_offset(distup,'right')
257
+ # impose the elevation
258
+ pardown.z = pardown_z
259
+ ref_ls = pardown.linestring
260
+ deltaz_cum += deltaz_loc
261
+ z_previous =cur_sz[1] # update the elevation of the trace
262
+ s_previous = cur_sz[0]
48
263
 
49
- distdown = (zmax-zmin)/self.slopedown
50
- pardown = parleft.parallel_offset(distdown,'left')
264
+ distance_cum += distances_down[-1]
51
265
 
52
- myzone.add_vector(parup)
53
- myzone.add_vector(pardown,0)
266
+ # on dispose de multiples vecteurs dans la zone, orientés de l'amont vers l'aval
267
+ trace.update_lengths()
54
268
 
55
- allpar = [parup,pardown]
56
- for curpar in allpar:
57
- for curv in curpar.myvertices:
58
- curv.z=zmin
269
+ nb_along_trace = int(trace.length3D / ds) # nombre de points sur la trace
59
270
 
60
- # on dispose de 5 vecteurs dans la zone, orientés de l'aval vers l'amont
271
+ self._triangulation = myzone.create_multibin(nb_along_trace)
61
272
 
62
- self.trace.update_lengths()
63
- nb = int(self.trace.length3D/ds)
64
- nb2 = int(max(distup,distdown)/ds)
273
+ for curvect in myzone.myvectors:
274
+ curvect.reset_linestring()
65
275
 
66
- mytri = myzone.create_multibin(nb,nb2)
67
- self.tri = mytri.tri
68
- self.pts = mytri.pts
69
- self.nb_pts = mytri.nb_pts
70
- self.nb_tri = mytri.nb_tri
71
276
 
72
- pass
@@ -1272,6 +1272,11 @@ class Config_Manager_2D_GPU:
1272
1272
  if ret != '':
1273
1273
  logging.warning(ret)
1274
1274
 
1275
+ bridge_deck.nullvalue = 99999.
1276
+ bridge_roof.nullvalue = 99999.
1277
+ bridge_deck.mask_data(99999.)
1278
+ bridge_roof.mask_data(99999.)
1279
+
1275
1280
  return ret
1276
1281
 
1277
1282
  def create_simulation(self,
@@ -1389,9 +1394,13 @@ class Config_Manager_2D_GPU:
1389
1394
  logging.error(_('Roof .tif must be a full single array ! -- The array will be ignored !'))
1390
1395
  roof = WolfArray(srcheader=bat.get_header(), whichtype= WOLF_ARRAY_FULL_SINGLE)
1391
1396
  roof.array.data[:,:] = 99999.
1397
+ roof.nullvalue = 99999.
1398
+ roof.nbnotnull = 0
1392
1399
  else:
1393
1400
  roof = WolfArray(srcheader=bat.get_header(), whichtype= WOLF_ARRAY_FULL_SINGLE)
1394
1401
  roof.array.data[:,:] = 99999.
1402
+ roof.nullvalue = 99999.
1403
+ roof.nbnotnull = 0
1395
1404
 
1396
1405
  # check for deck
1397
1406
  if exists(dir / '__deck.tif'):
@@ -1400,9 +1409,13 @@ class Config_Manager_2D_GPU:
1400
1409
  logging.error(_('Deck .tif must be a full single array ! -- The array will be ignored !'))
1401
1410
  deck = WolfArray(srcheader=bat.get_header(), whichtype= WOLF_ARRAY_FULL_SINGLE)
1402
1411
  deck.array.data[:,:] = 99999.
1412
+ deck.nullvalue = 99999.
1413
+ deck.nbnotnull = 0
1403
1414
  else:
1404
1415
  deck = WolfArray(srcheader=bat.get_header(), whichtype= WOLF_ARRAY_FULL_SINGLE)
1405
1416
  deck.array.data[:,:] = 99999.
1417
+ deck.nullvalue = 99999.
1418
+ deck.nbnotnull = 0
1406
1419
 
1407
1420
  # applying Python scrpitps on ARRAYS
1408
1421
  self._apply_scripts_update_topo_maning_inf_roof_deck(dir, bat, man, infiltration, roof, deck)
wolfhece/tools2d_dll.py CHANGED
@@ -5,6 +5,12 @@ import logging
5
5
 
6
6
  from .wolf_array import header_wolf, getkeyblock
7
7
 
8
+ from .os_check import isWindows
9
+
10
+ # Check if the platform is Windows
11
+ if not isWindows():
12
+ raise OSError("This module is only compatible with Windows.")
13
+
8
14
  try:
9
15
  import pefile
10
16
  except ImportError: