wolfhece 2.2.38__py3-none-any.whl → 2.2.39__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.
Files changed (49) hide show
  1. wolfhece/Coordinates_operations.py +5 -0
  2. wolfhece/GraphNotebook.py +72 -1
  3. wolfhece/GraphProfile.py +1 -1
  4. wolfhece/MulticriteriAnalysis.py +1579 -0
  5. wolfhece/PandasGrid.py +62 -1
  6. wolfhece/PyCrosssections.py +194 -43
  7. wolfhece/PyDraw.py +891 -73
  8. wolfhece/PyGui.py +913 -72
  9. wolfhece/PyGuiHydrology.py +528 -74
  10. wolfhece/PyPalette.py +26 -4
  11. wolfhece/PyParams.py +33 -0
  12. wolfhece/PyPictures.py +2 -2
  13. wolfhece/PyVertex.py +25 -0
  14. wolfhece/PyVertexvectors.py +94 -28
  15. wolfhece/PyWMS.py +52 -36
  16. wolfhece/acceptability/acceptability.py +15 -8
  17. wolfhece/acceptability/acceptability_gui.py +507 -360
  18. wolfhece/acceptability/func.py +80 -183
  19. wolfhece/apps/version.py +1 -1
  20. wolfhece/compare_series.py +480 -0
  21. wolfhece/drawing_obj.py +12 -1
  22. wolfhece/hydrology/Catchment.py +228 -162
  23. wolfhece/hydrology/Internal_variables.py +43 -2
  24. wolfhece/hydrology/Models_characteristics.py +69 -67
  25. wolfhece/hydrology/Optimisation.py +893 -182
  26. wolfhece/hydrology/PyWatershed.py +267 -165
  27. wolfhece/hydrology/SubBasin.py +185 -140
  28. wolfhece/hydrology/cst_exchanges.py +76 -1
  29. wolfhece/hydrology/forcedexchanges.py +413 -49
  30. wolfhece/hydrology/read.py +65 -5
  31. wolfhece/hydrometry/kiwis.py +14 -7
  32. wolfhece/insyde_be/INBE_func.py +746 -0
  33. wolfhece/insyde_be/INBE_gui.py +1776 -0
  34. wolfhece/insyde_be/__init__.py +3 -0
  35. wolfhece/interpolating_raster.py +366 -0
  36. wolfhece/irm_alaro.py +1457 -0
  37. wolfhece/irm_qdf.py +889 -57
  38. wolfhece/lifewatch.py +6 -3
  39. wolfhece/picc.py +124 -8
  40. wolfhece/pyLandUseFlanders.py +146 -0
  41. wolfhece/pydownloader.py +2 -1
  42. wolfhece/pywalous.py +225 -31
  43. wolfhece/toolshydrology_dll.py +149 -0
  44. wolfhece/wolf_array.py +63 -25
  45. {wolfhece-2.2.38.dist-info → wolfhece-2.2.39.dist-info}/METADATA +3 -1
  46. {wolfhece-2.2.38.dist-info → wolfhece-2.2.39.dist-info}/RECORD +49 -40
  47. {wolfhece-2.2.38.dist-info → wolfhece-2.2.39.dist-info}/WHEEL +0 -0
  48. {wolfhece-2.2.38.dist-info → wolfhece-2.2.39.dist-info}/entry_points.txt +0 -0
  49. {wolfhece-2.2.38.dist-info → wolfhece-2.2.39.dist-info}/top_level.txt +0 -0
@@ -28,6 +28,7 @@ from dbfread import DBF
28
28
  import ctypes as ct
29
29
  import pandas as pd
30
30
  from pathlib import Path
31
+ import ctypes as ct
31
32
 
32
33
  from ..PyTranslate import _
33
34
  from . import plot_hydrology as ph
@@ -80,7 +81,8 @@ class SubBasin:
80
81
  # myHydro[i][1] : interflow
81
82
  # myHydro[i][2] : baseflow
82
83
  # @unit $[\si{m}^3/\si{s}}]$
83
- myHydro:np.ndarray # [m^3/s] Hydro of the subbasin only -> UPDATE: [mm/h]!!!!!
84
+ myHydro:np.ndarray # [mm/h] Fortran-like array that is pointed to by ptr_q_all with Fortran DLL (old version in [m^3/s])
85
+ iv_saved:np.ndarray # [mm/h] or [mm] or [-] depending on the variable
84
86
 
85
87
  intletsObj:dict
86
88
  inlets:np.ndarray
@@ -123,7 +125,8 @@ class SubBasin:
123
125
  peakTime:datetime.datetime # datetime of the peak for total outflow -> time delay is already applied
124
126
 
125
127
  # Hello!
126
- ptr_q_all:np.ndarray # Pointer to Fortran for the result matrix
128
+ ptr_q_all:ct._Pointer|None # Pointer to Fortran for the result matrix
129
+ ptr_iv_saved:ct._Pointer|None # Pointer to Fortran for the saved internal variables
127
130
 
