将 zarr 目录存储转换为 zip 存储

Transform zarr directory storage to zip storage

代码:

store = zarr.ZipStore("/mnt/test.zip", "r")

问题描述: 嗨,抱歉打扰了,我在 Zarr 官方文档中找到了关于 ZipStorage 的声明: Alternatively, use a DirectoryStore when writing the data, then manually Zip the directory and use the Zip file for subsequent reads.

我正在尝试将 DirectoryStorage 格式的 Zarr 数据集转换为 ZipStorage。我使用 Linux 中提供的 zip 操作。 zip -r test.zip test.zarr这里test.zarr是一个目录存储数据集,包括三组。但是,当我尝试使用上面的代码打开它时,出现如下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/eddie/miniconda3/envs/train/lib/python3.8/site-packages/zarr/storage.py", line 1445, in __init__
    self.zf = zipfile.ZipFile(path, mode=mode, compression=compression,
  File "/home/eddie/miniconda3/envs/train/lib/python3.8/zipfile.py", line 1190, in __init__
    _check_compression(compression)
  File "/home/eddie/miniconda3/envs/train/lib/python3.8/zipfile.py", line 686, in _check_compression
    raise NotImplementedError("That compression method is not supported")
NotImplementedError: That compression method is not supported

不知是不是我的压缩方式不对,有没有办法将目录存储转为zip存储或其他DB格式,导致分组上升时,之前的存储节点太多,不太方便运输。提前致谢。

Version and installation information
Value of zarr.__version__: 2.8.1
Value of numcodecs.__version__: 0.7.3
Version of Python interpreter: 3.8.0
Operating system (Linux/Windows/Mac): linux ubuntu 18.04
How Zarr was installed: pip

因为 zarr 已经使用压缩,所以在创建 zip 存档时不需要使用压缩。也就是说,您可以使用 zip -r -0 将文件仅存储在 zip 存档中,而不进行压缩。

此外,您可能需要注意存储在 zip 存档中的路径。例如,如果我在某个目录“/path/to/foo”中有一个 zarr 层次结构,并且我想将其存储到一个位于“/path/to/bar.zip”的 zip 文件中,我会这样做:

cd /path/to/foo
zip -r0 /path/to/bar.zip

这确保存储在 zip 存档中的路径是相对于原始根目录的。

用-r0选项压缩后,你可以试试store = zarr.ZipStore("/mnt/test.zip"),这样你就不会再报错了。