def __init__(self, path: Path, *, location: Point5D = Point5D.zero(), filesystem: FS): try: raw_data = skimage.io.imread(filesystem.openbin(path.as_posix())) except ValueError: raise UnsupportedUrlException(path) axiskeys = "yxc"[: len(raw_data.shape)] super().__init__(url=filesystem.desc(path.as_posix()), data=raw_data, axiskeys=axiskeys, location=location)
def __init__(self, path: Path, *, location: Point5D = Point5D.zero(), filesystem: FS): self._dataset: Optional[h5py.Dataset] = None try: self._dataset, outer_path, inner_path = self.openDataset( path, filesystem=filesystem) axiskeys = self.getAxisKeys(self._dataset) tile_shape = Shape5D.create(raw_shape=self._dataset.chunks or self._dataset.shape, axiskeys=axiskeys) super().__init__( url=filesystem.desc(outer_path.as_posix()) + "/" + inner_path.as_posix(), tile_shape=tile_shape, shape=Shape5D.create(raw_shape=self._dataset.shape, axiskeys=axiskeys), dtype=self._dataset.dtype, name=self._dataset.file.filename.split("/")[-1] + self._dataset.name, location=location, axiskeys=axiskeys, ) except Exception as e: if self._dataset: self._dataset.file.close() raise e
def __init__(self, path: Path, *, location: Point5D = Point5D.zero(), chunk_size: Optional[Shape5D] = None, filesystem: FS): """A DataSource that handles Neurogancer's precomputed chunks path: a path all the pay down to the scale, i.e., if some scale has "key": "my_scale" then your path should end in "my_scale" chunk_size: a valid chunk_size for the scale selected by 'path' """ self.filesystem = filesystem.opendir(path.parent.as_posix()) self.info = PrecomputedChunksInfo.load(path=Path("info"), filesystem=self.filesystem) self.scale = self.info.get_scale(key=path.name) super().__init__( url="precomputed://" + filesystem.desc(path.as_posix()), tile_shape=self.scale.get_tile_shape_5d( self.info.num_channels, tile_shape_hint=chunk_size), shape=self.scale.get_shape_5d(self.info.num_channels), dtype=self.info.data_type, name=path.name, location=location, axiskeys=self.scale. axiskeys[:: -1], # externally reported axiskeys are always c-ordered ) encoding_type = self.scale.encoding if encoding_type == "raw": noop = lambda data: data self.decompressor = noop self.compressor = noop else: raise NotImplementedError( f"Don't know how to decompress {compression_type}")
def install_from_fs(self, name: str, source_fs: FS, path: str = ".", output_name: str = None): """ Copy a module directory from where it is located to the installation directory. :param name: Name of the module :param source_fs: FS object pointing to the source location :param path: Path to the module directory from the source location root :param output_name: Name to give to the module's directory at installation """ path_to_module = join(path, name) if name not in source_fs.listdir(path): raise InvalidModuleError( name, "Module directory not found - Given path should be the parent directory" ) if "__manifest__.py" not in source_fs.listdir(path_to_module): raise InvalidModuleError( name, "Manifest not found - Given path should be the parent directory" ) self.pretty_print(output_name, "Copying from {}".format( source_fs.desc(path_to_module)), level=VERBOSE_FULL) copy_dir(source_fs, path_to_module, self.install_dir, output_name or name) self.pretty_print(output_name, "Installed and up to date.", status=LOG_STATUS_OK, level=VERBOSE_NORMAL)