128
131
  transferParam:Wolf_Param # Parameter file with the type of transfer applied -> e.g. timeDelay
129
132
 
@@ -171,7 +174,8 @@ class SubBasin:
171
174
  # myHydro[i][1] : interflow
172
175
  # myHydro[i][2] : baseflow
173
176
  # @unit $[\si{m}^3/\si{s}}]$
174
- self.myHydro = [] # [m^3/s] Hydro of the subbasin only -> UPDATE: [mm/h]!!!!!
177
+ self.myHydro = np.empty((0,0),dtype=ct.c_double, order='F') # [mm/h] hydrograph of the subbasin (old version in [m^3/s]) (potentially with Fortran pointer to ptr_q_all)
178
+ self.saved_iv = np.empty((0,0),dtype=ct.c_double, order='F') # [mm/h] or [mm] or [-] depending on the variable (potentially with Fortran pointer to ptr_iv_saved)
175
179
 
176
180
  self.intletsObj = {}
177
181
  self.inlets = None
@@ -216,6 +220,7 @@ class SubBasin:
216
220
 
217
221
  # Hello!
218
222
  self.ptr_q_all = None
223
+ self.ptr_iv_saved = None
219
224
 
220
225
  # version of the Python WOLFHydro
221
226
  self._version = version
@@ -225,10 +230,12 @@ class SubBasin:
225
230
  # Load all the hydrographs of the sub-basins
226
231
  if(self.model==cst.measures or self.model==cst.compare_opti):
227
232
  readHydro=False
233
+
228
234
  # Get the main characteristics of the subbasin. If the hydro can be read, so be the main characteristics
229
235
  if(readHydro):
230
236
  self.read_myMainCharacteristics(_workingDir)
231
237
  self.init_timeDelay()
238
+
232
239
  if(readHydro):
233
240
  timeTest, self.myHydro = self.get_hydro(self.iDSorted, _workingDir, tzDelta=datetime.timedelta(hours=self.tz))
234
241
  if(self.time is None):
@@ -1012,6 +1019,10 @@ class SubBasin:
1012
1019
  print("ERROR: Expecting only 1 file name for UH model!")
1013
1020
  sys.exit()
1014
1021
 
1022
+ if not Path(fileName).exists():
1023
+ logging.error("The file " + fileName + " does not exist!")
1024
+ return None, None
1025
+
1015
1026
  with open(fileName, newline = '') as fileID:
1016
1027
  data_reader = csv.reader(fileID, delimiter='\t')
1017
1028
  list_data = []
@@ -1244,7 +1255,7 @@ class SubBasin:
1244
1255
  # Real hydrograph
1245
1256
  self._outFlow[nameOutFlow]["Net"] = self.inlets + tmpHydro
1246
1257
  elif(self.model==cst.tom_VHM or self.model==cst.tom_2layers_linIF or self.model==cst.tom_2layers_UH or
1247
- self.model==cst.tom_HBV, self.model==cst.tom_SAC_SMA, self.model==cst.tom_NAM):
1258
+ self.model==cst.tom_HBV or self.model==cst.tom_SAC_SMA or self.model==cst.tom_NAM or self.model==cst.tom_SAC_SMA_LROF):
1248
1259
  tmpOutFlow = np.sum(self.myHydro,1)*self.surfaceDrained/3.6
1249
1260
 
1250
1261
  # Raw hydrograph
@@ -1260,7 +1271,6 @@ class SubBasin:
1260
1271
  # self.outFlow[i] = self.inlets[i] + np.sum(self.myHydro[i])
1261
1272
 
1262
1273
 
1263
-
1264
1274
  def sum_inlets(self):
1265
1275
  """ Sum all the inlet hydrographs of a subbasin. Return an array of zeros otherwise.
1266
1276
 
@@ -1281,10 +1291,11 @@ class SubBasin:
1281
1291
  self.inlets += curObj.get_outFlow(typeOutFlow="Net", whichOutFlow=nameInlet, lag=deltaTr)
1282
1292
  self.inletsRaw += curObj.get_outFlow(typeOutFlow="Raw", whichOutFlow=nameInlet, lag=deltaTr)
1283
1293
  else:
1284
- self.inlets = np.zeros(len(self.myHydro), dtype=ct.c_double, order='F')
1285
- self.inletsRaw = np.zeros(len(self.myHydro), dtype=ct.c_double, order='F')
1286
-
1287
-
1294
+ if self.myHydro is not None:
1295
+ self.inlets = np.zeros(len(self.myHydro), dtype=ct.c_double, order='F')
1296
+ self.inletsRaw = np.zeros(len(self.myHydro), dtype=ct.c_double, order='F')
1297
+ else:
1298
+ logging.error("ERROR: No hydrograph computed for this subbasin!")
1288
1299
 
1289
1300
 
1290
1301
  def add_rain(self, workingDir, fileName=None, tzDelta=datetime.timedelta(hours=0)):
@@ -1298,6 +1309,10 @@ class SubBasin:
1298
1309
  if(fileName is None):
1299
1310
  fileName = 'Subbasin_'+str(self.iDSorted)+'/simul_lumped_rain.txt'
1300
1311
 
1312
+ if not Path(os.path.join(workingDir,fileName)).exists():
1313
+ logging.error("The file " + os.path.join(workingDir,fileName) + " does not exist!")
1314
+ return None
1315
+
1301
1316
  with open(os.path.join(workingDir,fileName), newline = '') as fileID2:
1302
1317
  data_reader = csv.reader(fileID2, delimiter='\t')
1303
1318
  list_data = []
@@ -1552,7 +1567,7 @@ class SubBasin:
1552
1567
  """
