smooth.framework.functions package¶
Submodules¶
smooth.framework.functions.calculate_external_costs module¶
-
smooth.framework.functions.calculate_external_costs.
costs_for_ext_components
(model)¶ Calculates costs for components in the system which are not to be included in the optimization but their costs must still be taken into consideration. The name of an external component must be unique within the model.
Parameters: model (dictionary) – smooth model Returns: external components Return type: list of Component
Raises: ValueError – an external component name is not unique within the model
smooth.framework.functions.debug module¶
-
smooth.framework.functions.debug.
get_df_debug
(df_results, results_dict, new_df_results)¶ Generate debug info from results.
Parameters: - df_results (pandas dataframe) – results dataframe to compare against (e.g. last iteration)
- results_dict – results dictionary from oemof.processing.parameter_as_dict
- new_df_results (pandas dataframe) – newest results dataframe
Returns: debug dataframe
Return type: pandas dataframe
Raises: TypeError – if df_results or results_dict is not set
smooth.framework.functions.functions module¶
-
smooth.framework.functions.functions.
choose_valid_dict
(component, var_dict)¶ Function to select a valid dict (capex / fix_emissions) depending on the value of an attribute of the specific component.
# todo: check opex and op_emissions
Parameters: - component (class:~smooth.components.component.Component) – object of this component
- var_dict (dict) – dict object (capex/fix_emissions) of this component
Returns: Valid dictionary (capex/fix_emissions) for the actual value of the depending parameter of the component
-
smooth.framework.functions.functions.
create_component_obj
(model, sim_params)¶ Create components from model.
Parameters: - model (dictionary) – smooth model
- sim_params (
SimulationParameters
) – simulation parameters
Returns: list of components in model
Return type: list of
Component
-
smooth.framework.functions.functions.
cut_suffix
(name, suffix)¶ Cuts off the suffix from name string, if it ends with it
Parameters: - name (string) – original name from which suffix will be cut off
- suffix – string to be removed
Returns: string without suffix
-
smooth.framework.functions.functions.
cut_suffix_loop
(name_tuple, suffix_list)¶ Cuts off all suffixes present in suffix_list from names in name_tuple
Parameters: - name_tuple – tuple of strings from which suffixes will be cut off
- suffix_list – list of strings to be removed
Returns: updated name_tuple
Return type: tuple of strings
-
smooth.framework.functions.functions.
extract_flow_per_bus
(smooth_result, name_label_dict)¶ Extract dict containing the busses that will be plotted.
Parameters: - smooth_result (list of
Component
) – result from run_smooth - name_label_dict – dictionary with key being a component name in the model and value the name to display
Returns: dictionary of all busses from the model with their flow values over time
- smooth_result (list of
-
smooth.framework.functions.functions.
get_date_time_index
(start_date, n_intervals, step_size)¶ Function defining the parameters for perfect/myopic foresight.
Parameters: - start_date (string) – the first evaluated time period, e.g. ‘1/1/2019’
- n_intervals (integer) – number of time periods
- step_size (number) – length of one time step in minutes
Returns: n_intervals dates, each step_size minutes apart
Return type: pandas DateTimeIndex
-
smooth.framework.functions.functions.
get_sim_time_span
(n_interval, step_size)¶ Calculate the time span of the simulation.
Parameters: n_interval (integer) – number of intervals Step_size: length of one time step in minutes Returns: time delta in minutes Return type: number
-
smooth.framework.functions.functions.
interval_time_index
(date_time_index, i_interval)¶ Function to divide the set date time index into hourly intervals.
This function seems to be unused.
Parameters: - date_time_index (DateTimeIndex) – chosen date range for the model
- i_interval (integer) – current interval index
Returns: pandas DateTimeIndex for current interval
-
smooth.framework.functions.functions.
read_data_file
(path, filename, csv_separator, column_title)¶ Function to read the input data files.
Parameters: - path (string) – path where the csv file is located
- filename (string) – name of csv file
- csv_separator (character) – separator of csv data
- column_title (string) – title of data column
Returns: column of data from csv file
Return type: pandas dataframe
-
smooth.framework.functions.functions.
replace_at_idx
(tup, i, val)¶ Replaces a value at index i of a tuple tup with value val
Parameters: - tup – tuple to be updated
- i (integer) – index at which the value should be replaced
- val (value) – new value at index i
Returns: new tuple with replaced value
smooth.framework.functions.load_results module¶
-
smooth.framework.functions.load_results.
load_results
(file_path)¶ Load the result of either a smooth run or an optimization run by the genetic algorithm.
Parameters: file_path (string) – path of the result pickle file
smooth.framework.functions.plot_results module¶
-
smooth.framework.functions.plot_results.
plot_smooth_results
(smooth_result, comp_label_dict={'CHP_Methane': 'Biogas-BHKW', 'ch4_grid': 'Biogas-Zufuhr', 'el_demand': 'Strombedarf', 'from_grid': 'Strombezug', 'fuel_cell_chp': 'Brennstoffzelle', 'h2_compressor': 'Wasserstoffkompressor (Hochdruck)', 'h2_compressor_from_ely': 'Wasserstoffkompressor (Niederdruck)', 'h2_demand': 'Wasserstoffbedarf', 'h2_storage': 'Wasserstoffspeicher', 'li_battery': 'Lithium-Batterie', 'pv_output': 'PV-Anlage', 'th_demand': 'Heizbedarf', 'this_ely': 'Elektrolyseur', 'this_pem_ely': 'PEM-Elektrolyseur', 'to_grid': 'Stromeinspeisung', 'wind_output': 'WE-Anlage'}, bus_dict={'bch4': 'Biomethan-Fluss', 'bel': 'Elektrische Leistung', 'bel_pv': 'PV Leistung', 'bel_wind': 'Wind Leistung', 'bh2_hp': 'Wasserstoff-Fluss bei Hochdruck', 'bh2_lp': 'Wasserstoff-Fluss bei Niederdruck', 'bh2_mp': 'Wasserstoff-Fluss bei Mitteldruck', 'bth': 'Thermische Leistung'}, y_dict={'bch4': 'Biomethan in kg/h', 'bel': 'Leistung in W', 'bel_pv': 'Leistung in W', 'bel_wind': 'Leistung in W', 'bh2_hp': 'Wasserstoff in kg/h', 'bh2_lp': 'Wasserstoff in kg/h', 'bh2_mp': 'Wasserstoff in kg/h', 'bth': 'Leistung in W'})¶ Create figures of smooth run.
All plots are drawn in a new window.
Parameters: - smooth_result (list of
Component
) – result from run_smooth containing all components - comp_label_dict (dictionary, optional) – component labels, key being the component name in the model and value the name to display. Defaults to comp_dict_german from example_plotting_dicts.
- bus_dict (dictionary, optional) – bus labels, key being the bus name in the model and value the name to display. Defaults to bus_dict_german from example_plotting_dicts.
- y_dict (dictionary, optional) – labels for y-axes, key being the bus names from the model to plot and value the y-axis labels. Defaults to y_dict_german from example_plotting_dicts.
- smooth_result (list of
smooth.framework.functions.print_results module¶
smooth.framework.functions.save_results module¶
-
smooth.framework.functions.save_results.
save_results
(file_name, result_data)¶ Save the result of either a smooth run or an optimization run by the genetic algorithm.
Parameters: - file_name (string) – name of the result pickle file
- result_data – data to save
smooth.framework.functions.update_annuities module¶
-
smooth.framework.functions.update_annuities.
calc_annual_emissions
(component, target)¶ Calculate annual emissions.
Parameters: - component (
Component
) – object of this component - target (dict) – dictionary with cost key, e.g. component.fix_emissions
Returns: annual emissions of target [kg/a]
Return type: number
- component (
-
smooth.framework.functions.update_annuities.
calc_annuity
(component, target)¶ Calculate annuity
Parameters: - component (
Component
) – object of this component - target (dict) – dictionary with cost key, e.g. component.capex
Returns: annuity of target [EUR/a]
Return type: number
- component (
smooth.framework.functions.update_fitted_cost module¶
-
smooth.framework.functions.update_fitted_cost.
get_dependant_value
(component, fitting_dict, index, fixedCost)¶ Get an attribute of the component as the dependant value.
Parameters: - component (
Component
) – object of this component - fitting_dict (dict) – usually financial or emission object of this component
- index (integer) – current position in fitting_dict
- fixedCost (string) – key of fixed type in fitting_dict
Returns: calculated costs using exponential fitting
Return type: number or None
- component (
-
smooth.framework.functions.update_fitted_cost.
get_exp
(component, fitting_dict, index, dependant_value)¶ Case: An exponential fitting of the cost function is wanted.
Here 3 variables are used in the following order:
# for 2 fitting parameters fv_1*exp(fv_2) # for 3 fitting parameters fv_1 + fv_2*exp(fv_3*Parameter)
Parameters: - component (
Component
) – object of this component - fitting_dict (dict) – usually financial or emission object of this component
- index (integer) – current position in fitting_dict
- dependant_value (number) – dependent attribute value of object
Returns: calculated costs using exponential fitting
Return type: number
- component (
-
smooth.framework.functions.update_fitted_cost.
get_free
(component, fitting_dict, index, dependant_value)¶ Case: A “free” fitting of the cost function is wanted.
In this case, an arbitrary number of fitting parameters can be given. They will be used in the following order: fv_1, fv_2, fv_3, … fv_n.
Function:
fv_1*dependant_value^fv_2 + fv_3*dependant_value^fv_4 + ... fv_(n-1)*dependant_value^fv_n
Parameters: - component (
Component
) – object of this component - fitting_dict (dict) – usually financial or emission object of this component
- index (integer) – current position in fitting_dict
- dependant_value (number) – dependent attribute value of object
Returns: calculated costs using “free” fitting
Return type: number
Raises: ValueError – if number of fitting values is odd
- component (
-
smooth.framework.functions.update_fitted_cost.
get_poly
(component, fitting_dict, index, dependant_value)¶ Case: A polynomial fitting of the cost function is wanted.
In this case, an arbitrary number of fitting parameters can be given. They will be used in the following order: fv_1, fv_2, fv_3, … fv_n.
Function:
fv_1 + fv_2*dependant_value + fv_3*dependant_value^2 + ... fv_n*dependant_value^(n-1)
It is possible to use the polynomial function to add different cost equations together. This is achieved because the result of the initial equation used (which can be any of the cost functions) is stored as the ‘cost’ variable, which can then be used in a following polynomial function but now as a new free variable. See the example_model_costs example for an applied case.
Parameters: - component (
Component
) – object of this component - fitting_dict (dict) – usually financial or emission object of this component
- index (integer) – current position in fitting_dict
- dependant_value (number) – dependent attribute value of object
Returns: calculated costs using polynomial fitting
Return type: number
- component (
-
smooth.framework.functions.update_fitted_cost.
get_spec
(component, fitting_dict, index, dependant_value)¶ Case: The fitting value is multiplied with the dependant value to get the costs.
Parameters: - component (
Component
) – object of this component - fitting_dict (dict) – usually financial or emission object of this component
- index (integer) – current position in fitting_dict
- dependant_value (number) – dependent attribute value of object
Returns: calculated costs using a fitting value
Return type: number
- component (
-
smooth.framework.functions.update_fitted_cost.
update_cost
(component, fitting_dict, index, dependant_value, name)¶ Update cost of component.
Parameters: - component (
Component
) – object of this component - fitting_dict (dict) – usually financial or emission object of this component
- index (integer) – current position in fitting_dict
- dependant_value (number) – dependent attribute value of object
- name (string) – human readable representation of attribute to be updated, e.g. “CAPEX/OPEX” or “emissions”
Raises: ValueError – on unknown fitting key
- component (
-
smooth.framework.functions.update_fitted_cost.
update_emissions
(component, emissions)¶ Calculate fixed and operational emissions for this component.
This function is calculating a fix and operational value for components where “fix_emissions” or “op_emissions” are dependant on certain values. The following list shows possible fitting methods. The fitting method is chosen by the “key” value given in the “emissions” dictionary:
- “fix” –> already the fix value, nothing has to be done
- “spec” –> cost value needs to be multiplied with the dependant value
- “exp” –> exponential cost fitting
- “poly” –> polynomial cost fitting
- “free” –> polynomial cost fitting with free choosable exponents
- “variable” –> definition of multiple “fix_emissions” or “op_emissions” structures: If the emission structure changes over the size of a specific value of the component, for example because of the effects of economics of scale, the special key “variable” can be used to define multiple “fix_emissions” or “op_emissions” dicts for different ranges of this value
If multiple keys are defined, the calculations are done sequentially in order.
Parameters: - component (component:
Component
) – object of this component - emissions (fix_emissions or op_emissions dict) – emission object of this component
-
smooth.framework.functions.update_fitted_cost.
update_financials
(component, financials)¶ Calculate “OPEX” or “CAPEX” for this component.
This function is calculating a fix “CAPEX” and “OPEX” value for components where “CAPEX” and “OPEX” are dependant on certain values. The following list shows possible fitting methods. The fitting method is chosen by the “CAPEX” and “OPEX” key:
- “fix” –> already the fix value, nothing has to be done
- “spec” –> cost value needs to be multiplied with the dependant value
- “exp” –> exponential cost fitting
- “poly” –> polynomial cost fitting
- “free” –> polynomial cost fitting with free choosable exponents
- “variable” –> definition of multiple “CAPEX” or “OPEX” structures: If the cost structure changes over the size of a specific value of the component, for example because of the effects of economics of scale, the special key “variable” can be used to define multiple “CAPEX” or “OPEX” dicts for different ranges of this value
If multiple keys are defined, the calculations are done sequentially in order.
Parameters: - component (
Component
) – object of this component - financials (capex or opex dict) – financial object of this component