easy_vic_build.build_Param
build_Param - A Python module for building VIC parameter file.
This module provides functions for constructing the Parameter file of the VIC model. It includes capabilities to: - Build the basic params_dataset_level0 - Build the params_dataset_level0 by g parameters and TF - Build the params_dataset_level1 - Searching grids for scaling grids from level 0 to level 1 - Scaling params_dataset_level0 to params_dataset_level1
Functions:
buildParam_level0: Build the parameter dataset for level 0, consisting of two components: buildParam_level0_basic and buildParam_level0_by_g.
buildParam_level0_basic: Build the basic parameter dataset for level 0.
buildParam_level0_by_g: Use global parameter lists and TF to generate the parameter dataset.
buildParam_level1: Build Level 1 parameters based on TF and dpc information.
scaling_level0_to_level1_search_grids: Searching grids for scaling grids from level 0 to level 1 (Matching).
scaling_level0_to_level1: Scaling the grid parameters from level 0 to level 1 based on matching grids.
Usage:
Call buildParam_level0 and provide g_list as well as dpc instances to generate basic params_dataset_level0.
Call buildParam_level1 to generate params_dataset_level1.
Call scaling_level0_to_level1_search_grids to search grids for match grids at level 0 and level 1.
4. Call scaling_level0_to_level1 to scale params_dataset_level0 to params_dataset_level1. Note: The Transfer function and scaling operator is set in params_func.TransferFunction and params_func.Scaling_operator module.
Example:
basin_index = 213 model_scale = “6km” date_period = [“19980101”, “19981231”] case_name = f”{basin_index}_{model_scale}”
evb_dir = Evb_dir(cases_home=”./examples”) # cases_home=”/home/xdz/code/VIC_xdz/cases” evb_dir.builddir(case_name)
dpc_VIC_level0, dpc_VIC_level1, dpc_level2 = readdpc(evb_dir)
domain_dataset = readDomain(evb_dir)
params_dataset_level0, stand_grids_lat, stand_grids_lon, rows_index, cols_index = buildParam_level0(evb_dir, default_g_list, dpc_VIC_level0, reverse_lat=True) params_dataset_level1, stand_grids_lat, stand_grids_lon, rows_index, cols_index = buildParam_level1(evb_dir, dpc_VIC_level1, reverse_lat=True, domain_dataset=domain_dataset) params_dataset_level1, searched_grids_bool_index = scaling_level0_to_level1(params_dataset_level0, params_dataset_level1)
domain_dataset.close() params_dataset_level0.close() params_dataset_level1.close()
Dependencies:
numpy: For numerical computations and array manipulations.
bulid_Domain.cal_mask_frac_area_length: For calculating mask fraction, area, and length within a domain.
tools.decoractors: For measuring function execution time.
tools.dpc_func: For data processing and computation functions.
tools.geo_func: For geometric calculations and spatial operations.
tools.params_func: Custom utility functions for parameter handling.
tools.utilities: Custom utility functions.
tools.decoractors: For measuring function execution time (duplicate entry, consider consolidating).
Functions
|
Build the parameter dataset for level 0, consisting of two components: buildParam_level0_basic and buildParam_level0_by_g. |
|
Build Level 1 parameters. |
|
Scaling the parameters from level 0 to level 1 based on matching grids. |
Searching grids for scaling grids from level 0 to level 1 (Matching grids at different levels). |
- easy_vic_build.build_Param.buildParam_level0(evb_dir, g_params, soillayerresampler, dpc_VIC_level0, TF_VIC_class=<class 'easy_vic_build.tools.params_func.TransferFunction.TF_VIC'>, buildParam_level0_interface_class=<class 'easy_vic_build.tools.params_func.build_Param_interface.buildParam_level0_interface'>, reverse_lat=True, stand_grids_lat_level0=None, stand_grids_lon_level0=None, rows_index_level0=None, cols_index_level0=None)[source]
Build the parameter dataset for level 0, consisting of two components: buildParam_level0_basic and buildParam_level0_by_g.
Parameters:
- evb_dirEvb_dir
An instance of the Evb_dir class, containing paths for VIC deployment.
- g_listlist
A list of global parameters (g-parameters).
- dpc_VIC_level0dpc_VIC_level0
An instance of the dpc_VIC_level0 class to process data at level 0 of the VIC model.
- reverse_latbool
Boolean flag to indicate whether to reverse latitudes (Northern Hemisphere: large -> small, set as True).
- stand_grids_latlist, optional
A list of standard latitudes. If not provided, will be calculated based on the grid shape.
- stand_grids_lonlist, optional
A list of standard longitudes. If not provided, will be calculated based on the grid shape.
- rows_indexlist, optional
A list of row indices for the grid. If not provided, will be calculated based on the grid shape.
- cols_indexlist, optional
A list of column indices for the grid. If not provided, will be calculated based on the grid shape.
Returns:
- params_dataset_level0netCDF.Dataset
The parameter dataset for level 0.
- stand_grids_latlist
A list of standard latitudes.
- stand_grids_lonlist
A list of standard longitudes.
- rows_indexlist
A list of row indices for the grid.
- cols_indexlist
A list of column indices for the grid.
Notes:
The function generates the parameter dataset for level 0, integrating two sub-components: buildParam_level0_basic for basic parameter generation and buildParam_level0_by_g for parameter adjustments based on global parameters.
- easy_vic_build.build_Param.buildParam_level1(evb_dir, dpc_VIC_level1, TF_VIC_class=<class 'easy_vic_build.tools.params_func.TransferFunction.TF_VIC'>, buildParam_level1_interface_class=<class 'easy_vic_build.tools.params_func.build_Param_interface.buildParam_level1_interface'>, reverse_lat=True, domain_dataset=None, stand_grids_lat_level1=None, stand_grids_lon_level1=None, rows_index_level1=None, cols_index_level1=None)[source]
Build Level 1 parameters.
- Parameters:
evb_dir (Evb_dir) – An instance of the Evb_dir class, containing paths for VIC deployment.
dpc_VIC_level1 (dpc_VIC_level1) – An instance of the dpc_VIC_level1 class to process data at level 0 of the VIC model.
reverse_lat (bool) – Boolean flag to indicate whether to reverse latitudes (Northern Hemisphere: large -> small, set as True).
domain_dataset (netCDF.Dataset, optional) – Domain dataset containing terrain and mask information. If not provided, mask will be computed based on dpc_VIC_level1.
stand_grids_lat (list of float, optional) – A list of standard grid latitudes. If not provided, will be calculated based on the grid shape.
stand_grids_lon (list of float, optional) – A list of standard grid longitudes. If not provided, will be calculated based on the grid shape.
rows_index (list of int, optional) – A list of row indices specifying grid positions. If not provided, will be calculated based on the grid shape.
cols_index (list of int, optional) – A list of column indices specifying grid positions. If not provided, will be calculated based on the grid shape.
- Returns:
params_dataset_level1 (netCDF.Dataset) – The parameter dataset for level 1.
stand_grids_lat (list of float) – The list of standard grid latitudes used in the dataset.
stand_grids_lon (list of float) – The list of standard grid longitudes used in the dataset.
rows_index (list of int) – The list of row indices used in the grid.
cols_index (list of int) – The list of column indices used in the grid.
- easy_vic_build.build_Param.scaling_level0_to_level1(params_dataset_level0, params_dataset_level1, searched_grids_bool_index=None, nlayer_list=[1, 2, 3])[source]
Scaling the parameters from level 0 to level 1 based on matching grids.
This function takes the parameters from the level 0 and level 1 datasets, and scales the grid parameters from the level 0 resolution to the level 1 resolution. It searches for the matching grids between the two levels and then returns the level 1 dataset with the corresponding data mapped from level 0, along with a boolean index indicating which grids in level 0 correspond to the grids in level 1. The scaling operators are applied.
- Parameters:
params_dataset_level0 (netCDF.Dataset) – The parameter dataset for level 0.
params_dataset_level1 (netCDF.Dataset) – The parameter dataset for level 1.
searched_grids_bool_index (array-like, optional, default=None) – Boolean indices indicating which grids from level 0 match the grids from level 1. If not provided, it is calculated within the function.
- Returns:
params_dataset_level1 (netCDF.Dataset) – The parameter dataset for level 1, with values from level 0 mapped onto the grids of level 1.
searched_grids_bool_index (array) – Boolean indices indicating which grids from level 0 correspond to grids from level 1.
Notes
This function performs a search for the closest grids between level 0 and level 1.
The mapping process takes into account the resolution of both grids and the spatial alignment.
- easy_vic_build.build_Param.scaling_level0_to_level1_search_grids(params_dataset_level0, params_dataset_level1)[source]
Searching grids for scaling grids from level 0 to level 1 (Matching grids at different levels).
This function reads longitude and latitude values from the parameter datasets of level 0 and level 1, calculates the grid resolutions, creates 2D mesh grids for level 1, and searches for the closest matching grid indices between level 0 and level 1 with search_grids.search_grids_radius_rectangle. The function then converts the results into boolean indices for the corresponding grids.
- Parameters:
params_dataset_level0 (object) – The parameter dataset for level 0, containing the longitude and latitude values of the original grid.
params_dataset_level1 (object) – The parameter dataset for level 1, containing the longitude and latitude values of the target grid.
- Returns:
searched_grids_index (array) – The indices of the grids from level 0 that correspond to the grids of level 1.
searched_grids_bool_index (array) – Boolean indices indicating which grids from level 0 match the grids from level 1.