问题
I am trying to use H5T_ARRAY inside the H5T_COMPOUND structure using Python. Basically, I am writing hdf5 file and if you open it using H5Dump, the structure looks like this.
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 ) }
}
}
}
Instead, the idea is to have this:
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 ) }
}
}
}
Thank you!
回答1:
Not sure how this is done with other libraries, but the above dataset compound layout may be created as follows with HDFql in Python:
# 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)")
Check HDFql reference manual for additional information and examples.
来源:https://stackoverflow.com/questions/64615524/using-h5t-array-in-python