wolfhece 2.2.29__py3-none-any.whl → 2.2.31__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/pyshields.py CHANGED
@@ -19,6 +19,7 @@ from .friction_law import f_barr_bathurst, f_colebrook, f_colebrook_pure
19
19
 
20
20
  RHO_PUREWATER = 1000. # kg/m3
21
21
  RHO_SEAWATER = 1025. # kg/m3
22
+ RHO_SEDIMENT = 2650. # kg/m3
22
23
  KIN_VISCOSITY = 1.e-6 # m2/s
23
24
  GRAVITY = 9.81 # m/s2
24
25
 
@@ -90,7 +91,7 @@ Autres :
90
91
 
91
92
  """
92
93
 
93
- def get_sadim(d:float, rhom:float =2650., rho:float =RHO_PUREWATER) -> float:
94
+ def get_sadim(d:float, rhom:float = RHO_SEDIMENT, rho:float =RHO_PUREWATER) -> float:
94
95
  """
95
96
  s_adim = d**(3/2) * ((s-1) * g)**.5 / (4 * nu)
96
97
 
@@ -99,7 +100,7 @@ def get_sadim(d:float, rhom:float =2650., rho:float =RHO_PUREWATER) -> float:
99
100
  s=rhom/rho
100
101
  return d**(3./2.) * ((s-1) * GRAVITY)**.5 / (4 * KIN_VISCOSITY)
101
102
 
102
- def get_dstar(d:float, rhom:float =2650., rho:float=RHO_PUREWATER) -> float:
103
+ def get_dstar(d:float, rhom:float = RHO_SEDIMENT, rho:float=RHO_PUREWATER) -> float:
103
104
  """ compute d* """
104
105
  s = rhom/rho
105
106
  return d*(GRAVITY*(s-1)/KIN_VISCOSITY**2)**(1./3.) #VanRijn Formula
@@ -110,7 +111,7 @@ def sadim2dstar(sadim:float) -> float:
110
111
  def dstar2sadim(dstar:float) -> float:
111
112
  return dstar**(3./2.) / 4
112
113
 
113
- def get_d_from_sadim(sadim:float, rhom:float=2650., rho:float=RHO_PUREWATER) -> float:
114
+ def get_d_from_sadim(sadim:float, rhom:float= RHO_SEDIMENT, rho:float=RHO_PUREWATER) -> float:
114
115
  """
115
116
  s_adim = d**(3/2) * ((s-1) * g)**.5 / (4 * nu)
116
117
 
@@ -119,7 +120,7 @@ def get_d_from_sadim(sadim:float, rhom:float=2650., rho:float=RHO_PUREWATER) ->
119
120
  s=rhom/rho
120
121
  return (sadim*(4*KIN_VISCOSITY)/math.sqrt((s-1)*GRAVITY))**(2/3)
121
122
 
122
- def get_d_from_dstar(dstar:float, rhom:float=2650., rho:float=RHO_PUREWATER) -> float:
123
+ def get_d_from_dstar(dstar:float, rhom:float= RHO_SEDIMENT, rho:float=RHO_PUREWATER) -> float:
123
124
  """
124
125
  d_star = d * (g * (s-1) / nu**2)**(1/3)
125
126
 
@@ -166,26 +167,38 @@ def get_psi_cr3(dstar:float) -> float:
166
167
  psicr = 0.13*dstar**-0.392*math.exp(-0.015*dstar**2.)+0.045*(1-math.exp(-0.068*dstar))
167
168
  return psicr
168
169
 
169
- # def get_shields_cr(d, rhom=2650., rho=RHO_PUREWATER, which=2):
170
- # """
171
- # Example:
172
- # [critical_shear_velocity, tau_cr,xadim_val, psicr] = get_shields_cr(0.2E-3, 2650)
173
- # """
170
+ def get_shields_cr(d, rhom = RHO_SEDIMENT, rho = RHO_PUREWATER, which=2):
171
+ """
172
+ :param d: grain diameter [m]
173
+ :param rhom: sediment density [kg/m3]
174
+ :param rho: water density [kg/m3]
175
+ :param which: which formula to use (default 2) -- see funcs = [(get_sadim, get_psi_cr), (get_dstar, get_psi_cr2), (get_dstar, get_psi_cr3)]
176
+
177
+ :return: [critical_shear_velocity, tau_cr, xadim_val, psicr]
178
+
179
+ Example:
180
+ [critical_shear_velocity, tau_cr, xadim_val, psicr] = get_shields_cr(0.2E-3, 2650)
181
+ """
182
+
183
+ assert which in [0, 1, 2], "which must be 0, 1 or 2"
174
184
 
175
- # funcs = [(get_sadim,get_psi_cr),(get_dstar,get_psi_cr2),(get_dstar,get_psi_cr3)]
176
- # # % Getting the sediment-fluid parameter
177
- # s = rhom/rho # [-]
178
- # denom_shields= (s-1)*GRAVITY*d # [m²/s²] en réalité denom/rho
185
+ funcs = [(get_sadim,get_psi_cr),
186
+ (get_dstar,get_psi_cr2),
187
+ (get_dstar,get_psi_cr3)]
179
188
 
180
- # xadim_val = funcs[which][0](d,rhom,rho)
181
- # psicr = funcs[which][1](xadim_val)
189
+ # % Getting the sediment-fluid parameter
190
+ s = rhom/rho # [-]
191
+ denom_shields= (s-1)*GRAVITY*d # [m²/s²] en réalité denom/rho
182
192
 
183
- # # Using the critical value of Shields parameter
184
- # # Knowing the maximum bottom shear stress
185
- # tau_cr = rho * denom_shields * psicr # Pa
186
- # critical_shear_velocity = math.sqrt(denom_shields * psicr) # m/s
193
+ xadim_val = funcs[which][0](d,rhom,rho)
194
+ psicr = funcs[which][1](xadim_val)
187
195
 
