示例#1
0
 def _write_in_storage(self, inst, value):
     """
     Store value on disk (in h5 file).
     :param inst: Will give us the storage_path, it is a MappedType instance
     :param value: expected to be of type self.wraps
     :raises Exception : when passed value is incompatible (e.g. used with chunks)
     """
     if self.trait.file_storage == FILE_STORAGE_NONE:
         pass
     elif self.trait.file_storage == FILE_STORAGE_DEFAULT:
         inst.store_data(self.trait.name, value)
     else:
         raise StorageException("You should not use SET on attributes-to-be-stored-in-files!")
示例#2
0
 def _read_from_storage(self, inst):
     """
     Call correct storage methods, and validation
     :param inst: Will give us the storage_path, it is a MappedType instance
     :returns: entity of self.wraps type
     :raises: Exception when used with chunks
     """
     if self.trait.file_storage == FILE_STORAGE_NONE:
         return None
     elif self.trait.file_storage == FILE_STORAGE_DEFAULT:
         try:
             return inst.get_data(self.trait.name, ignore_errors=True)
         except StorageException as exc:
             self.logger.debug("Missing dataSet " + self.trait.name)
             self.logger.debug(exc)
             return numpy.ndarray(0)
     else:
         raise StorageException("Use get_data(_, slice) not full GET on attributes-stored-in-files!")
示例#3
0
        :param inst: Will give us the storage_path, it is a MappedType instance
        :returns: entity of self.wraps type
        :raises: Exception when used with chunks
        """
        if self.trait.file_storage == FILE_STORAGE_NONE:
            return None
        elif self.trait.file_storage == FILE_STORAGE_DEFAULT:
            try:
                return inst.get_data(self.trait.name, ignore_errors=True)
            except StorageException, exc:
                self.logger.debug("Missing dataSet " + self.trait.name)
                self.logger.debug(exc)
                return numpy.ndarray(0)
        else:
            raise StorageException(
                "Use get_data(_, slice) not full GET on attributes-stored-in-files!"
            )


class SparseMatrix(mapped.SparseMatrix, Array):
    def _read_from_storage(self, inst):
        """
        Overwrite method from superclass, and call Sparse_Matrix specific reader.
        """
        try:
            return self._read_sparse_matrix(inst, self.trait.name)
        except StorageException, exc:
            self.logger.debug("Missing dataSet " + self.trait.name)
            self.logger.debug(exc)
            return None