-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_data.py
52 lines (45 loc) · 1.47 KB
/
get_data.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
import numpy as np
import scipy.io as sio
def get_data(subject,training,PATH):
'''
Loads the dataset 2a of the BCI Competition IV
download link available @ http://bnci-horizon-2020.eu/database/data-sets
see for original implementation :
add this later
Keyword arguments:
subject -- number of subject in [1, .. ,9]
training -- if True, load training data
if False, load testing data
Return: data_return numpy matrix size = NO_valid_trial x 22 x 1750
class_return numpy matrix size = NO_valid_trial
'''
NO_channels = 22
NO_tests = 6*48
Window_Length = 7*250
class_return = np.zeros(NO_tests)
data_return = np.zeros((NO_tests,NO_channels,Window_Length))
NO_valid_trial = 0
if training:
a = sio.loadmat(PATH+'A0'+str(subject)+'T.mat')
else:
a = sio.loadmat(PATH+'A0'+str(subject)+'E.mat')
a_data = a['data']
for ii in range(0,a_data.size):
a_data1 = a_data[0,ii]
a_data2=[a_data1[0,0]]
a_data3=a_data2[0]
a_X = a_data3[0]
a_trial = a_data3[1]
a_y = a_data3[2]
a_fs = a_data3[3]
a_classes = a_data3[4]
a_artifacts = a_data3[5]
a_gender = a_data3[6]
a_age = a_data3[7]
for trial in range(0,a_trial.size):
if(a_artifacts[trial]==0):
data_return[NO_valid_trial,:,:] = np.transpose(a_X[int(a_trial[trial]):(int(a_trial[trial])+Window_Length),:22])
class_return[NO_valid_trial] = int(a_y[trial])
NO_valid_trial +=1
return data_return[0:NO_valid_trial,:,:], class_return[0:NO_valid_trial]