Beispiel #1
0
    def _load(self, layer=None):
        """
        Load or update all or part of :attr:`model`.

        :param layer: Optionally load only specified layer.
        :type layer: str
        """
        # open model file for reading and convert JSON object to dictionary
        # read and load JSON parameter map file as "parameters"
        with open(self.param_file, 'r') as param_file:
            file_params = json.load(param_file)
            for layer, params in file_params.iteritems():
                # update parameters from file
                self.parameters[layer] = ModelParameter(**params)
        # if layer argument spec'd then only update/load spec'd layer
        if not layer or not self.model:
            # update/load model if layer not spec'd or if no model exists yet
            # TODO: separate model and parameters according to comments in #78
            self.model = copy.deepcopy(self.parameters)
        else:
            # convert non-sequence to tuple
            layers = _listify(layer)
            # update/load layers
            for layer in layers:
                self.model[layer] = copy.deepcopy(self.parameters[layer])
Beispiel #2
0
    def _load(self, layer=None):
        """
        Load or update all or part of :attr:`model`.

        :param layer: Optionally load only specified layer.
        :type layer: str
        """
        # open model file for reading and convert JSON object to dictionary
        # read and load JSON parameter map file as "parameters"
        with open(self.param_file, 'r') as param_file:
            file_params = json.load(param_file)
            for layer, params in file_params.iteritems():
                # update parameters from file
                self.parameters[layer] = ModelParameter(**params)
        # if layer argument spec'd then only update/load spec'd layer
        if not layer or not self.model:
            # update/load model if layer not spec'd or if no model exists yet
            # TODO: separate model and parameters according to comments in #78
            self.model = copy.deepcopy(self.parameters)
        else:
            # convert non-sequence to tuple
            layers = _listify(layer)
            # update/load layers
            for layer in layers:
                self.model[layer] = copy.deepcopy(self.parameters[layer])
Beispiel #3
0
 def delete(self, layer, items):
     """
     Delete items in model.
     """
     # Use edit to get the layer obj containing item
     items = _listify(items)  # make items a list if it's not
     layer_obj = self.edit(layer, dict.fromkeys(items), delete=True)
     for k in items:
         if k in layer_obj.layer:
             layer_obj.delete(k)
         else:
             raise AttributeError('item %s missing from layer %s' %
                                  (k, layer))
Beispiel #4
0
 def _update(self, layer=None):
     """
     Update layers in model.
     """
     if not layer:
         layers = self.layers
     else:
         # convert non-sequence to tuple
         layers = _listify(layer)
     for layer in layers:
         # relative path to layer files from model file
         path = os.path.abspath(os.path.join(self._meta.modelpath, layer))
         getattr(self, layer).load(path)
Beispiel #5
0
 def delete(self, layer, items):
     """
     Delete items in model.
     """
     # Use edit to get the layer obj containing item
     items = _listify(items)  # make items a list if it's not
     layer_obj = self.edit(layer, dict.fromkeys(items), delete=True)
     for k in items:
         if k in layer_obj.layer:
             layer_obj.delete(k)
         else:
             raise AttributeError('item %s missing from layer %s' %
                                  (k, layer))
Beispiel #6
0
 def _update(self, layer=None):
     """
     Update layers in model.
     """
     if not layer:
         layers = self.layers
     else:
         # convert non-sequence to tuple
         layers = _listify(layer)
     for layer in layers:
         # relative path to layer files from model file
         path = os.path.abspath(os.path.join(self.modelpath, layer))
         getattr(self, layer).load(path)
Beispiel #7
0
    def _load(self, layer=None):
        """
        Load or update all or part of :attr:`model`.

        :param layer: Optionally load only specified layer.
        :type layer: str
        """
        # open model file for reading and convert JSON object to dictionary
        with open(self.modelfile, 'r') as fp:
            _model = json.load(fp)
        # if layer argument spec'd then only update/load spec'd layer
        if not layer or not self.model:
            # update/load model if layer not spec'd or if no model exists yet
            self.model = _model
        else:
            # convert non-sequence to tuple
            layers = _listify(layer)
            # update/load layers
            for layer in layers:
                self.model[layer] = _model[layer]
Beispiel #8
0
    def _load(self, layer=None):
        """
        Load or update all or part of :attr:`model`.

        :param layer: Optionally load only specified layer.
        :type layer: str
        """
        # open model file for reading and convert JSON object to dictionary
        with open(self.modelfile, 'r') as fp:
            _model = json.load(fp)
        # if layer argument spec'd then only update/load spec'd layer
        if not layer or not self.model:
            # update/load model if layer not spec'd or if no model exists yet
            self.model = _model
        else:
            # convert non-sequence to tuple
            layers = _listify(layer)
            # update/load layers
            for layer in layers:
                self.model[layer] = _model[layer]