wolfhece 2.2.15__py3-none-any.whl → 2.2.16__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.
@@ -57,6 +57,8 @@ KIWIS WebServices command :
57
57
  checkValueLimit checks value limitations for time range value requests
58
58
  """
59
59
 
60
+ TIMEOUT = 5
61
+
60
62
  URL_SERVICE = 'https://hydrometrie.wallonie.be/services'
61
63
  URL_SERVICE_WATERINFO = 'https://download.waterinfo.be/tsmdownload'
62
64
  URL_SERVICE_HICWS = 'https://hicws.vlaanderen.be'
@@ -400,6 +402,13 @@ class hydrometry():
400
402
  if url=='':
401
403
  self.url=URL_SPW
402
404
 
405
+ # check if url is responding
406
+ try:
407
+ requests.get(self.url, timeout=TIMEOUT)
408
+ except requests.exceptions.RequestException as e:
409
+ logging.error(f"Error connecting to {self.url}: {e}")
410
+ return
411
+
403
412
  if urltoken=='':
404
413
  self.urltoken=URL_TOKEN
405
414
 
@@ -413,7 +422,7 @@ class hydrometry():
413
422
  self.get_sites()
414
423
  self.get_stations()
415
424
  self.get_groups()
416
- self.save_struct(self.dir)
425
+ self.save_struct()
417
426
  except Exception as e:
418
427
  print('Error in hydrometry init :', e)
419
428
  self.realstations = None
@@ -501,7 +510,11 @@ class hydrometry():
501
510
  """
502
511
 
503
512
  if dir=='':
504
- return
513
+ if self.dir:
514
+ dir = self.dir
515
+ else:
516
+ logging.warning('No directory to save structure')
517
+ return
505
518
 
506
519
  dir = Path(dir)
507
520
  dir.mkdir(parents=True, exist_ok=True)
@@ -572,7 +585,7 @@ class hydrometry():
572
585
  # returnfields += 'ts_id,ts_name,'
573
586
  # returnfields += 'ts_unitname,ts_unitsymbol,'
574
587
 
575
- if self.dir!='' and self.get_path(self.dir, 'stations.csv').exists():
588
+ if self.dir!='' and self.get_path(self.dir,'stations.csv').exists():
576
589
  self.stations = pd.read_csv(self.get_path(self.dir, 'stations.csv'),index_col=0)
577
590
  elif self.url!='':
578
591
  try:
@@ -583,14 +596,16 @@ class hydrometry():
583
596
  +'&ca_sta_returnfields='+ca_sta_returnfields \
584
597
  +'&orderby=station_no', \
585
598
  verify=True, \
586
- headers=self._header).json()
599
+ headers=self._header,
600
+ timeout=TIMEOUT).json()
587
601
  else:
588
602
  json_data = requests.get(self._get_commandstr(kiwis_command.getStationList, 'json') \
589
603
  +'&metadata=true' \
590
604
  +'&returnfields='+returnfields \
591
605
  +'&orderby=station_no', \
592
606
  verify=True, \
593
- headers=self._header)
607
+ headers=self._header,
608
+ timeout=TIMEOUT)
594
609
 
595
610
  json_data = json_data.text.replace('\x1a', ' ')
596
611
  json_data = json.loads(json_data)
@@ -802,7 +817,9 @@ class hydrometry():
802
817
  '&timeseriesgroup_id='+str(group_id)+
803
818
  '&orderby=station_no'+
804
819
  returnFields,
805
- verify=True, headers=self._header).json()
820
+ verify=True,
821
+ headers=self._header,
822
+ timeout=TIMEOUT).json()
806
823
  stations = pd.DataFrame(json_data[1:], columns = json_data[0])
807
824
  else:
808
825
  logging.error(f'{time} not found in Enum')
@@ -831,7 +848,10 @@ class hydrometry():
831
848
  '&timeseriesgroup_id='+str(group_id)+
832
849
  '&orderby=station_no'+
833
850
  returnFields,
834
- verify=True, headers=self._header).json()
851
+ verify=True,
852
+ headers=self._header,
853
+ timeout=TIMEOUT).json()
854
+
835
855
  stations = pd.DataFrame(json_data[1:], columns = json_data[0])
836
856
 
837
857
  return stations
@@ -844,7 +864,11 @@ class hydrometry():
844
864
  if self.dir!='' and self.get_path(self.dir, 'sites.csv').exists() and not forcerequest:
845
865
  self.sites = pd.read_csv(self.get_path(self.dir, 'sites.csv'),index_col=0)
