示例#1
0
 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)
示例#2
0
    def openDataset(cls, path: Path, filesystem: FS) -> Tuple[h5py.Dataset, Path, Path]:
        outer_path = path
        dataset_path_components: List[str] = []
        while True:
            try:
                info = filesystem.getinfo(outer_path.as_posix())
                if not info.is_file:
                    raise UnsupportedUrlException(path.as_posix())
                break
            except ResourceNotFound as e:
                dataset_path_components.insert(0, outer_path.name)
                parent = outer_path.parent
                if parent == outer_path:
                    raise UnsupportedUrlException(path.as_posix())
                outer_path = parent

        try:
            binfile = filesystem.openbin(outer_path.as_posix())
            f = h5py.File(binfile, "r")
        except OSError as e:
            raise UnsupportedUrlException(path) from e

        try:
            inner_path = "/".join(dataset_path_components)
            dataset = f[inner_path]
            if not isinstance(dataset, h5py.Dataset):
                raise ValueError(f"{inner_path} is not a h5py.Dataset")
        except Exception as e:
            f.close()
            raise e

        return dataset, outer_path, Path(inner_path)
示例#3
0
 def load(cls, path: Path, filesystem: FileSystem) -> "N5DatasetAttributes":
     with filesystem.openbin(
             path.joinpath("attributes.json").as_posix(), "r") as f:
         attributes_json = f.read().decode("utf8")
     raw_attributes = json.loads(attributes_json)
     return cls.from_json_data(raw_attributes)