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'])
... 
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: 
...     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: 
...     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: 
...     file = open('output/test/opres.txt', 'r')
...     for line in file:
...         print line.rstrip('\n')
... finally:
...     file.close() 
  op_level;     id; op_date; iteration; branch;      op_group;  op_name; Volume; cash_flow; assortment;  SP
 comp_unit; stand1;    2009;         0;      0;  regeneration; planting;       ;    -456...;           ;
 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: 
...     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[stratum:SP eq 2 and stratum: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

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

Results for expression (1 keys): sum[0:99](operation:Volume)
 01/01/09-08/02/09
             123.2

Results for expression (1 keys): sum[0:99](operation:cash_flow)
 01/01/09-08/02/09
            3000.0

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

Results for expression (2 keys): sum[0:99](operation:cash_flow)
 operation:op_name; comp_unit:SC; comp_unit:DEV_CLASS; 01/01/09-08/02/09
          clearcut;          3.0;                 4.0;            3456.7
          planting;          3.0;                 4.0;            -456...

>>> try: 
...     file = open('output/test/stand1_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;

{
node [shape=plaintext fontsize=14 height=.01];

20090207;
}

{
node [shape=doublecircle];

b_0_20090207 [label="0" fontcolor=red group="0"];
}

{
node [shape=point]

b_0_20090207 [group="0"];
}

{ rank = same; 20090207; b_0_20090207; }


}


>>> 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'])
... 
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