Table Of Contents

Previous topic

operationmodel.py

Next topic

predictionmodel.py

This Page

parametertable.py

>>> from simo.builder.modelbase.modelbase import ModelbaseDef
>>> tdf = open('../../simulator/xml/schemas/Typedefs_SIMO.xsd')
>>> typedef = tdf.read()
>>> tdf.close()
>>> sf = open('../../simulator/xml/schemas/parameter_table.xsd')
>>> schema = sf.read()
>>> sf.close()
>>> xml = u'''<parameter_tables xmlns="http://www.simo-project.org/simo"
...      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
... <parameter_table name="regeneration_limits"
...                  type="parameter_table" desc="...">
...     <classifiers>
...         <classifier>
...             <variable>MAIN_SP</variable>
...             <level>comp_unit</level>
...         </classifier>
...     </classifiers>
...         <targets>
...             <target>
...                 <data>
...                     <variable>upper_dgm</variable>
...                     <level>comp_unit</level>
...                 </data>
...             </target>
...             <target>
...                 <data>
...                     <variable>upper_age</variable>
...                     <level>comp_unit</level>
...                 </data>
...             </target>
...         </targets>
...         <table>
...             <value>1 32 70</value>
...             <value>9 21 50</value>
...         </table>
...     </parameter_table>
... </parameter_tables>'''
>>> mb = ModelbaseDef(typedef)
>>> mb.schema = ('parameter_table', schema)
>>> try:
...     mb.xml = ('testxml', xml, None, '', 'parameter_table')
... except ValueError, e:
...     e.message
'errors in xml to object conversion'
>>> mb.errors 
set(["No lexicon set when adding model for parameter table
      collection 'testxml'",
     "No lexicon set when validating variable for parameter table
      collection 'testxml'"])
>>> class Lexicon(object):
...     def __init__(self):
...         self.models = {}
...     def get_variable_ind(self, level, var, active=False):
...         return (1, 1)
...     def get_level_ind(self, level):
...         return 1
...     def add_model(self, mtype, mname):
...         if mtype not in self.models:
...             self.models[mtype] = set()
...         self.models[mtype].add(mname)
>>> mb.xml = ('testxml', xml, Lexicon(), '', 'parameter_table')
>>> mb.errors
set([])
>>> mb.ok
{'testxml': True}
>>> mb.xml['parameter_table']['testxml'][:17]
u'<parameter_tables'

class ParameterTable(object):

Parameter table definition

Attributes:

  • name: parameter table name as string
  • labels: parameter table labels
  • classifiers: parameter table classifiers as a dictionary with TableClassifier objects as values
  • Nclassifiers: number of classifiers as integer
  • targets: parameter table targets as a list of ParamTableTarget objects
  • Ntargets: number of targets as integer
  • arrays: list of Array objects
  • Narrays: number of arrays as integer
  • active_array: currently active array

def __init__(self, ns, elem, validator, dirs):

class ParamTableTarget(object):

Class for parameter table targets

Attributes:

  • type: target type
  • name: target variable name
  • level: target variable level
  • length: target length

def __init__(self, ns, elem, validator):