-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_process_forMATLAB.py
66 lines (44 loc) · 1.68 KB
/
data_process_forMATLAB.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# this is a first pass at a data extraction script in python
# import necessary modules
import numpy as np
import matplotlib.pyplot as plt
import json
import scipy
# define complex encoder class - from python docs
class ComplexEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, complex):
return [obj.real, obj.imag]
# Let the base class default method raise the TypeError
return json.JSONEncoder.default(self, obj)
# define arr2json dump function
def arr2json(arr):
return json.dumps(arr.tolist())
# load data
data = scipy.io.loadmat('matlabSubjData.mat')
#data = scipy.io.loadmat('d_854490.mat')
#data = scipy.io.loadmat('d.mat')
# subjects
#Columns 1 through 6
# '854490' '8adc5c' '979eab' '9ab7ab' '9d10c8' 'a3da50'
# Columns 7 through 8
# 'a9952e' 'd5cd55'
data_a = np.array(data['data_d5cd55'])
data_a_complex = np.add(data_a,0.j)
data_a_complex_trans = np.transpose(data_a_complex,[2,0,1])
#B = A + A.T - np.diag(np.diag(A))
# conver to list
data_reflect = data_a_complex_trans
for i in range(0,len(data_a_complex_trans)):
data_reflect[i] = data_a_complex_trans[i] + data_a_complex_trans[i].T -np.diag(np.diag(data_a_complex_trans[i]))
dataList = data_reflect.tolist()
# iterate through list, make fake complex
#for i in range(0,len(dataList)):
# for j in range(0,len(dataList[i])):
# for k in range(0,len(dataList[i][j])):
# dataList[i][j][k] = [dataList[i][j][k]]
# conver to encoded
dataEncode = ComplexEncoder().encode(dataList)
# write out to file
with open('data_d5cd55.txt', 'w') as outfile:
json.dump(dataEncode, outfile)