在 Python 中使用 H5T_ARRAY
using H5T_ARRAY in Python
我正在尝试使用 Python 在 H5T_COMPOUND 结构中使用 H5T_ARRAY。基本上,我正在编写 hdf5 文件,如果你使用 H5Dump 打开它,结构如下所示。
HDF5 "SO_64449277np.h5" {
GROUP "/" {
DATASET "Table3" {
DATATYPE H5T_COMPOUND {
H5T_COMPOUND {
H5T_STD_I16LE "id";
H5T_STD_I16LE "timestamp";
} "header";
H5T_COMPOUND {
H5T_IEEE_F32LE "latency";
H5T_STD_I16LE "segments_k";
H5T_COMPOUND {
H5T_STD_I16LE "segment_id";
H5T_IEEE_F32LE "segment_quality";
H5T_IEEE_F32LE "segment_length";
} "segments_k0";
H5T_COMPOUND {
H5T_STD_I16LE "segment_id";
H5T_IEEE_F32LE "segment_quality";
H5T_IEEE_F32LE "segment_length";
} "segments_k1";
.....
} "summary_data";
}
DATASPACE SIMPLE { ( 2 ) / ( H5S_UNLIMITED ) }
}
}
}
相反,我们的想法是:
HDF5 "SO_64449277np.h5" {
GROUP "/" {
DATASET "Table3" {
DATATYPE H5T_COMPOUND {
H5T_COMPOUND {
H5T_STD_I16LE "id";
H5T_STD_I16LE "timestamp";
} "header";
H5T_COMPOUND {
H5T_IEEE_F32LE "latency";
H5T_ARRAY {[70] H5T_COMPOUND {
H5T_STD_I16LE "segment_id";
H5T_IEEE_F32LE "segment_quality";
H5T_IEEE_F32LE "segment_length";
} } "segments_k";
} "summary_data";
}
DATASPACE SIMPLE { ( 2 ) / ( H5S_UNLIMITED ) }
}
}
}
谢谢!
不确定其他库是如何做到这一点的,但是上面的数据集复合布局可以通过 Python 中的 HDFql 创建如下:
# import HDFql package
import HDFql
# create an HDF5 file named 'SO_64449277np.h5'
HDFql.execute("CREATE FILE SO_64449277np.h5")
# create an HDF5 compound dataset named 'Table3' (in HDF5 file 'SO_64449277np.h5') with the wanted layout
HDFql.execute("CREATE DATASET SO_64449277np.h5 Table3 AS COMPOUND(header AS COMPOUND(id AS SMALLINT, timestamp AS SMALLINT), summary_data AS COMPOUND(latency AS FLOAT, segments_k AS COMPOUND(segment_id AS SMALLINT, segment_quality AS FLOAT, segment_length AS FLOAT)(70)))(2 TO UNLIMITED)")
检查 HDFql reference manual 以获取更多信息和示例。
我正在尝试使用 Python 在 H5T_COMPOUND 结构中使用 H5T_ARRAY。基本上,我正在编写 hdf5 文件,如果你使用 H5Dump 打开它,结构如下所示。
HDF5 "SO_64449277np.h5" {
GROUP "/" {
DATASET "Table3" {
DATATYPE H5T_COMPOUND {
H5T_COMPOUND {
H5T_STD_I16LE "id";
H5T_STD_I16LE "timestamp";
} "header";
H5T_COMPOUND {
H5T_IEEE_F32LE "latency";
H5T_STD_I16LE "segments_k";
H5T_COMPOUND {
H5T_STD_I16LE "segment_id";
H5T_IEEE_F32LE "segment_quality";
H5T_IEEE_F32LE "segment_length";
} "segments_k0";
H5T_COMPOUND {
H5T_STD_I16LE "segment_id";
H5T_IEEE_F32LE "segment_quality";
H5T_IEEE_F32LE "segment_length";
} "segments_k1";
.....
} "summary_data";
}
DATASPACE SIMPLE { ( 2 ) / ( H5S_UNLIMITED ) }
}
}
}
相反,我们的想法是:
HDF5 "SO_64449277np.h5" {
GROUP "/" {
DATASET "Table3" {
DATATYPE H5T_COMPOUND {
H5T_COMPOUND {
H5T_STD_I16LE "id";
H5T_STD_I16LE "timestamp";
} "header";
H5T_COMPOUND {
H5T_IEEE_F32LE "latency";
H5T_ARRAY {[70] H5T_COMPOUND {
H5T_STD_I16LE "segment_id";
H5T_IEEE_F32LE "segment_quality";
H5T_IEEE_F32LE "segment_length";
} } "segments_k";
} "summary_data";
}
DATASPACE SIMPLE { ( 2 ) / ( H5S_UNLIMITED ) }
}
}
}
谢谢!
不确定其他库是如何做到这一点的,但是上面的数据集复合布局可以通过 Python 中的 HDFql 创建如下:
# import HDFql package
import HDFql
# create an HDF5 file named 'SO_64449277np.h5'
HDFql.execute("CREATE FILE SO_64449277np.h5")
# create an HDF5 compound dataset named 'Table3' (in HDF5 file 'SO_64449277np.h5') with the wanted layout
HDFql.execute("CREATE DATASET SO_64449277np.h5 Table3 AS COMPOUND(header AS COMPOUND(id AS SMALLINT, timestamp AS SMALLINT), summary_data AS COMPOUND(latency AS FLOAT, segments_k AS COMPOUND(segment_id AS SMALLINT, segment_quality AS FLOAT, segment_length AS FLOAT)(70)))(2 TO UNLIMITED)")
检查 HDFql reference manual 以获取更多信息和示例。