h5py: Issues to correctly read a 'table' class stored in MATLAB (.mat -7.3)

Viewed 529

I am trying to import a MATLAB (.mat -7.3) file in Python 3.8 using the h5py module. The file contains a structure class and table class. I successfully imported the structure class object. However, the table class is showing wrong dimensions after importing.

    import h5py
    
    Path='data/LUT_0/LUT_0.mat' #path file path to be read
    f = h5py.File(Path, mode='r') #read mat file

    list(f.keys())

Results in:

['#refs#', '#subsystem#', 'LUT_Refl', 'LUT_Var']

LUT_Var is a <HDF5 dataset "LUT_Var": shape(1,6), type"">. Trying to access the data results in:

f['LUT_Var'][()]

array([[3707764736,          2,          1,          1,          1,
                 1]], dtype=uint32)

However, I am expecting a table of the size: 169560x12. When I export this table as a txt file from MATLAB, I can import is just fine in Python. I can also re-import the .mat file in MATLAB and don´t see any corruption of the data. Does anyone know what could be missing here?

Thanks.

1 Answers

@ThatNewGuy. I could access the contents of the Matlab file this way:

import h5py
import numpy as np
import pandas as pd

f = h5py.File(matloc, 'r') # matloc = path to your .mat
print(list(f))

re = f.get('LUT_Refl/Full')
w = f.get('LUT_Refl/WL')

data = pd.DataFrame(np.array(re)).transpose()  # For converting to a NumPy array
wl = pd.DataFrame(np.array(w))
Related