I'm attempting to use hdf5storage to write numpy data to a .mat file.
import hdf5storage
# For example
numpy_array = [array([(b'<detect>', 192, 1)], dtype=[('packet_sync', 'S8'), ('n_bytes', '<u4'), ('n_detect', '<u4')]), array([(b'<detect>', 192, 2)], dtype=[('packet_sync', 'S8'), ('n_bytes', '<u4'), ('n_detect', '<u4')])]
# The actual array is 192 bytes. and a binary file I am attempting to create a .mat file for contains thousands of these packets.
data = {"data": numpy_array}
hdf5storage.savemat(file_name="data.mat", mdict=data, format="7.3")
Using this conveniance function, or equivelantly
hdf5storage.write(data, '.', 'data.mat', matlab_compatible=True)
The file expands to >10X the binary file size, which is a python list with numpy dtypes composed of basic c types (<u4, <f4, <S8...). It also takes >1hour to process a 70MB file which seems like something isn't right, but I don't have a ton of experience with HDF5 format so this may be expected.
When testing saving a similar variable from MATLAB with
save("test.mat", 'variable', '-v7.3')
The file size is still much larger than the binary size. So as @hpaulj points out, HDF5 is not a compact format. But the time it takes to save in python is also not acceptable. In MATLAB, the file save in a few seconds, to save the same file using the hdf5storage library, it takes around an hour. Perhaps this library is just not performant?
Looking at the disk write speed while this is running though, I see a stat of 2-3 M/s via iotop while the file only grows ~0.5MB/s.
I would like to avoid writing to separate .mat files.
When using scipy's savemat, I am able to save files up to the matlab v5 limit of 2GB, but we are generating more data than that and would like to be able to use v7.3 matlab format. So the problem is with the hdf5storage library as scipy still works.
Is there some numpy dtype restrictions with matlab v7.3 format?
Why are these files getting inflated? Is there an option in hdf5storage that i'm missing? I've looked through the docs and partly through the code to no avail.
Alternatively, I may try loading an hdf5 file into MATLAB
import h5py
hf = h5py.File("test.h5", "w")
hf.create_dataset("data", data=data)
hf.close()
EDIT: I've discovered that my troubles may be dues to non-homogeneous data shape. I could have packets of variable size. HDF5 doesn't deal well with this apparently, so structuring the data for homogeneity is important.