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}")
def from_filesystem(cls, filesystem: FileSystem) -> "Protocol": if isinstance(filesystem, OSFS): return Protocol.FILE return Url.parse(filesystem.geturl("")).protocol #FIXME: is this reliable ?