wolfhece.hydrology.Optimisation
Author: HECE - University of Liege, Pierre Archambeau, Christophe Dessers Date: 2024
Copyright (c) 2024 University of Liege. All rights reserved.
This script and its content are protected by copyright law. Unauthorized copying or distribution of this file, via any medium, is strictly prohibited.
Module Contents
- class wolfhece.hydrology.Optimisation.CaseOpti(*args, **kw)[source]
Bases:
wolfhece.PyGui.GenMapManager
Default class for a Wolf Map Manager.
Will be overriden by the specific classes MapManager, GPU2DModel, HydrologyModel, Wolf2DModel.
It is not suitable for direct use.
- class wolfhece.hydrology.Optimisation.Optimisation(parent=None, title='', w=500, h=500, init_wx=True, debugDLL=False, for_test: bool = False)[source]
Bases:
wolfhece.wolf_array.wx.Frame
- all_intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]][source]
- apply_optim(event, idLauncher: int = 0, replace_only_if_better: bool = False, optim_params: wolfhece.wolf_array.np.ndarray = None)[source]
Apply optimal parameters based on the results file of the optimisation : “.rpt”.
- Parameters:
event – The event from the GUI.
(optional (replace_only_if_better) – int(0)): The ID of the launcher.
(optional – bool(False) by default): A boolean indicating whether to replace the current parameters if the new ones are better.
- Returns:
If replace_only_if_better is False, returns the best parameters found. If replace_only_if_better is True and the new parameters are better, returns the best parameters found. Otherwise, returns None.
- load_dll(path: str, fileName: str = 'WolfDLL.dll')[source]
Load the Fortran DLL for optimization.
- Parameters:
path – The directory where the DLL is located.
fileName – The name of the DLL file to load.
- get_all_activated_iv(idOpti: int = 1, idLauncher: int = 0, iv_variables: tuple[wolfhece.wolf_array.np.ndarray, wolfhece.wolf_array.np.ndarray] = None) tuple[wolfhece.wolf_array.np.ndarray, wolfhece.wolf_array.np.ndarray] [source]
- launch_semiDistributed_optimisation(event, idOpti=1, idLauncher=0)[source]
Procedure launching the semi-distributed optimisation process.
- Parameters:
event – The event triggering the optimisation.
idOpti (int) – The ID of the optimizer in Fortran.
idLauncher (int) – The ID of the launcher.
- Returns:
None
- reload_hydro(idCompar, firstLevel: int = 1, lastLevel: int = -1, fromStation: str = '', updateAll: bool = False)[source]
- read_all_attempts_SA(format='rpt', all_attempts=False, filter_repetitions=True, stationOut: str = '')[source]
- remove_py_params(idLauncher: int = 0)[source]
Removes the Python parameters from the optimization configuration.
- Parameters:
idLauncher (int, optional) – The ID of the launcher. Defaults to 0.
- _read_opti_intervals(idLauncher: int = 0) list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]] [source]
- _save_opti_intervals(idLauncher: int = 0, stationOut: str = '', intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]] = None) int [source]
- select_opti_intervals(all_intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]] = None, idLauncher: int = 0, stationOut='', filter_nan: bool = True) list[tuple] [source]
- _define_intervals_with_ts(intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]], time: wolfhece.wolf_array.np.ndarray, ts: wolfhece.wolf_array.np.ndarray, idLauncher: int = 0)[source]
Defines new intervals excluding all NaN measures based on the given intervals and measures dictionary. For instance, if there is continuous NaN measures within a given interval, the function will split that interval into smaller that do not contain NaN measures.
- Parameters:
intervals (list[tuple[datetime.datetime, datetime.datetime]]) – A list of intervals represented as tuples of start and end datetime objects.
ts (dict[str, SubBasin]) – A dictionary of time series where the keys are station names and the values are vectors of numpy array.
idLauncher (int, optional) – The id of the launcher. Defaults to 0.
stationOut (str, optional) – The station name. Defaults to “”.
- Returns:
A list of intervals with NaN measures.
- Return type:
list[tuple[datetime.datetime, datetime.datetime]]
- Raises:
None –
- _define_intervals_with_nan_inlets(intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]], measures: dict[str, wolfhece.hydrology.Comparison.SubBasin], idLauncher: int = 0, stationOut: str = '')[source]
Defines new intervals excluding all NaN measures based on the given intervals and measures dictionary. For instance, if there is continuous NaN measures within a given interval, the function will split that interval into smaller that do not contain NaN measures.
- Parameters:
intervals (list[tuple[datetime.datetime, datetime.datetime]]) – A list of intervals represented as tuples of start and end datetime objects.
measures (dict[str, SubBasin]) – A dictionary of measures where the keys are station names and the values are SubBasin objects.
idLauncher (int, optional) – The id of the launcher. Defaults to 0.
stationOut (str, optional) – The station name. Defaults to “”.
- Returns:
A list of intervals with NaN measures.
- Return type:
list[tuple[datetime.datetime, datetime.datetime]]
- Raises:
None –
- _define_intervals_with_nan_measures(intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]], measures: dict[str, wolfhece.hydrology.Comparison.SubBasin], idLauncher: int = 0, stationOut: str = '')[source]
Defines new intervals excluding all NaN measures based on the given intervals and measures dictionary. For instance, if there is continuous NaN measures within a given interval, the function will split that interval into smaller that do not contain NaN measures.
- Parameters:
intervals (list[tuple[datetime.datetime, datetime.datetime]]) – A list of intervals represented as tuples of start and end datetime objects.
measures (dict[str, SubBasin]) – A dictionary of measures where the keys are station names and the values are SubBasin objects.
idLauncher (int, optional) – The id of the launcher. Defaults to 0.
stationOut (str, optional) – The station name. Defaults to “”.
- Returns:
A list of intervals with NaN measures.
- Return type:
list[tuple[datetime.datetime, datetime.datetime]]
- Raises:
None –
- save_opti_dates_to_file(opti_dates: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]])[source]
Here the procedure is saving the intervals of dates for calibration in the compare.how.param
- prepare_init_params_from_best(best_params: wolfhece.wolf_array.np.array, idLauncher: int = 0)[source]
- save_current_compare_file(stationOut: str)[source]
Save the current compare file for a given station to prepare optimisation with Fortran.
- Parameters:
stationOut (str) – The station identifier.
- Returns:
None
- Raises:
None –
- prepare_simulation(opti_intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]], idLauncher: int = 0)[source]
- reset_simulation_intervals(default_interval: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]], idLauncher: int = 0)[source]
- test_equifinality_with_Nash(event, idLauncher: int = 0, idOpti: int = 1, quantile_Nash: float = 0.01, std_Nash: float = 0.3, clustering_Nash: bool = True)[source]
Test the equifinality of the model.
- Parameters:
idLauncher (int, optional) – The id of the launcher. Defaults to 0.
- Returns:
None
- Raises:
None –
- get_best_params(stationOut: str, criterion: str = 'Nash', quantile: float = None, std: float = None, eps: float = 0.2, rmv_near_max=None, nb_rand_close: int = 10, objective_fct: bool = True, apply_clustering: bool = False, objective_weight: float = 1.0)[source]
- _get_exceedance(idLauncher: int = 0, stationOut: str = '', intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]] = []) float [source]
- _get_cur_fractions(idLauncher: int = 0, stationOut: str = '', intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]] = []) dict[list[str], list[float]] [source]
Save the evaluations of the model.
- Parameters:
idOpti (int, optional) – The id of the optimisation. Defaults to 1.
stationOut (str, optional) – The station identifier. Defaults to “”.
fct_list (list[str], optional) – A list of functions. Defaults to [].
- Returns:
None
- Raises:
None –
- _get_volume_fractions(idLauncher: int = 0, stationOut: str = '', intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]] = []) dict[list[str], list[float]] [source]
- _get_flow_fractions(idLauncher: int = 0, stationOut: str = '', intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]] = [], from_full_matrix: tuple[wolfhece.wolf_array.np.ndarray, wolfhece.wolf_array.np.ndarray] = None) dict[list[str], list[float]] [source]
This function retrieves the flow fractions for a given sub-basin. It can also take a “full matrix” of internal variables to compute the fractions. This “full matrix” is a tuple containing the ids of the internal variables and the matrix itself.
- Parameters:
idLauncher (int, optional) – ID of the launcher, defaults to 0
stationOut (str, optional) – Name of the outlet station, defaults to “”
intervals (list[tuple[datetime.datetime, datetime.datetime]], optional) – List of start date and end date for the intervals to evaluate the flow fractions, defaults to []
from_full_matrix (tuple[np.ndarray, np.ndarray], optional) – Containing the matrix (nb_t, nb_iv) of I.V. coming from the Fortran code directly (not read in files), defaults to None
- Returns:
Dictionary containing the flow fractions for each type of flow with their names as keys and the fractions as values.
- Return type:
dict[list[str], list[float]]
- _get_max_flow_fractions(idLauncher: int = 0, stationOut: str = '', intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]] = [], from_full_matrix: tuple[wolfhece.wolf_array.np.ndarray, wolfhece.wolf_array.np.ndarray] = None) dict[list[str], list[float]] [source]
- _get_punctual_reservoir_fractions(eval_date: wolfhece.hydrology.Comparison.datetime.datetime, idLauncher: int = 0, stationOut: str = '', from_full_matrix: tuple[wolfhece.wolf_array.np.ndarray, wolfhece.wolf_array.np.ndarray] = None) dict[list[str], list[float]] [source]
- _get_max_runoff(idLauncher: int = 0, stationOut: str = '', intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]] = []) dict[list[str], list[float]] [source]
- _get_ratio_max_sim_obs(idLauncher: int = 0, stationOut: str = '', intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]] = []) float [source]
- launch_semi_dist_parameters(idLauncher: int = 0, idOpti: int = 1, params_to_test: dict[str, wolfhece.wolf_array.np.ndarray] = {}, return_outflows: bool = False) dict[str, wolfhece.wolf_array.np.ndarray] [source]
- _prepare_opti_hydro_files(stationOut: str, idLauncher: int = 0, onlyOwnSub: bool = False, doneList: list[str] = [], previousLevel: int = 1)[source]
- write_one_opti_param(filPath: wolfhece.wolf_array.Path, fileName: wolfhece.wolf_array.Path, myGroup: str, myKey: str, value: float, convers_factor: int = 1.0)[source]
- launch_models_propertie_with_Nash_old(event, idLauncher: int = 0, idOpti: int = 1, quantile_Nash: float = 0.01, std_Nash: float = 0.03, clustering_Nash: bool = True, save_every: int = 100, restart_from_file: bool = True)[source]
Analyse the properties of the model and compare them with the Nash coefficient.
- Parameters:
idLauncher (int, optional) – The id of the launcher. Defaults to 0.
- Returns:
None
- Raises:
None –
- launch_models_propertie_with_Nash_old2(event, idLauncher: int = 0, idOpti: int = 1, quantile_Nash: float = 0.01, std_Nash: float = 0.03, clustering_Nash: bool = True, save_every: int = 1000, restart_from_file: bool = True, intervals: list[tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime]] = [])[source]
Analyse the properties of the model and compare them with the Nash coefficient.
- Parameters:
idLauncher (int, optional) – The id of the launcher. Defaults to 0.
- Returns:
None
- Raises:
None –
- launch_models_properties_with_Nash(event, idLauncher: int = 0, idOpti: int = 1, quantile_Nash: float = 0.01, std_Nash: float = 0.03, clustering_Nash: bool = False, save_every: int = 1000, restart_from_file: bool = False, evaluation_interval: tuple[wolfhece.hydrology.Comparison.datetime.datetime, wolfhece.hydrology.Comparison.datetime.datetime] = [])[source]
Analyse the properties of the model and compare them with the Nash coefficient.
- Parameters:
idLauncher (int, optional) – The id of the launcher. Defaults to 0.
- Returns:
None
- Raises:
None –
- _intersect_intervals(intervals: list[tuple[wolfhece.hydrology.read.date, wolfhece.hydrology.read.date]], flood_intervals: tuple[wolfhece.hydrology.read.date, wolfhece.hydrology.read.date])[source]
- reload_optimal_subbasin(idLauncher: int = 0, idOpti: int = 1, stationOut: str = None)[source]
Reload the optimal subbasin for a given idLauncher and idOpti.
- Parameters:
idLauncher (int) – The id of the launcher.
idOpti (int) – The id of the optimizer.
stationOut (str) – The name of the station.
- Returns:
None
- Raises:
None –
- init_optimize_model_f(idOpti: int = 1)[source]
Initialize the optimization model for a given idOpti.
- Parameters:
idOpti (int) – The id of the optimizer.
- Returns:
None
- Raises:
None –
- prepare_optimize_model_F_one_station(idLauncher: int = 0, idOpti: int = 1, stationOut: str = None, all_intervals: list[tuple[wolfhece.hydrology.read.date, wolfhece.hydrology.read.date]] = [], onlyOwnSub: bool = True, previousLevel: int = 1, already_done_subbasins: list[str] = [], return_intervals: bool = False)[source]
- extract_hydro_from_params(idLauncher: int = 0, idOpti: int = 1, stationOut: str = None, all_params: wolfhece.wolf_array.np.ndarray = None)[source]
Extract the hydro from the parameters.
- Parameters:
idLauncher (int) – The id of the launcher.
idOpti (int) – The id of the optimizer.
stationOut (str) – The name of the station.
all_params (np.ndarray) – The parameters to be tested.
- Returns:
None
- Raises:
None –
- make_nd_array(c_pointer, shape, dtype=np.float64, order='C', own_data=True, readonly=False)[source]
- _reload_model_analysis(stationOut: str, all_params: wolfhece.wolf_array.np.ndarray) tuple[list, wolfhece.wolf_array.np.ndarray] [source]
Reload the model analysis for a given station.
- Parameters:
stationOut (str) – The name of the station.
all_params (np.ndarray) – The parameters to be tested.
- Returns:
None
- Raises:
None –