Reputation: 1
I meet some troubles when I try to laod matlab file (.mat) with scipy (scipy.io.loadmat). The dataset (4 Go) is an output from a wave numerical model (SWAN). The message error is : ValueError: Did not read any bytes The strange thing is that the .mat is a size of 4 Go. There is probably an explanation but I didn't find it. If someone has an idea... Here is the code using the mhkit library :
def _read_block_mat(swan_file):
'''
Reads in SWAN matlab output and creates a dictionary of DataFrames
for each swan output variable.
Parameters
----------
swan_file: str
filename to import
Returns
-------
dataDict: Dictionary
Dictionary of DataFrame of swan output variables
'''
assert isinstance(swan_file, str), 'swan_file must be of type str'
assert isfile(swan_file)==True, f'File not found: {swan_file}'
dataDict = loadmat(swan_file, struct_as_record=False, squeeze_me=True)
removeKeys = ['__header__', '__version__', '__globals__']
for key in removeKeys:
dataDict.pop(key, None)
for key in dataDict.keys():
dataDict[key] = pd.DataFrame(dataDict[key])
return dataDict
def read_block(swan_file):
'''
Reads in SWAN block output with headers and creates a dictionary
of DataFrames for each SWAN output variable in the output file.
Parameters
----------
swan_file: str
swan block file to import
Returns
-------
data: Dictionary
Dictionary of DataFrame of swan output variables
metaDict: Dictionary
Dictionary of metaData dependent on file type
'''
assert isinstance(swan_file, str), 'swan_file must be of type str'
assert isfile(swan_file)==True, f'File not found: {swan_file}'
extension = swan_file.split('.')[1].lower()
if extension == 'mat':
dataDict = _read_block_mat(swan_file)
metaData = {'filetype': 'mat',
'variables': [var for var in dataDict.keys()]}
else:
dataDict, metaData = _read_block_txt(swan_file)
return dataDict, metaData
Reading .mat file with the python module scipy (io.loadmat). The fonction doesn't read any bytes but the file is not empty (4Go)
Edouard
Upvotes: 0
Views: 980
Reputation: 1
The file was corrupted.
I had the same problem, it was not an empty file, but it was impossible to open it even in Matlab because the file was corrupted.
Upvotes: -1