>>> from simo.builder.modelbase.model import Model
>>> from simo.builder.modelbase.model import POModel
>>> from lxml import etree
>>> xml = u'''<model>
... <name>Productive_value_of_land_pine_Pukkala</name>
... <implemented_at>StaticstandModels.dll</implemented_at>
... <implemented_in>C</implemented_in>
... <author>
... <name>Timo Pukkala</name>
... </author>
... <description> ...</description>
... <published_in> ...</published_in>
... <species_list>
... <species>1</species>
... </species_list>
... <geographical_coverage> ...</geographical_coverage>
... <applies_for> ...</applies_for>
... <research_material> ...</research_material>
... <variables>
... <variable>
... <name>TS</name>
... <level>comp_unit</level>
... <limits>
... <lower_limit>700</lower_limit>
... <upper_limit>1300</upper_limit>
... </limits>
... </variable>
... </variables>
... <parameters>
... <parameter>
... <name>IR</name>
... <limits>
... <lower_limit>0</lower_limit>
... <upper_limit>20</upper_limit>
... </limits>
... </parameter>
... </parameters>
... <result>
... <object>self</object>
... <variables>
... <variable>
... <name>PVland_Sp</name>
... </variable>
... </variables>
... </result>
... </model>'''
>>> class Validator:
... def elem_name(self, text):
... return text
... def variable_ind(self, level, variable, active=False):
... return (1,1)
... def add_error(self, errorstr):
... pass
>>> elem = etree.fromstring(xml)
Super class for all modelbase model classes.
Properties:
>>> m = Model()
Load model function object from model library:
>>> m._name = 'dummymodel'
>>> m._lang = 'python'
>>> m._lib = 'dummylib.py'
>>> m._dirs = ['builder/modelbase/test']
>>> m.load_function(Validator())
True
>>> m.function
<function dummymodel at ...>
Load the model library and wrapper module from the given path.
Load model function object from model wrapper.
Super class for prediction and operation models.
Properties:
Attributes:
>>> m = POModel('', elem, Validator(), 'dummydir')
>>> m.n_vars
1
>>> m.vars[1]['index']
array([1])
>>> m.vars[1]['order']
[0]
Parse model parameters and possible limits set for the parameter values.
Parse model variable definitions (data level, variable name) and limits set for the variable values.
Class for handling model variable limits.
Construct variable/parameter limits from XML element:
>>> from lxml import etree
>>> from simo.builder.modelbase.model import Limit
>>> xml = u'''<limits>
... <lower_limit>700</lower_limit>
... <upper_limit>1300</upper_limit>
... </limits>'''
>>> ns = ''
>>> elem = etree.fromstring(xml)
>>> limits = Limit(ns, elem)
>>> limits.lower
700.0
>>> limits.upper
1300.0
Check if a value (or an array of values) is inside limits:
>>> import numpy
>>> values = numpy.array([600,700,1000,1300,1400], dtype=float)
>>> limits.check(values)
array([False, True, True, True, False], dtype=bool)
Return a string representation of the limits:
>>> limits.limitstr('VARNAME')
"700.0 <= 'VARNAME' <= 1300.0"