-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathConvertData.py
42 lines (39 loc) · 1.63 KB
/
ConvertData.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
import pickle
nLabel, nTrial, nUser, nChannel, nTime = 4, 40, 32, 40, 8064
no_of_users=32
def convertData():
print("Program started"+"\n")
fout_data = open("data/features_raw.dat",'w')
fout_labels0 = open("data/labels_0.dat",'w')
fout_labels1 = open("data/labels_1.dat",'w')
fout_labels2 = open("data/labels_2.dat",'w')
fout_labels3 = open("data/labels_3.dat",'w')
for i in range(no_of_users): #nUser #4, 40, 32, 40, 8064 4 labels, 40 sample for each user, 32 such user, 40 electrode, 8064*40 features
if(i%1 == 0):
if i < 10:
name = '%0*d' % (2,i+1)
else:
name = i+1
fname = "data/s"+str(name)+".dat"
f = open(fname, 'rb') #Read the file in Binary mode
x = pickle.load(f, encoding='latin1')
print(fname)
for tr in range(nTrial):
if(tr%1 == 0):
for dat in range(nTime):
if(dat%32 == 0):
for ch in range(nChannel):
fout_data.write(str(x['data'][tr][ch][dat]) + " ");
fout_labels0.write(str(x['labels'][tr][0]) + "\n");
fout_labels1.write(str(x['labels'][tr][1]) + "\n");
fout_labels2.write(str(x['labels'][tr][2]) + "\n");
fout_labels3.write(str(x['labels'][tr][3]) + "\n");
fout_data.write("\n");
fout_labels0.close()
fout_labels1.close()
fout_labels2.close()
fout_labels3.close()
fout_data.close()
print("\n"+"Print Successful")
if __name__ == '__main__':
convertData()