Table Of Contents

Previous topic

output.py

Next topic

condeval.py

This Page

smt.py

class OutputSMT(Output):

Module for data output in SMT file format: values from the last year in the simulation as whitespace separated fields starting with top-level id and object id and ending in the year for the values

def __init__(self, datadb, data_type, id_list, main_level, result_type, output_filename, output_constraint=None, default_decimal_places=1, archiving=False, result_padding=True, aggregation_def=None, expression_def=None, opres_vars=None):

Creates the output class. fully inherited, executes self.run()

>>> from simo.output.test.init_objects import InitData, TestLogger
>>> from pprint import pprint
>>> idata = InitData(alt_const=True)
>>> idata.init()
>>> testdb = idata.testdb
>>> const_obj = idata.const_obj
>>> aggr_obj = idata.aggr_obj
>>> expr_obj = idata.expr_obj
>>> from simo.output.smt import OutputSMT
>>> out = OutputSMT(testdb, 'result', ['stand1'], 'comp_unit',
...               'optimized',
...               'output/test/smt.txt', TestLogger(),
...               const_obj, 1, False, True, aggr_obj, expr_obj,
...               ['cash_flow', 'Income', 'Scrapwood', 'Volume',
...               'BIOMASS_branches', 'BIOMASS_stumps'])
... 
smt warning : Bad stratum id 'o-stratum1-1' on sim unit stand1, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum1-2' on sim unit stand1, year 2009
in results. Replacing with 2
smt warning : Bad stratum id 'o-stratum1-1' on sim unit stand1, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum1-2' on sim unit stand1, year 2009
in results. Replacing with 2

def run(self):

Uses data from init to run the class-specific output

def _get_strings(self, constraints=None, dates=None, sim_unit=None):

This method will get a list of strings from the datadb formatted in the SMT format

>>> result = out._get_strings() 
smt warning : Bad stratum id 'o-stratum1-1' on sim unit stand1, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum1-2' on sim unit stand1, year 2009
in results. Replacing with 2
smt warning : Bad stratum id 'o-stratum1-1' on sim unit stand1, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum1-2' on sim unit stand1, year 2009
in results. Replacing with 2
smt warning : Bad stratum id 'o-stratum2-3' on sim unit stand2, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum2-1' on sim unit stand2, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum2-2' on sim unit stand2, year 2009
in results. Replacing with 2
smt warning : Bad stratum id 'o-stratum2-1' on sim unit stand2, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum2-2' on sim unit stand2, year 2009
in results. Replacing with 2
smt warning : Bad stratum id 'o-stratum2-3' on sim unit stand2, year 2009
in results. Replacing with 1

>>> pprint(result)
[u'stand1 1 1.0 17.0 19.0 2009',
 u'stand1 2 2.0 8.0 18.5 2009',
 u'stand1 1 1.0 17.0 19.0 2009',
 u'stand1 2 2.0 8.0 18.5 2009',
 u'stand2 1 2.0 0.0 0.0 2009',
 u'stand2 1 2.0 24.0 31.0 2009',
 u'stand2 2 3.0 12.0 26.0 2009',
 u'stand2 1 2.0 24.0 31.0 2009',
 u'stand2 2 3.0 12.0 26.0 2009',
 u'stand2 1 2.0 0.0 0.0 2009']

def _get_strings_items(self, constraints=None, dates=None, level=1, sim_unit=None):

This method will fetch the items needed for the SMT output and return them as a list of lists of strings

>>> items = out._get_strings_items() 
smt warning : Bad stratum id 'o-stratum1-1' on sim unit stand1, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum1-2' on sim unit stand1, year 2009
in results. Replacing with 2
smt warning : Bad stratum id 'o-stratum1-1' on sim unit stand1, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum1-2' on sim unit stand1, year 2009
in results. Replacing with 2
smt warning : Bad stratum id 'o-stratum2-3' on sim unit stand2, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum2-1' on sim unit stand2, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum2-2' on sim unit stand2, year 2009
in results. Replacing with 2
smt warning : Bad stratum id 'o-stratum2-1' on sim unit stand2, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum2-2' on sim unit stand2, year 2009
in results. Replacing with 2
smt warning : Bad stratum id 'o-stratum2-3' on sim unit stand2, year 2009
in results. Replacing with 1
>>> pprint(items)
[[u'stand1', u'1', '1.0', '17.0', '19.0', '2009'],
 [u'stand1', u'2', '2.0', '8.0', '18.5', '2009'],
 [u'stand1', u'1', '1.0', '17.0', '19.0', '2009'],
 [u'stand1', u'2', '2.0', '8.0', '18.5', '2009'],
 [u'stand2', u'1', '2.0', '0.0', '0.0', '2009'],
 [u'stand2', u'1', '2.0', '24.0', '31.0', '2009'],
 [u'stand2', u'2', '3.0', '12.0', '26.0', '2009'],
 [u'stand2', u'1', '2.0', '24.0', '31.0', '2009'],
 [u'stand2', u'2', '3.0', '12.0', '26.0', '2009'],
 [u'stand2', u'1', '2.0', '0.0', '0.0', '2009']]

def smt(self, file, constraints=None, dates=None):

This method will fetch the SMT data with the given constraints and writes it to the given file

def inlined(self, file, constraints=None, dates=None, date_res=0):

This function will get the smt strings (with _get_strings, using the given restrictions and date resolution) and print them to the given file.

>>> out.smt('output/test/smt.txt') 
smt warning : Bad stratum id 'o-stratum1-1' on sim unit stand1, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum1-2' on sim unit stand1, year 2009
in results. Replacing with 2
smt warning : Bad stratum id 'o-stratum1-1' on sim unit stand1, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum1-2' on sim unit stand1, year 2009
in results. Replacing with 2
smt warning : Bad stratum id 'o-stratum2-3' on sim unit stand2, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum2-1' on sim unit stand2, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum2-2' on sim unit stand2, year 2009
in results. Replacing with 2
smt warning : Bad stratum id 'o-stratum2-1' on sim unit stand2, year 2009
in results. Replacing with 1
smt warning : Bad stratum id 'o-stratum2-2' on sim unit stand2, year 2009
in results. Replacing with 2
smt warning : Bad stratum id 'o-stratum2-3' on sim unit stand2, year 2009
in results. Replacing with 1
>>> try:
...     file = open('output/test/smt.txt', 'r')
...     for line in file:
...         print line.rstrip('\n')
... finally:
...     file.close()
stand1 1 1.0 17.0 19.0 2009
stand1 2 2.0 8.0 18.5 2009
stand1 1 1.0 17.0 19.0 2009
stand1 2 2.0 8.0 18.5 2009
stand2 1 2.0 0.0 0.0 2009
stand2 1 2.0 24.0 31.0 2009
stand2 2 3.0 12.0 26.0 2009
stand2 1 2.0 24.0 31.0 2009
stand2 2 3.0 12.0 26.0 2009
stand2 1 2.0 0.0 0.0 2009