-
Notifications
You must be signed in to change notification settings - Fork 1
financial_modules
There is no reason you can't access financial modules as long as they are given the correct input data and their module names are called to run by the SAM sdk after your simulation has run.
There is an extension of the standard map of values used as inputs to a single module that is an ordered map whose keys are the names of the modules to run in the order they should be run (the financial modules need the simulation results in the relevant data structures) and whose values are the usual map of input values. This is called as sam.run_from_config()
In its implementation you can see how you can string together calls to run modules with different names and configs by passing the results from previous runs in as the ssc_data for new calls. So you can
def run_from_config(self, run_config, ssc_data=None, output_selector=None):
if ssc_data is None:
ssc_data = self.ssc.data_create()
for module in run_config.keys():
print('Running module {}'.format(module))
ssc_data = self.run_module(module_name=module, model_params=run_config[module], ssc_data=ssc_data)
out = ssc_data
if output_selector is not None:
out = output_selector(ssc_data) # self.ssc.data_get_array( sscData, outVar )
return out
There is also experimental support for interpreting the variable assignments and module execution order of lk scripts automatically generated out of the GUI export functionality that takes advantage of this style of config.
The lines from the lk example, should load and parse an lk script into a config that provides a good example for you to follow:
https://github.com/sborgeson/SAMwrapper/blob/master/lk_example.py
It runs ['belpe', 'pvsamv1', 'utilityrate5', 'cashloan']
in order.
If you'd like to avoid compiling your inputs by hand, you can take a working setup from the GUI and export it as lk.
From the docs of the LKInterpreter:
You can press Shift F5 within the SAM GUI to generate an LK script file that sets the values of the input variables for each SSC module your SAM cases uses to the SAM input values. This class can interpret those files. Note: this class only looks for var setting commands and module invocations and doesn't do anything else that LK does.
The trick is that the lk script will actually be part of a directory of files that include data that needs to be loaded. If I remember correctly, lines like:
var( 'load', real_array(read_text_file('test/lk/load.csv')));
will have absolute paths to the directory they are in, and you will need to edit them by hand if you want them to be relative/portable. The python code is just barely smart enough to load these read_text_file type commands. That is a big part of why it is considered experimental but the case of running exported scripts works.