wolfhece 1.8.13__py3-none-any.whl → 2.0.0__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/GraphNotebook.py +0 -1
- wolfhece/PyCrosssections.py +591 -5
- wolfhece/PyDraw.py +1151 -413
- wolfhece/PyGui.py +2 -4
- wolfhece/PyParams.py +1515 -852
- wolfhece/PyVertex.py +73 -73
- wolfhece/PyVertexvectors.py +226 -808
- wolfhece/RatingCurve.py +19 -6
- wolfhece/apps/wolf2D.py +11 -0
- wolfhece/apps/wolfcompare2Darrays.py +51 -22
- wolfhece/bernoulli/NetworkOpenGL.py +337 -341
- wolfhece/drawing_obj.py +25 -0
- wolfhece/hydrology/Catchment.py +77 -77
- wolfhece/hydrology/Optimisation.py +206 -53
- wolfhece/hydrology/PostProcessHydrology.py +22 -22
- wolfhece/hydrology/SubBasin.py +17 -17
- wolfhece/hydrology/constant.py +4 -0
- wolfhece/hydrology/cst_exchanges.py +2 -1
- wolfhece/lazviewer/processing/estimate_normals/estimate_normals.cp310-win_amd64.pyd +0 -0
- wolfhece/lazviewer/vfuncs/vfuncs.cp310-win_amd64.pyd +0 -0
- wolfhece/libs/WolfDll.dll +0 -0
- wolfhece/libs/wolfogl.cp310-win_amd64.pyd +0 -0
- wolfhece/libs/wolfpy.cp310-win_amd64.pyd +0 -0
- wolfhece/mesh2d/wolf2dprev.py +4 -4
- wolfhece/multiprojects.py +13 -13
- wolfhece/pylogging.py +1 -1
- wolfhece/pyviews.py +23 -23
- wolfhece/wolf_array.py +69 -152
- wolfhece/wolf_texture.py +39 -16
- wolfhece/wolfresults_2D.py +1 -1
- {wolfhece-1.8.13.dist-info → wolfhece-2.0.0.dist-info}/METADATA +3 -2
- {wolfhece-1.8.13.dist-info → wolfhece-2.0.0.dist-info}/RECORD +37 -33
- wolfhece/apps/wolfgpu.py +0 -19
- /wolfhece/lazviewer/processing/estimate_normals/{estimate_normals.pyd → estimate_normals.cp39-win_amd64.pyd} +0 -0
- /wolfhece/lazviewer/vfuncs/{vfuncs.pyd → vfuncs.cp39-win_amd64.pyd} +0 -0
- {wolfhece-1.8.13.dist-info → wolfhece-2.0.0.dist-info}/LICENCE +0 -0
- {wolfhece-1.8.13.dist-info → wolfhece-2.0.0.dist-info}/WHEEL +0 -0
- {wolfhece-1.8.13.dist-info → wolfhece-2.0.0.dist-info}/top_level.txt +0 -0
@@ -92,9 +92,10 @@ class Optimisation(wx.Frame):
|
|
92
92
|
# launcherDir:list
|
93
93
|
myParams:dict
|
94
94
|
myParamsPy:dict
|
95
|
-
|
95
|
+
curParams_vec_F:np.ndarray
|
96
96
|
nbParams:int
|
97
|
-
|
97
|
+
optiFactor_F:ct.c_double
|
98
|
+
bestFactor:float
|
98
99
|
|
99
100
|
comparHowParam:Wolf_Param
|
100
101
|
# launcherParam:Wolf_Param
|
@@ -140,7 +141,7 @@ class Optimisation(wx.Frame):
|
|
140
141
|
self.myStations = []
|
141
142
|
self.compareFilesDict = {}
|
142
143
|
|
143
|
-
self.
|
144
|
+
self.curParams_vec_F = None
|
144
145
|
|
145
146
|
if self.debugDLL:
|
146
147
|
self.load_dll(self.pathDll, DLL_FILE_DEBUG)
|
@@ -415,14 +416,41 @@ class Optimisation(wx.Frame):
|
|
415
416
|
if self.debugDLL:
|
416
417
|
self.enable_MenuBar("Debug")
|
417
418
|
|
418
|
-
def apply_optim(self, event, idLauncher=0):
|
419
419
|
|
420
|
-
|
421
|
-
|
420
|
+
def apply_optim(self, event, idLauncher:int=0, replace_only_if_better:bool=False, optim_params:np.ndarray=None):
|
421
|
+
"""
|
422
|
+
Apply optimal parameters based on the results file of the optimisation : ".rpt".
|
422
423
|
|
423
|
-
|
424
|
+
Args:
|
425
|
+
event: The event from the GUI.
|
426
|
+
idLauncher (optional: int(0)): The ID of the launcher.
|
427
|
+
replace_only_if_better (optional: bool(False) by default): A boolean indicating whether to replace the current parameters if the new ones are better.
|
424
428
|
|
425
|
-
|
429
|
+
Returns:
|
430
|
+
If replace_only_if_better is False, returns the best parameters found.
|
431
|
+
If replace_only_if_better is True and the new parameters are better, returns the best parameters found.
|
432
|
+
Otherwise, returns None.
|
433
|
+
"""
|
434
|
+
# Get the best parameters
|
435
|
+
if optim_params is None:
|
436
|
+
bestParams:np.array = self.collect_optim()
|
437
|
+
else:
|
438
|
+
# FIXME : gneralise the -1 for the test for any number of objective function
|
439
|
+
assert self.nbParams==len(optim_params)-1, "ERROR : the number of parameters to appy are the ones expected!"
|
440
|
+
bestParams:np.array = optim_params
|
441
|
+
|
442
|
+
test_best = bestParams[-1] # FIXME : gneralise the -1 for the test for any number of objective function
|
443
|
+
if not replace_only_if_better:
|
444
|
+
self.apply_optim_2_params(bestParams[:-1], idLauncher=idLauncher)
|
445
|
+
self.bestFactor = test_best
|
446
|
+
return bestParams
|
447
|
+
elif test_best>self.bestFactor:
|
448
|
+
self.apply_optim_2_params(bestParams[:-1], idLauncher=idLauncher)
|
449
|
+
self.bestFactor = bestParams[-1]
|
450
|
+
return bestParams
|
451
|
+
else:
|
452
|
+
return None
|
453
|
+
|
426
454
|
|
427
455
|
|
428
456
|
# Initialisation of the Optimizer from Fortran
|
@@ -567,9 +595,14 @@ class Optimisation(wx.Frame):
|
|
567
595
|
self.myParamsPy[i]["junction_name"] = self.myCases[idLauncher].launcherParam.get_param(curParam, "junction_name")
|
568
596
|
|
569
597
|
|
570
|
-
def collect_optim(self):
|
598
|
+
def collect_optim(self, fileName=""):
|
599
|
+
|
600
|
+
isOk,fileName = check_path(fileName, self.workingDir)
|
601
|
+
if fileName=="":
|
602
|
+
nameTMP = self.optiParam.get_param("Optimizer","fname")
|
603
|
+
else:
|
604
|
+
isOk,nameTMP = check_path(fileName, self.workingDir)
|
571
605
|
|
572
|
-
nameTMP = self.optiParam.get_param("Optimizer","fname")
|
573
606
|
optimFileTxt = os.path.join(self.workingDir, nameTMP+".rpt")
|
574
607
|
optimFileBin = os.path.join(self.workingDir, nameTMP+".rpt.dat")
|
575
608
|
|
@@ -1096,9 +1129,9 @@ class Optimisation(wx.Frame):
|
|
1096
1129
|
dims = np.empty((ndims,), dtype=ct.c_int, order='F')
|
1097
1130
|
# The only dimension is the number of parameters to calibrate
|
1098
1131
|
dims[0] = self.nbParams
|
1099
|
-
self.
|
1132
|
+
self.curParams_vec_F = np.empty((self.nbParams,), dtype=ct.c_double, order='F')
|
1100
1133
|
# creation of the c_ptr to give to fortran to reconstruct the tensors
|
1101
|
-
pointerParam = self.
|
1134
|
+
pointerParam = self.curParams_vec_F.ctypes.data_as(ct.POINTER(ct.c_double))
|
1102
1135
|
pointerDims = dims.ctypes.data_as(ct.POINTER(ct.c_int))
|
1103
1136
|
# call of the Fortran function
|
1104
1137
|
isOk = self.dllFortran.associate_ptr_py(ct.byref(ct.c_int(idOpti)),ct.byref(ct.c_int(idLauncher+1)), ct.c_int(cste.ptr_params),
|
@@ -1115,12 +1148,12 @@ class Optimisation(wx.Frame):
|
|
1115
1148
|
dims = np.empty((ndims,), dtype=ct.c_int, order='F')
|
1116
1149
|
# The only dimension is the number of parameters to calibrate
|
1117
1150
|
dims[0] = 1
|
1118
|
-
self.
|
1151
|
+
self.optiFactor_F = ct.c_double(0.0)
|
1119
1152
|
# creation of the c_ptr to give to fortran to reconstruct the tensors
|
1120
1153
|
pointerDims = dims.ctypes.data_as(ct.POINTER(ct.c_int))
|
1121
1154
|
# call of the Fortran function
|
1122
1155
|
isOk = self.dllFortran.associate_ptr_py(ct.byref(ct.c_int(idOpti)),ct.byref(ct.c_int(idLauncher+1)), ct.c_int(cste.ptr_opti_factors),
|
1123
|
-
pointerDims, ct.byref(self.
|
1156
|
+
pointerDims, ct.byref(self.optiFactor_F))
|
1124
1157
|
|
1125
1158
|
print("End of factor pointer association.")
|
1126
1159
|
|
@@ -1151,8 +1184,8 @@ class Optimisation(wx.Frame):
|
|
1151
1184
|
# Launch Fortran routine to compute optimisation and write the best results
|
1152
1185
|
self.compute_optimizer(idOpti=idOpti)
|
1153
1186
|
|
1154
|
-
print("Best parameters : ", self.
|
1155
|
-
print("Best Factor = ", self.
|
1187
|
+
print("Best parameters : ", self.curParams_vec_F)
|
1188
|
+
print("Best Factor = ", self.optiFactor_F)
|
1156
1189
|
|
1157
1190
|
# Apply the best parameters
|
1158
1191
|
self.apply_optim(None)
|
@@ -1175,7 +1208,17 @@ class Optimisation(wx.Frame):
|
|
1175
1208
|
|
1176
1209
|
|
1177
1210
|
def launch_semiDistributed_optimisation(self, event, idOpti=1, idLauncher=0):
|
1211
|
+
"""
|
1212
|
+
Procedure launching the semi-distributed optimisation process.
|
1178
1213
|
|
1214
|
+
Args:
|
1215
|
+
event: The event triggering the optimisation.
|
1216
|
+
idOpti (int): The ID of the optimizer in Fortran.
|
1217
|
+
idLauncher (int): The ID of the launcher.
|
1218
|
+
|
1219
|
+
Returns:
|
1220
|
+
None
|
1221
|
+
"""
|
1179
1222
|
curCatch:Catchment = self.myCases[idLauncher].refCatchment
|
1180
1223
|
|
1181
1224
|
if (self.optiParam.get_group("Semi-Distributed"))is not None:
|
@@ -1193,6 +1236,18 @@ class Optimisation(wx.Frame):
|
|
1193
1236
|
compareFileName = self.optiParam.myparams["Semi-Distributed"]["File reference "+str(iRef)]["value"]
|
1194
1237
|
readDict[stationOut] = compareFileName
|
1195
1238
|
self.compareFilesDict = readDict
|
1239
|
+
# Get the initial number of intervals
|
1240
|
+
# -> these can evolve according to the measurement available at each station
|
1241
|
+
# FIXME : finish to generalise this part
|
1242
|
+
nb_comparisons = self.comparHowParam.get_param("Comparison global characteristics","nb")
|
1243
|
+
nb_intervals_init = [self.comparHowParam.get_param(" ".join(["Comparison",str(i)]),"nb intervals") for i in range(1,nb_comparisons+1)]
|
1244
|
+
# Get the number of attempts with random initial conditions and from the best parameters for each station
|
1245
|
+
# The total number of iterations per station is the product of these two numbers :
|
1246
|
+
# nb_iter total = nb_iter_from_random * nb_iter_from_best
|
1247
|
+
nb_iter_from_random = self.optiParam.get_param("Optimizer","nb iter from random initial conditions",default_value=1)
|
1248
|
+
nb_iter_from_best = self.optiParam.get_param("Optimizer","nb iter from best",default_value=1)
|
1249
|
+
# Check the initial parameters and if they are forced
|
1250
|
+
init_params = self.get_initial_parameters()
|
1196
1251
|
# Sort all the junctions by level
|
1197
1252
|
sortJct = curCatch.sort_level_given_junctions(list(readDict.keys()), changeNames=False)
|
1198
1253
|
self.myStations = sortJct
|
@@ -1206,6 +1261,8 @@ class Optimisation(wx.Frame):
|
|
1206
1261
|
curCatch.define_station_out(stationOut)
|
1207
1262
|
# Activate all the useful subs and write it in the param file
|
1208
1263
|
curCatch.activate_usefulSubs(blockJunction=doneList, onlyItself=onlyOwnSub)
|
1264
|
+
# # Select correct calibration intervals
|
1265
|
+
# self.select_opti_intervals(stationOut)
|
1209
1266
|
# Rename the result file
|
1210
1267
|
self.optiParam.change_param("Optimizer", "fname", stationOut)
|
1211
1268
|
self.optiParam.SavetoFile(None)
|
@@ -1213,13 +1270,46 @@ class Optimisation(wx.Frame):
|
|
1213
1270
|
self.update_myParams(idLauncher)
|
1214
1271
|
# Prepare the paramPy dictionnary before calibration
|
1215
1272
|
self.prepare_calibration_timeDelay(stationOut=stationOut)
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1273
|
+
## loop on the number of different optimisation attempt we would like for each station
|
1274
|
+
best_params_overall = None
|
1275
|
+
cur_i = 0
|
1276
|
+
i_best_overal = 0
|
1277
|
+
for i_rand in range(nb_iter_from_random):
|
1278
|
+
best_params = init_params
|
1279
|
+
for i_best in range(nb_iter_from_best):
|
1280
|
+
# Prepare I.C. starting from best configuration
|
1281
|
+
self.prepare_init_params_from_best(best_params=best_params, idLauncher=idLauncher)
|
1282
|
+
# Reload the useful modules
|
1283
|
+
self.reload_hydro(idCompar=0, fromStation=stationOut, lastLevel=previousLevel, updateAll=True)
|
1284
|
+
# Compute
|
1285
|
+
self.init_optimizer(idOpti)
|
1286
|
+
self.associate_ptr(None, idOpti=idOpti)
|
1287
|
+
self.compute_optimizer(idOpti)
|
1288
|
+
# Collect the best parameters and their objective function(s)
|
1289
|
+
test_params = self.apply_optim(None, replace_only_if_better=(i_best!=0)) # Always apply the best parameters for the first iteration
|
1290
|
+
# If test_params are not the best or 1st test => We don't save them
|
1291
|
+
if test_params is not None:
|
1292
|
+
best_params = test_params
|
1293
|
+
if best_params_overall is None:
|
1294
|
+
best_params_overall = best_params
|
1295
|
+
elif best_params[-1] > best_params_overall[-1]:
|
1296
|
+
best_params_overall = best_params
|
1297
|
+
i_best_overal = cur_i
|
1298
|
+
# copy the optimisation results to save it on the disk
|
1299
|
+
shutil.copyfile(os.path.join(self.workingDir, stationOut+".rpt.dat"),
|
1300
|
+
os.path.join(self.workingDir, stationOut+"_"+str(cur_i+1)+".rpt.dat"))
|
1301
|
+
shutil.copyfile(os.path.join(self.workingDir, stationOut+".rpt"),
|
1302
|
+
os.path.join(self.workingDir, stationOut+"_"+str(cur_i+1)+".rpt"))
|
1303
|
+
cur_i += 1
|
1304
|
+
# Apply the best parameters overall attemps
|
1305
|
+
self.apply_optim(None,optim_params=best_params_overall)
|
1306
|
+
# copy the optimisation results to save it on the disk
|
1307
|
+
shutil.copyfile(os.path.join(self.workingDir, stationOut+"_"+str(i_best_overal+1)+".rpt.dat"),
|
1308
|
+
os.path.join(self.workingDir, stationOut+".rpt.dat"))
|
1309
|
+
shutil.copyfile(os.path.join(self.workingDir, stationOut+"_"+str(i_best_overal+1)+".rpt"),
|
1310
|
+
os.path.join(self.workingDir, stationOut+".rpt"))
|
1311
|
+
|
1312
|
+
|
1223
1313
|
# Simulation with the best parameters
|
1224
1314
|
self.compute_distributed_hydro_model()
|
1225
1315
|
# Update myHydro of all effective subbasins to get the best configuration upstream
|
@@ -1245,7 +1335,7 @@ class Optimisation(wx.Frame):
|
|
1245
1335
|
# Will update all the normal parameters
|
1246
1336
|
for element in self.myParams:
|
1247
1337
|
junctionName = self.myParams[element]["junction_name"]
|
1248
|
-
paramValue = self.
|
1338
|
+
paramValue = self.curParams_vec_F[element-1]
|
1249
1339
|
if paramValue != self.myParams[element]["value"]:
|
1250
1340
|
self.myParams[element]["value"] = paramValue
|
1251
1341
|
isOk = self.myParams[element]["update"](junctionName, value=paramValue)
|
@@ -1263,7 +1353,7 @@ class Optimisation(wx.Frame):
|
|
1263
1353
|
isOk = self.myCases[0].refCatchment.update_hydro(idCompar, fromLevel=False)
|
1264
1354
|
tf = time_mod.process_time()
|
1265
1355
|
print("Time in update_hydro() : ", tf-t0)
|
1266
|
-
print("curParam = ", self.
|
1356
|
+
print("curParam = ", self.curParams_vec_F)
|
1267
1357
|
print("All timeDelays = ", self.myCases[0].refCatchment.get_all_timeDelay())
|
1268
1358
|
tf = time_mod.process_time()
|
1269
1359
|
print("Time in update_hydro() : ", tf-t0)
|
@@ -1290,7 +1380,7 @@ class Optimisation(wx.Frame):
|
|
1290
1380
|
def update_timeDelay(self, index):
|
1291
1381
|
|
1292
1382
|
isOk = 0.0
|
1293
|
-
newTimeDelay = self.
|
1383
|
+
newTimeDelay = self.curParams_vec_F[index-1]
|
1294
1384
|
if(self.myParamsPy[index]["value"]!=newTimeDelay):
|
1295
1385
|
junctionName = self.myParamsPy[index]["junction_name"]
|
1296
1386
|
self.myParamsPy[index]["value"] = newTimeDelay
|
@@ -1535,7 +1625,7 @@ class Optimisation(wx.Frame):
|
|
1535
1625
|
|
1536
1626
|
wx.Exit()
|
1537
1627
|
|
1538
|
-
|
1628
|
+
|
1539
1629
|
def get_all_outlets(self, event, idLauncher:int=0):
|
1540
1630
|
# this function will save all the hydrographs with the optimal parameters
|
1541
1631
|
|
@@ -1720,9 +1810,9 @@ class Optimisation(wx.Frame):
|
|
1720
1810
|
|
1721
1811
|
myModelDict = cste.modelParamsDict[myModel]["Parameters"]
|
1722
1812
|
|
1723
|
-
if self.
|
1724
|
-
or len(self.
|
1725
|
-
self.
|
1813
|
+
if self.curParams_vec_F is None \
|
1814
|
+
or len(self.curParams_vec_F) != self.nbParams:
|
1815
|
+
self.curParams_vec_F = np.empty((self.nbParams,), dtype=ct.c_double, order='F')
|
1726
1816
|
|
1727
1817
|
for i in range(self.nbParams):
|
1728
1818
|
myType = self.myParams[i+1]["type"]
|
@@ -1742,7 +1832,7 @@ class Optimisation(wx.Frame):
|
|
1742
1832
|
tmpWolf = None
|
1743
1833
|
else:
|
1744
1834
|
|
1745
|
-
self.
|
1835
|
+
self.curParams_vec_F[i] = params[i]
|
1746
1836
|
self.update_timeDelay(i+1)
|
1747
1837
|
refCatch.save_timeDelays([self.myParams[i+1]["junction_name"]])
|
1748
1838
|
print("TO DO : Complete the python parameter dict!!!!!!!")
|
@@ -1768,31 +1858,96 @@ class Optimisation(wx.Frame):
|
|
1768
1858
|
refCatch.update_hydro(idCompar=0)
|
1769
1859
|
|
1770
1860
|
|
1771
|
-
def remove_py_params(self, idLauncher:int=0):
|
1772
|
-
cur_opti = self.myCases[idLauncher]
|
1773
|
-
paramDict = cur_opti.launcherParam
|
1774
|
-
nb_params = int(paramDict.get_param("Paramètres à varier", "Nombre de paramètres à varier"))
|
1775
1861
|
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1862
|
+
def remove_py_params(self, idLauncher:int=0):
|
1863
|
+
"""
|
1864
|
+
Removes the Python parameters from the optimization configuration.
|
1865
|
+
|
1866
|
+
Args:
|
1867
|
+
idLauncher (int, optional): The ID of the launcher. Defaults to 0.
|
1868
|
+
"""
|
1869
|
+
cur_opti = self.myCases[idLauncher]
|
1870
|
+
paramDict = cur_opti.launcherParam
|
1871
|
+
nb_params = int(paramDict.get_param("Paramètres à varier", "Nombre de paramètres à varier"))
|
1872
|
+
|
1873
|
+
myModel = self.myCases[idLauncher].refCatchment.myModel
|
1874
|
+
nbParamsModel = cste.modelParamsDict[myModel]["Nb"]
|
1875
|
+
|
1876
|
+
for i in range(1,nb_params+1):
|
1877
|
+
curParam = "param_" + str(i)
|
1878
|
+
curType = int(paramDict.get_param(curParam, "type_of_data"))
|
1879
|
+
if curType < 0:
|
1880
|
+
del paramDict.myparams[curParam]
|
1881
|
+
nb_params -= 1
|
1882
|
+
|
1883
|
+
# Test
|
1884
|
+
if nb_params > nbParamsModel:
|
1885
|
+
logging.error("The number of to optimise are greater than the number of max parameter of the model!! ")
|
1886
|
+
return
|
1790
1887
|
|
1791
|
-
|
1888
|
+
self.myCases[idLauncher].launcherParam.change_param("Paramètres à varier", "Nombre de paramètres à varier", nb_params)
|
1792
1889
|
|
1793
|
-
|
1890
|
+
return
|
1891
|
+
|
1794
1892
|
|
1893
|
+
def select_opti_intervals(self, idLauncher:int=0, stationOut=""):
|
1894
|
+
cur_opti = self.myCases[idLauncher]
|
1895
|
+
cur_ref = cur_opti.refCatchment
|
1896
|
+
if stationOut == "":
|
1897
|
+
stationOut = cur_ref.junctionOut
|
1898
|
+
file_compare = os.path.join(self.workingDir,"compare.txt")
|
1899
|
+
isOk, file_compare = check_path(file_compare)
|
1900
|
+
if isOk<0:
|
1901
|
+
logging.error("The file compare.txt is not found!")
|
1902
|
+
return
|
1903
|
+
meas_hydro = SubBasin()
|
1904
|
+
|
1905
|
+
nb_comparison = self.comparHowParam.get_param("Comparison global characteristics", "nb")
|
1906
|
+
str_di = "date begin"
|
1907
|
+
str_df = "date end"
|
1908
|
+
for icomp in range(1, nb_comparison):
|
1909
|
+
cur_key = " ".join("Comparison", str(icomp))
|
1910
|
+
nb_intervals = self.comparHowParam.get_param(cur_key, "nb_intervals")
|
1911
|
+
for i_inter in range(1,nb_intervals):
|
1912
|
+
str_read = self.comparHowParam.get_param(" ".join(str_di,str(i_inter)))
|
1913
|
+
di = datetime.datetime.timestamp(
|
1914
|
+
datetime.datetime.strptime(str_read, cst.DATE_FORMAT_HYDRO).replace(tzinfo=datetime.timezone.utc))
|
1915
|
+
str_read = self.comparHowParam.get_param(" ".join(str_df,str(i_inter)))
|
1916
|
+
df = datetime.datetime.timestamp(
|
1917
|
+
datetime.datetime.strptime(str_read, cst.DATE_FORMAT_HYDRO).replace(tzinfo=datetime.timezone.utc))
|
1918
|
+
# Check that di is a timestamp lower than other date
|
1919
|
+
|
1920
|
+
|
1921
|
+
def prepare_init_params_from_best(self, best_params:np.array, idLauncher:int=0):
|
1922
|
+
# If there are no best params the initial values will be random
|
1923
|
+
if best_params is None:
|
1924
|
+
# Force the initial parameters to be defined randomly
|
1925
|
+
self.saParam.change_param("Initial parameters", "Read initial parameters?", 0)
|
1926
|
+
return
|
1927
|
+
|
1928
|
+
# In the following code, we apply the best parameters to the initial parameters
|
1929
|
+
self.saParam.change_param("Initial parameters", "Read initial parameters?", 1)
|
1930
|
+
for i in range(self.nbParams):
|
1931
|
+
self.saParam.change_param("Initial parameters", " ".join(["Parameter",str(i+1)]), best_params[i])
|
1932
|
+
|
1933
|
+
self.saParam.SavetoFile(None)
|
1934
|
+
self.saParam.Reload(None)
|
1795
1935
|
|
1936
|
+
|
1937
|
+
def get_initial_parameters(self)-> np.array:
|
1938
|
+
read_IP = self.saParam.get_param("Initial parameters", "Read initial parameters?")
|
1939
|
+
if read_IP == 1:
|
1940
|
+
# FIXME : Generalise for more than 1 objctive function
|
1941
|
+
init_params = np.zeros(self.nbParams+1)
|
1942
|
+
for i in range(self.nbParams):
|
1943
|
+
init_params[i] = self.saParam.get_param("Initial parameters", " ".join(["Parameter",str(i+1)]))
|
1944
|
+
init_params[-1] = -sys.float_info.max
|
1945
|
+
else:
|
1946
|
+
init_params = None
|
1947
|
+
|
1948
|
+
return init_params
|
1949
|
+
|
1950
|
+
|
1796
1951
|
def make_nd_array(self, c_pointer, shape, dtype=np.float64, order='C', own_data=True,readonly=False):
|
1797
1952
|
arr_size = np.prod(shape[:]) * np.dtype(dtype).itemsize
|
1798
1953
|
|
@@ -1809,5 +1964,3 @@ class Optimisation(wx.Frame):
|
|
1809
1964
|
return arr.copy()
|
1810
1965
|
else:
|
1811
1966
|
return arr
|
1812
|
-
|
1813
|
-
|
@@ -56,51 +56,51 @@ class PostProcessHydrology(wx.Frame):
|
|
56
56
|
# Reading of the input file 'Input.compar'
|
57
57
|
paramsCompar = Wolf_Param(to_read=False,toShow=False)
|
58
58
|
paramsCompar.ReadFile(self.filename)
|
59
|
-
nbCatchment = int(paramsCompar.myparams['Main information']['nb catchment'][
|
59
|
+
nbCatchment = int(paramsCompar.myparams['Main information']['nb catchment'][key_Param.VALUE])
|
60
60
|
|
61
61
|
beginElement = 'Catchment '
|
62
62
|
for i in range(1,nbCatchment+1):
|
63
63
|
element = beginElement + str(i)
|
64
64
|
self.myCatchments[element]={}
|
65
|
-
self.myCatchments[element]['Title'] = paramsCompar.myparams[element]['name'][
|
66
|
-
# Just check and correct the name of the filePath the way
|
67
|
-
paramsCompar.myparams[element]['filePath'][
|
68
|
-
if not(paramsCompar.myparams[element]['filePath'][
|
69
|
-
paramsCompar.myparams[element]['filePath'][
|
70
|
-
dirName = paramsCompar.myparams[element]['filePath'][
|
65
|
+
self.myCatchments[element]['Title'] = paramsCompar.myparams[element]['name'][key_Param.VALUE]
|
66
|
+
# Just check and correct the name of the filePath the way
|
67
|
+
paramsCompar.myparams[element]['filePath'][key_Param.VALUE] = paramsCompar.myparams[element]['filePath'][key_Param.VALUE].replace("\\", "/")
|
68
|
+
if not(paramsCompar.myparams[element]['filePath'][key_Param.VALUE].endswith('/')):
|
69
|
+
paramsCompar.myparams[element]['filePath'][key_Param.VALUE] = paramsCompar.myparams[element]['filePath'][key_Param.VALUE] + '/'
|
70
|
+
dirName = paramsCompar.myparams[element]['filePath'][key_Param.VALUE]
|
71
71
|
# Read the name of the input file
|
72
72
|
try:
|
73
|
-
self.fileName = paramsCompar.myparams[element]['fileName'][
|
73
|
+
self.fileName = paramsCompar.myparams[element]['fileName'][key_Param.VALUE]
|
74
74
|
except:
|
75
75
|
self.fileName = "Input.postPro"
|
76
76
|
|
77
77
|
paramsCatchment = Wolf_Param(to_read=False, toShow=False)
|
78
78
|
paramsCatchment.ReadFile(dirName+self.fileName)
|
79
|
-
nameCatchment = paramsCatchment.myparams['Main information']['Name'][
|
79
|
+
nameCatchment = paramsCatchment.myparams['Main information']['Name'][key_Param.VALUE]
|
80
80
|
|
81
|
-
paramsCatchment.myparams['Main information']['directoryPath'][
|
82
|
-
if not(paramsCatchment.myparams['Main information']['directoryPath'][
|
83
|
-
paramsCatchment.myparams['Main information']['directoryPath'][
|
84
|
-
dirCatchment = paramsCatchment.myparams['Main information']['directoryPath'][
|
81
|
+
paramsCatchment.myparams['Main information']['directoryPath'][key_Param.VALUE] = paramsCatchment.myparams['Main information']['directoryPath'][key_Param.VALUE].replace("\\", "/")
|
82
|
+
if not(paramsCatchment.myparams['Main information']['directoryPath'][key_Param.VALUE].endswith('/')):
|
83
|
+
paramsCatchment.myparams['Main information']['directoryPath'][key_Param.VALUE] = paramsCatchment.myparams['Main information']['directoryPath'][key_Param.VALUE] + '/'
|
84
|
+
dirCatchment = paramsCatchment.myparams['Main information']['directoryPath'][key_Param.VALUE]
|
85
85
|
|
86
86
|
isOk, dirCatchment = check_path(dirCatchment, prefix=self.directoryPath,applyCWD=True)
|
87
87
|
if isOk<0:
|
88
88
|
print("ERROR : Problem in directory path!")
|
89
89
|
|
90
90
|
try:
|
91
|
-
catchmentFileName = paramsCatchment.myparams['Main information']['Catchment file name'][
|
91
|
+
catchmentFileName = paramsCatchment.myparams['Main information']['Catchment file name'][key_Param.VALUE]
|
92
92
|
except:
|
93
93
|
catchmentFileName = ""
|
94
94
|
try:
|
95
|
-
rbFileName = paramsCatchment.myparams['Main information']['RB file name'][
|
95
|
+
rbFileName = paramsCatchment.myparams['Main information']['RB file name'][key_Param.VALUE]
|
96
96
|
except:
|
97
97
|
rbFileName = ""
|
98
98
|
try:
|
99
|
-
tz = int(paramsCatchment.myparams['Main information']['time zone'][
|
99
|
+
tz = int(paramsCatchment.myparams['Main information']['time zone'][key_Param.VALUE])
|
100
100
|
except:
|
101
101
|
tz = 0
|
102
102
|
|
103
|
-
if(int(paramsCatchment.myparams['Plot information']['plot all subbasin'][
|
103
|
+
if(int(paramsCatchment.myparams['Plot information']['plot all subbasin'][key_Param.VALUE]) == 1):
|
104
104
|
plotAllHydro = True
|
105
105
|
else:
|
106
106
|
plotAllHydro = False
|
@@ -109,7 +109,7 @@ class PostProcessHydrology(wx.Frame):
|
|
109
109
|
else:
|
110
110
|
isCompared = True
|
111
111
|
self.myCatchments[element]['Object'] = Catchment(nameCatchment, dirCatchment, plotAllHydro, isCompared, _catchmentFileName=catchmentFileName, _rbFileName=rbFileName, _tz=tz)
|
112
|
-
if(nbCatchment>0):
|
112
|
+
if(nbCatchment>0):
|
113
113
|
dictToCompare = paramsCompar.myparams['Plots']
|
114
114
|
self.myComparison = Comparison(self.directoryPath, self.myCatchments, dictToCompare)
|
115
115
|
self.myComparison.compare_now()
|
@@ -119,17 +119,17 @@ class PostProcessHydrology(wx.Frame):
|
|
119
119
|
self.myCatchments['Catchment 1']['Title']=''
|
120
120
|
paramsCatchment = Wolf_Param(to_read=False, toShow=False)
|
121
121
|
paramsCatchment.ReadFile(self.filename)
|
122
|
-
nameCatchment = paramsCatchment.myparams['Main information']['Name'][
|
123
|
-
if(int(paramsCatchment.myparams['Plot information']['plot all subbasin'][
|
122
|
+
nameCatchment = paramsCatchment.myparams['Main information']['Name'][key_Param.VALUE]
|
123
|
+
if(int(paramsCatchment.myparams['Plot information']['plot all subbasin'][key_Param.VALUE]) == 1):
|
124
124
|
plotAllHydro = True
|
125
125
|
else:
|
126
126
|
plotAllHydro = False
|
127
127
|
isCompared = False
|
128
128
|
try:
|
129
|
-
tz = int(paramsCatchment.myparams['Main information']['time zone'][
|
129
|
+
tz = int(paramsCatchment.myparams['Main information']['time zone'][key_Param.VALUE])
|
130
130
|
except:
|
131
131
|
tz = 0
|
132
|
-
|
132
|
+
|
133
133
|
self.myCatchments['Catchment 1']['Object'] = Catchment(nameCatchment, self.directoryPath, plotAllHydro, _plotNothing=False, _tz=tz)
|
134
134
|
|
135
135
|
else:
|
wolfhece/hydrology/SubBasin.py
CHANGED
@@ -2125,8 +2125,8 @@ class SubBasin:
|
|
2125
2125
|
paramFile = Wolf_Param(to_read=False,toShow=False)
|
2126
2126
|
paramFile.ReadFile(path +'simul_flood.out.param')
|
2127
2127
|
|
2128
|
-
nbFloods = int(paramFile.myparams['Floods characteristics']['nb'][
|
2129
|
-
dt = float(paramFile.myparams['Floods characteristics']['dt'][
|
2128
|
+
nbFloods = int(paramFile.myparams['Floods characteristics']['nb'][key_Param.VALUE])
|
2129
|
+
dt = float(paramFile.myparams['Floods characteristics']['dt'][key_Param.VALUE])
|
2130
2130
|
|
2131
2131
|
filePre = "simul_flood"
|
2132
2132
|
floodData = []
|
@@ -2964,38 +2964,38 @@ class SubBasin:
|
|
2964
2964
|
logging.error("=================")
|
2965
2965
|
|
2966
2966
|
return gOutFlow
|
2967
|
-
|
2967
|
+
|
2968
2968
|
|
2969
2969
|
@property
|
2970
2970
|
def cumul_rain(self) -> np.array:
|
2971
2971
|
return np.cumsum(self.myRain)
|
2972
|
-
|
2972
|
+
|
2973
2973
|
|
2974
2974
|
|
2975
2975
|
def evaluate_Nash(self, measure,
|
2976
2976
|
intervals:list[tuple[datetime.datetime]]=[]) -> list[float]:
|
2977
2977
|
ns = []
|
2978
|
-
|
2978
|
+
|
2979
2979
|
if intervals == []:
|
2980
|
-
ns.append( datt.evaluate_Nash(self.outFlow, self.time,
|
2981
|
-
measures=measure.get_myHydro(), tMeasures=measure.time,
|
2980
|
+
ns.append( datt.evaluate_Nash(self.outFlow, self.time,
|
2981
|
+
measures=measure.get_myHydro(), tMeasures=measure.time,
|
2982
2982
|
dateBegin=self.dateBegin, dateEnd=self.dateEnd) )
|
2983
2983
|
return tuple(ns)
|
2984
|
-
|
2984
|
+
|
2985
2985
|
# for el in intervals:
|
2986
|
-
# ns.append( datt.evaluate_Nash(self.outFlow, self.time,
|
2987
|
-
# measures=measure.get_myHydro(), tMeasures=measure.time,
|
2986
|
+
# ns.append( datt.evaluate_Nash(self.outFlow, self.time,
|
2987
|
+
# measures=measure.get_myHydro(), tMeasures=measure.time,
|
2988
2988
|
# dateBegin=el[0], dateEnd=el[1]) )
|
2989
|
-
ns = [ datt.evaluate_Nash(self.outFlow, self.time,
|
2990
|
-
measures=measure.get_myHydro(), tMeasures=measure.time,
|
2989
|
+
ns = [ datt.evaluate_Nash(self.outFlow, self.time,
|
2990
|
+
measures=measure.get_myHydro(), tMeasures=measure.time,
|
2991
2991
|
dateBegin=el[0], dateEnd=el[1])
|
2992
2992
|
for el in intervals ]
|
2993
2993
|
|
2994
2994
|
return tuple(ns)
|
2995
|
-
|
2995
|
+
|
2996
2996
|
|
2997
2997
|
def get_peak(self, intervals:list[tuple[datetime.datetime]]=[]) -> list[float]:
|
2998
|
-
|
2998
|
+
|
2999
2999
|
peak_s = []
|
3000
3000
|
for element in intervals:
|
3001
3001
|
# We conisder the indice to form complete intervals
|
@@ -3004,11 +3004,11 @@ class SubBasin:
|
|
3004
3004
|
# meas_i = math.floor((element[0]-measure.dateBegin).total_seconds/measure.deltaT)
|
3005
3005
|
# meas_f = math.floor((element[1]-measure.dateBegin).total_seconds/measure.deltaT)
|
3006
3006
|
if simul_i<0 or simul_f>len(self.time):
|
3007
|
-
continue
|
3007
|
+
continue
|
3008
3008
|
peak_s.append(self.outFlow[simul_i:simul_f+1].max())
|
3009
|
-
|
3009
|
+
|
3010
3010
|
return peak_s
|
3011
|
-
|
3011
|
+
|
3012
3012
|
|
3013
3013
|
|
3014
3014
|
# FIXME Finish the function below -> returning all possible or desired internal variables
|
wolfhece/hydrology/constant.py
CHANGED
@@ -34,6 +34,10 @@ DEFAULT_LANDUSE[5] = _("rivière")
|
|
34
34
|
DEFAULT_LANDUSE[6] = _("plan d'eau")
|
35
35
|
|
36
36
|
|
37
|
+
##
|
38
|
+
DATE_FORMAT_HYDRO = '%Y-%m-%dT%H:%M:%S'
|
39
|
+
|
40
|
+
|
37
41
|
## Version of the code
|
38
42
|
VERSION_WOLFHYDRO_2023_0 = "2023.1" # First version to include the versioning
|
39
43
|
VERSION_WOLFHYDRO_2023_1 = "2023.1" # First version to include the versioning
|
@@ -36,7 +36,8 @@ exchange_parameters_Dist_Soil_TSPAN = 113 #Paramètre modèle distribué Soil
|
|
36
36
|
exchange_parameters_Dist_Horton_F0 = 114 #Paramètre modèle distribué Horton
|
37
37
|
exchange_parameters_Dist_Horton_FC = 115 #Paramètre modèle distribué Horton
|
38
38
|
exchange_parameters_Dist_Horton_K = 116 #Paramètre modèle distribué Horton
|
39
|
-
exchange_parameters_Dist_kif = 117 #Paramètre modèle distribué
|
39
|
+
exchange_parameters_Dist_kif = 117 #Paramètre modèle distribué pour réservoir linéaire couche épidermique (if)
|
40
|
+
exchange_parameters_Dist_qlif = 118 #Paramètre modèle distribué pour réservoir linéaire couche épidermique (if)
|
40
41
|
|
41
42
|
|
42
43
|
# Constants representing the exchanges - Python
|
Binary file
|
Binary file
|
wolfhece/libs/WolfDll.dll
CHANGED
Binary file
|
Binary file
|
Binary file
|
wolfhece/mesh2d/wolf2dprev.py
CHANGED
@@ -1885,8 +1885,8 @@ class prev_parameters_simul:
|
|
1885
1885
|
|
1886
1886
|
def getvaluesx(self, event):
|
1887
1887
|
for curmodel in self.mysimuls.values():
|
1888
|
-
if curmodel
|
1889
|
-
locmodel = curmodel
|
1888
|
+
if curmodel.checked:
|
1889
|
+
locmodel = curmodel
|
1890
1890
|
|
1891
1891
|
curcol = 3
|
1892
1892
|
if locmodel is self.parent:
|
@@ -1917,8 +1917,8 @@ class prev_parameters_simul:
|
|
1917
1917
|
|
1918
1918
|
def getvaluesy(self, event):
|
1919
1919
|
for curmodel in self.mysimuls.values():
|
1920
|
-
if curmodel
|
1921
|
-
locmodel = curmodel
|
1920
|
+
if curmodel.checked:
|
1921
|
+
locmodel = curmodel
|
1922
1922
|
|
1923
1923
|
curcol = 3
|
1924
1924
|
if locmodel is self.parent:
|