846
866
  elif self.url!='' or forcerequest:
847
- json_data = requests.get(self._get_commandstr(kiwis_command.getSiteList),verify=True, headers=self._header).json()
867
+ json_data = requests.get(self._get_commandstr(kiwis_command.getSiteList),
868
+ verify=True,
869
+ headers=self._header,
870
+ timeout=TIMEOUT).json()
871
+
848
872
  self.sites = pd.DataFrame(json_data[1:], columns = json_data[0])
849
873
  else:
850
874
  self.sites = None
@@ -857,7 +881,10 @@ class hydrometry():
857
881
  if self.dir!='' and self.get_path(self.dir, 'groups.csv').exists() and not forcerequest:
858
882
  self.groups = pd.read_csv(self.get_path(self.dir, 'groups.csv'),index_col=0)
859
883
  elif self.url!='' or forcerequest:
860
- json_data = requests.get(self._get_commandstr(kiwis_command.getGroupList),verify=True, headers=self._header).json()
884
+ json_data = requests.get(self._get_commandstr(kiwis_command.getGroupList),
885
+ verify=True,
886
+ headers=self._header,
887
+ timeout=TIMEOUT).json()
861
888
  self.groups = pd.DataFrame(json_data[1:], columns = json_data[0])
862
889
  else:
863
890
  self.groups = None
@@ -878,7 +905,11 @@ class hydrometry():
878
905
  if self.dir!='' and self.get_path(self.dir, 'requests.csv').exists() and not forcerequest:
879
906
  self.requests = pd.read_csv(self.get_path(self.dir, 'requests.csv'),index_col=0)
880
907
  elif self.url!='' or forcerequest:
881
- json_data = requests.get(self._get_commandstr(kiwis_command.getrequestinfo),verify=True, headers=self._header).json()
908
+ json_data = requests.get(self._get_commandstr(kiwis_command.getrequestinfo),
909
+ verify=True,
910
+ headers=self._header,
911
+ timeout=TIMEOUT).json()
912
+
882
913
  self.requests = pd.DataFrame(json_data[0]['Requests'])
883
914
  else:
884
915
  self.requests = None
@@ -913,7 +944,9 @@ class hydrometry():
913
944
  json_data = requests.get(self._get_commandstr(kiwis_command.getTimeseriesList)
914
945
  +'&station_id='+str(id)
915
946
  +'&format=json'
916
- ,verify=True, headers=self._header).json()
947
+ ,verify=True,
948
+ headers=self._header,
949
+ timeout=TIMEOUT).json()
917
950
 
918
951
  try:
919
952
  if json_data[0] == 'No matches.':
@@ -978,7 +1011,7 @@ class hydrometry():
978
1011
 
979
1012
  id,list=self.timeseries_list(stationname=stationname,stationcode=stationcode)
980
1013
  filename = self._get_filename_list(stationname,stationcode)
981
- list.to_csv(dir / filename)
1014
+ list.to_csv(self.get_path(dir,filename))
982
1015
 
983
1016
  def timeseries(self, stationname:str='', stationcode:str='', stationid:str='',
984
1017
  dir:str='',
@@ -1027,7 +1060,8 @@ class hydrometry():
1027
1060
  "station_id":str(id),
1028
1061
  "ts_name":ts_name,
1029
1062
  "timezone":timezone})
1030
- ,verify=True).json()
1063
+ ,verify=True,
1064
+ timeout=TIMEOUT).json()
1031
1065
  if len(json_data)==1:
1032
1066
  return None
1033
1067
 
@@ -1090,7 +1124,9 @@ class hydrometry():
1090
1124
  "to":todate.strftime("%Y-%m-%dT%H:%M:%S"),
1091
1125
  # "format":"json",
1092
1126
  "timezone":timezone})
1093
- ,verify=True, headers=self._header).json()
1127
+ ,verify=True,
1128
+ headers=self._header,
1129
+ timeout=TIMEOUT).json()
1094
1130
 
1095
1131
  df = pd.DataFrame(json_data[0]['data'], columns = json_data[0]['columns'].split(','))
1096
1132
  df.set_index('Timestamp', inplace = True)
@@ -1139,7 +1175,8 @@ class hydrometry():
1139
1175
  "ts_name":ts_name,
1140
1176
  "timezone":timezone})+
1141
1177
  "&returnfields=Timestamp,Quality%20Code"
1142
- ,verify=True).json()
1178
+ ,verify=True,
1179
+ timeout=TIMEOUT).json()
1143
1180
  if len(json_data)==1:
1144
1181
  return None
1145
1182
 
@@ -1189,7 +1226,9 @@ class hydrometry():
1189
1226
  "to":todate.strftime("%Y-%m-%dT%H:%M:%S"),
1190
1227
  "timezone":timezone})+
1191
1228
  "&returnfields=Timestamp,Quality%20Code"
1192
- ,verify=True, headers=self._header).json()
1229
+ ,verify=True,
1230
+ headers=self._header,
1231
+ timeout=TIMEOUT).json()
1193
1232
 
1194
1233
  df = pd.DataFrame(json_data[0]['data'], columns = json_data[0]['columns'].split(','))
1195
1234
  df.set_index('Timestamp', inplace = True)
@@ -13,13 +13,14 @@ import logging
13
13
 
14
14
  from ..drawing_obj import Element_To_Draw
15
15
 
16
- try:
17
- # Trying to import the hydrometry_hece module from the hydrometry_hece package
18
- # containing the KEY access to the SPW server
19
- from ..hydrometry_hece.kiwis_hece import hydrometry_hece as hydrometry
20
- except:
21
- # If the hydrometry_hece module is not found, we import the hydrometry module from the hydrometry package
22
- from .kiwis import hydrometry
16
+ # try:
17
+ # # Trying to import the hydrometry_hece module from the hydrometry_hece package
18
+ # # containing the KEY access to the SPW server
19
+ # from ..hydrometry_hece.kiwis_hece import hydrometry_hece as hydrometry
20
+ # except:
21
+ # # If the hydrometry_hece module is not found, we import the hydrometry module from the hydrometry package
22
+ # from .kiwis import hydrometry
23
+ from .kiwis import hydrometry
23
24
 
24
25
  from .kiwis_gui import hydrometry_gui
25
26
  from ..PyVertex import cloud_vertices, wolfvertex, Cloud_Styles, getIfromRGB, getRGBfromI
@@ -95,12 +95,12 @@ class Classification_LAZ():
95
95
  10 : ['Ponts', 'Les ponts ont été classés à part pour améliorer la définition du MNT. Ils ont été ouverts grâce',Colors.rgb_withalpha_float('lightyellow1',1.)],
96
96
  11 : ['Mur de berges', 'Mur et muret en berge de la Vesdre dépassant le sol à des vocation de réaliser une modélisation 3D hydraulique avec ces obstacles.',Colors.rgb_withalpha_float('red1',1.)],
97
97
  13 : ['Inconnu', 'A vérifier auSPW', Colors.rgb_withalpha_float('lightslategray',.2)],
98
- 15 : ['Tranche d\'eau', 'Echo intermédiaire dans l\’eau n\’appartenant ni à la surface d\’eau ni au fond du lit', Colors.rgb_withalpha_float('lightblue',.2)],
99
- 16 : ['Surface bathymétrique', 'Fond du lit de la Vesdre et de ses affluents et des autres surfaces d\’eau mesurées à partir du scanner 3 FWF discrétisé',Colors.rgb_withalpha_float('sandybrown',1.)],
98
+ 15 : [r'Tranche d\'eau', r'Echo intermédiaire dans l\’eau n\’appartenant ni à la surface d\’eau ni au fond du lit', Colors.rgb_withalpha_float('lightblue',.2)],
99
+ 16 : ['Surface bathymétrique', r'Fond du lit de la Vesdre et de ses affluents et des autres surfaces d\’eau mesurées à partir du scanner 3 FWF discrétisé',Colors.rgb_withalpha_float('sandybrown',1.)],
100
100
  17 : ['Surface bathymétrique incertaine', 'Surface bathymétrique sur les zones peu profondes principalement sous végétation où les intensités des échos sont parfois trop faibles pour avoir la certitude qu\’ils représentent le fond de rivière. La classe 17 est néanmoins plus certaine que la classe 18. Elle est utilisée dans la génération des MNT par défaut.',Colors.rgb_withalpha_float('rosybrown',.5)],
101
- 19 : ['Surface d\eau calculée', 'Points sous échantillonnés de la surface d\’eau ayant servis à faire les calculs de correction de réfraction bathymétrique',Colors.rgb_withalpha_float('lightblue',.2)],
101
+ 19 : [r'Surface d\eau calculée', r'Points sous échantillonnés de la surface d\’eau ayant servis à faire les calculs de correction de réfraction bathymétrique',Colors.rgb_withalpha_float('lightblue',.2)],
102
102
  20 : ['Surface bathymétrique incertaine profonde', 'Surface bathymétrique sur les zones plus profondes principalement au centre de la rivière où les intensités des échos sont parfois trop faibles pour avoir la certitude qu\’ils représentent le fond de rivière. Non utilisée dans la génération du MNT. + Surface proche bathy mais potentiellement émergée pour les scanner 1 à 3',Colors.rgb_withalpha_float('lightblue',.5)],
