示例#1
0
 def add_data(self, data):
     if self.has_data():
         raise WorkspaceException('Workspace has already been initialized with data.')
     path = self.genpath(self.__dsname__)
     chunks = CHUNK_SIZE if CHUNK_DATA else None
     Dataset.create(path, data=data, chunks=chunks)
     self.add_session('default')
     return self.get_data()
示例#2
0
    def add_data(self, data_fname):
        if self.has_data():
            raise WorkspaceException(
                "Workspace has already been initialized with data.")

        # path = self.genpath(self.__dsname__)

        chunks = DataModel.g.CHUNK_SIZE if DataModel.g.CHUNK_DATA else None
        path = self.genpath(self.__dsname__)
        Dataset.create(path, data=data_fname, chunks=chunks)

        # self.add_session('default')

        return self.get_data()
示例#3
0
    def add_dataset(
        self,
        dataset_name,
        dtype,
        session="default",
        fillvalue=0,
        chunks=None,
        shape=None,
    ):
        dataset_name = dataset_name.replace("/", os.path.sep)

        if self.has_dataset(dataset_name, session=session):
            raise WorkspaceException("Dataset '{}::{}' already exists.".format(
                session, dataset_name))

        metadata = self.metadata()
        shape = shape or metadata["shape"]
        chunk_size = chunks or metadata["chunk_size"]
        dtype = np.dtype(dtype).name
        path = self.genpath(session, dataset_name)

        return Dataset.create(
            path,
            shape=shape,
            dtype=dtype,
            chunks=chunk_size,
            fillvalue=fillvalue,
            database=DataModel.g.DATABASE,
        )
示例#4
0
    def metadata(self):
        if not self.has_data():
            raise WorkspaceException("Workspace data has not been initialized")

        path = self.genpath(self.__dsname__)

        return Dataset(path).get_metadata(Dataset.__dsname__)
示例#5
0
    def has_dataset(self, dataset_name, session="default"):
        # logger.debug(f'has_dataset {dataset_name} for session {session}')
        dataset_name = dataset_name.replace("/", os.path.sep)

        if self.has_session(session):
            path = self.genpath(session, dataset_name)
            return Dataset.exists(path)
        return False
示例#6
0
 def get_dataset(self, dataset_name, session='default', **kwargs):
     dataset_name = dataset_name.replace('/', op.sep)
     if not self.has_dataset(dataset_name, session=session):
         raise WorkspaceException('Dataset \'{}::{}\' does not exist.'
                                  .format(session, dataset_name))
     path = self.genpath(session, dataset_name)
     ds = Dataset(path, **kwargs)
     if tuple(ds.shape) != tuple(self.metadata()['shape']):
         raise WorkspaceException('Dataset \'{}::{}\' has incorrect `shape`.'
                                  'Got {}, expected {}.'
                                  .format(session, dataset_name,
                                          tuple(ds.shape),
                                          tuple(self.metadata()['shape'])))
     return ds
示例#7
0
    def add_dataset(self, dataset_name, dtype, session='default',
                    fillvalue=0, chunks=None, shape=None):
        dataset_name = dataset_name.replace('/', op.sep)
        if self.has_dataset(dataset_name, session=session):
            raise WorkspaceException('Dataset \'{}::{}\' already exists.'
                                     .format(session, dataset_name))

        metadata = self.metadata()
        shape = shape or metadata['shape']
        chunk_size = chunks or metadata['chunk_size']
        dtype = np.dtype(dtype).name

        path = self.genpath(session, dataset_name)
        return Dataset.create(path, shape=shape, dtype=dtype, chunks=chunk_size,
                              fillvalue=fillvalue, database=DATABASE)
示例#8
0
    def get_dataset(self, dataset_name, session="default", **kwargs):
        dataset_name = dataset_name.replace("/", os.path.sep)

        if not self.has_dataset(dataset_name, session=session):
            raise WorkspaceException("Dataset '{}::{}' does not exist.".format(
                session, dataset_name))

        path = self.genpath(session, dataset_name)
        ds = Dataset(path, **kwargs)

        if tuple(ds.shape) != tuple(self.metadata()["shape"]):
            raise WorkspaceException("Dataset '{}::{}' has incorrect `shape`."
                                     "Got {}, expected {}.".format(
                                         session,
                                         dataset_name,
                                         tuple(ds.shape),
                                         tuple(self.metadata()["shape"]),
                                     ))
        return ds
示例#9
0
 def has_dataset(self, dataset_name, session='default'):
     dataset_name = dataset_name.replace('/', op.sep)
     if self.has_session(session):
         path = self.genpath(session, dataset_name)
         return Dataset.exists(path)
     return False
示例#10
0
 def get_data(self, **kwargs):
     kwargs.setdefault('readonly', True)
     if not self.has_data():
         raise WorkspaceException('Workspace data has not been initialized')
     path = self.genpath(self.__dsname__)
     return Dataset(path, **kwargs)
示例#11
0
 def has_data(self):
     path = self.genpath(self.__dsname__)
     return Dataset.exists(path)