hydrocnhs.calibration package

Submodules

hydrocnhs.calibration.convertor module

class hydrocnhs.calibration.convertor.Convertor

Bases: object

gen_cali_inputs(wd, df_list, par_bound_df_list, fixed_par_list=None)

Generate inputs dictionary required for calibration.

Parameters:
  • wd (str) – Working directory.

  • df_list (list) – A list of parameter dataframes. Dataframe index is parameter names.

  • par_bound_df_list (list) – A list of parameter bound dataframes.

  • fixed_par_list (list, optional) – A list contains a list of tuples of fixed parameter location like [([“CN2”], [“outlet1”, “outlet2”]), ([“b”], [“outlet1”])], by default None. The number of tuples in the list is corresponding to the number of dataframes.

Returns:

Input for calibration.

Return type:

dict

gen_formatter(df_list, fixed_par_list=None)

Generate formatter for given list of dataframe objects. This is already included in gen_cali_inputs().

Parameters:
  • df_list (list) – A list of parameter dataframes. Dataframe index is parameter names.

  • fixed_par_list (list, optional) – A list contains a list of tuples of fixed parameter location. For example, we want to fix par1 of outlet1 & 2 and all par2 in dataframe 1 and not to fix df2. We can input the following list, [[([“par1”], [“outlet1”, “outlet2”]), ([“par2”], [“:”])], []]. fixed_par_list is by default None. The number of lists in the list is corresponding to the number of dataframes.

Returns:

formatter.

Return type:

dict

static to_1D_array(df_list, formatter)

Convert a list of dataframes to a 1D array.

Parameters:
  • df_list (list) – A list of parameter dataframes. Dataframe index is parameter names.

  • formatter (dict) – Formatter, generated by gen_formatter or gen_cali_inputs. It is stored in attributes of the Convertor object.

Returns:

1D array.

Return type:

array

static to_df_list(var_array, formatter)

Convert 1D array back to a list of dataframes.

Parameters:
  • var_array (array) – 1D array.

  • formatter (dict) – Formatter, generated by gen_formatter or gen_cali_inputs. It is stored in attributes of the Convertor object.

Returns:

A list of dataframes.

Return type:

list

hydrocnhs.calibration.ga_deap module

class hydrocnhs.calibration.ga_deap.GA_DEAP(evaluation_func=<function GA_DEAP.<lambda>>, rn_gen=None)

Bases: object

auto_save()
find_best_and_record(pop)
gen_rn_gens(seed, size)
load(GA_auto_save_file, max_gen=None)

Load save pickle file (i.e., continue previous run).

Parameters:
  • GA_auto_save_file (str) – Filename.

  • max_gen (int, optional) – This allow user to increase max_gen for continuing calibration for a longer searching, by default None.

run(guess_pop=None)

Run calibration.

Parameters:

guess_pop (2darray, optional) – Assigned initial guesses, by default None. guess_pop has the size = [number of guesses, number of parameters]

run_individual(individual='best', name='best')

Run the evaluation for a given individual.

Warning! run_individual() does not generantee the same rn_gen will be assign to the evaluation, but the same one will be used for run_individual()

Parameters:
  • individual (1darray, optional) – Individual or solution, by default “best”.

  • name (str, optional) – This will be sent to the evaluation function through info = (cali_wd, name, name, formatter, rn_gen), by default “best”.

set(inputs, config, formatter=None, name='Calibration')

Setup the GA calibration.

Parameters:
  • inputs (dict) – Calibration input dictionary generated by Convertor. Or, get the template by calling get_inputs_template().

  • config (dict) – Calibration configuration dictionary. Get the template by calling get_config_template().

  • formatter (dict, optional) – Formatter generated by Convertor, by default None.

  • name (str, optional) – Name of the calibration, by default “Calibration”.

hydrocnhs.calibration.ga_deap.cxUniform(ind1, ind2, indpb, rn_gen_gen)
hydrocnhs.calibration.ga_deap.descale(individual, bound_scale, lower_bound)

individual is 1d ndarray.

hydrocnhs.calibration.ga_deap.gen_init_pop(creator, size, method='LHC', guess_pop=None, rn_gen_gen=None)
hydrocnhs.calibration.ga_deap.logger = <Logger HydroCNHS.GA (WARNING)>
[“a”,”b”,”c”],

“par_bound”: [[0,1],[0,1],[0,1]], “wd”: r””}

config = {“min_or_max”: “min”,

“pop_size”: 100, “num_ellite”: 1, “prob_cross”: 0.5, “prob_mut”: 0.1, “stochastic”: False, “max_gen”: 100, “sampling_method”: “LHC”, “drop_record”: False, “paral_cores”: -1, “paral_verbose”: 1, “auto_save”: True, “print_level”: 10, “plot”: True }

Type:

inputs = {“par_name”

hydrocnhs.calibration.ga_deap.mut_middle(individual, p1, p2, prob_mut, rn_gen_gen)
hydrocnhs.calibration.ga_deap.mut_uniform(individual, prob_mut, rn_gen_gen)
hydrocnhs.calibration.ga_deap.sample_by_LHC(size, rn_gen_gen)
hydrocnhs.calibration.ga_deap.sample_by_MC(size, rn_gen_gen)
hydrocnhs.calibration.ga_deap.scale(individual, bound_scale, lower_bound)

individual is 1d ndarray.

hydrocnhs.calibration.ga_deap.selRoulette(individuals, k, rn_gen_gen, fit_attr='fitness')

Module contents

hydrocnhs.calibration.get_config_template()
hydrocnhs.calibration.get_inputs_template()
hydrocnhs.calibration.helper()