easy_vic_build.calibrate
calibrate - A Python module for calibrating the VIC model.
This module provides functionality for calibrating hydrological models using the NSGA-II genetic algorithm approach. It includes the implementation of the NSGAII_VIC_SO class for single-objective optimization and a placeholder for the NSGAII_VIC_MO class for multi-objective optimization (which is not yet implemented). The module integrates with various tools for parameter setup, evaluation metrics, and simulation, as well as visualization capabilities.
Classes:
NSGAII_VIC_SO: Performs single-objective optimization using the NSGA-II genetic algorithm. It inherits from NSGAII_Base and handles the calibration process by optimizing model parameters.
NSGAII_VIC_MO: Placeholder for multi-objective optimization implementation (currently not implemented).
Usage:
Initialize an instance of NSGAII_VIC_SO with the necessary parameters and configuration.
Run the calibration process using the run method to optimize the model parameters.
Retrieve the best results using the get_best_results method to analyze the calibration performance.
Visualize the calibration results using the provided plotting functions.
Example:
basin_index = 397 model_scale = “6km” date_period = [“19980101”, “20071231”]
warmup_date_period = [“19980101”, “19991231”] calibrate_date_period = [“20000101”, “20071231”] verify_date_period = [“20080101”, “20101231”] case_name = f”{basin_index}_{model_scale}”
evb_dir = Evb_dir(cases_home=”/home/xdz/code/VIC_xdz/cases”) evb_dir.builddir(case_name) evb_dir.vic_exe_path = “/home/xdz/code/VIC_xdz/vic_image.exe”
dpc_VIC_level0, dpc_VIC_level1, dpc_VIC_level2 = readdpc(evb_dir)
modify_pourpoint_bool = True if modify_pourpoint_bool:
pourpoint_lon = -91.8225 pourpoint_lat = 38.3625
modifyDomain_for_pourpoint(evb_dir, pourpoint_lon, pourpoint_lat) # mask->1 buildPourPointFile(evb_dir, None, names=[“pourpoint”], lons=[pourpoint_lon], lats=[pourpoint_lat])
algParams = {“popSize”: 20, “maxGen”: 200, “cxProb”: 0.7, “mutateProb”: 0.2} nsgaII_VIC_SO = NSGAII_VIC_SO(evb_dir, dpc_VIC_level0, dpc_VIC_level1, date_period, warmup_date_period, calibrate_date_period, verify_date_period,
algParams=algParams, save_path=evb_dir.calibrate_cp_path, reverse_lat=True, parallel=False)
calibrate_bool = False if calibrate_bool:
nsgaII_VIC_SO.run()
get_best_results_bool = True if get_best_results_bool:
cali_result, verify_result = nsgaII_VIC_SO.get_best_results()
Dependencies:
os: For handling file operations and directory structures.
deap: A library for evolutionary algorithms, used for genetic operations like crossover, mutation, and selection.
pandas: For data manipulation and analysis.
netCDF4: For working with netCDF files to handle model output data.
matplotlib: For visualizing the calibration results.
.tools: Various utility and function modules for parameter setup, evaluation, and grid search.
.bulid_Param, .build_RVIC_Param, .build_GlobalParam: Modules for constructing configuration files and setting up model parameters.
.tools.decoractors: For applying the clock decorator to measure function execution time.
Classes
|
|
|
- class easy_vic_build.calibrate.NSGAII_VIC_MO(evb_dir, dpc_VIC_level0, dpc_VIC_level1, dpc_VIC_level3, date_period, warmup_date_period, calibrate_date_period, verify_date_period, domain_dataset=None, snaped_outlet_lons=None, snaped_outlet_lats=None, snaped_outlet_names=None, buildParam_level0_interface_class=<class 'easy_vic_build.tools.params_func.build_Param_interface.buildParam_level0_interface'>, buildParam_level1_interface_class=<class 'easy_vic_build.tools.params_func.build_Param_interface.buildParam_level1_interface'>, soillayerresampler=<easy_vic_build.tools.params_func.TransferFunction.SoilLayerResampler object>, TF_VIC_class=<class 'easy_vic_build.tools.params_func.TransferFunction.TF_VIC'>, nlayer_list=[1, 2, 3], rvic_OUTPUT_INTERVAL=86400, rvic_BASIN_FLOWDAYS=50, rvic_SUBSET_DAYS=10, rvic_uhbox_dt=3600, algParams={'cxProb': 0.7, 'maxGen': 250, 'mutateProb': 0.2, 'popSize': 40}, save_path='checkpoint.pkl', reverse_lat=True, parallel=False)[source]
Bases:
NSGAII_VIC_SO
- evaluate(ind)[source]
A placeholder function for evaluating an individual’s fitness.
- Parameters:
ind (Individual) – The individual to evaluate.
- Returns:
A tuple containing the fitness values.
- Return type:
tuple
- evaluatePop(population)[source]
Evaluates the fitness of the entire population.
- Parameters:
population (list of Individual) – The population to evaluate.
- operatorMate()[source]
Defines the crossover operation for mating two individuals.
- Parameters:
parent1 (Individual) – The first parent individual.
parent2 (Individual) – The second parent individual.
- Returns:
A tuple containing the offspring resulting from the crossover.
- Return type:
tuple
- operatorMutate()[source]
Defines the mutation operation for an individual.
- Parameters:
ind (Individual) – The individual to mutate.
- Returns:
A tuple containing the mutated individual.
- Return type:
tuple
- class easy_vic_build.calibrate.NSGAII_VIC_SO(evb_dir, dpc_VIC_level0, dpc_VIC_level1, dpc_VIC_level3, date_period, warmup_date_period, calibrate_date_period, verify_date_period, domain_dataset=None, snaped_outlet_lons=None, snaped_outlet_lats=None, snaped_outlet_names=None, buildParam_level0_interface_class=<class 'easy_vic_build.tools.params_func.build_Param_interface.buildParam_level0_interface'>, buildParam_level1_interface_class=<class 'easy_vic_build.tools.params_func.build_Param_interface.buildParam_level1_interface'>, soillayerresampler=<easy_vic_build.tools.params_func.TransferFunction.SoilLayerResampler object>, TF_VIC_class=<class 'easy_vic_build.tools.params_func.TransferFunction.TF_VIC'>, nlayer_list=[1, 2, 3], rvic_OUTPUT_INTERVAL=86400, rvic_BASIN_FLOWDAYS=50, rvic_SUBSET_DAYS=10, rvic_uhbox_dt=3600, algParams={'cxProb': 0.7, 'maxGen': 250, 'mutateProb': 0.2, 'popSize': 40}, save_path='checkpoint.pkl', reverse_lat=True, parallel=False)[source]
Bases:
NSGAII_Base
- apply_genetic_operators(offspring)[source]
Applies the genetic operators (crossover and mutation) to the offspring.
- Parameters:
offspring (list of Individual) – The offspring to apply the genetic operators to.
- evaluate(ind)[source]
A placeholder function for evaluating an individual’s fitness.
- Parameters:
ind (Individual) – The individual to evaluate.
- Returns:
A tuple containing the fitness values.
- Return type:
tuple
- get_obs()[source]
Placeholder function to get observed values (to be designed for specific use cases).
- Return type:
None
- get_sim()[source]
Placeholder function to get simulated values (to be designed for specific use cases).
- Return type:
None
- static operatorMate(parent1, parent2, low, up)[source]
Defines the crossover operation for mating two individuals.
- Parameters:
parent1 (Individual) – The first parent individual.
parent2 (Individual) – The second parent individual.
- Returns:
A tuple containing the offspring resulting from the crossover.
- Return type:
tuple
- static operatorMutate(ind, low, up, NDim)[source]
Defines the mutation operation for an individual.
- Parameters:
ind (Individual) – The individual to mutate.
- Returns:
A tuple containing the mutated individual.
- Return type:
tuple
- static operatorSelect(population, popSize)[source]
Defines the selection operation for choosing individuals from the population.
- Parameters:
population (list of Individual) – The population from which to select individuals.
- Returns:
A list of selected individuals.
- Return type:
list