engforge.eng.costs.Economics
- class Economics(*, name=NOTHING, parent=None, term_length=0, discount_rate=0.0, fixed_output=nan, output_type='generic', terms_per_year=1)[source]
Bases:
ComponentEconomics is a component that summarizes costs and reports the economics of a system and its components in a recursive format. .. attribute:: term_length
The length of the term for economic calculations. Default is 0.
- type:
int
- Parameters:
- discount_rate
The discount rate applied to economic calculations. Default is 0.0.
- Type:
float
- fixed_output
The fixed output value for the economic model. Default is numpy.nan.
- Type:
float
- output_type
The type of output for the economic model. Default is “generic”.
- Type:
str
- terms_per_year
The number of terms per year for economic calculations. Default is 1.
- Type:
int
- _calc_output
Internal variable to store calculated output.
- Type:
float
- _costs
Internal variable to store calculated costs.
- Type:
float
- _cost_references
Internal dictionary to store cost references.
- Type:
dict
- _cost_categories
Internal dictionary to store cost categories.
- Type:
dict
- _comp_categories
Internal dictionary to store component categories.
- Type:
dict
- _comp_costs
Internal dictionary to store component costs.
- Type:
dict
- parent
The parent component or system.
- Type:
parent_types
- update(parent
parent_types): Updates the economic model with the given parent component or system.
- calculate_production(parent, term) float[source]
Calculates the production output for the given parent and term. Must be overridden.
- Return type:
float
- calculate_costs(parent) float[source]
Recursively calculates the costs for the given parent component or system.
- Return type:
float
- term_fgen(comp, prop)[source]
Generates a function to calculate the term value for the given component and property.
- internal_references(recache=True, numeric_only=False)[source]
Gathers and sets internal references for the economic model.
- lifecycle_output() dict
Returns lifecycle calculations for the levelized cost of energy (LCOE).
- lifecycle_dataframe() pandas.DataFrame
Simulates the economics lifecycle and stores the results in a term-based dataframe.
- _create_term_eval_functions()[source]
Creates evaluation functions for term-based calculations grouped by categories and components.
- _gather_cost_references(parent
“System”): Gathers cost references from the parent component or system.
- _extract_cost_references(conf
“CostModel”, bse: str): Extracts cost references from the given cost model configuration.
- cost_references()
Returns the internal dictionary of cost references.
- combine_cost() float
Returns the combined cost of the economic model.
- output() float
Returns the calculated output of the economic model.
Method generated by attrs for class Economics.
Methods
Overwrite this to modify logging fields
recursively accounts for costs in the parent, its children recursively.
must override this function and set economic_output
change_all_log_lvlrecursively checks class slots for the key, and returns the slot type
cls_all_attrs_fieldscls_all_property_keyscls_all_property_labelscompiles this class, override this to compile functionality for this class
collects all the attributes for a system
collects all the references for the system grouped by component
collects the dynamics of the systems 1.
collects all the attributes for a system
checks all methods and creates ref's to execute them later
collects all the references for the system grouped by function and prepended with the system key
checks all methods and creates ref's to execute them later
A cached set of recursive references to any slot component #FIXME: by instance recache on iterative component change or other signals
compiles all subclass functionality
copy the system at the current state recrusively to a certain level, by default copying everything :type levels_deep:
int:param levels_deep: how many levels deep to copy, -1 is all :type level: :param level: the current level, defaults to 0 if not setcost_categories_from_dfcost_matrixGenerate a summary of costs, optionally annualized, and optionally print the summary.
creates a table of costs and categories
creates a graph of the cost model using network X and display it
creates a dynamics object for the system
creates the input matrix for the system, called D
creates the input matrix for the system, called B
creates the input matrix for the system, called O
creates the input matrix for the system, called C
creates the input matrix for the system, called F
creates the state matrix for the system
A routine to communicate to the root of the server network that there is an issue
Writes at a low level to the log file.
looks at all possible combinations of cost categories, scoring them based on coverage of costs, and not allowing any double accounting of costs.
determine the nearest stationary state
a context manager that will allow you to dynamically change any information, then will change it back in a fail safe way.
Writes to log as a error
extract_messageThis acts as the interface for logging.Filter Don't overwrite this, use add_fields instead.
format_columnsGet the references to system input based on the specified criteria.
A generator that will go through all internal configurations up to a certain level if levels_to_descend is less than 0 ie(-1) it will go down, if it 0, None, or False it will only go through this configuration
hash by parm or by input_kw, only input can be hashed by lookup as system properties can create a recursive loop and should be deterministic from input
hash_numeric_withGenerates a hash for the object's dictionary representation, updated with additional keyword arguments.
Writes to log but with info category, these are important typically and inform about progress of process in general
Lists all input attributes for class
no attr base types, no tuples, no lists, no dicts
We only want std logging to start
get all the internal components
go through all attributes determining which are configuration objects additionally this skip any configuration that start with an underscore (private variable)
standard component references are
get all the internal components
get all the internal tabulations
simulate the system over the course of time.
Optimal nonlinear steps
Pass a string of a relative var or property on this system or pass a callable to get a reference to a function.
converts to color and string via the termcolor library :type message:
str:param message: a string convertable entity :type color: :param color: a color in [grey,red,green,yellow,blue,magenta,cyan,white]Writes to log.
simulate the system over the course of time.
Optimal nonlinear steps
no tuples,lists, dicts, strings, or attr base types
returns all subclasses that are a Configuration
ensures correct input for simulation.
parses the simulation input
Lists all plot attributes for class
plot_cost_categoriesKwargs comes from eval_kw in solver
an overrideable classmethod that executes when compiled, however will not execute as a subclass
print_infosimulate the system over the course of time.
simulate the system over the course of time.
simulate the system over the course of time.
returns the reference to the time differential of the state
reset log
resets log on all internal instance LoggingMixins
set_attrsets the time of the system and context
sets attributes from a dictionary
Lists all signals attributes for class
slack_notificationreturns all slot references in this configuration
Lists all slots attributes for class
splits dataframe between constant values and variants
Lists all signals attributes for class
stepreturn all subclasses of components, including their subclasses :type out: :param out: out is to pass when the middle of a recursive operation, do not use it!
reliably compiles this method even for subclasses, override this to compile functionality for subclass interfaces & mixins
Combine other parent-classes table properties into this one, in the case of subclassed system_properties
gather a list of references to attributes and
the table attributes corresponding to
Lists all trace attributes for class
Lists all signals attributes for class
Kwargs comes from eval_kw in solver
Updates dynamics when nonlinear is enabled, otherwise it will do nothing
override
override
override
override
override
override
A customizeable validator at the end of class creation in forge
Writes to log as a warning
Attributes
alias for input values
alias for state values
alias for output values
use the on_setattr method to determine if anything changed, also assume that stat_tab could change without input changes
returns values as they are in the class instance
attrs_fieldsShorthand for the classname
combine_cost([fget, fset, fdel, doc])this property notifies the system this is a property to be tabulated in the dataframe output.
cost_category_storea dictionary of state var rates
this is what is captured and used in each row of the dataframe / table
Returns a pandas DataFrame based on the current context.
dataframe_constantsdataframe_variantsdisplaynamedynamic_Adynamic_Bdynamic_Cdynamic_Ddynamic_Fdynamic_Kdynamic_inputdynamic_input_varsdynamic_outputdynamic_output_varsdynamic_statedynamic_state_varsA nice to have, good to override
A customizeable property that will be in the log by default
returns values as they are in the class instance, but converts classes inputs to their input_as_dict
input_hashget the last context run, or the parent's
levelized_cost([fget, fset, fdel, doc])this property notifies the system this is a property to be tabulated in the dataframe output.
levelized_output([fget, fset, fdel, doc])this property notifies the system this is a property to be tabulated in the dataframe output.
simulates the economics lifecycle and stores the results in a term based dataframe
return lifecycle calculations for lcoe
log_fmtlog_levellog_onlog_silologgernonlinearrecursively gets internal components numeric_as_dict as well as its own numeric values
numeric_hashoutput([fget, fset, fdel, doc])this property notifies the system this is a property to be tabulated in the dataframe output.
Checks columns for ones that only contain numeric types or haven't been explicitly skipped
accesses '_skip_plot_vars' if it exists, otherwise returns empty list
slack_webhook_urlstatic_Astatic_Bstatic_Cstatic_Dstatic_Fstatic_Kreturns an instance unique id based on id(self)
table_hashreturns values as they would be put in a table row from this instance ignoring any sub components
term_years([fget, fset, fdel, doc])this property notifies the system this is a property to be tabulated in the dataframe output.
timetotal_cost([fget, fset, fdel, doc])this property notifies the system this is a property to be tabulated in the dataframe output.
unique_hashupdate_intervalterm_lengthname- property Ut_ref
alias for input values
- property Xt_ref
alias for state values
- property Yt_ref
alias for output values
- add_fields(record)
Overwrite this to modify logging fields
- property anything_changed
use the on_setattr method to determine if anything changed, also assume that stat_tab could change without input changes
- property as_dict
returns values as they are in the class instance
- calculate_costs(parent)[source]
recursively accounts for costs in the parent, its children recursively.
- Return type:
float
- calculate_production(parent, term)[source]
must override this function and set economic_output
- Return type:
float
- classmethod check_ref_slot_type(sys_key)
recursively checks class slots for the key, and returns the slot type
- Return type:
list- Parameters:
sys_key (str)
- property classname
Shorthand for the classname
- classmethod cls_compile()
compiles this class, override this to compile functionality for this class
- classmethod collect_all_attributes()
collects all the attributes for a system
- collect_comp_refs(conf=None, **kw)
collects all the references for the system grouped by component
- Parameters:
conf (Configuration | None)
- collect_dynamic_refs(conf=None, **kw)
collects the dynamics of the systems 1. Time.integrate 2. Dynamic Instances
- Return type:
dict- Parameters:
conf (Configuration | None)
- collect_inst_attributes(**kw)
collects all the attributes for a system
- collect_post_update_refs(eval_kw=None, ignore=None)
checks all methods and creates ref’s to execute them later
- collect_solver_refs(conf=None, check_atr_f=None, check_kw=None, check_dynamics=True, **kw)
collects all the references for the system grouped by function and prepended with the system key
- Parameters:
conf (Configuration | None)
- collect_update_refs(eval_kw=None, ignore=None)
checks all methods and creates ref’s to execute them later
- comp_references(ignore_none_comp=True, **kw)
A cached set of recursive references to any slot component #FIXME: by instance recache on iterative component change or other signals
- classmethod compile_classes()
compiles all subclass functionality
- copy_config_at_state(level=None, levels_deep=-1, changed=None, **kw)
copy the system at the current state recrusively to a certain level, by default copying everything :type levels_deep:
int:param levels_deep: how many levels deep to copy, -1 is all :type level: :param level: the current level, defaults to 0 if not set- Parameters:
levels_deep (int)
changed (dict | None)
- cost_summary(annualized=False, do_print=True, ignore_zero=True)[source]
Generate a summary of costs, optionally annualized, and optionally print the summary. :type annualized: :param annualized: If True, include only annualized costs in the summary. Default is False. :type annualized: bool :type do_print: :param do_print: If True, print the summary to the console. Default is True. :type do_print: bool :type ignore_zero: :param ignore_zero: If True, ignore costs with a value of zero. Default is True. :type ignore_zero: bool :return: A dictionary containing component costs, skipped costs, and summary. :rtype: dict
- create_cost_graph(plot=True)[source]
creates a graph of the cost model using network X and display it
- create_dynamic_matricies(**kw)
creates a dynamics object for the system
- create_feedthrough_matrix(**kwargs)
creates the input matrix for the system, called D
- Return type:
ndarray
- create_input_matrix(**kwargs)
creates the input matrix for the system, called B
- Return type:
ndarray
- create_output_constants(**kwargs)
creates the input matrix for the system, called O
- Return type:
ndarray
- create_output_matrix(**kwargs)
creates the input matrix for the system, called C
- Return type:
ndarray
- create_state_constants(**kwargs)
creates the input matrix for the system, called F
- Return type:
ndarray
- create_state_matrix(**kwargs)
creates the state matrix for the system
- Return type:
ndarray
- critical(*args)
A routine to communicate to the root of the server network that there is an issue
- property dXtdt_ref
a dictionary of state var rates
- property data_dict
this is what is captured and used in each row of the dataframe / table
- property dataframe
Returns a pandas DataFrame based on the current context.
This method checks for the presence of last_context and its dataframe attribute. If they exist, it returns the dataframe from last_context. If not, it checks for the _patch_dataframe attribute and returns it if it exists. If neither condition is met, it returns an empty DataFrame.
- Returns:
A pandas DataFrame based on the current context or an empty DataFrame if no context is available.
- Return type:
pandas.DataFrame
- debug(*args)
Writes at a low level to the log file… usually this should be detailed messages about what exactly is going on
- determine_exclusive_cost_categories(include_categories=None, ignore_categories=None, min_groups=2, max_group_size=None, min_score=0.95, include_item_cost=False)[source]
looks at all possible combinations of cost categories, scoring them based on coverage of costs, and not allowing any double accounting of costs. This is an NP-complete problem and will take a long time for large numbers of items. You can add ignore_categories to ignore certain categories
- Parameters:
ignore_categories (set | None)
min_groups (int)
- determine_nearest_stationary_state(t=0, X=None, U=None)
determine the nearest stationary state
- Return type:
ndarray
- difference(**kwargs)
a context manager that will allow you to dynamically change any information, then will change it back in a fail safe way.
- with self.difference(name=’new_name’, value = new_value) as new_config:
#do stuff with config, ok to fail
you may not access any “private” variable that starts with an _ as in _whatever
difference is useful for saving slight differences in configuration in conjunction with solve you might create wrappers for eval, or implement a strategy pattern.
only attributes may be changed.
#TODO: allow recursive operation with sub comps or systems. #TODO: make a full system copy so the system can be reverted later
- error(error, msg='')
Writes to log as a error
- property filename
A nice to have, good to override
- filter(record)
This acts as the interface for logging.Filter Don’t overwrite this, use add_fields instead.
- get_system_input_refs(strings=False, numeric=True, misc=False, all=False, boolean=False, **kw)
Get the references to system input based on the specified criteria.
- Parameters:
strings – Include system properties of string type.
numeric – Include system properties of numeric type (float, int).
misc – Include system properties of miscellaneous type.
all – Include all system properties regardless of type.
boolean – Include system properties of boolean type.
kw – Additional keyword arguments passed to recursive config loop
- Returns:
A dictionary of system property references.
- Return type:
dict
- go_through_configurations(level=0, levels_to_descend=-1, parent_level=0, only_inst=True, **kw)
A generator that will go through all internal configurations up to a certain level if levels_to_descend is less than 0 ie(-1) it will go down, if it 0, None, or False it will only go through this configuration
- Returns:
level,config
- hash(*args, **input_kw)
hash by parm or by input_kw, only input can be hashed by lookup as system properties can create a recursive loop and should be deterministic from input
- hash_with(**input_kw)
Generates a hash for the object’s dictionary representation, updated with additional keyword arguments. :type **input_kw: :param **input_kw: Arbitrary keyword arguments to update the object’s dictionary representation.
- Returns:
The hash value of the updated dictionary.
- Raises:
Any exceptions raised by deepdiff.DeepHash if hashing fails. –
- property identity
A customizeable property that will be in the log by default
- info(*args)
Writes to log but with info category, these are important typically and inform about progress of process in general
- property input_as_dict
returns values as they are in the class instance, but converts classes inputs to their input_as_dict
- classmethod input_attrs()
Lists all input attributes for class
- classmethod input_fields(add_ign_types=None)
no attr base types, no tuples, no lists, no dicts
- Parameters:
add_ign_types (list | None)
- installSTDLogger()
We only want std logging to start
- internal_components(recache=False)
get all the internal components
- Return type:
dict
- internal_configurations(check_config=True, use_dict=True, none_ok=False)
go through all attributes determining which are configuration objects additionally this skip any configuration that start with an underscore (private variable)
- Return type:
dict
- internal_systems(recache=False)
get all the internal components
- Return type:
dict
- internal_tabulations(recache=False)
get all the internal tabulations
- Return type:
dict
- property last_context
get the last context run, or the parent’s
- property lifecycle_dataframe: DataFrame
simulates the economics lifecycle and stores the results in a term based dataframe
- property lifecycle_output: dict
return lifecycle calculations for lcoe
- linear_output(t, dt, X, U=None)
simulate the system over the course of time. Return time differential of the state.
- Parameters:
dt (float) – interval to integrate over in time
X (np.ndarray) – state input
U (np.ndarray) – control input
- Returns:
time differential of the state
- Return type:
np.array
- linear_step(t, dt, X, U=None, set_Y=False)
Optimal nonlinear steps
- classmethod locate(key, fail=True)
- Return type:
type- Returns:
the class or attribute by key if its in this system class or a subcomponent. If nothing is found raise an error
- locate_ref(key, fail=True, **kw)
Pass a string of a relative var or property on this system or pass a callable to get a reference to a function. If the key has a . in it the comp the lowest level component will be returned, unless a callable is passed in which case this component will be used or the comp passed in the kw will be used. :type key: :param key: the key to locate, or a callable to be used as a reference :param comp: the component to use if a callable is passed :returns: the instance assigned to this system. If the key has a . in it the comp the lowest level component will be returned
- message_with_identiy(message, color=None)
converts to color and string via the termcolor library :type message:
str:param message: a string convertable entity :type color: :param color: a color in [grey,red,green,yellow,blue,magenta,cyan,white]- Parameters:
message (str)
- msg(*args, lvl=5)
Writes to log… this should be for raw data or something… least priorty
- nonlinear_output(t, dt, X, U=None, update=True)
simulate the system over the course of time. Return time differential of the state.
- Parameters:
dt (float) – interval to integrate over in time
X (np.ndarray) – state input
U (np.ndarray) – control input
- Returns:
time differential of the state
- Return type:
np.array
- nonlinear_step(t, dt, X, U=None, set_Y=False)
Optimal nonlinear steps
- property numeric_as_dict
recursively gets internal components numeric_as_dict as well as its own numeric values
- classmethod numeric_fields()
no tuples,lists, dicts, strings, or attr base types
- classmethod parent_configurations_cls()
returns all subclasses that are a Configuration
- Return type:
list
- parse_run_kwargs(**kwargs)
ensures correct input for simulation. :returns: first set of input for initalization, and all input dictionaries as tuple.
- parse_simulation_input(**kwargs)
parses the simulation input
- Parameters:
dt – timestep in s, required for transients
endtime – when to end the simulation
- classmethod plot_attributes()
Lists all plot attributes for class
- Return type:
Dict[str,Attribute]
- property plotable_variables
Checks columns for ones that only contain numeric types or haven’t been explicitly skipped
- post_update(parent, *args, **kwargs)
Kwargs comes from eval_kw in solver
- classmethod pre_compile()
an overrideable classmethod that executes when compiled, however will not execute as a subclass
- rate(t, dt, X, U, *args, **kwargs)
simulate the system over the course of time.
- Parameters:
dt (float) – interval to integrate over in time
X (np.ndarray) – state input
U (np.ndarray) – control input
subsystems (bool, optional) – simulate subsystems. Defaults to True.
- Returns:
tabulated data
- Return type:
dataframe
- rate_linear(t, dt, X, U=None)
simulate the system over the course of time. Return time differential of the state.
- rate_nonlinear(t, dt, X, U=None, update=True)
simulate the system over the course of time. Return time differential of the state.
- Parameters:
t (float) – time
dt (float) – interval to integrate over in time
X (np.ndarray) – state input
U (np.ndarray) – control input
- Returns:
time differential of the state
- Return type:
np.array
- ref_dXdt(name)
returns the reference to the time differential of the state
- Parameters:
name (str)
- resetLog()
reset log
- resetSystemLogs(reseted=None)
resets log on all internal instance LoggingMixins
- set_time(t, system=True, subcomponents=True)
sets the time of the system and context
- setattrs(dict)
sets attributes from a dictionary
- classmethod signals_attributes()
Lists all signals attributes for class
- Return type:
Dict[str,Attribute]
- property skip_plot_vars: list
accesses ‘_skip_plot_vars’ if it exists, otherwise returns empty list
- classmethod slot_refs(recache=False)
returns all slot references in this configuration
- classmethod slots_attributes(attr_type=False)
Lists all slots attributes for class
- Return type:
Dict[str,Attribute]
- smart_split_dataframe(df=None, split_groups=0, key_f=<function <lambda>>)
splits dataframe between constant values and variants
- classmethod solvers_attributes()
Lists all signals attributes for class
- Return type:
Dict[str,Attribute]
- classmethod subclasses(out=None)
return all subclasses of components, including their subclasses :type out: :param out: out is to pass when the middle of a recursive operation, do not use it!
- classmethod subcls_compile()
reliably compiles this method even for subclasses, override this to compile functionality for subclass interfaces & mixins
- property system_id: str
returns an instance unique id based on id(self)
- classmethod system_properties_classdef(recache=False)
Combine other parent-classes table properties into this one, in the case of subclassed system_properties
- system_references(recache=False, numeric_only=False, **kw)
gather a list of references to attributes and
- classmethod table_fields()
the table attributes corresponding to
- property table_row_dict
returns values as they would be put in a table row from this instance ignoring any sub components
- classmethod trace_attributes()
Lists all trace attributes for class
- Return type:
Dict[str,Attribute]
- classmethod transients_attributes()
Lists all signals attributes for class
- Return type:
Dict[str,Attribute]
- update_dynamics(t, X, U)
Updates dynamics when nonlinear is enabled, otherwise it will do nothing
- update_feedthrough(t, D, X, U)
override
- Return type:
ndarray
- update_input(t, B, X, U)
override
- Return type:
ndarray
- update_output_constants(t, O, X)
override
- Return type:
ndarray
- update_output_matrix(t, C, X)
override
- Return type:
ndarray
- update_state(t, A, X)
override
- Return type:
ndarray
- update_state_constants(t, F, X)
override
- Return type:
ndarray
- classmethod validate_class()
A customizeable validator at the end of class creation in forge
- warning(*args)
Writes to log as a warning