wolfhece 2.1.126__py3-none-any.whl → 2.1.128__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.
@@ -81,7 +81,7 @@ class Node_Watershed:
81
81
  self.cums=0.
82
82
  else:
83
83
  self.cums = self.down.cums+self.incrs
84
- for curup in self.up:
84
+ for curup in self.up:
85
85
  curup.incr_curvi()
86
86
 
87
87
  def mean_slope_up(self, threshold:float)-> float:
@@ -139,7 +139,7 @@ class Node_Watershed:
139
139
  """ Distance euclidienne """
140
140
 
141
141
  return np.sqrt(pow(self.x-x,2)+pow(self.y-y,2))
142
-
142
+
143
143
  def get_up_nodes(self, excluded_node:list["Node_Watershed"]=[]):
144
144
  """
145
145
  Get all upstream nodes
@@ -148,7 +148,7 @@ class Node_Watershed:
148
148
  all_up = [self]
149
149
  all_rivers = [self] if self.river else []
150
150
  all_runoff = [] if self.river else [self]
151
-
151
+
152
152
  for curup in self.up:
153
153
 
154
154
  if curup in excluded_node:
@@ -164,7 +164,7 @@ class Node_Watershed:
164
164
  all_up.extend(up)
165
165
  all_rivers.extend(river)
166
166
  all_runoff.extend(runoff)
167
-
167
+
168
168
  return all_up, all_rivers, all_runoff
169
169
 
170
170
  def get_up_nodes_same_sub(self, excluded_node:list["Node_Watershed"]=[]):
@@ -175,7 +175,7 @@ class Node_Watershed:
175
175
  all_up = [self]
176
176
  all_rivers = [self] if self.river else []
177
177
  all_runoff = [] if self.river else [self]
178
-
178
+
179
179
  for curup in self.up:
180
180
 
181
181
  if curup in excluded_node:
@@ -185,7 +185,7 @@ class Node_Watershed:
185
185
  if curup.sub == self.sub:
186
186
  all_up.append(curup)
187
187
  added = True
188
-
188
+
189
189
  if curup.river:
190
190
  all_rivers.append(curup)
191
191
  else:
@@ -196,9 +196,9 @@ class Node_Watershed:
196
196
  all_up.extend(up)
197
197
  all_rivers.extend(river)
198
198
  all_runoff.extend(runoff)
199
-
199
+
200
200
  return all_up, all_rivers, all_runoff
201
-
201
+
202
202
  def get_up_runoff_nodes(self):
203
203
  """
204
204
  Get all upstream runoff nodes
@@ -208,9 +208,9 @@ class Node_Watershed:
208
208
  for curup in self.up:
209
209
  if not curup.river:
210
210
  all_up += curup.get_up_runoff_nodes()
211
-
211
+
212
212
  return all_up
213
-
213
+
214
214
  def get_up_runoff_nodes_same_sub(self):
215
215
  """
216
216
  Get all upstream runoff nodes in the same sub-basin
@@ -220,10 +220,10 @@ class Node_Watershed:
220
220
  for curup in self.up:
221
221
  if curup.sub == self.sub and not curup.river:
222
222
  all_up += curup.get_up_runoff_nodes_same_sub()
223
-
223
+
224
224
  return all_up
225
225
 
226
-
226
+
227
227
  def get_up_rivernodes(self):
228
228
  """
229
229
  Get all upstream river nodes
@@ -232,9 +232,9 @@ class Node_Watershed:
232
232
  all_up = [self]
233
233
  for curup in self.upriver:
234
234
  all_up += curup.get_up_rivernodes()
235
-
235
+
236
236
  return all_up
237
-
237
+
238
238
  def get_up_rivernodes_same_sub(self):
239
239
  """
240
240
  Get all upstream river nodes in the same sub-basin
@@ -244,9 +244,9 @@ class Node_Watershed:
244
244
  for curup in self.upriver:
245
245
  if curup.sub == self.sub:
246
246
  all_up += curup.get_up_rivernodes_same_sub()
247
-
247
+
248
248
  return all_up
249
-
249
+
250
250
  def get_up_reaches_same_sub(self) -> list[int]:
251
251
  """