1553
1568
 
1554
1569
  if(self.model==cst.tom_UH or self.model==cst.tom_2layers_linIF or self.model==cst.tom_2layers_UH or self.model==cst.tom_GR4 or
1555
- self.model==cst.tom_HBV, self.model==cst.tom_SAC_SMA, self.model==cst.tom_NAM):
1570
+ self.model==cst.tom_HBV or self.model==cst.tom_SAC_SMA or self.model==cst.tom_NAM or self.model==cst.tom_SAC_SMA_LROF):
1556
1571
  # x = self.time/3600.0
1557
1572
  if(axis=="Hours"):
1558
1573
  x = (self.time[:]-self.time[0])/3600.0
@@ -1771,7 +1786,8 @@ class SubBasin:
1771
1786
  y[:,i] = self.myHydro[:,i]*self.surfaceDrained/3.6
1772
1787
  tmpSum += self.myHydro[:,i]*self.surfaceDrained/3.6
1773
1788
  y[:,-1] = tmpSum
1774
- elif(self.model==cst.tom_GR4 or self.model==cst.tom_HBV, self.model==cst.tom_SAC_SMA, self.model==cst.tom_NAM):
1789
+ elif(self.model==cst.tom_GR4 or self.model==cst.tom_HBV or
1790
+ self.model==cst.tom_SAC_SMA or self.model==cst.tom_NAM or self.model==cst.tom_SAC_SMA_LROF):
1775
1791
  y[:,0] = self.myHydro[:,0]*self.surfaceDrained/3.6
1776
1792
  else:
1777
1793
  print("ERROR: this model was not implemented yet!")
@@ -1984,7 +2000,7 @@ class SubBasin:
1984
2000
  # y = np.zeros((len(self.outFlow)-lastElement,nbElements))
1985
2001
  y = []
1986
2002
  if(self.model==cst.tom_UH or self.model==cst.tom_2layers_linIF or self.model==cst.tom_2layers_UH or
1987
- cst.tom_GR4 or cst.tom_HBV or cst.tom_SAC_SMA or cst.tom_NAM):
2003
+ cst.tom_GR4 or cst.tom_HBV or cst.tom_SAC_SMA or cst.tom_NAM or self.model==cst.tom_SAC_SMA_LROF):
1988
2004
  if(withDelay):
1989
2005
  # y[:,0] = self.outFlow[:-1]
1990
2006
  y.append(myOutFlow[:])
@@ -2053,7 +2069,7 @@ class SubBasin:
2053
2069
  # y_titles.append("Total")
2054
2070
  y_titles.append(_('Débits simulés'))
2055
2071
  elif(self.model==cst.tom_UH or self.model==cst.tom_2layers_linIF or self.model==cst.tom_2layers_UH or
2056
- self.model==cst.tom_HBV or self.model==cst.tom_SAC_SMA or self.model==cst.tom_NAM):
2072
+ self.model==cst.tom_HBV or self.model==cst.tom_SAC_SMA or self.model==cst.tom_NAM, self.model==cst.tom_SAC_SMA_LROF):
2057
2073
  if(ylabel==[]):
2058
2074
  y_titles.append(_('Débits simulés'))
2059
2075
  # y_titles.append('Avec reconstruction Qout B. Vesdre')
@@ -2200,127 +2216,138 @@ class SubBasin:
2200
2216
  fileName = fileNameList[0]
2201
2217
  fileNameHydro = fileNameList[1]
2202
2218
 
2203
- with open(os.path.join(workingDir,fileName), newline = '') as fileID2:
2204
- data_reader = csv.reader(fileID2, delimiter='\t')
2205
- list_data = []
2206
- i=0
2207
- for raw in data_reader:
2208
- if i>0:
2209
- list_data.append(raw)
2210
- i += 1
2219
+ filename = Path(workingDir) / fileName
2220
+ if filename.exists():
2211
2221
 
