From a56eb93a8a83bd8d27e3a24b32c1bbfe4827a2dc Mon Sep 17 00:00:00 2001 From: DeLaVlag Date: Fri, 6 Jan 2023 14:37:56 +0100 Subject: [PATCH] minval maxval extension for TVB Rateml --- lems/model/component.py | 20 ++++++++++++++++++-- lems/model/dynamics.py | 10 +++++++++- lems/parser/LEMS.py | 36 +++++++++++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/lems/model/component.py b/lems/model/component.py index 1b5b34f..595b5eb 100644 --- a/lems/model/component.py +++ b/lems/model/component.py @@ -21,7 +21,7 @@ class Parameter(LEMSBase): Stores a parameter declaration. """ - def __init__(self, name, dimension, description=""): + def __init__(self, name, dimension, minval, maxval, description=""): """ Constructor. @@ -56,6 +56,14 @@ def __init__(self, name, dimension, description=""): """ Description of this parameter. :type: str """ + self.minval = minval + """ Minimum value of this parameter. + :type: str """ + + self.maxval = maxval + """ Maximum value of this parameter. + :type: str """ + def toxml(self): """ Exports this object into a LEMS XML object @@ -309,7 +317,7 @@ class Exposure(LEMSBase): Stores a exposure specification. """ - def __init__(self, name, dimension, description=""): + def __init__(self, name, minval, maxval, dimension, description=""): """ Constructor. @@ -320,6 +328,14 @@ def __init__(self, name, dimension, description=""): """ Name of the exposure. :type: str """ + self.minval = minval + """ Minimum value of this parameter. + :type: str """ + + self.maxval = maxval + """ Maximum value of this parameter. + :type: str """ + self.dimension = dimension """ Physical dimension of the exposure. :type: str """ diff --git a/lems/model/dynamics.py b/lems/model/dynamics.py index 1ad1275..3fe6e59 100644 --- a/lems/model/dynamics.py +++ b/lems/model/dynamics.py @@ -16,7 +16,7 @@ class StateVariable(LEMSBase): Store the specification of a state variable. """ - def __init__(self, name, dimension, exposure=None): + def __init__(self, name, minval, maxval, dimension, exposure=None): """ Constructor. @@ -27,6 +27,14 @@ def __init__(self, name, dimension, exposure=None): """ Name of the state variable. :type: str """ + self.minval = minval + """ Minimum value of this parameter. + :type: str """ + + self.maxval = maxval + """ Maximum value of this parameter. + :type: str """ + self.dimension = dimension """ Dimension of the state variable. :type: str """ diff --git a/lems/parser/LEMS.py b/lems/parser/LEMS.py index a48eee9..00a4dca 100644 --- a/lems/parser/LEMS.py +++ b/lems/parser/LEMS.py @@ -985,6 +985,16 @@ def parse_exposure(self, node): except: self.raise_error(" must specify a name") + if "minval" in node.lattrib: + minval = node.lattrib["minval"] + else: + minval = 0.0 + + if "maxval" in node.lattrib: + maxval = node.lattrib["maxval"] + else: + maxval = 0.0 + try: dimension = node.lattrib["dimension"] except: @@ -992,7 +1002,7 @@ def parse_exposure(self, node): description = node.lattrib.get("description", "") - self.current_component_type.add_exposure(Exposure(name, dimension, description)) + self.current_component_type.add_exposure(Exposure(name, minval, maxval, dimension, description)) def parse_fixed(self, node): """ @@ -1286,13 +1296,23 @@ def parse_parameter(self, node): except: self.raise_error(" must specify a name") + if "minval" in node.lattrib: + minval = node.lattrib["minval"] + else: + minval = 0.0 + + if "maxval" in node.lattrib: + maxval = node.lattrib["maxval"] + else: + maxval = 0.0 + try: dimension = node.lattrib["dimension"] except: self.raise_error("Parameter '{0}' has no dimension", name) description = node.lattrib.get("description", "") - parameter = Parameter(name, dimension, description) + parameter = Parameter(name, dimension, minval, maxval, description) self.current_component_type.add_parameter(parameter) @@ -1638,6 +1658,16 @@ def parse_state_variable(self, node): else: self.raise_error(" must specify a name") + if "minval" in node.lattrib: + minval = node.lattrib["minval"] + else: + minval = 0.0 + + if "maxval" in node.lattrib: + maxval = node.lattrib["maxval"] + else: + maxval = 0.0 + if "dimension" in node.lattrib: dimension = node.lattrib["dimension"] else: @@ -1648,7 +1678,7 @@ def parse_state_variable(self, node): else: exposure = None - self.current_regime.add_state_variable(StateVariable(name, dimension, exposure)) + self.current_regime.add_state_variable(StateVariable(name, minval, maxval, dimension, exposure)) def parse_structure(self, node): """