103
- 29 : ['Surface d\'eau héliportée', 'La hauteur d\’eau du vol héliporté étant largement supérieure (de 30 à 40cm au vol Titan, les points matérialisant cette surface ont été reclassés dans cette classe séparée pour ne pas perturbé le reste du nuage de point.',Colors.rgb_withalpha_float('cyan',.3)]}
103
+ 29 : [r'Surface d\'eau héliportée', r'La hauteur d\’eau du vol héliporté étant largement supérieure (de 30 à 40cm au vol Titan, les points matérialisant cette surface ont été reclassés dans cette classe séparée pour ne pas perturbé le reste du nuage de point.',Colors.rgb_withalpha_float('cyan',.3)]}
104
104
 
105
105
  def callback_colors(self):
106
106
  """ Update from wx GUI """
@@ -1748,6 +1748,29 @@ class prev_parameters_blocks:
1748
1748
 
1749
1749
  self.parent._scheme_centered_slope = 2
1750
1750
 
1751
+ @property
1752
+ def is_Manning_surface_friction(self) -> bool:
1753
+ """ Retourne True si le modèle de surface de friction est de type Manning-Strickler """
1754
+ i, name = self.get_params_surface_friction()
1755
+ if i in [0, 1, 2, 3, 4, 5, 6, 7]:
1756
+ return True
1757
+ else:
1758
+ return False
1759
+
1760
+ @property
1761
+ def is_manning_strickler(self) -> bool:
1762
+ """ Retourne True si le modèle de surface de friction est de type Manning-Strickler """
1763
+ return self.is_Manning_surface_friction
1764
+
1765
+ @property
1766
+ def is_Colebrook_surface_friction(self) -> bool:
1767
+ """ Retourne True si le modèle de surface de friction est de type Colebrook """
1768
+ i, name = self.get_params_surface_friction()
1769
+ if i in [-3, -34, -5]:
1770
+ return True
1771
+ else:
1772
+ return False
1773
+
1751
1774
  def get_params_surface_friction(self) -> tuple[int, str]:
1752
1775
 
1753
1776
  if self._friction_law == 0:
wolfhece/pyshields.py CHANGED
@@ -15,7 +15,7 @@ from scipy.optimize import root_scalar
15
15
  from typing import Literal
16
16
  import logging
17
17
 
18
- from .friction_law import f_barr_bathurst
18
+ 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
@@ -530,6 +530,26 @@ def get_friction_slope_2D_Manning(q:float, h:float, n:float) -> float:
530
530
 
531
531
  return j
532
532
 
533
+ def get_friction_slope_2D_Colebrook(q:float, h:float, K:float) -> float:
534
+ """
535
+ Compute friction slope j for 2D flow with Colebrook-White friction law
536
+
537
+ :param q : discharge [m3/s]
538
+ :param h : water depth [m]
539
+ :param K : Colebrook-White friction coefficient [m]
540
+ """
541
+
542
+ four_hydraulic_radius = 4.0 * h
543
+
544
+ if four_hydraulic_radius > 0.:
545
+ reynolds = (q/h) * four_hydraulic_radius / KIN_VISCOSITY # u*4h/nu == 4q/nu
546
+ k_sur_D = K / four_hydraulic_radius
547
+ j = f_colebrook(k_sur_D, reynolds) / four_hydraulic_radius * (q/h)**2.0/2.0/GRAVITY
548
+ else:
549
+ j = 0.
550
+
551
+ return j
552
+
533
553
  def get_shear_velocity_2D_Manning(q:float, h:float, n:float) -> float:
534
554
  """
535
555
  Compute shear velocity u_* for 2D flow with Manning/Strickler friction law
@@ -542,7 +562,23 @@ def get_shear_velocity_2D_Manning(q:float, h:float, n:float) -> float:
542
562
 
543
563
  j = get_friction_slope_2D_Manning(q,h,n)
544
564
 
545
- ushear = (h*j*GRAVITY)**0.5
565
+ ushear = (GRAVITY*h*j)**0.5
566
+
567
+ return ushear
568
+
569
+ def get_shear_velocity_2D_Colebrook(q:float, h:float, K:float) -> float:
570
+ """
571
+ Compute shear velocity u_* for 2D flow with Colebrook-White friction law
572
+
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]
577
+ """
578
+
579
+ j = get_friction_slope_2D_Colebrook(q,h,K)
580
+
581
+ ushear = (GRAVITY*h*j)**0.5
546
582
 
547
583
  return ushear
548
584
 
wolfhece/wolf_array.py CHANGED
@@ -7976,6 +7976,9 @@ class WolfArray(Element_To_Draw, header_wolf):
7976
7976
  if type(other) == float:
7977
7977
  if other != 0.:
7978
7978
  newArray.array = np.ma.masked_array(self.array * other, self.array.mask, dtype=self.array.dtype)
7979
+ else:
7980
+ logging.debug(_('Multiplication by 0'))
7981
+ newArray.array = np.ma.masked_array(self.array * other, self.array.mask, dtype=self.array.dtype)
7979
7982
  else:
7980
7983
  newArray.array = np.ma.masked_array(self.array * other.array, self.array.mask, dtype=self.array.dtype)
7981
7984
  newArray.count()
@@ -10120,7 +10123,7 @@ class WolfArray(Element_To_Draw, header_wolf):
10120
10123
 
10121
10124
  if first_mask_data:
10122
10125
  self.mask_data(self.nullvalue)
10123
-
10126
+
10124
10127
  if update_palette:
10125
10128
  self.updatepalette(0)
10126
10129
 
@@ -10155,7 +10158,7 @@ class WolfArray(Element_To_Draw, header_wolf):
10155
10158
  self.origx + self.dx * self.nbx,
10156
10159
  self.origy,
10157
10160
  self.origy + self.dy * self.nby),
10158
- alpha=np.select([self.array.mask.T, ~self.array.mask.T],
10161
+ alpha=np.select([self.array.mask.T, ~self.array.mask.T],
10159
10162
  [np.zeros(self.shape).T, np.ones(self.shape).T]))
10160
10163
  else:
10161
10164
  im = ax.imshow(self.array.transpose(),
@@ -10166,7 +10169,7 @@ class WolfArray(Element_To_Draw, header_wolf):
10166
10169
  self.origy,
10167
10170
  self.origy + self.dy * self.nby),
10168
10171
  vmin=vmin, vmax=vmax,
10169
- alpha=np.select([self.array.mask.T, ~self.array.mask.T],
10172
+ alpha=np.select([self.array.mask.T, ~self.array.mask.T],
10170
10173
  [np.zeros(self.shape).T, np.ones(self.shape).T]) )
10171
10174
  ax.set_aspect('equal')
10172
10175
 
@@ -12090,13 +12093,13 @@ class WolfArrayMB(WolfArray):
12090
12093
 
12091
12094
  return newArray
12092
12095
 
12093
- def plot_matplotlib(self,
12094
- figax:tuple=None,
12095
- getdata_im:bool=False,
12096
- update_palette:bool=True,
12097
- vmin:float=None, vmax:float=None,
12098
- figsize:tuple=None,
12099
- Walonmap:bool=False,
12096
+ def plot_matplotlib(self,
12097
+ figax:tuple=None,
12098
+ getdata_im:bool=False,
12099
+ update_palette:bool=True,
12100
+ vmin:float=None, vmax:float=None,
12101
+ figsize:tuple=None,
12102
+ Walonmap:bool=False,
12100
12103
  cat:str='IMAGERIE/ORTHO_2022_ETE',
12101
12104
  first_mask_data:bool=True):
12102
12105
  """
@@ -12157,12 +12160,12 @@ class WolfArrayMB(WolfArray):
12157
12160
  # Convert to single block
12158
12161
  single_block = self.as_WolfArray()
12159
12162
 
12160
- return single_block.plot_matplotlib(figax=figax,
12161
- getdata_im=getdata_im,
12162
- update_palette=update_palette,
12163
- vmin=vmin, vmax=vmax,
12164
- figsize=figsize,
12165
- Walonmap=Walonmap,
12163
+ return single_block.plot_matplotlib(figax=figax,
12164
+ getdata_im=getdata_im,
12165
+ update_palette=update_palette,
12166
+ vmin=vmin, vmax=vmax,
12167
+ figsize=figsize,
12168
+ Walonmap=Walonmap,
12166
12169
  cat=cat,
12167
12170
  first_mask_data=first_mask_data)
12168
12171