2212
- tmp = ''
2213
- for i in range(len(list_data)):
2214
- if(list_data[i][0][:4]=="Area"):
2215
- tmp = list_data[i][0].split()
2216
- self.surfaceDrained = float(tmp[1].split("[")[0])
2217
- self.mainCharactDict["Area"] = {}
2218
- self.mainCharactDict["Area"]["value"] = self.surfaceDrained
2219
- self.mainCharactDict["Area"]["unit"] = "["+tmp[1].split("[")[1]
2220
- elif(list_data[i][0][:9]=="Perimeter"):
2221
- tmp = list_data[i][0].split()
2222
- self.mainCharactDict["Perimeter"] = {}
2223
- self.mainCharactDict["Perimeter"]["value"] = float(tmp[1].split("[")[0])
2224
- self.mainCharactDict["Perimeter"]["unit"] = "["+tmp[1].split("[")[1]
2225
- elif(list_data[i][0][:13]=="Average slope"):
2226
- tmp = list_data[i][0].split()
2227
- self.mainCharactDict["Average slope"] = {}
2228
- self.mainCharactDict["Average slope"]["value"] = float(tmp[2].split("[")[0])
2229
- self.mainCharactDict["Average slope"]["unit"] = "["+tmp[2].split("[")[1]
2230
- elif(list_data[i][0][:35]=="Compactness coefficient (Gravelius)"):
2231
- tmp = list_data[i][0].split()
2232
- self.mainCharactDict["Compactness coefficient (Gravelius)"] = {}
2233
- self.mainCharactDict["Compactness coefficient (Gravelius)"]["value"] = float(tmp[3].split("[")[0])
2234
- self.mainCharactDict["Compactness coefficient (Gravelius)"]["unit"] = "[-]"
2235
- elif(list_data[i][0][:12]=="Max lag time"):
2236
- tmp = list_data[i][0].split()
2237
- self.mainCharactDict["Max lag time"] = {}
2238
- self.mainCharactDict["Max lag time"]["value"] = float(tmp[3].split("[")[0])
2239
- self.mainCharactDict["Max lag time"]["unit"] = "["+tmp[3].split("[")[1]
2240
- elif(list_data[i][0][:12] == "Min lag time"):
2241
- tmp = list_data[i][0].split()
2242
- self.timeDelay = float(tmp[3].split("[")[0])
2243
- self.mainCharactDict["Min lag time"] = {}
2244
- self.mainCharactDict["Min lag time"]["value"] = float(tmp[3].split("[")[0])
2245
- self.mainCharactDict["Min lag time"]["unit"] = "["+tmp[3].split("[")[1]
2246
- elif(list_data[i][0][:12]=="Max altitude"):
2247
- tmp = list_data[i][0].split()
2248
- self.mainCharactDict["Max altitude"] = {}
2249
- self.mainCharactDict["Max altitude"]["value"] = float(tmp[2].split("[")[0])
2250
- self.mainCharactDict["Max altitude"]["unit"] = "["+tmp[2].split("[")[1]
2251
- elif(list_data[i][0][:12]=="Min altitude"):
2252
- tmp = list_data[i][0].split()
2253
- self.mainCharactDict["Min altitude"] = {}
2254
- self.mainCharactDict["Min altitude"]["value"] = float(tmp[2].split("[")[0])
2255
- self.mainCharactDict["Min altitude"]["unit"] = "["+tmp[2].split("[")[1]
2256
- elif(list_data[i][0][:21]=="Fraction of landuse n"):
2257
- tmp = list_data[i][0].split()
2258
- self.mainCharactDict["Fraction of landuse n "+tmp[4]] = {}
2259
- self.mainCharactDict["Fraction of landuse n "+tmp[4]]["value"] = float(tmp[5].split("[")[0])
2260
- self.mainCharactDict["Fraction of landuse n "+tmp[4]]["unit"] = "["+tmp[5].split("[")[1]
2222
+ with open(filename, newline = '') as fileID2:
2223
+ data_reader = csv.reader(fileID2, delimiter='\t')
2224
+ list_data = []
2225
+ i=0
2226
+ for raw in data_reader:
2227
+ if i>0:
2228
+ list_data.append(raw)
2229
+ i += 1
2230
+
2231
+ tmp = ''
2232
+ for i in range(len(list_data)):
2233
+ if(list_data[i][0][:4]=="Area"):
2234
+ tmp = list_data[i][0].split()
2235
+ self.surfaceDrained = float(tmp[1].split("[")[0])
2236
+ self.mainCharactDict["Area"] = {}
2237
+ self.mainCharactDict["Area"]["value"] = self.surfaceDrained
2238
+ self.mainCharactDict["Area"]["unit"] = "["+tmp[1].split("[")[1]
2239
+ elif(list_data[i][0][:9]=="Perimeter"):
2240
+ tmp = list_data[i][0].split()
2241
+ self.mainCharactDict["Perimeter"] = {}
2242
+ self.mainCharactDict["Perimeter"]["value"] = float(tmp[1].split("[")[0])
2243
+ self.mainCharactDict["Perimeter"]["unit"] = "["+tmp[1].split("[")[1]
2244
+ elif(list_data[i][0][:13]=="Average slope"):
2245
+ tmp = list_data[i][0].split()
2246
+ self.mainCharactDict["Average slope"] = {}
2247
+ self.mainCharactDict["Average slope"]["value"] = float(tmp[2].split("[")[0])
2248
+ self.mainCharactDict["Average slope"]["unit"] = "["+tmp[2].split("[")[1]
2249
+ elif(list_data[i][0][:35]=="Compactness coefficient (Gravelius)"):
2250
+ tmp = list_data[i][0].split()
2251
+ self.mainCharactDict["Compactness coefficient (Gravelius)"] = {}
2252
+ self.mainCharactDict["Compactness coefficient (Gravelius)"]["value"] = float(tmp[3].split("[")[0])
2253
+ self.mainCharactDict["Compactness coefficient (Gravelius)"]["unit"] = "[-]"
2254
+ elif(list_data[i][0][:12]=="Max lag time"):
2255
+ tmp = list_data[i][0].split()
2256
+ self.mainCharactDict["Max lag time"] = {}
2257
+ self.mainCharactDict["Max lag time"]["value"] = float(tmp[3].split("[")[0])
2258
+ self.mainCharactDict["Max lag time"]["unit"] = "["+tmp[3].split("[")[1]
2259
+ elif(list_data[i][0][:12] == "Min lag time"):
2260
+ tmp = list_data[i][0].split()
2261
+ self.timeDelay = float(tmp[3].split("[")[0])
2262
+ self.mainCharactDict["Min lag time"] = {}
2263
+ self.mainCharactDict["Min lag time"]["value"] = float(tmp[3].split("[")[0])
2264
+ self.mainCharactDict["Min lag time"]["unit"] = "["+tmp[3].split("[")[1]
2265
+ elif(list_data[i][0][:12]=="Max altitude"):
2266
+ tmp = list_data[i][0].split()
2267
+ self.mainCharactDict["Max altitude"] = {}
2268
+ self.mainCharactDict["Max altitude"]["value"] = float(tmp[2].split("[")[0])
2269
+ self.mainCharactDict["Max altitude"]["unit"] = "["+tmp[2].split("[")[1]
2270
+ elif(list_data[i][0][:12]=="Min altitude"):
2271
+ tmp = list_data[i][0].split()
2272
+ self.mainCharactDict["Min altitude"] = {}
2273
+ self.mainCharactDict["Min altitude"]["value"] = float(tmp[2].split("[")[0])
2274
+ self.mainCharactDict["Min altitude"]["unit"] = "["+tmp[2].split("[")[1]
2275
+ elif(list_data[i][0][:21]=="Fraction of landuse n"):
2276
+ tmp = list_data[i][0].split()
2277
+ self.mainCharactDict["Fraction of landuse n "+tmp[4]] = {}
2278
+ self.mainCharactDict["Fraction of landuse n "+tmp[4]]["value"] = float(tmp[5].split("[")[0])
2279
+ self.mainCharactDict["Fraction of landuse n "+tmp[4]]["unit"] = "["+tmp[5].split("[")[1]
2280
+ else:
2281
+ logging.error(f"File {filename} does not exist. Cannot read averaged characteristics.")
2261
2282
 
