wolfhece 2.1.127__py3-none-any.whl → 2.1.129__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/eikonal.py CHANGED
@@ -153,7 +153,8 @@ def _solve_eikonal_with_data(sources:list[tuple[int,int]],
153
153
  assert test_data.shape == where_compute.shape
154
154
 
155
155
  if len(sources) == 0:
156
- raise ValueError("No sources provided.")
156
+ logging.error("No sources provided")
157
+ return np.zeros((rows, cols))
157
158
 
158
159
  if speed is None:
159
160
  speed = np.ones((rows, cols))
@@ -195,6 +196,9 @@ def _process_submatrix(args):
195
196
  labels[0,:] = -1
196
197
  labels[-1,:] = -1
197
198
  sources = np.argwhere(np.logical_and(labels == 0, base_data != NoData))
199
+
200
+ if len(sources) == 0:
201
+ return (None, None)
198
202
  return (args, _solve_eikonal_with_data(sources, where_compute, base_data, test_data, speed, dx, dy))
199
203
 
200
204
  def _solve_eikonal_with_value_on_submatrices(where_compute:np.ndarray,
@@ -269,6 +273,8 @@ def _solve_eikonal_with_value_on_submatrices(where_compute:np.ndarray,
269
273
 
270
274
  time = np.zeros_like(where_compute)
271
275
  for slice, (sub, result) in zip(patch_slices, results):
276
+ if result is None:
277
+ continue
272
278
  useful_result = sub[3] != NoDataValue
273
279
  base_data[slice][useful_result] = sub[3][useful_result]
274
280
  time[slice][useful_result] = result[useful_result]
@@ -284,6 +290,8 @@ def _solve_eikonal_with_value_on_submatrices(where_compute:np.ndarray,
284
290
 
285
291
  time = np.zeros_like(where_compute)
286
292
  for slice, (sub, result) in zip(patch_slices, results):
293
+ if result is None:
294
+ continue
287
295
  useful_result = result != NoDataValue
288
296
  time[slice][useful_result] = result[useful_result]
289
297
 
@@ -378,7 +386,8 @@ def inpaint_waterlevel(water_level:np.ndarray | np.ma.MaskedArray,
378
386
  inplace:bool = True,
379
387
  dx:float = 1., dy:float = 1.,
380
388
  NoDataValue:float = 0.,
381
- multiprocess:bool = True) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
389
+ multiprocess:bool = True,
390
+ epsilon:float = 1e-3) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
382
391
  """ Inpaint the water level using the Fast Marching Method (FMM). Similar to the HOLES.EXE Fortran program.
383
392
 
384
393
  Assumptions:
@@ -452,9 +461,10 @@ def inpaint_waterlevel(water_level:np.ndarray | np.ma.MaskedArray,
452
461
  buildings[buildings < 0.] = 0.
453
462
 
454
463
  # If DTM is below DEM, we set the value to 1
464
+ buildings[buildings <= epsilon] = 0.
455
465
  buildings[buildings > 0.] = 1.
456
466
 
457
- # We interplate only if building cells are not already in the water_level
467
+ # We interpolate only if building cells are not already in the water_level
458
468
  comp = np.logical_and(buildings == 1., base_data != NoDataValue)
459
469
  if np.any(comp):
460
470
  logging.warning("Some building cells are already flooded.")
@@ -67,7 +67,8 @@ class Catchment:
67
67
  iP_Cloud:cloud_vertices # cloud of points containing the given coordinates (given in param files) of all subbasin outlets
68
68
 
69
69
  catchmentDict:dict[Union[str, int], Union[SubBasin, RetentionBasin]] # dictionnary containing all the elements of the catchment
70
- subBasinDict:dict[int, SubBasin] # dictionnary containing all the subbasins
70
+ subBasinDict:dict[int, SubBasin] # dictionnary containing all the subbasins with the convention dict{ID Interior Point : SubBasin object}
71
+ retentionBasinDict:dict[str, RetentionBasin] # dictionnary containing all the anthropogenic modules
71
72
 
72
73
  def __init__(self, _name, _workingDir, _plotAllSub, _plotNothing, _initWithResults=True, _catchmentFileName="", _rbFileName="", _tz=0, version=cst.VERSION_WOLFHYDRO):
73
74
  "This is the constructor of the class Catchment in which all the caractertics and the network of sub-basins will be created"
@@ -143,7 +144,7 @@ class Catchment:
143
144
 
144
145
  # Read the input files
145
146
  # read the Main File
146
- self.paramsInput = Wolf_Param(to_read=False,toShow=False)
147
+ self.paramsInput = Wolf_Param(to_read=False, toShow=False)
147
148
  self.paramsInput.ReadFile(os.path.join(self.workingDir,'Main_model.param'))
148
149
  # Get the version of WOLFHydro
149
150
  self.change_version(self.paramsInput.get_param("General information", "Version WOLFHydo"))
@@ -343,7 +344,7 @@ class Catchment:
343
344
  self._fill_cloud_retentionbasin()
344
345
 
345
346
  def get_subBasin(self, id_sorted_or_name:int | str) -> SubBasin:
346
- """
347
+ """
347
348
  This method returns the subbasin object associated with the sorted id or name given in argument.
348
349
 
349
350
  The sorted id is the one given by the Fortran code.
@@ -620,7 +621,7 @@ class Catchment:
620
621
 
621
622
  def get_retentionbasin_zones(self)-> Zones:
622
623
  """ This method returns a Zones instance of the retention basins. """
623
-
624
+
624
625
  zones = Zones()
625
626
  for curRB in self.retentionBasinDict.values():
626
627
  curRB:RetentionBasin
@@ -1390,6 +1391,75 @@ class Catchment:
1390
1391
  writer.close()
1391
1392
 
1392
1393
 
1394
+
1395
+ def save_hydro_for_2D(self, fileName:str="Hydros_2_simul2D.txt", directory:str="", format:str='%1.5e'):
1396
+ """
1397
+ Procedure that saves the data in an text file that can be read and used in a 2D model.
1398
+
1399
+ Args:
1400
+ fileName (str, optional): The name of the file to save the data to. Defaults to "Hydros_2_simul2D.txt".
1401
+ directory (str, optional): The directory to save the file in. Defaults to an empty string.
1402
+
1403
+ Returns:
1404
+ None
1405
+ """
1406
+ # Writes subbasins' hydrographs
1407
+ if(directory==""):
1408
+ directory = join(self.workingDir,"PostProcess")
1409
+
1410
+ cur_file = join(directory,fileName)
1411
+ time = np.reshape(self.time - self.time[0],(len(self.time),1))
1412
+ # Extract the data for the hydrological and anthropogenic modules
1413
+ data_subs = [cur_sub.outFlow for cur_sub in sorted(self.subBasinDict.values(), key=lambda sub: sub.iDSorted)]
1414
+ data_anth = [cur_anth.get_outFlow(whichOutFlow=name) for cur_anth in self.retentionBasinDict.values() for name in cur_anth.get_outFlow_names()]
1415
+ # Extract the column names according to their sorted subbasin indices
1416
+ col_time = ["Time [s]"]
1417
+ col_subs = [cur_sub.name for cur_sub in sorted(self.subBasinDict.values(), key=lambda sub: sub.iDSorted)]
1418
+ col_anth = [" : ".join([cur_anth.name, name])
1419
+ for cur_anth in self.retentionBasinDict.values()
1420
+ for name in cur_anth.get_outFlow_names()]
1421
+
1422
+
1423
+ all_data = np.concatenate((time, np.array(data_subs).T, np.array(data_anth).T), axis=1)
1424
+ all_columns = "\t".join(col_time+col_subs+col_anth)
1425
+
1426
+ # Save the data in a text file
1427
+ np.savetxt(cur_file, all_data, delimiter='\t', newline="\n", header=all_columns, fmt=format)
1428
+
1429
+
1430
+ def save_own_hydro_for_2D(self, fileName:str="HydrosSub_2_simul2D.txt", directory:str="", format:str='%1.5e'):
1431
+ """
1432
+ Saves subbasins' hydrographs from their own drained surface only (not taking into account the
1433
+ surface drained by the inlets or upstream elements) to a text file that can be read and used in a 2D model.
1434
+
1435
+ Args:
1436
+ fileName (str, optional): Name of the output file. Defaults to "HydrosSub_2_simul2D.txt".
1437
+ directory (str, optional): Directory where the file will be saved. Defaults to an empty string.
1438
+ format (str, optional): Format string for the data values. Defaults to '%1.5e'.
1439
+
1440
+ Returns:
1441
+ None
1442
+ """
1443
+ # Writes subbasins' hydrographs
1444
+ if(directory==""):
1445
+ directory = join(self.workingDir,"PostProcess")
1446
+
1447
+ cur_file = join(directory,fileName)
1448
+ time = np.reshape(self.time - self.time[0],(len(self.time),1))
1449
+ # Extract the data for the hydrological and anthropogenic modules
1450
+ data_subs = [cur_sub.get_myHydro(unit="m3/s") for cur_sub in sorted(self.subBasinDict.values(), key=lambda sub: sub.iDSorted)]
1451
+ # Extract the column names according to their sorted subbasin indices
1452
+ col_time = ["Time [s]"]
1453
+ col_subs = [cur_sub.name for cur_sub in sorted(self.subBasinDict.values(), key=lambda sub: sub.iDSorted)]
1454
+
1455
+
1456
+ all_data = np.concatenate((time, np.array(data_subs).T), axis=1)
1457
+ all_columns = "\t".join(col_time+col_subs)
1458
+
1459
+ # Save the data in a text file
1460
+ np.savetxt(cur_file, all_data, delimiter='\t', newline="\n", header=all_columns, fmt=format)
1461
+
1462
+
1393
1463
  def save_characteristics(self):
1394
1464
  "Procedure that saves the data in an Excel file."
1395
1465
  # Writes subbasins' main characteristics
@@ -1858,7 +1928,7 @@ class Catchment:
1858
1928
  paramsInput.SavetoFile(None)
1859
1929
 
1860
1930
 
1861
- def _correct_Umax_from_old_model(self, adapt_with_rain:bool=True):
1931
+ def _correct_Umax_from_old_model(self, adapt_with_rain:bool=True, k_opt:float=0.0, U_max_opt=0.0):
1862
1932
  fileName = "simul_soil.param"
1863
1933
  which="Umax"
1864
1934
 
@@ -1871,7 +1941,9 @@ class Catchment:
1871
1941
  paramsInput = Wolf_Param(to_read=False,toShow=False)
1872
1942
  paramsInput.ReadFile(fileToModif)
1873
1943
 
1874
- if adapt_with_rain:
1944
+ if U_max_opt>0.0:
1945
+ maxRain = U_max_opt
1946
+ elif adapt_with_rain:
1875
1947
  myInterval = paramsInput.get_param("Distributed production model parameters", "Time span soil", default_value=0.0)
1876
1948
  if myInterval==0.0:
1877
1949
  nbIntervals = len(myBasin.myRain)-1
@@ -1885,9 +1957,12 @@ class Catchment:
1885
1957
  if maxRain==0.0:
1886
1958
  logging.warning("The Umax is not adapted with the rain and its value is 0.0. It might be better to put 'adapt_with_rain' to True.")
1887
1959
 
1888
- k = paramsInput.get_param("Horton parameters", "k", default_value=0.0)
1889
- if k==0.0:
1890
- continue
1960
+ if k_opt==0.0:
1961
+ k = paramsInput.get_param("Horton parameters", "k", default_value=0.0)
1962
+ if k==0.0:
1963
+ continue
1964
+ else:
1965
+ k = k_opt
1891
1966
 
1892
1967
  U_max = maxRain/k
1893
1968
 
@@ -1899,7 +1974,7 @@ class Catchment:
1899
1974
 
1900
1975
 
1901
1976
 
1902
- def plot_all_diff_cumulRain_with_lagtime(self, interval, lagTime, selection_by_iD=[], graph_title="", show=True, writeDir="", lawNetRain=0, netRainParams={}):
1977
+ def plot_all_diff_cumulRain_with_lagtime(self, interval=0, lagTime=0, selection_by_iD=[], graph_title="", show=True, writeDir="", lawNetRain=0, netRainParams={}):
1903
1978
  """
1904
1979
 
1905
1980
  """
@@ -1951,7 +2026,7 @@ class Catchment:
1951
2026
  isOk, directory = check_path(directory, self.workingDir)
1952
2027
  if isOk<0:
1953
2028
  logging.error(_("ERROR : measuring station data path not present! "))
1954
- fileName = os.path.join(directory, self.paramsInput.get_param("Measuring stations SPW", "Filename"))
2029
+ fileName = os.path.join(directory, self.paramsInput.get_param("Measuring stations SPW", "Filename"))
1955
2030
 
1956
2031
 
1957
2032
  if os.path.exists(fileName):
@@ -2305,11 +2380,11 @@ class Catchment:
2305
2380
 
2306
2381
 
2307
2382
  return timeDelays
2308
-
2383
+
2309
2384
 
2310
2385
  def get_timeDelays_inlets(self, ref:str = "") -> dict[str, float]:
2311
-
2312
-
2386
+
2387
+
2313
2388
  if(ref==""):
2314
2389
  junctionKey = self.junctionOut
2315
2390
  else:
@@ -2317,7 +2392,7 @@ class Catchment:
2317
2392
  if junctionKey is None:
2318
2393
  logging.error("ERROR : Wrong reference to extract timeDelay !")
2319
2394
  return
2320
-
2395
+
2321
2396
  junctionKey = self.junctionOut
2322
2397
  refObj = self.catchmentDict[junctionKey]
2323
2398
  time_delays_inlets = refObj.get_timeDelays_inlets()
@@ -2535,14 +2610,14 @@ class Catchment:
2535
2610
  if self.charact_watrshd.to_update_times:
2536
2611
  self.charact_watrshd.update_times(self.time_wolf_array)
2537
2612
 
2538
-
2613
+
2539
2614
  def get_all_x_production(self, selection_by_iD: list = [], to_save:bool=True, to_plot:bool=False) -> dict:
2540
2615
  """
2541
2616
  Retrieves the x production values for all sub-basins or a specific selection of sub-basins.
2542
2617
 
2543
2618
  Args:
2544
- selection_by_iD (list, optional): A list of sub-basin IDs to retrieve x production values for.
2545
- If empty, retrieves x production values for all sub-basins.
2619
+ selection_by_iD (list, optional): A list of sub-basin IDs to retrieve x production values for.
2620
+ If empty, retrieves x production values for all sub-basins.
2546
2621
  Defaults to [].
2547
2622
 
2548
2623
  Returns:
@@ -2560,23 +2635,23 @@ class Catchment:
2560
2635
  cur_key = self.get_key_catchmentDict(curID)
2561
2636
  curBasin: SubBasin = self.catchmentDict[cur_key]
2562
2637
  all_x[curID] = curBasin.collect_x_from_production()
2563
-
2638
+
2564
2639
  if to_save:
2565
2640
  rd.write_excel_from_dict(all_x, path=self.workingDir, fileName="PostProcess/all_x.xlsx", time=self.time)
2566
2641
 
2567
2642
  return all_x
2568
-
2569
2643
 
2570
- def get_all_fractions(self, plt_dict:dict[str:np.array]={},selection_by_iD: list = [],
2644
+
2645
+ def get_all_fractions(self, plt_dict:dict[str:np.array]={},selection_by_iD: list = [],
2571
2646
  to_save:bool=True, to_plot:bool=False,
2572
- summary:str=None, summary_interval:list[datetime.datetime]=None,
2647
+ summary:str=None, summary_interval:list[datetime.datetime]=None,
2573
2648
  add_info:dict[dict[str,float]]={}) -> dict:
2574
2649
  """
2575
2650
  Retrieves the physical flux fractions values for all sub-basins or a specific selection of sub-basins.
2576
2651
 
2577
2652
  Args:
2578
- selection_by_iD (list, optional): A list of sub-basin IDs to retrieve fractions values for.
2579
- If empty, retrieves fractions values for all sub-basins.
2653
+ selection_by_iD (list, optional): A list of sub-basin IDs to retrieve fractions values for.
2654
+ If empty, retrieves fractions values for all sub-basins.
2580
2655
  Defaults to [].
2581
2656
 
2582
2657
  Returns:
@@ -2598,7 +2673,7 @@ class Catchment:
2598
2673
  summary_fractions = {}
2599
2674
  summary_dict = {}
2600
2675
  if selection_by_iD == []:
2601
- summary_fractions = {curBasin.name: curBasin.get_summary_fractions(summary=summary, interval=summary_interval)
2676
+ summary_fractions = {curBasin.name: curBasin.get_summary_fractions(summary=summary, interval=summary_interval)
2602
2677
  for curBasin in self.subBasinDict.values()}
2603
2678
  else:
2604
2679
  for curID in selection_by_iD:
@@ -2628,9 +2703,9 @@ class Catchment:
2628
2703
  else:
2629
2704
  summary_dict[key_add].append(np.nan)
2630
2705
 
2631
-
2632
2706
 
2633
- # summary_dict = {cur_key: [cur_dict[cur_key] for cur_dict in summary_fractions.values() if cur_key in cur_dict]
2707
+
2708
+ # summary_dict = {cur_key: [cur_dict[cur_key] for cur_dict in summary_fractions.values() if cur_key in cur_dict]
2634
2709
  # for cur_dict in summary_fractions.values() for cur_key in cur_dict}
2635
2710
  # all_fractions["Summary"] = summary_dict
2636
2711
 
@@ -2641,7 +2716,7 @@ class Catchment:
2641
2716
  self.plot_all_fractions(all_fractions)
2642
2717
 
2643
2718
  return all_fractions
2644
-
2719
+
2645
2720
 
2646
2721
  def plot_all_fractions(self, all_fractions:dict[str:np.array]={}, selection_by_iD:list=[], to_show:bool=False, writeDir:str="", range_data:list[datetime.datetime]=[]):
2647
2722
 
@@ -2655,7 +2730,7 @@ class Catchment:
2655
2730
  for curID in selection_by_iD:
2656
2731
  cur_key = self.get_key_catchmentDict(curID)
2657
2732
  curBasin: SubBasin = self.catchmentDict[cur_key]
2658
- curBasin.plot_all_fractions(to_show=False, writeDir=writeDir, range_data=range_data)
2733
+ curBasin.plot_all_fractions(to_show=False, writeDir=writeDir, range_data=range_data)
2659
2734
 
2660
2735
  if to_show:
2661
2736
  plt.show()
@@ -2667,8 +2742,8 @@ class Catchment:
2667
2742
  Retrieves the x production values for all sub-basins or a specific selection of sub-basins.
2668
2743
 
2669
2744
  Args:
2670
- selection_by_iD (list, optional): A list of sub-basin IDs to retrieve x production values for.
2671
- If empty, retrieves x production values for all sub-basins.
2745
+ selection_by_iD (list, optional): A list of sub-basin IDs to retrieve x production values for.
2746
+ If empty, retrieves x production values for all sub-basins.
2672
2747
  Defaults to [].
2673
2748
 
2674
2749
  Returns:
@@ -2691,15 +2766,15 @@ class Catchment:
2691
2766
  rd.write_excel_from_dict(all_iv, path=self.workingDir, fileName="PostProcess/all_iv.xlsx", time=self.time)
2692
2767
 
2693
2768
  return all_iv
2694
-
2695
-
2769
+
2770
+
2696
2771
  def activate_all_internal_variables(self, selection_by_iD: list = [])->dict:
2697
2772
  """
2698
2773
  Activates all internal variables for all sub-basins or a specific selection of sub-basins.
2699
2774
 
2700
2775
  Args:
2701
- selection_by_iD (list, optional): A list of sub-basin IDs to activate internal variables for.
2702
- If empty, activates internal variables for all sub-basins.
2776
+ selection_by_iD (list, optional): A list of sub-basin IDs to activate internal variables for.
2777
+ If empty, activates internal variables for all sub-basins.
2703
2778
  Defaults to [].
2704
2779
 
2705
2780
  Returns:
@@ -2722,8 +2797,8 @@ class Catchment:
2722
2797
  Checks the presence of internal variables for all sub-basins or a specific selection of sub-basins.
2723
2798
 
2724
2799
  Args:
2725
- selection_by_iD (list, optional): A list of sub-basin IDs to check the presence of internal variables for.
2726
- If empty, checks the presence of internal variables for all sub-basins.
2800
+ selection_by_iD (list, optional): A list of sub-basin IDs to check the presence of internal variables for.
2801
+ If empty, checks the presence of internal variables for all sub-basins.
2727
2802
  Defaults to [].
2728
2803
 
2729
2804
  Returns:
@@ -2743,7 +2818,7 @@ class Catchment:
2743
2818
  all_x[curID] = curBasin.check_presence_of_iv()
2744
2819
 
2745
2820
  return all_x
2746
-
2821
+
2747
2822
 
2748
2823
  def get_all_Qtest(self, selection_by_iD: list = [], nb_atttempts:int=-1) :
2749
2824
 
@@ -2755,17 +2830,17 @@ class Catchment:
2755
2830
  # curBasin: SubBasin = self.catchmentDict[cur_key]
2756
2831
  # q_test = curBasin.get_all_Qtest(nb_atttempts)
2757
2832
  q_test = [
2758
- self.catchmentDict[self.get_key_catchmentDict(curID)].get_all_Qtest(nb_atttempts)
2833
+ self.catchmentDict[self.get_key_catchmentDict(curID)].get_all_Qtest(nb_atttempts)
2759
2834
  for curID in selection_by_iD ]
2760
2835
 
2761
2836
  return q_test
2762
-
2837
+
2763
2838
 
2764
2839
  def _get_simulation_intervals(self):
2765
2840
  """
2766
2841
  This procedure is getting the simulation intervals of the current module.
2767
2842
  """
2768
-
2843
+
2769
2844
  nb_interv = self.paramsInput.get_param("Simulation intervals", "Nb", default_value=0)
2770
2845
  simulation_intervals = []
2771
2846
  for i in range(1, nb_interv+1):
@@ -2776,18 +2851,18 @@ class Catchment:
2776
2851
  simulation_intervals.append((di,df))
2777
2852
 
2778
2853
  return simulation_intervals
2779
-
2854
+
2780
2855
 
2781
2856
  def _set_simulation_intervals(self, simulation_intervals:list[tuple[datetime.datetime,datetime.datetime]]):
2782
2857
  """
2783
2858
  This procedure is setting the simulation intervals of the current module.
2784
2859
  """
2785
-
2860
+
2786
2861
  self.paramsInput.change_param("Simulation intervals", "Nb", len(simulation_intervals))
2787
2862
  for i, interval in enumerate(simulation_intervals):
2788
2863
  self.paramsInput.change_param("Simulation intervals", "Date begin "+str(i+1), interval[0].strftime(cst.DATE_FORMAT_HYDRO))
2789
2864
  self.paramsInput.change_param("Simulation intervals", "Date end "+str(i+1), interval[1].strftime(cst.DATE_FORMAT_HYDRO))
2790
-
2865
+
2791
2866
  self.paramsInput.SavetoFile(None)
2792
2867
  self.paramsInput.Reload(None)
2793
2868
 
@@ -2795,7 +2870,7 @@ class Catchment:
2795
2870
  @property
2796
2871
  def simulation_intervals(self) ->list[tuple[datetime.datetime,datetime.datetime]]:
2797
2872
  return self._get_simulation_intervals()
2798
-
2873
+
2799
2874
 
2800
2875
  @simulation_intervals.setter
2801
2876
  def simulation_intervals(self, value:list[tuple[datetime.datetime,datetime.datetime]]):
@@ -2806,35 +2881,61 @@ class Catchment:
2806
2881
  """
2807
2882
  This procedure is getting the temporal parameters of the current module.
2808
2883
  """
2809
-
2884
+
2810
2885
  return (self.dateBegin, self.dateEnd)
2811
-
2812
-
2886
+
2887
+
2813
2888
  def _set_temporal_parameters(self, simulation_intervals:tuple[datetime.datetime,datetime.datetime]):
2814
2889
  """
2815
2890
  This procedure is setting the temporal parameters of the current module.
2816
2891
  """
2817
-
2892
+
2818
2893
  self.dateBegin = simulation_intervals[0]
2819
2894
  self.dateEnd = simulation_intervals[1]
2820
2895
 
2821
2896
  self.paramsInput.change_param("Temporal Parameters", "Start date time", self.dateBegin.strftime(cst.DATE_FORMAT_HYDRO))
2822
2897
  self.paramsInput.change_param("Temporal Parameters", "End date time", self.dateEnd.strftime(cst.DATE_FORMAT_HYDRO))
2823
-
2898
+
2824
2899
  self.paramsInput.SavetoFile(None)
2825
2900
  self.paramsInput.Reload(None)
2826
2901
 
2827
-
2902
+
2828
2903
  @property
2829
2904
  def temporal_parameters(self) ->tuple[datetime.datetime, datetime.datetime]:
2830
2905
  return self._get_temporal_parameters()
2831
-
2906
+
2832
2907
 
2833
2908
  @temporal_parameters.setter
2834
2909
  def temporal_parameters(self, value:tuple[datetime.datetime,datetime.datetime]):
2835
2910
  self._set_temporal_parameters(value)
2836
2911
 
2837
2912
 
2913
+ def _set_IC_qif(self, keys:list[str], values:np.ndarray):
2914
+ assert len(keys) == len(values), "The number of keys should be equal to the number of values !"
2915
+ # assert len(keys) == len(self.subBasinDict), "The number of keys should be equal to the number of sub-basins !"
2916
+ # assert len(values) == len(self.subBasinDict), "The number of values should be equal to the number of sub-basins !"
2917
+ fileName = "simul_if.param"
2918
+ group = "Initial conditions"
2919
+ key = "Outflow"
2920
+
2921
+ for iBasin in range(1,len(self.subBasinDict)+1):
2922
+ if self.subBasinDict[iBasin].name in keys:
2923
+ index = np.where(np.array(keys) == self.subBasinDict[iBasin].name)[0][0]
2924
+ else:
2925
+ logging.warning(f"The sub-basin {self.subBasinDict[iBasin].name} is not in the keys list !")
2926
+ continue
2927
+ myBasin = self.subBasinDict[iBasin]
2928
+ dirID = myBasin.iDSorted
2929
+
2930
+ fileToModif = os.path.join(self.workingDir, "Subbasin_" + str(dirID), fileName)
2931
+
2932
+ paramsInput = Wolf_Param(to_read=False,toShow=False)
2933
+ paramsInput.ReadFile(fileToModif)
2934
+ paramsInput.change_param(group, key, values[index])
2935
+ paramsInput.SavetoFile(None)
2936
+ paramsInput.Reload(None)
2937
+
2938
+
2838
2939
  def make_nd_array(self, c_pointer, shape, dtype=np.float64, order='C', own_data=True,readonly=False):
2839
2940
  arr_size = np.prod(shape[:]) * np.dtype(dtype).itemsize
2840
2941
 
@@ -419,10 +419,10 @@ class Comparison:
419
419
  tzPlot = plotDict["General Parameters"]["Time Zone Plot"]
420
420
  tzDelta = datetime.timedelta(hours=tzPlot)
421
421
 
422
- if(envelop and not("Ref Name" in plotDict["General Parameters"])):
423
- refName = "Catchment 1"
424
- else:
425
- refName = plotDict["General Parameters"]["Ref Name"]
422
+ # if(envelop and not("Ref Name" in plotDict["General Parameters"])):
423
+ # refName = "Catchment 1"
424
+ # else:
425
+ # refName = plotDict["General Parameters"]["Ref Name"]
426
426
 
427
427
  if(not("Add Table" in plotDict["General Parameters"])):
428
428
  addTable = False
@@ -524,7 +524,7 @@ class Comparison:
524
524
  yLabels = []
525
525
  if(not("Catchment traits" in plotDict["General Parameters"])):
526
526
  myTraits = []
527
- rain = []
527
+ rain = None
528
528
  z = []
529
529
  nbAddRain=0
530
530
  y_labelAddRain = []
@@ -721,7 +721,7 @@ class Comparison:
721
721
  myTraits.append('-')
722
722
 
723
723
  if(sameRain and displayRain):
724
- if(rain==[]):
724
+ if(rain is None):
725
725
  rain = curCatch.subBasinDict[id].rain/curCatch.subBasinDict[id].surfaceDrainedHydro*3.6
726
726
  elif(displayRain):
727
727
  upperPlot = True
@@ -748,7 +748,7 @@ class Comparison:
748
748
  myTraits.append('-')
749
749
 
750
750
  if(sameRain and displayRain):
751
- if(rain==[]):
751
+ if(rain is None):
752
752
  rain = curCatch.subBasinDict[id].rain/curCatch.subBasinDict[id].surfaceDrainedHydro*3.6
753
753
  elif(displayRain):
754
754
  upperPlot = True
@@ -801,7 +801,7 @@ class Comparison:
801
801
  if("Measures" in plotDict[basinNames[id]]):
802
802
  Measures = plotDict[basinNames[id]]["Measures"]
803
803
  myMeasure = Measures.myHydro
804
- yLabels.append(_("Measures"))
804
+ yLabels.append(_("Measurement"))
805
805
  catchColorsAddData.append('k')
806
806
  myTraits.append('-')
807
807
  if(Measures.surfaceDrainedHydro>0.0):
@@ -904,6 +904,11 @@ class Comparison:
904
904
  else:
905
905
  dt = plotDict["General Parameters"]["Dt"]
906
906
 
907
+ if(not("Add Table" in plotDict["General Parameters"])):
908
+ addTable = False
909
+ else:
910
+ addTable = plotDict["General Parameters"]["Add Table"]
911
+
907
912
  # if(envelop and not("Ref Name" in plotDict["General Parameters"])):
908
913
  # refName = "Catchment 1"
909
914
 
@@ -1029,7 +1034,7 @@ class Comparison:
1029
1034
  if("Measures" in plotDict[RBNames[id]]):
1030
1035
  Measures = plotDict[RBNames[id]]["Measures"]
1031
1036
  myMeasure = Measures.myHydro
1032
- yLabels.append(_("Measures"))
1037
+ yLabels.append(_("Measurement"))
1033
1038
  catchColorsAddData.append('k')
1034
1039
  myTraits.append('--')
1035
1040
  else:
@@ -1052,15 +1057,17 @@ class Comparison:
1052
1057
 
1053
1058
 
1054
1059
  # Plot Rains
1055
- yTitles = "Hauteurs d'eau [m]"
1056
- writeFileDef = writeFile + "_H_" + graph_title.replace(".","")
1060
+ yTitles = _("Water level [m]")
1061
+ writeFileDef = os.path.join(writeFile, "H_" + graph_title.replace(".",""))
1057
1062
  if(Measures is not None):
1058
1063
  ph.plot_hydro(nbCatchment+nbAddData, y1,x_title=x_title, y_titles=yTitles, beginDate=beginDateRB+beginDateAddData,endDate=endDateRB+endDateAddData,dt=dt+dtAddData,graph_title=graph_title, \
1059
1064
  y_labels=yLabels,rangeData=xRange,y_data_range=yRange,myColors=catchColors+catchColorsAddData,typeOfTraits=myTraits,writeFile=writeFileDef,\
1060
- measures=myMeasure,beginDateMeasure=Measures.dateBegin+tzDelta, endDateMeasure=Measures.dateEnd+tzDelta,dtMeasure=Measures.deltaT,deltaMajorTicks=86400/2.0,deltaMinorTicks=3600)
1065
+ measures=myMeasure,beginDateMeasure=Measures.dateBegin+tzDelta, endDateMeasure=Measures.dateEnd+tzDelta,dtMeasure=Measures.deltaT,deltaMajorTicks=86400/2.0,deltaMinorTicks=3600,
1066
+ addTable=addTable)
1061
1067
  else:
1062
1068
  ph.plot_hydro(nbCatchment+nbAddData, y1,x_title=x_title, y_titles=yTitles, beginDate=beginDateRB+beginDateAddData,endDate=endDateRB+endDateAddData,dt=dt+dtAddData,graph_title=graph_title, \
1063
- y_labels=yLabels,rangeData=xRange,y_data_range=yRange,myColors=catchColors+catchColorsAddData,typeOfTraits=myTraits,writeFile=writeFileDef,deltaMajorTicks=86400/2.0,deltaMinorTicks=3600)
1069
+ y_labels=yLabels,rangeData=xRange,y_data_range=yRange,myColors=catchColors+catchColorsAddData,typeOfTraits=myTraits,writeFile=writeFileDef,deltaMajorTicks=86400/2.0,deltaMinorTicks=3600,
1070
+ addTable=addTable)
1064
1071
 
1065
1072
  if(show):
1066
1073
  plt.show()
@@ -1175,7 +1182,7 @@ class Comparison:
1175
1182
  yLabels = []
1176
1183
  if(not("Catchment traits" in plotDict["General Parameters"])):
1177
1184
  myTraits = []
1178
- rain = []
1185
+ rain = None
1179
1186
  z = []
1180
1187
  nbAddRain=0
1181
1188
  y_labelAddRain = []
@@ -1308,7 +1315,7 @@ class Comparison:
1308
1315
  if("Measures" in plotDict[RBNames[id]]):
1309
1316
  Measures = plotDict[RBNames[id]]["Measures"]
1310
1317
  myMeasure = Measures.myHydro
1311
- yLabels.append(_("Measures"))
1318
+ yLabels.append(_("Measurement"))
1312
1319
  catchColorsAddData.append('k')
1313
1320
  myTraits.append('-')
1314
1321
  if(Measures.surfaceDrainedHydro>0.0):
@@ -1387,7 +1394,7 @@ class Comparison:
1387
1394
 
1388
1395
 
1389
1396
 
1390
- def plot_all_diff_cumulRain_with_lagtime(self, interval, selection_by_iD=[], writeDir=""):
1397
+ def plot_all_diff_cumulRain_with_lagtime(self, interval=0, selection_by_iD=[], writeDir=""):
1391
1398
 
1392
1399
  for idCatch in self.myCatchments:
1393
1400
  curCatch:Catchment = self.myCatchments[idCatch]['Object']
@@ -1529,10 +1536,7 @@ class Comparison:
1529
1536
  self.plotDict[stationKey]["Add Data"]["Dt"] = []
1530
1537
 
1531
1538
  for element in myAddDataObj:
1532
- if addDataUnits == "mm/h":
1533
- self.plotDict[stationKey]["Add Data"]["Data"].append(element.myHydro[:])
1534
- else:
1535
- self.plotDict[stationKey]["Add Data"]["Data"].append(element.myHydro[:]*element.surfaceDrained/3.6)
1539
+ self.plotDict[stationKey]["Add Data"]["Data"].append(element.get_myHydro(unit=addDataUnits))
1536
1540
  self.plotDict[stationKey]["Add Data"]["Date Begin"].append(element.dateBegin)
1537
1541
  self.plotDict[stationKey]["Add Data"]["Date End"].append(element.dateEnd)
1538
1542
  self.plotDict[stationKey]["Add Data"]["Dt"].append(element.deltaT)
@@ -1579,7 +1583,7 @@ class Comparison:
1579
1583
 
1580
1584
 
1581
1585
 
1582
- def plot_Nash_and_peak(self, stationKey:list[str, int], measures:list[SubBasin], intervals:list=[]):
1586
+ def plot_Nash_and_peak(self, stationKey:list[str, int], measures:list[SubBasin], intervals:list=[], toShow:bool=True):
1583
1587
  assert len(stationKey) == len(measures)
1584
1588
 
1585
1589
  all_ns = {stationKey[i]: [ self.myCatchments[el]["Object"].get_sub_Nash(measures[i], stationKey[i], intervals)
@@ -1662,8 +1666,8 @@ class Comparison:
1662
1666
  type_of_data = ["Nash", r"$ \frac{Q^{s}_{max}-Q^{m}_{max}}{Q^{m}_{max}} $ "]
1663
1667
  type_of_data_names = ["Nash", "Exceedance"]
1664
1668
 
1665
- ph.bar_Nash_n_other(all_data, all_colors, nb_x=len(intervals), nb_data=len(type_of_model), nb_lines=nb_stations,
1666
- y_titles=type_of_data, x_titles=all_names, nameModel=type_of_model, line_names=sorted_keys, toShow=False)
1669
+ # ph.bar_Nash_n_other(all_data, all_colors, nb_x=len(intervals), nb_data=len(type_of_model), nb_lines=nb_stations,
1670
+ # y_titles=type_of_data, x_titles=all_names, nameModel=type_of_model, line_names=sorted_keys, toShow=False)
1667
1671
 
1668
1672
  # =========
1669
1673
  # =========
@@ -1700,5 +1704,5 @@ class Comparison:
1700
1704
  ph.table_Nash_n_other(cur_data, name_of_data,
1701
1705
  row_names=sorted_keys, column_names=all_names,
1702
1706
  writeFile=file_name, toShow=False)
1703
-
1704
- plt.show()
1707
+ if toShow:
1708
+ plt.show()