-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_loader.py
More file actions
35 lines (28 loc) · 1.18 KB
/
data_loader.py
File metadata and controls
35 lines (28 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from scipy.io import loadmat
from pathlib import Path
import numpy as np
class data_loader():
def load_data(self, data_file):
"""
The load_data method allows to load a matrix from a file (.mat).
:param data_file: is the name of the file (with its path) containing the matrix
:return: the loaded matrix
"""
if '.mat' in data_file:
data = self._load_mat(data_file)
return np.squeeze(np.array(data)).tolist()
def _load_mat(self, data_file):
"""
The _load_mat method loads a matrix from a .mat file (FOR INTERNAL USE ONLY).
:param data_file: is the name of the file (with its path) containing the matrix
:return: the loaded matrix
"""
data = loadmat(r'%s' % data_file)
for k in data.keys():
if not ('__' in k):
data = data[k]
for i in range(1, 5):
if not (isinstance(data, np.ndarray)) or data.shape == (1, 1) or data.shape == (1,) or data.shape == ():
data = data[0]
else:
return data