Ejemplo n.º 1
0
 def __init__(self, outputs=None):
     super(Outputs, self).__init__(outputs)
     #: dictionary of output sources added to the Formula layer
     self.output_sources = {}
     #: output source objects
     self.output_obj = {}
     #: outputs
     self.outputs = OutputRegistry()
Ejemplo n.º 2
0
 def __init__(self, outputs=None):
     super(Outputs, self).__init__(outputs)
     #: dictionary of output sources added to the Formula layer
     self.output_sources = {}
     #: output source objects
     self.output_obj = {}
     #: outputs
     self.outputs = OutputRegistry()
Ejemplo n.º 3
0
class Outputs(Layer):
    """
    Layer containing outputs.
    """
    def __init__(self, outputs=None):
        super(Outputs, self).__init__(outputs)
        #: dictionary of output sources added to the Formula layer
        self.output_sources = {}
        #: output source objects
        self.output_obj = {}
        #: outputs
        self.outputs = OutputRegistry()
        # layers are initialized by the model

    def add(self, output_sources, module, package=None):
        """
        """
        # import module
        mod = importlib.import_module(module, package)
        # get output source class definition from module
        if output_sources.startswith('_'):
            err_msg = 'No "%s" attribute in "%s".' % (output_sources, mod)
            raise AttributeError(err_msg)
        self.output_sources[output_sources] = getattr(mod, output_sources)
        # instantiate the output object
        self.output_obj[output_sources] = self.output_sources[output_sources]()
        # register outputs and meta-data in registry
        out_src_obj = self.output_obj[output_sources]
        self.outputs.register(out_src_obj.outputs, out_src_obj.initial_value,
                              out_src_obj.size, out_src_obj.uncertainty,
                              out_src_obj.isconstant, out_src_obj.isproperty)

    def open(self, output_source, module, package=None):
        self.add(output_source, module, package=None)

    def load(self):
        """
        Add output_source to layer.
        """
        for k, v in self.layer.iteritems():
            self.add(k, v['module'], v.get('package'))
Ejemplo n.º 4
0
class Outputs(Layer):
    """
    Layer containing outputs.
    """
    def __init__(self, outputs=None):
        super(Outputs, self).__init__(outputs)
        #: dictionary of output sources added to the Formula layer
        self.output_sources = {}
        #: output source objects
        self.output_obj = {}
        #: outputs
        self.outputs = OutputRegistry()
        # layers are initialized by the model

    def add(self, output_sources, module, package=None):
        """
        """
        # import module
        mod = importlib.import_module(module, package)
        # get output source class definition from module
        if output_sources.startswith('_'):
                err_msg = 'No "%s" attribute in "%s".' % (output_sources, mod)
                raise AttributeError(err_msg)
        self.output_sources[output_sources] = getattr(mod, output_sources)
        # instantiate the output object
        self.output_obj[output_sources] = self.output_sources[output_sources]()
        # register outputs and meta-data in registry
        out_src_obj = self.output_obj[output_sources]
        self.outputs.register(out_src_obj.outputs, out_src_obj.initial_value,
                              out_src_obj.size, out_src_obj.uncertainty,
                              out_src_obj.isconstant, out_src_obj.isproperty)

    def open(self, output_source, module, package=None):
        self.add(output_source, module, package=None)

    def load(self):
        """
        Add output_source to layer.
        """
        for k, v in self.layer.iteritems():
            self.add(k, v['module'], v.get('package'))