252
252
  Get all upstream reaches in the same sub-basin
@@ -258,7 +258,7 @@ class Node_Watershed:
258
258
  all_up += curup.get_up_reaches_same_sub()
259
259
 
260
260
  return np.unique(all_up).tolist()
261
-
261
+
262
262
  def get_down_reaches_same_sub(self) -> list[int]:
263
263
  """
264
264
  Get all downstream reaches in the same sub-basin
@@ -269,7 +269,7 @@ class Node_Watershed:
269
269
  if self.down.sub == self.sub:
270
270
  all_down += self.down.get_down_reaches_same_sub()
271
271
 
272
- return np.unique(all_down).tolist()
272
+ return np.unique(all_down).tolist()
273
273
 
274
274
  def get_down_nodes(self):
275
275
  """
@@ -279,7 +279,7 @@ class Node_Watershed:
279
279
  all_down = [self]
280
280
  if self.down is not None:
281
281
  all_down += self.down.get_down_nodes()
282
-
282
+
283
283
  return all_down
284
284
 
285
285
  def get_down_nodes_same_sub(self):
@@ -291,7 +291,7 @@ class Node_Watershed:
291
291
  if self.down is not None:
292
292
  if self.down.sub == self.sub:
293
293
  all_down += self.down.get_down_nodes_same_sub()
294
-
294
+
295
295
  return all_down
296
296
 
297
297
  class RiverSystem:
@@ -390,11 +390,11 @@ class RiverSystem:
390
390
 
391
391
  return
392
392
  """
393
-
393
+
394
394
  if isinstance(xy, vector):
395
- centroid = xy.asshapely_pol().centroid
395
+ centroid = xy.centroid
396
396
  xy = np.array([[centroid.x, centroid.y]])
397
-
397
+
398
398
  dd, ii = self.kdtree.query(xy, nb)
399
399
 
400
400
  if isinstance(ii, int | np.int64):
@@ -404,7 +404,7 @@ class RiverSystem:
404
404
  return dd[0], self.all_nodes[ii[0]]
405
405
  else:
406
406
  return dd, [self.all_nodes[curi] for curi in ii]
407
-
407
+
408
408
  def get_nodes_in_reaches(self, reaches:list[int])->list[Node_Watershed]:
409
409
  """
410
410
  Get nodes in a reaches
@@ -412,23 +412,23 @@ class RiverSystem:
412
412
  all_nodes = []
413
413
  for cur_reach in reaches:
414
414
  all_nodes.extend(self.reaches['reaches'][cur_reach]['baselist'])
415
-
415
+
416
416
  return all_nodes
417
-
417
+
418
418
  def get_downstream_node_in_reach(self, reach:int)->Node_Watershed:
419
419
  """
420
420
  Get downstream node in a reach
421
421
  """
422
422
 
423
423
  return self.reaches['reaches'][reach]['baselist'][0]
424
-
424
+
425
425
  def get_upstream_node_in_reach(self, reach:int)->Node_Watershed:
426
426
  """
427
427
  Get upstream node in a reach
428
428
  """
429
429
 
430
430
  return self.reaches['reaches'][reach]['baselist'][-1]
431
-
431
+
432
432
  def get_downstream_reaches(self, node:Node_Watershed)->list[int]:
433
433
  """
434
434
  Get index of downstream reaches
@@ -441,7 +441,7 @@ class RiverSystem:
441
441
  curnode = curnode.down
442
442
 
443
443
  return list(np.unique(downreaches))
444
-
444
+
445
445
  def get_kdtree_downstream(self, node:Node_Watershed)-> tuple[list[Node_Watershed], KDTree]:
446
446
  """
447
447
  Get KDTree of downstream reaches
@@ -449,7 +449,7 @@ class RiverSystem:
449
449
 
450
450
  downreaches = self.get_downstream_reaches(node)
451
451
  return self.get_kdtree_from_reaches(downreaches)
452
-
452
+
453
453
  def get_kdtree_from_reaches(self, reaches:list[int])->tuple[list[Node_Watershed], KDTree]:
454
454
  """
455
455
  Get KDTree from a list of reaches
@@ -458,7 +458,7 @@ class RiverSystem:
458
458
  nodes = self.get_nodes_in_reaches(reaches)
459
459
  xy = [[curnode.x, curnode.y] for curnode in nodes]
460
460
  return nodes, KDTree(xy)
461
-
461
+
462
462
  def get_downstream_reaches_excluded(self, node:Node_Watershed, excluded:list[int])->list[int]:
463
463
  """
464
464
  Get index of downstream reaches, excepted the excluded ones
@@ -488,7 +488,7 @@ class RiverSystem:
488
488
  curnode = curnode.down
489
489
 
490
490
  return curnode
491
-
491
+
492
492
  def get_cums(self, whichreach:int=None, whichup:int=None):
493
493
  """
494
494
  Récupération de la position curvi
@@ -576,7 +576,7 @@ class RiverSystem:
576
576
 
577
577
  xy = [[curnode.x, curnode.y] for curnode in self.upstreams['list']]
578
578
  return np.array(xy)
579
-
579
+
580
580
  def get_nearest_upstream(self, xy:np.ndarray, nb:int) -> tuple[np.ndarray, list[Node_Watershed]]:
581
581
  """
582
582
  Recherche des amonts les plus proches
@@ -587,7 +587,7 @@ class RiverSystem:
587
587
  dd, ii =loc_kd.query(xy, nb)
588
588
 
589
589
  return dd, [self.upstreams['list'][curi] for curi in ii]
590
-
590
+
591
591
  def create_index(self):
592
592
  """
593
593
  Incrément d'index depuis l'amont jusque l'exutoire final
@@ -1427,11 +1427,11 @@ class SubWatershed:
1427
1427
  self.name:str = name # name of the subwatershed
1428
1428
  self.mask:WolfArray = mask # WolfArray of the subwatershed -- All nodes are masked except the subwatershed
1429
1429
  self.mask.count()
1430
-
1430
+
1431
1431
  self.nodes:list[Node_Watershed] = nodes # all nodes in the subwatershed
1432
1432
  self.rivers:list[Node_Watershed] = rivers # only rivers - sorted by dem value --> outlet is the first one
1433
1433
  self.runoff:list[Node_Watershed] = runoff
1434
-
1434
+
1435
1435
  self.idx_reaches = np.unique(np.asarray([x.reach for x in rivers]))
1436
1436
 
1437
1437
  self._index_sorted = idx
@@ -1444,23 +1444,23 @@ class SubWatershed:
1444
1444
  """ Vérification si le sous-bassin est virtuel """
1445
1445
 
1446
1446
  return self._is_virtual
1447
-
1447
+
1448
1448
  @property
1449
1449
  def surface(self) -> float:
1450
1450
  """ Surface du bassin versant en m² """
1451
1451
  return self.mask.nbnotnull * self.mask.dx * self.mask.dy
1452
-
1452
+
1453
1453
  @property
1454
1454
  def area(self) -> float:
1455
1455
  """ Surface du bassin versant en km² """
1456
1456
  return self.surface / 1.e6
1457
-
1457
+
1458
1458
  @property
1459
1459
  def area_outlet(self) -> float:
1460
1460
  """ Surface du bassin à l'exutoire """
1461
1461
 
1462
1462
  return self.outlet.uparea
1463
-
1463
+
1464
1464
  @property
1465
1465
  def outlet(self) -> Node_Watershed:
1466
1466
  """ Outlet of the subbasin """
@@ -1471,7 +1471,7 @@ class SubWatershed:
1471
1471
  """ Vérification si un bief est dans le sous-bassin """
1472
1472
 
1473
1473
  return idx_reach in self.idx_reaches
1474
-
1474
+
1475
1475
  def is_in_rivers(self, node:Node_Watershed) -> bool:
1476
1476
  """ Vérification si un noeud est dans les rivières """
1477
1477
 
@@ -1483,36 +1483,36 @@ class SubWatershed:
1483
1483
  """
1484
1484
 
1485
1485
  return [x for x in self.rivers if x.reach==idx_reach]
1486
-
1486
+
1487
1487
  def get_nearest_river(self, x, y) -> Node_Watershed:
1488
1488
  """
