.. _predictionmodel-py: ################## predictionmodel.py ################## :: >>> from simo.builder.modelbase.predictionmodel import PredictionModel >>> from lxml import etree >>> xml = u''' ... ... Productive_value_of_land_pine_Pukkala ... StaticstandModels.dll ... C ... ... Timo Pukkala ... ... ... ... ... ... ... 1 ... ... ... ... ... ... ... ... ... ... TS ... comp_unit ... ... ... ... ... IR ... ... ... ... self ... ... ... PVland_Sp ... ... ... ... ... ''' >>> class Validator: ... def elem_name(self, text): ... return text ... def variable_ind(self, level, variable, active=False): ... return (1,1) ... def add_model(self, mname, mtype): ... pass >>> elem = etree.fromstring(xml) ******************************* class PredictionModel(POModel): ******************************* Class for prediction model definitions Properties: - type: get model type as string - name: get model name as string - language: get model implementation language as string - dirs: get model library directories as a list of strings - function: get model function object - library: get model library object - wrapper: get model library wrapper object Attributes: - n_vars: number of input variables - vars: input variables in a dictionary: level as the key and value is a dictionary with the structure {'index': , 'order': , 'limits': } - n_params: number of input parameters - params: number of input parameters in a list where each item is a (, ) -tuple - result_level: result level indice as int - result_vars: result variables in a list of ResultVariable instances def __init__(self, ns, elem, validator, dirs): ============================================== Construct prediction model object from XML element:: >>> pr = PredictionModel('', elem[0], Validator(), 'dummydir', ... elem.attrib['name']) >>> pr.name 'Productive_value_of_land_pine_Pukkala' >>> pr.group 'Distribution models' >>> pr.language 'c' >>> pr.n_vars 1 >>> pr.vars {1: {'index': array([1]), 'order': [0], 'limits': [None]}} >>> pr.n_params 1 >>> pr.param_names ['IR'] >>> pr.param_limits [None] >>> pr.result_level 1 ***************************** class ResultVariable(object): ***************************** Class for prediction model result variables Attributes: - variable - time_span - time_unit - cumulation def __init__(self, variable, timespan=None, unit=None, cumul=None): =================================================================== *************************************** class PredictionModelParam(Persistent): *************************************** Class for prediction model parameters def __init__(self, ns, elem, task, model): ========================================== Initialize prediction model parameter object:: >>> execfile('builder/modelbase/test/mocktask.py') >>> xml_no_param = u''' ... 1.15 ... 2 ... ''' >>> xml = u''' ... ... ... IR ... 10.5 ... ... ... PARAMETER2 ... VALUE ... ... ... 1.15 ... 2 ... ''' >>> from simo.builder.modelbase.predictionmodel import PredictionModelParam >>> elem = etree.fromstring(xml_no_param) >>> pmp = PredictionModelParam('', elem, task, pr) >>> abs(pmp.rect_factor - 1.15) < 0.0001 True >>> abs(pmp.risk_level - 2.0) < 0.0001 True >>> task.validator.errors # doctest: +NORMALIZE_WHITESPACE set(["No parameters defined in model chain for prediction model 'Productive_value_of_land_pine_Pukkala', 1 parameters expected"]) >>> task.validator.errors = set([]) >>> elem = etree.fromstring(xml) >>> pmp = PredictionModelParam('', elem, task, pr) >>> pmp.parameters [10.5] >>> task.validator.errors # doctest: +NORMALIZE_WHITESPACE set(["Parameter 'PARAMETER2' is not a valid parameter for prediction model 'Productive_value_of_land_pine_Pukkala'"])