如何解压缩存储在 zstd 压缩的 HDF5 文件中的数据?

问题描述

我在 zstd 情况下遇到了一些解压问题。我有 hdf5 格式的文件,压缩方式如下:

import h5py as h5
import hdf5plugin
import sys
import os
filefrom = sys.argv[1] 
h5path  = sys.argv[2]
f = h5.File(filefrom,'r')
data = f[h5path]
shape_data = data.shape[1:]
num = data.shape[0]
initShape = (1,) + shape_data
maxShape = (num,) + shape_data
f_zstd = h5.File(filefrom.split('.')[0]+'_zstd.h5','w')
d_zstd = f_zstd.create_dataset(path_to_data,initShape,maxshape=maxShape,dtype=np.int32,chunks=initShape,**hdf5plugin.Zstd())
d_zstd[0,] = data[0,]
for i in range(num):
    d_zstd.resize((i+1,) + shape_data)
    d_zstd[i,] = data[i,]
f_zstd.close()
f.close()
    

所以它压缩没有任何错误,但是当我尝试使用 h5lsh5dump 查看数据时,它打印出无法打印数据,并且没有其他查看方式在文件内部,如使用 h5py 在 python3 (3.6) 中读取此压缩数据是不成功的。我还尝试了 h5repack (h5repack -i compressed_file.h5 -o out_file.h5 --filter=var:NONE) 或以下代码:

import zstandard
import pathlib
import os

def decompress_zstandard_to_folder(input_file):
    input_file = pathlib.Path(input_file)
    destination_dir = os.path.dirname(input_file)
    with open(input_file,'rb') as compressed:
        decomp = zstandard.ZstdDecompressor()
        output_path = pathlib.Path(destination_dir) / input_file.stem
        with open(output_path,'wb') as destination:
            decomp.copy_stream(compressed,destination)

没有成功。在 h5repack 的情况下没有出现警告或错误,最后一段代码我得到了这个 zstd.ZstdError: zstd decompressor error: Unknown frame descriptor,所以我得到这意味着压缩数据没有适当的标题。

我使用 python 3.6.7hdf5 1.10.5。所以我有点困惑,不知道如何克服这个问题。

乐于接受任何想法/建议!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)