2262
2283
 
2263
2284
  data_reader = None
2264
2285
  list_data = []
2265
2286
  # fileName = "/Subbasin_" + str(self.iDSorted) + "/" + "simul_subbasin.avrg_caractWholeHydroSubBasin"
2266
- with open(os.path.join(workingDir,fileNameHydro), newline = '') as fileID2:
2267
- data_reader = csv.reader(fileID2, delimiter='\t')
2268
- list_data = []
2269
- i=0
2270
- for raw in data_reader:
2271
- if i>0:
2272
- list_data.append(raw)
2273
- i += 1
2274
2287
 
2275
- tmp = ''
2276
- for i in range(len(list_data)):
2277
- if(list_data[i][0][:4]=="Area"):
2278
- tmp = list_data[i][0].split()
2279
- self.surfaceDrainedHydro = float(tmp[1].split("[")[0])
2280
- self.mainCharactDictWholeHydro["Area"] = {}
2281
- self.mainCharactDictWholeHydro["Area"]["value"] = self.surfaceDrainedHydro
2282
- self.mainCharactDictWholeHydro["Area"]["unit"] = "["+tmp[1].split("[")[1]
2283
- elif(list_data[i][0][:9]=="Perimeter"):
2284
- tmp = list_data[i][0].split()
2285
- self.mainCharactDictWholeHydro["Perimeter"] = {}
2286
- self.mainCharactDictWholeHydro["Perimeter"]["value"] = float(tmp[1].split("[")[0])
2287
- self.mainCharactDictWholeHydro["Perimeter"]["unit"] = "["+tmp[1].split("[")[1]
2288
- elif(list_data[i][0][:13]=="Average slope"):
2289
- tmp = list_data[i][0].split()
2290
- self.mainCharactDictWholeHydro["Average slope"] = {}
2291
- self.mainCharactDictWholeHydro["Average slope"]["value"] = float(tmp[2].split("[")[0])
2292
- self.mainCharactDictWholeHydro["Average slope"]["unit"] = "["+tmp[2].split("[")[1]
2293
- elif(list_data[i][0][:35]=="Compactness coefficient (Gravelius)"):
2294
- tmp = list_data[i][0].split()
2295
- self.mainCharactDictWholeHydro["Compactness coefficient (Gravelius)"] = {}
2296
- self.mainCharactDictWholeHydro["Compactness coefficient (Gravelius)"]["value"] = float(tmp[3].split("[")[0])
2297
- self.mainCharactDictWholeHydro["Compactness coefficient (Gravelius)"]["unit"] = "[-]"
2298
- elif(list_data[i][0][:12]=="Max lag time"):
2299
- tmp = list_data[i][0].split()
2300
- self.mainCharactDictWholeHydro["Max lag time"] = {}
2301
- self.mainCharactDictWholeHydro["Max lag time"]["value"] = float(tmp[3].split("[")[0])
2302
- self.mainCharactDictWholeHydro["Max lag time"]["unit"] = "["+tmp[3].split("[")[1]
2303
- elif(list_data[i][0][:12] == "Min lag time"):
2304
- tmp = list_data[i][0].split()
2305
- self.timeDelay = float(tmp[3].split("[")[0])
2306
- self.mainCharactDictWholeHydro["Min lag time"] = {}
2307
- self.mainCharactDictWholeHydro["Min lag time"]["value"] = float(tmp[3].split("[")[0])
2308
- self.mainCharactDictWholeHydro["Min lag time"]["unit"] = "["+tmp[3].split("[")[1]
2309
- elif(list_data[i][0][:12]=="Max altitude"):
2310
- tmp = list_data[i][0].split()
2311
- self.mainCharactDictWholeHydro["Max altitude"] = {}
2312
- self.mainCharactDictWholeHydro["Max altitude"]["value"] = float(tmp[2].split("[")[0])
2313
- self.mainCharactDictWholeHydro["Max altitude"]["unit"] = "["+tmp[2].split("[")[1]
2314
- elif(list_data[i][0][:12]=="Min altitude"):
2315
- tmp = list_data[i][0].split()
2316
- self.mainCharactDictWholeHydro["Min altitude"] = {}
2317
- self.mainCharactDictWholeHydro["Min altitude"]["value"] = float(tmp[2].split("[")[0])
2318
- self.mainCharactDictWholeHydro["Min altitude"]["unit"] = "["+tmp[2].split("[")[1]
2319
- elif(list_data[i][0][:21]=="Fraction of landuse n"):
2320
- tmp = list_data[i][0].split()
2321
- self.mainCharactDictWholeHydro["Fraction of landuse n "+tmp[4]] = {}
2322
- self.mainCharactDictWholeHydro["Fraction of landuse n "+tmp[4]]["value"] = float(tmp[5].split("[")[0])
2323
- self.mainCharactDictWholeHydro["Fraction of landuse n "+tmp[4]]["unit"] = "["+tmp[5].split("[")[1]
2288
+ fileNameHydro = Path(workingDir) / fileNameHydro
2289
+ if fileNameHydro.exists():
2290
+ with open(fileNameHydro, newline = '') as fileID2:
2291
+ data_reader = csv.reader(fileID2, delimiter='\t')
2292
+ list_data = []
2293
+ i=0
2294
+ for raw in data_reader:
2295
+ if i>0:
2296
+ list_data.append(raw)
2297
+ i += 1
2298
+
2299
+ tmp = ''
2300
+ for i in range(len(list_data)):
2301
+ if(list_data[i][0][:4]=="Area"):
2302
+ tmp = list_data[i][0].split()
2303
+ self.surfaceDrainedHydro = float(tmp[1].split("[")[0])
2304
+ self.mainCharactDictWholeHydro["Area"] = {}
2305
+ self.mainCharactDictWholeHydro["Area"]["value"] = self.surfaceDrainedHydro
2306
+ self.mainCharactDictWholeHydro["Area"]["unit"] = "["+tmp[1].split("[")[1]
2307
+ elif(list_data[i][0][:9]=="Perimeter"):
2308
+ tmp = list_data[i][0].split()
2309
+ self.mainCharactDictWholeHydro["Perimeter"] = {}
2310
+ self.mainCharactDictWholeHydro["Perimeter"]["value"] = float(tmp[1].split("[")[0])
2311
+ self.mainCharactDictWholeHydro["Perimeter"]["unit"] = "["+tmp[1].split("[")[1]
2312
+ elif(list_data[i][0][:13]=="Average slope"):
2313
+ tmp = list_data[i][0].split()
2314
+ self.mainCharactDictWholeHydro["Average slope"] = {}
2315
+ self.mainCharactDictWholeHydro["Average slope"]["value"] = float(tmp[2].split("[")[0])
2316
+ self.mainCharactDictWholeHydro["Average slope"]["unit"] = "["+tmp[2].split("[")[1]
2317
+ elif(list_data[i][0][:35]=="Compactness coefficient (Gravelius)"):
2318
+ tmp = list_data[i][0].split()
2319
+ self.mainCharactDictWholeHydro["Compactness coefficient (Gravelius)"] = {}
2320
+ self.mainCharactDictWholeHydro["Compactness coefficient (Gravelius)"]["value"] = float(tmp[3].split("[")[0])
2321
+ self.mainCharactDictWholeHydro["Compactness coefficient (Gravelius)"]["unit"] = "[-]"
2322
+ elif(list_data[i][0][:12]=="Max lag time"):
2323
+ tmp = list_data[i][0].split()
2324
+ self.mainCharactDictWholeHydro["Max lag time"] = {}
2325
+ self.mainCharactDictWholeHydro["Max lag time"]["value"] = float(tmp[3].split("[")[0])
2326
+ self.mainCharactDictWholeHydro["Max lag time"]["unit"] = "["+tmp[3].split("[")[1]
2327
+ elif(list_data[i][0][:12] == "Min lag time"):
2328
+ tmp = list_data[i][0].split()
2329
+ self.timeDelay = float(tmp[3].split("[")[0])
2330
+ self.mainCharactDictWholeHydro["Min lag time"] = {}
2331
+ self.mainCharactDictWholeHydro["Min lag time"]["value"] = float(tmp[3].split("[")[0])
2332
+ self.mainCharactDictWholeHydro["Min lag time"]["unit"] = "["+tmp[3].split("[")[1]
2333
+ elif(list_data[i][0][:12]=="Max altitude"):
2334
+ tmp = list_data[i][0].split()
2335
+ self.mainCharactDictWholeHydro["Max altitude"] = {}
2336
+ self.mainCharactDictWholeHydro["Max altitude"]["value"] = float(tmp[2].split("[")[0])
2337
+ self.mainCharactDictWholeHydro["Max altitude"]["unit"] = "["+tmp[2].split("[")[1]
2338
+ elif(list_data[i][0][:12]=="Min altitude"):
2339
+ tmp = list_data[i][0].split()
2340
+ self.mainCharactDictWholeHydro["Min altitude"] = {}
2341
+ self.mainCharactDictWholeHydro["Min altitude"]["value"] = float(tmp[2].split("[")[0])
2342
+ self.mainCharactDictWholeHydro["Min altitude"]["unit"] = "["+tmp[2].split("[")[1]
2343
+ elif(list_data[i][0][:21]=="Fraction of landuse n"):
2344
+ tmp = list_data[i][0].split()
2345
+ self.mainCharactDictWholeHydro["Fraction of landuse n "+tmp[4]] = {}
2346
+ self.mainCharactDictWholeHydro["Fraction of landuse n "+tmp[4]]["value"] = float(tmp[5].split("[")[0])
2347
+ self.mainCharactDictWholeHydro["Fraction of landuse n "+tmp[4]]["unit"] = "["+tmp[5].split("[")[1]
2348
+
2349
+ else:
2350
+ logging.error(f"File {fileNameHydro} does not exist. Cannot read averaged characteristics of the whole hydro subbasin.")
2324
2351
 
