cost_eco_model_linker.sampling¶
Attributes¶
Functions¶
|
Set input cells, trigger recalculation, and read back capex and opex. |
|
Calculates set up and operational costs in the deployment cost model (wb), given a set of parameters to sample. |
|
Calculates set up and operational costs in the production cost model (wb), given a set of parameters to sample. |
Load configuration file for model sampling |
|
Load internal config for model sampling |
|
|
Create a problem specification for sampling cost models using SALib. |
|
SALib samples floats, so convert categorical variables to integers by taking the ceiling. |
|
Map sampled integer indices back to their actual discrete values. |
|
Run the production cost model. |
|
Run the deployment cost model. |
|
Generate Sobol' samples for the deployment model and run |
|
Generate Sobol' samples for the production model and run |
|
Module Contents¶
- cost_eco_model_linker.sampling.THIS_DIR¶
- cost_eco_model_linker.sampling.DEFAULT_PROD_VER = '3.9.1'¶
- cost_eco_model_linker.sampling.DEFAULT_DEPLOY_VER = '3.9.0'¶
- cost_eco_model_linker.sampling.evaluate_spreadsheet(wb, model_spec, params) tuple[float, float]¶
Set input cells, trigger recalculation, and read back capex and opex.
This is the inner function for both cost models. All model-specific parameter transformations (yield adjustment, reef name resolution, vessel type switching) must be applied to params before calling this function.
- Parameters:
wb (Workbook) – Open Excel workbook.
model_spec (DataFrame) – Factor specification with columns: factor_names, sheet, cell_pos.
params (Series) – Fully-resolved parameter values indexed by factor_names.
- Returns:
capex (float)
opex (float)
- cost_eco_model_linker.sampling.calculate_deployment_cost(wb, model_spec, factors)¶
Calculates set up and operational costs in the deployment cost model (wb), given a set of parameters to sample.
- Parameters:
wb (Workbook) – The cost model as an excel workbook
model_spec (DataFrame) – The cost model specification, detailing where cells are in the spreadsheet
factors (DataFrameRow) – Factor values to run cost model with
- Returns:
capex (float) – Setup cost (CAPEX)
opex (float) – Operational cost (OPEX)
- cost_eco_model_linker.sampling.calculate_production_cost(wb, factor_spec, factors)¶
Calculates set up and operational costs in the production cost model (wb), given a set of parameters to sample.
- Parameters:
wb (Workbook) – The cost model as an excel workbook
factor_spec (DataFrame) – Factor specification, as loaded from the config.csv
factors (DataFrameRow) – Factor values to run model with
- Returns:
capex (float) – Setup cost (CAPEX)
opex (float) – Operational cost (OPEX)
- cost_eco_model_linker.sampling.load_config()¶
Load configuration file for model sampling
- Parameters:
config_filepath (str) – String specifying filepath of config file, default is the default package config file
- cost_eco_model_linker.sampling.load_internal_config(fp)¶
Load internal config for model sampling
- Parameters:
fp (str) – Filename of config file within the package structure
- cost_eco_model_linker.sampling.problem_spec(cost_type)¶
Create a problem specification for sampling cost models using SALib.
- Parameters:
cost_type (str) – String specifying cost model type, “production_params” or “deployment_params”
config_filepath (str) – String specifying filepath of config file, default is the default package config file
- Returns:
sp (dict) – ProblemSpec for sampling with SALib
model_spec (dataframe) – factor specification, as loaded from the config.csv
- cost_eco_model_linker.sampling.convert_factor_types(factors_df, is_cat)¶
SALib samples floats, so convert categorical variables to integers by taking the ceiling.
- Parameters:
factors_df (dataframe) – A dataframe of sampled factors
is_cat (list{bool}) – Boolian vector specifian whether each factor is categorical
- Returns:
factors_df
- Return type:
Updated sampled factor dataframe with categorical factors as integers
- cost_eco_model_linker.sampling.apply_discrete_mapping(factors_df, model_spec)¶
Map sampled integer indices back to their actual discrete values. Only applies to factors with a discrete_values entry in model_spec. Factors marked as is_cat without discrete_values are already handled by the flooring trick in convert_factor_types.
- Parameters:
factors_df (dataframe) – A dataframe of sampled factors
model_spec (dataframe) – Factor specification, as loaded from the config CSV
- Returns:
factors_df
- Return type:
Updated sampled factor dataframe with discrete mappings applied
- Raises:
ValueError – If the min/max of discrete_values does not match range_lower/range_upper
- cost_eco_model_linker.sampling.collect_production_costs(wb, cost_factors, factor_spec)¶
Run the production cost model.
- Parameters:
wb_file_path (Workbook file path) – A cost model as an excel workbook
cost_factors (dataframe) – Dataframe of factors to input in the cost model
factor_spec (dataframe) – Factor specification, as loaded from the config.csv
- Returns:
cost_factors – Updated sampled factor dataframe with costs added
- Return type:
dataframe
- cost_eco_model_linker.sampling.collect_deployment_costs(wb, cost_factors, factor_spec)¶
Run the deployment cost model.
- Parameters:
wb_file_path (str) – Filepath to a cost model as an excel workbook
cost_factors (dataframe) – Dataframe of factors to input in the cost model
factor_spec (dataframe) – Factor specification, as loaded from the config.csv
- Returns:
cost_factors – Updated sampled factor dataframe with costs added
- Return type:
dataframe
- cost_eco_model_linker.sampling.run_deployment_model(cost_model: str, N: int)¶
Generate Sobol’ samples for the deployment model and run
- Parameters:
cost_model (str) – Path to cost (spreadsheet) model
N (int) – Number of desired Sobol’ sample points (resolves to N * (2D + 2) samples) where D is the number of model factors
- Return type:
SALib ProblemSpec with cost_model_results added as a field.
- cost_eco_model_linker.sampling.run_production_model(cost_model: str, N: int, nprocs=1)¶
Generate Sobol’ samples for the production model and run
- Parameters:
cost_model (str) – Path to cost (spreadsheet) model, including extension (.xlsx)
N (int) – Number of desired Sobol’ sample points (resolves to N * (2D + 2) samples) where D is the number of model factors
- Return type:
SALib ProblemSpec with cost_model_results added as a field.
- cost_eco_model_linker.sampling.extract_sa_results(sp: SALib.ProblemSpec, fig_path: str = './figs/')¶