188
- # return [critical_shear_velocity, tau_cr,xadim_val, psicr]
196
+ # Using the critical value of Shields parameter
197
+ # Knowing the maximum bottom shear stress
198
+ tau_cr = rho * denom_shields * psicr # Pa
199
+ critical_shear_velocity = math.sqrt(denom_shields * psicr) # m/s
200
+
201
+ return [critical_shear_velocity, tau_cr, xadim_val, psicr]
189
202
 
190
203
  def _poly(x:float) -> float:
191
204
  return ((0.002235*x**5)-(0.06043*x**4)+(0.20307*x**3)+ \
@@ -204,7 +217,7 @@ def get_tau_from_psiadim(psiadim, d:float, rhom:float=2650, rho:float=RHO_PUREWA
204
217
  denom_shields= (s-1)*GRAVITY*d ## en réalité denom/rho
205
218
  return rho * denom_shields * psiadim
206
219
 
207
- def get_d_min(rhom:float=2650., rho:float=RHO_PUREWATER) -> float:
220
+ def get_d_min(rhom:float = RHO_SEDIMENT, rho:float=RHO_PUREWATER) -> float:
208
221
  return get_d_from_sadim(get_sadim_min(),rhom,rho)
209
222
 
210
223
  def _d_cr(x:float, tau_obj:float, rhom:float, rho:float, xadim:float, yadim:float) -> float:
@@ -215,66 +228,91 @@ def _d_cr(x:float, tau_obj:float, rhom:float, rho:float, xadim:float, yadim:floa
215
228
  psi_cr=yadim(xadim(x,rhom,rho))
216
229
  return psi_obj-psi_cr
217
230
 
218
- # def _get_d_cr(tau_cr,rhom=2650,rho=RHO_PUREWATER):
231
+ def _get_d_cr(tau_cr, rhom = RHO_SEDIMENT, rho=RHO_PUREWATER, which=2) -> float:
232
+ """ Critical diameter d_cr for Shields criterion
233
+
234
+ :param tau_cr: critical shear stress [Pa]
235
+ :param rhom: sediment density [kg/m3]
236
+ :param rho: water density [kg/m3]
237
+ :param which: which formula to use (default 2) -- see funcs = [(get_sadim, get_psi_cr), (get_dstar, get_psi_cr2), (get_dstar, get_psi_cr3)]
238
+ """
239
+
240
+ assert which in [0, 1, 2], "which must be 0, 1 or 2"
241
+
242
+ dminabs = 1.e-100
243
+ dmaxabs = 20
244
+ funcs = [(get_sadim, get_psi_cr),
245
+ (get_dstar, get_psi_cr2),
246
+ (get_dstar, get_psi_cr3)]
219
247
 
220
- # dminabs = 1.e-6
221
- # dmaxabs = .5
222
- # d_cr = root_scalar(_d_cr,(tau_cr,rhom,rho,get_sadim,get_psi_cr),'bisect',bracket=[dminabs, dmaxabs])
248
+ d_cr = root_scalar(_d_cr,(tau_cr, rhom, rho, funcs[which][0],funcs[which][1]), 'bisect', bracket=[dminabs, dmaxabs])
223
249
 
224
- # return d_cr
250
+ return d_cr.root
225
251
 
226
- def get_d_cr(q:float, h:float, K:float, rhom:float=2650., rho:float=RHO_PUREWATER, method='brenth', which=2) -> list[float]:
252
+ def get_d_cr(q:float, h:float, K:float,
253
+ rhom:float = RHO_SEDIMENT, rho:float=RHO_PUREWATER,
254
+ method='brenth', which=2,
255
+ friction_law:Literal['Strickler', 'Colebrook'] = 'Strickler') -> list[float]:
227
256
  """
228
257
  Diamètre critique d'emportement par :
229
258
  - Shields
230
259
  - Izbach
231
260
 
232
- :param q : discharge [m3/s]
233
- :param h : water depth [m]
234
- :param K : Strickler friction coefficient [m1/3/s]
235
- :param rhom : sediment density [kg/m3]
236
- :param rho : water density [kg/m3]
237
- :param method : method to solve the equation (default 'brenth')
238
- :param which : which formula to use (default 2) -- see funcs = [(get_sadim,get_psi_cr),(get_dstar,get_psi_cr2),(get_dstar,get_psi_cr3)]
261
+ :param q: discharge [m3/s]
262
+ :param h: water depth [m]
263
+ :param K: Strickler friction coefficient [m1/3/s]
264
+ :param rhom: sediment density [kg/m3]
265
+ :param rho: water density [kg/m3]
266
+ :param method: method to solve the equation (default 'brenth')
267
+ :param which: which formula to use (default 2) -- see funcs = [(get_sadim,get_psi_cr),(get_dstar,get_psi_cr2),(get_dstar,get_psi_cr3)]
239
268
  """
269
+
270
+ assert which in [0, 1, 2], "which must be 0, 1 or 2"
271
+ assert friction_law in ['Strickler', 'Colebrook'], "friction_law must be 'Strickler' or 'Colebrook'"
272
+
240
273
  if q==0.:
241
274
  return 0.,0.
242
275
 
243
- tau_cr = (q/K)**2 / h**(7/3) * rho * GRAVITY # rho*g*h*J
276
+ # tau_cr = (q/K)**2 / h**(7/3) * rho * GRAVITY # rho*g*h*J
277
+ if friction_law == 'Strickler':
278
+ tau_cr = get_friction_slope_2D_Manning(q, h, 1/K) * rho * GRAVITY * h # rho*g*h*J
279
+ elif friction_law == 'Colebrook':
280
+ tau_cr = get_friction_slope_2D_Colebrook(q, h, K) * rho * GRAVITY * h
281
+
244
282
  dminabs = 1.e-100
245
283
  dmaxabs = 20
246
284
 
247
285
  funcs = [(get_sadim, get_psi_cr),(get_dstar, get_psi_cr2),(get_dstar, get_psi_cr3)]
248
286
 
249
287
  try:
250
- d_cr = root_scalar(_d_cr,(tau_cr,rhom,rho,funcs[which][0],funcs[which][1]),method,bracket=[dminabs, dmaxabs],rtol = 1e-2)
288
+ d_cr = root_scalar(_d_cr,(tau_cr,rhom,rho,funcs[which][0],funcs[which][1]), method, bracket=[dminabs, dmaxabs], rtol = 1e-2)
251
289
  return d_cr.root, izbach_d_cr(q,h,rhom,rho)
252
290
  except:
253
291
  izbach = izbach_d_cr(q,h,rhom,rho)
254
292
  return izbach,izbach
255
293
 
256
- def get_settling_vel(d:float, rhom:float=2650., rho:float=RHO_PUREWATER) -> float:
294
+ def get_settling_vel(d:float, rhom:float= RHO_SEDIMENT, rho:float=RHO_PUREWATER) -> float:
257
295
  """
258
296
  Vitesse de chute
259
297
 
260
- :param d : grain diameter [m]
261
- :param rhom : sediment density [kg/m3]
262
- :param rho : water density [kg/m3]
298
+ :param d: grain diameter [m]
299
+ :param rhom: sediment density [kg/m3]
300
+ :param rho: water density [kg/m3]
263
301
  """
264
302
  dstar = get_dstar(d,rhom,rho)
265
303
  ws = KIN_VISCOSITY/d*(math.sqrt(25+1.2*dstar**2.)-5)**(3./2.)
266
304
  return ws
267
305
 
268
- def get_Rouse(d:float, q:float, h:float, K:float, rhom:float=2650., rho:float=RHO_PUREWATER) -> float:
306
+ def get_Rouse(d:float, q:float, h:float, K:float, rhom:float= RHO_SEDIMENT, rho:float=RHO_PUREWATER) -> float:
269
307
  """
270
308
  Vitesse de chute
271
309
 
272
- :param d : grain diameter [m]
273
- :param q : discharge [m3/s]
274
- :param h : water depth [m]
275
- :param K : Strickler friction coefficient [m1/3/s]
276
- :param rhom : sediment density [kg/m3]
277
- :param rho : water density [kg/m3]
310
+ :param d: grain diameter [m]
311
+ :param q: discharge [m3/s]
312
+ :param h: water depth [m]
313
+ :param K: Strickler friction coefficient [m1/3/s]
314
+ :param rhom: sediment density [kg/m3]
315
+ :param rho: water density [kg/m3]
278
316
  """
279
317
  # tau_cr = (q/K)**2 / h**(7/3) * rho * GRAVITY
280
318
  # shear_vel = math.sqrt(tau_cr/rho)
@@ -285,16 +323,16 @@ def get_Rouse(d:float, q:float, h:float, K:float, rhom:float=2650., rho:float=RH
285
323
 
286
324
  return ws/(k*shear_vel)
287
325
 
288
- def _get_Rouse(d:float, q:float, h:float, K:float, rhom:float=2650., rho:float=RHO_PUREWATER, frac:float=50) -> float:
326
+ def _get_Rouse(d:float, q:float, h:float, K:float, rhom:float= RHO_SEDIMENT, rho:float=RHO_PUREWATER, frac:float=50) -> float:
289
327
  """
290
328
  Settling velocity function -- used in root_scalar
291
329
 
292
- :param d : grain diameter [m]
293
- :param q : discharge [m3/s]
294
- :param h : water depth [m]
295
- :param K : Strickler friction coefficient [m1/3/s]
296
- :param rhom : sediment density [kg/m3]
297
- :param rho : water density [kg/m3]
330
+ :param d: grain diameter [m]
331
+ :param q: discharge [m3/s]
332
+ :param h: water depth [m]
333
+ :param K: Strickler friction coefficient [m1/3/s]
334
+ :param rhom: sediment density [kg/m3]
335
+ :param rho: water density [kg/m3]
298
336
  """
299
337
  # tau_cr = (q/K)**2 / h**(7/3) * rho * GRAVITY
300
338
  # shear_vel = math.sqrt(tau_cr/rho)
@@ -313,18 +351,18 @@ def _get_Rouse(d:float, q:float, h:float, K:float, rhom:float=2650., rho:float=R
313
351
  elif frac==100:
314
352
  return rouse-1.2
315
353
 
316
- def get_transport_mode(d:float, q:float, h:float, K:float, rhom:float=2650., rho:float=RHO_PUREWATER): # -> BED_LOAD | SUSPENDED_LOAD_50 | SUSPENDED_LOAD_100 | WASH_LOAD:
354
+ def get_transport_mode(d:float, q:float, h:float, K:float, rhom:float= RHO_SEDIMENT, rho:float=RHO_PUREWATER): # -> BED_LOAD | SUSPENDED_LOAD_50 | SUSPENDED_LOAD_100 | WASH_LOAD:
317
355
  """
318
356
  Transport mode
319
357
 
320
358
  return in [BED_LOAD, SUSPENDED_LOAD_50, SUSPENDED_LOAD_100, WASH_LOAD]
321
359
 
322
- :param d : grain diameter [m]
323
- :param q : discharge [m3/s]
324
- :param h : water depth [m]
325
- :param K : Strickler friction coefficient [m1/3/s]
326
- :param rhom : sediment density [kg/m3]
327
- :param rho : water density [kg/m3]
360
+ :param d: grain diameter [m]
361
+ :param q: discharge [m3/s]
362
+ :param h: water depth [m]
363
+ :param K: Strickler friction coefficient [m1/3/s]
364
+ :param rhom: sediment density [kg/m3]
365
+ :param rho: water density [kg/m3]
328
366
 
329
367
  """
330
368
 
@@ -338,15 +376,15 @@ def get_transport_mode(d:float, q:float, h:float, K:float, rhom:float=2650., rho
338
376
  else:
339
377
  return WASH_LOAD
340
378
 
341
- def get_d_cr_susp(q:float, h:float, K:float, rhom:float=2650., rho:float=RHO_PUREWATER, method='brenth', which=50) -> float:
379
+ def get_d_cr_susp(q:float, h:float, K:float, rhom:float= RHO_SEDIMENT, rho:float=RHO_PUREWATER, method='brenth', which=50) -> float:
342
380
  """
343
381
  Diamètre critique d'emportement par suspension à 50% --> cf Rouse 1.2
344
382
 
345
- :param q : discharge [m3/s]
346
- :param h : water depth [m]
347
- :param K : Strickler friction coefficient [m1/3/s]
348
- :param rhom : sediment density [kg/m3]
349
- :param rho : water density [kg/m3]
383
+ :param q: discharge [m3/s]
384
+ :param h: water depth [m]
385
+ :param K: Strickler friction coefficient [m1/3/s]
386
+ :param rhom: sediment density [kg/m3]
387
+ :param rho: water density [kg/m3]
350
388
 
351
389
  """
352
390
  if q==0.:
@@ -360,8 +398,13 @@ def get_d_cr_susp(q:float, h:float, K:float, rhom:float=2650., rho:float=RHO_PUR
360
398
  except:
361
399
  return 0.
362
400
 
363
- def shieldsdia_sadim(s_psicr=None, dstar_psicr=None, rhom=2650., rho=RHO_PUREWATER, figax=None) -> tuple[plt.Figure,plt.Axes]:
364
- """ Plot Shields diagram with sadim"""
401
+ def shieldsdia_sadim(s_psicr=None, dstar_psicr=None, figax=None) -> tuple[plt.Figure,plt.Axes]:
402
+ """ Plot Shields diagram with sadim as x-axis
403
+
404
+ :param s_psicr: tuple (S, psicr) for a specific point to plot on the diagram
405
+ :param dstar_psicr: tuple (dstar, psicr) for a specific point to plot on the diagram
406
+ :param figax: tuple (fig, ax) to plot on a specific figure and axes
407
+ """
365
408
 
366
409
  smax = 1000
367
410
  rangoS = np.arange(0.1,smax,0.1)
@@ -416,8 +459,13 @@ def shieldsdia_sadim(s_psicr=None, dstar_psicr=None, rhom=2650., rho=RHO_PUREWAT
416
459
 
417
460
  return fig,ax
418
461
 
419
- def shieldsdia_dstar(s_psicr=None, dstar_psicr=None, rhom=2650., rho=RHO_PUREWATER, figax=None) -> tuple[plt.Figure,plt.Axes]:
420
- """ Plot Shields diagram with dstar"""
462
+ def shieldsdia_dstar(s_psicr=None, dstar_psicr=None, figax=None) -> tuple[plt.Figure,plt.Axes]:
463
+ """ Plot Shields diagram with dstar as x-axis
464
+
465
+ :param s_psicr: tuple (S, psicr) for a specific point to plot on the diagram
466
+ :param dstar_psicr: tuple (dstar, psicr) for a specific point to plot on the diagram
467
+ :param figax: tuple (fig, ax) to plot on a specific figure and axes
468
+ """
421
469
 
422
470
  smax = 1000
423
471
  d_stars = np.arange(0.1,smax,0.1)
@@ -517,9 +565,9 @@ def get_friction_slope_2D_Manning(q:float, h:float, n:float) -> float:
517
565
  """
518
566
  Compute friction slope j for 2D flow with Manning/Strickler friction law
519
567
 
520
- :param q : discharge [m3/s]
521
- :param h : water depth [m]
522
- :param n : Manning friction coefficient [m-1/3.s]
568
+ :param q: discharge [m3/s]
569
+ :param h: water depth [m]
570
+ :param n: Manning friction coefficient [m^{-1/3}.s]
523
571
  """
524
572
 
525
573
  denom = h**(4./3.)
@@ -530,13 +578,24 @@ def get_friction_slope_2D_Manning(q:float, h:float, n:float) -> float:
530
578
 
531
579
  return j
532
580
 
581
+ def get_friction_slope_2D_Strickler(q:float, h:float, K:float) -> float:
582
+ """
583
+ Compute friction slope j for 2D flow with Strickler friction law
584
+
585
+ :param q: discharge [m3/s]
586
+ :param h: water depth [m]
587
+ :param K: Strickler friction coefficient [m^{1/3}/s]
588
+ """
589
+
590
+ return get_friction_slope_2D_Manning(q, h, 1./K) # n = 1/K
591
+
533
592
  def get_friction_slope_2D_Colebrook(q:float, h:float, K:float) -> float:
534
593
  """
535
594
  Compute friction slope j for 2D flow with Colebrook-White friction law
536
595
 
537
- :param q : discharge [m3/s]
538
- :param h : water depth [m]
539
- :param K : Colebrook-White friction coefficient [m]
596
+ :param q: discharge [m3/s]
597
+ :param h: water depth [m]
598
+ :param K: height of roughness [m] - will be used to compute k/D or k/(4h) in 2D flow
540
599
  """
541
600
 
542
601
  four_hydraulic_radius = 4.0 * h
@@ -554,10 +613,10 @@ def get_shear_velocity_2D_Manning(q:float, h:float, n:float) -> float:
554
613
  """
555
614
  Compute shear velocity u_* for 2D flow with Manning/Strickler friction law
556
615
 
557
- :param j : friction slope [-]
558
- :param h : water depth [m]
559
- :param q : discharge [m3/s]
560
- :param n : Manning friction coefficient [m-1/3.s]
616
+ :param j: friction slope [-]
617
+ :param h: water depth [m]
618
+ :param q: discharge [m3/s]
619
+ :param n: Manning friction coefficient [m-1/3.s]
561
620
  """
562
621
 
563
622
  j = get_friction_slope_2D_Manning(q,h,n)
@@ -570,10 +629,10 @@ def get_shear_velocity_2D_Colebrook(q:float, h:float, K:float) -> float:
570
629
  """
571
630
  Compute shear velocity u_* for 2D flow with Colebrook-White friction law
572
631
 
573
- :param j : friction slope [-]
574
- :param h : water depth [m]
575
- :param q : discharge [m3/s]
576
- :param K : Colebrook-White friction coefficient [m]
632
+ :param j: friction slope [-]
633
+ :param h: water depth [m]
634
+ :param q: discharge [m3/s]
635
+ :param K: Colebrook-White friction coefficient [m]
577
636
  """
578
637
 
579
638
  j = get_friction_slope_2D_Colebrook(q,h,K)
@@ -586,11 +645,11 @@ def get_Shields_2D_Manning(s:float, d:float, q:float, h:float, n:float) -> float
586
645
  """
587
646
  Compute Shields dimensionless parameter for 2D flow with Manning/Strickler friction law
588
647
 
589
- :param s : sediment density / water density [-]
590
- :param d : sediment diameter [m]
591
- :param q : discharge [m3/s]
592
- :param h : water depth [m]
593
- :param n : Manning friction coefficient [m-1/3.s]
648
+ :param s: sediment density / water density [-]
649
+ :param d: sediment diameter [m]
650
+ :param q: discharge [m3/s]
651
+ :param h: water depth [m]
652
+ :param n: Manning friction coefficient [m-1/3.s]
594
653
 
595
654
  See also get_Shields_2D_Strickler
596
655
  """
@@ -607,11 +666,11 @@ def get_Shields_2D_Strickler(s:float, d:float, q:float, h:float, K:float) -> flo
607
666
  """
608
667
  Compute Shields dimensionless parameter for 2D flow with Manning/Strickler friction law
609
668
 
610
- :param s : sediment density / water density [-]
611
- :param d : sediment diameter [m]
612
- :param q : discharge [m3/s]
613
- :param h : water depth [m]
614
- :param K : Strickler friction coefficient [m1/3/s]
669
+ :param s: sediment density / water density [-]
670
+ :param d: sediment diameter [m]
671
+ :param q: discharge [m3/s]
672
+ :param h: water depth [m]
673
+ :param K: Strickler friction coefficient [m1/3/s]
615
674
 
616
675
  See also get_Shields_2D_Manning
617
676
  """
@@ -631,21 +690,23 @@ def izbach_d_cr(q:float, h:float, rhom:float=2650, rho:float=RHO_PUREWATER, meth
631
690
  (s-1) = (rho_m - rho) / rho
632
691
  u_c = 85% u_moyen)
633
692
 
634
- --> d = u_c**2 / (s * g) / 1.7**2
693
+ --> d = u_c**2 / ((s-1) * g) / 1.7**2
635
694
 
636
- --> d = (0.85 * q/h)**2 / (s * g) / 1.7**2
695
+ --> d = (0.85 * q/h)**2 / ((s-1) * g) / 1.7**2
637
696
 
638
- :param q : discharge [m3/s]
639
- :param h : water depth [m]
640
- :param rhom : sediment density [kg/m3]
641
- :param rho : water density [kg/m3]
642
- :param method : method to solve the equation (default 'ridder')
697
+ :param q: discharge [m3/s]
698
+ :param h: water depth [m]
699
+ :param rhom: sediment density [kg/m3]
700
+ :param rho: water density [kg/m3]
701
+ :param method: method to solve the equation (default 'ridder')
643
702
  """
644
703
  s = rhom/rho
645
704
  # (0.85 * q/h)**2. / ((s-1.) * GRAVITY) / 1.7**2.
646
- # <=> 0.7 * (0.85*q/h)**2. / (2 * GRAVITY) / (s-1.)
647
- # <=> (q/h)**2. / (2 * GRAVITY) / (s-1.) / .86**2
648
- return (q/h)**2. / (2 * GRAVITY) / (s-1.) / 1.2**2
705
+ # avec (2 / 1.7**2) = 0.692041... = 0.7
706
+ # <=> 0.7 * (0.85 * q/h)**2. / (2 * GRAVITY) / (s-1.)
707
+ # <=> (q/h)**2. / (2 * GRAVITY) / (s-1.) / 1.406**2
708
+
709
+ return (q/h)**2. / (2 * GRAVITY) / (s-1.) / 1.2**2 # We are using 1.2 instead of 1.406 -- see GCIV2035-1 - Hydrodynamique fluviale
649
710
 
650
711
 
651
712
  ## Portage de WOLF2D - Fortran pour Barr-Bathurst
wolfhece/wolf_array.py CHANGED
@@ -111,6 +111,11 @@ except ImportError as e:
111
111
  print(e)
112
112
  raise Exception(_('Error importing modules'))
113
113
 
114
+ try:
115
+ from .pydownloader import download_file, toys_dataset
116
+ except ImportError as e:
117
+ raise Exception(_('Error importing pydownloader module'))
118
+
114
119
  WOLF_ARRAY_HILLSHAPE = -1
115
120
  WOLF_ARRAY_FULL_SINGLE = 1
116
121
  WOLF_ARRAY_FULL_DOUBLE = 2
@@ -5605,6 +5610,14 @@ class WolfArray(Element_To_Draw, header_wolf):
5605
5610
 
5606
5611
  if fname is not None:
5607
5612
 
5613
+ # check if fname is an url
5614
+ if str(fname).startswith('http:') or str(fname).startswith('https:'):
5615
+ try:
5616
+ fname = download_file(fname)
5617
+ except Exception as e:
5618
+ logging.error(_('Error while downloading file: %s') % e)
5619
+ return
5620
+
5608
5621
  self.filename = str(fname)
5609
5622
  logging.info(_('Loading file : %s') % self.filename)
5610
5623
  self.read_all()
@@ -6240,20 +6253,39 @@ class WolfArray(Element_To_Draw, header_wolf):
6240
6253
  if reset_plot:
6241
6254
  self.reset_plot()
6242
6255
 
6243
- def statistics(self, inside_polygon:vector | Polygon = None):
6256
+ def statistics(self, inside_polygon:vector | Polygon | np.ndarray = None) -> dict[str, float | np.ndarray]:
6244
6257
  """
6245
6258
  Statistics on Selected data or the whole array if no selection
6246
6259
 
6247
6260
  :param inside_polygon: vector or Polygon to select data inside the polygon
6248
6261
  :return: mean, std, median, sum, volume (sum*dx*dy), values
6262
+ :rtype: dict[str, float | np.ndarray]
6263
+
6264
+ Translated Keys are:
6265
+ - _('Mean'): mean value of the selected data
6266
+ - _('Std'): standard deviation of the selected data
6267
+ - _('Median'): median value of the selected data
6268
+ - _('Sum'): sum of the selected data
6269
+ - _('Volume'): volume of the selected data (sum * dx * dy)
6270
+ - _('Values'): values of the selected data as a numpy array
6249
6271
  """
6250
6272
 
6251
6273
  if inside_polygon is not None:
6252
- ij = self.get_ij_inside_polygon(inside_polygon)
6274
+ if isinstance(inside_polygon, vector | Polygon):
6275
+ ij = self.get_ij_inside_polygon(inside_polygon)
6276
+ elif isinstance(inside_polygon, np.ndarray):
6277
+ if inside_polygon.ndim == 2 and inside_polygon.shape[1] == 2:
6278
+ ij = self.get_ij_from_xy_array(inside_polygon)
6279
+ else:
6280
+ logging.error(_('Invalid shape for inside_polygon numpy array'))
6281
+ return {}
6282
+
6253
6283
  vals = self.array[ij[:,0], ij[:,1]]
6284
+
6254
6285
  elif self.SelectionData.nb == 0 or self.SelectionData.myselection == 'all':
6255
6286
  logging.info(_('No selection -- statistics on the whole array'))
6256
6287
  vals = self.array[~self.array.mask].ravel().data # all values
6288
+
6257
6289
  else:
6258
6290
  vals = self.SelectionData.get_values_sel()
6259
6291
 
@@ -8996,7 +9028,7 @@ class WolfArray(Element_To_Draw, header_wolf):
8996
9028
  C'est le cas notamment de Wolfresults_2D
8997
9029
  """
8998
9030
 
8999
- return self.get_values_insidepoly(myvect, usemask,getxy)
9031
+ return self.get_values_insidepoly(myvect, usemask, getxy)
9000
9032
 
9001
9033
  def get_all_values_underpoly(self, myvect: vector, usemask:bool=True, getxy:bool=False):
9002
9034
  """
@@ -10145,7 +10177,7 @@ class WolfArray(Element_To_Draw, header_wolf):
10145
10177
 
10146
10178
  return my_extr
10147
10179
 
10148
- def get_value(self, x:float, y:float, z:float=0., nullvalue:float=-99999):
10180
+ def get_value(self, x:float, y:float, z:float=0., nullvalue:float=-99999, convert_to_float:bool=True):
10149
10181
  """
10150
10182
  Return the value at given coordinates
10151
10183
 
@@ -10180,8 +10212,10 @@ class WolfArray(Element_To_Draw, header_wolf):
10180
10212
  else:
10181
10213
  value = nullvalue
10182
10214
 
10183
- #FIXME : forcing to convert to float is not a good idea
10184
- return float(value)
10215
+ if convert_to_float:
10216
+ return float(value)
10217
+ else:
10218
+ return value
10185
10219
 
10186
10220
  def get_xlim(self, window_x:float, window_y:float):
10187
10221
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wolfhece
3
- Version: 2.2.29
3
+ Version: 2.2.31
4
4
  Author-email: Pierre Archambeau <pierre.archambeau@uliege.be>
5
5
  Project-URL: Homepage, https://uee.uliege.be/hece
6
6
  Project-URL: Issues, https://uee.uliege.be/hece
@@ -7,8 +7,8 @@ wolfhece/ManageParams.py,sha256=EeuUI5Vvh9ixCvYf8YShMC1s1Yacc7OxOCN7q81gqiQ,517
7
7
  wolfhece/Model1D.py,sha256=snEmu8Uj2YGcp1ybPnly-4A389XRnuOujGduqInNcgw,477001
8
8
  wolfhece/PandasGrid.py,sha256=YIleVkUkoP2MjtQBZ9Xgwk61zbgMj4Pmjj-clVTfPRs,2353
9
9
  wolfhece/PyConfig.py,sha256=Zs9852UnTMDjiH9RhC_-cQdOowDaS1U5PbmmU9nEpv0,18265
10
- wolfhece/PyCrosssections.py,sha256=igU_ELrg5VrHU6RNbF5tHxPyVImpR3xdpfopJYc7haw,114711
11
- wolfhece/PyDraw.py,sha256=-hPVoASNtB7k9_P7F3uq-4Vqytie4wjEL36OUiqtszQ,671455
10
+ wolfhece/PyCrosssections.py,sha256=iSmuQ1753bWxRLgOkrRLPd3tiMwGRCvfKD2Mim26_8c,114836
11
+ wolfhece/PyDraw.py,sha256=cloYUTYk6tTCuSmBehVcz2DOadkb7J5w9i1ihBilT2Q,671960
12
12
  wolfhece/PyGui.py,sha256=DqMTDsC9GthnMdYOXvkMKfl5pNciExVzxG4ogptWf6g,146010
13
13
  wolfhece/PyGuiHydrology.py,sha256=sKafpOopBg50L5llZCI_fZtbebVTDtxvoRI6-osUwhg,14745
14
14
  wolfhece/PyHydrographs.py,sha256=1P5XAURNqCvtSsMQXhOn1ihjTpr725sRsZdlCEhhk6M,3730
@@ -17,7 +17,7 @@ wolfhece/PyParams.py,sha256=BgTAwxxq831rYEq_KLcFBX_upjiSUpVtfoQnCxCNWUI,100443
17
17
  wolfhece/PyPictures.py,sha256=m1kY0saW6Y9Q0bDCo47lW6XxDkBrbQG-Fd8uVn8G5ic,2514
18
18
  wolfhece/PyTranslate.py,sha256=4appkmNeHHZLFmUtaA_k5_5QL-5ymxnbVN4R2OblmtE,622
19
19
  wolfhece/PyVertex.py,sha256=a56oY1NB45QnwARg96Tbnq-z-mhZKFkYOkFOO1lNtlk,51056
20
- wolfhece/PyVertexvectors.py,sha256=DZpuqfzAEWAtGJ5oSzRY0kRMlkwErogcGMJQOh6niDE,341983
20
+ wolfhece/PyVertexvectors.py,sha256=MXoqgHVRMvpUOngqpErwT68JwUJo9FhEl1H4HB10-Zk,352574
21
21
  wolfhece/PyWMS.py,sha256=XcSlav5icct2UwV7K2r7vpxa5rKZWiHkp732lI94HFI,31534
22
22
  wolfhece/RatingCurve.py,sha256=bUjIrQjvIjkD4V-z8bZmA6pe1ILtYNM0-3fT6YUY1RU,22498
23
23
  wolfhece/RatingCurveData.py,sha256=5UvnIm89BwqjnEbLCcY3CA8WoFd_xHJbooNy62fX5iY,57660
@@ -26,7 +26,7 @@ wolfhece/ReadDataDCENN.py,sha256=vm-I4YMryvRldjXTvRYEUCxZsjb_tM7U9yj6OaPyD0k,153
26
26
  wolfhece/Results2DGPU.py,sha256=GTu7PMuwfH-xH8J7sVr6zq2CTkGKF24fG1ujEW62PtM,31598
27
27
  wolfhece/__init__.py,sha256=EnpZ2yDEXueP7GAKV0uA2vAwMiZFyBjDAFcL5Y7LzbM,1850
28
28
  wolfhece/_add_path.py,sha256=mAyu85CQHk0KgUI6ZizweeQiw1Gdyea9OEjGLC6lLA4,916
29
- wolfhece/analyze_poly.py,sha256=jsCUsd0ZJtTwSk5hekcXj8i0tGhH-WCfNkrBtPRJpCc,12715
29
+ wolfhece/analyze_poly.py,sha256=gJlQZ0vwDG_N98eMDtUsLng9kKu-HlJ8a4xER9ubfDc,54527
30
30
  wolfhece/analyze_vect.py,sha256=3lkMwaQ4KRddBVRvlP9PcM66wZwwC0eCmypP91AW-os,6015
31
31
  wolfhece/cli.py,sha256=h1tSMHALiftktreyugKcjbASXfpJUm9UYMeVxR-MtG4,6424
32
32
  wolfhece/color_constants.py,sha256=Snc5RX11Ydi756EkBp_83C7DiAQ_Z1aHD9jFIBsosAU,37121
@@ -51,16 +51,17 @@ wolfhece/pidcontroller.py,sha256=PHYenOdzfyPK2pXAhyRolCxMSMRd2AFza0eVMafpPHk,520
51
51
  wolfhece/pyGui1D.py,sha256=9g7OS3YiKsqy--6y0cBD7x2gaqTTYFXWkxImpgnTA20,121937
52
52
  wolfhece/pybridges.py,sha256=bFAqjL4ColeJtwvyCPGQ8VllWoq1RbVWXxFrdfrvqm8,65954
53
53
  wolfhece/pydike.py,sha256=dRb6qGkqoTXjf107KcajcIk1F_FuMPaOZLSwixT3dgA,11196
54
+ wolfhece/pydownloader.py,sha256=7vcxzllphhQcH0nEI2NwX-HC0bKhOVpDkODq54oFMbU,7136
54
55
  wolfhece/pylogging.py,sha256=4TI8hgBB65z-zpvU5Rfa2jkPXPhJaqXjHVPwbcdzTNc,4528
55
- wolfhece/pypolygons_scen.py,sha256=dG4zyJL_t5wgDqRfe-OqSH-fnxUt-su1H-tM3K3wHnc,46339
56
- wolfhece/pyshields.py,sha256=ymH393EQys2aZmh41ccJnWmmlF7dVa-eTY32jFgwK08,25269
56
+ wolfhece/pypolygons_scen.py,sha256=NWaNeK0RSUeOkgukeogK9FLmQiDjGZ9yhqs9208fojM,46237
57
+ wolfhece/pyshields.py,sha256=KMtUO5kD0lisKnJD1NsDz-qaY5DpFcmS4O3WkXtUSmo,27898
57
58
  wolfhece/pyviews.py,sha256=zuZjWUptRDm1MTE1PN4Xj_qSITnojgDMG0LlFIBH3SE,13739
58
59
  wolfhece/pywalous.py,sha256=mWB7UxlYMIbPxNUDlONQEjcOOy9VSaRU9aYWZ5IFLu8,19164
59
60
  wolfhece/rain_SPWMI.py,sha256=qCfcmF7LajloOaCwnTrrSMzyME03YyilmRUOqrPrv3U,13846
60
61
  wolfhece/textpillow.py,sha256=map7HsGYML_o5NHRdFg2s_TVQed_lDnpYNDv27MM0Vw,14130
61
62
  wolfhece/tools2d_dll.py,sha256=TfvvmyZUqEZIH0uHwUCJf0bdmCks_AiidDt23Unsp5w,13550
62
63
  wolfhece/tools_mpl.py,sha256=gQ3Jg1iuZiecmMqa5Eli2ZLSkttu68VXL8YmMDBaEYU,564
63
- wolfhece/wolf_array.py,sha256=15bCTr6nplKwGrkKR4vJR_NZCnhSZsoceUtV99Uy4C8,521981
64
+ wolfhece/wolf_array.py,sha256=jin9_ntHASNcqMx0CPYFHMEIw-LaF6UnousSaQx3AxU,523441
64
65
  wolfhece/wolf_hist.py,sha256=fTEb60Q4TEwobdZsRU4CFXAId1eOKdWAqF8lnF1xEWc,3590
65
66
  wolfhece/wolf_texture.py,sha256=f4psYah1vqyeQjXz2O46d6qeKuv_Lzowk39O9Fmh_2g,20969
66
67
  wolfhece/wolf_tiles.py,sha256=v-HohqaWuMYdn75XLnA22dlloAG90iwnIqrgnB0ASQ4,10488
@@ -88,7 +89,7 @@ wolfhece/apps/curvedigitizer.py,sha256=lEJJwgAfulrrWQc-U6ij6sj59hWN3SZl4Yu1kQxVz
88
89
  wolfhece/apps/hydrometry.py,sha256=lhhJsFeb4zGL4bNQTs0co85OQ_6ssL1Oy0OUJCzhfYE,656
89
90
  wolfhece/apps/isocurrent.py,sha256=dagmGR8ja9QQ1gwz_8fU-N052hIw-W0mWGVkzLu6C7I,4247
90
91
  wolfhece/apps/splashscreen.py,sha256=EdGDN9NhudIiP7c3gVqj7dp4MWFB8ySizM_tpMnsgpE,3091
91
- wolfhece/apps/version.py,sha256=MsRPVPFz_Nd-g9QBhzEMZR5szCY4WxPCUofNwlSWVMA,388
92
+ wolfhece/apps/version.py,sha256=5D9bE5dzDLfYPyBmgVoMOincHBhGAqYJzByZrRcBiy8,388
92
93
  wolfhece/apps/wolf.py,sha256=mRnjYsUu4KIsRuamdQWAINFMuwN4eJgMo9erG-hkZ70,729
93
94
  wolfhece/apps/wolf2D.py,sha256=4z_OPQ3IgaLtjexjMKX9ppvqEYyjFLt1hcfFABy3-jU,703
94
95
  wolfhece/apps/wolf_logo.bmp,sha256=ruJ4MA51CpGO_AYUp_dB4SWKHelvhOvd7Q8NrVOjDJk,3126
@@ -307,8 +308,8 @@ wolfhece/ui/wolf_multiselection_collapsiblepane.py,sha256=u4C7CXe_bUyGKx7c_Bi0x9
307
308
  wolfhece/ui/wolf_times_selection_comparison_models.py,sha256=ORy7fz4dcp691qKzaOZHrRLZ0uXNhL-LIHxmpDGL6BI,5007
308
309
  wolfhece/wintab/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
309
310
  wolfhece/wintab/wintab.py,sha256=8A-JNONV6ujgsgG3lM5Uw-pVgglPATwKs86oBzzljoc,7179
310
- wolfhece-2.2.29.dist-info/METADATA,sha256=35R9m7_Q5LYcKUXvUBBwZ8p1A-JMWrMYn5VtO4ncgNw,2729
311
- wolfhece-2.2.29.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
312
- wolfhece-2.2.29.dist-info/entry_points.txt,sha256=Jr187pyvA3EeJiQLjZK9yo6mJX7IAn6ygZU9T8qF_gQ,658
313
- wolfhece-2.2.29.dist-info/top_level.txt,sha256=EfqZXMVCn7eILUzx9xsEu2oBbSo9liWPFWjIHik0iCI,9
314
- wolfhece-2.2.29.dist-info/RECORD,,
311
+ wolfhece-2.2.31.dist-info/METADATA,sha256=FCE-JySySzwE8OSrK7O7_8IIPOg9RBfBVDS8sPiXfek,2729
312
+ wolfhece-2.2.31.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
313
+ wolfhece-2.2.31.dist-info/entry_points.txt,sha256=Jr187pyvA3EeJiQLjZK9yo6mJX7IAn6ygZU9T8qF_gQ,658
314
+ wolfhece-2.2.31.dist-info/top_level.txt,sha256=EfqZXMVCn7eILUzx9xsEu2oBbSo9liWPFWjIHik0iCI,9
315
+ wolfhece-2.2.31.dist-info/RECORD,,