Table Of Contents

Previous topic

opres.py

Next topic

output.py

This Page

out.py

class Out(object):

This class executes all the given output types and writes them to the given output files.

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

Creates the output class

>>> from simo.output.test.init_objects import InitData, TestLogger
>>> idata = InitData()
>>> idata.init()
>>> testdb = idata.testdb
>>> const_obj = idata.const_obj
>>> aggr_obj = idata.aggr_obj
>>> expr_obj = idata.expr_obj
>>> from simo.output.out import Out
>>> out = Out(testdb, 'result', ['stand1'], 'stratum',
...               'optimized', ['inlined', 'by_level', 'operation_result',
...               'aggregation', 'branching_graph', 'smt'], 'output',
...              ['test/inlined.txt',
...               'test/by_level.txt',
...               'test/opres.txt',
...               'test/aggregation.txt',
...               'test',
...               'test/smt.txt'], TestLogger(),
...               const_obj, 1, False, True, aggr_obj, expr_obj,
...               ['cash_flow', 'Income', 'Scrapwood', 'Volume',
...                'BIOMASS_branches', 'BIOMASS_stumps'], ['assortment',
...                'SP'])
... #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
output info : Writing inlined
output info : finished in ...
output info : Writing by_level
output info : finished in ...
output info : Writing operation_result
output info : finished in ...
output info : Writing aggregation
output info : finished in ...
output info : Writing branching_graph
output info : finished in ...
output info : Writing smt
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
output info : finished in ...

>>> try: # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
...     file = open('output/test/inlined.txt', 'r')
...     for line in file:
...         print line.rstrip('\n')
... finally:
...     file.close()
 sim unit; branch; iteration; data level;           id; date; AREA;   SC
   stand1;      0;         0;  comp_unit;     o-stand1; 2009;  1.0;  3.0
 sim unit; branch; iteration; data level;           id; date;   SP;   BA;  HgM
   stand1;      0;         0;    stratum; o-stratum1-1; 2009;  1.0; 17.0; 19.0
 sim unit; branch; iteration; data level;           id; date;    d;    h
   stand1;      0;         0;       tree;  o-tree1-1-1; 2009; 17.0; 18.0
 sim unit; branch; iteration; data level;           id; date;   SP;   BA;  HgM
   stand1;      0;         0;    stratum; o-stratum1-2; 2009;  2.0;  8.0; 18.5
 sim unit; branch; iteration; data level;           id; date;    d;    h
   stand1;      0;         0;       tree;  o-tree1-2-1; 2009; 22.0; 21.0
 sim unit; branch; iteration; data level;           id; date; AREA;   SC
   stand1;      0;         1;  comp_unit;     o-stand1; 2009;  1.0;  3.0
 sim unit; branch; iteration; data level;           id; date;   SP;   BA;  HgM
   stand1;      0;         1;    stratum; o-stratum1-1; 2009;  1.0; 17.0; 19.0
 sim unit; branch; iteration; data level;           id; date;    d;    h
   stand1;      0;         1;       tree;  o-tree1-1-1; 2009; 17.0; 18.0
 sim unit; branch; iteration; data level;           id; date;   SP;   BA;  HgM
   stand1;      0;         1;    stratum; o-stratum1-2; 2009;  2.0;  8.0; 18.5
 sim unit; branch; iteration; data level;           id; date;    d;    h
   stand1;      0;         1;       tree;  o-tree1-2-1; 2009; 22.0; 21.0

>>> try: # doctest: +ELLIPSIS
...     file = open('output/test/by_level.txt', 'r')
...     for line in file:
...         print line.rstrip('\n')
... finally:
...     file.close()
 sim unit; branch; iteration; data level;           id; date; AREA;  SC;  SP;   BA;  HgM;    d;    h
   stand1;      0;         0;  comp_unit;     o-stand1; 2009;  1.0; 3.0;    ;     ;     ;     ;
   stand1;      0;         0;    stratum; o-stratum1-1; 2009;     ;    ; 1.0; 17.0; 19.0;     ;
   stand1;      0;         0;       tree;  o-tree1-1-1; 2009;     ;    ;    ;     ;     ; 17.0; 18.0
   stand1;      0;         0;    stratum; o-stratum1-2; 2009;     ;    ; 2.0;  8.0; 18.5;     ;
   stand1;      0;         0;       tree;  o-tree1-2-1; 2009;     ;    ;    ;     ;     ; 22.0; 21.0
   stand1;      0;         1;  comp_unit;     o-stand1; 2009;  1.0; 3.0;    ;     ;     ;     ;
   stand1;      0;         1;    stratum; o-stratum1-1; 2009;     ;    ; 1.0; 17.0; 19.0;     ;
   stand1;      0;         1;       tree;  o-tree1-1-1; 2009;     ;    ;    ;     ;     ; 17.0; 18.0
   stand1;      0;         1;    stratum; o-stratum1-2; 2009;     ;    ; 2.0;  8.0; 18.5;     ;
   stand1;      0;         1;       tree;  o-tree1-2-1; 2009;     ;    ;    ;     ;     ; 22.0; 21.0

