Esempio n. 1
0
 def __init__(self,
              *,
              outer_path: Path,
              inner_path: PurePosixPath,
              location: Point5D = Point5D.zero(),
              filesystem: JsonableFilesystem):
     self.outer_path = outer_path
     self.inner_path = inner_path
     self.filesystem = filesystem
     binfile = filesystem.openbin(outer_path.as_posix())
     f = h5py.File(binfile, "r")
     try:
         dataset = f[inner_path.as_posix()]
         if not isinstance(dataset, h5py.Dataset):
             raise ValueError(f"{inner_path} is not a Dataset")
         axiskeys = self.getAxisKeys(dataset)
         self._dataset = cast(h5py.Dataset, dataset)
         tile_shape = Shape5D.create(raw_shape=self._dataset.chunks
                                     or self._dataset.shape,
                                     axiskeys=axiskeys)
         super().__init__(
             tile_shape=tile_shape,
             interval=Shape5D.create(
                 raw_shape=self._dataset.shape,
                 axiskeys=axiskeys).to_interval5d(location),
             dtype=self._dataset.dtype,
             axiskeys=axiskeys,
         )
     except Exception as e:
         f.close()
         raise e
Esempio n. 2
0
    def __init__(self,
                 path: Path,
                 *,
                 location: Point5D = Point5D.zero(),
                 filesystem: FS):
        url = filesystem.geturl(path.as_posix())
        match = re.search(r"[^/]+\.n5/.*$", url, re.IGNORECASE)
        if not match:
            raise UnsupportedUrlException(url)
        name = match.group(0)
        self.filesystem = filesystem.opendir(path.as_posix())

        with self.filesystem.openbin("attributes.json", "r") as f:
            attributes_json_bytes = f.read()
        attributes = json.loads(attributes_json_bytes.decode("utf8"))

        dimensions = attributes["dimensions"][::-1]
        blockSize = attributes["blockSize"][::-1]
        axiskeys = "".join(attributes["axes"]).lower(
        )[::-1] if "axes" in attributes else guess_axiskeys(dimensions)

        super().__init__(
            url=url,
            name=name,
            tile_shape=Shape5D.create(raw_shape=blockSize, axiskeys=axiskeys),
            shape=Shape5D.create(raw_shape=dimensions, axiskeys=axiskeys),
            dtype=np.dtype(attributes["dataType"]).newbyteorder(">"),
            location=location,
            axiskeys=axiskeys,
        )
        self.compression_type = attributes["compression"]["type"]
        if self.compression_type not in N5Block.DECOMPRESSORS.keys():
            raise NotImplementedError(
                f"Don't know how to decompress from {self.compression_type}")
Esempio n. 3
0
 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