1489
1489
  Récupération du noeud de rivière le plus proche
1490
1490
  """
1491
1491
 
1492
1492
  return min(self.rivers, key=lambda x: x.distance(x,y))
1493
-
1493
+
1494
1494
  def get_max_area_in_reach(self, idx_reach:int) -> float:
1495
1495
  """
1496
1496
  Récupération de la surface maximale dans un bief
1497
1497
  """
1498
1498
 
1499
1499
  return max([x.uparea for x in self.get_list_nodes_river(idx_reach)])
1500
-
1500
+
1501
1501
  def get_min_area_in_reach(self, idx_reach:int) -> float:
1502
1502
  """
1503
1503
  Récupération de la surface minimale dans un bief
1504
1504
  """
1505
1505
 
1506
1506
  return min([x.uparea for x in self.get_list_nodes_river(idx_reach)])
1507
-
1508
- def get_min_area_along_reaches(self, reaches:list[int], starting_node:Node_Watershed = None) -> float:
1507
+
1508
+ def get_min_area_along_reaches(self, reaches:list[int], starting_node:Node_Watershed = None) -> float:
1509
1509
  """ Aire drainée à la limite amont du ss-bassin """
1510
-
1510
+
1511
1511
  if starting_node is None:
1512
1512
  starting_node = self.outlet
1513
-
1513
+
1514
1514
  upriver = starting_node.upriver
1515
-
1515
+
1516
1516
  area_min = []
1517
1517
 
1518
1518
  idx_reach = 0
@@ -1525,12 +1525,12 @@ class SubWatershed:
1525
1525
  return None
1526
1526
  else:
1527
1527
  return min(area_min)
1528
-
1528
+
1529
1529
  def get_up_rivernode_outside_sub(self, starting_node:Node_Watershed, reaches:list[int]) -> Node_Watershed:
1530
1530
  """ Récupération du noeud de rivière en amont du sous-bassin """
1531
-
1532
- def up_in_reaches(node:Node_Watershed, reaches:list[int]) -> Node_Watershed:
1533
-
1531
+
1532
+ def up_in_reaches(node:Node_Watershed, reaches:list[int]) -> Node_Watershed:
1533
+
1534
1534
  if len(node.upriver) == 0:
1535
1535
  # No upstream node
1536
1536
  return node
@@ -1539,8 +1539,8 @@ class SubWatershed:
1539
1539
  for curup in node.upriver:
1540
1540
  if curup.reach in reaches:
1541
1541
  # If the reach is in the list, return the node
1542
- return curup
1543
-
1542
+ return curup
1543
+
1544
1544
  # No node found in the list of reaches
1545
1545
  return node
1546
1546
 
@@ -1559,20 +1559,20 @@ class SubWatershed:
1559
1559
 
1560
1560
  def get_area_outside_sub_if_exists(self, starting_node:Node_Watershed, reaches:list[int]) -> float:
1561
1561
  """ Aire drainée en amont du sous-bassin """
1562
-
1562
+
1563
1563
  up_outside = self.get_up_rivernode_outside_sub(starting_node, reaches)
1564
-
1564
+
1565
1565
  if up_outside is None:
1566
1566
  return 0.
1567
1567
  else:
1568
- return up_outside.uparea
1569
-
1568
+ return up_outside.uparea
1569
+
1570
1570
  def get_river_nodes_from_upareas(self, min_area:float, max_area:float) -> list[Node_Watershed]:
1571
1571
  """
1572
1572
  Récupération des noeuds de rivière entre deux surfacesde BV.
1573
1573
 
1574
1574
  Les surfaces sont exprimées en km².
1575
-
1575
+
1576
1576
  Les bornes sont incluses.
1577
1577
 
1578
1578
  :param min_area: surface minimale
@@ -1584,12 +1584,12 @@ class SubWatershed:
1584
1584
  def is_in_subwatershed(self, vec:vector) -> bool:
1585
1585
  """ Vérification si un vecteur est dans le sous-bassin """
1586
1586
 
