Exemplo n.º 1
0
    def __init__(self, variable, value):
        """
        Constructor.

        See instance variable documentation for more info on parameters.
        """

        Action.__init__(self)

        self.variable = variable
        """ Name of the variable for which the time derivative is being specified.
        @type: str """

        self.value = value
        """ Derivative expression.
        @type: str """

        self.expression_tree = None
        """ Parse tree for the time derivative expression.
        @type: lems.parser.expr.ExprNode """

        try:
            self.expression_tree = ExprParser(value).parse()
        except:
            raise ParseError("Parse error when parsing state assignment "
                             "value expression "
                             "'{0}' for state variable {1}",
                             self.value, self.variable)
Exemplo n.º 2
0
    def __init__(self, name, value, dimension=None, description=''):
        """
        Constructor.

        See instance variable documentation for more info on derived parameters.
        """

        self.name = name
        """ Name of the derived parameter.
        @type: str """

        self.dimension = dimension
        """ Physical dimensions of the derived parameter.
        @type: str """

        self.value = value
        """ Value of the derived parameter.
        @type: str """

        self.description = description
        """ Description of the derived parameter.
        @type: str """

        try:
            ep = ExprParser(self.value)
            self.expression_tree = ep.parse()
        except:
            raise ParseError(
                "Parse error when parsing value expression "
                "'{0}' for derived parameter {1}", self.value, self.name)
Exemplo n.º 3
0
    def __init__(self, condition, value):
        """
        Constructor.
        """

        self.condition = condition
        """ Condition for this case.
        @type: str """

        self.value = value
        """ Value if the condition is true.
        @type: str """

        self.condition_expression_tree = None
        """ Parse tree for the case condition expression.
        @type: lems.parser.expr.ExprNode """

        self.value_expression_tree = None
        """ Parse tree for the case condition expression.
        @type: lems.parser.expr.ExprNode """

        try:
            self.value_expression_tree = ExprParser(self.value).parse()

            if not self.condition:
                self.condition_expression_tree = None
            else:
                self.condition_expression_tree = ExprParser(self.condition).parse()
        except:
            raise ParseError("Parse error when parsing case with condition "
                             "'{0}' and value {1}",
                             self.condition, self.value)
Exemplo n.º 4
0
    def __init__(self, variable, value):
        """
        Constructor.

        @param variable: Name of the state variable
        @type variable: string

        @param value: Time derivative expression of the given state variable.
        @type value: string
        """

        self.variable = variable
        """ State variable whose time derivative is stored in this object.
        @type: string """

        self.value = value
        """ Time derivative expression for the state variable.
        @type: string """

        try:
            self.expression_tree = ExprParser(value).parse()
            """ Parse tree for the time derivative expression.
            @type: lems.parser.expr.ExprNode """
        except:
            raise ParseError("Parse error when parsing value expression "
                             "'{0}' for derived variable {1}".format(\
                                 self.value,
                                 self.variable))
Exemplo n.º 5
0
    def raise_error(self, message):
        s = 'Parser error in '

        self.xml_node_stack.reverse()
        if len(self.xml_node_stack) > 1:
            node = self.xml_node_stack[0]
            s += '<{0}'.format(node.tag)
            if 'name' in node.lattrib:
                s += ' name=\"{0}\"'.format(node.lattrib['name'])
            if 'id' in node.lattrib:
                s += ' id=\"{0}\"'.format(node.lattrib['id'])
            s += '>'

        for node in self.xml_node_stack[1:]:
            s += '.<{0}'.format(node.tag)
            if 'name' in node.lattrib:
                s += ' name=\"{0}\"'.format(node.lattrib['name'])
            if 'id' in node.lattrib:
                s += ' id=\"{0}\"'.format(node.lattrib['id'])
            s += '>'

        s += ':\n  ' + message

        raise ParseError(s)

        self.xml_node_stack.reverse()
Exemplo n.º 6
0
    def __init__(self, name, **params):
        """
        Constructor.

        See instance variable documentation for more info on parameters.
        """

        self.name = name
        """ Name of the derived variable.
        @type: str """

        self.dimension = params['dimension'] if 'dimension' in params else None
        """ Dimension of the derived variable or None if computed.
        @type: str """

        self.exposure = params['exposure'] if 'exposure' in params else None
        """ Exposure name for the derived variable.
        @type: str """

        self.select = params['select'] if 'select' in params else None
        """ Selection path/expression for the derived variable.
        @type: str """

        self.expression = params[
            'expression'] if 'expression' in params else None
        """ Value of the derived variable.
        @type: str """

        self.reduce = params['reduce'] if 'reduce' in params else None
        """ Reduce method for the derived variable.
        @type: str """

        self.required = params['required'] if 'required' in params else None
        """ Requried or not.
        @type: str """

        self.expression_tree = None
        """ Parse tree for the time derivative expression.
        @type: lems.parser.expr.ExprNode """

        if self.expression != None:
            try:
                self.expression_tree = ExprParser(self.expression).parse()
            except:
                raise ParseError(
                    "Parse error when parsing value expression "
                    "'{0}' for derived variable {1}", self.expression,
                    self.name)
Exemplo n.º 7
0
    def __init__(self, test):
        """
        Constructor.

        See instance variable documentation for more details on parameters.
        """

        EventHandler.__init__(self)

        self.test = test
        """ Condition to be tested for.
        @type: str """

        try:
            self.expression_tree = ExprParser(test).parse()
        except:
            raise ParseError("Parse error when parsing OnCondition test '{0}'", test)
Exemplo n.º 8
0
    def parse(self, xmltext):
        """
        Parse a string containing LEMS XML text.

        @param xmltext: String containing LEMS XML formatted text.
        @type xmltext: str
        """

        xml = LEMSXMLNode(xe.XML(xmltext))

        if xml.ltag != 'lems' and xml.ltag != 'neuroml':
            raise ParseError(
                '<Lems> expected as root element (or even <neuroml>), found: {0}'
                .format(xml.ltag))
        '''
        if xml.ltag == 'lems':
            if 'description' in xml.lattrib:
                self.description = xml.lattrib['description']
        '''

        self.process_nested_tags(xml)
Exemplo n.º 9
0
    def __init__(self, name, exposure, dimension, value, select, reduce):
        """
        Constructor.

        @param name: Name (internal) of the derived variable.
        @type name: string

        @param exposure: Name (external) of the derived variable.
        @type exposure: string

        @param dimension: Dimension of the derived variable.
        @type dimension: string

        @param value: Value expression for the derived variable.
        @type value: string

        @param select: Target component selection for reduction operations.
        @type select: string

        @param reduce: Reduce operation.
        @type reduce: string
        """

        self.name = name
        """ Internal name of the derived variable. This is the name used to
        refer to this variable inside the <Behavior> element.
        @type: string """

        self.exposure = exposure
        """ Exposure name of the derived variable. This is the name used to
        refer to this variable from other objects.
        @type: string """

        self.dimension = dimension
        """ Dimension of this derived variable.
        @type: string """

        self.value = value
        """ Expression used for computing the value of the derived variable.
        @type: string """

        self.select = select
        """ Selected target object for the reduce operation.
        @type: string """

        self.reduce = reduce
        """ Reduce operation to be applied over the selected target.
        @type: string """

        if value != None:
            try:
                self.expression_tree = ExprParser(value).parse()
                """ Parse tree for the time derivative expression.
                @type: lems.parser.expr.ExprNode """
            except:
                raise ParseError("Parse error when parsing value expression "
                                 "'{0}' for derived variable {1}".format(\
                                     self.value,
                                     self.name))
        else:
            self.expression_tree = None