Skip to content

Commit

Permalink
fixing matlab 7.3 files; changed reading
Browse files Browse the repository at this point in the history
  • Loading branch information
Cesare Corrado committed Sep 30, 2024
1 parent 367fd7c commit a889eaa
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions openep/io/matlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ def _mat_v73_flat_to_nested(data):
Args:
data (dict): Data loaded from a v7.3 .mat file.
"""
nested_data = {}
#nested_dict = lambda: defaultdict(nested_dict) # noqa: E731

nested_dict = lambda: defaultdict(nested_dict) # noqa: E731

nested_data = nested_dict()
#nested_data = nested_dict()
for key in data:

nested_keys = key.split('/')[1:]
Expand All @@ -155,14 +155,26 @@ def _mat_v73_flat_to_nested(data):

elif len(nested_keys) == 2:
key1, key2 = nested_keys
if not key1 in nested_data.keys():
nested_data[key1] = {}
nested_data[key1][key2] = data[key]

elif len(nested_keys) == 3:
key1, key2, key3 = nested_keys
if not key1 in nested_data.keys():
nested_data[key1] = {}
if not key2 in nested_data[key1].keys():
nested_data[key1][key2] = {}
nested_data[key1][key2][key3] = data[key]

elif len(nested_keys) == 4:
key1, key2, key3, key4 = nested_keys
if not key1 in nested_data.keys():
nested_data[key1] = {}
if not key2 in nested_data[key1].keys():
nested_data[key1][key2] = {}
if not key3 in nested_data[key1][key2].keys():
nested_data[key1][key2][key3] = {}
nested_data[key1][key2][key3][key4] = data[key]

else:
Expand All @@ -171,6 +183,7 @@ def _mat_v73_flat_to_nested(data):
return nested_data



def _load_mat_v73(filename):
"""
Load a v7.3 MATLAB file.
Expand Down

0 comments on commit a889eaa

Please sign in to comment.