2325
2352
 
2326
2353
  def get_flood(self, path='', check_coherence=False):
@@ -2921,13 +2948,15 @@ class SubBasin:
2921
2948
  # It will then fill the given or not dict of landuse with a name property
2922
2949
  def get_landuse_index_transform_default(self, landuseDict:dict={}) -> dict:
2923
2950
 
2924
- if landuseDict==None:
2951
+ if landuseDict is None:
2925
2952
  landuseDict = {}
2926
2953
 
2927
2954
  for key in cst.DEFAULT_LANDUSE:
2928
2955
  if not key in landuseDict:
2929
2956
  landuseDict[key] = {}
2930
2957
  landuseDict[key]["name"] = cst.DEFAULT_LANDUSE[key]
2958
+ landuseDict[key]["surface"] = 0.0
2959
+ landuseDict[key]["unit"] = "[-]"
2931
2960
 
2932
2961
  return landuseDict
2933
2962
 
@@ -2966,6 +2995,8 @@ class SubBasin:
2966
2995
  if not key in landuseDict:
2967
2996
  landuseDict[key] = {}
2968
2997
  landuseDict[key]["name"] = line[1].strip()
2998
+ landuseDict[key]["surface"] = 0.0
2999
+ landuseDict[key]["unit"] = "[-]"
2969
3000
 
