【问题标题】:Transform zarr directory storage to zip storage将 zarr 目录存储转换为 zip 存储
【发布时间】:2021-05-21 10:55:14
【问题描述】:

代码:

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

【问题讨论】:

标签: python compression zarr


【解决方案1】:

因为 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 存档中的路径是相对于原始根目录的。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      • 2016-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多