本文介绍了在python中使用h5py读取或写入复合数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在某些C ++,matlab和python代码中使用hdf5文件.我的h5文件在C ++和matlab中都能正常运行,但是无法用h5py读取.

I want to use hdf5 file among some C++, matlab, and python code.My h5 file works well in C++ and matlab, but cannot be read with h5py.

h5py是否很好地支持H5T_STD_B64LE之类的数据类型?谢谢!

Is data types like H5T_STD_B64LE not well supported by h5py?Thanks!

In [2]: f = h5py.File('art.mips.log.h5', 'r')

In [3]: f.keys()
Out[3]: [u'mem']

In [4]: f['mem']
Out[4]: <repr(<h5py._hl.dataset.Dataset at 0x29f70d0>) failed: TypeError: No NumPy equivalent for TypeBitfieldID exists>

hdf5文件格式如下:

The hdf5 file format is as follows:

$ h5dump -H art.mips.log.h5
HDF5 "art.mips.log.h5" { GROUP "/" {    DATASET "mem" {
      DATATYPE  H5T_COMPOUND {
         H5T_STD_B64LE "clock";
         H5T_STD_B32LE "addr";
         H5T_STD_B32LE "operation";
         H5T_ARRAY { [16] H5T_STD_B32LE } "data";
      }
      DATASPACE  SIMPLE { ( 68614468 ) / ( H5S_UNLIMITED ) }
      ATTRIBUTE "CLASS" {
         DATATYPE  H5T_STRING {
            STRSIZE 6;
            STRPAD H5T_STR_NULLTERM;
            CSET H5T_CSET_ASCII;
            CTYPE H5T_C_S1;
         }
         DATASPACE  SCALAR
      }
      ATTRIBUTE "FIELD_0_NAME" {
         DATATYPE  H5T_STRING {
            STRSIZE 6;
            STRPAD H5T_STR_NULLTERM;
            CSET H5T_CSET_ASCII;
            CTYPE H5T_C_S1;
         }
         DATASPACE  SCALAR
      }
      ATTRIBUTE "FIELD_1_NAME" {
         DATATYPE  H5T_STRING {
            STRSIZE 5;
            STRPAD H5T_STR_NULLTERM;
            CSET H5T_CSET_ASCII;
            CTYPE H5T_C_S1;
         }
         DATASPACE  SCALAR
      }
      ATTRIBUTE "FIELD_2_NAME" {
         DATATYPE  H5T_STRING {
            STRSIZE 10;
            STRPAD H5T_STR_NULLTERM;
            CSET H5T_CSET_ASCII;
            CTYPE H5T_C_S1;
         }
         DATASPACE  SCALAR
      }
      ATTRIBUTE "FIELD_3_NAME" {
         DATATYPE  H5T_STRING {
            STRSIZE 5;
            STRPAD H5T_STR_NULLTERM;
            CSET H5T_CSET_ASCII;
            CTYPE H5T_C_S1;
         }
         DATASPACE  SCALAR
      }
      ATTRIBUTE "TITLE" {
         DATATYPE  H5T_STRING {
            STRSIZE 4;
            STRPAD H5T_STR_NULLTERM;
            CSET H5T_CSET_ASCII;
            CTYPE H5T_C_S1;
         }
         DATASPACE  SCALAR
      }
      ATTRIBUTE "VERSION" {
         DATATYPE  H5T_STRING {
            STRSIZE 4;
            STRPAD H5T_STR_NULLTERM;
            CSET H5T_CSET_ASCII;
            CTYPE H5T_C_S1;
         }
         DATASPACE  SCALAR
      }
   }
}
}

推荐答案

h5py不支持位域,如 https://github.com/h5py/h5py/issues/109

h5py does not support bitfields, as stated in https://github.com/h5py/h5py/issues/109

我快速浏览了h5py中的低级接口,以查看是否有一种方法可以提取原始数据,但是看起来底层的id对象需要支持read()方法.

I had a quick look at the low-level interface within h5py to see if there was a way to get the raw data out but it looks like the underlying id object needs to support a read() method.

>>> mem_id = h5py.h5o.get_info(f.id, 'mem')
>>> mem_id.read
...
AttributeError: 'h5py.h5o.ObjInfo' object has no attribute 'read'

这篇关于在python中使用h5py读取或写入复合数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-29 14:27