1587
- centroid = vec.asshapely_pol().centroid
1587
+ centroid = vec.centroid
1588
1588
 
1589
1589
  i, j = self.mask.get_ij_from_xy(centroid.x, centroid.y)
1590
1590
 
1591
1591
  return self.mask.array.mask[i,j] == False
1592
-
1592
+
1593
1593
  def filter_zones(self, zones_to_filter:Zones, force_virtual_if_any:bool = False) -> list[vector]:
1594
1594
  """
1595
1595
  Filtrage des zones pour ne garder que celle se trouvant dans le sous-bassin
@@ -1599,7 +1599,7 @@ class SubWatershed:
1599
1599
  return self._src_sub.filter_zones(zones_to_filter)
1600
1600
 
1601
1601
  return [curvec for curzone in zones_to_filter.myzones for curvec in curzone.myvectors if self.is_in_subwatershed(curvec)]
1602
-
1602
+
1603
1603
  def get_virtual_subwatershed(self, outlet:Node_Watershed, excluded_nodes:list[Node_Watershed] = []) -> "SubWatershed":
1604
1604
  """
1605
1605
  Création d'un sous-bassin virtuel sur base d'une maille rivière aval
@@ -1617,20 +1617,20 @@ class SubWatershed:
1617
1617
  for curnode in all:
1618
1618
  mymask.array.mask[curnode.i,curnode.j] = False
1619
1619
 
