问题描述
代码:
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"),这样就不会再出现错误了。