>>> try: # doctest: +ELLIPSIS
...     file = open('output/test/opres.txt', 'r')
...     for line in file:
...         print line.rstrip('\n')
... finally:
...     file.close()
     level;     id; date; iteration; branch;      op_group;  op_name; Volume; cash_flow; assortment;  SP
 comp_unit; stand1; 2009;         0;      0;  regeneration; planting;       ;    -456.7;           ;
 comp_unit; stand1; 2009;         0;      0; final_harvest; clearcut;       ;    3456.7;           ;
 comp_unit; stand1; 2009;         0;      0; final_harvest; clearcut;  123.2;          ;        5.0; 1.0
>>> try: # doctest: +ELLIPSIS
...     file = open('output/test/aggregation.txt', 'r')
...     for line in file:
...         print line.rstrip('\n')
... finally:
...     file.close()
Results for expression (5 keys): sum[-1:-1](stratum:HgM[SP eq 2 and DgM gt 19])
 stratum:SP; stratum:DgM; 08/02/09-08/02/09
        1.0;        20.0;               0.0
        2.0;         0.0;               0.0
        2.0;        18.0;               0.0
        2.0;        30.0;              62.0
        3.0;        27.0;               0.0
Errors (key: stratum:SP, stratum:DgM):
No values for stratum:HgM between 2009-02-08 and 2009-02-08;1.0, 20.0;2.0, 0.0;2.0, 18.0;3.0, 27.0
<BLANKLINE>
Proportions for expression (5 keys): sum[0:99](stratum:SP*stratum:HgM)
 stratum:HgM; stratum:DgM; 01/01/09-08/02/09
         0.0;         0.0;               0.0
        18.5;        18.0;               0.2
        19.0;        20.0;               0.1
        26.0;        27.0;               0.4
        31.0;        30.0;               0.3
Errors (key: stratum:HgM, stratum:DgM):
<BLANKLINE>
Results for expression (1 keys): sum[0:99](operation:Volume)
 01/01/09-08/02/09
             123.2
Errors (key: ):
<BLANKLINE>
Results for expression (1 keys): sum[0:99](operation:cash_flow)
 01/01/09-08/02/09
            3000.0
Errors (key: ):
<BLANKLINE>
Results for expression (2 keys): sum[0:99](operation:cash_flow)
 comp_unit:AREA; 01/01/09-08/02/09
            1.0;            3000.0
            2.0;               0.0
Errors (key: comp_unit:AREA):
No values for operation:cash_flow between 2009-01-01 and 2009-02-08;2.0
<BLANKLINE>
>>> try: # doctest: +ELLIPSIS
...     file = open('output/test/stratum2-1_0.dot', 'r')
...     for line in file:
...         print line.rstrip('\n')
... finally:
...     file.close()
digraph branches {
nodesep=0.01;
ranksep=0.01;
size="8.27,11.69";
ratio=fill;
<BLANKLINE>
{
node [shape=plaintext fontsize=14 height=.01];
<BLANKLINE>
2009;
}
<BLANKLINE>
{
node [shape=doublecircle];
<BLANKLINE>
b_0_2009 [label="0" fontcolor=red group="0"];
b_1_2009 [label="1" fontcolor=red group="1"];
}
<BLANKLINE>
{
node [shape=point]
<BLANKLINE>
b_0_2009 [group="0"];
b_1_2009 [group="1"];
}
<BLANKLINE>
{ rank = same; 2009; b_0_2009; b_1_2009; }
<BLANKLINE>
b_0_2009 -> b_1_2009 [ label="branch_name" fontsize=14 fontcolor=red];
<BLANKLINE>
}
<BLANKLINE>

>>> out = Out(testdb, 'result', ['stand1'], 'comp_unit',
...               'optimized', ['smt'], 'output',
...              ['test/smt.txt'], TestLogger(),
...               const_obj, 1, False, True, aggr_obj,
...               ['cash_flow', 'Income', 'Scrapwood', 'Volume',
...               'BIOMASS_branches', 'BIOMASS_stumps'])
... #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
output info : Writing smt
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
output info : finished in ...
>>> try: # doctest:
...     file = open('output/test/smt.txt', 'r')
...     for line in file:
...         print line.rstrip('\n')
... finally:
...     file.close()
stand1 1 1.0 3.0 2009
stand1 1 1.0 17.0 19.0 2009
stand1 2 2.0 8.0 18.5 2009
stand1 1 1.0 3.0 2009
stand1 1 1.0 17.0 19.0 2009
stand1 2 2.0 8.0 18.5 2009

>>> try: # doctest:
...     file = open('output/test/expression.txt', 'r')
...     for line in file:
...         print line.rstrip('\n')
... finally:
...     file.close()
level;unit;iteration;branch;1st expression;2nd expression
comp_unit;stand1;0;0;0.0;0.0
comp_unit;stand1;1;0;0.0;0.0
comp_unit;stand2;0;0;0.0;0.0
comp_unit;stand2;0;1;0.0;0.0
comp_unit;stand2;1;0;0.0;0.0
comp_unit;stand2;1;1;0.0;0.0
stratum;stratum1-1;0;0;0.0;0.0
stratum;stratum1-1;1;0;0.0;0.0
stratum;stratum1-2;0;0;0.0;0.0
stratum;stratum1-2;1;0;0.0;0.0
stratum;stratum2-1;0;0;31.0;0.0
stratum;stratum2-1;1;0;31.0;0.0
stratum;stratum2-2;0;0;0.0;0.0
stratum;stratum2-2;1;0;0.0;0.0
stratum;stratum2-3;0;1;0.0;0.0
stratum;stratum2-3;1;1;0.0;0.0