1620
- newsub = SubWatershed(self.parent,
1621
- self.name + '_virtual',
1622
- self.parent.nb_subs + 1,
1623
- mymask,
1620
+ newsub = SubWatershed(self.parent,
1621
+ self.name + '_virtual',
1622
+ self.parent.nb_subs + 1,
1623
+ mymask,
1624
1624
  all,
1625
1625
  runoff,
1626
- river,
1626
+ river,
1627
1627
  )
1628
-
1628
+
1629
1629
  newsub._is_virtual = True
1630
1630
  newsub._src_sub = self
1631
-
1631
+
1632
1632
  return newsub
1633
-
1633
+
1634
1634
  def get_downstream_node_in_reach(self, reach:int) -> Node_Watershed:
1635
1635
  """
1636
1636
  Récupération du noeud aval dans un bief
@@ -1758,7 +1758,7 @@ class Watershed:
1758
1758
  @property
1759
1759
  def resolution(self):
1760
1760
  return self.header.dx
1761
-
1761
+
1762
1762
  # def impose_sorted_index_subbasins(self, new_idx=list[int]):
1763
1763
  # """
1764
1764
  # Tri des sous-bassins
@@ -1776,7 +1776,7 @@ class Watershed:
1776
1776
  self.get_subwatershed(cursub).name = curname
1777
1777
 
1778
1778
  def add_virtual_subwatershed(self, subwater:SubWatershed):
1779
- """
1779
+ """
1780
1780
  Ajout d'un sous-bassin virtuel
1781
1781
  """
1782
1782
 
@@ -1790,12 +1790,12 @@ class Watershed:
1790
1790
  """
1791
1791
 
1792
1792
  newsub = self.get_subwatershed(outlet.sub).get_virtual_subwatershed(outlet, excluded_nodes=excluded_nodes)
1793
-
1793
+
1794
1794
  self.add_virtual_subwatershed(newsub)
1795
1795
 
1796
1796
  return newsub
1797
1797
 
1798
- def get_xy_downstream_node(self,
1798
+ def get_xy_downstream_node(self,
1799
1799
  starting_node:Node_Watershed,
1800
1800
  limit_to_sub:bool = False):
1801
1801
  """
@@ -1809,9 +1809,9 @@ class Watershed:
1809
1809
 
1810
1810
  return [[cur.x, cur.y] for cur in down]
1811
1811
 
1812
- def get_xy_upstream_node(self,
1813
- starting_node:Node_Watershed,
1814
- limit_to_sub:bool = False,
1812
+ def get_xy_upstream_node(self,
1813
+ starting_node:Node_Watershed,
1814
+ limit_to_sub:bool = False,
1815
1815
  limit_to_river:bool = False,
1816
1816
  limit_to_runoff:bool = False) -> list[list[float]]:
1817
1817
  """
@@ -1836,9 +1836,9 @@ class Watershed:
1836
1836
  up, all_river, all_runoff = starting_node.get_up_nodes()
1837
1837
 
1838
1838
  return [[cur.x, cur.y] for cur in up]
1839
-
1840
- def get_array_from_upstream_node(self,
1841
- starting_node:Node_Watershed,
1839
+
1840
+ def get_array_from_upstream_node(self,
1841
+ starting_node:Node_Watershed,
1842
1842
  limit_to_sub:bool = False):
1843
1843
  """
1844
1844
  Récupération de l'array à partir d'un noeud amont
@@ -1875,8 +1875,8 @@ class Watershed:
1875
1875
  newarray.mask_data(0.)
1876
1876
 
1877
1877
  return newarray
1878
-
1879
- def get_vector_from_upstream_node(self,
1878
+
1879
+ def get_vector_from_upstream_node(self,
1880
1880
  starting_node:Node_Watershed,
1881
1881
  limit_to_sub:bool = False):
1882
1882
  """ Return a vector contouring the upstream area """
@@ -1895,29 +1895,29 @@ class Watershed:
1895
1895
  """
1896
1896
  Récupération d'un sous-bassin sur base de l'index trié
1897
1897
  """
1898
-
1898
+
1899
1899
  if isinstance(idx_sorted_or_name, str):
1900
1900
  for cur_sub in self.subcatchments:
1901
1901
  if cur_sub.name == idx_sorted_or_name:
1902
1902
  return cur_sub
1903
-
1903
+
1904
1904
  if len(self.virtualcatchments)>0:
1905
1905
  for cur_sub in self.virtualcatchments:
1906
1906
  if cur_sub.name == idx_sorted_or_name:
1907
1907
  return cur_sub
1908
-
1909
- elif isinstance(idx_sorted_or_name, int):
1908
+
1909
+ elif isinstance(idx_sorted_or_name, int):
1910
1910
  for cur_sub in self.subcatchments:
1911
1911
  if cur_sub._index_sorted+1 == idx_sorted_or_name:
1912
- return cur_sub
1913
-
1912
+ return cur_sub
1913
+
1914
1914
  if len(self.virtualcatchments)>0:
1915
1915
  for cur_sub in self.virtualcatchments:
1916
1916
  if cur_sub._index_sorted+1 == idx_sorted_or_name:
1917
1917
  return cur_sub
1918
1918
  else:
1919
1919
  logging.error(_('Index must be an integer or a string!'))
1920
-
1920
+
1921
1921
  return None
1922
1922
 
1923
1923
  def get_node_from_ij(self, i:int,j:int):
@@ -2657,7 +2657,7 @@ class Watershed:
2657
2657
  idx_sub = self.subs_array.array[i,j]
2658
2658
 
2659
2659
  return self.subcatchments[idx_sub-1]
2660
-
2660
+
2661
2661
  def get_subwatershed_from_xy(self, x:float, y:float) -> SubWatershed:
2662
2662
  """
2663
2663
  Récupération d'un sous-bassin sur base des coordonnées (x,y)
@@ -2667,7 +2667,7 @@ class Watershed:
2667
2667
 
2668
2668
  i,j = self.header.get_ij_from_xy(x,y)
2669
2669
  return self.get_subwatershed_from_ij(i,j)
2670
-
2670
+
2671
2671
  def get_subwatershed_from_vector(self, vec:vector) -> tuple[SubWatershed, bool, list[SubWatershed]]:
2672
2672
  """
2673
2673
  Récupération d'un sous-bassin sur base d'un vecteur.
@@ -2679,7 +2679,7 @@ class Watershed:
2679
2679
  :return: tuple(SubWatershed, bool, list[SubWatershed]) : sous-bassin, entièrement dans le sous-bassin, autres sous-bassins
2680
2680
  """
2681
2681
 
2682
- centroid = vec.asshapely_pol().centroid
2682
+ centroid = vec.centroid
2683
2683
 
2684
2684
  sub = self.get_subwatershed_from_xy(centroid.x, centroid.y)
2685
2685