将.h5(HDF5)文件转换为.zarr格式时,我遇到一个类型错误

2024-05-14 11:06:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将.h5文件转换为.zarr格式,但出现以下错误

TypeError: Object of type bytes_ is not JSON serializable

我把我的密码贴在下面

import h5py
import zarr
from sys import stdout

source = h5py.File('file.h5', 'r')
dest = zarr.open('file.zarr', 'w')
zarr.convenience.copy_all(source, dest, log=stdout, dry_run=False, if_exists='replace')

我查看了zarr文档,发现了一些github问题,但无法找到解决此错误的方法

我正在添加我已经查找过但找不到(或者老实说,无法理解)任何内容的链接

https://zarr.readthedocs.io/en/stable/api/convenience.html#zarr.convenience.copy_all

https://github.com/zarr-developers/zarr-python/issues/87

这是错误的回溯

Traceback (most recent call last):
  File "/home/prk/Documents/IISER-stuff/scripts/h5_to_zarr.py", line 8, in <module>
    zarr.convenience.copy_all(source, dest, log=stdout, dry_run=False, if_exists='replace')
  File "/home/prk/Documents/IISER-stuff/venv/lib/python3.8/site-packages/zarr/convenience.py", line 1063, in copy_all
    c, s, b = _copy(
  File "/home/prk/Documents/IISER-stuff/venv/lib/python3.8/site-packages/zarr/convenience.py", line 903, in _copy
    ds.attrs.update(source.attrs)
  File "/home/prk/Documents/IISER-stuff/venv/lib/python3.8/site-packages/zarr/attrs.py", line 120, in update
    self._write_op(self._update_nosync, *args, **kwargs)
  File "/home/prk/Documents/IISER-stuff/venv/lib/python3.8/site-packages/zarr/attrs.py", line 74, in _write_op
    return f(*args, **kwargs)
  File "/home/prk/Documents/IISER-stuff/venv/lib/python3.8/site-packages/zarr/attrs.py", line 131, in _update_nosync
    self._put_nosync(d)
  File "/home/prk/Documents/IISER-stuff/venv/lib/python3.8/site-packages/zarr/attrs.py", line 113, in _put_nosync
    self.store[self.key] = json_dumps(d)
  File "/home/prk/Documents/IISER-stuff/venv/lib/python3.8/site-packages/zarr/util.py", line 24, in json_dumps
    return json.dumps(o, indent=4, sort_keys=True, ensure_ascii=True,
  File "/usr/lib/python3.8/json/__init__.py", line 234, in dumps
    return cls(
  File "/usr/lib/python3.8/json/encoder.py", line 201, in encode
    chunks = list(chunks)
  File "/usr/lib/python3.8/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.8/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/usr/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes_ is not JSON serializable

Tags: inpyjsonhomevenvlibpackagesline
1条回答
网友
1楼 · 发布于 2024-05-14 11:06:23

您是否有资源尝试此命令行工具:https://github.com/saalfeldlab/n5-utils

安装后调用

n5-copy -i file.h5 -o file.zarr

这可能只是JSON导出器处理字节元数据的一个小故障,这至少可以为您提供所需的副本

相关问题 更多 >

    热门问题