2970
3001
  return landuseDict
2971
3002
 
@@ -2986,13 +3017,19 @@ class SubBasin:
2986
3017
  # Get the names of all landuses
2987
3018
  landuseDict = {}
2988
3019
  landuseDict = self.get_landuse_index_transform(landuse_index_transform, landuseDict=landuseDict)
2989
- if landuseDict == None:
3020
+ if landuseDict is None:
2990
3021
  landuseDict = self.get_landuse_index_transform_default(landuseDict=landuseDict)
2991
3022
 
2992
3023
  # Get the surfaces and units of all landuses
2993
3024
  for key in landuseDict:
2994
- landuseDict[key]["surface"] = avrgDict["Fraction of landuse n "+str(key)]["value"]
2995
- landuseDict[key]["unit"] = avrgDict["Fraction of landuse n "+str(key)]["unit"]
3025
+ associated_key = "Fraction of landuse n "+str(key)
3026
+ if associated_key in avrgDict:
3027
+ # If the lanuse type is not present, it will be set to 0.0
3028
+ landuseDict[key]["surface"] = avrgDict[associated_key]["value"]
3029
+ landuseDict[key]["unit"] = avrgDict[associated_key]["unit"]
3030
+ else:
3031
+ landuseDict[key]["surface"] = 0.0
3032
+ landuseDict[key]["unit"] = "[-]"
2996
3033
 
2997
3034
  if toSave:
2998
3035
  if onlySub:
@@ -3024,9 +3061,9 @@ class SubBasin:
3024
3061
  # Creation of data and legend
3025
3062
  data = []
3026
3063
  names = []
3027
- for key in landuseDict:
3028
- data.append(landuseDict[key]["surface"])
3029
- names.append(landuseDict[key]["name"])
3064
+ for landuse in landuseDict.values():
3065
+ data.append(landuse["surface"])
3066
+ names.append(landuse["name"])
3030
3067
 
3031
3068
  # Creation of colors
3032
3069
  colorDict = {}
@@ -3069,7 +3106,7 @@ class SubBasin:
3069
3106
 
3070
3107
  def change_version(self, newVersion=None):
3071
3108
 
3072
- if newVersion == None:
3109
+ if newVersion is None:
3073
3110
  self._version = float(cst.VERSION_WOLFHYDRO)
3074
3111
  elif type(newVersion) == str:
3075
3112
  self._version = float(newVersion)
@@ -3300,7 +3337,7 @@ class SubBasin:
3300
3337
  # elif self.model == cst.tom_2layers_linIF:
3301
3338
  # self.activate_all_iv_2layers()
3302
3339
  cur_dir = os.path.join(self.fileNameRead, "Subbasin_"+str(self.iDSorted))
3303
-
3340
+ mc.MODELS_VAR[self.model].deactivate_all(directory=cur_dir, prefix_file='simul')
3304
3341
  mc.MODELS_VAR[self.model].activate_all(directory=cur_dir, prefix_file='simul', type_of_var=iv.FINAL_OUT_VAR)
3305
3342
  mc.MODELS_VAR[self.model].activate_all(directory=cur_dir, prefix_file='simul', type_of_var=iv.IV_VAR)
3306
3343
 
@@ -3716,7 +3753,7 @@ class SubBasin:
3716
3753
  Returns:
3717
3754
  - dict: A dictionary containing the summary of the fractions of the current module.
3718
3755
  """
3719
-
3756
+ print(f"Computing flow fractions for station :{self.name}")
3720
3757
  if all_f == {}:
3721
3758
  cur_dir = os.path.join(self.fileNameRead, "Subbasin_"+str(self.iDSorted))
3722
3759
  all_qin = mc.MODELS_VAR[self.model].get_all_iv_timeseries(directory=cur_dir,
@@ -3725,8 +3762,16 @@ class SubBasin:
3725
3762
  prefix_file='simul', type_of_var=iv.DEFAULT_VAR)
3726
3763
  all_f.update(all_qin)
3727
3764
 
3728
- q_simul = self.get_outFlow(unit='mm/h')
3729
- all_r = {"%"+key: val/q_simul * 100.0 for key, val in all_f.items()}
3765
+ q_simul = self.get_myHydro(unit='mm/h')
3766
+ for key, val in all_f.items():
3767
+ if len(val) != len(q_simul):
3768
+ logging.warning(f"Length of {key} does not match with the length of the simulated flow!")
3769
+ continue
3770
+ # all_r = {"%"+key: val/q_simul * 100.0 for key, val in all_f.items()}
3771
+ all_r = {
3772
+ f"%{key}": np.where(np.isfinite(val / q_simul), (val / q_simul) * 100.0, np.nan)
3773
+ for key, val in all_f.items()
3774
+ }
3730
3775
 
3731
3776
  return self._operation_on_ts(all_r, summary=summary, interval=interval)
3732
3777
 
@@ -3749,7 +3794,7 @@ class SubBasin:
3749
3794
  all_iv = mc.MODELS_VAR[self.model].get_all_iv_timeseries(directory=cur_dir,
3750
3795
  prefix_file='simul', type_of_var=iv.IV_VAR)
3751
3796
  if max_params != {}:
3752
- out_dict = {key: all_iv[key]/cur_max for key, cur_max in max_params.items()}
3797
+ out_dict = {key: all_iv[key]/cur_max*100 for key, cur_max in max_params.items()}
3753
3798
  else:
3754
3799
  out_dict = all_iv
3755
3800